dolibarr 19.0.3
box_supplier_orders_awaiting_reception.php
Go to the documentation of this file.
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 public $boxcode = "supplierordersawaitingreception";
34 public $boximg = "object_order";
35 public $boxlabel = "BoxLatestSupplierOrdersAwaitingReception";
36 public $depends = array("fournisseur");
37
41 public $db;
42
43 public $param;
44 public $info_box_head = array();
45 public $info_box_contents = array();
46
47
54 public function __construct($db, $param)
55 {
56 global $user;
57
58 $this->db = $db;
59
60 $this->hidden = !($user->hasRight('fournisseur', 'commande', 'lire'));
61 }
62
69 public function loadBox($max = 5)
70 {
71 global $conf, $user, $langs;
72 $langs->loadLangs(array("boxes", "sendings", "orders"));
73
74 $this->max = $max;
75
76 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
77 $supplierorderstatic = new CommandeFournisseur($this->db);
78 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
79 $thirdpartystatic = new Fournisseur($this->db);
80
81 $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max));
82
83 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
84 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
85 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
86 $sql .= ", s.logo, s.email, s.entity";
87 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande, c.date_livraison as delivery_date";
88 $sql .= ", c.total_ht";
89 $sql .= ", c.total_tva";
90 $sql .= ", c.total_ttc";
91 $sql .= ", c.fk_statut as status";
92 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
94 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
95 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
96 }
97 $sql .= " WHERE c.fk_soc = s.rowid";
98 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
99 $sql .= " AND c.date_livraison IS NOT NULL";
100 $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
101 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
102 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
103 }
104 if ($user->socid) {
105 $sql .= " AND s.rowid = ".((int) $user->socid);
106 }
107 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
108 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC";
109 } else {
110 $sql .= " ORDER BY c.date_livraison ASC, c.fk_statut ASC";
111 }
112 $sql .= $this->db->plimit($max, 0);
113
114 $result = $this->db->query($sql);
115 if ($result) {
116 $num = $this->db->num_rows($result);
117
118 $line = 0;
119 while ($line < $num) {
120 $objp = $this->db->fetch_object($result);
121 $date = $this->db->jdate($objp->date_commande);
122 $delivery_date = $this->db->jdate($objp->delivery_date);
123 $datem = $this->db->jdate($objp->tms);
124
125 $supplierorderstatic->id = $objp->rowid;
126 $supplierorderstatic->ref = $objp->ref;
127 $supplierorderstatic->delivery_date = $delivery_date;
128 $supplierorderstatic->statut = $objp->status;
129
130 $thirdpartystatic->id = $objp->socid;
131 $thirdpartystatic->name = $objp->name;
132 //$thirdpartystatic->name_alias = $objp->name_alias;
133 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
134 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
135 $thirdpartystatic->fournisseur = $objp->fournisseur;
136 $thirdpartystatic->logo = $objp->logo;
137 $thirdpartystatic->email = $objp->email;
138 $thirdpartystatic->entity = $objp->entity;
139
140 $this->info_box_contents[$line][] = array(
141 'td' => 'class="nowraponall"',
142 'text' => $supplierorderstatic->getNomUrl(1),
143 'asis' => 1
144 );
145
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
148 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
149 'asis' => 1,
150 );
151
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="nowraponall right amount"',
154 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
155 );
156
157 $delayIcon = '';
158 if ($supplierorderstatic->hasDelay()) {
159 $delayIcon = img_warning($langs->trans("Late"));
160 }
161
162 $this->info_box_contents[$line][] = array(
163 'td' => 'class="right"',
164 '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>',
165 'asis' => 1
166 );
167
168 $line++;
169 }
170
171 if ($num == 0) {
172 $this->info_box_contents[$line][] = array(
173 'td' => 'class="center"',
174 'text' => '<span class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</span>',
175 );
176 }
177
178 $this->db->free($result);
179 } else {
180 $this->info_box_contents[0][] = array(
181 'td' => '',
182 'maxlength'=>500,
183 'text' => ($this->db->error().' sql='.$sql),
184 );
185 }
186 } else {
187 $this->info_box_contents[0][] = array(
188 'td' => 'class="nohover left"',
189 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
190 );
191 }
192 }
193
202 public function showBox($head = null, $contents = null, $nooutput = 0)
203 {
204 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
205 }
206}
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
Class to manage suppliers.
Class ModeleBoxes.
Class to manage the box to show last supplier orders awaiting reception.
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).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.