68 $langs->loadLangs(array(
'orders',
'sendings'));
72 include_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
73 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
74 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
77 $orderstatic =
new Commande($this->db);
78 $societestatic =
new Societe($this->db);
80 $this->info_box_head = array(
81 'text' => $langs->trans(
"BoxTitleLastCustomerShipments", $max).
'<a class="paddingleft" href="'.DOL_URL_ROOT.
'/expedition/list.php?sortfield=e.tms&sortorder=DESC"><span class="badge">...</span></a>'
84 if ($user->hasRight(
'expedition',
'lire')) {
85 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
86 $sql .=
", s.code_client, s.code_compta, s.client";
87 $sql .=
", s.logo, s.email, s.entity";
88 $sql .=
", e.ref, e.tms";
90 $sql .=
", e.ref_customer";
91 $sql .=
", e.fk_statut";
92 $sql .=
", e.fk_user_valid";
93 $sql .=
", c.ref as commande_ref";
94 $sql .=
", c.rowid as commande_id";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
96 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
97 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
98 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = e.fk_soc";
99 if (!$user->hasRight(
'societe',
'client',
'voir')) {
100 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
102 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
104 $sql .=
" AND e.fk_statut = 1";
106 if ($user->socid > 0) {
107 $sql .=
" AND s.rowid = ".((int) $user->socid);
109 if (!$user->hasRight(
'societe',
'client',
'voir')) {
110 $sql .=
" AND sc.fk_user = ".((int) $user->id);
112 $sql .=
" ORDER BY e.tms DESC, e.date_delivery DESC, e.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);
125 $shipmentstatic->id = $objp->rowid;
126 $shipmentstatic->ref = $objp->ref;
127 $shipmentstatic->ref_customer = $objp->ref_customer;
129 $orderstatic->id = $objp->commande_id;
130 $orderstatic->ref = $objp->commande_ref;
132 $societestatic->id = $objp->socid;
133 $societestatic->name = $objp->name;
135 $societestatic->code_client = $objp->code_client;
136 $societestatic->code_compta = $objp->code_compta;
137 $societestatic->code_compta_client = $objp->code_compta;
138 $societestatic->client = $objp->client;
139 $societestatic->logo = $objp->logo;
140 $societestatic->email = $objp->email;
141 $societestatic->entity = $objp->entity;
143 $this->info_box_contents[$line][] = array(
144 'td' =>
'class="nowraponall"',
145 'text' => $shipmentstatic->getNomUrl(1),
149 $this->info_box_contents[$line][] = array(
150 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
151 'text' => $societestatic->getNomUrl(1),
155 $this->info_box_contents[$line][] = array(
156 'td' =>
'class="nowraponall"',
157 'text' => ($orderstatic->id > 0 ? $orderstatic->getNomUrl(1) :
''),
161 $this->info_box_contents[$line][] = array(
162 'td' =>
'class="right" width="18"',
163 'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
176 $this->db->free($result);
178 $this->info_box_contents[0][0] = array(
181 'text' => ($this->db->error().
' sql='.$sql),
185 $this->info_box_contents[0][0] = array(
186 'td' =>
'class="nohover left"',
187 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'