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';
82 $commandestatic =
new Commande($this->db);
83 $societestatic =
new Societe($this->db);
84 $userstatic =
new User($this->db);
86 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLast".(getDolGlobalString(
'MAIN_LASTBOX_ON_OBJECT_DATE') ?
"" :
"Modified").
"CustomerOrders", $max));
88 if ($user->hasRight(
'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.
"commande as c, ".MAIN_DB_PREFIX.
"societe as s";
103 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
104 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
106 $sql .=
" WHERE c.fk_soc = s.rowid";
107 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
109 $sql .=
" AND c.fk_statut = 1";
111 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
112 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
115 $sql .=
" AND s.rowid = ".((int) $user->socid);
118 $sql .=
" ORDER BY c.date_commande DESC, c.ref DESC ";
120 $sql .=
" ORDER BY c.tms DESC, c.ref DESC ";
122 $sql .= $this->db->plimit($max, 0);
124 $result = $this->db->query($sql);
126 $num = $this->db->num_rows($result);
130 while ($line < $num) {
131 $objp = $this->db->fetch_object($result);
132 $date = $this->db->jdate($objp->date_commande);
133 $datem = $this->db->jdate($objp->tms);
135 $commandestatic->id = $objp->rowid;
136 $commandestatic->ref = $objp->ref;
137 $commandestatic->ref_client = $objp->ref_client;
138 $commandestatic->total_ht = $objp->total_ht;
139 $commandestatic->total_tva = $objp->total_tva;
140 $commandestatic->total_ttc = $objp->total_ttc;
141 $commandestatic->date = $date;
142 $commandestatic->date_modification = $datem;
144 $societestatic->id = $objp->socid;
145 $societestatic->name = $objp->name;
147 $societestatic->code_client = $objp->code_client;
148 $societestatic->code_compta = $objp->code_compta;
149 $societestatic->client = $objp->client;
150 $societestatic->logo = $objp->logo;
151 $societestatic->email = $objp->email;
152 $societestatic->entity = $objp->entity;
154 $this->info_box_contents[$line][] = array(
155 'td' =>
'class="nowraponall"',
156 'text' => $commandestatic->getNomUrl(1),
160 $this->info_box_contents[$line][] = array(
161 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
162 'text' => $societestatic->getNomUrl(1),
166 $this->info_box_contents[$line][] = array(
167 'td' =>
'class="nowraponall right amount"',
168 'text' =>
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
172 if ($objp->fk_user_valid > 0) {
173 $userstatic->fetch($objp->fk_user_valid);
175 $this->info_box_contents[$line][] = array(
176 'td' =>
'class="right"',
177 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) :
''),
182 $this->info_box_contents[$line][] = array(
187 $this->info_box_contents[$line][] = array(
188 'td' =>
'class="right" width="18"',
189 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
196 $this->info_box_contents[$line][0] = array(
197 'td' =>
'class="center"',
198 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedOrders").
'</span>'
202 $this->db->free($result);
204 $this->info_box_contents[0][0] = array(
207 'text' => ($this->db->error().
' sql='.$sql),
211 $this->info_box_contents[0][0] = array(
212 'td' =>
'class="nohover left"',
213 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'