dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
33{
34 public $boxcode = "supplierordersawaitingreception";
35 public $boximg = "object_order";
36 public $boxlabel = "BoxLatestSupplierOrdersAwaitingReception";
37 public $depends = array("fournisseur");
38
45 public function __construct($db, $param)
46 {
47 global $user;
48
49 $this->db = $db;
50
51 $this->hidden = !($user->hasRight('fournisseur', 'commande', 'lire'));
52 }
53
60 public function loadBox($max = 5)
61 {
62 global $conf, $user, $langs;
63 $langs->loadLangs(array("boxes", "sendings", "orders"));
64
65 $this->max = $max;
66
67 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
68 $supplierorderstatic = new CommandeFournisseur($this->db);
69 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
70 $thirdpartystatic = new Fournisseur($this->db);
71
72 $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max));
73
74 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
75 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
76 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
77 $sql .= ", s.logo, s.email, s.entity";
78 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande, c.date_livraison as delivery_date";
79 $sql .= ", c.total_ht";
80 $sql .= ", c.total_tva";
81 $sql .= ", c.total_ttc";
82 $sql .= ", c.fk_statut as status";
83 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
84 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
85 if (!$user->hasRight('societe', 'client', 'voir')) {
86 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
87 }
88 $sql .= " WHERE c.fk_soc = s.rowid";
89 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
90 $sql .= " AND c.date_livraison IS NOT NULL";
91 $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
92 if (!$user->hasRight('societe', 'client', 'voir')) {
93 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
94 }
95 if ($user->socid) {
96 $sql .= " AND s.rowid = ".((int) $user->socid);
97 }
98 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
99 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC";
100 } else {
101 $sql .= " ORDER BY c.date_livraison ASC, c.fk_statut ASC";
102 }
103 $sql .= $this->db->plimit($max, 0);
104
105 $result = $this->db->query($sql);
106 if ($result) {
107 $num = $this->db->num_rows($result);
108
109 $line = 0;
110 while ($line < $num) {
111 $objp = $this->db->fetch_object($result);
112 $date = $this->db->jdate($objp->date_commande);
113 $delivery_date = $this->db->jdate($objp->delivery_date);
114 $datem = $this->db->jdate($objp->tms);
115
116 $supplierorderstatic->id = $objp->rowid;
117 $supplierorderstatic->ref = $objp->ref;
118 $supplierorderstatic->delivery_date = $delivery_date;
119 $supplierorderstatic->statut = $objp->status;
120
121 $thirdpartystatic->id = $objp->socid;
122 $thirdpartystatic->name = $objp->name;
123 //$thirdpartystatic->name_alias = $objp->name_alias;
124 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
125 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
126 $thirdpartystatic->fournisseur = $objp->fournisseur;
127 $thirdpartystatic->logo = $objp->logo;
128 $thirdpartystatic->email = $objp->email;
129 $thirdpartystatic->entity = $objp->entity;
130
131 $this->info_box_contents[$line][] = array(
132 'td' => 'class="nowraponall"',
133 'text' => $supplierorderstatic->getNomUrl(1),
134 'asis' => 1
135 );
136
137 $this->info_box_contents[$line][] = array(
138 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
139 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
140 'asis' => 1,
141 );
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="nowraponall right amount"',
145 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
146 );
147
148 $delayIcon = '';
149 if ($supplierorderstatic->hasDelay()) {
150 $delayIcon = img_warning($langs->trans("Late"));
151 }
152
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="right"',
155 '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>',
156 'asis' => 1
157 );
158
159 $line++;
160 }
161
162 if ($num == 0) {
163 $this->info_box_contents[$line][] = array(
164 'td' => 'class="center"',
165 'text' => '<span class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</span>',
166 );
167 }
168
169 $this->db->free($result);
170 } else {
171 $this->info_box_contents[0][] = array(
172 'td' => '',
173 'maxlength' => 500,
174 'text' => ($this->db->error().' sql='.$sql),
175 );
176 }
177 } else {
178 $this->info_box_contents[0][] = array(
179 'td' => 'class="nohover left"',
180 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
181 );
182 }
183 }
184
185
186
195 public function showBox($head = null, $contents = null, $nooutput = 0)
196 {
197 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
198 }
199}
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 a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79