dolibarr  9.0.0
box_factures.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
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  var $boxcode="lastcustomerbills";
34  var $boximg="object_bill";
35  var $boxlabel="BoxLastCustomerBills";
36  var $depends = array("facture");
37 
41  public $db;
42 
43  var $param;
44 
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->facture->lire);
62  }
63 
70  function loadBox($max=5)
71  {
72  global $conf, $user, $langs, $db;
73 
74  $this->max=$max;
75 
76  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
77  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
78 
79  $facturestatic = new Facture($db);
80  $societestatic = new Societe($db);
81 
82  $langs->load("bills");
83 
84  $text = $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."CustomerBills",$max);
85  $this->info_box_head = array(
86  'text' => $text,
87  'limit'=> dol_strlen($text)
88  );
89 
90  if ($user->rights->facture->lire) {
91  $sql = "SELECT f.rowid as facid";
92  $sql.= ", f.facnumber, f.type, f.total as total_ht";
93  $sql.= ", f.tva as total_tva";
94  $sql.= ", f.total_ttc";
95  $sql.= ", f.datef as df";
96  $sql.= ", f.paye, f.fk_statut, f.datec, f.tms";
97  $sql.= ", s.rowid as socid, s.nom as name, s.code_client, s.email, s.tva_intra, s.code_compta, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
98  $sql.= ", f.date_lim_reglement as datelimite";
99  $sql.= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
100  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
101  $sql.= ")";
102  $sql.= " WHERE f.fk_soc = s.rowid";
103  $sql.= " AND f.entity = ".$conf->entity;
104  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
105  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
106  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY f.datef DESC, f.facnumber DESC ";
107  else $sql.= " ORDER BY f.tms DESC, f.facnumber DESC ";
108  $sql.= $db->plimit($max, 0);
109 
110  $result = $db->query($sql);
111  if ($result)
112  {
113  $num = $db->num_rows($result);
114  $now=dol_now();
115 
116  $line = 0;
117  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
118 
119  while ($line < $num) {
120  $objp = $db->fetch_object($result);
121  $datelimite = $db->jdate($objp->datelimite);
122  $date = $db->jdate($objp->df);
123  $datem = $db->jdate($objp->tms);
124 
125  $facturestatic->id = $objp->facid;
126  $facturestatic->ref = $objp->facnumber;
127  $facturestatic->type = $objp->type;
128  $facturestatic->total_ht = $objp->total_ht;
129  $facturestatic->total_tva = $objp->total_tva;
130  $facturestatic->total_ttc = $objp->total_ttc;
131  $facturestatic->statut = $objp->fk_statut;
132  $facturestatic->date_lim_reglement = $db->jdate($objp->datelimite);
133 
134  $societestatic->id = $objp->socid;
135  $societestatic->name = $objp->name;
136  $societestatic->code_client = $objp->code_client;
137  $societestatic->tva_intra = $objp->tva_intra;
138  $societestatic->email = $objp->email;
139  $societestatic->idprof1 = $objp->idprof1;
140  $societestatic->idprof2 = $objp->idprof2;
141  $societestatic->idprof3 = $objp->idprof3;
142  $societestatic->idprof4 = $objp->idprof4;
143  $societestatic->idprof5 = $objp->idprof5;
144  $societestatic->idprof6 = $objp->idprof6;
145 
146  $late = '';
147  if ($facturestatic->hasDelay()) {
148  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite,'day')));
149  }
150 
151  $this->info_box_contents[$line][] = array(
152  'td' => '',
153  'text' => $facturestatic->getNomUrl(1),
154  'text2'=> $late,
155  'asis' => 1,
156  );
157 
158  $this->info_box_contents[$line][] = array(
159  'td' => '',
160  'text' => $societestatic->getNomUrl(1, '', 40),
161  'asis' => 1,
162  );
163 
164  $this->info_box_contents[$line][] = array(
165  'td' => 'class="right"',
166  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
167  );
168 
169  $this->info_box_contents[$line][] = array(
170  'td' => 'class="right"',
171  'text' => dol_print_date($date,'day'),
172  );
173 
174  $this->info_box_contents[$line][] = array(
175  'td' => 'align="right" width="18"',
176  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3),
177  );
178 
179  $line++;
180  }
181 
182  if ($num==0)
183  $this->info_box_contents[$line][0] = array(
184  'td' => 'align="center"',
185  'text'=>$langs->trans("NoRecordedInvoices"),
186  );
187 
188  $db->free($result);
189  } else {
190  $this->info_box_contents[0][0] = array(
191  'td' => '',
192  'maxlength'=>500,
193  'text' => ($db->error().' sql='.$sql),
194  );
195  }
196  } else {
197  $this->info_box_contents[0][0] = array(
198  'td' => 'align="left" class="nohover opacitymedium"',
199  'text' => $langs->trans("ReadPermissionNotAllowed")
200  );
201  }
202  }
203 
212  function showBox($head = null, $contents = null, $nooutput=0)
213  {
214  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
215  }
216 }
img_warning($titlealt='default', $moreatt='')
Show warning logo.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_now($mode='gmt')
Return date for now.
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).
Class to manage the box to show last invoices.
Class to manage invoices.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.