diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index cbdb58c0818..95cbbd05986 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1036,7 +1036,7 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM if (!empty($conf->societe->enabled) && !empty($conf->supplier_invoice->enabled)) { $langs->load("bills"); - $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"), 0, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); + $newmenu->add("/fourn/facture/index.php?leftmenu=suppliers_bills", $langs->trans("BillsSuppliers"), 0, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills'); $newmenu->add("/fourn/facture/card.php?leftmenu=suppliers_bills&action=create", $langs->trans("NewBill"), 1, $user->rights->fournisseur->facture->creer, '', $mainmenu, 'suppliers_bills_create'); $newmenu->add("/fourn/facture/list.php?leftmenu=suppliers_bills", $langs->trans("List"), 1, $user->rights->fournisseur->facture->lire, '', $mainmenu, 'suppliers_bills_list'); diff --git a/htdocs/fourn/facture/index.php b/htdocs/fourn/facture/index.php new file mode 100644 index 00000000000..df32ee1b19a --- /dev/null +++ b/htdocs/fourn/facture/index.php @@ -0,0 +1,535 @@ + + * + * 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/forun/facture/index.php +* \ingroup facture + * \brief Home page of customer invoices area + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.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, 'fournisseur', 0, '', 'facture'); + +// Load translation files required by the page +$langs->loadLangs(['bills', 'boxes']); + +// Filter to show only result of one supplier +$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("SupplierInvoicesArea"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores'); + +print load_fiche_titre($langs->trans("SupplierInvoicesArea"), '', 'invoicing'); + +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 supplier invoices + * + * @param int $socid (Optional) Show only results from the supplier with this id + * @return string A HTML table that contains a pie chart of supplier 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_fourn 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_fourn').")"; + 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 FactureFournisseur($db); + $array = [FactureFournisseur::STATUS_DRAFT, FactureFournisseur::STATUS_VALIDATED, FactureFournisseur::STATUS_CLOSED, FactureFournisseur::STATUS_ABANDONED]; + $dataseries = []; + + foreach ($array as $status) + { + $objectstatic->statut = $status; + $objectstatic->paye = $status == FactureFournisseur::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("SupplierInvoice").'
'.$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 supplier invoice drafts + * + * @param int $maxCount (Optional) The maximum count of elements inside the table + * @param int $socid (Optional) Show only results from the supplier with this id + * @return string A HTML table that contains a list with supplier 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_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn 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_fourn').")"; + $sql .= " AND f.fk_statut = ".FactureFournisseur::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("SuppliersDraftInvoices"); + $result .= ' '; + $result .= ''.$num.''; + $result .= ''; + $result .= '
'; + $result .= '
'; + return $result; + } + + $objectstatic = new FactureFournisseur($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, 'supplier', 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 supplier invoices + * + * @param int $maxCount (Optional) The maximum count of elements inside the table + * @param int $socid (Optional) Show only results from the supplier with this id + * @return string A HTML table that contains a list with latest edited supplier 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_fourn 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_fourn').")"; + 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); + return ''; + } + + $num = $db->num_rows($resql); + + $result = '
'; + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + + if ($num < 1) + { + $result .= '
'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'
'; + $result .= '
'; + return $result; + } + + $objectstatic = new FactureFournisseur($db); + $companystatic = new Societe($db); + $formfile = new FormFile($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, 'supplier').''; + $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) supplier invoices + * + * @param int $maxCount (Optional) The maximum count of elements inside the table + * @param int $socid (Optional) Show only results from the supplier with this id + * @return string A HTML table that conatins a list with open (unpaid) supplier 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_ttc, f.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_fourn 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_fourn').")"; + $sql .= " AND f.fk_statut = ".FactureFournisseur::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); + return ''; + } + + $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 FactureFournisseur($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].'/'.$filename; + + $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; +} diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 95b741a83f5..740248026b0 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -572,3 +572,4 @@ BILL_DELETEInDolibarr=Invoice deleted BILL_SUPPLIER_DELETEInDolibarr=Supplier invoice deleted UnitPriceXQtyLessDiscount=Unit price x Qty - Discount CustomersInvoicesArea=Customer billing area +SupplierInvoicesArea=Supplier billing area