27 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
35 public $boxcode =
"lastcustomerorders";
36 public $boximg =
"object_order";
37 public $boxlabel =
"BoxLastCustomerOrders";
38 public $depends = array(
"commande");
47 public $info_box_head = array();
48 public $info_box_contents = array();
63 $this->hidden = !($user->rights->commande->lire);
74 global $user, $langs, $conf;
75 $langs->load(
'orders');
79 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
80 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
84 $userstatic =
new User($this->
db);
86 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE ?
"" :
"Modified").
"CustomerOrders", $max));
88 if ($user->rights->commande->lire)
90 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .=
", s.code_client, s.code_compta, s.client";
92 $sql .=
", s.logo, s.email, s.entity";
93 $sql .=
", c.ref, c.tms";
95 $sql .=
", c.date_commande";
96 $sql .=
", c.ref_client";
97 $sql .=
", c.fk_statut";
98 $sql .=
", c.fk_user_valid";
99 $sql .=
", c.facture";
100 $sql .=
", c.total_ht";
101 $sql .=
", c.tva as total_tva";
102 $sql .=
", c.total_ttc";
103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
104 $sql .=
", ".MAIN_DB_PREFIX.
"commande as c";
105 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
106 $sql .=
" WHERE c.fk_soc = s.rowid";
107 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
108 if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) $sql .=
" AND c.fk_statut = 1";
109 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
110 if ($user->socid) $sql .=
" AND s.rowid = ".$user->socid;
111 if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .=
" ORDER BY c.date_commande DESC, c.ref DESC ";
112 else $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
113 $sql .= $this->
db->plimit($max, 0);
115 $result = $this->
db->query($sql);
117 $num = $this->
db->num_rows($result);
121 while ($line < $num) {
122 $objp = $this->
db->fetch_object($result);
123 $date = $this->
db->jdate($objp->date_commande);
124 $datem = $this->
db->jdate($objp->tms);
126 $commandestatic->id = $objp->rowid;
127 $commandestatic->ref = $objp->ref;
128 $commandestatic->ref_client = $objp->ref_client;
129 $commandestatic->total_ht = $objp->total_ht;
130 $commandestatic->total_tva = $objp->total_tva;
131 $commandestatic->total_ttc = $objp->total_ttc;
133 $societestatic->id = $objp->socid;
134 $societestatic->name = $objp->name;
136 $societestatic->code_client = $objp->code_client;
137 $societestatic->code_compta = $objp->code_compta;
138 $societestatic->client = $objp->client;
139 $societestatic->logo = $objp->logo;
140 $societestatic->email = $objp->email;
141 $societestatic->entity = $objp->entity;
143 $this->info_box_contents[$line][] = array(
144 'td' =>
'class="nowraponall"',
145 'text' => $commandestatic->getNomUrl(1),
149 $this->info_box_contents[$line][] = array(
150 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
151 'text' => $societestatic->getNomUrl(1),
155 $this->info_box_contents[$line][] = array(
156 'td' =>
'class="nowraponall right"',
157 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
160 if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
161 if ($objp->fk_user_valid > 0) $userstatic->fetch($objp->fk_user_valid);
162 $this->info_box_contents[$line][] = array(
163 'td' =>
'class="right"',
164 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) :
''),
169 $this->info_box_contents[$line][] = array(
170 'td' =>
'class="right"',
174 $this->info_box_contents[$line][] = array(
175 'td' =>
'class="right" width="18"',
176 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
182 if ($num == 0) $this->info_box_contents[$line][0] = array(
183 'td' =>
'class="center opacitymedium"',
184 'text'=>$langs->trans(
"NoRecordedOrders")
187 $this->
db->free($result);
189 $this->info_box_contents[0][0] = array(
192 'text' => ($this->
db->error().
' sql='.$sql),
196 $this->info_box_contents[0][0] = array(
197 'td' =>
'class="nohover opacitymedium left"',
198 'text' => $langs->trans(
"ReadPermissionNotAllowed")
211 public function showBox($head = null, $contents = null, $nooutput = 0)
213 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
Class to manage the box to show last orders.
loadBox($max=5)
Load data for box to show them later.
Class to manage Dolibarr users.
$conf db
API class for accounts.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage third parties objects (customers, suppliers, prospects...)
__construct($db, $param)
Constructor.
Class to manage customers orders.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).