dolibarr  7.0.0-beta
box_supplier_orders.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (C) 2004-2006 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2012 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
6  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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 <http://www.gnu.org/licenses/>.
20  */
21 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
33 {
34 
35  var $boxcode = "latestsupplierorders";
36  var $boximg = "object_order";
37  var $boxlabel="BoxLatestSupplierOrders";
38  var $depends = array("fournisseur");
39 
40  var $db;
41  var $param;
42  var $info_box_head = array();
43  var $info_box_contents = array();
44 
45 
52  function __construct($db,$param)
53  {
54  global $user;
55 
56  $this->db=$db;
57 
58  $this->hidden=! ($user->rights->fournisseur->commande->lire);
59  }
60 
67  function loadBox($max = 5)
68  {
69  global $conf, $user, $langs, $db;
70  $langs->load("boxes");
71 
72  $this->max = $max;
73 
74  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
75  $supplierorderstatic=new CommandeFournisseur($db);
76  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
77  $thirdpartytmp = new Fournisseur($db);
78 
79  $this->info_box_head = array('text' => $langs->trans("BoxTitleLatest".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."SupplierOrders", $max));
80 
81  if ($user->rights->fournisseur->commande->lire)
82  {
83  $sql = "SELECT s.nom as name, s.rowid as socid,";
84  $sql.= " s.code_client, s.code_fournisseur,";
85  $sql.= " s.logo,";
86  $sql.= " c.ref, c.tms, c.rowid, c.date_commande,";
87  $sql.= " c.total_ht,";
88  $sql.= " c.tva as total_tva,";
89  $sql.= " c.total_ttc,";
90  $sql.= " c.fk_statut";
91  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
92  $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
93  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94  $sql.= " WHERE c.fk_soc = s.rowid";
95  $sql.= " AND c.entity = ".$conf->entity;
96  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
97  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
98  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY c.date_commande DESC, c.ref DESC ";
99  else $sql.= " ORDER BY c.tms DESC, c.ref DESC ";
100  $sql.= $db->plimit($max, 0);
101 
102  $result = $db->query($sql);
103  if ($result)
104  {
105  $num = $db->num_rows($result);
106 
107  $line = 0;
108  while ($line < $num) {
109  $objp = $db->fetch_object($result);
110  $date=$db->jdate($objp->date_commande);
111  $datem=$db->jdate($objp->tms);
112 
113  $supplierorderstatic->id = $objp->id;
114  $supplierorderstatic->ref = $objp->ref;
115 
116  $thirdpartytmp->id = $objp->socid;
117  $thirdpartytmp->name = $objp->name;
118  $thirdpartytmp->fournisseur = 1;
119  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
120  $thirdpartytmp->logo = $objp->logo;
121 
122  $this->info_box_contents[$line][] = array(
123  'td' => '',
124  'text' => $supplierorderstatic->getNomUrl(1),
125  'asis' => 1
126  );
127 
128  $this->info_box_contents[$line][] = array(
129  'td' => '',
130  'text' => $thirdpartytmp->getNomUrl(1, 'supplier'),
131  'asis' => 1,
132  );
133 
134  $this->info_box_contents[$line][] = array(
135  'td' => 'class="right"',
136  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
137  );
138 
139  $this->info_box_contents[$line][] = array(
140  'td' => 'class="right"',
141  'text' => dol_print_date($date,'day'),
142  );
143 
144  $this->info_box_contents[$line][] = array(
145  'td' => 'align="right" width="18"',
146  'text' => $supplierorderstatic->LibStatut($objp->fk_statut,3),
147  );
148 
149  $line++;
150  }
151 
152  if ($num == 0)
153  $this->info_box_contents[$line][] = array(
154  'td' => 'align="center"',
155  'text' => $langs->trans("NoSupplierOrder"),
156  );
157 
158  $db->free($result);
159  } else {
160  $this->info_box_contents[0][] = array(
161  'td' => '',
162  'maxlength'=>500,
163  'text' => ($db->error().' sql='.$sql),
164  );
165  }
166  }
167  else
168  {
169  $this->info_box_contents[0][] = array(
170  'td' => 'align="left" class="nohover opacitymedium"',
171  'text' => $langs->trans("ReadPermissionNotAllowed")
172  );
173  }
174  }
175 
184  function showBox($head = null, $contents = null, $nooutput=0)
185  {
186  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
187  }
188 
189 }
190 
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.