diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index 4110781298d..366681eeea8 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -48,6 +48,12 @@ if (!empty($user->socid)) { // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('productstatsinvoice')); +$extrafields = new ExtraFields($db); + +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label('facture'); + +$search_array_options = $extrafields->getOptionalsFromPost('facture', '', 'search_'); $showmessage = GETPOST('showmessage'); @@ -160,12 +166,32 @@ if ($id > 0 || !empty($ref)) { if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { $sql .= ", sc.fk_soc, sc.fk_user "; } + // Add fields from extrafields + if (!empty($extrafields->attributes['facture']['label'])) { + foreach ($extrafields->attributes['facture']['label'] as $key => $val) { + $sql .= ($extrafields->attributes['facture']['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : ''); + } + } + // Add fields from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; + $sql = preg_replace('/,\s*$/', '', $sql); + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."facture as f"; + if (isset($extrafields->attributes['facture']['label']) && is_array($extrafields->attributes['facture']['label']) && count($extrafields->attributes['facture']['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.'facture'."_extrafields as ef on (f.rowid = ef.fk_object)"; + } $sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } + // Add table from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; + $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; $sql .= " AND d.fk_facture = f.rowid"; @@ -182,6 +208,18 @@ if ($id > 0 || !empty($ref)) { if ($socid) { $sql .= " AND f.fk_soc = ".((int) $socid); } + // Add where from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; + + // Add HAVING from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint; + $sql .= $db->order($sortfield, $sortorder); // Calcul total qty and amount for global if full scan list @@ -213,6 +251,13 @@ if ($id > 0 || !empty($ref)) { $option .= '&search_year='.urlencode($search_year); } + // Add $param from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + // Add $param from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $option .= $hookmanager->resPrint; + print '
'."\n"; print ''; if (!empty($sortfield)) { @@ -233,6 +278,10 @@ if ($id > 0 || !empty($ref)) { print $langs->trans('Period').' ('.$langs->trans("DateInvoice").') - '; print $langs->trans('Month').': '; print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + print '
'; print ''; print ''; @@ -251,6 +300,10 @@ if ($id > 0 || !empty($ref)) { print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder); print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); + // Hook fields + $parameters = array('param'=>$option, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); + $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print "\n"; if ($num > 0) { @@ -280,6 +333,10 @@ if ($id > 0 || !empty($ref)) { print ''.$objp->qty."\n"; print ''.price($objp->total_ht)."\n"; print ''.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5, $paiement, $objp->type).''; + // Fields from hook + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print "\n"; $i++; }