dolibarr  19.0.0-dev
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, $user;
39 
40  $h = 0;
41  $head = array();
42 
43  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/card.php?id='.$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?id='.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 (isModEnabled('prelevement')) {
60  $nbStandingOrders = 0;
61  $sql = "SELECT COUNT(pfd.rowid) as nb";
62  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
63  $sql .= " WHERE pfd.fk_facture = ".((int) $object->id);
64  $sql .= " AND pfd.ext_payment_id IS NULL";
65  $resql = $db->query($sql);
66  if ($resql) {
67  $obj = $db->fetch_object($resql);
68  if ($obj) {
69  $nbStandingOrders = $obj->nb;
70  }
71  } else {
72  dol_print_error($db);
73  }
74  $langs->load("banks");
75 
76  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?id='.urlencode($object->id);
77  $head[$h][1] = $langs->trans('StandingOrders');
78  if ($nbStandingOrders > 0) {
79  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
80  }
81  $head[$h][2] = 'standingorders';
82  $h++;
83  }
84 
85  // Show more tabs from modules
86  // Entries must be declared in modules descriptor with line
87  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
88  // $this->tabs = array('entity:-tabname); to remove a tab
89  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'core');
90 
91  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
92  $nbNote = 0;
93  if (!empty($object->note_private)) {
94  $nbNote++;
95  }
96  if (!empty($object->note_public)) {
97  $nbNote++;
98  }
99  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?id='.$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?id='.$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/agenda.php?id='.$object->id;
122  $head[$h][1] = $langs->trans("Events");
123  if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
124  $nbEvent = 0;
125  // Enable caching of thirdparty count actioncomm
126  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
127  $cachekey = 'count_events_facture_'.$object->id;
128  $dataretrieved = dol_getcache($cachekey);
129  if (!is_null($dataretrieved)) {
130  $nbEvent = $dataretrieved;
131  } else {
132  $sql = "SELECT COUNT(id) as nb";
133  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
134  $sql .= " WHERE fk_element = ".((int) $object->id);
135  $sql .= " AND elementtype = 'invoice'";
136  $resql = $db->query($sql);
137  if ($resql) {
138  $obj = $db->fetch_object($resql);
139  $nbEvent = $obj->nb;
140  } else {
141  dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
142  }
143  dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
144  }
145 
146  $head[$h][1] .= '/';
147  $head[$h][1] .= $langs->trans("Agenda");
148  if ($nbEvent > 0) {
149  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
150  }
151  }
152  $head[$h][2] = 'agenda';
153  $h++;
154 
155  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'external');
156 
157  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'remove');
158 
159  return $head;
160 }
161 
168 {
169  global $langs, $conf, $user, $db;
170 
171  $extrafields = new ExtraFields($db);
172  $extrafields->fetch_name_optionals_label('facture');
173  $extrafields->fetch_name_optionals_label('facturedet');
174  $extrafields->fetch_name_optionals_label('facture_rec');
175  $extrafields->fetch_name_optionals_label('facturedet_rec');
176 
177  $h = 0;
178  $head = array();
179 
180  $head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
181  $head[$h][1] = $langs->trans("Miscellaneous");
182  $head[$h][2] = 'general';
183  $h++;
184 
185  $head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
186  $head[$h][1] = $langs->trans("Payments");
187  $head[$h][2] = 'payment';
188  $h++;
189 
190  // Show more tabs from modules
191  // Entries must be declared in modules descriptor with line
192  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
193  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
194  complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
195 
196  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
197  $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
198  $nbExtrafields = $extrafields->attributes['facture']['count'];
199  if ($nbExtrafields > 0) {
200  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
201  }
202  $head[$h][2] = 'attributes';
203  $h++;
204 
205  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
206  $head[$h][1] = $langs->trans("ExtraFieldsLines");
207  $nbExtrafields = $extrafields->attributes['facturedet']['count'];
208  if ($nbExtrafields > 0) {
209  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
210  }
211  $head[$h][2] = 'attributeslines';
212  $h++;
213 
214  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_rec_cust_extrafields.php';
215  $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
216  $nbExtrafields = $extrafields->attributes['facture_rec']['count'];
217  if ($nbExtrafields > 0) {
218  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
219  }
220  $head[$h][2] = 'attributesrec';
221  $h++;
222 
223  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_rec_cust_extrafields.php';
224  $head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
225  $nbExtrafields = $extrafields->attributes['facturedet_rec']['count'];
226  if ($nbExtrafields > 0) {
227  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
228  }
229  $head[$h][2] = 'attributeslinesrec';
230  $h++;
231 
232  if (!empty($conf->global->INVOICE_USE_SITUATION)) { // Warning, implementation is seriously bugged and a new one not compatible is expected to become stable
233  $head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php';
234  $head[$h][1] = $langs->trans("InvoiceSituation");
235  $head[$h][2] = 'situation';
236  $h++;
237  }
238 
239  complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
240 
241  return $head;
242 }
243 
244 
251 function invoice_rec_prepare_head($object)
252 {
253  global $db, $langs, $conf, $user;
254 
255  $h = 0;
256  $head = array();
257 
258  $head[$h][0] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object->id;
259  $head[$h][1] = $langs->trans("RepeatableInvoice");
260  $head[$h][2] = 'card';
261  $h++;
262 
263  $head[$h][0] = DOL_URL_ROOT.'/compta/facture/agenda-rec.php?id='.$object->id;
264  $head[$h][1] = $langs->trans("Events");
265  if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
266  $nbEvent = 0;
267  // Enable caching of thirdparty count actioncomm
268  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
269  $cachekey = 'count_events_facturerec_'.$object->id;
270  $dataretrieved = dol_getcache($cachekey);
271  if (!is_null($dataretrieved)) {
272  $nbEvent = $dataretrieved;
273  } else {
274  $sql = "SELECT COUNT(id) as nb";
275  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
276  $sql .= " WHERE fk_element = ".((int) $object->id);
277  $sql .= " AND elementtype = 'invoicerec'";
278  $resql = $db->query($sql);
279  if ($resql) {
280  $obj = $db->fetch_object($resql);
281  $nbEvent = $obj->nb;
282  } else {
283  dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
284  }
285  dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
286  }
287 
288  $head[$h][1] .= '/';
289  $head[$h][1] .= $langs->trans("Agenda");
290  if ($nbEvent > 0) {
291  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
292  }
293  }
294  $head[$h][2] = 'agenda';
295  $h++;
296 
297  // Show more tabs from modules
298  // Entries must be declared in modules descriptor with line
299  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
300  // $this->tabs = array('entity:-tabname); to remove a tab
301  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
302 
303  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
304 
305  return $head;
306 }
307 
315 {
316  global $db, $langs, $conf;
317 
318  $h = 0;
319  $head = array();
320 
321  $head[$h][0] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object->id;
322  $head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
323  $head[$h][2] = 'card';
324  $h++;
325 
326  // Show more tabs from modules
327  // Entries must be declared in modules descriptor with line
328  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
329  // $this->tabs = array('entity:-tabname); to remove a tab
330  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
331 
332  complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
333 
334  return $head;
335 }
336 
344 {
345  global $conf, $db, $langs, $user;
346 
347  if (($mode == 'customers' && isModEnabled('facture') && $user->hasRight('facture', 'lire'))
348  || ($mode == 'suppliers' && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('fournisseur', 'facture', 'lire'))
349  ) {
350  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
351 
352  $now = date_create(date('Y-m-d', dol_now()));
353  $datenowsub30 = date_create(date('Y-m-d', dol_now()));
354  $datenowsub15 = date_create(date('Y-m-d', dol_now()));
355  $datenowadd30 = date_create(date('Y-m-d', dol_now()));
356  $datenowadd15 = date_create(date('Y-m-d', dol_now()));
357  $interval30days = date_interval_create_from_date_string('30 days');
358  $interval15days = date_interval_create_from_date_string('15 days');
359  date_sub($datenowsub30, $interval30days);
360  date_sub($datenowsub15, $interval15days);
361  date_add($datenowadd30, $interval30days);
362  date_add($datenowadd15, $interval15days);
363 
364  $sql = "SELECT";
365  $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", 1, 0).") as nblate30";
366  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."'", 1, 0).") as nblate15";
367  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."'", 1, 0).") as nblatenow";
368  $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";
369  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd15, 'Y-m-d')."'", 1, 0).") as nbnotlate15";
370  $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd30, 'Y-m-d')."'", 1, 0).") as nbnotlate30";
371  if ($mode == 'customers') {
372  $element = 'invoice';
373  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
374  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
375  $element = 'supplier_invoice';
376  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
377  } else {
378  return '';
379  }
380  $sql .= " WHERE f.entity IN (".getEntity($element).")";
381  $sql .= " AND f.type <> 2";
382  $sql .= " AND f.fk_statut = 1";
383  if (isset($user->socid) && $user->socid > 0) {
384  $sql .= " AND f.fk_soc = ".((int) $user->socid);
385  }
386 
387  $resql = $db->query($sql);
388  if ($resql) {
389  $num = $db->num_rows($resql);
390  $i = 0;
391  $total = 0;
392  $dataseries = array();
393 
394  while ($i < $num) {
395  $obj = $db->fetch_object($resql);
396  /*
397  $dataseries = array(array($langs->trans('InvoiceLate30Days'), $obj->nblate30)
398  ,array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30)
399  ,array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15)
400  ,array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15)
401  ,array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30)
402  ,array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30));
403  */
404  $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);
405  $i++;
406  }
407  if (!empty($dataseries[0])) {
408  foreach ($dataseries[0] as $key => $value) {
409  if (is_numeric($value)) {
410  $total += $value;
411  }
412  }
413  }
414  $legend = array(
415  $langs->trans('InvoiceLate30Days'),
416  $langs->trans('InvoiceLate15Days'),
417  $langs->trans('InvoiceLateMinus15Days'),
418  $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
419  $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
420  $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
421  );
422 
423  $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
424 
425  $result = '<div class="div-table-responsive-no-min">';
426  $result .= '<table class="noborder nohover centpercent">';
427  $result .= '<tr class="liste_titre">';
428  $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
429  if ($mode == 'customers') {
430  $result .= $langs->trans("CustomerInvoice");
431  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
432  $result .= $langs->trans("SupplierInvoice");
433  } else {
434  return '';
435  }
436  $result .= '</td>';
437  $result .= '</tr>';
438 
439  if ($conf->use_javascript_ajax) {
440  //var_dump($dataseries);
441  $dolgraph = new DolGraph();
442  $dolgraph->SetData($dataseries);
443 
444  $dolgraph->setLegend($legend);
445 
446  $dolgraph->SetDataColor(array_values($colorseries));
447  $dolgraph->setShowLegend(2);
448  $dolgraph->setShowPercent(1);
449  $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
450  //$dolgraph->SetType(array('pie'));
451  $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
452  $dolgraph->setWidth('450');
453  $dolgraph->setHideXValues(true);
454  if ($mode == 'customers') {
455  $dolgraph->draw('idgraphcustomerinvoices');
456  } elseif ($mode == 'fourn' || $mode == 'suppliers') {
457  $dolgraph->draw('idgraphfourninvoices');
458  } else {
459  return '';
460  }
461  $result .= '<tr maxwidth="255">';
462  $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
463  $result .= '</tr>';
464  } else {
465  // Print text lines
466  }
467 
468  $result .= '</table>';
469  $result .= '</div>';
470 
471  return $result;
472  } else {
473  dol_print_error($db);
474  }
475  }
476  return '';
477 }
478 
486 function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
487 {
488  global $conf, $db, $langs, $user, $hookmanager;
489 
490  $result = '';
491 
492  if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
493  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
494 
495  $tmpinvoice = new Facture($db);
496 
497  $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
498  $sql .= ", f.type, f.fk_statut as status, f.paye";
499  $sql .= ", s.nom as name";
500  $sql .= ", s.rowid as socid, s.email";
501  $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
502  $sql .= ", cc.rowid as country_id, cc.code as country_code";
503  if (empty($user->rights->societe->client->voir) && !$socid) {
504  $sql .= ", sc.fk_soc, sc.fk_user ";
505  }
506  $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";
507  if (empty($user->rights->societe->client->voir) && !$socid) {
508  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
509  }
510  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
511  $sql .= " AND f.entity IN (".getEntity('invoice').")";
512  if (empty($user->rights->societe->client->voir) && !$socid) {
513  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
514  }
515 
516  if ($socid) {
517  $sql .= " AND f.fk_soc = ".((int) $socid);
518  }
519  // Add where from hooks
520  $parameters = array();
521  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
522  $sql .= $hookmanager->resPrint;
523 
524  $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,";
525  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
526  $sql .= " cc.rowid, cc.code";
527  if (empty($user->rights->societe->client->voir) && !$socid) {
528  $sql .= ", sc.fk_soc, sc.fk_user";
529  }
530 
531  // Add Group from hooks
532  $parameters = array();
533  $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
534  $sql .= $hookmanager->resPrint;
535 
536  $resql = $db->query($sql);
537 
538  if ($resql) {
539  $num = $db->num_rows($resql);
540  $nbofloop = min($num, $maxofloop);
541 
542  $result .= '<div class="div-table-responsive-no-min">';
543  $result .= '<table class="noborder centpercent">';
544 
545  $result .= '<tr class="liste_titre">';
546  $result .= '<th colspan="3">';
547  $result .= $langs->trans("CustomersDraftInvoices").' ';
548  $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
549  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
550  $result .= '</a>';
551  $result .= '</th>';
552  $result .= '</tr>';
553 
554  if ($num) {
555  $companystatic = new Societe($db);
556 
557  $i = 0;
558  $othernb = 0;
559  $tot_ttc = 0;
560  while ($i < $nbofloop) {
561  $obj = $db->fetch_object($resql);
562 
563  if ($i >= $maxCount) {
564  $othernb += 1;
565  $i++;
566  $tot_ttc += $obj->total_ttc;
567  continue;
568  }
569 
570  $tmpinvoice->id = $obj->rowid;
571  $tmpinvoice->ref = $obj->ref;
572  $tmpinvoice->date = $db->jdate($obj->date);
573  $tmpinvoice->type = $obj->type;
574  $tmpinvoice->total_ht = $obj->total_ht;
575  $tmpinvoice->total_tva = $obj->total_tva;
576  $tmpinvoice->total_ttc = $obj->total_ttc;
577  $tmpinvoice->ref_client = $obj->ref_client;
578  $tmpinvoice->statut = $obj->status;
579  $tmpinvoice->paye = $obj->paye;
580 
581  $companystatic->id = $obj->socid;
582  $companystatic->name = $obj->name;
583  $companystatic->email = $obj->email;
584  $companystatic->country_id = $obj->country_id;
585  $companystatic->country_code = $obj->country_code;
586  $companystatic->client = 1;
587  $companystatic->code_client = $obj->code_client;
588  $companystatic->code_fournisseur = $obj->code_fournisseur;
589  $companystatic->code_compta = $obj->code_compta;
590  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
591 
592  $result .= '<tr class="oddeven">';
593  $result .= '<td class="nowrap tdoverflowmax100">';
594  $result .= $tmpinvoice->getNomUrl(1, '');
595  $result .= '</td>';
596  $result .= '<td class="nowrap tdoverflowmax100">';
597  $result .= $companystatic->getNomUrl(1, 'customer');
598  $result .= '</td>';
599  $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
600  $result .= '</tr>';
601  $tot_ttc += $obj->total_ttc;
602  $i++;
603  }
604 
605  if ($othernb) {
606  $result .= '<tr class="oddeven">';
607  $result .= '<td class="nowrap" colspan="3">';
608  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
609  $result .= '</td>';
610  $result .= "</tr>\n";
611  }
612 
613  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
614  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
615  $result .= '</tr>';
616  } else {
617  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
618  }
619  $result .= "</table></div>";
620  $db->free($resql);
621  } else {
622  dol_print_error($db);
623  }
624  }
625 
626  return $result;
627 }
628 
636 function getDraftSupplierTable($maxCount = 500, $socid = 0)
637 {
638  global $conf, $db, $langs, $user, $hookmanager;
639 
640  $result = '';
641 
642  if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
643  $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
644 
645  $facturesupplierstatic = new FactureFournisseur($db);
646 
647  $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";
648  $sql .= ", s.nom as name";
649  $sql .= ", s.rowid as socid, s.email";
650  $sql .= ", s.code_client, s.code_compta";
651  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
652  $sql .= ", cc.rowid as country_id, cc.code as country_code";
653  $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";
654  if (empty($user->rights->societe->client->voir) && !$socid) {
655  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
656  }
657  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
658  $sql .= " AND f.entity IN (".getEntity('invoice').')';
659  if (empty($user->rights->societe->client->voir) && !$socid) {
660  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
661  }
662  if ($socid) {
663  $sql .= " AND f.fk_soc = ".((int) $socid);
664  }
665  // Add where from hooks
666  $parameters = array();
667  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
668  $sql .= $hookmanager->resPrint;
669  $resql = $db->query($sql);
670 
671  if ($resql) {
672  $num = $db->num_rows($resql);
673  $nbofloop = min($num, $maxofloop);
674 
675  $result .= '<div class="div-table-responsive-no-min">';
676  $result .= '<table class="noborder centpercent">';
677 
678  $result .= '<tr class="liste_titre">';
679  $result .= '<th colspan="3">';
680  $result .= $langs->trans("SuppliersDraftInvoices").' ';
681  $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
682  $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
683  $result .= '</a>';
684  $result .= '</th>';
685  $result .= '</tr>';
686 
687  if ($num) {
688  $companystatic = new Societe($db);
689 
690  $i = 0;
691  $othernb = 0;
692  $tot_ttc = 0;
693  while ($i < $nbofloop) {
694  $obj = $db->fetch_object($resql);
695 
696  if ($i >= $maxCount) {
697  $othernb += 1;
698  $i++;
699  $tot_ttc += $obj->total_ttc;
700  continue;
701  }
702 
703  $facturesupplierstatic->ref = $obj->ref;
704  $facturesupplierstatic->id = $obj->rowid;
705  $facturesupplierstatic->total_ht = $obj->total_ht;
706  $facturesupplierstatic->total_tva = $obj->total_tva;
707  $facturesupplierstatic->total_ttc = $obj->total_ttc;
708  $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
709  $facturesupplierstatic->type = $obj->type;
710  $facturesupplierstatic->statut = $obj->status;
711  $facturesupplierstatic->paye = $obj->paye;
712 
713  $companystatic->id = $obj->socid;
714  $companystatic->name = $obj->name;
715  $companystatic->email = $obj->email;
716  $companystatic->country_id = $obj->country_id;
717  $companystatic->country_code = $obj->country_code;
718  $companystatic->fournisseur = 1;
719  $companystatic->code_client = $obj->code_client;
720  $companystatic->code_fournisseur = $obj->code_fournisseur;
721  $companystatic->code_compta = $obj->code_compta;
722  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
723 
724  $result .= '<tr class="oddeven">';
725  $result .= '<td class="nowrap tdoverflowmax100">';
726  $result .= $facturesupplierstatic->getNomUrl(1, '');
727  $result .= '</td>';
728  $result .= '<td class="nowrap tdoverflowmax100">';
729  $result .= $companystatic->getNomUrl(1, 'supplier');
730  $result .= '</td>';
731  $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
732  $result .= '</tr>';
733  $tot_ttc += $obj->total_ttc;
734  $i++;
735  }
736 
737  if ($othernb) {
738  $result .= '<tr class="oddeven">';
739  $result .= '<td class="nowrap" colspan="3">';
740  $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
741  $result .= '</td>';
742  $result .= "</tr>\n";
743  }
744 
745  $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
746  $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
747  $result .= '</tr>';
748  } else {
749  $result .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
750  }
751  $result .= "</table></div>";
752  $db->free($resql);
753  } else {
754  dol_print_error($db);
755  }
756  }
757 
758  return $result;
759 }
760 
761 
769 function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
770 {
771  global $conf, $db, $langs, $user;
772 
773  $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,";
774  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
775  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
776  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
777  if (empty($user->rights->societe->client->voir) && !$socid) {
778  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
779  }
780  $sql .= " WHERE f.fk_soc = s.rowid";
781  $sql .= " AND f.entity IN (".getEntity('facture').")";
782  if ($socid) {
783  $sql .= " AND f.fk_soc = ".((int) $socid);
784  }
785  if (empty($user->rights->societe->client->voir) && !$socid) {
786  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
787  }
788  $sql .= " ORDER BY f.tms DESC";
789  $sql .= $db->plimit($maxCount, 0);
790 
791  $resql = $db->query($sql);
792  if (!$resql) {
793  dol_print_error($db);
794  }
795 
796  $num = $db->num_rows($resql);
797 
798  $result = '<div class="div-table-responsive-no-min">';
799  $result .= '<table class="noborder centpercent">';
800 
801  $result .= '<tr class="liste_titre">';
802  $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
803  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
804  $result .= '<th class="right"></th>';
805  $result .= '</tr>';
806 
807  if ($num < 1) {
808  $result .= '</table>';
809  $result .= '</div>';
810  return $result;
811  }
812 
813  $formfile = new FormFile($db);
814  $objectstatic = new Facture($db);
815  $companystatic = new Societe($db);
816  $i = 0;
817 
818  while ($i < $num) {
819  $obj = $db->fetch_object($resql);
820 
821  $objectstatic->id = $obj->rowid;
822  $objectstatic->ref = $obj->ref;
823  $objectstatic->paye = $obj->paye;
824  $objectstatic->statut = $obj->status;
825  $objectstatic->total_ht = $obj->total_ht;
826  $objectstatic->total_tva = $obj->total_tva;
827  $objectstatic->total_ttc = $obj->total_ttc;
828  $objectstatic->type = $obj->type;
829 
830  $companystatic->id = $obj->socid;
831  $companystatic->name = $obj->socname;
832  $companystatic->client = $obj->client;
833  $companystatic->canvas = $obj->canvas;
834 
835  $filename = dol_sanitizeFileName($obj->ref);
836  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
837 
838  $result .= '<tr class="nowrap">';
839 
840  $result .= '<td class="oddeven">';
841  $result .= '<table class="nobordernopadding">';
842  $result .= '<tr class="nocellnopadd">';
843 
844  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
845  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
846  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
847 
848  $result .= '</tr>';
849  $result .= '</table>';
850  $result .= '</td>';
851 
852  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
853  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
854  $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
855 
856  // Load amount of existing payment of invoice (needed for complete status)
857  $payment = $objectstatic->getSommePaiement();
858  $result .= '<td class="right">'.$objectstatic->getLibStatut(5, $payment).'</td>';
859 
860  $result .= '</tr>';
861 
862  $i++;
863  }
864 
865  $result .= '</table>';
866  $result .= '</div>';
867  return $result;
868 }
869 
877 function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
878 {
879  global $conf, $db, $langs, $user;
880 
881  $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,";
882  $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
883  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
884  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
885  if (empty($user->rights->societe->client->voir) && !$socid) {
886  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
887  }
888  $sql .= " WHERE f.fk_soc = s.rowid";
889  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
890  if ($socid) {
891  $sql .= " AND f.fk_soc = ".((int) $socid);
892  }
893  if (empty($user->rights->societe->client->voir) && !$socid) {
894  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
895  }
896  $sql .= " ORDER BY f.tms DESC";
897  $sql .= $db->plimit($maxCount, 0);
898 
899  $resql = $db->query($sql);
900  if (!$resql) {
901  dol_print_error($db);
902  return '';
903  }
904 
905  $num = $db->num_rows($resql);
906 
907  $result = '<div class="div-table-responsive-no-min">';
908  $result .= '<table class="noborder centpercent">';
909  $result .= '<tr class="liste_titre">';
910  $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'</th>';
911  $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
912  $result .= '<th class="right"></th>';
913  $result .= '</tr>';
914 
915  if ($num < 1) {
916  $result .= '</table>';
917  $result .= '</div>';
918  return $result;
919  }
920 
921  $objectstatic = new FactureFournisseur($db);
922  $companystatic = new Societe($db);
923  $formfile = new FormFile($db);
924  $i = 0;
925 
926  while ($i < $num) {
927  $obj = $db->fetch_object($resql);
928 
929  $objectstatic->id = $obj->rowid;
930  $objectstatic->ref = $obj->ref;
931  $objectstatic->paye = $obj->paye;
932  $objectstatic->statut = $obj->status;
933  $objectstatic->total_ht = $obj->total_ht;
934  $objectstatic->total_tva = $obj->total_tva;
935  $objectstatic->total_ttc = $obj->total_ttc;
936  $objectstatic->type = $obj->type;
937 
938  $companystatic->id = $obj->socid;
939  $companystatic->name = $obj->socname;
940  $companystatic->client = $obj->client;
941  $companystatic->canvas = $obj->canvas;
942 
943  $filename = dol_sanitizeFileName($obj->ref);
944  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
945 
946  $result .= '<tr class="nowrap">';
947 
948  $result .= '<td class="oddeven">';
949  $result .= '<table class="nobordernopadding">';
950  $result .= '<tr class="nocellnopadd">';
951 
952  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
953  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
954  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
955 
956  $result .= '</tr>';
957  $result .= '</table>';
958  $result .= '</td>';
959 
960  $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
961 
962  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
963 
964  $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
965 
966  $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
967 
968  $result .= '</tr>';
969 
970  $i++;
971  }
972 
973  $result .= '</table>';
974  $result .= '</div>';
975  return $result;
976 }
977 
985 function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
986 {
987  global $conf, $db, $langs, $user, $hookmanager;
988 
989  $result = '';
990 
991  if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
992  $tmpinvoice = new Facture($db);
993 
994  $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";
995  $sql .= ", f.date_lim_reglement as datelimite";
996  $sql .= ", s.nom as name";
997  $sql .= ", s.rowid as socid, s.email";
998  $sql .= ", s.code_client, s.code_compta";
999  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1000  $sql .= ", cc.rowid as country_id, cc.code as country_code";
1001  $sql .= ", sum(pf.amount) as am";
1002  $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";
1003  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1004  if (empty($user->rights->societe->client->voir) && !$socid) {
1005  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1006  }
1007  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1008  $sql .= " AND f.entity IN (".getEntity('invoice').')';
1009  if (empty($user->rights->societe->client->voir) && !$socid) {
1010  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1011  }
1012  if ($socid) {
1013  $sql .= " AND f.fk_soc = ".((int) $socid);
1014  }
1015  // Add where from hooks
1016  $parameters = array();
1017  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1018  $sql .= $hookmanager->resPrint;
1019 
1020  $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,";
1021  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1022  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1023  $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1024 
1025  $resql = $db->query($sql);
1026  if ($resql) {
1027  $num = $db->num_rows($resql);
1028  $i = 0;
1029  $othernb = 0;
1030 
1031  $formfile = new FormFile($db);
1032 
1033  print '<div class="div-table-responsive-no-min">';
1034  print '<table class="noborder centpercent">';
1035 
1036  print '<tr class="liste_titre">';
1037  print '<th colspan="2">';
1038  print $langs->trans("BillsCustomersUnpaid", $num).' ';
1039  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1040  print '<span class="badge">'.$num.'</span>';
1041  print '</a>';
1042  print '</th>';
1043 
1044  print '<th class="right">'.$langs->trans("DateDue").'</th>';
1045  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1046  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1047  }
1048  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1049  print '<th class="right">'.$langs->trans("Received").'</th>';
1050  print '<th width="16">&nbsp;</th>';
1051  print '</tr>';
1052  if ($num) {
1053  $societestatic = new Societe($db);
1054  $total_ttc = $totalam = $total = 0;
1055  while ($i < $num) {
1056  $obj = $db->fetch_object($resql);
1057 
1058  if ($i >= $maxCount) {
1059  $othernb += 1;
1060  $i++;
1061  $total += $obj->total_ht;
1062  $total_ttc += $obj->total_ttc;
1063  $totalam += $obj->am;
1064  continue;
1065  }
1066 
1067  $tmpinvoice->ref = $obj->ref;
1068  $tmpinvoice->id = $obj->rowid;
1069  $tmpinvoice->total_ht = $obj->total_ht;
1070  $tmpinvoice->total_tva = $obj->total_tva;
1071  $tmpinvoice->total_ttc = $obj->total_ttc;
1072  $tmpinvoice->type = $obj->type;
1073  $tmpinvoice->statut = $obj->status;
1074  $tmpinvoice->paye = $obj->paye;
1075  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1076 
1077  $societestatic->id = $obj->socid;
1078  $societestatic->name = $obj->name;
1079  $societestatic->email = $obj->email;
1080  $societestatic->country_id = $obj->country_id;
1081  $societestatic->country_code = $obj->country_code;
1082  $societestatic->client = 1;
1083  $societestatic->code_client = $obj->code_client;
1084  $societestatic->code_fournisseur = $obj->code_fournisseur;
1085  $societestatic->code_compta = $obj->code_compta;
1086  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1087 
1088  print '<tr class="oddeven">';
1089  print '<td class="nowrap">';
1090 
1091  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1092  print '<td class="nobordernopadding nowrap">';
1093  print $tmpinvoice->getNomUrl(1, '');
1094  print '</td>';
1095  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1096  $filename = dol_sanitizeFileName($obj->ref);
1097  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1098  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1099  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1100  print '</td></tr></table>';
1101 
1102  print '</td>';
1103  print '<td class="nowrap tdoverflowmax100">';
1104  print $societestatic->getNomUrl(1, 'customer');
1105  print '</td>';
1106  print '<td class="right">';
1107  print dol_print_date($db->jdate($obj->datelimite), 'day');
1108  if ($tmpinvoice->hasDelay()) {
1109  print img_warning($langs->trans("Late"));
1110  }
1111  print '</td>';
1112  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1113  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1114  }
1115  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1116  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1117  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1118  print '</tr>';
1119 
1120  $total_ttc += $obj->total_ttc;
1121  $total += $obj->total_ht;
1122  $totalam += $obj->am;
1123 
1124  $i++;
1125  }
1126 
1127  if ($othernb) {
1128  $colspan = 6;
1129  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1130  $colspan++;
1131  }
1132  print '<tr class="oddeven">';
1133  print '<td class="nowrap" colspan="'.$colspan.'">';
1134  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1135  print '</td>';
1136  print "</tr>\n";
1137  }
1138 
1139  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>';
1140  print '<td>&nbsp;</td>';
1141  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1142  print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1143  }
1144  print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1145  print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1146  print '<td>&nbsp;</td>';
1147  print '</tr>';
1148  } else {
1149  $colspan = 6;
1150  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1151  $colspan++;
1152  }
1153  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1154  }
1155  print '</table></div><br>';
1156  $db->free($resql);
1157  } else {
1158  dol_print_error($db);
1159  }
1160  }
1161 
1162  return $result;
1163 }
1164 
1165 
1173 function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1174 {
1175  global $conf, $db, $langs, $user, $hookmanager;
1176 
1177  $result = '';
1178 
1179  if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1180  $facstatic = new FactureFournisseur($db);
1181 
1182  $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";
1183  $sql .= ", ff.date_lim_reglement";
1184  $sql .= ", s.nom as name";
1185  $sql .= ", s.rowid as socid, s.email";
1186  $sql .= ", s.code_client, s.code_compta";
1187  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1188  $sql .= ", sum(pf.amount) as am";
1189  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1190  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1191  if (empty($user->rights->societe->client->voir) && !$socid) {
1192  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1193  }
1194  $sql .= " WHERE s.rowid = ff.fk_soc";
1195  $sql .= " AND ff.entity = ".$conf->entity;
1196  $sql .= " AND ff.paye = 0";
1197  $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1198  if (empty($user->rights->societe->client->voir) && !$socid) {
1199  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1200  }
1201  if ($socid) {
1202  $sql .= " AND ff.fk_soc = ".((int) $socid);
1203  }
1204  // Add where from hooks
1205  $parameters = array();
1206  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1207  $sql .= $hookmanager->resPrint;
1208 
1209  $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,";
1210  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1211  $sql .= " ORDER BY ff.date_lim_reglement ASC";
1212 
1213  $resql = $db->query($sql);
1214  if ($resql) {
1215  $num = $db->num_rows($resql);
1216  $othernb = 0;
1217 
1218  $formfile = new FormFile($db);
1219 
1220  print '<div class="div-table-responsive-no-min">';
1221  print '<table class="noborder centpercent">';
1222 
1223  print '<tr class="liste_titre">';
1224  print '<th colspan="2">';
1225  print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1226  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1227  print '<span class="badge">'.$num.'</span>';
1228  print '</a>';
1229  print '</th>';
1230 
1231  print '<th class="right">'.$langs->trans("DateDue").'</th>';
1232  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1233  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1234  }
1235  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1236  print '<th class="right">'.$langs->trans("Paid").'</th>';
1237  print '<th width="16">&nbsp;</th>';
1238  print "</tr>\n";
1239  $societestatic = new Societe($db);
1240  if ($num) {
1241  $i = 0;
1242  $total = $total_ttc = $totalam = 0;
1243  while ($i < $num) {
1244  $obj = $db->fetch_object($resql);
1245 
1246  if ($i >= $maxCount) {
1247  $othernb += 1;
1248  $i++;
1249  $total += $obj->total_ht;
1250  $total_ttc += $obj->total_ttc;
1251  continue;
1252  }
1253 
1254  $facstatic->ref = $obj->ref;
1255  $facstatic->id = $obj->rowid;
1256  $facstatic->type = $obj->type;
1257  $facstatic->total_ht = $obj->total_ht;
1258  $facstatic->total_tva = $obj->total_tva;
1259  $facstatic->total_ttc = $obj->total_ttc;
1260  $facstatic->statut = $obj->status;
1261  $facstatic->paye = $obj->paye;
1262 
1263  $societestatic->id = $obj->socid;
1264  $societestatic->name = $obj->name;
1265  $societestatic->email = $obj->email;
1266  $societestatic->client = 0;
1267  $societestatic->fournisseur = 1;
1268  $societestatic->code_client = $obj->code_client;
1269  $societestatic->code_fournisseur = $obj->code_fournisseur;
1270  $societestatic->code_compta = $obj->code_compta;
1271  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1272 
1273  print '<tr class="oddeven">';
1274  print '<td class="nowrap tdoverflowmax100">';
1275  print $facstatic->getNomUrl(1, '');
1276  print '</td>';
1277  print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1278  print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1279  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1280  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1281  }
1282  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1283  print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1284  print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1285  print '</tr>';
1286  $total += $obj->total_ht;
1287  $total_ttc += $obj->total_ttc;
1288  $totalam += $obj->am;
1289  $i++;
1290  }
1291 
1292  if ($othernb) {
1293  $colspan = 6;
1294  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1295  $colspan++;
1296  }
1297  print '<tr class="oddeven">';
1298  print '<td class="nowrap" colspan="'.$colspan.'">';
1299  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1300  print '</td>';
1301  print "</tr>\n";
1302  }
1303 
1304  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>';
1305  print '<td>&nbsp;</td>';
1306  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1307  print '<td class="right">'.price($total).'</td>';
1308  }
1309  print '<td class="nowrap right">'.price($total_ttc).'</td>';
1310  print '<td class="nowrap right">'.price($totalam).'</td>';
1311  print '<td>&nbsp;</td>';
1312  print '</tr>';
1313  } else {
1314  $colspan = 6;
1315  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1316  $colspan++;
1317  }
1318  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1319  }
1320  print '</table></div><br>';
1321  } else {
1322  dol_print_error($db);
1323  }
1324  }
1325 
1326  return $result;
1327 }
Class to build graphs.
Class to manage standard extra fields.
Class to manage suppliers invoices.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated (need to be paid)
Class to offer components to list and upload files.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:62
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices.
invoice_admin_prepare_head()
Return array head with list of tabs to view object informations.
getCustomerInvoiceLatestEditTable($maxCount=5, $socid=0)
Return a HTML table that contains a list with latest edited customer invoices.
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
getPurchaseInvoiceLatestEditTable($maxCount=5, $socid=0)
Return a HTML table that contains a list with latest edited supplier invoices.
getCustomerInvoiceDraftTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object informations.
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
getCustomerInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid customers invoices.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36
getPurchaseInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid purchase invoices.
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:68
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:140