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