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