dolibarr  16.0.1
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_facture_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');
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', 'remove');
127 
128  return $head;
129 }
130 
137 {
138  global $langs, $conf, $user;
139 
140  $h = 0;
141  $head = array();
142 
143  $head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
144  $head[$h][1] = $langs->trans("Miscellaneous");
145  $head[$h][2] = 'general';
146  $h++;
147 
148  $head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
149  $head[$h][1] = $langs->trans("Payments");
150  $head[$h][2] = 'payment';
151  $h++;
152 
153  // Show more tabs from modules
154  // Entries must be declared in modules descriptor with line
155  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
156  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
157  complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
158 
159  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
160  $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
161  $head[$h][2] = 'attributes';
162  $h++;
163 
164  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
165  $head[$h][1] = $langs->trans("ExtraFieldsLines");
166  $head[$h][2] = 'attributeslines';
167  $h++;
168 
169  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_rec_cust_extrafields.php';
170  $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
171  $head[$h][2] = 'attributesrec';
172  $h++;
173 
174  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_rec_cust_extrafields.php';
175  $head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
176  $head[$h][2] = 'attributeslinesrec';
177  $h++;
178 
179  if ($conf->global->INVOICE_USE_SITUATION) { // Warning, implementation is seriously bugged and a new one not compatible is expected to become stable
180  $head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php';
181  $head[$h][1] = $langs->trans("InvoiceSituation");
182  $head[$h][2] = 'situation';
183  $h++;
184  }
185 
186  complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
187 
188  return $head;
189 }
190 
191 
198 function invoice_rec_prepare_head($object)
199 {
200  global $db, $langs, $conf;
201 
202  $h = 0;
203  $head = array();
204 
205  $head[$h][0] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object->id;
206  $head[$h][1] = $langs->trans("RepeatableInvoice");
207  $head[$h][2] = 'card';
208  $h++;
209 
210  // Show more tabs from modules
211  // Entries must be declared in modules descriptor with line
212  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
213  // $this->tabs = array('entity:-tabname); to remove a tab
214  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
215 
216  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
217 
218  return $head;
219 }
220 
228 {
229  global $db, $langs, $conf;
230 
231  $h = 0;
232  $head = array();
233 
234  $head[$h][0] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object->id;
235  $head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
236  $head[$h][2] = 'card';
237  $h++;
238 
239  // Show more tabs from modules
240  // Entries must be declared in modules descriptor with line
241  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
242  // $this->tabs = array('entity:-tabname); to remove a tab
243  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
244 
245  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
246 
247  return $head;
248 }
249 
257 {
258  global $conf, $db, $langs, $user;
259  if (($mode == 'customers' && isModEnabled('facture') && !empty($user->rights->facture->lire))
260  || ($mode = 'suppliers') && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && !empty($user->rights->facture->lire)
261  ) {
262  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
263 
264  $now = date_create(date('Y-m-d', dol_now()));
265  $datenowsub30 = date_create(date('Y-m-d', dol_now()));
266  $datenowsub15 = date_create(date('Y-m-d', dol_now()));
267  $datenowadd30 = date_create(date('Y-m-d', dol_now()));
268  $datenowadd15 = date_create(date('Y-m-d', dol_now()));
269  $interval30days = date_interval_create_from_date_string('30 days');
270  $interval15days = date_interval_create_from_date_string('15 days');
271  date_sub($datenowsub30, $interval30days);
272  date_sub($datenowsub15, $interval15days);
273  date_add($datenowadd30, $interval30days);
274  date_add($datenowadd15, $interval15days);
275 
276  $sql = "SELECT";
277  $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", 1, 0).") as nblate30";
278  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."'", 1, 0).") as nblate15";
279  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."'", 1, 0).") as nblatenow";
280  $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";
281  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd15, 'Y-m-d')."'", 1, 0).") as nbnotlate15";
282  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd30, 'Y-m-d')."'", 1, 0).") as nbnotlate30";
283  if ($mode == 'customers') {
284  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
285  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
286  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
287  } else {
288  return '';
289  }
290  $sql .= " WHERE f.type <> 2";
291  $sql .= " AND f.fk_statut = 1";
292  if (isset($user->socid) && $user->socid > 0) {
293  $sql .= " AND f.fk_soc = ".((int) $user->socid);
294  }
295 
296  $resql = $db->query($sql);
297  if ($resql) {
298  $num = $db->num_rows($resql);
299  $i = 0;
300  $total = 0;
301  $dataseries = array();
302 
303  while ($i < $num) {
304  $obj = $db->fetch_object($resql);
305  /*
306  $dataseries = array(array($langs->trans('InvoiceLate30Days'), $obj->nblate30)
307  ,array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30)
308  ,array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15)
309  ,array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15)
310  ,array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30)
311  ,array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30));
312  */
313  $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);
314  $i++;
315  }
316  if (!empty($dataseries[0])) {
317  foreach ($dataseries[0] as $key => $value) {
318  if (is_numeric($value)) {
319  $total += $value;
320  }
321  }
322  }
323  $legend = array(
324  $langs->trans('InvoiceLate30Days'),
325  $langs->trans('InvoiceLate15Days'),
326  $langs->trans('InvoiceLateMinus15Days'),
327  $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
328  $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
329  $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
330  );
331 
332  $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
333 
334  $result = '<div class="div-table-responsive-no-min">';
335  $result .= '<table class="noborder nohover centpercent">';
336  $result .= '<tr class="liste_titre">';
337  $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
338  if ($mode == 'customers') {
339  $result .= $langs->trans("CustomerInvoice");
340  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
341  $result .= $langs->trans("SupplierInvoice");
342  } else {
343  return '';
344  }
345  $result .= '</td>';
346  $result .= '</tr>';
347 
348  if ($conf->use_javascript_ajax) {
349  //var_dump($dataseries);
350  $dolgraph = new DolGraph();
351  $dolgraph->SetData($dataseries);
352 
353  $dolgraph->setLegend($legend);
354 
355  $dolgraph->SetDataColor(array_values($colorseries));
356  $dolgraph->setShowLegend(2);
357  $dolgraph->setShowPercent(1);
358  $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
359  //$dolgraph->SetType(array('pie'));
360  $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
361  $dolgraph->setWidth('450');
362  $dolgraph->setHideXValues(true);
363  if ($mode == 'customers') {
364  $dolgraph->draw('idgraphcustomerinvoices');
365  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
366  $dolgraph->draw('idgraphfourninvoices');
367  } else {
368  return '';
369  }
370  $result .= '<tr maxwidth="255">';
371  $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
372  $result .= '</tr>';
373  } else {
374  // Print text lines
375  }
376 
377  $result .= '</table>';
378  $result .= '</div>';
379 
380  return $result;
381  } else {
382  dol_print_error($db);
383  }
384  }
385 }
393 function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
394 {
395  global $conf, $db, $langs, $user, $hookmanager;
396 
397  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
398 
399  $result = '';
400  $tmpinvoice = new Facture($db);
401 
402  $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
403  $sql .= ", f.type, f.fk_statut as status, f.paye";
404  $sql .= ", s.nom as name";
405  $sql .= ", s.rowid as socid, s.email";
406  $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
407  $sql .= ", cc.rowid as country_id, cc.code as country_code";
408  if (empty($user->rights->societe->client->voir) && !$socid) {
409  $sql .= ", sc.fk_soc, sc.fk_user ";
410  }
411  $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";
412  if (empty($user->rights->societe->client->voir) && !$socid) {
413  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
414  }
415  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
416  $sql .= " AND f.entity IN (".getEntity('invoice').")";
417  if (empty($user->rights->societe->client->voir) && !$socid) {
418  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
419  }
420 
421  if ($socid) {
422  $sql .= " AND f.fk_soc = ".((int) $socid);
423  }
424  // Add where from hooks
425  $parameters = array();
426  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
427  $sql .= $hookmanager->resPrint;
428 
429  $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,";
430  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
431  $sql .= " cc.rowid, cc.code";
432  if (empty($user->rights->societe->client->voir) && !$socid) {
433  $sql .= ", sc.fk_soc, sc.fk_user";
434  }
435 
436  // Add Group from hooks
437  $parameters = array();
438  $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
439  $sql .= $hookmanager->resPrint;
440 
441  $resql = $db->query($sql);
442 
443  if ($resql) {
444  $num = $db->num_rows($resql);
445  $nbofloop = min($num, $maxofloop);
446 
447  $result .= '<div class="div-table-responsive-no-min">';
448  $result .= '<table class="noborder centpercent">';
449 
450  $result .= '<tr class="liste_titre">';
451  $result .= '<th colspan="3">';
452  $result .= $langs->trans("CustomersDraftInvoices").' ';
453  $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
454  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
455  $result .= '</a>';
456  $result .= '</th>';
457  $result .= '</tr>';
458 
459  if ($num) {
460  $companystatic = new Societe($db);
461 
462  $i = 0;
463  $othernb = 0;
464  $tot_ttc = 0;
465  while ($i < $nbofloop) {
466  $obj = $db->fetch_object($resql);
467 
468  if ($i >= $maxCount) {
469  $othernb += 1;
470  $i++;
471  $tot_ttc += $obj->total_ttc;
472  continue;
473  }
474 
475  $tmpinvoice->id = $obj->rowid;
476  $tmpinvoice->ref = $obj->ref;
477  $tmpinvoice->date = $db->jdate($obj->date);
478  $tmpinvoice->type = $obj->type;
479  $tmpinvoice->total_ht = $obj->total_ht;
480  $tmpinvoice->total_tva = $obj->total_tva;
481  $tmpinvoice->total_ttc = $obj->total_ttc;
482  $tmpinvoice->ref_client = $obj->ref_client;
483  $tmpinvoice->statut = $obj->status;
484  $tmpinvoice->paye = $obj->paye;
485 
486  $companystatic->id = $obj->socid;
487  $companystatic->name = $obj->name;
488  $companystatic->email = $obj->email;
489  $companystatic->country_id = $obj->country_id;
490  $companystatic->country_code = $obj->country_code;
491  $companystatic->client = 1;
492  $companystatic->code_client = $obj->code_client;
493  $companystatic->code_fournisseur = $obj->code_fournisseur;
494  $companystatic->code_compta = $obj->code_compta;
495  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
496 
497  $result .= '<tr class="oddeven">';
498  $result .= '<td class="nowrap tdoverflowmax100">';
499  $result .= $tmpinvoice->getNomUrl(1, '');
500  $result .= '</td>';
501  $result .= '<td class="nowrap tdoverflowmax100">';
502  $result .= $companystatic->getNomUrl(1, 'customer');
503  $result .= '</td>';
504  $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
505  $result .= '</tr>';
506  $tot_ttc += $obj->total_ttc;
507  $i++;
508  }
509 
510  if ($othernb) {
511  $result .= '<tr class="oddeven">';
512  $result .= '<td class="nowrap" colspan="3">';
513  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
514  $result .= '</td>';
515  $result .= "</tr>\n";
516  }
517 
518  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
519  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
520  $result .= '</tr>';
521  } else {
522  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
523  }
524  $result .= "</table></div>";
525  $db->free($resql);
526  } else {
527  dol_print_error($db);
528  }
529 
530  return $result;
531 }
532 
540 function getDraftSupplierTable($maxCount = 500, $socid = 0)
541 {
542  global $conf, $db, $langs, $user, $hookmanager;
543 
544  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
545 
546  $result = '';
547  $facturesupplierstatic = new FactureFournisseur($db);
548 
549  $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";
550  $sql .= ", s.nom as name";
551  $sql .= ", s.rowid as socid, s.email";
552  $sql .= ", s.code_client, s.code_compta";
553  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
554  $sql .= ", cc.rowid as country_id, cc.code as country_code";
555  $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";
556  if (empty($user->rights->societe->client->voir) && !$socid) {
557  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
558  }
559  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
560  $sql .= " AND f.entity IN (".getEntity('invoice').')';
561  if (empty($user->rights->societe->client->voir) && !$socid) {
562  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
563  }
564  if ($socid) {
565  $sql .= " AND f.fk_soc = ".((int) $socid);
566  }
567  // Add where from hooks
568  $parameters = array();
569  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
570  $sql .= $hookmanager->resPrint;
571  $resql = $db->query($sql);
572 
573  if ($resql) {
574  $num = $db->num_rows($resql);
575  $nbofloop = min($num, $maxofloop);
576 
577  $result .= '<div class="div-table-responsive-no-min">';
578  $result .= '<table class="noborder centpercent">';
579 
580  $result .= '<tr class="liste_titre">';
581  $result .= '<th colspan="3">';
582  $result .= $langs->trans("SuppliersDraftInvoices").' ';
583  $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
584  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
585  $result .= '</a>';
586  $result .= '</th>';
587  $result .= '</tr>';
588 
589  if ($num) {
590  $companystatic = new Societe($db);
591 
592  $i = 0;
593  $othernb = 0;
594  $tot_ttc = 0;
595  while ($i < $nbofloop) {
596  $obj = $db->fetch_object($resql);
597 
598  if ($i >= $maxCount) {
599  $othernb += 1;
600  $i++;
601  $tot_ttc += $obj->total_ttc;
602  continue;
603  }
604 
605  $facturesupplierstatic->ref = $obj->ref;
606  $facturesupplierstatic->id = $obj->rowid;
607  $facturesupplierstatic->total_ht = $obj->total_ht;
608  $facturesupplierstatic->total_tva = $obj->total_tva;
609  $facturesupplierstatic->total_ttc = $obj->total_ttc;
610  $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
611  $facturesupplierstatic->type = $obj->type;
612  $facturesupplierstatic->statut = $obj->status;
613  $facturesupplierstatic->paye = $obj->paye;
614 
615  $companystatic->id = $obj->socid;
616  $companystatic->name = $obj->name;
617  $companystatic->email = $obj->email;
618  $companystatic->country_id = $obj->country_id;
619  $companystatic->country_code = $obj->country_code;
620  $companystatic->fournisseur = 1;
621  $companystatic->code_client = $obj->code_client;
622  $companystatic->code_fournisseur = $obj->code_fournisseur;
623  $companystatic->code_compta = $obj->code_compta;
624  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
625 
626  $result .= '<tr class="oddeven">';
627  $result .= '<td class="nowrap tdoverflowmax100">';
628  $result .= $facturesupplierstatic->getNomUrl(1, '');
629  $result .= '</td>';
630  $result .= '<td class="nowrap tdoverflowmax100">';
631  $result .= $companystatic->getNomUrl(1, 'supplier');
632  $result .= '</td>';
633  $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
634  $result .= '</tr>';
635  $tot_ttc += $obj->total_ttc;
636  $i++;
637  }
638 
639  if ($othernb) {
640  $result .= '<tr class="oddeven">';
641  $result .= '<td class="nowrap" colspan="3">';
642  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
643  $result .= '</td>';
644  $result .= "</tr>\n";
645  }
646 
647  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
648  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
649  $result .= '</tr>';
650  } else {
651  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
652  }
653  $result .= "</table></div>";
654  $db->free($resql);
655  } else {
656  dol_print_error($db);
657  }
658 
659  return $result;
660 }
661 
662 
670 function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
671 {
672  global $conf, $db, $langs, $user;
673 
674  $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,";
675  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
676  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
677  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
678  if (empty($user->rights->societe->client->voir) && !$socid) {
679  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
680  }
681  $sql .= " WHERE f.fk_soc = s.rowid";
682  $sql .= " AND f.entity IN (".getEntity('facture').")";
683  if ($socid) {
684  $sql .= " AND f.fk_soc = ".((int) $socid);
685  }
686  if (empty($user->rights->societe->client->voir) && !$socid) {
687  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
688  }
689  $sql .= " ORDER BY f.tms DESC";
690  $sql .= $db->plimit($maxCount, 0);
691 
692  $resql = $db->query($sql);
693  if (!$resql) {
694  dol_print_error($db);
695  }
696 
697  $num = $db->num_rows($resql);
698 
699  $result = '<div class="div-table-responsive-no-min">';
700  $result .= '<table class="noborder centpercent">';
701 
702  $result .= '<tr class="liste_titre">';
703  $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
704  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
705  $result .= '<th class="right"></th>';
706  $result .= '</tr>';
707 
708  if ($num < 1) {
709  $result .= '</table>';
710  $result .= '</div>';
711  return $result;
712  }
713 
714  $formfile = new FormFile($db);
715  $objectstatic = new Facture($db);
716  $companystatic = new Societe($db);
717  $i = 0;
718 
719  while ($i < $num) {
720  $obj = $db->fetch_object($resql);
721 
722  $objectstatic->id = $obj->rowid;
723  $objectstatic->ref = $obj->ref;
724  $objectstatic->paye = $obj->paye;
725  $objectstatic->statut = $obj->status;
726  $objectstatic->total_ht = $obj->total_ht;
727  $objectstatic->total_tva = $obj->total_tva;
728  $objectstatic->total_ttc = $obj->total_ttc;
729  $objectstatic->type = $obj->type;
730 
731  $companystatic->id = $obj->socid;
732  $companystatic->name = $obj->socname;
733  $companystatic->client = $obj->client;
734  $companystatic->canvas = $obj->canvas;
735 
736  $filename = dol_sanitizeFileName($obj->ref);
737  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
738 
739  $result .= '<tr class="nowrap">';
740 
741  $result .= '<td class="oddeven">';
742  $result .= '<table class="nobordernopadding">';
743  $result .= '<tr class="nocellnopadd">';
744 
745  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
746  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
747  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
748 
749  $result .= '</tr>';
750  $result .= '</table>';
751  $result .= '</td>';
752 
753  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
754  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
755  $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
756 
757  // Load amount of existing payment of invoice (needed for complete status)
758  $payment = $objectstatic->getSommePaiement();
759  $result .= '<td class="right">'.$objectstatic->getLibStatut(5, $payment).'</td>';
760 
761  $result .= '</tr>';
762 
763  $i++;
764  }
765 
766  $result .= '</table>';
767  $result .= '</div>';
768  return $result;
769 }
770 
778 function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
779 {
780  global $conf, $db, $langs, $user;
781 
782  $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,";
783  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
784  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
785  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
786  if (empty($user->rights->societe->client->voir) && !$socid) {
787  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
788  }
789  $sql .= " WHERE f.fk_soc = s.rowid";
790  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
791  if ($socid) {
792  $sql .= " AND f.fk_soc = ".((int) $socid);
793  }
794  if (empty($user->rights->societe->client->voir) && !$socid) {
795  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
796  }
797  $sql .= " ORDER BY f.tms DESC";
798  $sql .= $db->plimit($maxCount, 0);
799 
800  $resql = $db->query($sql);
801  if (!$resql) {
802  dol_print_error($db);
803  return '';
804  }
805 
806  $num = $db->num_rows($resql);
807 
808  $result = '<div class="div-table-responsive-no-min">';
809  $result .= '<table class="noborder centpercent">';
810  $result .= '<tr class="liste_titre">';
811  $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'</th>';
812  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
813  $result .= '<th class="right"></th>';
814  $result .= '</tr>';
815 
816  if ($num < 1) {
817  $result .= '</table>';
818  $result .= '</div>';
819  return $result;
820  }
821 
822  $objectstatic = new FactureFournisseur($db);
823  $companystatic = new Societe($db);
824  $formfile = new FormFile($db);
825  $i = 0;
826 
827  while ($i < $num) {
828  $obj = $db->fetch_object($resql);
829 
830  $objectstatic->id = $obj->rowid;
831  $objectstatic->ref = $obj->ref;
832  $objectstatic->paye = $obj->paye;
833  $objectstatic->statut = $obj->status;
834  $objectstatic->total_ht = $obj->total_ht;
835  $objectstatic->total_tva = $obj->total_tva;
836  $objectstatic->total_ttc = $obj->total_ttc;
837  $objectstatic->type = $obj->type;
838 
839  $companystatic->id = $obj->socid;
840  $companystatic->name = $obj->socname;
841  $companystatic->client = $obj->client;
842  $companystatic->canvas = $obj->canvas;
843 
844  $filename = dol_sanitizeFileName($obj->ref);
845  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
846 
847  $result .= '<tr class="nowrap">';
848 
849  $result .= '<td class="oddeven">';
850  $result .= '<table class="nobordernopadding">';
851  $result .= '<tr class="nocellnopadd">';
852 
853  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
854  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
855  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
856 
857  $result .= '</tr>';
858  $result .= '</table>';
859  $result .= '</td>';
860 
861  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
862 
863  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
864 
865  $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
866 
867  $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
868 
869  $result .= '</tr>';
870 
871  $i++;
872  }
873 
874  $result .= '</table>';
875  $result .= '</div>';
876  return $result;
877 }
878 
886 function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
887 {
888  global $conf, $db, $langs, $user, $hookmanager;
889 
890  $result = '';
891 
892  if (isModEnabled('facture') && !empty($user->rights->facture->lire)) {
893  $tmpinvoice = new Facture($db);
894 
895  $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";
896  $sql .= ", f.date_lim_reglement as datelimite";
897  $sql .= ", s.nom as name";
898  $sql .= ", s.rowid as socid, s.email";
899  $sql .= ", s.code_client, s.code_compta";
900  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
901  $sql .= ", cc.rowid as country_id, cc.code as country_code";
902  $sql .= ", sum(pf.amount) as am";
903  $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";
904  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
905  if (empty($user->rights->societe->client->voir) && !$socid) {
906  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
907  }
908  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
909  $sql .= " AND f.entity IN (".getEntity('invoice').')';
910  if (empty($user->rights->societe->client->voir) && !$socid) {
911  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
912  }
913  if ($socid) {
914  $sql .= " AND f.fk_soc = ".((int) $socid);
915  }
916  // Add where from hooks
917  $parameters = array();
918  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
919  $sql .= $hookmanager->resPrint;
920 
921  $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,";
922  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
923  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
924  $sql .= " ORDER BY f.datef ASC, f.ref ASC";
925 
926  $resql = $db->query($sql);
927  if ($resql) {
928  $num = $db->num_rows($resql);
929  $i = 0;
930  $othernb = 0;
931 
932  $formfile = new FormFile($db);
933 
934  print '<div class="div-table-responsive-no-min">';
935  print '<table class="noborder centpercent">';
936 
937  print '<tr class="liste_titre">';
938  print '<th colspan="2">';
939  print $langs->trans("BillsCustomersUnpaid", $num).' ';
940  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
941  print '<span class="badge">'.$num.'</span>';
942  print '</a>';
943  print '</th>';
944 
945  print '<th class="right">'.$langs->trans("DateDue").'</th>';
946  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
947  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
948  }
949  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
950  print '<th class="right">'.$langs->trans("Received").'</th>';
951  print '<th width="16">&nbsp;</th>';
952  print '</tr>';
953  if ($num) {
954  $societestatic = new Societe($db);
955  $total_ttc = $totalam = $total = 0;
956  while ($i < $num) {
957  $obj = $db->fetch_object($resql);
958 
959  if ($i >= $maxCount) {
960  $othernb += 1;
961  $i++;
962  $total += $obj->total_ht;
963  $total_ttc += $obj->total_ttc;
964  $totalam += $obj->am;
965  continue;
966  }
967 
968  $tmpinvoice->ref = $obj->ref;
969  $tmpinvoice->id = $obj->rowid;
970  $tmpinvoice->total_ht = $obj->total_ht;
971  $tmpinvoice->total_tva = $obj->total_tva;
972  $tmpinvoice->total_ttc = $obj->total_ttc;
973  $tmpinvoice->type = $obj->type;
974  $tmpinvoice->statut = $obj->status;
975  $tmpinvoice->paye = $obj->paye;
976  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
977 
978  $societestatic->id = $obj->socid;
979  $societestatic->name = $obj->name;
980  $societestatic->email = $obj->email;
981  $societestatic->country_id = $obj->country_id;
982  $societestatic->country_code = $obj->country_code;
983  $societestatic->client = 1;
984  $societestatic->code_client = $obj->code_client;
985  $societestatic->code_fournisseur = $obj->code_fournisseur;
986  $societestatic->code_compta = $obj->code_compta;
987  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
988 
989  print '<tr class="oddeven">';
990  print '<td class="nowrap">';
991 
992  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
993  print '<td class="nobordernopadding nowrap">';
994  print $tmpinvoice->getNomUrl(1, '');
995  print '</td>';
996  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
997  $filename = dol_sanitizeFileName($obj->ref);
998  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
999  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1000  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1001  print '</td></tr></table>';
1002 
1003  print '</td>';
1004  print '<td class="nowrap tdoverflowmax100">';
1005  print $societestatic->getNomUrl(1, 'customer');
1006  print '</td>';
1007  print '<td class="right">';
1008  print dol_print_date($db->jdate($obj->datelimite), 'day');
1009  if ($tmpinvoice->hasDelay()) {
1010  print img_warning($langs->trans("Late"));
1011  }
1012  print '</td>';
1013  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1014  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1015  }
1016  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1017  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1018  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1019  print '</tr>';
1020 
1021  $total_ttc += $obj->total_ttc;
1022  $total += $obj->total_ht;
1023  $totalam += $obj->am;
1024 
1025  $i++;
1026  }
1027 
1028  if ($othernb) {
1029  $colspan = 6;
1030  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1031  $colspan++;
1032  }
1033  print '<tr class="oddeven">';
1034  print '<td class="nowrap" colspan="'.$colspan.'">';
1035  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1036  print '</td>';
1037  print "</tr>\n";
1038  }
1039 
1040  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>';
1041  print '<td>&nbsp;</td>';
1042  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1043  print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1044  }
1045  print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1046  print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1047  print '<td>&nbsp;</td>';
1048  print '</tr>';
1049  } else {
1050  $colspan = 6;
1051  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1052  $colspan++;
1053  }
1054  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1055  }
1056  print '</table></div><br>';
1057  $db->free($resql);
1058  } else {
1059  dol_print_error($db);
1060  }
1061  }
1062 
1063  return $result;
1064 }
1065 
1066 
1074 function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1075 {
1076  global $conf, $db, $langs, $user, $hookmanager;
1077 
1078  $result = '';
1079 
1080  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (!empty($conf->supplier_invoice->enabled) && $user->rights->supplier_invoice->lire)) {
1081  $facstatic = new FactureFournisseur($db);
1082 
1083  $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";
1084  $sql .= ", ff.date_lim_reglement";
1085  $sql .= ", s.nom as name";
1086  $sql .= ", s.rowid as socid, s.email";
1087  $sql .= ", s.code_client, s.code_compta";
1088  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1089  $sql .= ", sum(pf.amount) as am";
1090  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1091  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1092  if (empty($user->rights->societe->client->voir) && !$socid) {
1093  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1094  }
1095  $sql .= " WHERE s.rowid = ff.fk_soc";
1096  $sql .= " AND ff.entity = ".$conf->entity;
1097  $sql .= " AND ff.paye = 0";
1098  $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1099  if (empty($user->rights->societe->client->voir) && !$socid) {
1100  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1101  }
1102  if ($socid) {
1103  $sql .= " AND ff.fk_soc = ".((int) $socid);
1104  }
1105  // Add where from hooks
1106  $parameters = array();
1107  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1108  $sql .= $hookmanager->resPrint;
1109 
1110  $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,";
1111  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1112  $sql .= " ORDER BY ff.date_lim_reglement ASC";
1113 
1114  $resql = $db->query($sql);
1115  if ($resql) {
1116  $num = $db->num_rows($resql);
1117  $othernb = 0;
1118 
1119  $formfile = new FormFile($db);
1120 
1121  print '<div class="div-table-responsive-no-min">';
1122  print '<table class="noborder centpercent">';
1123 
1124  print '<tr class="liste_titre">';
1125  print '<th colspan="2">';
1126  print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1127  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1128  print '<span class="badge">'.$num.'</span>';
1129  print '</a>';
1130  print '</th>';
1131 
1132  print '<th class="right">'.$langs->trans("DateDue").'</th>';
1133  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1134  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1135  }
1136  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1137  print '<th class="right">'.$langs->trans("Paid").'</th>';
1138  print '<th width="16">&nbsp;</th>';
1139  print "</tr>\n";
1140  $societestatic = new Societe($db);
1141  if ($num) {
1142  $i = 0;
1143  $total = $total_ttc = $totalam = 0;
1144  while ($i < $num) {
1145  $obj = $db->fetch_object($resql);
1146 
1147  if ($i >= $maxCount) {
1148  $othernb += 1;
1149  $i++;
1150  $total += $obj->total_ht;
1151  $total_ttc += $obj->total_ttc;
1152  continue;
1153  }
1154 
1155  $facstatic->ref = $obj->ref;
1156  $facstatic->id = $obj->rowid;
1157  $facstatic->type = $obj->type;
1158  $facstatic->total_ht = $obj->total_ht;
1159  $facstatic->total_tva = $obj->total_tva;
1160  $facstatic->total_ttc = $obj->total_ttc;
1161  $facstatic->statut = $obj->status;
1162  $facstatic->paye = $obj->paye;
1163 
1164  $societestatic->id = $obj->socid;
1165  $societestatic->name = $obj->name;
1166  $societestatic->email = $obj->email;
1167  $societestatic->client = 0;
1168  $societestatic->fournisseur = 1;
1169  $societestatic->code_client = $obj->code_client;
1170  $societestatic->code_fournisseur = $obj->code_fournisseur;
1171  $societestatic->code_compta = $obj->code_compta;
1172  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1173 
1174  print '<tr class="oddeven">';
1175  print '<td class="nowrap tdoverflowmax100">';
1176  print $facstatic->getNomUrl(1, '');
1177  print '</td>';
1178  print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1179  print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1180  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1181  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1182  }
1183  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1184  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1185  print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1186  print '</tr>';
1187  $total += $obj->total_ht;
1188  $total_ttc += $obj->total_ttc;
1189  $totalam += $obj->am;
1190  $i++;
1191  }
1192 
1193  if ($othernb) {
1194  $colspan = 6;
1195  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1196  $colspan++;
1197  }
1198  print '<tr class="oddeven">';
1199  print '<td class="nowrap" colspan="'.$colspan.'">';
1200  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1201  print '</td>';
1202  print "</tr>\n";
1203  }
1204 
1205  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>';
1206  print '<td>&nbsp;</td>';
1207  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1208  print '<td class="right">'.price($total).'</td>';
1209  }
1210  print '<td class="nowrap right">'.price($total_ttc).'</td>';
1211  print '<td class="nowrap right">'.price($totalam).'</td>';
1212  print '<td>&nbsp;</td>';
1213  print '</tr>';
1214  } else {
1215  $colspan = 6;
1216  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1217  $colspan++;
1218  }
1219  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1220  }
1221  print '</table></div><br>';
1222  } else {
1223  dol_print_error($db);
1224  }
1225  }
1226 
1227  return $result;
1228 }
getPurchaseInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid purchase invoices.
dol_now($mode= 'auto')
Return date for now.
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices...
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage suppliers invoices.
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage third parties objects (customers, suppliers, prospects...)
const STATUS_VALIDATED
Validated (need to be paid)
getCustomerInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid customers invoices.
const STATUS_DRAFT
Draft status.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
Class to offer components to list and upload files.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
Class to build graphs.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage invoices.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
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.
invoice_rec_prepare_head($object)
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.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36