dolibarr  7.0.0-beta
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@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 
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 
41  var $db;
42  var $param;
43 
44  var $info_box_head = array();
45  var $info_box_contents = array();
46 
47 
54  function __construct($db,$param)
55  {
56  global $user;
57 
58  $this->db=$db;
59 
60  $this->hidden=! ($user->rights->facture->lire);
61  }
62 
69  function loadBox($max=5)
70  {
71  global $conf, $user, $langs, $db;
72 
73  $this->max=$max;
74 
75  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
76  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
77 
78  $facturestatic = new Facture($db);
79  $societestatic = new Societe($db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidCustomerBills",$max));
82 
83  if ($user->rights->facture->lire)
84  {
85  $sql = "SELECT s.nom as name, s.rowid as socid,";
86  $sql.= " s.code_client,";
87  $sql.= " s.logo,";
88  $sql.= " f.facnumber, f.date_lim_reglement as datelimite,";
89  $sql.= " f.type,";
90  $sql.= " f.amount, f.datef as df,";
91  $sql.= " f.total as total_ht,";
92  $sql.= " f.tva as total_tva,";
93  $sql.= " f.total_ttc,";
94  $sql.= " f.paye, f.fk_statut, f.rowid as facid";
95  $sql.= ", sum(pf.amount) as am";
96  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
97  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98  $sql.= ", ".MAIN_DB_PREFIX."facture as f";
99  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
100  $sql.= " WHERE f.fk_soc = s.rowid";
101  $sql.= " AND f.entity = ".$conf->entity;
102  $sql.= " AND f.paye = 0";
103  $sql.= " AND fk_statut = 1";
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  $sql.= " GROUP BY s.nom, s.rowid, s.code_client, s.logo, f.facnumber, f.date_lim_reglement,";
107  $sql.= " f.type, f.amount, f.datef, f.total, f.tva, f.total_ttc, f.paye, f.fk_statut, f.rowid";
108  //$sql.= " ORDER BY f.datef DESC, f.facnumber DESC ";
109  $sql.= " ORDER BY datelimite ASC, f.facnumber ASC ";
110  $sql.= $db->plimit($max, 0);
111 
112  $result = $db->query($sql);
113  if ($result)
114  {
115  $num = $db->num_rows($result);
116  $now=dol_now();
117 
118  $line = 0;
119  $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
120 
121  while ($line < $num)
122  {
123  $objp = $db->fetch_object($result);
124  $datelimite=$db->jdate($objp->datelimite);
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  $societestatic->id = $objp->socid;
134  $societestatic->name = $objp->name;
135  $societestatic->client = 1;
136  $societestatic->code_client = $objp->code_client;
137  $societestatic->logo = $objp->logo;
138 
139  $late='';
140  if ($facturestatic->hasDelay()) {
141  $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day')));
142  }
143 
144  $this->info_box_contents[$line][] = array(
145  'td' => '',
146  'text' => $facturestatic->getNomUrl(1),
147  'text2'=> $late,
148  'asis' => 1,
149  );
150 
151  $this->info_box_contents[$line][] = array(
152  'td' => '',
153  'text' => $societestatic->getNomUrl(1, '', 44),
154  'asis' => 1,
155  );
156 
157  $this->info_box_contents[$line][] = array(
158  'td' => 'class="right"',
159  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
160  );
161 
162  $this->info_box_contents[$line][] = array(
163  'td' => 'class="right"',
164  'text' => dol_print_date($datelimite,'day'),
165  );
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'align="right" width="18"',
169  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3,$objp->am),
170  );
171 
172  $line++;
173  }
174 
175  if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoUnpaidCustomerBills"));
176 
177  $db->free($result);
178  }
179  else
180  {
181  $this->info_box_contents[0][0] = array(
182  'td' => '',
183  'maxlength'=>500,
184  'text' => ($db->error().' sql='.$sql),
185  );
186  }
187  }
188  else {
189  $this->info_box_contents[0][0] = array(
190  'td' => 'align="left" class="nohover opacitymedium"',
191  'text' => $langs->trans("ReadPermissionNotAllowed")
192  );
193  }
194  }
195 
204  function showBox($head = null, $contents = null, $nooutput=0)
205  {
206  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
207  }
208 
209 }
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
__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.