dolibarr  9.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 Frederic France <frederic.france@free.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 <http://www.gnu.org/licenses/>.
19  */
20 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
32 {
33 
34  var $boxcode = "latestsupplierorders";
35  var $boximg = "object_order";
36  var $boxlabel="BoxLatestSupplierOrders";
37  var $depends = array("fournisseur");
38 
42  public $db;
43 
44  var $param;
45  var $info_box_head = array();
46  var $info_box_contents = array();
47 
48 
55  function __construct($db,$param)
56  {
57  global $user;
58 
59  $this->db=$db;
60 
61  $this->hidden=! ($user->rights->fournisseur->commande->lire);
62  }
63 
70  function loadBox($max = 5)
71  {
72  global $conf, $user, $langs, $db;
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($db);
79  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
80  $thirdpartytmp = new Fournisseur($db);
81 
82  $this->info_box_head = array('text' => $langs->trans("BoxTitleLatest".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."SupplierOrders", $max));
83 
84  if ($user->rights->fournisseur->commande->lire)
85  {
86  $sql = "SELECT s.nom as name, s.rowid as socid,";
87  $sql.= " s.code_client, s.code_fournisseur,";
88  $sql.= " s.logo,";
89  $sql.= " c.rowid, c.ref, c.tms, c.date_commande,";
90  $sql.= " c.total_ht,";
91  $sql.= " c.tva as total_tva,";
92  $sql.= " c.total_ttc,";
93  $sql.= " c.fk_statut";
94  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
95  $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
96  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97  $sql.= " WHERE c.fk_soc = s.rowid";
98  $sql.= " AND c.entity = ".$conf->entity;
99  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
100  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
101  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY c.date_commande DESC, c.ref DESC ";
102  else $sql.= " ORDER BY c.tms DESC, c.ref DESC ";
103  $sql.= $db->plimit($max, 0);
104 
105  $result = $db->query($sql);
106  if ($result)
107  {
108  $num = $db->num_rows($result);
109 
110  $line = 0;
111  while ($line < $num) {
112  $objp = $db->fetch_object($result);
113  $date=$db->jdate($objp->date_commande);
114  $datem=$db->jdate($objp->tms);
115 
116  $supplierorderstatic->id = $objp->rowid;
117  $supplierorderstatic->ref = $objp->ref;
118 
119  $thirdpartytmp->id = $objp->socid;
120  $thirdpartytmp->name = $objp->name;
121  $thirdpartytmp->fournisseur = 1;
122  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
123  $thirdpartytmp->logo = $objp->logo;
124 
125  $this->info_box_contents[$line][] = array(
126  'td' => '',
127  'text' => $supplierorderstatic->getNomUrl(1),
128  'asis' => 1
129  );
130 
131  $this->info_box_contents[$line][] = array(
132  'td' => '',
133  'text' => $thirdpartytmp->getNomUrl(1, 'supplier'),
134  'asis' => 1,
135  );
136 
137  $this->info_box_contents[$line][] = array(
138  'td' => 'class="right"',
139  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
140  );
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => 'class="right"',
144  'text' => dol_print_date($date,'day'),
145  );
146 
147  $this->info_box_contents[$line][] = array(
148  'td' => 'align="right" width="18"',
149  'text' => $supplierorderstatic->LibStatut($objp->fk_statut,3),
150  );
151 
152  $line++;
153  }
154 
155  if ($num == 0)
156  $this->info_box_contents[$line][] = array(
157  'td' => 'align="center"',
158  'text' => $langs->trans("NoSupplierOrder"),
159  );
160 
161  $db->free($result);
162  } else {
163  $this->info_box_contents[0][] = array(
164  'td' => '',
165  'maxlength'=>500,
166  'text' => ($db->error().' sql='.$sql),
167  );
168  }
169  }
170  else
171  {
172  $this->info_box_contents[0][] = array(
173  'td' => 'align="left" class="nohover opacitymedium"',
174  'text' => $langs->trans("ReadPermissionNotAllowed")
175  );
176  }
177  }
178 
187  function showBox($head = null, $contents = null, $nooutput=0)
188  {
189  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
190  }
191 }
192 
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
Class that manages the box showing latest supplier orders.
Class ModeleBoxes.
Class to manage suppliers.
Class to manage predefined suppliers products.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
loadBox($max=5)
Load data into info_box_contents array to show array later.