38 global $db, $langs, $conf, $user;
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';
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');
53 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbContact.
'</span>';
55 $head[$h][2] =
'contact';
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);
67 $obj = $db->fetch_object($resql);
69 $nbStandingOrders = $obj->nb;
74 $langs->load(
"banks");
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>';
81 $head[$h][2] =
'standingorders';
91 if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
93 if (!empty($object->note_private)) {
96 if (!empty($object->note_public)) {
99 $head[$h][0] = DOL_URL_ROOT.
'/compta/facture/note.php?id='.$object->id;
100 $head[$h][1] = $langs->trans(
'Notes');
102 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbNote.
'</span>';
104 $head[$h][2] =
'note';
108 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
109 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
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>';
118 $head[$h][2] =
'documents';
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'))) {
126 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
127 $cachekey =
'count_events_facture_'.$object->id;
129 if (!is_null($dataretrieved)) {
130 $nbEvent = $dataretrieved;
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);
138 $obj = $db->fetch_object($resql);
141 dol_syslog(
'Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
147 $head[$h][1] .= $langs->trans(
"Agenda");
149 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbEvent.
'</span>';
152 $head[$h][2] =
'agenda';
169 global $langs, $conf, $user, $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');
180 $head[$h][0] = DOL_URL_ROOT.
'/admin/facture.php';
181 $head[$h][1] = $langs->trans(
"Miscellaneous");
182 $head[$h][2] =
'general';
185 $head[$h][0] = DOL_URL_ROOT.
'/admin/payment.php';
186 $head[$h][1] = $langs->trans(
"Payments");
187 $head[$h][2] =
'payment';
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>';
202 $head[$h][2] =
'attributes';
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>';
211 $head[$h][2] =
'attributeslines';
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>';
220 $head[$h][2] =
'attributesrec';
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>';
229 $head[$h][2] =
'attributeslinesrec';
233 $head[$h][0] = DOL_URL_ROOT.
'/admin/facture_situation.php';
234 $head[$h][1] = $langs->trans(
"InvoiceSituation");
235 $head[$h][2] =
'situation';
253 global $db, $langs, $conf;
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';
282 global $db, $langs, $conf;
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';
311 global $conf, $db, $langs, $user;
313 if (($mode ==
'customers' && isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire'))
314 || ($mode ==
'suppliers' && (isModEnabled(
'fournisseur') || isModEnabled(
'supplier_invoice')) && $user->hasRight(
'fournisseur',
'facture',
'lire'))
316 include DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/theme_vars.inc.php';
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);
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";
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);
353 $resql = $db->query($sql);
355 $num = $db->num_rows($resql);
358 $dataseries = array();
361 $obj = $db->fetch_object($resql);
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);
373 if (!empty($dataseries[0])) {
374 foreach ($dataseries[0] as $key => $value) {
375 if (is_numeric($value)) {
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"),
389 $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11,
'-'.$badgeStatus11);
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");
405 if ($conf->use_javascript_ajax) {
408 $dolgraph->SetData($dataseries);
410 $dolgraph->setLegend($legend);
412 $dolgraph->SetDataColor(array_values($colorseries));
413 $dolgraph->setShowLegend(2);
414 $dolgraph->setShowPercent(1);
415 $dolgraph->SetType(array(
'bars',
'bars',
'bars',
'bars',
'bars',
'bars'));
417 $dolgraph->setHeight(
'160');
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');
427 $result .=
'<tr maxwidth="255">';
428 $result .=
'<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans(
"NoOpenInvoice")).
'</td>';
434 $result .=
'</table>';
454 global $conf, $db, $langs, $user, $hookmanager;
458 if (isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire')) {
459 $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
461 $tmpinvoice =
new Facture($db);
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 ";
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";
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);
483 $sql .=
" AND f.fk_soc = ".((int) $socid);
486 $parameters = array();
487 $reshook = $hookmanager->executeHooks(
'printFieldListWhereCustomerDraft', $parameters);
488 $sql .= $hookmanager->resPrint;
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";
498 $parameters = array();
499 $reshook = $hookmanager->executeHooks(
'printFieldListGroupByCustomerDraft', $parameters);
500 $sql .= $hookmanager->resPrint;
502 $resql = $db->query($sql);
505 $num = $db->num_rows($resql);
506 $nbofloop = min($num, $maxofloop);
508 $result .=
'<div class="div-table-responsive-no-min">';
509 $result .=
'<table class="noborder centpercent">';
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>';
521 $companystatic =
new Societe($db);
526 while ($i < $nbofloop) {
527 $obj = $db->fetch_object($resql);
529 if ($i >= $maxCount) {
532 $tot_ttc += $obj->total_ttc;
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;
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;
558 $result .=
'<tr class="oddeven">';
559 $result .=
'<td class="nowrap tdoverflowmax100">';
560 $result .= $tmpinvoice->getNomUrl(1,
'');
562 $result .=
'<td class="nowrap tdoverflowmax100">';
563 $result .= $companystatic->getNomUrl(1,
'customer');
565 $result .=
'<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).
'</span></td>';
567 $tot_ttc += $obj->total_ttc;
572 $result .=
'<tr class="oddeven">';
573 $result .=
'<td class="nowrap" colspan="3">';
574 $result .=
'<span class="opacitymedium">'.$langs->trans(
"More").
'...'.($othernb < $maxofloop ?
' ('.$othernb.
')' :
'').
'</span>';
576 $result .=
"</tr>\n";
579 $result .=
'<tr class="liste_total"><td class="left">'.$langs->trans(
"Total").
'</td>';
580 $result .=
'<td colspan="2" class="right">'.price($tot_ttc).
'</td>';
583 $result .=
'<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans(
"NoInvoice").
'</span></td></tr>';
585 $result .=
"</table></div>";
604 global $conf, $db, $langs, $user, $hookmanager;
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);
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";
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);
629 $sql .=
" AND f.fk_soc = ".((int) $socid);
632 $parameters = array();
633 $reshook = $hookmanager->executeHooks(
'printFieldListWhereSupplierDraft', $parameters);
634 $sql .= $hookmanager->resPrint;
635 $resql = $db->query($sql);
638 $num = $db->num_rows($resql);
639 $nbofloop = min($num, $maxofloop);
641 $result .=
'<div class="div-table-responsive-no-min">';
642 $result .=
'<table class="noborder centpercent">';
644 $result .=
'<tr class="liste_titre">';
645 $result .=
'<th colspan="3">';
646 $result .= $langs->trans(
"SuppliersDraftInvoices").
' ';
648 $result .=
'<span class="badge marginleftonlyshort">'.$num.
'</span>';
654 $companystatic =
new Societe($db);
659 while ($i < $nbofloop) {
660 $obj = $db->fetch_object($resql);
662 if ($i >= $maxCount) {
665 $tot_ttc += $obj->total_ttc;
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;
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;
690 $result .=
'<tr class="oddeven">';
691 $result .=
'<td class="nowrap tdoverflowmax100">';
692 $result .= $facturesupplierstatic->getNomUrl(1,
'');
694 $result .=
'<td class="nowrap tdoverflowmax100">';
695 $result .= $companystatic->getNomUrl(1,
'supplier');
697 $result .=
'<td class="right"><span class="amount">'.price($obj->total_ttc).
'</span></td>';
699 $tot_ttc += $obj->total_ttc;
704 $result .=
'<tr class="oddeven">';
705 $result .=
'<td class="nowrap" colspan="3">';
706 $result .=
'<span class="opacitymedium">'.$langs->trans(
"More").
'...'.($othernb < $maxofloop ?
' ('.$othernb.
')' :
'').
'</span>';
708 $result .=
"</tr>\n";
711 $result .=
'<tr class="liste_total"><td class="left">'.$langs->trans(
"Total").
'</td>';
712 $result .=
'<td colspan="2" class="right">'.price($tot_ttc).
'</td>';
715 $result .=
'<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans(
"NoInvoice").
'</span></td></tr>';
717 $result .=
"</table></div>";
737 global $conf, $db, $langs, $user;
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";
746 $sql .=
" WHERE f.fk_soc = s.rowid";
747 $sql .=
" AND f.entity IN (".getEntity(
'facture').
")";
749 $sql .=
" AND f.fk_soc = ".((int) $socid);
751 if (empty($user->rights->societe->client->voir) && !$socid) {
752 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
754 $sql .=
" ORDER BY f.tms DESC";
755 $sql .= $db->plimit($maxCount, 0);
757 $resql = $db->query($sql);
762 $num = $db->num_rows($resql);
764 $result =
'<div class="div-table-responsive-no-min">';
765 $result .=
'<table class="noborder centpercent">';
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>';
774 $result .=
'</table>';
780 $objectstatic =
new Facture($db);
781 $companystatic =
new Societe($db);
785 $obj = $db->fetch_object($resql);
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;
796 $companystatic->id = $obj->socid;
797 $companystatic->name = $obj->socname;
798 $companystatic->client = $obj->client;
799 $companystatic->canvas = $obj->canvas;
802 $filedir = $conf->propal->multidir_output[$obj->entity].
'/'.$filename;
804 $result .=
'<tr class="nowrap">';
806 $result .=
'<td class="oddeven">';
807 $result .=
'<table class="nobordernopadding">';
808 $result .=
'<tr class="nocellnopadd">';
810 $result .=
'<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).
'</td>';
811 $result .=
'<td width="16" class="nobordernopadding nowrap"> </td>';
812 $result .=
'<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).
'</td>';
815 $result .=
'</table>';
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>';
823 $payment = $objectstatic->getSommePaiement();
824 $result .=
'<td class="right">'.$objectstatic->getLibStatut(5, $payment).
'</td>';
831 $result .=
'</table>';
845 global $conf, $db, $langs, $user;
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";
854 $sql .=
" WHERE f.fk_soc = s.rowid";
855 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn').
")";
857 $sql .=
" AND f.fk_soc = ".((int) $socid);
859 if (empty($user->rights->societe->client->voir) && !$socid) {
860 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
862 $sql .=
" ORDER BY f.tms DESC";
863 $sql .= $db->plimit($maxCount, 0);
865 $resql = $db->query($sql);
871 $num = $db->num_rows($resql);
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>';
882 $result .=
'</table>';
888 $companystatic =
new Societe($db);
893 $obj = $db->fetch_object($resql);
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;
904 $companystatic->id = $obj->socid;
905 $companystatic->name = $obj->socname;
906 $companystatic->client = $obj->client;
907 $companystatic->canvas = $obj->canvas;
910 $filedir = $conf->propal->multidir_output[$obj->entity].
'/'.$filename;
912 $result .=
'<tr class="nowrap">';
914 $result .=
'<td class="oddeven">';
915 $result .=
'<table class="nobordernopadding">';
916 $result .=
'<tr class="nocellnopadd">';
918 $result .=
'<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).
'</td>';
919 $result .=
'<td width="16" class="nobordernopadding nowrap"> </td>';
920 $result .=
'<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).
'</td>';
923 $result .=
'</table>';
926 $result .=
'<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1,
'supplier').
'</td>';
928 $result .=
'<td>'.dol_print_date($db->jdate($obj->datec),
'day').
'</td>';
930 $result .=
'<td class="amount right">'.price($obj->total_ttc).
'</td>';
932 $result .=
'<td class="right">'.$objectstatic->getLibStatut(5).
'</td>';
939 $result .=
'</table>';
953 global $conf, $db, $langs, $user, $hookmanager;
957 if (isModEnabled(
'facture') && $user->hasRight(
'facture',
'lire')) {
958 $tmpinvoice =
new Facture($db);
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";
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);
979 $sql .=
" AND f.fk_soc = ".((int) $socid);
982 $parameters = array();
983 $reshook = $hookmanager->executeHooks(
'printFieldListWhereCustomerUnpaid', $parameters);
984 $sql .= $hookmanager->resPrint;
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";
991 $resql = $db->query($sql);
993 $num = $db->num_rows($resql);
999 print
'<div class="div-table-responsive-no-min">';
1000 print
'<table class="noborder centpercent">';
1002 print
'<tr class="liste_titre">';
1003 print
'<th colspan="2">';
1004 print $langs->trans(
"BillsCustomersUnpaid", $num).
' ';
1006 print
'<span class="badge">'.$num.
'</span>';
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>';
1014 print
'<th class="right">'.$langs->trans(
"AmountTTC").
'</th>';
1015 print
'<th class="right">'.$langs->trans(
"Received").
'</th>';
1016 print
'<th width="16"> </th>';
1019 $societestatic =
new Societe($db);
1020 $total_ttc = $totalam = $total = 0;
1022 $obj = $db->fetch_object($resql);
1024 if ($i >= $maxCount) {
1027 $total += $obj->total_ht;
1028 $total_ttc += $obj->total_ttc;
1029 $totalam += $obj->am;
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);
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;
1054 print
'<tr class="oddeven">';
1055 print
'<td class="nowrap">';
1057 print
'<table class="nobordernopadding"><tr class="nocellnopadd">';
1058 print
'<td class="nobordernopadding nowrap">';
1059 print $tmpinvoice->getNomUrl(1,
'');
1061 print
'<td width="16" class="nobordernopadding hideonsmartphone right">';
1064 $urlsource = $_SERVER[
'PHP_SELF'].
'?facid='.$obj->rowid;
1065 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1066 print
'</td></tr></table>';
1069 print
'<td class="nowrap tdoverflowmax100">';
1070 print $societestatic->getNomUrl(1,
'customer');
1072 print
'<td class="right">';
1074 if ($tmpinvoice->hasDelay()) {
1078 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1079 print
'<td class="right"><span class="amount">'.price($obj->total_ht).
'</span></td>';
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>';
1086 $total_ttc += $obj->total_ttc;
1087 $total += $obj->total_ht;
1088 $totalam += $obj->am;
1095 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1098 print
'<tr class="oddeven">';
1099 print
'<td class="nowrap" colspan="'.$colspan.
'">';
1100 print
'<span class="opacitymedium">'.$langs->trans(
"More").
'... ('.$othernb.
')</span>';
1105 print
'<tr class="liste_total"><td colspan="2">'.$langs->trans(
"Total").
' <span style="font-weight: normal">('.$langs->trans(
"RemainderToTake").
': '.
price($total_ttc - $totalam).
')</span> </td>';
1106 print
'<td> </td>';
1107 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1108 print
'<td class="right"><span class="amount">'.price($total).
'</span></td>';
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> </td>';
1116 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1119 print
'<tr class="oddeven"><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoInvoice").
'</td></tr>';
1121 print
'</table></div><br>';
1141 global $conf, $db, $langs, $user, $hookmanager;
1145 if (isModEnabled(
"supplier_invoice") && ($user->hasRight(
'fournisseur',
'facture',
'lire') || $user->hasRight(
'supplier_invoice',
'read'))) {
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";
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);
1168 $sql .=
" AND ff.fk_soc = ".((int) $socid);
1171 $parameters = array();
1172 $reshook = $hookmanager->executeHooks(
'printFieldListWhereSupplierUnpaid', $parameters);
1173 $sql .= $hookmanager->resPrint;
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";
1179 $resql = $db->query($sql);
1181 $num = $db->num_rows($resql);
1186 print
'<div class="div-table-responsive-no-min">';
1187 print
'<table class="noborder centpercent">';
1189 print
'<tr class="liste_titre">';
1190 print
'<th colspan="2">';
1191 print $langs->trans(
"BillsSuppliersUnpaid", $num).
' ';
1193 print
'<span class="badge">'.$num.
'</span>';
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>';
1201 print
'<th class="right">'.$langs->trans(
"AmountTTC").
'</th>';
1202 print
'<th class="right">'.$langs->trans(
"Paid").
'</th>';
1203 print
'<th width="16"> </th>';
1205 $societestatic =
new Societe($db);
1208 $total = $total_ttc = $totalam = 0;
1210 $obj = $db->fetch_object($resql);
1212 if ($i >= $maxCount) {
1215 $total += $obj->total_ht;
1216 $total_ttc += $obj->total_ttc;
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;
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;
1239 print
'<tr class="oddeven">';
1240 print
'<td class="nowrap tdoverflowmax100">';
1241 print $facstatic->getNomUrl(1,
'');
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>';
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>';
1252 $total += $obj->total_ht;
1253 $total_ttc += $obj->total_ttc;
1254 $totalam += $obj->am;
1260 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1263 print
'<tr class="oddeven">';
1264 print
'<td class="nowrap" colspan="'.$colspan.
'">';
1265 print
'<span class="opacitymedium">'.$langs->trans(
"More").
'... ('.$othernb.
')</span>';
1270 print
'<tr class="liste_total"><td colspan="2">'.$langs->trans(
"Total").
' <span style="font-weight: normal">('.$langs->trans(
"RemainderToPay").
': '.
price($total_ttc - $totalam).
')</span> </td>';
1271 print
'<td> </td>';
1272 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1273 print
'<td class="right">'.price($total).
'</td>';
1275 print
'<td class="nowrap right">'.price($total_ttc).
'</td>';
1276 print
'<td class="nowrap right">'.price($totalam).
'</td>';
1277 print
'<td> </td>';
1281 if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
1284 print
'<tr class="oddeven"><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoInvoice").
'</td></tr>';
1286 print
'</table></div><br>';
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)
static count($dbs, $objecttype, $objectid)
Return nb of links.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
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).
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.
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.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.