dolibarr 20.0.0
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
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->load("boxes");
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 $text = $langs->trans("BoxTitleLatest".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."SupplierOrders", $max);
72 $this->info_box_head = array(
73 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?sortfield=cf.tms&sortorder=DESC"><span class="badge">...</span></a>'
74 );
75
76 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
77 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
78 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
79 $sql .= ", s.logo, s.email, s.entity";
80 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande";
81 $sql .= ", c.total_ht";
82 $sql .= ", c.total_tva";
83 $sql .= ", c.total_ttc";
84 $sql .= ", c.fk_statut as status";
85 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
86 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
87 if (!$user->hasRight('societe', 'client', 'voir')) {
88 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
89 }
90 $sql .= " WHERE c.fk_soc = s.rowid";
91 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
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.tms DESC, c.ref DESC ";
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 $datem = $this->db->jdate($objp->tms);
114
115 $supplierorderstatic->id = $objp->rowid;
116 $supplierorderstatic->ref = $objp->ref;
117 $supplierorderstatic->statut = $objp->status;
118 $supplierorderstatic->status = $objp->status;
119 $supplierorderstatic->date = $date;
120 $supplierorderstatic->date_modification = $datem;
121
122 $thirdpartystatic->id = $objp->socid;
123 $thirdpartystatic->name = $objp->name;
124 //$thirdpartystatic->name_alias = $objp->name_alias;
125 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
126 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
127 $thirdpartystatic->fournisseur = $objp->fournisseur;
128 $thirdpartystatic->logo = $objp->logo;
129 $thirdpartystatic->email = $objp->email;
130 $thirdpartystatic->entity = $objp->entity;
131
132 $this->info_box_contents[$line][] = array(
133 'td' => 'class="nowraponall"',
134 'text' => $supplierorderstatic->getNomUrl(1),
135 'asis' => 1
136 );
137
138 $this->info_box_contents[$line][] = array(
139 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
140 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
141 'asis' => 1,
142 );
143
144 $this->info_box_contents[$line][] = array(
145 'td' => 'class="nowraponall right amount"',
146 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
147 );
148
149 $this->info_box_contents[$line][] = array(
150 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
151 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
152 );
153
154 $this->info_box_contents[$line][] = array(
155 'td' => 'class="right" width="18"',
156 'text' => $supplierorderstatic->LibStatut($objp->status, 3),
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
193 public function showBox($head = null, $contents = null, $nooutput = 0)
194 {
195 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
196 }
197}
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=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.
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...