dolibarr  13.0.2
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-2019 Frederic France <frederic.france@netlogic.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 <https://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  public $boxcode = "oldestunpaidcustomerbills";
37  public $boximg = "object_bill";
38  public $boxlabel = "BoxOldestUnpaidCustomerBills";
39  public $depends = array("facture");
40 
44  public $db;
45 
46  public $param;
47 
48  public $info_box_head = array();
49  public $info_box_contents = array();
50 
51 
58  public function __construct($db, $param)
59  {
60  global $user;
61 
62  $this->db = $db;
63 
64  $this->hidden = !($user->rights->facture->lire);
65  }
66 
73  public function loadBox($max = 5)
74  {
75  global $conf, $user, $langs;
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($this->db);
83  $societestatic = new Societe($this->db);
84 
85  $langs->load("bills");
86 
87  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidCustomerBills", $max));
88 
89  if ($user->rights->facture->lire)
90  {
91  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
92  $sql .= ", s.code_client, s.code_compta, s.client";
93  $sql .= ", s.logo, s.email, s.entity";
94  $sql .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
95  $sql .= ", f.ref, f.date_lim_reglement as datelimite";
96  $sql .= ", f.type";
97  $sql .= ", f.datef as df";
98  $sql .= ", f.total as total_ht";
99  $sql .= ", f.tva as total_tva";
100  $sql .= ", f.total_ttc";
101  $sql .= ", f.paye, f.fk_statut as status, f.rowid as facid";
102  $sql .= ", sum(pf.amount) as am";
103  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
104  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
105  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
106  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
107  $sql .= " WHERE f.fk_soc = s.rowid";
108  $sql .= " AND f.entity IN (".getEntity('invoice').")";
109  $sql .= " AND f.paye = 0";
110  $sql .= " AND fk_statut = 1";
111  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
112  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
113  $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
114  $sql .= " f.ref, f.date_lim_reglement,";
115  $sql .= " f.type, f.datef, f.total, f.tva, f.total_ttc, f.paye, f.fk_statut, f.rowid";
116  //$sql.= " ORDER BY f.datef DESC, f.ref DESC ";
117  $sql .= " ORDER BY datelimite ASC, f.ref ASC ";
118  $sql .= $this->db->plimit($max, 0);
119 
120  $result = $this->db->query($sql);
121  if ($result)
122  {
123  $num = $this->db->num_rows($result);
124  $now = dol_now();
125 
126  $line = 0;
127  $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
128 
129  while ($line < $num)
130  {
131  $objp = $this->db->fetch_object($result);
132  $datelimite = $this->db->jdate($objp->datelimite);
133  $facturestatic->id = $objp->facid;
134  $facturestatic->ref = $objp->ref;
135  $facturestatic->type = $objp->type;
136  $facturestatic->total_ht = $objp->total_ht;
137  $facturestatic->total_tva = $objp->total_tva;
138  $facturestatic->total_ttc = $objp->total_ttc;
139  $facturestatic->statut = $objp->status;
140  $facturestatic->status = $objp->status;
141  $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
142  $facturestatic->alreadypaid = $objp->paye;
143 
144  $societestatic->id = $objp->socid;
145  $societestatic->name = $objp->name;
146  //$societestatic->name_alias = $objp->name_alias;
147  $societestatic->code_client = $objp->code_client;
148  $societestatic->code_compta = $objp->code_compta;
149  $societestatic->client = $objp->client;
150  $societestatic->logo = $objp->logo;
151  $societestatic->email = $objp->email;
152  $societestatic->entity = $objp->entity;
153  $societestatic->tva_intra = $objp->tva_intra;
154  $societestatic->idprof1 = $objp->idprof1;
155  $societestatic->idprof2 = $objp->idprof2;
156  $societestatic->idprof3 = $objp->idprof3;
157  $societestatic->idprof4 = $objp->idprof4;
158  $societestatic->idprof5 = $objp->idprof5;
159  $societestatic->idprof6 = $objp->idprof6;
160 
161  $late = '';
162  if ($facturestatic->hasDelay()) {
163  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day')));
164  }
165 
166  $this->info_box_contents[$line][] = array(
167  'td' => 'class="nowraponall"',
168  'text' => $facturestatic->getNomUrl(1),
169  'text2'=> $late,
170  'asis' => 1,
171  );
172 
173  $this->info_box_contents[$line][] = array(
174  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
175  'text' => $societestatic->getNomUrl(1, '', 44),
176  'asis' => 1,
177  );
178 
179  $this->info_box_contents[$line][] = array(
180  'td' => 'class="nowraponall right"',
181  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
182  );
183 
184  $this->info_box_contents[$line][] = array(
185  'td' => 'class="right"',
186  'text' => dol_print_date($datelimite, 'day'),
187  );
188 
189  $this->info_box_contents[$line][] = array(
190  'td' => 'class="right" width="18"',
191  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
192  );
193 
194  $line++;
195  }
196 
197  if ($num == 0) $this->info_box_contents[$line][0] = array(
198  'td' => 'class="center opacitymedium"',
199  'text'=>$langs->trans("NoUnpaidCustomerBills")
200  );
201 
202  $this->db->free($result);
203  } else {
204  $this->info_box_contents[0][0] = array(
205  'td' => '',
206  'maxlength'=>500,
207  'text' => ($this->db->error().' sql='.$sql),
208  );
209  }
210  } else {
211  $this->info_box_contents[0][0] = array(
212  'td' => 'class="nohover opacitymedium left"',
213  'text' => $langs->trans("ReadPermissionNotAllowed")
214  );
215  }
216  }
217 
226  public function showBox($head = null, $contents = null, $nooutput = 0)
227  {
228  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
229  }
230 }
dol_now($mode= 'auto')
Return date for now.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
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.
Class to manage the box to show last invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage invoices.