dolibarr 19.0.4
box_supplier_orders.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-2019 Frederic France <frederic.france@netlogic.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 = "latestsupplierorders";
34 public $boximg = "object_order";
35 public $boxlabel = "BoxLatestSupplierOrders";
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->load("boxes");
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("BoxTitleLatest".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."SupplierOrders", $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";
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 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
100 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
101 }
102 if ($user->socid) {
103 $sql .= " AND s.rowid = ".((int) $user->socid);
104 }
105 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
106 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
107 } else {
108 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
109 }
110 $sql .= $this->db->plimit($max, 0);
111
112 $result = $this->db->query($sql);
113 if ($result) {
114 $num = $this->db->num_rows($result);
115
116 $line = 0;
117 while ($line < $num) {
118 $objp = $this->db->fetch_object($result);
119 $date = $this->db->jdate($objp->date_commande);
120 $datem = $this->db->jdate($objp->tms);
121
122 $supplierorderstatic->id = $objp->rowid;
123 $supplierorderstatic->ref = $objp->ref;
124 $supplierorderstatic->statut = $objp->status;
125 $supplierorderstatic->status = $objp->status;
126 $supplierorderstatic->date = $date;
127 $supplierorderstatic->date_modification = $datem;
128
129 $thirdpartystatic->id = $objp->socid;
130 $thirdpartystatic->name = $objp->name;
131 //$thirdpartystatic->name_alias = $objp->name_alias;
132 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
133 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
134 $thirdpartystatic->fournisseur = $objp->fournisseur;
135 $thirdpartystatic->logo = $objp->logo;
136 $thirdpartystatic->email = $objp->email;
137 $thirdpartystatic->entity = $objp->entity;
138
139 $this->info_box_contents[$line][] = array(
140 'td' => 'class="nowraponall"',
141 'text' => $supplierorderstatic->getNomUrl(1),
142 'asis' => 1
143 );
144
145 $this->info_box_contents[$line][] = array(
146 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
147 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
148 'asis' => 1,
149 );
150
151 $this->info_box_contents[$line][] = array(
152 'td' => 'class="nowraponall right amount"',
153 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
154 );
155
156 $this->info_box_contents[$line][] = array(
157 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
158 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
159 );
160
161 $this->info_box_contents[$line][] = array(
162 'td' => 'class="right" width="18"',
163 'text' => $supplierorderstatic->LibStatut($objp->status, 3),
164 );
165
166 $line++;
167 }
168
169 if ($num == 0) {
170 $this->info_box_contents[$line][] = array(
171 'td' => 'class="center"',
172 'text' => '<span class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</span>',
173 );
174 }
175
176 $this->db->free($result);
177 } else {
178 $this->info_box_contents[0][] = array(
179 'td' => '',
180 'maxlength'=>500,
181 'text' => ($this->db->error().' sql='.$sql),
182 );
183 }
184 } else {
185 $this->info_box_contents[0][] = array(
186 'td' => 'class="nohover left"',
187 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
188 );
189 }
190 }
191
200 public function showBox($head = null, $contents = null, $nooutput = 0)
201 {
202 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
203 }
204}
Class to manage predefined suppliers products.
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.
__construct($db, $param)
Constructor.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...