24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
33 $langs->load(
'bills');
36 $socid =
GETPOST(
'socid',
'int');
37 if (isset($user->socid) && $user->socid > 0)
40 $socid = $user->socid;
44 $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
45 $maxLatestEditCount = 5;
46 $maxOpenCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
52 llxHeader(
"", $langs->trans(
"CustomersInvoicesArea"),
"EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes");
56 print '<div class="fichecenter">';
58 print
'<div class="fichethirdleft">';
61 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))
63 print getAreaSearchFrom();
67 print getPieChart($socid);
69 print getDraftTable($maxDraftCount, $socid);
73 print
'<div class="fichetwothirdright">';
74 print
'<div class="ficheaddleft">';
76 print getLatestEditTable($maxLatestEditCount, $socid);
78 print getOpenTable($maxOpenCount, $socid);
94 function getAreaSearchFrom()
98 $result =
'<form method="post" action="'.DOL_URL_ROOT.
'/compta/facture/list.php">';
99 $result .=
'<div class="div-table-responsive-no-min">';
100 $result .=
'<input type="hidden" name="token" value="'.newToken().
'">';
101 $result .=
'<table class="noborder nohover centpercent">';
103 $result .=
'<tr class="liste_titre">';
104 $result .=
'<td colspan="3">'.$langs->trans(
"Search").
'</td>';
107 $result .=
'<tr class="oddeven">';
108 $result .=
'<td>'.$langs->trans(
"Invoice").
':</td><td><input type="text" class="flat" name="sall" size=18></td>';
109 $result .=
'<td><input type="submit" value="'.$langs->trans(
"Search").
'" class="button"></td>';
112 $result .=
"</table>";
114 $result .=
"</form>";
125 function getPieChart($socid = 0)
127 global $conf, $db, $langs, $user;
129 $sql =
"SELECT count(f.rowid), f.fk_statut";
130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
131 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
132 if (!$user->rights->societe->client->voir && !$socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
133 $sql .=
" WHERE f.fk_soc = s.rowid";
134 $sql .=
" AND f.entity IN (".getEntity(
'facture').
")";
135 if ($user->socid) $sql .=
' AND f.fk_soc = '.$user->socid;
136 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
137 $sql .=
" GROUP BY f.fk_statut";
139 $resql = $db->query($sql);
146 $num = $db->num_rows(
$resql);
154 $row = $db->fetch_row(
$resql);
157 $vals[$row[1]] = $row[0];
166 $result =
'<div class="div-table-responsive-no-min">';
167 $result .=
'<table class="noborder nohover centpercent">';
168 $result .=
'<tr class="liste_titre">';
169 $result .=
'<td colspan="2">'.$langs->trans(
"Statistics").
' - '.$langs->trans(
"CustomerInvoice").
'</td>';
172 $objectstatic =
new Facture($db);
176 foreach ($array as $status)
178 $objectstatic->statut = $status;
179 $objectstatic->paye = $status == Facture::STATUS_CLOSED ? -1 : 0;
181 $dataseries[] = [$objectstatic->getLibStatut(1), (isset($vals[$status]) ? (int) $vals[$status] : 0)];
182 if (!$conf->use_javascript_ajax)
184 $result .=
'<tr class="oddeven">';
185 $result .=
'<td>'.$objectstatic->getLibStatut(0).
'</td>';
186 $result .=
'<td class="right"><a href="list.php?statut='.$status.
'">'.(isset($vals[$status]) ? $vals[$status] : 0).
'</a></td>';
191 if ($conf->use_javascript_ajax)
194 $dolgraph->SetData($dataseries);
195 $dolgraph->setShowLegend(2);
196 $dolgraph->setShowPercent(1);
197 $dolgraph->SetType([
'pie']);
198 $dolgraph->setHeight(
'200');
199 $dolgraph->draw(
'idgraphthirdparties');
202 $result .=
'<td align="center" colspan="2">'.$dolgraph->show($total ? 0 : 1).
'</td>';
206 $result .=
'<tr class="liste_total">';
207 $result .=
'<td>'.$langs->trans(
"Total").
'</td>';
208 $result .=
'<td class="right">'.$total.
'</td>';
211 $result .=
'</table>';
223 function getDraftTable($maxCount = 500, $socid = 0)
225 global $db, $langs, $user;
227 $sql =
"SELECT f.rowid, f.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client, f.total as total_ttc";
228 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
229 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
230 if (!$user->rights->societe->client->voir && !$socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
231 $sql .=
" WHERE f.fk_soc = s.rowid";
232 $sql .=
" AND f.entity IN (".getEntity(
'facture').
")";
233 $sql .=
" AND f.fk_statut = ".Facture::STATUS_DRAFT;
234 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
235 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
236 $sql .= $db->plimit($maxCount, 0);
238 $resql = $db->query($sql);
245 $num = $db->num_rows(
$resql);
247 $result =
'<div class="div-table-responsive-no-min">';
248 $result .=
'<table class="noborder centpercent">';
250 $result .=
'<tr class="liste_titre">';
251 $result .=
'<td colspan="3">';
252 $result .= $langs->trans(
"CustomersDraftInvoices");
253 $result .=
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?search_status=0">';
254 $result .=
'<span class="badge">'.$num.
'</span>';
261 $result .=
'</table>';
266 $objectstatic =
new Facture($db);
267 $companystatic =
new Societe($db);
268 $nbofloop = min($num, $maxCount);
272 while ($i < $nbofloop)
274 $obj = $db->fetch_object(
$resql);
276 $objectstatic->id = $obj->rowid;
277 $objectstatic->ref = $obj->ref;
279 $companystatic->id = $obj->socid;
280 $companystatic->name = $obj->socname;
281 $companystatic->client = $obj->client;
282 $companystatic->canvas = $obj->canvas;
284 $result .=
'<tr class="oddeven">';
285 $result .=
'<td class="nowrap">'.$objectstatic->getNomUrl(1).
'</td>';
286 $result .=
'<td>'.$companystatic->getNomUrl(1,
'customer', 24).
'</td>';
287 $result .=
'<td class="right">'.price($obj->total_ttc).
'</td>';
291 $total += $obj->total_ttc;
294 if ($num > $nbofloop)
296 $result .=
'<tr class="liste_total">';
297 $result .=
'<td colspan="3" class="right">'.$langs->trans(
"XMoreLines", ($num - $nbofloop)).
'</td>';
302 $result .=
'<tr class="liste_total">';
303 $result .=
'<td colspan="2" class="right">'.$langs->trans(
"Total").
'</td>';
304 $result .=
'<td class="right">'.price($total).
'</td>';
308 $result .=
'</table>';
320 function getLatestEditTable($maxCount = 5, $socid = 0)
322 global $conf, $db, $langs, $user;
324 $sql =
"SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
326 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
327 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
328 if (!$user->rights->societe->client->voir && !$socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
329 $sql .=
" WHERE f.fk_soc = s.rowid";
330 $sql .=
" AND f.entity IN (".getEntity(
'facture').
")";
331 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
332 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
333 $sql .=
" ORDER BY f.tms DESC";
334 $sql .= $db->plimit($maxCount, 0);
336 $resql = $db->query($sql);
342 $num = $db->num_rows(
$resql);
344 $result =
'<div class="div-table-responsive-no-min">';
345 $result .=
'<table class="noborder centpercent">';
347 $result .=
'<tr class="liste_titre">';
348 $result .=
'<td colspan="4">'.$langs->trans(
"LastCustomersBills", $maxCount).
'</td>';
353 $result .=
'</table>';
359 $objectstatic =
new Facture($db);
360 $companystatic =
new Societe($db);
365 $obj = $db->fetch_object(
$resql);
367 $objectstatic->id = $obj->rowid;
368 $objectstatic->ref = $obj->ref;
369 $objectstatic->paye = $obj->paye;
370 $objectstatic->statut = $obj->status;
372 $companystatic->id = $obj->socid;
373 $companystatic->name = $obj->socname;
374 $companystatic->client = $obj->client;
375 $companystatic->canvas = $obj->canvas;
378 $filedir = $conf->propal->multidir_output[$obj->entity].
'/'.$filename;
380 $result .=
'<tr width="20%" class="nowrap">';
382 $result .=
'<td class="oddeven">';
383 $result .=
'<table class="nobordernopadding">';
384 $result .=
'<tr class="nocellnopadd">';
386 $result .=
'<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).
'</td>';
387 $result .=
'<td width="16" class="nobordernopadding nowrap"> </td>';
388 $result .=
'<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).
'</td>';
391 $result .=
'</table>';
394 $result .=
'<td>'.$companystatic->getNomUrl(1,
'customer').
'</td>';
395 $result .=
'<td>'.dol_print_date($db->jdate($obj->datec),
'day').
'</td>';
396 $result .=
'<td class="right">'.$objectstatic->getLibStatut(5).
'</td>';
403 $result .=
'</table>';
415 function getOpenTable($maxCount = 500, $socid = 0)
417 global $conf, $db, $langs, $user;
419 $sql =
"SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client";
420 $sql .=
", f.rowid as id, f.entity, f.total as total_ttc, f.total as total_ht, f.ref, f.fk_statut";
421 $sql .=
", f.datef as df, f.date_lim_reglement as datelimite";
422 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
423 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
424 if (!$user->rights->societe->client->voir && !$socid) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
425 $sql .=
" WHERE f.fk_soc = s.rowid";
426 $sql .=
" AND f.entity IN (".getEntity(
'facture').
")";
427 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
428 if (!$user->rights->societe->client->voir && !$socid) $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
429 if ($socid) $sql .=
" AND s.rowid = ".$socid;
430 $sql .=
" ORDER BY f.rowid DESC";
431 $sql .= $db->plimit($maxCount, 0);
433 $resql = $db->query($sql);
439 $num = $db->num_rows(
$resql);
441 $result =
'<div class="div-table-responsive-no-min">';
442 $result .=
'<table class="noborder centpercent">';
444 $result .=
'<tr class="liste_titre">';
445 $result .=
'<td colspan="4">';
446 $result .= $langs->trans(
"BillsCustomersUnpaid");
447 $result .=
' <a href="'.DOL_URL_ROOT.
'/compta/facture/list.php?search_status=1">';
448 $result .=
'<span class="badge">'.$num.
'</span>';
455 $result .=
'</table>';
460 $objectstatic =
new Facture($db);
461 $companystatic =
new Societe($db);
463 $nbofloop = min($num, $maxCount);
468 while ($i < $nbofloop)
470 $obj = $db->fetch_object(
$resql);
472 $objectstatic->id = $obj->id;
473 $objectstatic->ref = $obj->ref;
475 $companystatic->id = $obj->socid;
476 $companystatic->name = $obj->socname;
477 $companystatic->client = $obj->client;
478 $companystatic->canvas = $obj->canvas;
483 $result .=
'<tr class="oddeven">';
485 $result .=
'<td class="nowrap" width="140">';
486 $result .=
'<table class="nobordernopadding">';
487 $result .=
'<tr class="nocellnopadd">';
489 $result .=
'<td class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).
'</td>';
491 $result .=
'<td width="18" class="nobordernopadding nowrap">';
493 if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay))
500 $result .=
'<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).
'</td>';
503 $result .=
'</table>';
506 $result .=
'<td class="left">'.$companystatic->getNomUrl(1,
'customer', 44).
'</td>';
507 $result .=
'<td class="right">'.dol_print_date($db->jdate($obj->df),
'day').
'</td>';
508 $result .=
'<td class="right">'.price($obj->total_ttc).
'</td>';
513 $total += $obj->total_ttc;
516 if ($num > $nbofloop)
518 $result .=
'<tr class="liste_total">';
519 $result .=
'<td colspan="4" class="right">'.$langs->trans(
"XMoreLines", ($num - $nbofloop)).
'</td>';
524 $result .=
'<tr class="liste_total">';
525 $result .=
'<td colspan="2" class="right">'.$langs->trans(
"Total").
'</td>';
526 $result .=
'<td align="right">'.price($total).
'</td>';
527 $result .=
'<td> </td>';
531 $result .=
'</table>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
Class to manage third parties objects (customers, suppliers, prospects...)
const STATUS_VALIDATED
Validated (need to be paid)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
const STATUS_DRAFT
Draft status.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
const STATUS_CLOSED
Classified paid.
const STATUS_ABANDONED
Classified abandoned and no payment done.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage invoices.