dolibarr  17.0.4
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 = empty($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  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
91  $sql .= ", s.code_client, s.client";
92  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
93  $sql .= ", spe.accountancy_code_customer as code_compta";
94  } else {
95  $sql .= ", s.code_compta";
96  }
97  $sql .= ", s.logo, s.email, s.entity";
98  $sql .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
99  $sql .= ", f.ref, f.date_lim_reglement as datelimite";
100  $sql .= ", f.type";
101  $sql .= ", f.datef as date";
102  $sql .= ", f.total_ht";
103  $sql .= ", f.total_tva";
104  $sql .= ", f.total_ttc";
105  $sql .= ", f.paye, f.fk_statut as status, f.rowid as facid";
106  $sql .= ", sum(pf.amount) as am";
107  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
108  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
109  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
110  }
111  if (empty($user->rights->societe->client->voir) && !$user->socid) {
112  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
113  }
114  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
115  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
116  $sql .= " WHERE f.fk_soc = s.rowid";
117  $sql .= " AND f.entity IN (".getEntity('invoice').")";
118  $sql .= " AND f.paye = 0";
119  $sql .= " AND fk_statut = 1";
120  if (empty($user->rights->societe->client->voir) && !$user->socid) {
121  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
122  }
123  if ($user->socid) {
124  $sql .= " AND s.rowid = ".((int) $user->socid);
125  }
126  $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
127  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
128  $sql .= " spe.accountancy_code_customer as code_compta,";
129  } else {
130  $sql .= " s.code_compta,";
131  }
132  $sql .= " f.ref, f.date_lim_reglement,";
133  $sql .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.rowid";
134  //$sql.= " ORDER BY f.datef DESC, f.ref DESC ";
135  $sql .= " ORDER BY datelimite ASC, f.ref ASC ";
136  $sql .= $this->db->plimit($max, 0);
137 
138  $result = $this->db->query($sql);
139  if ($result) {
140  $num = $this->db->num_rows($result);
141  $now = dol_now();
142 
143  $line = 0;
144  $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
145 
146  while ($line < $num) {
147  $objp = $this->db->fetch_object($result);
148 
149  $datelimite = $this->db->jdate($objp->datelimite);
150 
151  $facturestatic->id = $objp->facid;
152  $facturestatic->ref = $objp->ref;
153  $facturestatic->type = $objp->type;
154  $facturestatic->total_ht = $objp->total_ht;
155  $facturestatic->total_tva = $objp->total_tva;
156  $facturestatic->total_ttc = $objp->total_ttc;
157  $facturestatic->statut = $objp->status;
158  $facturestatic->status = $objp->status;
159  $facturestatic->date = $this->db->jdate($objp->date);
160  $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
161  $facturestatic->alreadypaid = $objp->paye;
162 
163  $societestatic->id = $objp->socid;
164  $societestatic->name = $objp->name;
165  //$societestatic->name_alias = $objp->name_alias;
166  $societestatic->code_client = $objp->code_client;
167  $societestatic->code_compta = $objp->code_compta;
168  $societestatic->client = $objp->client;
169  $societestatic->logo = $objp->logo;
170  $societestatic->email = $objp->email;
171  $societestatic->entity = $objp->entity;
172  $societestatic->tva_intra = $objp->tva_intra;
173  $societestatic->idprof1 = $objp->idprof1;
174  $societestatic->idprof2 = $objp->idprof2;
175  $societestatic->idprof3 = $objp->idprof3;
176  $societestatic->idprof4 = $objp->idprof4;
177  $societestatic->idprof5 = $objp->idprof5;
178  $societestatic->idprof6 = $objp->idprof6;
179 
180  $late = '';
181  if ($facturestatic->hasDelay()) {
182  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
183  }
184 
185  $this->info_box_contents[$line][] = array(
186  'td' => 'class="nowraponall"',
187  'text' => $facturestatic->getNomUrl(1),
188  'text2'=> $late,
189  'asis' => 1,
190  );
191 
192  $this->info_box_contents[$line][] = array(
193  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
194  'text' => $societestatic->getNomUrl(1, '', 44),
195  'asis' => 1,
196  );
197 
198  $this->info_box_contents[$line][] = array(
199  'td' => 'class="nowraponall right amount"',
200  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
201  );
202 
203  $this->info_box_contents[$line][] = array(
204  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
205  'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
206  );
207 
208  $this->info_box_contents[$line][] = array(
209  'td' => 'class="right" width="18"',
210  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
211  );
212 
213  $line++;
214  }
215 
216  if ($num == 0) {
217  $this->info_box_contents[$line][0] = array(
218  'td' => 'class="center opacitymedium"',
219  'text'=>$langs->trans("NoUnpaidCustomerBills")
220  );
221  }
222 
223  $this->db->free($result);
224  } else {
225  $this->info_box_contents[0][0] = array(
226  'td' => '',
227  'maxlength'=>500,
228  'text' => ($this->db->error().' sql='.$sql),
229  );
230  }
231  } else {
232  $this->info_box_contents[0][0] = array(
233  'td' => 'class="nohover opacitymedium left"',
234  'text' => $langs->trans("ReadPermissionNotAllowed")
235  );
236  }
237  }
238 
247  public function showBox($head = null, $contents = null, $nooutput = 0)
248  {
249  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
250  }
251 }
Class to manage invoices.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last invoices.
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.
__construct($db, $param)
Constructor.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
$conf db
API class for accounts.
Definition: inc.php:41