68 global $user, $langs,
$conf;
69 $langs->load(
'orders');
73 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
74 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
76 $commandestatic =
new Commande($this->db);
77 $societestatic =
new Societe($this->db);
78 $userstatic =
new User($this->db);
80 $text = $langs->trans(
"BoxTitleLast".(
getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"CustomerOrders", $max);
81 $this->info_box_head = array(
82 'text' => $text.
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/commande/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
85 if ($user->hasRight(
'commande',
'lire')) {
86 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
87 $sql .=
", s.code_client, s.code_compta as code_compta_client, s.client";
88 $sql .=
", s.logo, s.email, s.entity";
89 $sql .=
", c.ref, c.tms";
91 $sql .=
", c.date_commande";
92 $sql .=
", c.ref_client";
93 $sql .=
", c.fk_statut";
94 $sql .=
", c.fk_user_valid";
95 $sql .=
", c.facture";
96 $sql .=
", c.total_ht";
97 $sql .=
", c.total_tva";
98 $sql .=
", c.total_ttc";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c, ".MAIN_DB_PREFIX.
"societe as s";
100 if (!$user->hasRight(
'societe',
'client',
'voir')) {
101 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
103 $sql .=
" WHERE c.fk_soc = s.rowid";
104 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
106 $sql .=
" AND c.fk_statut = 1";
108 if (!$user->hasRight(
'societe',
'client',
'voir')) {
109 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
112 $sql .=
" AND s.rowid = ".((int) $user->socid);
115 $sql .=
" ORDER BY c.date_commande DESC, c.ref DESC ";
117 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
119 $sql .= $this->db->plimit($max, 0);
121 $result = $this->db->query($sql);
123 $num = $this->db->num_rows($result);
127 while ($line < $num) {
128 $objp = $this->db->fetch_object($result);
129 $date = $this->db->jdate($objp->date_commande);
130 $datem = $this->db->jdate($objp->tms);
132 $commandestatic->id = $objp->rowid;
133 $commandestatic->ref = $objp->ref;
134 $commandestatic->ref_client = $objp->ref_client;
135 $commandestatic->total_ht = $objp->total_ht;
136 $commandestatic->total_tva = $objp->total_tva;
137 $commandestatic->total_ttc = $objp->total_ttc;
138 $commandestatic->date = $date;
139 $commandestatic->date_modification = $datem;
141 $societestatic->id = $objp->socid;
142 $societestatic->name = $objp->name;
144 $societestatic->code_client = $objp->code_client;
145 $societestatic->code_compta = $objp->code_compta_client;
146 $societestatic->code_compta_client = $objp->code_compta_client;
147 $societestatic->client = $objp->client;
148 $societestatic->logo = $objp->logo;
149 $societestatic->email = $objp->email;
150 $societestatic->entity = $objp->entity;
152 $this->info_box_contents[$line][] = array(
153 'td' =>
'class="nowraponall"',
154 'text' => $commandestatic->getNomUrl(1),
158 $this->info_box_contents[$line][] = array(
159 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
160 'text' => $societestatic->getNomUrl(1),
164 $this->info_box_contents[$line][] = array(
165 'td' =>
'class="nowraponall right amount"',
166 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1,
$conf->currency),
170 if ($objp->fk_user_valid > 0) {
171 $userstatic->fetch($objp->fk_user_valid);
173 $this->info_box_contents[$line][] = array(
174 'td' =>
'class="right"',
175 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) :
''),
180 $this->info_box_contents[$line][] = array(
185 $this->info_box_contents[$line][] = array(
186 'td' =>
'class="right" width="18"',
187 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
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>'