dolibarr 20.0.0
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
44 public function __construct($db, $param)
45 {
46 global $user;
47
48 $this->db = $db;
49
50 $this->hidden = !($user->hasRight('fournisseur', 'commande', 'lire'));
51 }
52
59 public function loadBox($max = 5)
60 {
61 global $conf, $user, $langs;
62 $langs->loadLangs(array("boxes", "sendings", "orders"));
63
64 $this->max = $max;
65
66 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
67 $supplierorderstatic = new CommandeFournisseur($this->db);
68 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
69 $thirdpartystatic = new Fournisseur($this->db);
70
71 $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max));
72
73 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
74 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
75 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
76 $sql .= ", s.logo, s.email, s.entity";
77 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande, c.date_livraison as delivery_date";
78 $sql .= ", c.total_ht";
79 $sql .= ", c.total_tva";
80 $sql .= ", c.total_ttc";
81 $sql .= ", c.fk_statut as status";
82 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
83 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
84 if (!$user->hasRight('societe', 'client', 'voir')) {
85 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
86 }
87 $sql .= " WHERE c.fk_soc = s.rowid";
88 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
89 $sql .= " AND c.date_livraison IS NOT NULL";
90 $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
91 if (!$user->hasRight('societe', 'client', 'voir')) {
92 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
93 }
94 if ($user->socid) {
95 $sql .= " AND s.rowid = ".((int) $user->socid);
96 }
97 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
98 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC";
99 } else {
100 $sql .= " ORDER BY c.date_livraison ASC, c.fk_statut ASC";
101 }
102 $sql .= $this->db->plimit($max, 0);
103
104 $result = $this->db->query($sql);
105 if ($result) {
106 $num = $this->db->num_rows($result);
107
108 $line = 0;
109 while ($line < $num) {
110 $objp = $this->db->fetch_object($result);
111 $date = $this->db->jdate($objp->date_commande);
112 $delivery_date = $this->db->jdate($objp->delivery_date);
113 $datem = $this->db->jdate($objp->tms);
114
115 $supplierorderstatic->id = $objp->rowid;
116 $supplierorderstatic->ref = $objp->ref;
117 $supplierorderstatic->delivery_date = $delivery_date;
118 $supplierorderstatic->statut = $objp->status;
119
120 $thirdpartystatic->id = $objp->socid;
121 $thirdpartystatic->name = $objp->name;
122 //$thirdpartystatic->name_alias = $objp->name_alias;
123 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
124 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
125 $thirdpartystatic->fournisseur = $objp->fournisseur;
126 $thirdpartystatic->logo = $objp->logo;
127 $thirdpartystatic->email = $objp->email;
128 $thirdpartystatic->entity = $objp->entity;
129
130 $this->info_box_contents[$line][] = array(
131 'td' => 'class="nowraponall"',
132 'text' => $supplierorderstatic->getNomUrl(1),
133 'asis' => 1
134 );
135
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
138 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
139 'asis' => 1,
140 );
141
142 $this->info_box_contents[$line][] = array(
143 'td' => 'class="nowraponall right amount"',
144 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
145 );
146
147 $delayIcon = '';
148 if ($supplierorderstatic->hasDelay()) {
149 $delayIcon = img_warning($langs->trans("Late"));
150 }
151
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="right"',
154 '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>',
155 'asis' => 1
156 );
157
158 $line++;
159 }
160
161 if ($num == 0) {
162 $this->info_box_contents[$line][] = array(
163 'td' => 'class="center"',
164 'text' => '<span class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</span>',
165 );
166 }
167
168 $this->db->free($result);
169 } else {
170 $this->info_box_contents[0][] = array(
171 'td' => '',
172 'maxlength'=>500,
173 'text' => ($this->db->error().' sql='.$sql),
174 );
175 }
176 } else {
177 $this->info_box_contents[0][] = array(
178 'td' => 'class="nohover left"',
179 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
180 );
181 }
182 }
183
192 public function showBox($head = null, $contents = null, $nooutput = 0)
193 {
194 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
195 }
196}
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=null, $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.