dolibarr  20.0.0-beta
box_factures_fourn_imp.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
5  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  public $boxcode = "oldestunpaidsupplierbills";
35  public $boximg = "object_bill";
36  public $boxlabel = "BoxOldestUnpaidSupplierBills";
37  public $depends = array("facture", "fournisseur");
38 
45  public function __construct($db, $param)
46  {
47  global $user;
48 
49  $this->db = $db;
50 
51  $this->hidden = !($user->hasRight('fournisseur', 'facture', 'lire'));
52  }
53 
60  public function loadBox($max = 5)
61  {
62  global $conf, $user, $langs;
63 
64  $this->max = $max;
65  //$this->max = 1000;
66 
67  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
68  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
69 
70  $facturestatic = new FactureFournisseur($this->db);
71  $thirdpartystatic = new Fournisseur($this->db);
72 
73  $langs->load("bills");
74 
75  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills", $this->max));
76 
77  if ($user->hasRight('fournisseur', 'facture', 'lire')) {
78  $sql1 = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
79  $sql1 .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
80  $sql1 .= ", s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6";
81  $sql1 .= ", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
82  $sql1 .= ", f.datef as df";
83  $sql1 .= ", f.total_ht";
84  $sql1 .= ", f.total_tva";
85  $sql1 .= ", f.total_ttc";
86  $sql1 .= ", f.paye, f.fk_statut as status, f.type";
87  $sql1 .= ", f.tms";
88  $sql1 .= ", SUM(pf.amount) as am";
89  $sql2 = " FROM ".MAIN_DB_PREFIX."societe as s";
90  $sql2 .= ",".MAIN_DB_PREFIX."facture_fourn as f";
91  $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
92  if (!$user->hasRight('societe', 'client', 'voir')) {
93  $sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94  }
95  $sql2 .= " WHERE f.fk_soc = s.rowid";
96  $sql2 .= " AND f.entity IN (".getEntity('supplier_invoice').")";
97  $sql2 .= " AND f.paye = 0";
98  $sql2 .= " AND fk_statut = 1";
99  if (!$user->hasRight('societe', 'client', 'voir')) {
100  $sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
101  }
102  if ($user->socid) {
103  $sql2 .= " AND s.rowid = ".((int) $user->socid);
104  }
105  $sql3 = " GROUP BY s.rowid, s.nom, s.name_alias, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
106  $sql3 .= " f.rowid, f.ref, f.ref_supplier, f.date_lim_reglement,";
107  $sql3 .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.tms";
108  $sql3 .= " ORDER BY datelimite DESC, f.ref_supplier DESC ";
109  $sql3 .= $this->db->plimit($this->max + 1, 0);
110 
111  $sql = $sql1.$sql2.$sql3;
112 
113  $result = $this->db->query($sql);
114  if ($result) {
115  $num = $this->db->num_rows($result);
116 
117  $line = 0;
118  $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
119 
120  while ($line < min($num, $this->max)) {
121  $objp = $this->db->fetch_object($result);
122 
123  $datelimite = $this->db->jdate($objp->datelimite);
124  $date = $this->db->jdate($objp->df);
125  $datem = $this->db->jdate($objp->tms);
126 
127  $facturestatic->id = $objp->facid;
128  $facturestatic->ref = $objp->ref;
129  $facturestatic->type = $objp->type;
130  $facturestatic->total_ht = $objp->total_ht;
131  $facturestatic->total_tva = $objp->total_tva;
132  $facturestatic->total_ttc = $objp->total_ttc;
133  $facturestatic->date = $date;
134  $facturestatic->date_echeance = $datelimite;
135  $facturestatic->statut = $objp->status;
136  $facturestatic->status = $objp->status;
137 
138  //$alreadypaid = $facturestatic->getSommePaiement();
139 
140  $facturestatic->paye = $objp->paye;
141  $facturestatic->paid = $objp->paye;
142  $facturestatic->alreadypaid = $objp->am;
143 
144  $thirdpartystatic->id = $objp->socid;
145  $thirdpartystatic->name = $objp->name;
146  $thirdpartystatic->name_alias = $objp->name_alias;
147  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
148  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
149  $thirdpartystatic->fournisseur = $objp->fournisseur;
150  $thirdpartystatic->logo = $objp->logo;
151  $thirdpartystatic->email = $objp->email;
152  $thirdpartystatic->entity = $objp->entity;
153  $thirdpartystatic->tva_intra = $objp->tva_intra;
154  $thirdpartystatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 : '';
155  $thirdpartystatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 : '';
156  $thirdpartystatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 : '';
157  $thirdpartystatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 : '';
158  $thirdpartystatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 : '';
159  $thirdpartystatic->idprof6 = !empty($objp->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  $tooltip = $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier;
168 
169  $this->info_box_contents[$line][] = array(
170  'td' => 'class="nowraponall"',
171  'text' => $facturestatic->getNomUrl(1),
172  'text2' => $late,
173  'asis' => 1,
174  );
175 
176  $this->info_box_contents[$line][] = array(
177  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
178  'text' => $thirdpartystatic->getNomUrl(1, '', 44),
179  'asis' => 1,
180  );
181 
182  $this->info_box_contents[$line][] = array(
183  'td' => 'class="nowraponall right amount"',
184  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
185  );
186 
187  $this->info_box_contents[$line][] = array(
188  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
189  'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
190  );
191 
192  $this->info_box_contents[$line][] = array(
193  'td' => 'class="right" width="18"',
194  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
195  );
196 
197  $line++;
198  }
199  if ($this->max < $num) {
200  $this->info_box_contents[$line][] = array('td' => 'colspan="6"', 'text' => '...');
201  $line++;
202  }
203 
204  if ($num == 0) {
205  $this->info_box_contents[$line][0] = array(
206  'td' => 'class="center"',
207  'text' => '<span class="opacitymedium">'.$langs->trans("NoUnpaidSupplierBills").'</span>',
208  );
209  }
210 
211  $sql = "SELECT SUM(f.total_ht) as total_ht ".$sql2;
212 
213  $result = $this->db->query($sql);
214  $objp = $this->db->fetch_object($result);
215  $totalamount = $objp->total_ht;
216 
217  // Add the sum à the bottom of the boxes
218  $this->info_box_contents[$line][] = array(
219  'tr' => 'class="liste_total_wrap"',
220  'td' => 'class="liste_total"',
221  'text' => $langs->trans("Total"),
222  );
223  $this->info_box_contents[$line][] = array(
224  'td' => 'class="liste_total"',
225  'text' => "&nbsp;",
226  );
227  $this->info_box_contents[$line][] = array(
228  'td' => 'class="right liste_total" ',
229  'text' => price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
230  );
231  $this->info_box_contents[$line][] = array(
232  'td' => 'class="liste_total"',
233  'text' => "&nbsp;",
234  );
235  $this->info_box_contents[$line][] = array(
236  'td' => 'class="liste_total"',
237  'text' => "&nbsp;",
238  );
239 
240  $this->db->free($result);
241  } else {
242  $this->info_box_contents[0][0] = array(
243  'td' => '',
244  'maxlength' => 500,
245  'text' => ($this->db->error().' sql='.$sql),
246  );
247  }
248  } else {
249  $this->info_box_contents[0][0] = array(
250  'td' => 'class="nohover left"',
251  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
252  );
253  }
254  }
255 
264  public function showBox($head = null, $contents = null, $nooutput = 0)
265  {
266  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
267  }
268 }
Class to manage suppliers invoices.
Class to manage suppliers.
Class ModeleBoxes.
Class to manage the box to show not paid suppliers 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.
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.
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=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...