dolibarr 21.0.0-alpha
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 * 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 = "latestsupplierorders";
35 public $boximg = "object_order";
36 public $boxlabel = "BoxLatestSupplierOrders";
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->load("boxes");
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 $text = $langs->trans("BoxTitleLatest".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."SupplierOrders", $max);
73 $this->info_box_head = array(
74 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?sortfield=cf.tms&sortorder=DESC"><span class="badge">...</span></a>'
75 );
76
77 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
78 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
79 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
80 $sql .= ", s.logo, s.email, s.entity";
81 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande";
82 $sql .= ", c.total_ht";
83 $sql .= ", c.total_tva";
84 $sql .= ", c.total_ttc";
85 $sql .= ", c.fk_statut as status";
86 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
87 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
88 if (!$user->hasRight('societe', 'client', 'voir')) {
89 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
90 }
91 $sql .= " WHERE c.fk_soc = s.rowid";
92 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95 }
96 if ($user->socid) {
97 $sql .= " AND s.rowid = ".((int) $user->socid);
98 }
99 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
100 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
101 } else {
102 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
103 }
104 $sql .= $this->db->plimit($max, 0);
105
106 $result = $this->db->query($sql);
107 if ($result) {
108 $num = $this->db->num_rows($result);
109
110 $line = 0;
111 while ($line < $num) {
112 $objp = $this->db->fetch_object($result);
113 $date = $this->db->jdate($objp->date_commande);
114 $datem = $this->db->jdate($objp->tms);
115
116 $supplierorderstatic->id = $objp->rowid;
117 $supplierorderstatic->ref = $objp->ref;
118 $supplierorderstatic->statut = $objp->status;
119 $supplierorderstatic->status = $objp->status;
120 $supplierorderstatic->date = $date;
121 $supplierorderstatic->date_modification = $datem;
122
123 $thirdpartystatic->id = $objp->socid;
124 $thirdpartystatic->name = $objp->name;
125 //$thirdpartystatic->name_alias = $objp->name_alias;
126 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
127 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
128 $thirdpartystatic->fournisseur = $objp->fournisseur;
129 $thirdpartystatic->logo = $objp->logo;
130 $thirdpartystatic->email = $objp->email;
131 $thirdpartystatic->entity = $objp->entity;
132
133 $this->info_box_contents[$line][] = array(
134 'td' => 'class="nowraponall"',
135 'text' => $supplierorderstatic->getNomUrl(1),
136 'asis' => 1
137 );
138
139 $this->info_box_contents[$line][] = array(
140 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
141 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
142 'asis' => 1,
143 );
144
145 $this->info_box_contents[$line][] = array(
146 'td' => 'class="nowraponall right amount"',
147 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
148 );
149
150 $this->info_box_contents[$line][] = array(
151 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
152 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
153 );
154
155 $this->info_box_contents[$line][] = array(
156 'td' => 'class="right" width="18"',
157 'text' => $supplierorderstatic->LibStatut($objp->status, 3),
158 );
159
160 $line++;
161 }
162
163 if ($num == 0) {
164 $this->info_box_contents[$line][] = array(
165 'td' => 'class="center"',
166 'text' => '<span class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</span>',
167 );
168 }
169
170 $this->db->free($result);
171 } else {
172 $this->info_box_contents[0][] = array(
173 'td' => '',
174 'maxlength' => 500,
175 'text' => ($this->db->error().' sql='.$sql),
176 );
177 }
178 } else {
179 $this->info_box_contents[0][] = array(
180 'td' => 'class="nohover left"',
181 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
182 );
183 }
184 }
185
186
187
196 public function showBox($head = null, $contents = null, $nooutput = 0)
197 {
198 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
199 }
200}
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 a 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...