dolibarr  17.0.4
invoice.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
7  * Copyright (C) 2017 ATM-CONSULTING <contact@atm-consulting.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  * or see https://www.gnu.org/
22  */
23 
36 function facture_prepare_head($object)
37 {
38  global $db, $langs, $conf;
39 
40  $h = 0;
41  $head = array();
42 
43  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$object->id;
44  $head[$h][1] = $langs->trans('CustomerInvoice');
45  $head[$h][2] = 'compta';
46  $h++;
47 
48  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
49  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
50  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.urlencode($object->id);
51  $head[$h][1] = $langs->trans('ContactsAddresses');
52  if ($nbContact > 0) {
53  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
54  }
55  $head[$h][2] = 'contact';
56  $h++;
57  }
58 
59  if (!empty($conf->prelevement->enabled)) {
60  $nbStandingOrders = 0;
61  $sql = "SELECT COUNT(pfd.rowid) as nb";
62  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
63  $sql .= " WHERE pfd.fk_facture = ".((int) $object->id);
64  $sql .= " AND pfd.ext_payment_id IS NULL";
65  $resql = $db->query($sql);
66  if ($resql) {
67  $obj = $db->fetch_object($resql);
68  if ($obj) {
69  $nbStandingOrders = $obj->nb;
70  }
71  } else {
72  dol_print_error($db);
73  }
74  $langs->load("banks");
75 
76  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.urlencode($object->id);
77  $head[$h][1] = $langs->trans('StandingOrders');
78  if ($nbStandingOrders > 0) {
79  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
80  }
81  $head[$h][2] = 'standingorders';
82  $h++;
83  }
84 
85  // Show more tabs from modules
86  // Entries must be declared in modules descriptor with line
87  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
88  // $this->tabs = array('entity:-tabname); to remove a tab
89  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'core');
90 
91  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
92  $nbNote = 0;
93  if (!empty($object->note_private)) {
94  $nbNote++;
95  }
96  if (!empty($object->note_public)) {
97  $nbNote++;
98  }
99  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$object->id;
100  $head[$h][1] = $langs->trans('Notes');
101  if ($nbNote > 0) {
102  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
103  }
104  $head[$h][2] = 'note';
105  $h++;
106  }
107 
108  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
109  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
110  $upload_dir = $conf->facture->dir_output."/".dol_sanitizeFileName($object->ref);
111  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
112  $nbLinks = Link::count($db, $object->element, $object->id);
113  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id;
114  $head[$h][1] = $langs->trans('Documents');
115  if (($nbFiles + $nbLinks) > 0) {
116  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
117  }
118  $head[$h][2] = 'documents';
119  $h++;
120 
121  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$object->id;
122  $head[$h][1] = $langs->trans('Info');
123  $head[$h][2] = 'info';
124  $h++;
125 
126  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'external');
127 
128  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'remove');
129 
130  return $head;
131 }
132 
139 {
140  global $langs, $conf, $user, $db;
141 
142  $extrafields = new ExtraFields($db);
143  $extrafields->fetch_name_optionals_label('facture');
144  $extrafields->fetch_name_optionals_label('facturedet');
145  $extrafields->fetch_name_optionals_label('facture_rec');
146  $extrafields->fetch_name_optionals_label('facturedet_rec');
147 
148  $h = 0;
149  $head = array();
150 
151  $head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
152  $head[$h][1] = $langs->trans("Miscellaneous");
153  $head[$h][2] = 'general';
154  $h++;
155 
156  $head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
157  $head[$h][1] = $langs->trans("Payments");
158  $head[$h][2] = 'payment';
159  $h++;
160 
161  // Show more tabs from modules
162  // Entries must be declared in modules descriptor with line
163  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
164  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
165  complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
166 
167  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
168  $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
169  $nbExtrafields = $extrafields->attributes['facture']['count'];
170  if ($nbExtrafields > 0) {
171  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
172  }
173  $head[$h][2] = 'attributes';
174  $h++;
175 
176  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
177  $head[$h][1] = $langs->trans("ExtraFieldsLines");
178  $nbExtrafields = $extrafields->attributes['facturedet']['count'];
179  if ($nbExtrafields > 0) {
180  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
181  }
182  $head[$h][2] = 'attributeslines';
183  $h++;
184 
185  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_rec_cust_extrafields.php';
186  $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
187  $nbExtrafields = $extrafields->attributes['facture_rec']['count'];
188  if ($nbExtrafields > 0) {
189  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
190  }
191  $head[$h][2] = 'attributesrec';
192  $h++;
193 
194  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_rec_cust_extrafields.php';
195  $head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
196  $nbExtrafields = $extrafields->attributes['facturedet_rec']['count'];
197  if ($nbExtrafields > 0) {
198  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
199  }
200  $head[$h][2] = 'attributeslinesrec';
201  $h++;
202 
203  if (getDolGlobalInt('INVOICE_USE_SITUATION') > 0) { // Warning, implementation with value 1 is seriously bugged and a new one not compatible is expected to become stable
204  $head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php';
205  $head[$h][1] = $langs->trans("InvoiceSituation");
206  $head[$h][2] = 'situation';
207  $h++;
208  }
209 
210  complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
211 
212  return $head;
213 }
214 
215 
222 function invoice_rec_prepare_head($object)
223 {
224  global $db, $langs, $conf;
225 
226  $h = 0;
227  $head = array();
228 
229  $head[$h][0] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object->id;
230  $head[$h][1] = $langs->trans("RepeatableInvoice");
231  $head[$h][2] = 'card';
232  $h++;
233 
234  // Show more tabs from modules
235  // Entries must be declared in modules descriptor with line
236  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
237  // $this->tabs = array('entity:-tabname); to remove a tab
238  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
239 
240  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
241 
242  return $head;
243 }
244 
252 {
253  global $db, $langs, $conf;
254 
255  $h = 0;
256  $head = array();
257 
258  $head[$h][0] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object->id;
259  $head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
260  $head[$h][2] = 'card';
261  $h++;
262 
263  // Show more tabs from modules
264  // Entries must be declared in modules descriptor with line
265  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
266  // $this->tabs = array('entity:-tabname); to remove a tab
267  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
268 
269  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
270 
271  return $head;
272 }
273 
281 {
282  global $conf, $db, $langs, $user;
283 
284  if (($mode == 'customers' && isModEnabled('facture') && $user->hasRight('facture', 'lire'))
285  || ($mode == 'suppliers' && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('fournisseur', 'facture', 'lire'))
286  ) {
287  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
288 
289  $now = date_create(date('Y-m-d', dol_now()));
290  $datenowsub30 = date_create(date('Y-m-d', dol_now()));
291  $datenowsub15 = date_create(date('Y-m-d', dol_now()));
292  $datenowadd30 = date_create(date('Y-m-d', dol_now()));
293  $datenowadd15 = date_create(date('Y-m-d', dol_now()));
294  $interval30days = date_interval_create_from_date_string('30 days');
295  $interval15days = date_interval_create_from_date_string('15 days');
296  date_sub($datenowsub30, $interval30days);
297  date_sub($datenowsub15, $interval15days);
298  date_add($datenowadd30, $interval30days);
299  date_add($datenowadd15, $interval15days);
300 
301  $sql = "SELECT";
302  $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", 1, 0).") as nblate30";
303  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."'", 1, 0).") as nblate15";
304  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."'", 1, 0).") as nblatenow";
305  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($now, 'Y-m-d')."' OR f.date_lim_reglement IS NULL", 1, 0).") as nbnotlatenow";
306  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd15, 'Y-m-d')."'", 1, 0).") as nbnotlate15";
307  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd30, 'Y-m-d')."'", 1, 0).") as nbnotlate30";
308  if ($mode == 'customers') {
309  $element = 'invoice';
310  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
311  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
312  $element = 'supplier_invoice';
313  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
314  } else {
315  return '';
316  }
317  $sql .= " WHERE f.entity IN (".getEntity($element).")";
318  $sql .= " AND f.type <> 2";
319  $sql .= " AND f.fk_statut = 1";
320  if (isset($user->socid) && $user->socid > 0) {
321  $sql .= " AND f.fk_soc = ".((int) $user->socid);
322  }
323 
324  $resql = $db->query($sql);
325  if ($resql) {
326  $num = $db->num_rows($resql);
327  $i = 0;
328  $total = 0;
329  $dataseries = array();
330 
331  while ($i < $num) {
332  $obj = $db->fetch_object($resql);
333  /*
334  $dataseries = array(array($langs->trans('InvoiceLate30Days'), $obj->nblate30)
335  ,array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30)
336  ,array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15)
337  ,array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15)
338  ,array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30)
339  ,array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30));
340  */
341  $dataseries[$i]=array($langs->transnoentitiesnoconv('NbOfOpenInvoices'), $obj->nblate30, $obj->nblate15 - $obj->nblate30, $obj->nblatenow - $obj->nblate15, $obj->nbnotlatenow - $obj->nbnotlate15, $obj->nbnotlate15 - $obj->nbnotlate30, $obj->nbnotlate30);
342  $i++;
343  }
344  if (!empty($dataseries[0])) {
345  foreach ($dataseries[0] as $key => $value) {
346  if (is_numeric($value)) {
347  $total += $value;
348  }
349  }
350  }
351  $legend = array(
352  $langs->trans('InvoiceLate30Days'),
353  $langs->trans('InvoiceLate15Days'),
354  $langs->trans('InvoiceLateMinus15Days'),
355  $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
356  $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
357  $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
358  );
359 
360  $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
361 
362  $result = '<div class="div-table-responsive-no-min">';
363  $result .= '<table class="noborder nohover centpercent">';
364  $result .= '<tr class="liste_titre">';
365  $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
366  if ($mode == 'customers') {
367  $result .= $langs->trans("CustomerInvoice");
368  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
369  $result .= $langs->trans("SupplierInvoice");
370  } else {
371  return '';
372  }
373  $result .= '</td>';
374  $result .= '</tr>';
375 
376  if ($conf->use_javascript_ajax) {
377  //var_dump($dataseries);
378  $dolgraph = new DolGraph();
379  $dolgraph->SetData($dataseries);
380 
381  $dolgraph->setLegend($legend);
382 
383  $dolgraph->SetDataColor(array_values($colorseries));
384  $dolgraph->setShowLegend(2);
385  $dolgraph->setShowPercent(1);
386  $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
387  //$dolgraph->SetType(array('pie'));
388  $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
389  $dolgraph->setWidth('450');
390  $dolgraph->setHideXValues(true);
391  if ($mode == 'customers') {
392  $dolgraph->draw('idgraphcustomerinvoices');
393  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
394  $dolgraph->draw('idgraphfourninvoices');
395  } else {
396  return '';
397  }
398  $result .= '<tr maxwidth="255">';
399  $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
400  $result .= '</tr>';
401  } else {
402  // Print text lines
403  }
404 
405  $result .= '</table>';
406  $result .= '</div>';
407 
408  return $result;
409  } else {
410  dol_print_error($db);
411  }
412  }
413  return '';
414 }
415 
423 function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
424 {
425  global $conf, $db, $langs, $user, $hookmanager;
426 
427  $result = '';
428 
429  if (isModEnabled('facture') && !empty($user->rights->facture->lire)) {
430  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
431 
432  $tmpinvoice = new Facture($db);
433 
434  $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
435  $sql .= ", f.type, f.fk_statut as status, f.paye";
436  $sql .= ", s.nom as name";
437  $sql .= ", s.rowid as socid, s.email";
438  $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
439  $sql .= ", cc.rowid as country_id, cc.code as country_code";
440  if (empty($user->rights->societe->client->voir) && !$socid) {
441  $sql .= ", sc.fk_soc, sc.fk_user ";
442  }
443  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
444  if (empty($user->rights->societe->client->voir) && !$socid) {
445  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
446  }
447  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
448  $sql .= " AND f.entity IN (".getEntity('invoice').")";
449  if (empty($user->rights->societe->client->voir) && !$socid) {
450  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
451  }
452 
453  if ($socid) {
454  $sql .= " AND f.fk_soc = ".((int) $socid);
455  }
456  // Add where from hooks
457  $parameters = array();
458  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
459  $sql .= $hookmanager->resPrint;
460 
461  $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,";
462  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
463  $sql .= " cc.rowid, cc.code";
464  if (empty($user->rights->societe->client->voir) && !$socid) {
465  $sql .= ", sc.fk_soc, sc.fk_user";
466  }
467 
468  // Add Group from hooks
469  $parameters = array();
470  $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
471  $sql .= $hookmanager->resPrint;
472 
473  $resql = $db->query($sql);
474 
475  if ($resql) {
476  $num = $db->num_rows($resql);
477  $nbofloop = min($num, $maxofloop);
478 
479  $result .= '<div class="div-table-responsive-no-min">';
480  $result .= '<table class="noborder centpercent">';
481 
482  $result .= '<tr class="liste_titre">';
483  $result .= '<th colspan="3">';
484  $result .= $langs->trans("CustomersDraftInvoices").' ';
485  $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
486  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
487  $result .= '</a>';
488  $result .= '</th>';
489  $result .= '</tr>';
490 
491  if ($num) {
492  $companystatic = new Societe($db);
493 
494  $i = 0;
495  $othernb = 0;
496  $tot_ttc = 0;
497  while ($i < $nbofloop) {
498  $obj = $db->fetch_object($resql);
499 
500  if ($i >= $maxCount) {
501  $othernb += 1;
502  $i++;
503  $tot_ttc += $obj->total_ttc;
504  continue;
505  }
506 
507  $tmpinvoice->id = $obj->rowid;
508  $tmpinvoice->ref = $obj->ref;
509  $tmpinvoice->date = $db->jdate($obj->date);
510  $tmpinvoice->type = $obj->type;
511  $tmpinvoice->total_ht = $obj->total_ht;
512  $tmpinvoice->total_tva = $obj->total_tva;
513  $tmpinvoice->total_ttc = $obj->total_ttc;
514  $tmpinvoice->ref_client = $obj->ref_client;
515  $tmpinvoice->statut = $obj->status;
516  $tmpinvoice->paye = $obj->paye;
517 
518  $companystatic->id = $obj->socid;
519  $companystatic->name = $obj->name;
520  $companystatic->email = $obj->email;
521  $companystatic->country_id = $obj->country_id;
522  $companystatic->country_code = $obj->country_code;
523  $companystatic->client = 1;
524  $companystatic->code_client = $obj->code_client;
525  $companystatic->code_fournisseur = $obj->code_fournisseur;
526  $companystatic->code_compta = $obj->code_compta;
527  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
528 
529  $result .= '<tr class="oddeven">';
530  $result .= '<td class="nowrap tdoverflowmax100">';
531  $result .= $tmpinvoice->getNomUrl(1, '');
532  $result .= '</td>';
533  $result .= '<td class="nowrap tdoverflowmax100">';
534  $result .= $companystatic->getNomUrl(1, 'customer');
535  $result .= '</td>';
536  $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
537  $result .= '</tr>';
538  $tot_ttc += $obj->total_ttc;
539  $i++;
540  }
541 
542  if ($othernb) {
543  $result .= '<tr class="oddeven">';
544  $result .= '<td class="nowrap" colspan="3">';
545  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
546  $result .= '</td>';
547  $result .= "</tr>\n";
548  }
549 
550  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
551  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
552  $result .= '</tr>';
553  } else {
554  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
555  }
556  $result .= "</table></div>";
557  $db->free($resql);
558  } else {
559  dol_print_error($db);
560  }
561  }
562 
563  return $result;
564 }
565 
573 function getDraftSupplierTable($maxCount = 500, $socid = 0)
574 {
575  global $conf, $db, $langs, $user, $hookmanager;
576 
577  $result = '';
578 
579  if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && !empty($user->rights->facture->lire)) {
580  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
581 
582  $facturesupplierstatic = new FactureFournisseur($db);
583 
584  $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye";
585  $sql .= ", s.nom as name";
586  $sql .= ", s.rowid as socid, s.email";
587  $sql .= ", s.code_client, s.code_compta";
588  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
589  $sql .= ", cc.rowid as country_id, cc.code as country_code";
590  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
591  if (empty($user->rights->societe->client->voir) && !$socid) {
592  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
593  }
594  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
595  $sql .= " AND f.entity IN (".getEntity('invoice').')';
596  if (empty($user->rights->societe->client->voir) && !$socid) {
597  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
598  }
599  if ($socid) {
600  $sql .= " AND f.fk_soc = ".((int) $socid);
601  }
602  // Add where from hooks
603  $parameters = array();
604  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
605  $sql .= $hookmanager->resPrint;
606  $resql = $db->query($sql);
607 
608  if ($resql) {
609  $num = $db->num_rows($resql);
610  $nbofloop = min($num, $maxofloop);
611 
612  $result .= '<div class="div-table-responsive-no-min">';
613  $result .= '<table class="noborder centpercent">';
614 
615  $result .= '<tr class="liste_titre">';
616  $result .= '<th colspan="3">';
617  $result .= $langs->trans("SuppliersDraftInvoices").' ';
618  $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
619  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
620  $result .= '</a>';
621  $result .= '</th>';
622  $result .= '</tr>';
623 
624  if ($num) {
625  $companystatic = new Societe($db);
626 
627  $i = 0;
628  $othernb = 0;
629  $tot_ttc = 0;
630  while ($i < $nbofloop) {
631  $obj = $db->fetch_object($resql);
632 
633  if ($i >= $maxCount) {
634  $othernb += 1;
635  $i++;
636  $tot_ttc += $obj->total_ttc;
637  continue;
638  }
639 
640  $facturesupplierstatic->ref = $obj->ref;
641  $facturesupplierstatic->id = $obj->rowid;
642  $facturesupplierstatic->total_ht = $obj->total_ht;
643  $facturesupplierstatic->total_tva = $obj->total_tva;
644  $facturesupplierstatic->total_ttc = $obj->total_ttc;
645  $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
646  $facturesupplierstatic->type = $obj->type;
647  $facturesupplierstatic->statut = $obj->status;
648  $facturesupplierstatic->paye = $obj->paye;
649 
650  $companystatic->id = $obj->socid;
651  $companystatic->name = $obj->name;
652  $companystatic->email = $obj->email;
653  $companystatic->country_id = $obj->country_id;
654  $companystatic->country_code = $obj->country_code;
655  $companystatic->fournisseur = 1;
656  $companystatic->code_client = $obj->code_client;
657  $companystatic->code_fournisseur = $obj->code_fournisseur;
658  $companystatic->code_compta = $obj->code_compta;
659  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
660 
661  $result .= '<tr class="oddeven">';
662  $result .= '<td class="nowrap tdoverflowmax100">';
663  $result .= $facturesupplierstatic->getNomUrl(1, '');
664  $result .= '</td>';
665  $result .= '<td class="nowrap tdoverflowmax100">';
666  $result .= $companystatic->getNomUrl(1, 'supplier');
667  $result .= '</td>';
668  $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
669  $result .= '</tr>';
670  $tot_ttc += $obj->total_ttc;
671  $i++;
672  }
673 
674  if ($othernb) {
675  $result .= '<tr class="oddeven">';
676  $result .= '<td class="nowrap" colspan="3">';
677  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
678  $result .= '</td>';
679  $result .= "</tr>\n";
680  }
681 
682  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
683  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
684  $result .= '</tr>';
685  } else {
686  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
687  }
688  $result .= "</table></div>";
689  $db->free($resql);
690  } else {
691  dol_print_error($db);
692  }
693  }
694 
695  return $result;
696 }
697 
698 
706 function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
707 {
708  global $conf, $db, $langs, $user;
709 
710  $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datec,";
711  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
712  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
713  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
714  if (empty($user->rights->societe->client->voir) && !$socid) {
715  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
716  }
717  $sql .= " WHERE f.fk_soc = s.rowid";
718  $sql .= " AND f.entity IN (".getEntity('facture').")";
719  if ($socid) {
720  $sql .= " AND f.fk_soc = ".((int) $socid);
721  }
722  if (empty($user->rights->societe->client->voir) && !$socid) {
723  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
724  }
725  $sql .= " ORDER BY f.tms DESC";
726  $sql .= $db->plimit($maxCount, 0);
727 
728  $resql = $db->query($sql);
729  if (!$resql) {
730  dol_print_error($db);
731  }
732 
733  $num = $db->num_rows($resql);
734 
735  $result = '<div class="div-table-responsive-no-min">';
736  $result .= '<table class="noborder centpercent">';
737 
738  $result .= '<tr class="liste_titre">';
739  $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
740  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
741  $result .= '<th class="right"></th>';
742  $result .= '</tr>';
743 
744  if ($num < 1) {
745  $result .= '</table>';
746  $result .= '</div>';
747  return $result;
748  }
749 
750  $formfile = new FormFile($db);
751  $objectstatic = new Facture($db);
752  $companystatic = new Societe($db);
753  $i = 0;
754 
755  while ($i < $num) {
756  $obj = $db->fetch_object($resql);
757 
758  $objectstatic->id = $obj->rowid;
759  $objectstatic->ref = $obj->ref;
760  $objectstatic->paye = $obj->paye;
761  $objectstatic->statut = $obj->status;
762  $objectstatic->total_ht = $obj->total_ht;
763  $objectstatic->total_tva = $obj->total_tva;
764  $objectstatic->total_ttc = $obj->total_ttc;
765  $objectstatic->type = $obj->type;
766 
767  $companystatic->id = $obj->socid;
768  $companystatic->name = $obj->socname;
769  $companystatic->client = $obj->client;
770  $companystatic->canvas = $obj->canvas;
771 
772  $filename = dol_sanitizeFileName($obj->ref);
773  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
774 
775  $result .= '<tr class="nowrap">';
776 
777  $result .= '<td class="oddeven">';
778  $result .= '<table class="nobordernopadding">';
779  $result .= '<tr class="nocellnopadd">';
780 
781  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
782  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
783  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
784 
785  $result .= '</tr>';
786  $result .= '</table>';
787  $result .= '</td>';
788 
789  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
790  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
791  $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
792 
793  // Load amount of existing payment of invoice (needed for complete status)
794  $payment = $objectstatic->getSommePaiement();
795  $result .= '<td class="right">'.$objectstatic->getLibStatut(5, $payment).'</td>';
796 
797  $result .= '</tr>';
798 
799  $i++;
800  }
801 
802  $result .= '</table>';
803  $result .= '</div>';
804  return $result;
805 }
806 
814 function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
815 {
816  global $conf, $db, $langs, $user;
817 
818  $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.datec,";
819  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
820  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
821  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
822  if (empty($user->rights->societe->client->voir) && !$socid) {
823  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
824  }
825  $sql .= " WHERE f.fk_soc = s.rowid";
826  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
827  if ($socid) {
828  $sql .= " AND f.fk_soc = ".((int) $socid);
829  }
830  if (empty($user->rights->societe->client->voir) && !$socid) {
831  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
832  }
833  $sql .= " ORDER BY f.tms DESC";
834  $sql .= $db->plimit($maxCount, 0);
835 
836  $resql = $db->query($sql);
837  if (!$resql) {
838  dol_print_error($db);
839  return '';
840  }
841 
842  $num = $db->num_rows($resql);
843 
844  $result = '<div class="div-table-responsive-no-min">';
845  $result .= '<table class="noborder centpercent">';
846  $result .= '<tr class="liste_titre">';
847  $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'</th>';
848  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
849  $result .= '<th class="right"></th>';
850  $result .= '</tr>';
851 
852  if ($num < 1) {
853  $result .= '</table>';
854  $result .= '</div>';
855  return $result;
856  }
857 
858  $objectstatic = new FactureFournisseur($db);
859  $companystatic = new Societe($db);
860  $formfile = new FormFile($db);
861  $i = 0;
862 
863  while ($i < $num) {
864  $obj = $db->fetch_object($resql);
865 
866  $objectstatic->id = $obj->rowid;
867  $objectstatic->ref = $obj->ref;
868  $objectstatic->paye = $obj->paye;
869  $objectstatic->statut = $obj->status;
870  $objectstatic->total_ht = $obj->total_ht;
871  $objectstatic->total_tva = $obj->total_tva;
872  $objectstatic->total_ttc = $obj->total_ttc;
873  $objectstatic->type = $obj->type;
874 
875  $companystatic->id = $obj->socid;
876  $companystatic->name = $obj->socname;
877  $companystatic->client = $obj->client;
878  $companystatic->canvas = $obj->canvas;
879 
880  $filename = dol_sanitizeFileName($obj->ref);
881  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
882 
883  $result .= '<tr class="nowrap">';
884 
885  $result .= '<td class="oddeven">';
886  $result .= '<table class="nobordernopadding">';
887  $result .= '<tr class="nocellnopadd">';
888 
889  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
890  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
891  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
892 
893  $result .= '</tr>';
894  $result .= '</table>';
895  $result .= '</td>';
896 
897  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
898 
899  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
900 
901  $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
902 
903  $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
904 
905  $result .= '</tr>';
906 
907  $i++;
908  }
909 
910  $result .= '</table>';
911  $result .= '</div>';
912  return $result;
913 }
914 
922 function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
923 {
924  global $conf, $db, $langs, $user, $hookmanager;
925 
926  $result = '';
927 
928  if (isModEnabled('facture') && !empty($user->rights->facture->lire)) {
929  $tmpinvoice = new Facture($db);
930 
931  $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms";
932  $sql .= ", f.date_lim_reglement as datelimite";
933  $sql .= ", s.nom as name";
934  $sql .= ", s.rowid as socid, s.email";
935  $sql .= ", s.code_client, s.code_compta";
936  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
937  $sql .= ", cc.rowid as country_id, cc.code as country_code";
938  $sql .= ", sum(pf.amount) as am";
939  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays,".MAIN_DB_PREFIX."facture as f";
940  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
941  if (empty($user->rights->societe->client->voir) && !$socid) {
942  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
943  }
944  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
945  $sql .= " AND f.entity IN (".getEntity('invoice').')';
946  if (empty($user->rights->societe->client->voir) && !$socid) {
947  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
948  }
949  if ($socid) {
950  $sql .= " AND f.fk_soc = ".((int) $socid);
951  }
952  // Add where from hooks
953  $parameters = array();
954  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
955  $sql .= $hookmanager->resPrint;
956 
957  $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
958  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
959  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
960  $sql .= " ORDER BY f.datef ASC, f.ref ASC";
961 
962  $resql = $db->query($sql);
963  if ($resql) {
964  $num = $db->num_rows($resql);
965  $i = 0;
966  $othernb = 0;
967 
968  $formfile = new FormFile($db);
969 
970  print '<div class="div-table-responsive-no-min">';
971  print '<table class="noborder centpercent">';
972 
973  print '<tr class="liste_titre">';
974  print '<th colspan="2">';
975  print $langs->trans("BillsCustomersUnpaid", $num).' ';
976  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
977  print '<span class="badge">'.$num.'</span>';
978  print '</a>';
979  print '</th>';
980 
981  print '<th class="right">'.$langs->trans("DateDue").'</th>';
982  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
983  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
984  }
985  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
986  print '<th class="right">'.$langs->trans("Received").'</th>';
987  print '<th width="16">&nbsp;</th>';
988  print '</tr>';
989  if ($num) {
990  $societestatic = new Societe($db);
991  $total_ttc = $totalam = $total = 0;
992  while ($i < $num) {
993  $obj = $db->fetch_object($resql);
994 
995  if ($i >= $maxCount) {
996  $othernb += 1;
997  $i++;
998  $total += $obj->total_ht;
999  $total_ttc += $obj->total_ttc;
1000  $totalam += $obj->am;
1001  continue;
1002  }
1003 
1004  $tmpinvoice->ref = $obj->ref;
1005  $tmpinvoice->id = $obj->rowid;
1006  $tmpinvoice->total_ht = $obj->total_ht;
1007  $tmpinvoice->total_tva = $obj->total_tva;
1008  $tmpinvoice->total_ttc = $obj->total_ttc;
1009  $tmpinvoice->type = $obj->type;
1010  $tmpinvoice->statut = $obj->status;
1011  $tmpinvoice->paye = $obj->paye;
1012  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1013 
1014  $societestatic->id = $obj->socid;
1015  $societestatic->name = $obj->name;
1016  $societestatic->email = $obj->email;
1017  $societestatic->country_id = $obj->country_id;
1018  $societestatic->country_code = $obj->country_code;
1019  $societestatic->client = 1;
1020  $societestatic->code_client = $obj->code_client;
1021  $societestatic->code_fournisseur = $obj->code_fournisseur;
1022  $societestatic->code_compta = $obj->code_compta;
1023  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1024 
1025  print '<tr class="oddeven">';
1026  print '<td class="nowrap">';
1027 
1028  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1029  print '<td class="nobordernopadding nowrap">';
1030  print $tmpinvoice->getNomUrl(1, '');
1031  print '</td>';
1032  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1033  $filename = dol_sanitizeFileName($obj->ref);
1034  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1035  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1036  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1037  print '</td></tr></table>';
1038 
1039  print '</td>';
1040  print '<td class="nowrap tdoverflowmax100">';
1041  print $societestatic->getNomUrl(1, 'customer');
1042  print '</td>';
1043  print '<td class="right">';
1044  print dol_print_date($db->jdate($obj->datelimite), 'day');
1045  if ($tmpinvoice->hasDelay()) {
1046  print img_warning($langs->trans("Late"));
1047  }
1048  print '</td>';
1049  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1050  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1051  }
1052  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1053  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1054  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1055  print '</tr>';
1056 
1057  $total_ttc += $obj->total_ttc;
1058  $total += $obj->total_ht;
1059  $totalam += $obj->am;
1060 
1061  $i++;
1062  }
1063 
1064  if ($othernb) {
1065  $colspan = 6;
1066  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1067  $colspan++;
1068  }
1069  print '<tr class="oddeven">';
1070  print '<td class="nowrap" colspan="'.$colspan.'">';
1071  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1072  print '</td>';
1073  print "</tr>\n";
1074  }
1075 
1076  print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <span style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')</span> </td>';
1077  print '<td>&nbsp;</td>';
1078  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1079  print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1080  }
1081  print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1082  print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1083  print '<td>&nbsp;</td>';
1084  print '</tr>';
1085  } else {
1086  $colspan = 6;
1087  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1088  $colspan++;
1089  }
1090  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1091  }
1092  print '</table></div><br>';
1093  $db->free($resql);
1094  } else {
1095  dol_print_error($db);
1096  }
1097  }
1098 
1099  return $result;
1100 }
1101 
1102 
1110 function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1111 {
1112  global $conf, $db, $langs, $user, $hookmanager;
1113 
1114  $result = '';
1115 
1116  if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (isModEnabled("supplier_invoice") && $user->rights->supplier_invoice->lire)) {
1117  $facstatic = new FactureFournisseur($db);
1118 
1119  $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye";
1120  $sql .= ", ff.date_lim_reglement";
1121  $sql .= ", s.nom as name";
1122  $sql .= ", s.rowid as socid, s.email";
1123  $sql .= ", s.code_client, s.code_compta";
1124  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1125  $sql .= ", sum(pf.amount) as am";
1126  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1127  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1128  if (empty($user->rights->societe->client->voir) && !$socid) {
1129  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1130  }
1131  $sql .= " WHERE s.rowid = ff.fk_soc";
1132  $sql .= " AND ff.entity = ".$conf->entity;
1133  $sql .= " AND ff.paye = 0";
1134  $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1135  if (empty($user->rights->societe->client->voir) && !$socid) {
1136  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1137  }
1138  if ($socid) {
1139  $sql .= " AND ff.fk_soc = ".((int) $socid);
1140  }
1141  // Add where from hooks
1142  $parameters = array();
1143  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1144  $sql .= $hookmanager->resPrint;
1145 
1146  $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,";
1147  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1148  $sql .= " ORDER BY ff.date_lim_reglement ASC";
1149 
1150  $resql = $db->query($sql);
1151  if ($resql) {
1152  $num = $db->num_rows($resql);
1153  $othernb = 0;
1154 
1155  $formfile = new FormFile($db);
1156 
1157  print '<div class="div-table-responsive-no-min">';
1158  print '<table class="noborder centpercent">';
1159 
1160  print '<tr class="liste_titre">';
1161  print '<th colspan="2">';
1162  print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1163  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1164  print '<span class="badge">'.$num.'</span>';
1165  print '</a>';
1166  print '</th>';
1167 
1168  print '<th class="right">'.$langs->trans("DateDue").'</th>';
1169  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1170  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1171  }
1172  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1173  print '<th class="right">'.$langs->trans("Paid").'</th>';
1174  print '<th width="16">&nbsp;</th>';
1175  print "</tr>\n";
1176  $societestatic = new Societe($db);
1177  if ($num) {
1178  $i = 0;
1179  $total = $total_ttc = $totalam = 0;
1180  while ($i < $num) {
1181  $obj = $db->fetch_object($resql);
1182 
1183  if ($i >= $maxCount) {
1184  $othernb += 1;
1185  $i++;
1186  $total += $obj->total_ht;
1187  $total_ttc += $obj->total_ttc;
1188  continue;
1189  }
1190 
1191  $facstatic->ref = $obj->ref;
1192  $facstatic->id = $obj->rowid;
1193  $facstatic->type = $obj->type;
1194  $facstatic->total_ht = $obj->total_ht;
1195  $facstatic->total_tva = $obj->total_tva;
1196  $facstatic->total_ttc = $obj->total_ttc;
1197  $facstatic->statut = $obj->status;
1198  $facstatic->paye = $obj->paye;
1199 
1200  $societestatic->id = $obj->socid;
1201  $societestatic->name = $obj->name;
1202  $societestatic->email = $obj->email;
1203  $societestatic->client = 0;
1204  $societestatic->fournisseur = 1;
1205  $societestatic->code_client = $obj->code_client;
1206  $societestatic->code_fournisseur = $obj->code_fournisseur;
1207  $societestatic->code_compta = $obj->code_compta;
1208  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1209 
1210  print '<tr class="oddeven">';
1211  print '<td class="nowrap tdoverflowmax100">';
1212  print $facstatic->getNomUrl(1, '');
1213  print '</td>';
1214  print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1215  print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1216  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1217  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1218  }
1219  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1220  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1221  print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1222  print '</tr>';
1223  $total += $obj->total_ht;
1224  $total_ttc += $obj->total_ttc;
1225  $totalam += $obj->am;
1226  $i++;
1227  }
1228 
1229  if ($othernb) {
1230  $colspan = 6;
1231  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1232  $colspan++;
1233  }
1234  print '<tr class="oddeven">';
1235  print '<td class="nowrap" colspan="'.$colspan.'">';
1236  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1237  print '</td>';
1238  print "</tr>\n";
1239  }
1240 
1241  print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <span style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')</span> </td>';
1242  print '<td>&nbsp;</td>';
1243  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1244  print '<td class="right">'.price($total).'</td>';
1245  }
1246  print '<td class="nowrap right">'.price($total_ttc).'</td>';
1247  print '<td class="nowrap right">'.price($totalam).'</td>';
1248  print '<td>&nbsp;</td>';
1249  print '</tr>';
1250  } else {
1251  $colspan = 6;
1252  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1253  $colspan++;
1254  }
1255  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1256  }
1257  print '</table></div><br>';
1258  } else {
1259  dol_print_error($db);
1260  }
1261  }
1262 
1263  return $result;
1264 }
Class to build graphs.
Class to manage standard extra fields.
Class to manage suppliers invoices.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated (need to be paid)
Class to offer components to list and upload files.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
isModEnabled($module)
Is Dolibarr module enabled.
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices.
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
getCustomerInvoiceLatestEditTable($maxCount=5, $socid=0)
Return a HTML table that contains a list with latest edited customer invoices.
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
getPurchaseInvoiceLatestEditTable($maxCount=5, $socid=0)
Return a HTML table that contains a list with latest edited supplier invoices.
getCustomerInvoiceDraftTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
getCustomerInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid customers invoices.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36
getPurchaseInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid purchase invoices.