63 global $user, $langs, $conf;
64 $langs->load(
'orders');
68 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
69 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
71 $commandestatic =
new Commande($this->db);
72 $societestatic =
new Societe($this->db);
73 $userstatic =
new User($this->db);
75 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"CustomerOrders", $max);
76 $this->info_box_head = array(
77 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/commande/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
80 if ($user->hasRight(
'commande',
'lire')) {
81 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
82 $sql .=
", s.code_client, s.code_compta, s.client";
83 $sql .=
", s.logo, s.email, s.entity";
84 $sql .=
", c.ref, c.tms";
86 $sql .=
", c.date_commande";
87 $sql .=
", c.ref_client";
88 $sql .=
", c.fk_statut";
89 $sql .=
", c.fk_user_valid";
90 $sql .=
", c.facture";
91 $sql .=
", c.total_ht";
92 $sql .=
", c.total_tva";
93 $sql .=
", c.total_ttc";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c, ".MAIN_DB_PREFIX.
"societe as s";
95 if (!$user->hasRight(
'societe',
'client',
'voir')) {
96 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
98 $sql .=
" WHERE c.fk_soc = s.rowid";
99 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
101 $sql .=
" AND c.fk_statut = 1";
103 if (!$user->hasRight(
'societe',
'client',
'voir')) {
104 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107 $sql .=
" AND s.rowid = ".((int) $user->socid);
110 $sql .=
" ORDER BY c.date_commande DESC, c.ref DESC ";
112 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
114 $sql .= $this->db->plimit($max, 0);
116 $result = $this->db->query($sql);
118 $num = $this->db->num_rows($result);
122 while ($line < $num) {
123 $objp = $this->db->fetch_object($result);
124 $date = $this->db->jdate($objp->date_commande);
125 $datem = $this->db->jdate($objp->tms);
127 $commandestatic->id = $objp->rowid;
128 $commandestatic->ref = $objp->ref;
129 $commandestatic->ref_client = $objp->ref_client;
130 $commandestatic->total_ht = $objp->total_ht;
131 $commandestatic->total_tva = $objp->total_tva;
132 $commandestatic->total_ttc = $objp->total_ttc;
133 $commandestatic->date = $date;
134 $commandestatic->date_modification = $datem;
136 $societestatic->id = $objp->socid;
137 $societestatic->name = $objp->name;
139 $societestatic->code_client = $objp->code_client;
140 $societestatic->code_compta = $objp->code_compta;
141 $societestatic->client = $objp->client;
142 $societestatic->logo = $objp->logo;
143 $societestatic->email = $objp->email;
144 $societestatic->entity = $objp->entity;
146 $this->info_box_contents[$line][] = array(
147 'td' =>
'class="nowraponall"',
148 'text' => $commandestatic->getNomUrl(1),
152 $this->info_box_contents[$line][] = array(
153 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
154 'text' => $societestatic->getNomUrl(1),
158 $this->info_box_contents[$line][] = array(
159 'td' =>
'class="nowraponall right amount"',
160 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
164 if ($objp->fk_user_valid > 0) {
165 $userstatic->fetch($objp->fk_user_valid);
167 $this->info_box_contents[$line][] = array(
168 'td' =>
'class="right"',
169 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) :
''),
174 $this->info_box_contents[$line][] = array(
179 $this->info_box_contents[$line][] = array(
180 'td' =>
'class="right" width="18"',
181 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
188 $this->info_box_contents[$line][0] = array(
189 'td' =>
'class="center"',
190 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedOrders").
'</span>'
194 $this->db->free($result);
196 $this->info_box_contents[0][0] = array(
199 'text' => ($this->db->error().
' sql='.$sql),
203 $this->info_box_contents[0][0] = array(
204 'td' =>
'class="nohover left"',
205 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'