dolibarr  9.0.0
box_factures_imp.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2007 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 
27 require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
29 
30 
35 {
36  var $boxcode="oldestunpaidcustomerbills";
37  var $boximg="object_bill";
38  var $boxlabel="BoxOldestUnpaidCustomerBills";
39  var $depends = array("facture");
40 
44  public $db;
45 
46  var $param;
47 
48  var $info_box_head = array();
49  var $info_box_contents = array();
50 
51 
58  function __construct($db,$param)
59  {
60  global $user;
61 
62  $this->db=$db;
63 
64  $this->hidden=! ($user->rights->facture->lire);
65  }
66 
73  function loadBox($max=5)
74  {
75  global $conf, $user, $langs, $db;
76 
77  $this->max=$max;
78 
79  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
80  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
81 
82  $facturestatic = new Facture($db);
83  $societestatic = new Societe($db);
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidCustomerBills",$max));
86 
87  if ($user->rights->facture->lire)
88  {
89  $sql = "SELECT s.nom as name, s.rowid as socid, s.email,";
90  $sql.= " s.code_client,";
91  $sql.= " s.logo,";
92  $sql.= " f.facnumber, f.date_lim_reglement as datelimite,";
93  $sql.= " f.type,";
94  $sql.= " f.amount, f.datef as df,";
95  $sql.= " f.total as total_ht,";
96  $sql.= " f.tva as total_tva,";
97  $sql.= " f.total_ttc,";
98  $sql.= " f.paye, f.fk_statut, f.rowid as facid";
99  $sql.= ", sum(pf.amount) as am";
100  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
101  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
102  $sql.= ", ".MAIN_DB_PREFIX."facture as f";
103  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
104  $sql.= " WHERE f.fk_soc = s.rowid";
105  $sql.= " AND f.entity = ".$conf->entity;
106  $sql.= " AND f.paye = 0";
107  $sql.= " AND fk_statut = 1";
108  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
109  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
110  $sql.= " GROUP BY s.nom, s.rowid, s.code_client, s.logo, f.facnumber, f.date_lim_reglement,";
111  $sql.= " f.type, f.amount, f.datef, f.total, f.tva, f.total_ttc, f.paye, f.fk_statut, f.rowid";
112  //$sql.= " ORDER BY f.datef DESC, f.facnumber DESC ";
113  $sql.= " ORDER BY datelimite ASC, f.facnumber ASC ";
114  $sql.= $db->plimit($max, 0);
115 
116  $result = $db->query($sql);
117  if ($result)
118  {
119  $num = $db->num_rows($result);
120  $now=dol_now();
121 
122  $line = 0;
123  $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
124 
125  while ($line < $num)
126  {
127  $objp = $db->fetch_object($result);
128  $datelimite=$db->jdate($objp->datelimite);
129  $facturestatic->id = $objp->facid;
130  $facturestatic->ref = $objp->facnumber;
131  $facturestatic->type = $objp->type;
132  $facturestatic->total_ht = $objp->total_ht;
133  $facturestatic->total_tva = $objp->total_tva;
134  $facturestatic->total_ttc = $objp->total_ttc;
135  $facturestatic->statut = $objp->fk_statut;
136  $facturestatic->date_lim_reglement = $db->jdate($objp->datelimite);
137 
138  $societestatic->id = $objp->socid;
139  $societestatic->name = $objp->name;
140  $societestatic->client = 1;
141  $societestatic->email = $objp->email;
142  $societestatic->code_client = $objp->code_client;
143  $societestatic->logo = $objp->logo;
144 
145  $late='';
146  if ($facturestatic->hasDelay()) {
147  $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day')));
148  }
149 
150  $this->info_box_contents[$line][] = array(
151  'td' => '',
152  'text' => $facturestatic->getNomUrl(1),
153  'text2'=> $late,
154  'asis' => 1,
155  );
156 
157  $this->info_box_contents[$line][] = array(
158  'td' => '',
159  'text' => $societestatic->getNomUrl(1, '', 44),
160  'asis' => 1,
161  );
162 
163  $this->info_box_contents[$line][] = array(
164  'td' => 'class="right"',
165  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
166  );
167 
168  $this->info_box_contents[$line][] = array(
169  'td' => 'class="right"',
170  'text' => dol_print_date($datelimite,'day'),
171  );
172 
173  $this->info_box_contents[$line][] = array(
174  'td' => 'align="right" width="18"',
175  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3,$objp->am),
176  );
177 
178  $line++;
179  }
180 
181  if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoUnpaidCustomerBills"));
182 
183  $db->free($result);
184  }
185  else
186  {
187  $this->info_box_contents[0][0] = array(
188  'td' => '',
189  'maxlength'=>500,
190  'text' => ($db->error().' sql='.$sql),
191  );
192  }
193  }
194  else {
195  $this->info_box_contents[0][0] = array(
196  'td' => 'align="left" class="nohover opacitymedium"',
197  'text' => $langs->trans("ReadPermissionNotAllowed")
198  );
199  }
200  }
201 
210  function showBox($head = null, $contents = null, $nooutput=0)
211  {
212  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
213  }
214 }
img_warning($titlealt='default', $moreatt='')
Show warning logo.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
__construct($db, $param)
Constructor.
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.
dol_now($mode='gmt')
Return date for now.
Class to manage the box to show last invoices.
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 invoices.