dolibarr  20.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@inodbox.com>
5  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
6  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
33 {
34  public $boxcode = "lastcustomerbills";
35  public $boximg = "object_bill";
36  public $boxlabel = "BoxLastCustomerBills";
37  public $depends = array("facture");
38 
45  public function __construct($db, $param)
46  {
47  global $user;
48 
49  $this->db = $db;
50 
51  $this->hidden = !$user->hasRight('facture', 'lire');
52  }
53 
60  public function loadBox($max = 5)
61  {
62  global $conf, $user, $langs;
63 
64  $this->max = $max;
65 
66  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
67  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
68 
69  $facturestatic = new Facture($this->db);
70  $societestatic = new Societe($this->db);
71 
72  $langs->load("bills");
73 
74  $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."CustomerBills", $max);
75  $this->info_box_head = array(
76  'text' => $text,
77  'limit' => dol_strlen($text)
78  );
79 
80  if ($user->hasRight('facture', 'lire')) {
81  $sql = "SELECT f.rowid as facid";
82  $sql .= ", f.ref, f.type, f.total_ht";
83  $sql .= ", f.total_tva";
84  $sql .= ", f.total_ttc";
85  $sql .= ", f.datef as date";
86  $sql .= ", f.paye, f.fk_statut as status, f.datec, f.tms";
87  $sql .= ", f.date_lim_reglement as datelimite";
88  $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
89  $sql .= ", s.code_client, s.code_compta, s.client";
90  $sql .= ", s.logo, s.email, s.entity";
91  $sql .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
92  $sql .= ", SUM(pf.amount) as am";
93  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
94  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture,";
95  $sql .= " ".MAIN_DB_PREFIX."societe as s";
96  if (!$user->hasRight('societe', 'client', 'voir')) {
97  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98  }
99  $sql .= " WHERE f.fk_soc = s.rowid";
100  $sql .= " AND f.entity IN (".getEntity('invoice').")";
101  if (!$user->hasRight('societe', 'client', 'voir')) {
102  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
103  }
104  if ($user->socid) {
105  $sql .= " AND s.rowid = ".((int) $user->socid);
106  }
107  $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,";
108  $sql .= " f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datef, f.paye, f.fk_statut, f.datec, f.tms, f.date_lim_reglement";
109  if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
110  $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
111  } else {
112  $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
113  }
114  $sql .= $this->db->plimit($max, 0);
115 
116  $result = $this->db->query($sql);
117  if ($result) {
118  $num = $this->db->num_rows($result);
119  $now = dol_now();
120 
121  $line = 0;
122  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
123 
124  while ($line < $num) {
125  $objp = $this->db->fetch_object($result);
126 
127  $datelimite = $this->db->jdate($objp->datelimite);
128  $datem = $this->db->jdate($objp->tms);
129 
130  $facturestatic->id = $objp->facid;
131  $facturestatic->ref = $objp->ref;
132  $facturestatic->type = $objp->type;
133  $facturestatic->total_ht = $objp->total_ht;
134  $facturestatic->total_tva = $objp->total_tva;
135  $facturestatic->total_ttc = $objp->total_ttc;
136  $facturestatic->statut = $objp->status;
137  $facturestatic->status = $objp->status;
138  $facturestatic->date = $this->db->jdate($objp->date);
139  $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
140 
141  $facturestatic->paye = $objp->paye;
142  $facturestatic->alreadypaid = $objp->am;
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  // @phan-suppress-next-line PhanPluginPrintfVariableFormatString
164  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
165  }
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="nowraponall"',
169  'text' => $facturestatic->getNomUrl(1),
170  'text2' => $late,
171  'asis' => 1,
172  );
173 
174  $this->info_box_contents[$line][] = array(
175  'td' => 'class="tdoverflowmax200"',
176  'text' => $societestatic->getNomUrl(1, '', 40),
177  'asis' => 1,
178  );
179 
180  $this->info_box_contents[$line][] = array(
181  'td' => 'class="right nowraponall amount"',
182  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
183  );
184 
185  $this->info_box_contents[$line][] = array(
186  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
187  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
188  );
189 
190  $this->info_box_contents[$line][] = array(
191  'td' => 'class="right" width="18"',
192  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
193  );
194 
195  $line++;
196  }
197 
198  if ($num == 0) {
199  $this->info_box_contents[$line][0] = array(
200  'td' => 'class="center"',
201  'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedInvoices").'</span>',
202  );
203  }
204 
205  $this->db->free($result);
206  } else {
207  $this->info_box_contents[0][0] = array(
208  'td' => '',
209  'maxlength' => 500,
210  'text' => ($this->db->error().' sql='.$sql),
211  );
212  }
213  } else {
214  $this->info_box_contents[0][0] = array(
215  'td' => 'class="nohover left"',
216  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
217  );
218  }
219  }
220 
229  public function showBox($head = null, $contents = null, $nooutput = 0)
230  {
231  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
232  }
233 }
Class to manage invoices.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last invoices.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...