dolibarr 21.0.0-beta
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 $this->urltoaddentry = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
54 $this->msgNoRecords = 'NoSupplierOrder';
55 }
56
63 public function loadBox($max = 5)
64 {
65 global $conf, $user, $langs;
66 $langs->load("boxes");
67
68 $this->max = $max;
69
70 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
71 $supplierorderstatic = new CommandeFournisseur($this->db);
72 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
73 $thirdpartystatic = new Fournisseur($this->db);
74
75 $text = $langs->trans("BoxTitleLatest".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."SupplierOrders", $max);
76 $this->info_box_head = array(
77 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?sortfield=cf.tms&sortorder=DESC"><span class="badge">...</span></a>'
78 );
79
80 if ($user->hasRight('fournisseur', 'commande', 'lire')) {
81 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
82 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
83 $sql .= ", s.logo, s.email, s.entity";
84 $sql .= ", c.rowid, c.ref, c.tms, c.date_commande";
85 $sql .= ", c.total_ht";
86 $sql .= ", c.total_tva";
87 $sql .= ", c.total_ttc";
88 $sql .= ", c.fk_statut as status";
89 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
90 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
91 if (!$user->hasRight('societe', 'client', 'voir')) {
92 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
93 }
94 $sql .= " WHERE c.fk_soc = s.rowid";
95 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
96 if (!$user->hasRight('societe', 'client', 'voir')) {
97 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
98 }
99 if ($user->socid) {
100 $sql .= " AND s.rowid = ".((int) $user->socid);
101 }
102 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
103 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
104 } else {
105 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
106 }
107 $sql .= $this->db->plimit($max, 0);
108
109 $result = $this->db->query($sql);
110 if ($result) {
111 $num = $this->db->num_rows($result);
112
113 $line = 0;
114 while ($line < $num) {
115 $objp = $this->db->fetch_object($result);
116 $date = $this->db->jdate($objp->date_commande);
117 $datem = $this->db->jdate($objp->tms);
118
119 $supplierorderstatic->id = $objp->rowid;
120 $supplierorderstatic->ref = $objp->ref;
121 $supplierorderstatic->statut = $objp->status;
122 $supplierorderstatic->status = $objp->status;
123 $supplierorderstatic->date = $date;
124 $supplierorderstatic->date_modification = $datem;
125
126 $thirdpartystatic->id = $objp->socid;
127 $thirdpartystatic->name = $objp->name;
128 //$thirdpartystatic->name_alias = $objp->name_alias;
129 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
130 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
131 $thirdpartystatic->fournisseur = $objp->fournisseur;
132 $thirdpartystatic->logo = $objp->logo;
133 $thirdpartystatic->email = $objp->email;
134 $thirdpartystatic->entity = $objp->entity;
135
136 $this->info_box_contents[$line][] = array(
137 'td' => 'class="nowraponall"',
138 'text' => $supplierorderstatic->getNomUrl(1),
139 'asis' => 1
140 );
141
142 $this->info_box_contents[$line][] = array(
143 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
144 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
145 'asis' => 1,
146 );
147
148 $this->info_box_contents[$line][] = array(
149 'td' => 'class="nowraponall right amount"',
150 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
151 );
152
153 $this->info_box_contents[$line][] = array(
154 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
155 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
156 );
157
158 $this->info_box_contents[$line][] = array(
159 'td' => 'class="right" width="18"',
160 'text' => $supplierorderstatic->LibStatut($objp->status, 3),
161 );
162
163 $line++;
164 }
165
166 $this->db->free($result);
167 } else {
168 $this->info_box_contents[0][] = array(
169 'td' => '',
170 'maxlength' => 500,
171 'text' => ($this->db->error().' sql='.$sql),
172 );
173 }
174 } else {
175 $this->info_box_contents[0][] = array(
176 'td' => 'class="nohover left"',
177 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
178 );
179 }
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79