64 global $user, $langs, $conf;
65 $langs->load(
'orders');
69 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
70 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
72 $commandestatic =
new Commande($this->db);
73 $societestatic =
new Societe($this->db);
74 $userstatic =
new User($this->db);
76 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"CustomerOrders", $max);
77 $this->info_box_head = array(
78 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/commande/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
81 if ($user->hasRight(
'commande',
'lire')) {
82 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
83 $sql .=
", s.code_client, s.code_compta as code_compta_client, s.client";
84 $sql .=
", s.logo, s.email, s.entity";
85 $sql .=
", c.ref, c.tms";
87 $sql .=
", c.date_commande";
88 $sql .=
", c.ref_client";
89 $sql .=
", c.fk_statut";
90 $sql .=
", c.fk_user_valid";
91 $sql .=
", c.facture";
92 $sql .=
", c.total_ht";
93 $sql .=
", c.total_tva";
94 $sql .=
", c.total_ttc";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c, ".MAIN_DB_PREFIX.
"societe as s";
96 if (!$user->hasRight(
'societe',
'client',
'voir')) {
97 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
99 $sql .=
" WHERE c.fk_soc = s.rowid";
100 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
102 $sql .=
" AND c.fk_statut = 1";
104 if (!$user->hasRight(
'societe',
'client',
'voir')) {
105 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
108 $sql .=
" AND s.rowid = ".((int) $user->socid);
111 $sql .=
" ORDER BY c.date_commande DESC, c.ref DESC ";
113 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
115 $sql .= $this->db->plimit($max, 0);
117 $result = $this->db->query($sql);
119 $num = $this->db->num_rows($result);
123 while ($line < $num) {
124 $objp = $this->db->fetch_object($result);
125 $date = $this->db->jdate($objp->date_commande);
126 $datem = $this->db->jdate($objp->tms);
128 $commandestatic->id = $objp->rowid;
129 $commandestatic->ref = $objp->ref;
130 $commandestatic->ref_client = $objp->ref_client;
131 $commandestatic->total_ht = $objp->total_ht;
132 $commandestatic->total_tva = $objp->total_tva;
133 $commandestatic->total_ttc = $objp->total_ttc;
134 $commandestatic->date = $date;
135 $commandestatic->date_modification = $datem;
137 $societestatic->id = $objp->socid;
138 $societestatic->name = $objp->name;
140 $societestatic->code_client = $objp->code_client;
141 $societestatic->code_compta = $objp->code_compta_client;
142 $societestatic->code_compta_client = $objp->code_compta_client;
143 $societestatic->client = $objp->client;
144 $societestatic->logo = $objp->logo;
145 $societestatic->email = $objp->email;
146 $societestatic->entity = $objp->entity;
148 $this->info_box_contents[$line][] = array(
149 'td' =>
'class="nowraponall"',
150 'text' => $commandestatic->getNomUrl(1),
154 $this->info_box_contents[$line][] = array(
155 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
156 'text' => $societestatic->getNomUrl(1),
160 $this->info_box_contents[$line][] = array(
161 'td' =>
'class="nowraponall right amount"',
162 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
166 if ($objp->fk_user_valid > 0) {
167 $userstatic->fetch($objp->fk_user_valid);
169 $this->info_box_contents[$line][] = array(
170 'td' =>
'class="right"',
171 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) :
''),
176 $this->info_box_contents[$line][] = array(
181 $this->info_box_contents[$line][] = array(
182 'td' =>
'class="right" width="18"',
183 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
190 $this->info_box_contents[$line][0] = array(
191 'td' =>
'class="center"',
192 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedOrders").
'</span>'
196 $this->db->free($result);
198 $this->info_box_contents[0][0] = array(
201 'text' => ($this->db->error().
' sql='.$sql),
205 $this->info_box_contents[0][0] = array(
206 'td' =>
'class="nohover left"',
207 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'