* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compat/facture/index.php * \ingroup facture * \brief Home page of customer invoices area */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; // Security check restrictedArea($user, 'facture'); // Load translation files required by the page $langs->load('bills'); // Filter to show only result of one customer $socid = GETPOST('socid', 'int'); if (isset($user->socid) && $user->socid > 0) { $action = ''; $socid = $user->socid; } // Maximum elements of the tables $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD; $maxLatestEditCount = 5; $maxOpenCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD; /* * View */ llxHeader("", $langs->trans("CustomersInvoicesArea"), "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes"); print load_fiche_titre($langs->trans("CustomersInvoicesArea"), '', 'bill'); print '
'; print '
'; // This is useless due to the global search combo if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { print getAreaSearchFrom(); print '
'; } print getPieChart($socid); print '
'; print getDraftTable($maxDraftCount, $socid); print '
'; print '
'; print '
'; print getLatestEditTable($maxLatestEditCount, $socid); print '
'; print getOpenTable($maxOpenCount, $socid); print '
'; print '
'; print '
'; // End of page llxFooter(); $db->close(); /** * Return a HTML string that contains a additional search form * * @return string A HTML string that contains a additional search form */ function getAreaSearchFrom() { global $langs; $result = '
'; $result .= '
'; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= "
'.$langs->trans("Search").'
'.$langs->trans("Invoice").':
"; $result .= "
"; $result .= "
"; return $result; } /** * Return a HTML table that contains a pie chart of customer invoices * * @param int $socid (Optional) Show only results from the customer with this id * @return string A HTML table that contains a pie chart of customer invoices */ function getPieChart($socid = 0) { global $conf, $db, $langs, $user; $sql = "SELECT count(f.rowid), f.fk_statut"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."facture as f"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture').")"; if ($user->socid) $sql .= ' AND f.fk_soc = '.$user->socid; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; $sql .= " GROUP BY f.fk_statut"; $resql = $db->query($sql); if (!$resql) { dol_print_error($db); return ''; } $num = $db->num_rows($resql); $i = 0; $total = 0; $vals = []; while ($i < $num) { $row = $db->fetch_row($resql); if ($row) { $vals[$row[1]] = $row[0]; $total += $row[0]; } $i++; } $db->free($resql); $result = '
'; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $objectstatic = new Facture($db); $array = [Facture::STATUS_DRAFT, Facture::STATUS_VALIDATED, Facture::STATUS_CLOSED, Facture::STATUS_ABANDONED]; $dataseries = []; foreach ($array as $status) { $objectstatic->statut = $status; $objectstatic->paye = $status == Facture::STATUS_CLOSED ? -1 : 0; $dataseries[] = [$objectstatic->getLibStatut(1), (isset($vals[$status]) ? (int) $vals[$status] : 0)]; if (!$conf->use_javascript_ajax) { $result .= ''; $result .= ''; $result .= ''; $result .= ''; } } if ($conf->use_javascript_ajax) { $dolgraph = new DolGraph(); $dolgraph->SetData($dataseries); $dolgraph->setShowLegend(1); $dolgraph->setShowPercent(1); $dolgraph->SetType(['pie']); $dolgraph->setWidth('100%'); $dolgraph->draw('idgraphthirdparties'); $result .= ''; $result .= ''; $result .= ''; } $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= '
'.$langs->trans("Statistics").' - '.$langs->trans("CustomerInvoice").'
'.$objectstatic->getLibStatut(0).''.(isset($vals[$status]) ? $vals[$status] : 0).'
'.$dolgraph->show($total ? 0 : 1).'
'.$langs->trans("Total").''.$total.'
'; $result .= '
'; return $result; } /** * Return a HTML table that contains a list with customer invoice drafts * * @param int $maxCount (Optional) The maximum count of elements inside the table * @param int $socid (Optional) Show only results from the customer with this id * @return string A HTML table that contains a list with customer invoice drafts */ function getDraftTable($maxCount = 500, $socid = 0) { global $db, $langs, $user; $sql = "SELECT f.rowid, f.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client, f.total as total_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture').")"; $sql .= " AND f.fk_statut = ".Facture::STATUS_DRAFT; if ($socid) $sql .= " AND f.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; $sql .= $db->plimit($maxCount, 0); $resql = $db->query($sql); if (!$resql) { dol_print_error($db); return ''; } $num = $db->num_rows($resql); $result = '
'; $result .= ''; $result .= ''; $result .= ''; $result .= ''; if ($num < 1) { $result .= '
'; $result .= $langs->trans("CustomersDraftInvoices"); $result .= ' '; $result .= ''.$num.''; $result .= ''; $result .= '
'; $result .= '
'; return $result; } $objectstatic = new Facture($db); $companystatic = new Societe($db); $nbofloop = min($num, $maxCount); $total = 0; $i = 0; while ($i < $nbofloop) { $obj = $db->fetch_object($resql); $objectstatic->id = $obj->rowid; $objectstatic->ref = $obj->ref; $companystatic->id = $obj->socid; $companystatic->name = $obj->socname; $companystatic->client = $obj->client; $companystatic->canvas = $obj->canvas; $result .= ''; $result .= ''.$objectstatic->getNomUrl(1).''; $result .= ''.$companystatic->getNomUrl(1, 'customer', 24).''; $result .= ''.price($obj->total_ttc).''; $result .= ''; $i++; $total += $obj->total_ttc; } if ($num > $nbofloop) { $result .= ''; $result .= ''.$langs->trans("XMoreLines", ($num - $nbofloop)).''; $result .= ''; } elseif ($total > 0) { $result .= ''; $result .= ''.$langs->trans("Total").''; $result .= ''.price($total).''; $result .= ''; } $result .= ''; $result .= ''; return $result; } /** * Return a HTML table that contains a list with latest edited customer invoices * * @param int $maxCount (Optional) The maximum count of elements inside the table * @param int $socid (Optional) Show only results from the customer with this id * @return string A HTML table that contains a list with latest edited customer invoices */ function getLatestEditTable($maxCount = 5, $socid = 0) { global $conf, $db, $langs, $user; $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,"; $sql .= " f.datec"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture').")"; if ($socid) $sql .= " AND f.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; $sql .= " ORDER BY f.tms DESC"; $sql .= $db->plimit($maxCount, 0); $resql = $db->query($sql); if (!$resql) { dol_print_error($db); } $num = $db->num_rows($resql); $result = '
'; $result .= ''; $result .= ''; $result .= ''; $result .= ''; if ($num < 1) { $result .= '
'.$langs->trans("LastCustomersBills", $maxCount).'
'; $result .= '
'; return $result; } $formfile = new FormFile($db); $objectstatic = new Facture($db); $companystatic = new Societe($db); $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $objectstatic->id = $obj->rowid; $objectstatic->ref = $obj->ref; $objectstatic->paye = $obj->paye; $objectstatic->statut = $obj->status; $companystatic->id = $obj->socid; $companystatic->name = $obj->socname; $companystatic->client = $obj->client; $companystatic->canvas = $obj->canvas; $filename = dol_sanitizeFileName($obj->ref); $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= '
'.$objectstatic->getNomUrl(1).' '.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'
'; $result .= ''; $result .= ''.$companystatic->getNomUrl(1, 'customer').''; $result .= ''.dol_print_date($db->jdate($obj->datec), 'day').''; $result .= ''.$objectstatic->getLibStatut(5).''; $result .= ''; $i++; } $result .= ''; $result .= ''; return $result; } /** * Return a HTML table that contains a list with open (unpaid) customer invoices * * @param int $maxCount (Optional) The maximum count of elements inside the table * @param int $socid (Optional) Show only results from the customer with this id * @return string A HTML table that conatins a list with open (unpaid) customer invoices */ function getOpenTable($maxCount = 500, $socid = 0) { global $conf, $db, $langs, $user; $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client"; $sql .= ", f.rowid as id, f.entity, f.total as total_ttc, f.total as total_ht, f.ref, f.fk_statut"; $sql .= ", f.datef as df, f.date_lim_reglement as datelimite"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."facture as f"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture').")"; $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; if ($socid) $sql .= " AND s.rowid = ".$socid; $sql .= " ORDER BY f.rowid DESC"; $sql .= $db->plimit($maxCount, 0); $resql = $db->query($sql); if (!$resql) { dol_print_error($db); } $num = $db->num_rows($resql); $result = '
'; $result .= ''; $result .= ''; $result .= ''; $result .= ''; if ($num < 1) { $result .= '
'; $result .= $langs->trans("BillsCustomersUnpaid"); $result .= ' '; $result .= ''.$num.''; $result .= ''; $result .= '
'; $result .= '
'; return $result; } $objectstatic = new Facture($db); $companystatic = new Societe($db); $formfile = new FormFile($db); $nbofloop = min($num, $maxCount); $now = dol_now(); $total = 0; $i = 0; while ($i < $nbofloop) { $obj = $db->fetch_object($resql); $objectstatic->id = $obj->id; $objectstatic->ref = $obj->ref; $companystatic->id = $obj->socid; $companystatic->name = $obj->socname; $companystatic->client = $obj->client; $companystatic->canvas = $obj->canvas; $filename = dol_sanitizeFileName($obj->ref); $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref); $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= ''; $result .= '
'.$objectstatic->getNomUrl(1).''; if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) { $result .= img_warning($langs->trans("Late")); } $result .= ''.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'
'; $result .= ''; $result .= ''.$companystatic->getNomUrl(1, 'customer', 44).''; $result .= ''.dol_print_date($db->jdate($obj->df), 'day').''; $result .= ''.price($obj->total_ttc).''; $result .= ''; $i++; $total += $obj->total_ttc; } if ($num > $nbofloop) { $result .= ''; $result .= ''.$langs->trans("XMoreLines", ($num - $nbofloop)).''; $result .= ''; } elseif ($total > 0) { $result .= ''; $result .= ''.$langs->trans("Total").''; $result .= ''.price($total).''; $result .= ' '; $result .= ''; } $result .= ''; $result .= ''; return $result; }