74 global $user, $langs, $conf;
75 $langs->loadLangs(array(
'orders',
'sendings'));
79 include_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
80 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
81 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
84 $orderstatic =
new Commande($this->db);
85 $societestatic =
new Societe($this->db);
87 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleLastCustomerShipments", $max));
89 if ($user->hasRight(
'expedition',
'lire')) {
90 $sql =
"SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .=
", s.code_client, s.code_compta, s.client";
92 $sql .=
", s.logo, s.email, s.entity";
93 $sql .=
", e.ref, e.tms";
95 $sql .=
", e.ref_customer";
96 $sql .=
", e.fk_statut";
97 $sql .=
", e.fk_user_valid";
98 $sql .=
", c.ref as commande_ref";
99 $sql .=
", c.rowid as commande_id";
100 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
101 $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')";
102 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
103 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = e.fk_soc";
104 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
105 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
107 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
109 $sql .=
" AND e.fk_statut = 1";
111 if ($user->socid > 0) {
112 $sql.=
" AND s.rowid = ".((int) $user->socid);
114 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
115 $sql .=
" AND sc.fk_user = ".((int) $user->id);
117 $sql .=
" ORDER BY e.date_delivery, e.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);
130 $shipmentstatic->id = $objp->rowid;
131 $shipmentstatic->ref = $objp->ref;
132 $shipmentstatic->ref_customer = $objp->ref_customer;
134 $orderstatic->id = $objp->commande_id;
135 $orderstatic->ref = $objp->commande_ref;
137 $societestatic->id = $objp->socid;
138 $societestatic->name = $objp->name;
140 $societestatic->code_client = $objp->code_client;
141 $societestatic->code_compta = $objp->code_compta;
142 $societestatic->client = $objp->client;
143 $societestatic->logo = $objp->logo;
144 $societestatic->email = $objp->email;
145 $societestatic->entity = $objp->entity;
147 $this->info_box_contents[$line][] = array(
148 'td' =>
'class="nowraponall"',
149 'text' => $shipmentstatic->getNomUrl(1),
153 $this->info_box_contents[$line][] = array(
154 'td' =>
'class="tdoverflowmax150 maxwidth150onsmartphone"',
155 'text' => $societestatic->getNomUrl(1),
159 $this->info_box_contents[$line][] = array(
160 'td' =>
'class="nowraponall"',
161 'text' => $orderstatic->getNomUrl(1),
165 $this->info_box_contents[$line][] = array(
166 'td' =>
'class="right" width="18"',
167 'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
174 $this->info_box_contents[$line][0] = array(
175 'td' =>
'class="center"',
176 'text'=>
'<span class="opacitymedium">'.$langs->trans(
"NoRecordedShipments").
'</span>'
180 $this->db->free($result);
182 $this->info_box_contents[0][0] = array(
185 'text' => ($this->db->error().
' sql='.$sql),
189 $this->info_box_contents[0][0] = array(
190 'td' =>
'class="nohover left"',
191 'text' =>
'<span class="opacitymedium">'.$langs->trans(
"ReadPermissionNotAllowed").
'</span>'