diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php index 7bb9d81607f..7e77817ac5c 100644 --- a/htdocs/accountancy/admin/categories.php +++ b/htdocs/accountancy/admin/categories.php @@ -32,9 +32,7 @@ $error = 0; // Load translation files required by the page $langs->loadLangs(array("bills", "accountancy")); -$mesg = ''; $id = GETPOST('id', 'int'); -$rowid = GETPOST('rowid', 'int'); $cancel = GETPOST('cancel', 'alpha'); $action = GETPOST('action', 'aZ09'); $cat_id = GETPOST('account_category', 'int'); diff --git a/htdocs/accountancy/admin/categories_list.php b/htdocs/accountancy/admin/categories_list.php index c61674921f1..cb987055cea 100644 --- a/htdocs/accountancy/admin/categories_list.php +++ b/htdocs/accountancy/admin/categories_list.php @@ -247,7 +247,7 @@ if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) { if ($_POST[$listfieldvalue[$i]] == '' && !$listfieldvalue[$i] == 'formula') { $sql .= "null"; // For vat, we want/accept code = '' } else { - $sql .= "'".$db->escape($_POST[$listfieldvalue[$i]])."'"; + $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'"; } $i++; } @@ -787,7 +787,7 @@ if ($id) { $class = 'tddict'; // Show value for field if ($showfield) { - print ''.$valuetoshow.''; + print ''.dol_escape_htmltag($valuetoshow).''; } } } diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 9878f67890c..27b37c74932 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -997,8 +997,11 @@ if (empty($action) || $action == 'view') { if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1' || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1' || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { - print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); + $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); + print $desc; + print '
'; } diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index 2f7569ab152..2916d4d1fca 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -506,8 +506,11 @@ if (empty($action) || $action == 'view') { // Button to write into Ledger if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { - print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); + $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); + print $desc; + print '
'; } print '
'; diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index f6fa5c4b76a..bf950182798 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -735,9 +735,11 @@ if (empty($action) || $action == 'view') { // Button to write into Ledger if (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { - print '
'; - print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); + $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); + print $desc; + print '
'; } print '
'; if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') { diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index e5f52cbc2ea..1904631775d 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -688,9 +688,11 @@ if (empty($action) || $action == 'view') { // Button to write into Ledger if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { - print '
'; - print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); + $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); + print $desc; + print '
'; } print '
'; if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') { diff --git a/htdocs/admin/system/modules.php b/htdocs/admin/system/modules.php index f9b8bdb65c8..51f3b4577cf 100644 --- a/htdocs/admin/system/modules.php +++ b/htdocs/admin/system/modules.php @@ -228,26 +228,26 @@ print ''; if ($arrayfields['name']['checked']) { print ''; - print ''; + print ''; print ''; } if ($arrayfields['version']['checked']) { print ''; - print ''; + print ''; print ''; } if ($arrayfields['id']['checked']) { print ''; - print ''; - print ''; -} -if ($arrayfields['module_position']['checked']) { - print ''; + print ''; print ''; } if ($arrayfields['permission']['checked']) { print ''; - print ''; + print ''; + print ''; +} +if ($arrayfields['module_position']['checked']) { + print ''; print ''; } @@ -267,14 +267,14 @@ if ($arrayfields['version']['checked']) { print_liste_field_titre($arrayfields['version']['label'], $_SERVER["PHP_SELF"], "version", "", "", "", $sortfield, $sortorder); } if ($arrayfields['id']['checked']) { - print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder); -} -if ($arrayfields['module_position']['checked']) { - print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder); + print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder, 'nowraponall '); } if ($arrayfields['permission']['checked']) { print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder); } +if ($arrayfields['module_position']['checked']) { + print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder); +} // Fields from hook $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); @@ -289,37 +289,30 @@ if ($sortfield == "name" && $sortorder == "asc") { usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($a->name, $b->name); }); -} -if ($sortfield == "name" && $sortorder == "desc") { +} elseif ($sortfield == "name" && $sortorder == "desc") { usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($b->name, $a->name); }); -} -if ($sortfield == "version" && $sortorder == "asc") { +} elseif ($sortfield == "version" && $sortorder == "asc") { usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($a->version, $b->version); }); -} -if ($sortfield == "version" && $sortorder == "desc") { +} elseif ($sortfield == "version" && $sortorder == "desc") { usort($moduleList, function (stdClass $a, stdClass $b) { return strcasecmp($b->version, $a->version); }); -} -if ($sortfield == "id" && $sortorder == "asc") { +} elseif ($sortfield == "id" && $sortorder == "asc") { usort($moduleList, "compareIdAsc"); -} -if ($sortfield == "id" && $sortorder == "desc") { +} elseif ($sortfield == "id" && $sortorder == "desc") { usort($moduleList, "compareIdDesc"); -} -if ($sortfield == "permission" && $sortorder == "asc") { +} elseif ($sortfield == "permission" && $sortorder == "asc") { usort($moduleList, "comparePermissionIdsAsc"); -} -if ($sortfield == "permission" && $sortorder == "desc") { +} elseif ($sortfield == "permission" && $sortorder == "desc") { usort($moduleList, "comparePermissionIdsDesc"); +} else { + $moduleList = dol_sort_array($moduleList, 'module_position'); } -$moduleList = dol_sort_array($moduleList, 'module_position'); - foreach ($moduleList as $module) { print ''; @@ -338,10 +331,6 @@ foreach ($moduleList as $module) { print ''.$module->id.''; } - if ($arrayfields['module_position']['checked']) { - print ''.$module->module_position.''; - } - if ($arrayfields['permission']['checked']) { $idperms = ''; @@ -357,7 +346,11 @@ foreach ($moduleList as $module) { } } - print ''.($idperms ? $idperms : " ").''; + print ''.($idperms ? $idperms : " ").''; + } + + if ($arrayfields['module_position']['checked']) { + print ''.$module->module_position.''; } print ''; @@ -394,11 +387,11 @@ $db->close(); */ function compareIdAsc(stdClass $a, stdClass $b) { - if ($a->id == $b->id) { + if ((int) $a->id == (int) $b->id) { return 0; } - return $a->id > $b->id ? -1 : 1; + return ((int) $a->id < (int) $b->id) ? -1 : 1; } /** @@ -410,11 +403,11 @@ function compareIdAsc(stdClass $a, stdClass $b) */ function compareIdDesc(stdClass $a, stdClass $b) { - if ($a->id == $b->id) { + if ((int) $a->id == (int) $b->id) { return 0; } - return $b->id > $a->id ? -1 : 1; + return ((int) $b->id < (int) $a->id) ? -1 : 1; } /** @@ -441,7 +434,7 @@ function comparePermissionIdsAsc(stdClass $a, stdClass $b) return 0; } - return $a->permission[0] > $b->permission[0] ? -1 : 1; + return $a->permission[0] < $b->permission[0] ? -1 : 1; } /** @@ -468,5 +461,5 @@ function comparePermissionIdsDesc(stdClass $a, stdClass $b) return 0; } - return $a->permission[0] > $b->permission[0] ? 1 : -1; + return $b->permission[0] < $a->permission[0] ? -1 : 1; } diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 97fa9eb0cfc..149f28f42d3 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -28,7 +28,6 @@ */ require '../main.inc.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 00c5c946326..4958811ef4d 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -524,15 +524,15 @@ if (empty($reshook)) { } /* - * Add file in email form + * Action of adding a file in email form */ - if (!empty($_POST['addfile'])) { + if (GETPOST('addfile')) { $upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing'); require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Set tmp user directory - dol_add_file_process($upload_dir, 0, 0); + dol_add_file_process($upload_dir, 0, 0, 'addedfile', '', null, '', 0); $action = "edit"; } @@ -543,7 +543,7 @@ if (empty($reshook)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_remove_file_process($_POST['removedfile'], 0, 0); // We really delete file linked to mailing + dol_remove_file_process(GETPOST('removedfile'), 0, 0); // We really delete file linked to mailing $action = "edit"; } @@ -1216,7 +1216,7 @@ if ($action == 'create') { $out .= '
'; } } else { - $out .= $langs->trans("NoAttachedFiles").'
'; + $out .= ''.$langs->trans("NoAttachedFiles").'
'; } // Add link to add file $out .= ''; diff --git a/htdocs/compta/facture/index.php b/htdocs/compta/facture/index.php index ba0d8e2f2aa..0b2f4538636 100644 --- a/htdocs/compta/facture/index.php +++ b/htdocs/compta/facture/index.php @@ -25,6 +25,7 @@ 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'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php'; // Security check restrictedArea($user, 'facture'); @@ -39,14 +40,17 @@ if (isset($user->socid) && $user->socid > 0) { $socid = $user->socid; } +$max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; + // 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 -*/ + * View + */ llxHeader("", $langs->trans("CustomersInvoicesArea"), "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes"); @@ -56,24 +60,18 @@ 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 getCustomerInvoicePieChart($socid); print '
'; -print getDraftTable($maxDraftCount, $socid); +print getCustomerInvoiceDraftTable($max, $socid); print '
'; print '
'; print '
'; -print getLatestEditTable($maxLatestEditCount, $socid); +print getCustomerInvoiceLatestEditTable($maxLatestEditCount, $socid); print '
'; -print getOpenTable($maxOpenCount, $socid); +print getCustomerInvoiceUnpaidOpenTable($max, $socid); print '
'; print '
'; @@ -83,452 +81,3 @@ 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(2); - $dolgraph->setShowPercent(1); - $dolgraph->SetType(['pie']); - $dolgraph->setHeight('200'); - $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 = ".((int) $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 = ".((int) $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 = ".((int) $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; -} diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index a24bce0e0e2..8823e399d77 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -38,6 +38,8 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php'; // L'espace compta/treso doit toujours etre actif car c'est un espace partage // par de nombreux modules (banque, facture, commande a facturer, etc...) independamment @@ -64,13 +66,21 @@ if ($user->socid > 0) { $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; +// 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; + // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('invoiceindex')); + /* * Actions */ +// None + /* * View @@ -89,301 +99,19 @@ print load_fiche_titre($langs->trans("AccountancyTreasuryArea"), '', 'bill'); print '
'; - -if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo - // Search customer invoices - if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { - $listofsearchfields['search_invoice'] = array('text'=>'CustomerInvoice'); - } - // Search supplier invoices - if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->lire) { - $listofsearchfields['search_supplier_invoice'] = array('text'=>'SupplierInvoice'); - } - if (!empty($conf->don->enabled) && $user->rights->don->lire) { - $langs->load("donations"); - $listofsearchfields['search_donation'] = array('text'=>'Donation'); - } - - if (count($listofsearchfields)) { - print '
'; - print ''; - print '
'; - print ''; - $i = 0; - foreach ($listofsearchfields as $key => $value) { - if ($i == 0) { - print ''; - } - print ''; - print ''; - if ($i == 0) { - print ''; - } - print ''; - $i++; - } - print '
'.$langs->trans("Search").'
'; - print '
'; - print '
'; - print '
'; - } -} - - -/** - * Draft customers invoices - */ -if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { - $tmpinvoice = new Facture($db); - - $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.ref_client"; - $sql .= ", f.type, f.fk_statut as status, f.paye"; - $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= ", sc.fk_soc, sc.fk_user "; - } - $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"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT; - $sql .= " AND f.entity IN (".getEntity('invoice').")"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - } - - if ($socid) { - $sql .= " AND f.fk_soc = $socid"; - } - // Add where from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters); - $sql .= $hookmanager->resPrint; - - $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total, f.tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,"; - $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,"; - $sql .= " cc.rowid, cc.code"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql.= ", sc.fk_soc, sc.fk_user"; - } - - // Add Group from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters); - $sql .= $hookmanager->resPrint; - - $resql = $db->query($sql); - - if ($resql) { - $num = $db->num_rows($resql); - - print '
'; - print ''; - - print ''; - print ''; - print ''; - - if ($num) { - $companystatic = new Societe($db); - - $i = 0; - $othernb = 0; - $tot_ttc = 0; - while ($i < $num && $i < $conf->liste_limit) { - $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $tot_ttc += $obj->total_ttc; - continue; - } - - $tmpinvoice->id = $obj->rowid; - $tmpinvoice->ref = $obj->ref; - $tmpinvoice->date = $db->jdate($obj->date); - $tmpinvoice->type = $obj->type; - $tmpinvoice->total_ht = $obj->total_ht; - $tmpinvoice->total_tva = $obj->total_tva; - $tmpinvoice->total_ttc = $obj->total_ttc; - $tmpinvoice->ref_client = $obj->ref_client; - $tmpinvoice->statut = $obj->status; - $tmpinvoice->paye = $obj->paye; - - $companystatic->id = $obj->socid; - $companystatic->name = $obj->name; - $companystatic->email = $obj->email; - $companystatic->country_id = $obj->country_id; - $companystatic->country_code = $obj->country_code; - $companystatic->client = 1; - $companystatic->code_client = $obj->code_client; - $companystatic->code_fournisseur = $obj->code_fournisseur; - $companystatic->code_compta = $obj->code_compta; - $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - - print ''; - print ''; - print ''; - print ''; - $tot_ttc += $obj->total_ttc; - $i++; - } - - if ($othernb) { - print ''; - print ''; - print "\n"; - } - - print ''; - print ''; - print ''; - } else { - print ''; - } - print "
'; - print $langs->trans("CustomersDraftInvoices").' '; - print ''; - print ''.$num.''; - print ''; - print '
'; - print $tmpinvoice->getNomUrl(1, ''); - print ''; - print $companystatic->getNomUrl(1, 'customer'); - print ''.price($obj->total_ttc).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'

"; - $db->free($resql); - } else { - dol_print_error($db); - } -} - -/** - * Draft suppliers invoices - */ -if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) { - $facturesupplierstatic = new FactureFournisseur($db); - - $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"; - $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - $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"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT; - $sql .= " AND f.entity IN (".getEntity('invoice').')'; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - } - if ($socid) { - $sql .= " AND f.fk_soc = ".$socid; - } - // Add where from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters); - $sql .= $hookmanager->resPrint; - $resql = $db->query($sql); - - if ($resql) { - $num = $db->num_rows($resql); - - print '
'; - print ''; - - print ''; - print ''; - print ''; - - if ($num) { - $companystatic = new Societe($db); - - $i = 0; - $othernb = 0; - $tot_ttc = 0; - while ($i < $num && $i < $conf->liste_limit) { - $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $tot_ttc += $obj->total_ttc; - continue; - } - - $facturesupplierstatic->ref = $obj->ref; - $facturesupplierstatic->id = $obj->rowid; - $facturesupplierstatic->total_ht = $obj->total_ht; - $facturesupplierstatic->total_tva = $obj->total_tva; - $facturesupplierstatic->total_ttc = $obj->total_ttc; - $facturesupplierstatic->ref_supplier = $obj->ref_supplier; - $facturesupplierstatic->type = $obj->type; - $facturesupplierstatic->statut = $obj->status; - $facturesupplierstatic->paye = $obj->paye; - - $companystatic->id = $obj->socid; - $companystatic->name = $obj->name; - $companystatic->email = $obj->email; - $companystatic->country_id = $obj->country_id; - $companystatic->country_code = $obj->country_code; - $companystatic->fournisseur = 1; - $companystatic->code_client = $obj->code_client; - $companystatic->code_fournisseur = $obj->code_fournisseur; - $companystatic->code_compta = $obj->code_compta; - $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - - print ''; - print ''; - print ''; - print ''; - $tot_ttc += $obj->total_ttc; - $i++; - } - - if ($othernb) { - print ''; - print ''; - print "\n"; - } - - print ''; - print ''; - print ''; - } else { - print ''; - } - print "
'; - print $langs->trans("SuppliersDraftInvoices").' '; - print ''; - print ''.$num.''; - print ''; - print '
'; - print $facturesupplierstatic->getNomUrl(1, ''); - print ''; - print $companystatic->getNomUrl(1, 'supplier'); - print ''.price($obj->total_ttc).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'

"; - $db->free($resql); - } else { - dol_print_error($db); - } -} - +print getCustomerInvoicePieChart($socid); +print '
'; +print getPurchaseInvoicePieChart($socid); +print '
'; +print getCustomerInvoiceDraftTable($max, $socid); +print '
'; +print getDraftSupplierTable($max, $socid); print '
'; // Latest modified customer invoices -if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { +if (!empty($conf->facture->enabled) && !empty($user->rights->facture->lire)) { $langs->load("boxes"); $tmpinvoice = new Facture($db); @@ -495,7 +223,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { print ''.price($obj->total_ht).''; } - print ''.price($obj->total_ttc).''; + print ''.price($obj->total_ttc).''; print ''.dol_print_date($db->jdate($obj->tms), 'day').''; print ''.$tmpinvoice->getLibStatut(3, $obj->am).''; print ''; @@ -529,9 +257,8 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { } - // Last modified supplier invoices -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->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) { $langs->load("boxes"); $facstatic = new FactureFournisseur($db); @@ -622,7 +349,7 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { print ''.price($obj->total_ht).''; } - print ''.price($obj->total_ttc).''; + print ''.price($obj->total_ttc).''; print ''.dol_print_date($db->jdate($obj->tms), 'day').''; print ''.$facstatic->getLibStatut(3).''; print ''; @@ -655,7 +382,7 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU // Latest donations -if (!empty($conf->don->enabled) && $user->rights->don->lire) { +if (!empty($conf->don->enabled) && !empty($user->rights->don->lire)) { include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; $langs->load("boxes"); @@ -718,7 +445,7 @@ if (!empty($conf->don->enabled) && $user->rights->don->lire) { print ''; print ''.$donationstatic->getNomUrl(1).''; print ''.$label.''; - print ''.price($objp->amount).''; + print ''.price($objp->amount).''; print ''.dol_print_date($db->jdate($objp->dm), 'day').''; print ''.$donationstatic->getLibStatut(3).''; print ''; @@ -745,7 +472,7 @@ if (!empty($conf->don->enabled) && $user->rights->don->lire) { /** * Social contributions to pay */ -if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) { +if (!empty($conf->tax->enabled) && !empty($user->rights->tax->charges->lire)) { if (!$socid) { $chargestatic = new ChargeSociales($db); @@ -802,8 +529,8 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) { print ''; print ''.$chargestatic->getNomUrl(1).''; print ''.dol_print_date($db->jdate($obj->date_ech), 'day').''; - print ''.price($obj->amount).''; - print ''.price($obj->sumpaid).''; + print ''.price($obj->amount).''; + print ''.price($obj->sumpaid).''; print ''.$chargestatic->getLibStatut(3).''; print ''; @@ -953,8 +680,8 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { print ''.price($obj->total_ht).''; } - print ''.price($obj->total_ttc).''; - print ''.price($obj->total_ttc - $obj->tot_fttc).''; + print ''.price($obj->total_ttc).''; + print ''.price($obj->total_ttc - $obj->tot_fttc).''; print ''.$commandestatic->getLibStatut(3).''; print ''; $tot_ht += $obj->total_ht; @@ -974,10 +701,10 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user print ''.$langs->trans("Total").'   ('.$langs->trans("RemainderToBill").': '.price($tot_tobill).') '; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''.price($tot_ht).''; + print ''.price($tot_ht).''; } - print ''.price($tot_ttc).''; - print ''.price($tot_tobill).''; + print ''.price($tot_ttc).''; + print ''.price($tot_tobill).''; print ' '; print ''; print '

'; @@ -988,328 +715,9 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user } } -/* - * Unpaid customers invoices - */ -if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { - $tmpinvoice = new Facture($db); - - $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms"; - $sql .= ", f.date_lim_reglement as datelimite"; - $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - $sql .= ", sum(pf.amount) as am"; - $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"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED; - $sql .= " AND f.entity IN (".getEntity('invoice').')'; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - } - if ($socid) { - $sql .= " AND f.fk_soc = ".$socid; - } - // Add where from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters); - $sql .= $hookmanager->resPrint; - - $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total, f.tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,"; - $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= " ORDER BY f.datef ASC, f.ref ASC"; - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - $othernb = 0; - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - if ($num) { - $societestatic = new Societe($db); - $total_ttc = $totalam = $total = 0; - while ($i < $num && $i < $conf->liste_limit) { - $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } - - $tmpinvoice->ref = $obj->ref; - $tmpinvoice->id = $obj->rowid; - $tmpinvoice->total_ht = $obj->total_ht; - $tmpinvoice->total_tva = $obj->total_tva; - $tmpinvoice->total_ttc = $obj->total_ttc; - $tmpinvoice->type = $obj->type; - $tmpinvoice->statut = $obj->status; - $tmpinvoice->paye = $obj->paye; - $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite); - - $societestatic->id = $obj->socid; - $societestatic->name = $obj->name; - $societestatic->email = $obj->email; - $societestatic->country_id = $obj->country_id; - $societestatic->country_code = $obj->country_code; - $societestatic->client = 1; - $societestatic->code_client = $obj->code_client; - $societestatic->code_fournisseur = $obj->code_fournisseur; - $societestatic->code_compta = $obj->code_compta; - $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - - print ''; - print ''; - print ''; - print ''; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - - $total_ttc += $obj->total_ttc; - $total += $obj->total_ht; - $totalam += $obj->am; - - $i++; - } - - if ($othernb) { - $colspan = 6; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - $colspan++; - } - print ''; - print ''; - print "\n"; - } - - print ''; - print ''; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - } else { - $colspan = 6; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - $colspan++; - } - print ''; - } - print '
'; - print $langs->trans("BillsCustomersUnpaid", $num).' '; - print ''; - print ''.$num.''; - print ''; - print ''.$langs->trans("DateDue").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Received").' 
'; - - print ''; - print ''; - print ''; - print '
'; - print $tmpinvoice->getNomUrl(1, ''); - print ''; - if ($tmpinvoice->hasDelay()) { - print img_warning($langs->trans("Late")); - } - print ''; - $filename = dol_sanitizeFileName($obj->ref); - $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref); - $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid; - print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir); - print '
'; - - print '
'; - print $societestatic->getNomUrl(1, 'customer'); - print ''.dol_print_date($db->jdate($obj->datelimite), 'day').''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->am).''.$tmpinvoice->getLibStatut(3, $obj->am).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')  '.price($total).''.price($total_ttc).''.price($totalam).' 
'.$langs->trans("NoInvoice").'

'; - $db->free($resql); - } else { - dol_print_error($db); - } -} - -/* - * Unpaid supplier invoices - */ -if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) { - $facstatic = new FactureFournisseur($db); - - $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"; - $sql .= ", ff.date_lim_reglement"; - $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; - $sql .= ", sum(pf.amount) as am"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; - if (!$user->rights->societe->client->voir && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE s.rowid = ff.fk_soc"; - $sql .= " AND ff.entity = ".$conf->entity; - $sql .= " AND ff.paye = 0"; - $sql .= " AND ff.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 ff.fk_soc = ".$socid; - } - // Add where from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters); - $sql .= $hookmanager->resPrint; - - $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,"; - $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur"; - $sql .= " ORDER BY ff.date_lim_reglement ASC"; - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $othernb = 0; - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''; - } - print ''; - print ''; - print ''; - print "\n"; - $societestatic = new Societe($db); - if ($num) { - $i = 0; - $total = $total_ttc = $totalam = 0; - while ($i < $num) { - $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } - - $facstatic->ref = $obj->ref; - $facstatic->id = $obj->rowid; - $facstatic->type = $obj->type; - $facstatic->total_ht = $obj->total_ht; - $facstatic->total_tva = $obj->total_tva; - $facstatic->total_ttc = $obj->total_ttc; - $facstatic->statut = $obj->status; - $facstatic->paye = $obj->paye; - - $societestatic->id = $obj->socid; - $societestatic->name = $obj->name; - $societestatic->email = $obj->email; - $societestatic->client = 0; - $societestatic->fournisseur = 1; - $societestatic->code_client = $obj->code_client; - $societestatic->code_fournisseur = $obj->code_fournisseur; - $societestatic->code_compta = $obj->code_compta; - $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - - print ''; - print ''; - print ''; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - $totalam += $obj->am; - $i++; - } - - if ($othernb) { - $colspan = 6; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - $colspan++; - } - print ''; - print ''; - print "\n"; - } - - print ''; - print ''; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - print ''; - } - print ''; - print ''; - print ''; - print ''; - } else { - $colspan = 6; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { - $colspan++; - } - print ''; - } - print '
'; - print $langs->trans("BillsSuppliersUnpaid", $num).' '; - print ''; - print ''.$num.''; - print ''; - print ''.$langs->trans("DateDue").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Paid").' 
'; - print $facstatic->getNomUrl(1, ''); - print ''.$societestatic->getNomUrl(1, 'supplier').''.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->am).''.$facstatic->getLibStatut(3, $obj->am).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')  '.price($total).''.price($total_ttc).''.price($totalam).' 
'.$langs->trans("NoInvoice").'

'; - } else { - dol_print_error($db); - } -} - - // TODO Mettre ici recup des actions en rapport avec la compta -$resql = 0; +$resql = ''; if ($resql) { print '
'; print ''; diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index 67bc2d2e61f..467169230d0 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -1,7 +1,7 @@ * Copyright (C) 2016 Alexandre Spangaro - * Copyright (C) 2018 Laurent Destailleur + * Copyright (C) 2018-2020 Laurent Destailleur * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -318,9 +318,9 @@ if ($modecompta == 'CREANCES-DETTES') { // Year NP print ''; $vars = array(); @@ -337,7 +337,7 @@ if ($modecompta == 'CREANCES-DETTES') { $r = dol_eval($result, 1); //var_dump($r); - print ''; + print ''; // Year N $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...) @@ -355,7 +355,7 @@ if ($modecompta == 'CREANCES-DETTES') { //$r = $AccCat->calculate($result); $r = dol_eval($result, 1); - print ''; + print ''; $sommes[$code]['N'] += $r; // Detail by month @@ -369,7 +369,7 @@ if ($modecompta == 'CREANCES-DETTES') { //$r = $AccCat->calculate($result); $r = dol_eval($result, 1); - print ''; + print ''; $sommes[$code]['M'][$k] += $r; } } @@ -383,7 +383,7 @@ if ($modecompta == 'CREANCES-DETTES') { //$r = $AccCat->calculate($result); $r = dol_eval($result, 1); - print ''; + print ''; $sommes[$code]['M'][$k] += $r; } } @@ -471,12 +471,12 @@ if ($modecompta == 'CREANCES-DETTES') { // Column group print ''; // Label of group print ''; + + $result .= ''; + + $result .= ''; + $result .= ''; + $result .= ''; + + $result .= ''; + + $i++; + } + + $result .= '
'; - print $cat['code']; + print dol_escape_htmltag($cat['code']); print ''; - print $cat['label']; + print dol_escape_htmltag($cat['label']); print ''.price($r).''.price($r).''.price($r).''.price($r).''.price($r).''.price($r).''.price($r).''.price($r).''; - print $cat['code']; + print dol_escape_htmltag($cat['code']); print ''; - print $cat['label']; + print dol_escape_htmltag($cat['label']); if (count($cpts) > 0) { // Show example of 5 first accounting accounts $i = 0; foreach ($cpts as $cpt) { @@ -489,7 +489,7 @@ if ($modecompta == 'CREANCES-DETTES') { } else { print ' ('; } - print $cpt['account_number']; + print dol_escape_htmltag($cpt['account_number']); $i++; } if ($i <= 5) { diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 5c0ad2747ba..9e342b9b8d3 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1530,7 +1530,7 @@ if ($action == 'create') { print ''; if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0)) { print ''; - print ''; + print ''; print img_picto($langs->trans("MoveToAnotherContract"), 'uparrow'); print ''; } diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 87706703c23..afbda03be8e 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -275,8 +275,10 @@ class FormAccounting extends Form if ($obj->rowid == $selected) { $out .= ' selected'; } - $out .= '>'.($maxlen ? dol_trunc($obj->type, $maxlen) : $obj->type); - $out .= ' ('.$obj->range_account.')'; + $out .= '>'; + $titletoshow = dol_string_nohtmltag(($maxlen ? dol_trunc($obj->type, $maxlen) : $obj->type).' ('.$obj->range_account.')'); + $out .= dol_escape_htmltag($titletoshow); + $out .= ''; $i++; } $out .= ''; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 431cdffccf4..782b0ec4694 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1544,7 +1544,9 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess if (!empty($_FILES[$varfiles])) { // For view $_FILES[$varfiles]['error'] dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); - if (dol_mkdir($upload_dir) >= 0) { + $result = dol_mkdir($upload_dir); + // var_dump($result);exit; + if ($result >= 0) { $TFile = $_FILES[$varfiles]; if (!is_array($TFile['name'])) { foreach ($TFile as $key => &$val) { @@ -1647,6 +1649,8 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess $res = 1; setEventMessages($langs->trans("FileTransferComplete"), null, 'mesgs'); } + } else { + setEventMessages($langs->trans("ErrorFailedToCreateDir", $upload_dir), null, 'errors'); } } elseif ($link) { require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d22aa0d40e2..3cca19ba0ff 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3525,7 +3525,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'object_recruitmentjobposition', 'object_recruitmentcandidature', 'object_salary', 'object_shipment', 'object_share-alt', 'object_supplier_invoice', 'object_supplier_invoicea', 'object_supplier_invoiced', 'object_supplier_order', 'object_supplier_proposal', 'object_service', 'object_stock', 'object_technic', 'object_ticket', 'object_trip', 'object_user', 'object_group', 'object_member', - 'object_phoning', 'object_phoning_mobile', 'object_phoning_fax', 'object_email', 'object_website', 'object_movement', + 'object_phoning', 'object_phoning_mobile', 'object_phoning_fax', 'object_email', 'object_website', 'object_movement', 'object_workstation', 'off', 'on', 'order', 'paiment', 'play', 'pdf', 'phone', 'playdisabled', 'previous', 'poll', 'pos', 'printer', 'product', 'propal', 'stock', 'resize', 'service', 'stats', 'trip', 'setup', 'share-alt', 'sign-out', 'split', 'stripe', 'stripe-s', 'switch_off', 'switch_on', 'tools', 'unlink', 'uparrow', 'user', 'vcard', 'wrench', @@ -3537,7 +3537,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'recruitmentcandidature', 'recruitmentjobposition', 'resource', 'shapes', 'supplier_proposal', 'supplier_order', 'supplier_invoice', 'timespent', 'title_setup', 'title_accountancy', 'title_bank', 'title_hrm', 'title_agenda', - 'user-cog', 'website', + 'user-cog', 'website', 'workstation', 'conferenceorbooth', 'eventorganization' ))) { $pictowithouttext = str_replace('object_', '', $pictowithouttext); @@ -3585,7 +3585,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'title_agenda'=>'calendar-alt', 'uparrow'=>'share', 'vcard'=>'address-card', 'jabber'=>'comment-o', - 'website'=>'globe-americas', + 'website'=>'globe-americas', 'workstation'=>'pallet', 'conferenceorbooth'=>'chalkboard-teacher', 'eventorganization'=>'project-diagram' ); if ($pictowithouttext == 'off') { @@ -3619,7 +3619,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ if (in_array($pictowithouttext, array('dollyrevert', 'member', 'members', 'contract', 'group', 'resource', 'shipment'))) { $morecss = 'em092'; } - if (in_array($pictowithouttext, array('conferenceorbooth', 'collab', 'eventorganization', 'holiday', 'project'))) { + if (in_array($pictowithouttext, array('conferenceorbooth', 'collab', 'eventorganization', 'holiday', 'project', 'workstation'))) { $morecss = 'em088'; } if (in_array($pictowithouttext, array('intervention', 'info', 'payment', 'loan', 'stock', 'technic'))) { @@ -3676,7 +3676,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $ 'other'=>'#ddd', 'playdisabled'=>'#ccc', 'printer'=>'#444', 'projectpub'=>'#986c6a', 'resize'=>'#444', 'rss'=>'#cba', 'shipment'=>'#a69944', 'stats'=>'#444', 'switch_off'=>'#999', 'technic'=>'#999', 'timespent'=>'#555', 'uparrow'=>'#555', 'user-cog'=>'#999', 'country'=>'#aaa', 'globe-americas'=>'#aaa', - 'website'=>'#304' + 'website'=>'#304', 'workstation'=>'#a69944' ); if (isset($arrayconvpictotocolor[$pictowithouttext])) { $facolor = $arrayconvpictotocolor[$pictowithouttext]; diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 89e7f8c8e55..acf714be32b 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -215,3 +215,1023 @@ function invoice_rec_prepare_head($object) return $head; } + +/** + * 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 getCustomerInvoicePieChart($socid = 0) +{ + global $conf, $db, $langs, $user; + + if (empty($conf->facture->enabled) || empty($user->rights->facture->lire)) { + return ''; + } + + $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(2); + $dolgraph->setShowPercent(1); + $dolgraph->SetType(['pie']); + $dolgraph->setHeight('200'); + $dolgraph->draw('idgraphcustomerinvoices'); + + $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 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 getPurchaseInvoicePieChart($socid = 0) +{ + global $conf, $db, $langs, $user; + + if (!(!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) { + return ''; + } + + $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(2); + $dolgraph->setShowPercent(1); + $dolgraph->SetType(['pie']); + $dolgraph->setHeight('200'); + $dolgraph->draw('idgraphpurchaseinvoices'); + + $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 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 getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0) +{ + global $conf, $db, $langs, $user, $hookmanager; + + $result = ''; + $tmpinvoice = new Facture($db); + + $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.ref_client"; + $sql .= ", f.type, f.fk_statut as status, f.paye"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", sc.fk_soc, sc.fk_user "; + } + $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"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + + if ($socid) { + $sql .= " AND f.fk_soc = $socid"; + } + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters); + $sql .= $hookmanager->resPrint; + + $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total, f.tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,"; + $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,"; + $sql .= " cc.rowid, cc.code"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql.= ", sc.fk_soc, sc.fk_user"; + } + + // Add Group from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters); + $sql .= $hookmanager->resPrint; + + $resql = $db->query($sql); + + if ($resql) { + $num = $db->num_rows($resql); + + $result .= '
'; + $result .= ''; + + $result .= ''; + $result .= ''; + $result .= ''; + + if ($num) { + $companystatic = new Societe($db); + + $i = 0; + $othernb = 0; + $tot_ttc = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + + if ($i >= $maxCount) { + $othernb += 1; + $i++; + $tot_ttc += $obj->total_ttc; + continue; + } + + $tmpinvoice->id = $obj->rowid; + $tmpinvoice->ref = $obj->ref; + $tmpinvoice->date = $db->jdate($obj->date); + $tmpinvoice->type = $obj->type; + $tmpinvoice->total_ht = $obj->total_ht; + $tmpinvoice->total_tva = $obj->total_tva; + $tmpinvoice->total_ttc = $obj->total_ttc; + $tmpinvoice->ref_client = $obj->ref_client; + $tmpinvoice->statut = $obj->status; + $tmpinvoice->paye = $obj->paye; + + $companystatic->id = $obj->socid; + $companystatic->name = $obj->name; + $companystatic->email = $obj->email; + $companystatic->country_id = $obj->country_id; + $companystatic->country_code = $obj->country_code; + $companystatic->client = 1; + $companystatic->code_client = $obj->code_client; + $companystatic->code_fournisseur = $obj->code_fournisseur; + $companystatic->code_compta = $obj->code_compta; + $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; + + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + $tot_ttc += $obj->total_ttc; + $i++; + } + + if ($othernb) { + $result .= ''; + $result .= ''; + $result .= "\n"; + } + + $result .= ''; + $result .= ''; + $result .= ''; + } else { + $result .= ''; + } + $result .= "
'; + $result .= $langs->trans("CustomersDraftInvoices").' '; + $result .= ''; + $result .= ''.$num.''; + $result .= ''; + $result .= '
'; + $result .= $tmpinvoice->getNomUrl(1, ''); + $result .= ''; + $result .= $companystatic->getNomUrl(1, 'customer'); + $result .= ''.price($obj->total_ttc).'
'; + $result .= ''.$langs->trans("More").'... ('.$othernb.')'; + $result .= '
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'
"; + $db->free($resql); + } else { + dol_print_error($db); + } + + 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 getDraftSupplierTable($maxCount = 500, $socid = 0) +{ + global $conf, $db, $langs, $user, $hookmanager; + + $result = ''; + $facturesupplierstatic = new FactureFournisseur($db); + + $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"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + $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"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT; + $sql .= " AND f.entity IN (".getEntity('invoice').')'; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND f.fk_soc = ".$socid; + } + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters); + $sql .= $hookmanager->resPrint; + $resql = $db->query($sql); + + if ($resql) { + $num = $db->num_rows($resql); + + $result .= '
'; + $result .= ''; + + $result .= ''; + $result .= ''; + $result .= ''; + + if ($num) { + $companystatic = new Societe($db); + + $i = 0; + $othernb = 0; + $tot_ttc = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + + if ($i >= $maxCount) { + $othernb += 1; + $i++; + $tot_ttc += $obj->total_ttc; + continue; + } + + $facturesupplierstatic->ref = $obj->ref; + $facturesupplierstatic->id = $obj->rowid; + $facturesupplierstatic->total_ht = $obj->total_ht; + $facturesupplierstatic->total_tva = $obj->total_tva; + $facturesupplierstatic->total_ttc = $obj->total_ttc; + $facturesupplierstatic->ref_supplier = $obj->ref_supplier; + $facturesupplierstatic->type = $obj->type; + $facturesupplierstatic->statut = $obj->status; + $facturesupplierstatic->paye = $obj->paye; + + $companystatic->id = $obj->socid; + $companystatic->name = $obj->name; + $companystatic->email = $obj->email; + $companystatic->country_id = $obj->country_id; + $companystatic->country_code = $obj->country_code; + $companystatic->fournisseur = 1; + $companystatic->code_client = $obj->code_client; + $companystatic->code_fournisseur = $obj->code_fournisseur; + $companystatic->code_compta = $obj->code_compta; + $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; + + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + $tot_ttc += $obj->total_ttc; + $i++; + } + + if ($othernb) { + $result .= ''; + $result .= ''; + $result .= "\n"; + } + + $result .= ''; + $result .= ''; + $result .= ''; + } else { + $result .= ''; + } + $result .= "
'; + $result .= $langs->trans("SuppliersDraftInvoices").' '; + $result .= ''; + $result .= ''.$num.''; + $result .= ''; + $result .= '
'; + $result .= $facturesupplierstatic->getNomUrl(1, ''); + $result .= ''; + $result .= $companystatic->getNomUrl(1, 'supplier'); + $result .= ''.price($obj->total_ttc).'
'; + $result .= ''.$langs->trans("More").'... ('.$othernb.')'; + $result .= '
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'
"; + $db->free($resql); + } else { + dol_print_error($db); + } + + 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 getCustomerInvoiceLatestEditTable($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 = ".((int) $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 .= '
'.$objectstatic->getNomUrl(1).' '.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'
'; + $result .= '
'.$companystatic->getNomUrl(1, 'customer').''.dol_print_date($db->jdate($obj->datec), 'day').''.$objectstatic->getLibStatut(5).'
'; + $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 getPurchaseInvoiceLatestEditTable($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 of unpaid customers 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 getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0) +{ + global $conf, $db, $langs, $user, $hookmanager; + + $result = ''; + + if (!empty($conf->facture->enabled) && !empty($user->rights->facture->lire)) { + $tmpinvoice = new Facture($db); + + $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms"; + $sql .= ", f.date_lim_reglement as datelimite"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + $sql .= ", sum(pf.amount) as am"; + $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"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED; + $sql .= " AND f.entity IN (".getEntity('invoice').')'; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) { + $sql .= " AND f.fk_soc = ".$socid; + } + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters); + $sql .= $hookmanager->resPrint; + + $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total, f.tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,"; + $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= " ORDER BY f.datef ASC, f.ref ASC"; + + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + $othernb = 0; + + $formfile = new FormFile($db); + + print '
'; + print ''; + + print ''; + print ''; + + print ''; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + if ($num) { + $societestatic = new Societe($db); + $total_ttc = $totalam = $total = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + + if ($i >= $maxCount) { + $othernb += 1; + $i++; + $total += $obj->total_ht; + $total_ttc += $obj->total_ttc; + continue; + } + + $tmpinvoice->ref = $obj->ref; + $tmpinvoice->id = $obj->rowid; + $tmpinvoice->total_ht = $obj->total_ht; + $tmpinvoice->total_tva = $obj->total_tva; + $tmpinvoice->total_ttc = $obj->total_ttc; + $tmpinvoice->type = $obj->type; + $tmpinvoice->statut = $obj->status; + $tmpinvoice->paye = $obj->paye; + $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite); + + $societestatic->id = $obj->socid; + $societestatic->name = $obj->name; + $societestatic->email = $obj->email; + $societestatic->country_id = $obj->country_id; + $societestatic->country_code = $obj->country_code; + $societestatic->client = 1; + $societestatic->code_client = $obj->code_client; + $societestatic->code_fournisseur = $obj->code_fournisseur; + $societestatic->code_compta = $obj->code_compta; + $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur; + + print ''; + print ''; + print ''; + print ''; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + + $total_ttc += $obj->total_ttc; + $total += $obj->total_ht; + $totalam += $obj->am; + + $i++; + } + + if ($othernb) { + $colspan = 6; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + $colspan++; + } + print ''; + print ''; + print "\n"; + } + + print ''; + print ''; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + } else { + $colspan = 6; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + $colspan++; + } + print ''; + } + print '
'; + print $langs->trans("BillsCustomersUnpaid", $num).' '; + print ''; + print ''.$num.''; + print ''; + print ''.$langs->trans("DateDue").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Received").' 
'; + + print ''; + print ''; + print ''; + print '
'; + print $tmpinvoice->getNomUrl(1, ''); + print ''; + if ($tmpinvoice->hasDelay()) { + print img_warning($langs->trans("Late")); + } + print ''; + $filename = dol_sanitizeFileName($obj->ref); + $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref); + $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid; + print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir); + print '
'; + + print '
'; + print $societestatic->getNomUrl(1, 'customer'); + print ''.dol_print_date($db->jdate($obj->datelimite), 'day').''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->am).''.$tmpinvoice->getLibStatut(3, $obj->am).'
'; + print ''.$langs->trans("More").'... ('.$othernb.')'; + print '
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')  '.price($total).''.price($total_ttc).''.price($totalam).' 
'.$langs->trans("NoInvoice").'

'; + $db->free($resql); + } else { + dol_print_error($db); + } + } + + return $result; +} + + +/** + * Return a HTML table that contains of unpaid purchase 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 getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0) +{ + global $conf, $db, $langs, $user, $hookmanager; + + $result = ''; + + if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) { + $facstatic = new FactureFournisseur($db); + + $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"; + $sql .= ", ff.date_lim_reglement"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", sum(pf.amount) as am"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + $sql .= " WHERE s.rowid = ff.fk_soc"; + $sql .= " AND ff.entity = ".$conf->entity; + $sql .= " AND ff.paye = 0"; + $sql .= " AND ff.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 ff.fk_soc = ".$socid; + } + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters); + $sql .= $hookmanager->resPrint; + + $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,"; + $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur"; + $sql .= " ORDER BY ff.date_lim_reglement ASC"; + + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $othernb = 0; + + $formfile = new FormFile($db); + + print '
'; + print ''; + + print ''; + print ''; + + print ''; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + print ''; + } + print ''; + print ''; + print ''; + print "\n"; + $societestatic = new Societe($db); + if ($num) { + $i = 0; + $total = $total_ttc = $totalam = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + + if ($i >= $maxCount) { + $othernb += 1; + $i++; + $total += $obj->total_ht; + $total_ttc += $obj->total_ttc; + continue; + } + + $facstatic->ref = $obj->ref; + $facstatic->id = $obj->rowid; + $facstatic->type = $obj->type; + $facstatic->total_ht = $obj->total_ht; + $facstatic->total_tva = $obj->total_tva; + $facstatic->total_ttc = $obj->total_ttc; + $facstatic->statut = $obj->status; + $facstatic->paye = $obj->paye; + + $societestatic->id = $obj->socid; + $societestatic->name = $obj->name; + $societestatic->email = $obj->email; + $societestatic->client = 0; + $societestatic->fournisseur = 1; + $societestatic->code_client = $obj->code_client; + $societestatic->code_fournisseur = $obj->code_fournisseur; + $societestatic->code_compta = $obj->code_compta; + $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur; + + print ''; + print ''; + print ''; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + $total += $obj->total_ht; + $total_ttc += $obj->total_ttc; + $totalam += $obj->am; + $i++; + } + + if ($othernb) { + $colspan = 6; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + $colspan++; + } + print ''; + print ''; + print "\n"; + } + + print ''; + print ''; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + print ''; + } + print ''; + print ''; + print ''; + print ''; + } else { + $colspan = 6; + if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { + $colspan++; + } + print ''; + } + print '
'; + print $langs->trans("BillsSuppliersUnpaid", $num).' '; + print ''; + print ''.$num.''; + print ''; + print ''.$langs->trans("DateDue").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Paid").' 
'; + print $facstatic->getNomUrl(1, ''); + print ''.$societestatic->getNomUrl(1, 'supplier').''.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->am).''.$facstatic->getLibStatut(3, $obj->am).'
'; + print ''.$langs->trans("More").'... ('.$othernb.')'; + print '
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')  '.price($total).''.price($total_ttc).''.price($totalam).' 
'.$langs->trans("NoInvoice").'

'; + } else { + dol_print_error($db); + } + } + + return $result; +} diff --git a/htdocs/core/modules/modBlockedLog.class.php b/htdocs/core/modules/modBlockedLog.class.php index 16f95a5e926..9a90fa945bb 100644 --- a/htdocs/core/modules/modBlockedLog.class.php +++ b/htdocs/core/modules/modBlockedLog.class.php @@ -113,7 +113,7 @@ class modBlockedLog extends DolibarrModules // ----------------- $this->rights = array(); // Permission array used by this module - $r = 0; + $r = 1; $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) $this->rights[$r][1] = 'Read archived events and fingerprints'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) diff --git a/htdocs/core/modules/modBom.class.php b/htdocs/core/modules/modBom.class.php index 67a480dcc08..6b69c6b7af0 100644 --- a/htdocs/core/modules/modBom.class.php +++ b/htdocs/core/modules/modBom.class.php @@ -205,7 +205,7 @@ class modBom extends DolibarrModules // Permissions provided by this module $this->rights = array(); // Permission array used by this module - $r = 0; + $r = 1; $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) $this->rights[$r][1] = 'Read bom of Bom'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) diff --git a/htdocs/core/modules/modDebugBar.class.php b/htdocs/core/modules/modDebugBar.class.php index 1b591f02da1..ae2bdcfffc8 100644 --- a/htdocs/core/modules/modDebugBar.class.php +++ b/htdocs/core/modules/modDebugBar.class.php @@ -79,7 +79,7 @@ class modDebugBar extends DolibarrModules // Permissions $this->rights = array(); - $this->rights[1][0] = 430; // id de la permission + $this->rights[1][0] = 431; // id de la permission $this->rights[1][1] = 'Use Debug Bar'; // libelle de la permission $this->rights[1][2] = 'u'; // type de la permission (deprecie a ce jour) $this->rights[1][3] = 1; // La permission est-elle une permission par defaut diff --git a/htdocs/core/modules/modEventOrganization.class.php b/htdocs/core/modules/modEventOrganization.class.php index 9ee0cb1b74f..3a81102f4bd 100644 --- a/htdocs/core/modules/modEventOrganization.class.php +++ b/htdocs/core/modules/modEventOrganization.class.php @@ -224,7 +224,8 @@ class modEventOrganization extends DolibarrModules // Permissions provided by this module $this->rights = array(); - $r = 0; + $r = 1; + // Add here entries to declare new permissions /* BEGIN MODULEBUILDER PERMISSIONS */ $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) diff --git a/htdocs/core/modules/modLoan.class.php b/htdocs/core/modules/modLoan.class.php index 30aa547cb3a..b061e1b73a6 100644 --- a/htdocs/core/modules/modLoan.class.php +++ b/htdocs/core/modules/modLoan.class.php @@ -97,7 +97,7 @@ class modLoan extends DolibarrModules $r = 0; $r++; - $this->rights[$r][0] = 520; + $this->rights[$r][0] = 521; $this->rights[$r][1] = 'Read loans'; $this->rights[$r][2] = 'r'; $this->rights[$r][3] = 0; diff --git a/htdocs/core/modules/modMailing.class.php b/htdocs/core/modules/modMailing.class.php index 9d590631fe4..ad14724d154 100644 --- a/htdocs/core/modules/modMailing.class.php +++ b/htdocs/core/modules/modMailing.class.php @@ -48,7 +48,7 @@ class modMailing extends DolibarrModules // It is used to group modules by family in module setup page $this->family = "interface"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '22'; + $this->module_position = '23'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); diff --git a/htdocs/core/modules/modMrp.class.php b/htdocs/core/modules/modMrp.class.php index 0a4a7592a20..eb3baae78cd 100644 --- a/htdocs/core/modules/modMrp.class.php +++ b/htdocs/core/modules/modMrp.class.php @@ -236,7 +236,7 @@ class modMrp extends DolibarrModules // Permissions provided by this module $this->rights = array(); - $r = 0; + $r = 1; // Add here entries to declare new permissions /* BEGIN MODULEBUILDER PERMISSIONS */ $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) diff --git a/htdocs/core/modules/modNotification.class.php b/htdocs/core/modules/modNotification.class.php index e124b8304f3..072e0607b60 100644 --- a/htdocs/core/modules/modNotification.class.php +++ b/htdocs/core/modules/modNotification.class.php @@ -45,7 +45,7 @@ class modNotification extends DolibarrModules // It is used to group modules in module setup page $this->family = "interface"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '01'; + $this->module_position = '22'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); $this->description = "EMail notifications (push) on business Dolibarr events"; diff --git a/htdocs/core/modules/modReceiptPrinter.class.php b/htdocs/core/modules/modReceiptPrinter.class.php index 4fe437700e4..ee87f4c57ba 100644 --- a/htdocs/core/modules/modReceiptPrinter.class.php +++ b/htdocs/core/modules/modReceiptPrinter.class.php @@ -95,7 +95,7 @@ class modReceiptPrinter extends DolibarrModules // $this->rights[$r][5] Niveau 2 pour nommer permission dans code $r++; - $this->rights[$r][0] = 67000; + $this->rights[$r][0] = 67001; $this->rights[$r][1] = 'ReceiptPrinter'; $this->rights[$r][2] = 'r'; $this->rights[$r][3] = 0; diff --git a/htdocs/core/modules/modWorkstation.class.php b/htdocs/core/modules/modWorkstation.class.php index 02f5e059297..b0fae39bb52 100755 --- a/htdocs/core/modules/modWorkstation.class.php +++ b/htdocs/core/modules/modWorkstation.class.php @@ -45,12 +45,12 @@ class modWorkstation extends DolibarrModules // Id for module (must be unique). // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). - $this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module + $this->numero = 690; // Key text used to identify module (for permissions, menus, etc...) $this->rights_class = 'workstation'; // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...' // It is used to group modules by family in module setup page - $this->family = "other"; + $this->family = "products"; // Module position in the family on 2 digits ('01', '10', '20', ...) $this->module_position = '90'; // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) @@ -71,7 +71,7 @@ class modWorkstation extends DolibarrModules // Name of image file used for this module. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' - $this->picto = 'mrp'; + $this->picto = 'workstation'; // Define some features supported by module (triggers, login, substitutions, menus, css, etc...) $this->module_parts = array( // Set this to 1 if module has its own trigger directory (core/triggers) @@ -239,7 +239,7 @@ class modWorkstation extends DolibarrModules // Permissions provided by this module $this->rights = array(); - $r = 0; + $r = 1; // Add here entries to declare new permissions /* BEGIN MODULEBUILDER PERMISSIONS */ $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) @@ -330,6 +330,7 @@ class modWorkstation extends DolibarrModules // This is a Left menu entry 'type'=>'left', 'titre'=>$langs->trans('Workstations'), + 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'), 'mainmenu'=>'mrp', 'leftmenu'=>'workstation_workstation', 'url'=>'', diff --git a/htdocs/core/modules/modZapier.class.php b/htdocs/core/modules/modZapier.class.php index 5685a30c701..430622465ca 100644 --- a/htdocs/core/modules/modZapier.class.php +++ b/htdocs/core/modules/modZapier.class.php @@ -242,7 +242,7 @@ class modZapier extends DolibarrModules // Permission array used by this module $this->rights = array(); - $r = 0; + $r = 1; // Permission id (must not be already used) $this->rights[$r][0] = $this->numero + $r; // Permission label diff --git a/htdocs/fourn/facture/index.php b/htdocs/fourn/facture/index.php index 1e3c4f5e686..e76426f54c2 100644 --- a/htdocs/fourn/facture/index.php +++ b/htdocs/fourn/facture/index.php @@ -25,6 +25,7 @@ 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'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php'; // Security check restrictedArea($user, 'fournisseur', 0, '', 'facture'); @@ -39,6 +40,8 @@ if (isset($user->socid) && $user->socid > 0) { $socid = $user->socid; } +$max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; + // Maximum elements of the tables $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD; $maxLatestEditCount = 5; @@ -56,24 +59,18 @@ 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 getPurchaseInvoicePieChart($socid); print '
'; -print getDraftTable($maxDraftCount, $socid); +print getDraftSupplierTable($maxDraftCount, $socid); print '
'; print '
'; print '
'; -print getLatestEditTable($maxLatestEditCount, $socid); +print getPurchaseInvoiceLatestEditTable($maxLatestEditCount, $socid); print '
'; -print getOpenTable($maxOpenCount, $socid); +print getPurchaseInvoiceUnpaidOpenTable($max, $socid); print '
'; print '
'; @@ -83,453 +80,3 @@ 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(2); - $dolgraph->setShowPercent(1); - $dolgraph->SetType(['pie']); - $dolgraph->setHeight('200'); - $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/install/upgrade2.php b/htdocs/install/upgrade2.php index 32959af80cc..0db923b138f 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -456,6 +456,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ $listofmodule = array( 'MAIN_MODULE_ACCOUNTING'=>'newboxdefonly', 'MAIN_MODULE_AGENDA'=>'newboxdefonly', + 'MAIN_MODULE_BOM'=>'menuonly', 'MAIN_MODULE_BANQUE'=>'menuonly', 'MAIN_MODULE_BARCODE'=>'newboxdefonly', 'MAIN_MODULE_CRON'=>'newboxdefonly', @@ -470,6 +471,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ 'MAIN_MODULE_FOURNISSEUR'=>'newboxdefonly', 'MAIN_MODULE_HOLIDAY'=>'newboxdefonly', 'MAIN_MODULE_MARGIN'=>'menuonly', + 'MAIN_MODULE_MRP'=>'menuonly', 'MAIN_MODULE_OPENSURVEY'=>'newboxdefonly', 'MAIN_MODULE_PAYBOX'=>'newboxdefonly', 'MAIN_MODULE_PRINTING'=>'newboxdefonly', diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 857ef41bbc2..202f11f7f46 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1977,7 +1977,7 @@ MAIN_PDF_MARGIN_BOTTOM=Bottom margin on PDF MAIN_DOCUMENTS_LOGO_HEIGHT=Height for logo on PDF NothingToSetup=There is no specific setup required for this module. SetToYesIfGroupIsComputationOfOtherGroups=Set this to yes if this group is a computation of other groups -EnterCalculationRuleIfPreviousFieldIsYes=Enter calculation rule if previous field was set to Yes (For example 'CODEGRP1+CODEGRP2') +EnterCalculationRuleIfPreviousFieldIsYes=Enter calculation rule if previous field was set to Yes.
For example:
CODEGRP1+CODEGRP2 SeveralLangugeVariatFound=Several language variants found RemoveSpecialChars=Remove special characters COMPANY_AQUARIUM_CLEAN_REGEX=Regex filter to clean value (COMPANY_AQUARIUM_CLEAN_REGEX) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 301d26333cc..340ae1bf9e7 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -62,7 +62,7 @@ EnhancedValueOfWarehouses=Warehouses value UserWarehouseAutoCreate=Create a user warehouse automatically when creating a user AllowAddLimitStockByWarehouse=Manage also value for minimum and desired stock per pairing (product-warehouse) in addition to the value for minimum and desired stock per product RuleForWarehouse=Rule for warehouses -WarehouseAskWarehouseOnThirparty=Set a warehouse on thirparty +WarehouseAskWarehouseOnThirparty=Set a warehouse on third-party WarehouseAskWarehouseDuringPropal=Set a warehouse on Commercial proposals WarehouseAskWarehouseDuringOrder=Set a warehouse on Sale orders UserDefaultWarehouse=Set a warehouse on Users diff --git a/htdocs/theme/eldy/img/object_zapier.png b/htdocs/theme/eldy/img/object_zapier.png index b1337750b67..b244cb1d5d6 100644 Binary files a/htdocs/theme/eldy/img/object_zapier.png and b/htdocs/theme/eldy/img/object_zapier.png differ diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index b3303492417..db9010cc504 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -673,8 +673,7 @@ class User extends CommonObject if (!empty($rid)) { $module = $perms = $subperms = ''; - // Si on a demande ajout d'un droit en particulier, on recupere - // les caracteristiques (module, perms et subperms) de ce droit. + // Si on a demande ajout d'un droit en particulier, on recupere les caracteristiques (module, perms et subperms) de ce droit. $sql = "SELECT module, perms, subperms"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; $sql .= " WHERE id = ".((int) $rid); @@ -718,7 +717,7 @@ class User extends CommonObject } } - // Ajout des droits trouves grace au critere whereforadd + // Add automatically other permission using the criteria whereforadd if (!empty($whereforadd)) { //print "$module-$perms-$subperms"; $sql = "SELECT id"; diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index 48b44d2fc57..e80cb6c8462 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -105,7 +105,7 @@ if (empty($reshook)) { setEventMessages($edituser->error, $edituser->errors, 'errors'); } - // If we are changing our own permissions, we reload + // If we are changing our own permissions, we reload permissions and menu if ($object->id == $user->id) { $user->clearrights(); $user->getrights(); @@ -124,7 +124,7 @@ if (empty($reshook)) { setEventMessages($edituser->error, $edituser->errors, 'errors'); } - // If we are changing our own permissions, we reload + // If we are changing our own permissions, we reload permissions and menu if ($object->id == $user->id) { $user->clearrights(); $user->getrights(); @@ -288,7 +288,7 @@ if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->ad } print ''.$langs->trans("Permissions").''; if ($user->admin) { - print ''.$langs->trans("ID").''; + print ''; } print ''."\n"; @@ -438,7 +438,12 @@ if ($result) { // Permission id if ($user->admin) { - print ''.$obj->id.''; + print ''; + $htmltext = $langs->trans("ID").': '.$obj->id; + $htmltext .= '
'.$langs->trans("Permission").': user->rights->'.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : ''); + print $form->textwithpicto('', $htmltext); + //print ''.$obj->id.''; + print ''; } print ''."\n"; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 3e4c56cd240..26ca6df9bf8 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -895,6 +895,7 @@ if ($action == 'addcontainer' && $usercanedit) { getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto); + // We try to convert the CSS we got by adding a prefix .bodywebsite with lessc to avoid conflicit with CSS of Dolibarr. include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php'; $lesscobj = new Lessc(); try { diff --git a/htdocs/workstation/class/workstation.class.php b/htdocs/workstation/class/workstation.class.php index 07edb353aa4..b4364a2cc82 100755 --- a/htdocs/workstation/class/workstation.class.php +++ b/htdocs/workstation/class/workstation.class.php @@ -61,7 +61,7 @@ class Workstation extends CommonObject /** * @var string String with name of icon for workstation. Must be the part after the 'object_' into object_workstation.png */ - public $picto = 'mrp'; + public $picto = 'workstation'; const STATUS_DISABLED = 0; @@ -100,7 +100,7 @@ class Workstation extends CommonObject */ public $fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"), - 'ref' => array('type'=>'varchar(128)', 'picto'=>'mrp', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>1, 'noteditable'=>'0', 'default'=>'', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"), + 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>1, 'noteditable'=>'0', 'default'=>'', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"), 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'showoncombobox'=>'1',), 'type' => array('type'=>'select', 'label'=>'Type', 'enabled'=>'1', 'position'=>32, 'default'=>1, 'notnull'=>1, 'visible'=>1, 'arrayofkeyval'=>array('HUMAN'=>'Human', 'MACHINE'=>'Machine', 'BOTH'=>'HumanMachine'),), 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,), diff --git a/htdocs/workstation/workstation_agenda.php b/htdocs/workstation/workstation_agenda.php index 8096aa3d771..f33961d5768 100755 --- a/htdocs/workstation/workstation_agenda.php +++ b/htdocs/workstation/workstation_agenda.php @@ -82,13 +82,11 @@ if ($id > 0 || !empty($ref)) { $upload_dir = $conf->workstation->multidir_output[$object->entity]."/".$object->id; } -// Security check - Protection if external user -//if ($user->socid > 0) accessforbidden(); -//if ($user->socid > 0) $socid = $user->socid; -//$result = restrictedArea($user, 'workstation', $object->id); - $permissiontoadd = $user->rights->workstation->workstation->write; // Used by the include of actions_addupdatedelete.inc.php +// Security check +restrictedArea($user, $object->element, $object->id, '', 'workstation'); + /* * Actions @@ -134,7 +132,7 @@ if ($object->id > 0) { $head = workstationPrepareHead($object); - print dol_get_fiche_head($head, 'agenda', $langs->trans("Workstation"), -1, 'mrp'); + print dol_get_fiche_head($head, 'agenda', $langs->trans("Workstation"), -1, 'workstation'); // Object card // ------------------------------------------------------------ diff --git a/htdocs/workstation/workstation_card.php b/htdocs/workstation/workstation_card.php index b64f15e1f76..8f351523ecb 100755 --- a/htdocs/workstation/workstation_card.php +++ b/htdocs/workstation/workstation_card.php @@ -82,15 +82,8 @@ $permissionnote = $user->rights->workstation->workstation->write; // Used by the $permissiondellink = $user->rights->workstation->workstation->write; // Used by the include of actions_dellink.inc.php $upload_dir = $conf->workstation->multidir_output[isset($object->entity) ? $object->entity : 1]; -// Security check - Protection if external user -//if ($user->socid > 0) accessforbidden(); -//if ($user->socid > 0) $socid = $user->socid; -//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0); -//$result = restrictedArea($user, 'workstation', $object->id, '', '', 'fk_soc', 'rowid', $isdraft); - -if (!$permissiontoread) { - accessforbidden(); -} +// Security check +restrictedArea($user, $object->element, $object->id, '', 'workstation'); /* @@ -219,7 +212,7 @@ if ($action == 'create') { print ''; print ''; print img_picto('', 'group'); - print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $object->entity, true); + print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'minwidth200'); print ''; print ''; @@ -227,7 +220,7 @@ if ($action == 'create') { print ''; print ''; print img_picto('', 'resource'); - print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $object->entity, true, 0, '', true); + print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $object->entity, true, 0, 'minwidth200', true); print ''; // Other attributes @@ -343,7 +336,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Object card // ------------------------------------------------------------ - $linkback = ''.$langs->trans("BackToList").''; + $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; /* diff --git a/htdocs/workstation/workstation_document.php b/htdocs/workstation/workstation_document.php index 2c1a9906c8e..2deb06579b8 100755 --- a/htdocs/workstation/workstation_document.php +++ b/htdocs/workstation/workstation_document.php @@ -74,13 +74,10 @@ if ($id > 0 || !empty($ref)) { $upload_dir = $conf->workstation->multidir_output[$object->entity ? $object->entity : $conf->entity]."/workstation/".get_exdir(0, 0, 0, 1, $object); } -// Security check - Protection if external user -//if ($user->socid > 0) accessforbidden(); -//if ($user->socid > 0) $socid = $user->socid; -//$result = restrictedArea($user, 'workstation', $object->id); - $permissiontoadd = $user->rights->workstation->workstation->write; // Used by the include of actions_addupdatedelete.inc.php +// Security check +restrictedArea($user, $object->element, $object->id, '', 'workstation'); /* diff --git a/htdocs/workstation/workstation_list.php b/htdocs/workstation/workstation_list.php index 59dbfc658d3..40265496dbf 100755 --- a/htdocs/workstation/workstation_list.php +++ b/htdocs/workstation/workstation_list.php @@ -28,9 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php'; - -// load workstation libraries -require_once __DIR__.'/class/workstation.class.php'; +require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php'; // Load translation files required by the page $langs->loadLangs(array("workstation", "other")); @@ -87,8 +85,9 @@ foreach ($object->fields as $key => $val) { if (GETPOST('search_'.$key, 'alpha') !== '') { $search[$key] = GETPOST('search_'.$key, 'alpha'); } - if (in_array($key, array('type', 'status')) && GETPOST('search_'.$key, 'alpha') == -1) { - $search[$key] = ''; + if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { + $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int')); + $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int')); } } @@ -108,7 +107,7 @@ $arrayfields = array(); foreach ($object->fields as $key => $val) { // If $val['visible']==0, then we never show the field if (!empty($val['visible'])) { - $visible = dol_eval($val['visible'], 1); + $visible = (int) dol_eval($val['visible'], 1); $arrayfields['t.'.$key] = array( 'label'=>$val['label'], 'checked'=>(($visible < 0) ? 0 : 1), @@ -146,18 +145,7 @@ $permissiontoadd = $user->rights->workstation->workstation->write; $permissiontodelete = $user->rights->workstation->workstation->delete; // Security check -if (empty($conf->workstation->enabled)) { - accessforbidden('Module not enabled'); -} -$socid = 0; -if ($user->socid > 0) { - // Protection if external user - //$socid = $user->socid; - accessforbidden(); -} -//$result = restrictedArea($user, 'workstation', $id, ''); -//if (!$permissiontoread) accessforbidden(); - +restrictedArea($user, $object->element, 0, '', 'workstation'); /* @@ -165,7 +153,8 @@ if ($user->socid > 0) { */ if (GETPOST('cancel', 'alpha')) { - $action = 'list'; $massaction = ''; + $action = 'list'; + $massaction = ''; } if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; @@ -185,6 +174,10 @@ if (empty($reshook)) { if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers foreach ($object->fields as $key => $val) { $search[$key] = ''; + if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { + $search[$key.'_dtstart'] = ''; + $search[$key.'_dtend'] = ''; + } } $groups=$resources=array(); $toselect = ''; @@ -214,19 +207,15 @@ $formresource = new FormResource($db); $now = dol_now(); $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("Workstations")); - -//$help_url="EN:Module_Workstation|FR:Module_Workstation_FR|ES:Módulo_Workstation"; $help_url = 'EN:Module_Workstation'; - -llxHeader('', $title, $help_url); +$morejs = array(); +$morecss = array(); // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT '; -foreach ($object->fields as $key => $val) { - $sql .= 't.'.$key.', '; -} +$sql .= $object->getFieldList('t'); // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { @@ -258,18 +247,32 @@ if ($object->ismultientitymanaged == 1) { $sql .= " WHERE 1 = 1"; } foreach ($search as $key => $val) { - if ($key == 'status' && $search[$key] == -1) { - continue; - } - $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); - if (strpos($object->fields[$key]['type'], 'integer:') === 0) { - if ($search[$key] == '-1') { - $search[$key] = ''; + if (array_key_exists($key, $object->fields)) { + if ($key == 'status' && $search[$key] == -1) { + continue; + } + $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); + if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0)) { + if ($search[$key] == '-1' || $search[$key] === '0') { + $search[$key] = ''; + } + $mode_search = 2; + } + if ($search[$key] != '') { + $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); + } + } else { + if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') { + $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key); + if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) { + if (preg_match('/_dtstart$/', $key)) { + $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'"; + } + if (preg_match('/_dtend$/', $key)) { + $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'"; + } + } } - $mode_search = 2; - } - if ($search[$key] != '') { - $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search)); } } if ($search_all) { @@ -294,10 +297,8 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; -/* If a group by is required $sql.= " GROUP BY "; -foreach($object->fields as $key => $val) -{ +foreach ($object->fields as $key => $val) { $sql.='t.'.$key.', '; } // Add fields from extrafields @@ -306,11 +307,9 @@ if (! empty($extrafields->attributes[$object->table_element]['label'])) { } // Add where from hooks $parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook +$reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; -$sql=preg_replace('/,\s*$/','', $sql); -*/ -$sql.= ' GROUP BY t.rowid'; +$sql=preg_replace('/,\s*$/', '', $sql); $sql .= $db->order($sortfield, $sortorder); // Count total nb of records @@ -352,7 +351,7 @@ if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $ // Output page // -------------------------------------------------------------------- -llxHeader('', $title, $help_url); +llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs'); // Example : Adding jquery code print '