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 = empty($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".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ?
"" :
"Modified").
"CustomerOrders", $max));
88 if ($user->rights->commande->lire) {
89 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
90 $sql .=
", s.code_client, s.code_compta, s.client";
91 $sql .=
", s.logo, s.email, s.entity";
92 $sql .=
", c.ref, c.tms";
94 $sql .=
", c.date_commande";
95 $sql .=
", c.ref_client";
96 $sql .=
", c.fk_statut";
97 $sql .=
", c.fk_user_valid";
98 $sql .=
", c.facture";
99 $sql .=
", c.total_ht";
100 $sql .=
", c.total_tva";
101 $sql .=
", c.total_ttc";
102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
103 $sql .=
", ".MAIN_DB_PREFIX.
"commande as c";
104 if (empty($user->rights->societe->client->voir) && !$user->socid) {
105 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
107 $sql .=
" WHERE c.fk_soc = s.rowid";
108 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
109 if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) {
110 $sql .=
" AND c.fk_statut = 1";
112 if (empty($user->rights->societe->client->voir) && !$user->socid) {
113 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
116 $sql .=
" AND s.rowid = ".((int) $user->socid);
118 if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
119 $sql .=
" ORDER BY c.date_commande DESC, c.ref DESC ";
121 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
123 $sql .= $this->
db->plimit($max, 0);
125 $result = $this->
db->query($sql);
127 $num = $this->
db->num_rows($result);
131 while ($line < $num) {
132 $objp = $this->
db->fetch_object($result);
133 $date = $this->
db->jdate($objp->date_commande);
134 $datem = $this->
db->jdate($objp->tms);
136 $commandestatic->id = $objp->rowid;
137 $commandestatic->ref = $objp->ref;
138 $commandestatic->ref_client = $objp->ref_client;
139 $commandestatic->total_ht = $objp->total_ht;
140 $commandestatic->total_tva = $objp->total_tva;
141 $commandestatic->total_ttc = $objp->total_ttc;
142 $commandestatic->date = $date;
143 $commandestatic->date_modification = $datem;
145 $societestatic->id = $objp->socid;
146 $societestatic->name = $objp->name;
148 $societestatic->code_client = $objp->code_client;
149 $societestatic->code_compta = $objp->code_compta;
150 $societestatic->client = $objp->client;
151 $societestatic->logo = $objp->logo;
152 $societestatic->email = $objp->email;
153 $societestatic->entity = $objp->entity;
155 $this->info_box_contents[$line][] = array(
156 'td' =>
'class="nowraponall"',
157 'text' => $commandestatic->getNomUrl(1),
161 $this->info_box_contents[$line][] = array(
162 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
163 'text' => $societestatic->getNomUrl(1),
167 $this->info_box_contents[$line][] = array(
168 'td' =>
'class="nowraponall right amount"',
169 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
172 if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
173 if ($objp->fk_user_valid > 0) {
174 $userstatic->fetch($objp->fk_user_valid);
176 $this->info_box_contents[$line][] = array(
177 'td' =>
'class="right"',
178 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) :
''),
183 $this->info_box_contents[$line][] = array(
188 $this->info_box_contents[$line][] = array(
189 'td' =>
'class="right" width="18"',
190 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
197 $this->info_box_contents[$line][0] = array(
198 'td' =>
'class="center opacitymedium"',
199 'text'=>$langs->trans(
"NoRecordedOrders")
203 $this->
db->free($result);
205 $this->info_box_contents[0][0] = array(
208 'text' => ($this->
db->error().
' sql='.$sql),
212 $this->info_box_contents[0][0] = array(
213 'td' =>
'class="nohover opacitymedium left"',
214 'text' => $langs->trans(
"ReadPermissionNotAllowed")
227 public function showBox($head = null, $contents = null, $nooutput = 0)
229 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.
$conf db
API class for accounts.
Class to manage Dolibarr users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
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).