dolibarr  x.y.z
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 (!empty($conf->global->INVOICE_USE_SITUATION)) { // Warning, implementation 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  if (($mode == 'customers' && isModEnabled('facture') && !empty($user->rights->facture->lire))
284  || ($mode = 'suppliers') && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && !empty($user->rights->facture->lire)
285  ) {
286  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
287 
288  $now = date_create(date('Y-m-d', dol_now()));
289  $datenowsub30 = date_create(date('Y-m-d', dol_now()));
290  $datenowsub15 = date_create(date('Y-m-d', dol_now()));
291  $datenowadd30 = date_create(date('Y-m-d', dol_now()));
292  $datenowadd15 = date_create(date('Y-m-d', dol_now()));
293  $interval30days = date_interval_create_from_date_string('30 days');
294  $interval15days = date_interval_create_from_date_string('15 days');
295  date_sub($datenowsub30, $interval30days);
296  date_sub($datenowsub15, $interval15days);
297  date_add($datenowadd30, $interval30days);
298  date_add($datenowadd15, $interval15days);
299 
300  $sql = "SELECT";
301  $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", 1, 0).") as nblate30";
302  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."'", 1, 0).") as nblate15";
303  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."'", 1, 0).") as nblatenow";
304  $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";
305  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd15, 'Y-m-d')."'", 1, 0).") as nbnotlate15";
306  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd30, 'Y-m-d')."'", 1, 0).") as nbnotlate30";
307  if ($mode == 'customers') {
308  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
309  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
310  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
311  } else {
312  return '';
313  }
314  $sql .= " WHERE f.type <> 2";
315  $sql .= " AND f.fk_statut = 1";
316  if (isset($user->socid) && $user->socid > 0) {
317  $sql .= " AND f.fk_soc = ".((int) $user->socid);
318  }
319 
320  $resql = $db->query($sql);
321  if ($resql) {
322  $num = $db->num_rows($resql);
323  $i = 0;
324  $total = 0;
325  $dataseries = array();
326 
327  while ($i < $num) {
328  $obj = $db->fetch_object($resql);
329  /*
330  $dataseries = array(array($langs->trans('InvoiceLate30Days'), $obj->nblate30)
331  ,array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30)
332  ,array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15)
333  ,array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15)
334  ,array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30)
335  ,array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30));
336  */
337  $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);
338  $i++;
339  }
340  if (!empty($dataseries[0])) {
341  foreach ($dataseries[0] as $key => $value) {
342  if (is_numeric($value)) {
343  $total += $value;
344  }
345  }
346  }
347  $legend = array(
348  $langs->trans('InvoiceLate30Days'),
349  $langs->trans('InvoiceLate15Days'),
350  $langs->trans('InvoiceLateMinus15Days'),
351  $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
352  $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
353  $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
354  );
355 
356  $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
357 
358  $result = '<div class="div-table-responsive-no-min">';
359  $result .= '<table class="noborder nohover centpercent">';
360  $result .= '<tr class="liste_titre">';
361  $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
362  if ($mode == 'customers') {
363  $result .= $langs->trans("CustomerInvoice");
364  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
365  $result .= $langs->trans("SupplierInvoice");
366  } else {
367  return '';
368  }
369  $result .= '</td>';
370  $result .= '</tr>';
371 
372  if ($conf->use_javascript_ajax) {
373  //var_dump($dataseries);
374  $dolgraph = new DolGraph();
375  $dolgraph->SetData($dataseries);
376 
377  $dolgraph->setLegend($legend);
378 
379  $dolgraph->SetDataColor(array_values($colorseries));
380  $dolgraph->setShowLegend(2);
381  $dolgraph->setShowPercent(1);
382  $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
383  //$dolgraph->SetType(array('pie'));
384  $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
385  $dolgraph->setWidth('450');
386  $dolgraph->setHideXValues(true);
387  if ($mode == 'customers') {
388  $dolgraph->draw('idgraphcustomerinvoices');
389  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
390  $dolgraph->draw('idgraphfourninvoices');
391  } else {
392  return '';
393  }
394  $result .= '<tr maxwidth="255">';
395  $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
396  $result .= '</tr>';
397  } else {
398  // Print text lines
399  }
400 
401  $result .= '</table>';
402  $result .= '</div>';
403 
404  return $result;
405  } else {
406  dol_print_error($db);
407  }
408  }
409 }
417 function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
418 {
419  global $conf, $db, $langs, $user, $hookmanager;
420 
421  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
422 
423  $result = '';
424  $tmpinvoice = new Facture($db);
425 
426  $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
427  $sql .= ", f.type, f.fk_statut as status, f.paye";
428  $sql .= ", s.nom as name";
429  $sql .= ", s.rowid as socid, s.email";
430  $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
431  $sql .= ", cc.rowid as country_id, cc.code as country_code";
432  if (empty($user->rights->societe->client->voir) && !$socid) {
433  $sql .= ", sc.fk_soc, sc.fk_user ";
434  }
435  $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";
436  if (empty($user->rights->societe->client->voir) && !$socid) {
437  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
438  }
439  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
440  $sql .= " AND f.entity IN (".getEntity('invoice').")";
441  if (empty($user->rights->societe->client->voir) && !$socid) {
442  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
443  }
444 
445  if ($socid) {
446  $sql .= " AND f.fk_soc = ".((int) $socid);
447  }
448  // Add where from hooks
449  $parameters = array();
450  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
451  $sql .= $hookmanager->resPrint;
452 
453  $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,";
454  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
455  $sql .= " cc.rowid, cc.code";
456  if (empty($user->rights->societe->client->voir) && !$socid) {
457  $sql .= ", sc.fk_soc, sc.fk_user";
458  }
459 
460  // Add Group from hooks
461  $parameters = array();
462  $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
463  $sql .= $hookmanager->resPrint;
464 
465  $resql = $db->query($sql);
466 
467  if ($resql) {
468  $num = $db->num_rows($resql);
469  $nbofloop = min($num, $maxofloop);
470 
471  $result .= '<div class="div-table-responsive-no-min">';
472  $result .= '<table class="noborder centpercent">';
473 
474  $result .= '<tr class="liste_titre">';
475  $result .= '<th colspan="3">';
476  $result .= $langs->trans("CustomersDraftInvoices").' ';
477  $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
478  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
479  $result .= '</a>';
480  $result .= '</th>';
481  $result .= '</tr>';
482 
483  if ($num) {
484  $companystatic = new Societe($db);
485 
486  $i = 0;
487  $othernb = 0;
488  $tot_ttc = 0;
489  while ($i < $nbofloop) {
490  $obj = $db->fetch_object($resql);
491 
492  if ($i >= $maxCount) {
493  $othernb += 1;
494  $i++;
495  $tot_ttc += $obj->total_ttc;
496  continue;
497  }
498 
499  $tmpinvoice->id = $obj->rowid;
500  $tmpinvoice->ref = $obj->ref;
501  $tmpinvoice->date = $db->jdate($obj->date);
502  $tmpinvoice->type = $obj->type;
503  $tmpinvoice->total_ht = $obj->total_ht;
504  $tmpinvoice->total_tva = $obj->total_tva;
505  $tmpinvoice->total_ttc = $obj->total_ttc;
506  $tmpinvoice->ref_client = $obj->ref_client;
507  $tmpinvoice->statut = $obj->status;
508  $tmpinvoice->paye = $obj->paye;
509 
510  $companystatic->id = $obj->socid;
511  $companystatic->name = $obj->name;
512  $companystatic->email = $obj->email;
513  $companystatic->country_id = $obj->country_id;
514  $companystatic->country_code = $obj->country_code;
515  $companystatic->client = 1;
516  $companystatic->code_client = $obj->code_client;
517  $companystatic->code_fournisseur = $obj->code_fournisseur;
518  $companystatic->code_compta = $obj->code_compta;
519  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
520 
521  $result .= '<tr class="oddeven">';
522  $result .= '<td class="nowrap tdoverflowmax100">';
523  $result .= $tmpinvoice->getNomUrl(1, '');
524  $result .= '</td>';
525  $result .= '<td class="nowrap tdoverflowmax100">';
526  $result .= $companystatic->getNomUrl(1, 'customer');
527  $result .= '</td>';
528  $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
529  $result .= '</tr>';
530  $tot_ttc += $obj->total_ttc;
531  $i++;
532  }
533 
534  if ($othernb) {
535  $result .= '<tr class="oddeven">';
536  $result .= '<td class="nowrap" colspan="3">';
537  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
538  $result .= '</td>';
539  $result .= "</tr>\n";
540  }
541 
542  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
543  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
544  $result .= '</tr>';
545  } else {
546  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
547  }
548  $result .= "</table></div>";
549  $db->free($resql);
550  } else {
551  dol_print_error($db);
552  }
553 
554  return $result;
555 }
556 
564 function getDraftSupplierTable($maxCount = 500, $socid = 0)
565 {
566  global $conf, $db, $langs, $user, $hookmanager;
567 
568  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
569 
570  $result = '';
571  $facturesupplierstatic = new FactureFournisseur($db);
572 
573  $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";
574  $sql .= ", s.nom as name";
575  $sql .= ", s.rowid as socid, s.email";
576  $sql .= ", s.code_client, s.code_compta";
577  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
578  $sql .= ", cc.rowid as country_id, cc.code as country_code";
579  $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";
580  if (empty($user->rights->societe->client->voir) && !$socid) {
581  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
582  }
583  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
584  $sql .= " AND f.entity IN (".getEntity('invoice').')';
585  if (empty($user->rights->societe->client->voir) && !$socid) {
586  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
587  }
588  if ($socid) {
589  $sql .= " AND f.fk_soc = ".((int) $socid);
590  }
591  // Add where from hooks
592  $parameters = array();
593  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
594  $sql .= $hookmanager->resPrint;
595  $resql = $db->query($sql);
596 
597  if ($resql) {
598  $num = $db->num_rows($resql);
599  $nbofloop = min($num, $maxofloop);
600 
601  $result .= '<div class="div-table-responsive-no-min">';
602  $result .= '<table class="noborder centpercent">';
603 
604  $result .= '<tr class="liste_titre">';
605  $result .= '<th colspan="3">';
606  $result .= $langs->trans("SuppliersDraftInvoices").' ';
607  $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
608  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
609  $result .= '</a>';
610  $result .= '</th>';
611  $result .= '</tr>';
612 
613  if ($num) {
614  $companystatic = new Societe($db);
615 
616  $i = 0;
617  $othernb = 0;
618  $tot_ttc = 0;
619  while ($i < $nbofloop) {
620  $obj = $db->fetch_object($resql);
621 
622  if ($i >= $maxCount) {
623  $othernb += 1;
624  $i++;
625  $tot_ttc += $obj->total_ttc;
626  continue;
627  }
628 
629  $facturesupplierstatic->ref = $obj->ref;
630  $facturesupplierstatic->id = $obj->rowid;
631  $facturesupplierstatic->total_ht = $obj->total_ht;
632  $facturesupplierstatic->total_tva = $obj->total_tva;
633  $facturesupplierstatic->total_ttc = $obj->total_ttc;
634  $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
635  $facturesupplierstatic->type = $obj->type;
636  $facturesupplierstatic->statut = $obj->status;
637  $facturesupplierstatic->paye = $obj->paye;
638 
639  $companystatic->id = $obj->socid;
640  $companystatic->name = $obj->name;
641  $companystatic->email = $obj->email;
642  $companystatic->country_id = $obj->country_id;
643  $companystatic->country_code = $obj->country_code;
644  $companystatic->fournisseur = 1;
645  $companystatic->code_client = $obj->code_client;
646  $companystatic->code_fournisseur = $obj->code_fournisseur;
647  $companystatic->code_compta = $obj->code_compta;
648  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
649 
650  $result .= '<tr class="oddeven">';
651  $result .= '<td class="nowrap tdoverflowmax100">';
652  $result .= $facturesupplierstatic->getNomUrl(1, '');
653  $result .= '</td>';
654  $result .= '<td class="nowrap tdoverflowmax100">';
655  $result .= $companystatic->getNomUrl(1, 'supplier');
656  $result .= '</td>';
657  $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
658  $result .= '</tr>';
659  $tot_ttc += $obj->total_ttc;
660  $i++;
661  }
662 
663  if ($othernb) {
664  $result .= '<tr class="oddeven">';
665  $result .= '<td class="nowrap" colspan="3">';
666  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
667  $result .= '</td>';
668  $result .= "</tr>\n";
669  }
670 
671  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
672  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
673  $result .= '</tr>';
674  } else {
675  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
676  }
677  $result .= "</table></div>";
678  $db->free($resql);
679  } else {
680  dol_print_error($db);
681  }
682 
683  return $result;
684 }
685 
686 
694 function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
695 {
696  global $conf, $db, $langs, $user;
697 
698  $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,";
699  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
700  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
701  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
702  if (empty($user->rights->societe->client->voir) && !$socid) {
703  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
704  }
705  $sql .= " WHERE f.fk_soc = s.rowid";
706  $sql .= " AND f.entity IN (".getEntity('facture').")";
707  if ($socid) {
708  $sql .= " AND f.fk_soc = ".((int) $socid);
709  }
710  if (empty($user->rights->societe->client->voir) && !$socid) {
711  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
712  }
713  $sql .= " ORDER BY f.tms DESC";
714  $sql .= $db->plimit($maxCount, 0);
715 
716  $resql = $db->query($sql);
717  if (!$resql) {
718  dol_print_error($db);
719  }
720 
721  $num = $db->num_rows($resql);
722 
723  $result = '<div class="div-table-responsive-no-min">';
724  $result .= '<table class="noborder centpercent">';
725 
726  $result .= '<tr class="liste_titre">';
727  $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
728  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
729  $result .= '<th class="right"></th>';
730  $result .= '</tr>';
731 
732  if ($num < 1) {
733  $result .= '</table>';
734  $result .= '</div>';
735  return $result;
736  }
737 
738  $formfile = new FormFile($db);
739  $objectstatic = new Facture($db);
740  $companystatic = new Societe($db);
741  $i = 0;
742 
743  while ($i < $num) {
744  $obj = $db->fetch_object($resql);
745 
746  $objectstatic->id = $obj->rowid;
747  $objectstatic->ref = $obj->ref;
748  $objectstatic->paye = $obj->paye;
749  $objectstatic->statut = $obj->status;
750  $objectstatic->total_ht = $obj->total_ht;
751  $objectstatic->total_tva = $obj->total_tva;
752  $objectstatic->total_ttc = $obj->total_ttc;
753  $objectstatic->type = $obj->type;
754 
755  $companystatic->id = $obj->socid;
756  $companystatic->name = $obj->socname;
757  $companystatic->client = $obj->client;
758  $companystatic->canvas = $obj->canvas;
759 
760  $filename = dol_sanitizeFileName($obj->ref);
761  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
762 
763  $result .= '<tr class="nowrap">';
764 
765  $result .= '<td class="oddeven">';
766  $result .= '<table class="nobordernopadding">';
767  $result .= '<tr class="nocellnopadd">';
768 
769  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
770  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
771  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
772 
773  $result .= '</tr>';
774  $result .= '</table>';
775  $result .= '</td>';
776 
777  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
778  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
779  $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
780 
781  // Load amount of existing payment of invoice (needed for complete status)
782  $payment = $objectstatic->getSommePaiement();
783  $result .= '<td class="right">'.$objectstatic->getLibStatut(5, $payment).'</td>';
784 
785  $result .= '</tr>';
786 
787  $i++;
788  }
789 
790  $result .= '</table>';
791  $result .= '</div>';
792  return $result;
793 }
794 
802 function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
803 {
804  global $conf, $db, $langs, $user;
805 
806  $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,";
807  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
808  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
809  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
810  if (empty($user->rights->societe->client->voir) && !$socid) {
811  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
812  }
813  $sql .= " WHERE f.fk_soc = s.rowid";
814  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
815  if ($socid) {
816  $sql .= " AND f.fk_soc = ".((int) $socid);
817  }
818  if (empty($user->rights->societe->client->voir) && !$socid) {
819  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
820  }
821  $sql .= " ORDER BY f.tms DESC";
822  $sql .= $db->plimit($maxCount, 0);
823 
824  $resql = $db->query($sql);
825  if (!$resql) {
826  dol_print_error($db);
827  return '';
828  }
829 
830  $num = $db->num_rows($resql);
831 
832  $result = '<div class="div-table-responsive-no-min">';
833  $result .= '<table class="noborder centpercent">';
834  $result .= '<tr class="liste_titre">';
835  $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'</th>';
836  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
837  $result .= '<th class="right"></th>';
838  $result .= '</tr>';
839 
840  if ($num < 1) {
841  $result .= '</table>';
842  $result .= '</div>';
843  return $result;
844  }
845 
846  $objectstatic = new FactureFournisseur($db);
847  $companystatic = new Societe($db);
848  $formfile = new FormFile($db);
849  $i = 0;
850 
851  while ($i < $num) {
852  $obj = $db->fetch_object($resql);
853 
854  $objectstatic->id = $obj->rowid;
855  $objectstatic->ref = $obj->ref;
856  $objectstatic->paye = $obj->paye;
857  $objectstatic->statut = $obj->status;
858  $objectstatic->total_ht = $obj->total_ht;
859  $objectstatic->total_tva = $obj->total_tva;
860  $objectstatic->total_ttc = $obj->total_ttc;
861  $objectstatic->type = $obj->type;
862 
863  $companystatic->id = $obj->socid;
864  $companystatic->name = $obj->socname;
865  $companystatic->client = $obj->client;
866  $companystatic->canvas = $obj->canvas;
867 
868  $filename = dol_sanitizeFileName($obj->ref);
869  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
870 
871  $result .= '<tr class="nowrap">';
872 
873  $result .= '<td class="oddeven">';
874  $result .= '<table class="nobordernopadding">';
875  $result .= '<tr class="nocellnopadd">';
876 
877  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
878  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
879  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
880 
881  $result .= '</tr>';
882  $result .= '</table>';
883  $result .= '</td>';
884 
885  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
886 
887  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
888 
889  $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
890 
891  $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
892 
893  $result .= '</tr>';
894 
895  $i++;
896  }
897 
898  $result .= '</table>';
899  $result .= '</div>';
900  return $result;
901 }
902 
910 function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
911 {
912  global $conf, $db, $langs, $user, $hookmanager;
913 
914  $result = '';
915 
916  if (isModEnabled('facture') && !empty($user->rights->facture->lire)) {
917  $tmpinvoice = new Facture($db);
918 
919  $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";
920  $sql .= ", f.date_lim_reglement as datelimite";
921  $sql .= ", s.nom as name";
922  $sql .= ", s.rowid as socid, s.email";
923  $sql .= ", s.code_client, s.code_compta";
924  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
925  $sql .= ", cc.rowid as country_id, cc.code as country_code";
926  $sql .= ", sum(pf.amount) as am";
927  $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";
928  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
929  if (empty($user->rights->societe->client->voir) && !$socid) {
930  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
931  }
932  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
933  $sql .= " AND f.entity IN (".getEntity('invoice').')';
934  if (empty($user->rights->societe->client->voir) && !$socid) {
935  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
936  }
937  if ($socid) {
938  $sql .= " AND f.fk_soc = ".((int) $socid);
939  }
940  // Add where from hooks
941  $parameters = array();
942  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
943  $sql .= $hookmanager->resPrint;
944 
945  $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,";
946  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
947  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
948  $sql .= " ORDER BY f.datef ASC, f.ref ASC";
949 
950  $resql = $db->query($sql);
951  if ($resql) {
952  $num = $db->num_rows($resql);
953  $i = 0;
954  $othernb = 0;
955 
956  $formfile = new FormFile($db);
957 
958  print '<div class="div-table-responsive-no-min">';
959  print '<table class="noborder centpercent">';
960 
961  print '<tr class="liste_titre">';
962  print '<th colspan="2">';
963  print $langs->trans("BillsCustomersUnpaid", $num).' ';
964  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
965  print '<span class="badge">'.$num.'</span>';
966  print '</a>';
967  print '</th>';
968 
969  print '<th class="right">'.$langs->trans("DateDue").'</th>';
970  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
971  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
972  }
973  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
974  print '<th class="right">'.$langs->trans("Received").'</th>';
975  print '<th width="16">&nbsp;</th>';
976  print '</tr>';
977  if ($num) {
978  $societestatic = new Societe($db);
979  $total_ttc = $totalam = $total = 0;
980  while ($i < $num) {
981  $obj = $db->fetch_object($resql);
982 
983  if ($i >= $maxCount) {
984  $othernb += 1;
985  $i++;
986  $total += $obj->total_ht;
987  $total_ttc += $obj->total_ttc;
988  $totalam += $obj->am;
989  continue;
990  }
991 
992  $tmpinvoice->ref = $obj->ref;
993  $tmpinvoice->id = $obj->rowid;
994  $tmpinvoice->total_ht = $obj->total_ht;
995  $tmpinvoice->total_tva = $obj->total_tva;
996  $tmpinvoice->total_ttc = $obj->total_ttc;
997  $tmpinvoice->type = $obj->type;
998  $tmpinvoice->statut = $obj->status;
999  $tmpinvoice->paye = $obj->paye;
1000  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1001 
1002  $societestatic->id = $obj->socid;
1003  $societestatic->name = $obj->name;
1004  $societestatic->email = $obj->email;
1005  $societestatic->country_id = $obj->country_id;
1006  $societestatic->country_code = $obj->country_code;
1007  $societestatic->client = 1;
1008  $societestatic->code_client = $obj->code_client;
1009  $societestatic->code_fournisseur = $obj->code_fournisseur;
1010  $societestatic->code_compta = $obj->code_compta;
1011  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1012 
1013  print '<tr class="oddeven">';
1014  print '<td class="nowrap">';
1015 
1016  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1017  print '<td class="nobordernopadding nowrap">';
1018  print $tmpinvoice->getNomUrl(1, '');
1019  print '</td>';
1020  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1021  $filename = dol_sanitizeFileName($obj->ref);
1022  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1023  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1024  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1025  print '</td></tr></table>';
1026 
1027  print '</td>';
1028  print '<td class="nowrap tdoverflowmax100">';
1029  print $societestatic->getNomUrl(1, 'customer');
1030  print '</td>';
1031  print '<td class="right">';
1032  print dol_print_date($db->jdate($obj->datelimite), 'day');
1033  if ($tmpinvoice->hasDelay()) {
1034  print img_warning($langs->trans("Late"));
1035  }
1036  print '</td>';
1037  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1038  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1039  }
1040  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1041  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1042  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1043  print '</tr>';
1044 
1045  $total_ttc += $obj->total_ttc;
1046  $total += $obj->total_ht;
1047  $totalam += $obj->am;
1048 
1049  $i++;
1050  }
1051 
1052  if ($othernb) {
1053  $colspan = 6;
1054  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1055  $colspan++;
1056  }
1057  print '<tr class="oddeven">';
1058  print '<td class="nowrap" colspan="'.$colspan.'">';
1059  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1060  print '</td>';
1061  print "</tr>\n";
1062  }
1063 
1064  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>';
1065  print '<td>&nbsp;</td>';
1066  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1067  print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1068  }
1069  print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1070  print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1071  print '<td>&nbsp;</td>';
1072  print '</tr>';
1073  } else {
1074  $colspan = 6;
1075  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1076  $colspan++;
1077  }
1078  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1079  }
1080  print '</table></div><br>';
1081  $db->free($resql);
1082  } else {
1083  dol_print_error($db);
1084  }
1085  }
1086 
1087  return $result;
1088 }
1089 
1090 
1098 function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1099 {
1100  global $conf, $db, $langs, $user, $hookmanager;
1101 
1102  $result = '';
1103 
1104  if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (isModEnabled("supplier_invoice") && $user->rights->supplier_invoice->lire)) {
1105  $facstatic = new FactureFournisseur($db);
1106 
1107  $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";
1108  $sql .= ", ff.date_lim_reglement";
1109  $sql .= ", s.nom as name";
1110  $sql .= ", s.rowid as socid, s.email";
1111  $sql .= ", s.code_client, s.code_compta";
1112  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1113  $sql .= ", sum(pf.amount) as am";
1114  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1115  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1116  if (empty($user->rights->societe->client->voir) && !$socid) {
1117  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1118  }
1119  $sql .= " WHERE s.rowid = ff.fk_soc";
1120  $sql .= " AND ff.entity = ".$conf->entity;
1121  $sql .= " AND ff.paye = 0";
1122  $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1123  if (empty($user->rights->societe->client->voir) && !$socid) {
1124  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1125  }
1126  if ($socid) {
1127  $sql .= " AND ff.fk_soc = ".((int) $socid);
1128  }
1129  // Add where from hooks
1130  $parameters = array();
1131  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1132  $sql .= $hookmanager->resPrint;
1133 
1134  $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,";
1135  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1136  $sql .= " ORDER BY ff.date_lim_reglement ASC";
1137 
1138  $resql = $db->query($sql);
1139  if ($resql) {
1140  $num = $db->num_rows($resql);
1141  $othernb = 0;
1142 
1143  $formfile = new FormFile($db);
1144 
1145  print '<div class="div-table-responsive-no-min">';
1146  print '<table class="noborder centpercent">';
1147 
1148  print '<tr class="liste_titre">';
1149  print '<th colspan="2">';
1150  print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1151  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1152  print '<span class="badge">'.$num.'</span>';
1153  print '</a>';
1154  print '</th>';
1155 
1156  print '<th class="right">'.$langs->trans("DateDue").'</th>';
1157  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1158  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1159  }
1160  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1161  print '<th class="right">'.$langs->trans("Paid").'</th>';
1162  print '<th width="16">&nbsp;</th>';
1163  print "</tr>\n";
1164  $societestatic = new Societe($db);
1165  if ($num) {
1166  $i = 0;
1167  $total = $total_ttc = $totalam = 0;
1168  while ($i < $num) {
1169  $obj = $db->fetch_object($resql);
1170 
1171  if ($i >= $maxCount) {
1172  $othernb += 1;
1173  $i++;
1174  $total += $obj->total_ht;
1175  $total_ttc += $obj->total_ttc;
1176  continue;
1177  }
1178 
1179  $facstatic->ref = $obj->ref;
1180  $facstatic->id = $obj->rowid;
1181  $facstatic->type = $obj->type;
1182  $facstatic->total_ht = $obj->total_ht;
1183  $facstatic->total_tva = $obj->total_tva;
1184  $facstatic->total_ttc = $obj->total_ttc;
1185  $facstatic->statut = $obj->status;
1186  $facstatic->paye = $obj->paye;
1187 
1188  $societestatic->id = $obj->socid;
1189  $societestatic->name = $obj->name;
1190  $societestatic->email = $obj->email;
1191  $societestatic->client = 0;
1192  $societestatic->fournisseur = 1;
1193  $societestatic->code_client = $obj->code_client;
1194  $societestatic->code_fournisseur = $obj->code_fournisseur;
1195  $societestatic->code_compta = $obj->code_compta;
1196  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1197 
1198  print '<tr class="oddeven">';
1199  print '<td class="nowrap tdoverflowmax100">';
1200  print $facstatic->getNomUrl(1, '');
1201  print '</td>';
1202  print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1203  print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1204  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1205  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1206  }
1207  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1208  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1209  print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1210  print '</tr>';
1211  $total += $obj->total_ht;
1212  $total_ttc += $obj->total_ttc;
1213  $totalam += $obj->am;
1214  $i++;
1215  }
1216 
1217  if ($othernb) {
1218  $colspan = 6;
1219  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1220  $colspan++;
1221  }
1222  print '<tr class="oddeven">';
1223  print '<td class="nowrap" colspan="'.$colspan.'">';
1224  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1225  print '</td>';
1226  print "</tr>\n";
1227  }
1228 
1229  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>';
1230  print '<td>&nbsp;</td>';
1231  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1232  print '<td class="right">'.price($total).'</td>';
1233  }
1234  print '<td class="nowrap right">'.price($total_ttc).'</td>';
1235  print '<td class="nowrap right">'.price($totalam).'</td>';
1236  print '<td>&nbsp;</td>';
1237  print '</tr>';
1238  } else {
1239  $colspan = 6;
1240  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1241  $colspan++;
1242  }
1243  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1244  }
1245  print '</table></div><br>';
1246  } else {
1247  dol_print_error($db);
1248  }
1249  }
1250 
1251  return $result;
1252 }
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.
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.