dolibarr  7.0.0-beta
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@capnetworks.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 
38  var $db;
39  var $param;
40 
41  var $info_box_head = array();
42  var $info_box_contents = array();
43 
44 
51  function __construct($db,$param)
52  {
53  global $user;
54 
55  $this->db=$db;
56 
57  $this->hidden=! ($user->rights->facture->lire);
58  }
59 
66  function loadBox($max=5)
67  {
68  global $conf, $user, $langs, $db;
69 
70  $this->max=$max;
71 
72  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
73  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
74 
75  $facturestatic=new Facture($db);
76  $societestatic = new Societe($db);
77 
78  $text = $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."CustomerBills",$max);
79  $this->info_box_head = array(
80  'text' => $text,
81  'limit'=> dol_strlen($text)
82  );
83 
84  if ($user->rights->facture->lire) {
85  $sql = "SELECT f.rowid as facid";
86  $sql.= ", f.facnumber, f.type, f.total as total_ht";
87  $sql.= ", f.tva as total_tva";
88  $sql.= ", f.total_ttc";
89  $sql.= ", f.datef as df";
90  $sql.= ", f.paye, f.fk_statut, f.datec, f.tms";
91  $sql.= ", s.nom as name";
92  $sql.= ", s.rowid as socid";
93  $sql.= ", s.code_client";
94  $sql.= ", f.date_lim_reglement as datelimite";
95  $sql.= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
96  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97  $sql.= ")";
98  $sql.= " WHERE f.fk_soc = s.rowid";
99  $sql.= " AND f.entity = ".$conf->entity;
100  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
101  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
102  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY f.datef DESC, f.facnumber DESC ";
103  else $sql.= " ORDER BY f.tms DESC, f.facnumber DESC ";
104  $sql.= $db->plimit($max, 0);
105 
106  $result = $db->query($sql);
107  if ($result)
108  {
109  $num = $db->num_rows($result);
110  $now=dol_now();
111 
112  $line = 0;
113  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
114 
115  while ($line < $num) {
116  $objp = $db->fetch_object($result);
117  $datelimite = $db->jdate($objp->datelimite);
118  $date = $db->jdate($objp->df);
119  $datem = $db->jdate($objp->tms);
120  $facturestatic->id = $objp->facid;
121  $facturestatic->ref = $objp->facnumber;
122  $facturestatic->type = $objp->type;
123  $facturestatic->total_ht = $objp->total_ht;
124  $facturestatic->total_tva = $objp->total_tva;
125  $facturestatic->total_ttc = $objp->total_ttc;
126  $facturestatic->statut = $objp->fk_statut;
127  $facturestatic->date_lim_reglement = $db->jdate($objp->datelimite);
128 
129  $societestatic->id = $objp->socid;
130  $societestatic->name = $objp->name;
131  $societestatic->code_client = $objp->code_client;
132 
133 
134  $late = '';
135  if ($facturestatic->hasDelay()) {
136  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite,'day')));
137  }
138 
139  $this->info_box_contents[$line][] = array(
140  'td' => '',
141  'text' => $facturestatic->getNomUrl(1),
142  'text2'=> $late,
143  'asis' => 1,
144  );
145 
146  $this->info_box_contents[$line][] = array(
147  'td' => '',
148  'text' => $societestatic->getNomUrl(1, '', 40),
149  'asis' => 1,
150  );
151 
152  $this->info_box_contents[$line][] = array(
153  'td' => 'class="right"',
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="right"',
159  'text' => dol_print_date($date,'day'),
160  );
161 
162  $this->info_box_contents[$line][] = array(
163  'td' => 'align="right" width="18"',
164  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3),
165  );
166 
167  $line++;
168  }
169 
170  if ($num==0)
171  $this->info_box_contents[$line][0] = array(
172  'td' => 'align="center"',
173  'text'=>$langs->trans("NoRecordedInvoices"),
174  );
175 
176  $db->free($result);
177  } else {
178  $this->info_box_contents[0][0] = array(
179  'td' => '',
180  'maxlength'=>500,
181  'text' => ($db->error().' sql='.$sql),
182  );
183  }
184 
185  } else {
186  $this->info_box_contents[0][0] = array(
187  'td' => 'align="left" class="nohover opacitymedium"',
188  'text' => $langs->trans("ReadPermissionNotAllowed")
189  );
190  }
191  }
192 
201  function showBox($head = null, $contents = null, $nooutput=0)
202  {
203  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
204  }
205 
206 }
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...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
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.