dolibarr 18.0.6
box_supplier_orders_awaiting_reception.php
1<?php
2/* Copyright (C) 2004-2006 Destailleur Laurent <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2012 Raphaƫl Doursenaud <rdoursenaud@gpcsolutions.fr>
5 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27
32{
33
34 public $boxcode = "supplierordersawaitingreception";
35 public $boximg = "object_order";
36 public $boxlabel = "BoxLatestSupplierOrdersAwaitingReception";
37 public $depends = array("fournisseur");
38
42 public $db;
43
44 public $param;
45 public $info_box_head = array();
46 public $info_box_contents = array();
47
48
55 public function __construct($db, $param)
56 {
57 global $user;
58
59 $this->db = $db;
60
61 $this->hidden = !($user->hasRight('fournisseur', 'commande', 'lire'));
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $conf, $user, $langs;
73 $langs->loadLangs(array("boxes", "sendings", "orders"));
74
75 $this->max = $max;
76
77 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
78 $supplierorderstatic = new CommandeFournisseur($this->db);
79 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
80 $thirdpartystatic = new Fournisseur($this->db);
81
82 $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max));
83
84 if ($user->rights->fournisseur->commande->lire) {
85 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
86 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
87 $sql .= ", s.logo, s.email, s.entity";
88 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande, c.date_livraison as delivery_date";
89 $sql .= ", c.total_ht";
90 $sql .= ", c.total_tva";
91 $sql .= ", c.total_ttc";
92 $sql .= ", c.fk_statut as status";
93 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
94 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
95 if (empty($user->rights->societe->client->voir) && !$user->socid) {
96 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97 }
98 $sql .= " WHERE c.fk_soc = s.rowid";
99 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
100 $sql .= " AND c.date_livraison IS NOT NULL";
101 $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
102 if (empty($user->rights->societe->client->voir) && !$user->socid) {
103 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
104 }
105 if ($user->socid) {
106 $sql .= " AND s.rowid = ".((int) $user->socid);
107 }
108 if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
109 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC";
110 } else {
111 $sql .= " ORDER BY c.date_livraison ASC, c.fk_statut ASC";
112 }
113 $sql .= $this->db->plimit($max, 0);
114
115 $result = $this->db->query($sql);
116 if ($result) {
117 $num = $this->db->num_rows($result);
118
119 $line = 0;
120 while ($line < $num) {
121 $objp = $this->db->fetch_object($result);
122 $date = $this->db->jdate($objp->date_commande);
123 $delivery_date = $this->db->jdate($objp->delivery_date);
124 $datem = $this->db->jdate($objp->tms);
125
126 $supplierorderstatic->id = $objp->rowid;
127 $supplierorderstatic->ref = $objp->ref;
128 $supplierorderstatic->delivery_date = $delivery_date;
129 $supplierorderstatic->statut = $objp->status;
130
131 $thirdpartystatic->id = $objp->socid;
132 $thirdpartystatic->name = $objp->name;
133 //$thirdpartystatic->name_alias = $objp->name_alias;
134 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
135 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
136 $thirdpartystatic->fournisseur = $objp->fournisseur;
137 $thirdpartystatic->logo = $objp->logo;
138 $thirdpartystatic->email = $objp->email;
139 $thirdpartystatic->entity = $objp->entity;
140
141 $this->info_box_contents[$line][] = array(
142 'td' => 'class="nowraponall"',
143 'text' => $supplierorderstatic->getNomUrl(1),
144 'asis' => 1
145 );
146
147 $this->info_box_contents[$line][] = array(
148 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
149 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
150 'asis' => 1,
151 );
152
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="nowraponall right amount"',
155 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
156 );
157
158 $delayIcon = '';
159 if ($supplierorderstatic->hasDelay()) {
160 $delayIcon = img_warning($langs->trans("Late"));
161 }
162
163 $this->info_box_contents[$line][] = array(
164 'td' => 'class="right"',
165 'text' => $delayIcon.'<span class="classfortooltip" title="'.$langs->trans('DateDeliveryPlanned').'"><i class="fa fa-flip-dolly" ></i> '.($delivery_date ? dol_print_date($delivery_date, 'day', 'tzuserrel') : '').'</span>',
166 'asis' => 1
167 );
168
169 $line++;
170 }
171
172 if ($num == 0) {
173 $this->info_box_contents[$line][] = array(
174 'td' => 'class="center"',
175 'text' => '<span class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</span>',
176 );
177 }
178
179 $this->db->free($result);
180 } else {
181 $this->info_box_contents[0][] = array(
182 'td' => '',
183 'maxlength'=>500,
184 'text' => ($this->db->error().' sql='.$sql),
185 );
186 }
187 } else {
188 $this->info_box_contents[0][] = array(
189 'td' => 'class="nohover opacitymedium left"',
190 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
191 );
192 }
193 }
194
203 public function showBox($head = null, $contents = null, $nooutput = 0)
204 {
205 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
206 }
207}
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
Class to manage suppliers.
Class ModeleBoxes.
Class that manages the box showing latest supplier orders.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).