dolibarr  19.0.0-dev
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 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
32 {
33 
34  public $boxcode = "latestsupplierorders";
35  public $boximg = "object_order";
36  public $boxlabel = "BoxLatestSupplierOrders";
37  public $depends = array("fournisseur");
38 
42  public $db;
43 
44  public $param;
45  public $info_box_head = array();
46  public $info_box_contents = array();
47 
48 
55  public function __construct($db, $param)
56  {
57  global $user;
58 
59  $this->db = $db;
60 
61  $this->hidden = !($user->hasRight('fournisseur', 'commande', 'lire'));
62  }
63 
70  public function loadBox($max = 5)
71  {
72  global $conf, $user, $langs;
73  $langs->load("boxes");
74 
75  $this->max = $max;
76 
77  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
78  $supplierorderstatic = new CommandeFournisseur($this->db);
79  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
80  $thirdpartystatic = new Fournisseur($this->db);
81 
82  $this->info_box_head = array('text' => $langs->trans("BoxTitleLatest".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."SupplierOrders", $max));
83 
84  if ($user->rights->fournisseur->commande->lire) {
85  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
86  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
87  $sql .= ", s.logo, s.email, s.entity";
88  $sql .= ", c.rowid, c.ref, c.tms, c.date_commande";
89  $sql .= ", c.total_ht";
90  $sql .= ", c.total_tva";
91  $sql .= ", c.total_ttc";
92  $sql .= ", c.fk_statut as status";
93  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
94  $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
95  if (empty($user->rights->societe->client->voir) && !$user->socid) {
96  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97  }
98  $sql .= " WHERE c.fk_soc = s.rowid";
99  $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
100  if (empty($user->rights->societe->client->voir) && !$user->socid) {
101  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
102  }
103  if ($user->socid) {
104  $sql .= " AND s.rowid = ".((int) $user->socid);
105  }
106  if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
107  $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
108  } else {
109  $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
110  }
111  $sql .= $this->db->plimit($max, 0);
112 
113  $result = $this->db->query($sql);
114  if ($result) {
115  $num = $this->db->num_rows($result);
116 
117  $line = 0;
118  while ($line < $num) {
119  $objp = $this->db->fetch_object($result);
120  $date = $this->db->jdate($objp->date_commande);
121  $datem = $this->db->jdate($objp->tms);
122 
123  $supplierorderstatic->id = $objp->rowid;
124  $supplierorderstatic->ref = $objp->ref;
125  $supplierorderstatic->statut = $objp->status;
126  $supplierorderstatic->status = $objp->status;
127  $supplierorderstatic->date = $date;
128  $supplierorderstatic->date_modification = $datem;
129 
130  $thirdpartystatic->id = $objp->socid;
131  $thirdpartystatic->name = $objp->name;
132  //$thirdpartystatic->name_alias = $objp->name_alias;
133  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
134  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
135  $thirdpartystatic->fournisseur = $objp->fournisseur;
136  $thirdpartystatic->logo = $objp->logo;
137  $thirdpartystatic->email = $objp->email;
138  $thirdpartystatic->entity = $objp->entity;
139 
140  $this->info_box_contents[$line][] = array(
141  'td' => 'class="nowraponall"',
142  'text' => $supplierorderstatic->getNomUrl(1),
143  'asis' => 1
144  );
145 
146  $this->info_box_contents[$line][] = array(
147  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
148  'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
149  'asis' => 1,
150  );
151 
152  $this->info_box_contents[$line][] = array(
153  'td' => 'class="nowraponall right amount"',
154  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
155  );
156 
157  $this->info_box_contents[$line][] = array(
158  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
159  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
160  );
161 
162  $this->info_box_contents[$line][] = array(
163  'td' => 'class="right" width="18"',
164  'text' => $supplierorderstatic->LibStatut($objp->status, 3),
165  );
166 
167  $line++;
168  }
169 
170  if ($num == 0) {
171  $this->info_box_contents[$line][] = array(
172  'td' => 'class="center"',
173  'text' => $langs->trans("NoSupplierOrder"),
174  );
175  }
176 
177  $this->db->free($result);
178  } else {
179  $this->info_box_contents[0][] = array(
180  'td' => '',
181  'maxlength'=>500,
182  'text' => ($this->db->error().' sql='.$sql),
183  );
184  }
185  } else {
186  $this->info_box_contents[0][] = array(
187  'td' => 'class="nohover left"',
188  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
189  );
190  }
191  }
192 
201  public function showBox($head = null, $contents = null, $nooutput = 0)
202  {
203  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
204  }
205 }
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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).
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...