diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 2c6fe91ac33..18d40dbf836 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -85,6 +85,8 @@ class AccountancyExport public static $EXPORT_TYPE_GESTIMUMV5 = 135; /** @var int */ public static $EXPORT_TYPE_ISUITEEXPERT = 200; + /** @var int */ + public static $EXPORT_TYPE_ISTEA = 205; // Generic FEC after that /** @var int */ public static $EXPORT_TYPE_FEC = 1000; @@ -161,6 +163,7 @@ class AccountancyExport self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'), self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'), self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert', + self::$EXPORT_TYPE_ISTEA => $langs->trans('Modelcsv_ISTEA'), ); $listofgenericformatexport = array( @@ -223,6 +226,7 @@ class AccountancyExport self::$EXPORT_TYPE_FEC => 'fec', self::$EXPORT_TYPE_FEC2 => 'fec2', self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert', + self::$EXPORT_TYPE_ISTEA => 'istea', ); global $hookmanager; @@ -317,6 +321,10 @@ class AccountancyExport 'label' => 'iSuite Expert', 'ACCOUNTING_EXPORT_FORMAT' => 'csv', ), + self::$EXPORT_TYPE_ISTEA => array( + 'label' => 'ISTEA', + 'ACCOUNTING_EXPORT_FORMAT' => 'csv', + ), ), 'cr' => array( '1' => $langs->trans("Unix"), @@ -539,6 +547,9 @@ class AccountancyExport case self::$EXPORT_TYPE_ISUITEEXPERT: $this->exportiSuiteExpert($TData, $exportFile); break; + case self::$EXPORT_TYPE_ISTEA: + $this->exportISTEA($TData, $exportFile); + break; default: global $hookmanager; $parameters = array('format' => $formatexportset, 'exportFile' => $exportFile); @@ -1345,6 +1356,63 @@ class AccountancyExport } } + /** + * Export format : ISTEA + * + * @param BookKeepingLine[] $objectLines data + * @param ?resource $exportFile [=null] File resource to export or print if null + * @return void + */ + public function exportISTEA($objectLines, $exportFile = null) + { + global $conf; + + $separator = ';'; + $end_line = "\n"; + + // parcours du tableau pour recuperation des numero de compte des tiers pour pouvoir les fournir dans la bonne ligne pour istea + $tiers=[]; + foreach ($objectLines as $line) { + if ( $line->subledger_account && substr($line->subledger_account, 0, 1) == '4' ) { + $tiers[$line->piece_num] = $line->subledger_label; + } + } + + foreach ($objectLines as $line) { + $date_document = dol_print_date($line->doc_date, '%d/%m/%Y'); + + /*** preparation du champ label operation pour istea ***/ + // retrecissement du champs car ISTEA n'affiche pas bcp de caract�re. + $search = array('Paiement fournisseur ', 'Virement ', 'Paiement '); + $replace = array('Paiemt fourn ','Virt ','Paiemt '); + $label_operation = str_replace($search, $replace, $line->label_operation); + // encadrement par des ' si le champs contient le separateur + $label_operation = preg_match('/'.$separator.'/', $label_operation) ? "'".$label_operation."'" : $label_operation; + + $tab = array(); + // export configurable + $tab[] = $line->piece_num; // colonne 1 : numero de piece ISTEA + $tab[] = $date_document; // colonne 2 : date ISTEA + $tab[] = $line->doc_ref; // colonne 3 : reference piece ISTEA + $tab[] = array_key_exists($line->piece_num, $tiers)?$tiers[$line->piece_num]:''; // colonne 4 : nom tiers ISTEA + $tab[] = length_accountg(($line->subledger_account && ( substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2) ) )?$line->subledger_account:$line->numero_compte); // colonne 5 : numero de compte ISTEA + $tab[] = length_accountg($line->subledger_account?$line->subledger_account:$line->numero_compte); // colonne 6 : numero de compte + $tab[] = length_accountg($line->subledger_account?$line->numero_compte:''); // G // colonne 7 : numero de compte principal (divers paiement ou 40100000 ou 41100000) + $tab[] = ($line->doc_type == 'bank')?$label_operation:($line->subledger_account?$line->subledger_label:$line->label_compte); // colonne 8 : label de l'operation ISTEA + $tab[] = $label_operation; // colonne 9 : label de l'operation (semble non prise en compte par ISTEA) + $tab[] = price2num($line->debit); // colonne 10 : debit ISTEA + $tab[] = price2num($line->credit); // colonne 11 : credit ISTEA + $tab[] = $line->code_journal; // colonne 12 : journal ISTEA + + $output = mb_convert_encoding('"'.implode('"'.$separator.'"', $tab).'"'.$this->end_line, 'ISO-8859-1'); + if ($exportFile) { + fwrite($exportFile, $output); + } else { + print $output; + } + } + } + /** * Export format : FEC * Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi.fr) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 655b9182d40..55822cedadd 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -891,6 +891,7 @@ if ($object->id > 0) { * Latest proposals */ if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) { + $propal_static = new Propal($db); $langs->load("propal"); $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_projet, p.fk_statut, p.total_ht"; @@ -902,12 +903,13 @@ if ($object->id > 0) { $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id"; $sql .= " AND s.rowid = ".((int) $object->id); $sql .= " AND p.entity IN (".getEntity('propal').")"; + $parameters = array(); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $propal_static); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY p.datep DESC"; $resql = $db->query($sql); if ($resql) { - $propal_static = new Propal($db); - $num = $db->num_rows($resql); if ($num > 0) { print '
'; @@ -996,6 +998,7 @@ if ($object->id > 0) { * Latest orders */ if (isModEnabled('order') && $user->hasRight('commande', 'lire')) { + $commande_static = new Commande($db); $sql = "SELECT s.nom, s.rowid"; $sql .= ", c.rowid as cid, c.entity, c.fk_projet, c.total_ht"; $sql .= ", c.total_tva"; @@ -1007,12 +1010,13 @@ if ($object->id > 0) { $sql .= " WHERE c.fk_soc = s.rowid "; $sql .= " AND s.rowid = ".((int) $object->id); $sql .= " AND c.entity IN (".getEntity('commande').')'; + $parameters = array(); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $commande_static); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.date_commande DESC"; $resql = $db->query($sql); if ($resql) { - $commande_static = new Commande($db); - $num = $db->num_rows($resql); if ($num > 0) { // Check if there are orders billable diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 062fb7e68da..8d07fd48f36 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -168,6 +168,10 @@ if (isModEnabled("propal") && $user->hasRight("propal", "lire") && is_object($pr if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { @@ -269,7 +273,10 @@ if (isModEnabled('supplier_proposal') && $user->hasRight("supplier_proposal", "l if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $supplierproposalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { $total = 0; @@ -367,7 +374,10 @@ if (isModEnabled('order') && $user->hasRight('commande', 'lire') && is_object($o if ($socid) { $sql .= " AND c.fk_soc = ".((int) $socid); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { $total = 0; @@ -469,7 +479,10 @@ if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMO if ($socid) { $sql .= " AND cf.fk_soc = ".((int) $socid); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $supplierorderstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { $total = 0; @@ -569,7 +582,10 @@ if (isModEnabled('intervention') && is_object($fichinterstatic)) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $fichinterstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -742,12 +758,12 @@ if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) { */ if (isModEnabled('propal') && is_object($propalstatic)) { - $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.tms as datem,"; + $sql = "SELECT p.rowid, p.entity, p.ref, p.fk_statut as status, p.tms as datem,"; $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal as c,"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p,"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; - $sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")"; - $sql .= " AND c.fk_soc = s.rowid"; + $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")"; + $sql .= " AND p.fk_soc = s.rowid"; // If the internal user must only see his customers, force searching by him $search_sale = 0; if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { @@ -756,16 +772,20 @@ if (isModEnabled('propal') && is_object($propalstatic)) { // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { - $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)"; + $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)"; } elseif ($search_sale > 0) { - $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; + $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } // Search on socid if ($socid) { - $sql .= " AND c.fk_soc = ".((int) $socid); + $sql .= " AND p.fk_soc = ".((int) $socid); } - $sql .= " ORDER BY c.tms DESC"; + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; + $sql .= " ORDER BY p.tms DESC"; $sql .= $db->plimit($max, 0); @@ -857,6 +877,10 @@ if (isModEnabled('order')) { if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.tms DESC"; $sql .= $db->plimit($max, 0); @@ -1061,6 +1085,10 @@ if (isModEnabled('contract') && $user->hasRight("contrat", "lire") && 0) { // TO if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $staticcontrat); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.tms DESC"; $sql .= $db->plimit($max + 1, 0); @@ -1137,6 +1165,10 @@ if (isModEnabled("propal") && $user->hasRight("propal", "lire")) { if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY p.rowid DESC"; $resql = $db->query($sql); @@ -1258,6 +1290,10 @@ if (isModEnabled('order') && $user->hasRight('commande', 'lire') && is_object($o if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.rowid DESC"; $resql = $db->query($sql); diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index e4984ff4205..be57b1dbd69 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -187,6 +187,8 @@ class Proposals extends DolibarrApi */ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false, $loadlinkedobjects = 0) { + global $hookmanager; + if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) { throw new RestException(403); } @@ -201,7 +203,6 @@ class Proposals extends DolibarrApi if (!DolibarrApiAccess::$user->hasRight('societe', 'client', 'voir') && !$socids) { $search_sale = DolibarrApiAccess::$user->id; } - $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."propal AS t"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe AS s ON (s.rowid = t.fk_soc)"; @@ -218,6 +219,9 @@ class Proposals extends DolibarrApi $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } + $parameters = array(); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $this->propal); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; // Add sql filters if ($sqlfilters) { $errormessage = ''; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index e33da456a7f..bb8a641ec6d 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3500,7 +3500,7 @@ class Propal extends CommonObject public function load_board($user, $mode) { // phpcs:enable - global $conf, $langs; + global $conf, $langs, $hookmanager; $clause = " WHERE"; @@ -3529,6 +3529,10 @@ class Propal extends CommonObject if ($user->socid) { $sql .= " AND p.fk_soc = ".((int) $user->socid); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { @@ -3687,7 +3691,7 @@ class Propal extends CommonObject */ public function loadStateBoard() { - global $user; + global $user, $hookmanager; $this->nb = array(); $clause = "WHERE"; @@ -3711,6 +3715,10 @@ class Propal extends CommonObject } } + // Add where from hooks + $parameters = array(); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { // This assignment in condition is not a bug. It allows walking the results. diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index ab24c41a58b..df107fd116f 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -85,11 +85,12 @@ class PropaleStats extends Stats */ public function __construct($db, $socid = 0, $userid = 0, $mode = 'customer', $typentid = 0, $categid = 0) { + global $hookmanager; $this->db = $db; $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; $this->join = ''; - + $object = null; if ($mode == 'customer') { $object = new Propal($this->db); @@ -129,6 +130,10 @@ class PropaleStats extends Stats if ($categid) { $this->where .= ' AND EXISTS (SELECT rowid FROM '.MAIN_DB_PREFIX.'categorie_societe as cats WHERE cats.fk_soc = p.fk_soc AND cats.fk_categorie = '.((int) $categid).')'; } + // Add where from hooks + $parameters = array('socid' => $socid); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook + $this->where .= $hookmanager->resPrint; } @@ -153,7 +158,6 @@ class PropaleStats extends Stats $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); - $res = $this->_getNbByMonth($year, $sql, $format); return $res; } diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index 1d3bc091b1c..7ff7a943aaa 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -111,7 +111,10 @@ if (isModEnabled("propal")) { if ($socid) { $sql .= " AND p.fk_soc = ".((int) $socid); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -171,12 +174,12 @@ print '
'; * Last modified proposals */ -$sql = "SELECT c.rowid, c.entity, c.ref, c.total_ht, c.total_tva, c.total_ttc, c.fk_statut as status, date_cloture as datec, c.tms as datem,"; +$sql = "SELECT p.rowid, p.entity, p.ref, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status, date_cloture as datec, p.tms as datem,"; $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client"; -$sql .= " FROM ".MAIN_DB_PREFIX."propal as c,"; +$sql .= " FROM ".MAIN_DB_PREFIX."propal as p,"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; -$sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")"; -$sql .= " AND c.fk_soc = s.rowid"; +$sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")"; +$sql .= " AND p.fk_soc = s.rowid"; // If the internal user must only see his customers, force searching by him $search_sale = 0; if (!$user->hasRight('societe', 'client', 'voir')) { @@ -185,16 +188,20 @@ if (!$user->hasRight('societe', 'client', 'voir')) { // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { - $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)"; + $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)"; } elseif ($search_sale > 0) { - $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; + $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } // Search on socid if ($socid) { - $sql .= " AND c.fk_soc = ".((int) $socid); + $sql .= " AND p.fk_soc = ".((int) $socid); } -$sql .= " ORDER BY c.tms DESC"; +// Add where from hooks +$parameters = array('socid' => $user->socid); +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; +$sql .= " ORDER BY p.tms DESC"; $sql .= $db->plimit($max, 0); @@ -289,6 +296,10 @@ if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) { if ($socid) { $sql .= " AND p.fk_soc = ".((int) $socid); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY p.rowid DESC"; $resql = $db->query($sql); diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 3972551f4d6..c62359d0f94 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -179,6 +179,8 @@ class Orders extends DolibarrApi */ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $sqlfilterlines = '', $properties = '', $pagination_data = false, $loadlinkedobjects = 0) { + global $hookmanager; + if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) { throw new RestException(403); } @@ -210,6 +212,9 @@ class Orders extends DolibarrApi $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")"; } } + $parameters = array(); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $this->commande); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; // Add sql filters if ($sqlfilters) { $errormessage = ''; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f62cb3f9d01..8de4c416b0a 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3627,7 +3627,7 @@ class Commande extends CommonOrder public function load_board($user, $mode) { // phpcs:enable - global $conf, $langs; + global $conf, $langs, $hookmanager; $clause = " WHERE"; @@ -3655,7 +3655,10 @@ class Commande extends CommonOrder if ($user->socid) { $sql .= " AND c.fk_soc = ".((int) $user->socid); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { $delay_warning = 0; @@ -4150,21 +4153,24 @@ class Commande extends CommonOrder */ public function loadStateBoard() { - global $user; + global $user, $hookmanager; $this->nb = array(); $clause = "WHERE"; - $sql = "SELECT count(co.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as co"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON co.fk_soc = s.rowid"; + $sql = "SELECT count(c.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql .= " WHERE sc.fk_user = ".((int) $user->id); $clause = "AND"; } - $sql .= " ".$clause." co.entity IN (".getEntity('commande').")"; - + $sql .= " ".$clause." c.entity IN (".getEntity('commande').")"; + // Add where from hooks + $parameters = array(); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index d1f4d8798a5..b7b25eb9bed 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -100,12 +100,14 @@ class CommandeStats extends Stats */ public function __construct($db, $socid, $mode, $userid = 0, $typentid = 0, $categid = 0) { + global $hookmanager; $this->db = $db; $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; $this->cachefilesuffix = $mode; $this->join = ''; + $object = null; if ($mode == 'customer') { $object = new Commande($this->db); @@ -142,6 +144,10 @@ class CommandeStats extends Stats if ($categid) { $this->where .= ' AND EXISTS (SELECT rowid FROM '.$this->categ_link.' as cats WHERE cats.fk_soc = c.fk_soc AND cats.fk_categorie = '.((int) $categid).')'; } + // Add where from hooks + $parameters = array('socid' => $socid); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook + $this->where .= $hookmanager->resPrint; } /** diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index cfbd0fafdb9..036f898424d 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -117,7 +117,10 @@ if (isModEnabled('order')) { if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } - + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $db->query($sql); if ($resql) { print '
'; @@ -183,6 +186,10 @@ if ($socid) { if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } +// Add where from hooks +$parameters = array('socid' => $user->socid); +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.tms DESC"; $sql .= $db->plimit($max, 0); @@ -269,6 +276,10 @@ if (isModEnabled('order')) { if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.rowid DESC"; $resql = $db->query($sql); @@ -358,6 +369,10 @@ if (isModEnabled('order')) { if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " ORDER BY c.rowid DESC"; $resql = $db->query($sql); diff --git a/htdocs/commande/list_det.php b/htdocs/commande/list_det.php index 3db34f69289..3302870c7f6 100644 --- a/htdocs/commande/list_det.php +++ b/htdocs/commande/list_det.php @@ -663,7 +663,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks $parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; // Add HAVING from hooks diff --git a/htdocs/contact/consumption.php b/htdocs/contact/consumption.php index a73467912a6..c01597074f3 100644 --- a/htdocs/contact/consumption.php +++ b/htdocs/contact/consumption.php @@ -365,6 +365,9 @@ if (!empty($sql_select)) { } $sql .= ")"; } + $parameters = array('type_element' => $type_element); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); $resql = $db->query($sql); $totalnboflines = $db->num_rows($resql); diff --git a/htdocs/core/boxes/box_commandes.php b/htdocs/core/boxes/box_commandes.php index ce9961e4072..70a54d0e1ad 100644 --- a/htdocs/core/boxes/box_commandes.php +++ b/htdocs/core/boxes/box_commandes.php @@ -65,7 +65,7 @@ class box_commandes extends ModeleBoxes */ public function loadBox($max = 5) { - global $user, $langs, $conf; + global $user, $langs, $conf, $hookmanager; $langs->load('orders'); $this->max = $max; @@ -108,9 +108,15 @@ class box_commandes extends ModeleBoxes if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } - if ($user->socid) { - $sql .= " AND s.rowid = ".((int) $user->socid); + // Add where from hooks + $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + if ($user->socid) { + $sql .= " AND s.rowid = " . ((int) $user->socid); + } } + $sql .= $hookmanager->resPrint; if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) { $sql .= " ORDER BY c.date_commande DESC, c.ref DESC "; } else { diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index 3820900aa16..b76e83c82f4 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -65,7 +65,7 @@ class box_propales extends ModeleBoxes */ public function loadBox($max = 5) { - global $user, $langs, $conf; + global $user, $langs, $conf, $hookmanager; $this->max = $max; @@ -93,9 +93,15 @@ class box_propales extends ModeleBoxes if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } - if ($user->socid) { - $sql .= " AND s.rowid = ".((int) $user->socid); + // Add where from hooks + $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + if ($user->socid) { + $sql .= " AND s.rowid = " . ((int) $user->socid); + } } + $sql .= $hookmanager->resPrint; if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) { $sql .= " ORDER BY p.datep DESC, p.ref DESC "; } else { diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php index e24546f6db7..fec1ff21de8 100644 --- a/htdocs/core/lib/order.lib.php +++ b/htdocs/core/lib/order.lib.php @@ -229,7 +229,7 @@ function order_admin_prepare_head() */ function getCustomerOrderPieChart($socid = 0) { - global $conf, $db, $langs, $user; + global $conf, $db, $langs, $user, $hookmanager; $result = ''; @@ -257,6 +257,10 @@ function getCustomerOrderPieChart($socid = 0) if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " GROUP BY c.fk_statut"; $resql = $db->query($sql); diff --git a/htdocs/core/lib/propal.lib.php b/htdocs/core/lib/propal.lib.php index e73d594aeac..c1425b76b02 100644 --- a/htdocs/core/lib/propal.lib.php +++ b/htdocs/core/lib/propal.lib.php @@ -212,7 +212,7 @@ function propal_admin_prepare_head() */ function getCustomerProposalPieChart($socid = 0) { - global $conf, $db, $langs, $user; + global $conf, $db, $langs, $user, $hookmanager; $result = ''; @@ -239,6 +239,10 @@ function getCustomerProposalPieChart($socid = 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } $sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")"; + // Add where from hooks + $parameters = array('socid' => $user->socid); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " GROUP BY p.fk_statut"; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index c5a977b183d..2c1a311dd2d 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -48,7 +48,7 @@ class modCommande extends DolibarrModules */ public function __construct($db) { - global $conf, $user; + global $conf, $user, $hookmanager; $this->db = $db; $this->numero = 25; @@ -298,6 +298,9 @@ class modCommande extends DolibarrModules if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); } + $parameters = array(); + $hookmanager->executeHooks('printExportWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $this->export_sql_end[$r] .= $hookmanager->resPrint; // Imports //-------- diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index a3381f2f45f..3281a789ab5 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -44,7 +44,7 @@ class modPropale extends DolibarrModules */ public function __construct($db) { - global $conf, $user; + global $conf, $user, $hookmanager; $this->db = $db; $this->numero = 20; @@ -306,6 +306,9 @@ class modPropale extends DolibarrModules if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); } + $parameters = array(); + $hookmanager->executeHooks('printExportWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $this->export_sql_end[$r] .= $hookmanager->resPrint; // Imports //-------- diff --git a/htdocs/expedition/index.php b/htdocs/expedition/index.php index 418c1906106..e491f4882f2 100644 --- a/htdocs/expedition/index.php +++ b/htdocs/expedition/index.php @@ -231,6 +231,11 @@ if ($socid > 0) { if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } + +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListWhereOpenedOrders', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; + $sql .= " ORDER BY c.rowid ASC"; $resql = $db->query($sql); diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 83af4f420f5..9c071bfcbea 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -401,6 +401,7 @@ Modelcsv_winfic=Export for Winfic - eWinfic - WinSis Compta Modelcsv_Gestinumv3=Export for Gestinum (v3) Modelcsv_Gestinumv5=Export for Gestinum (v5) Modelcsv_charlemagne=Export for Aplim Charlemagne +Modelcsv_ISTEA=Export for ISTEA ChartofaccountsId=Chart of accounts Id ExportToPdf = Export to PDF ExportToCsv = Export to CSV diff --git a/htdocs/langs/fr_FR/accountancy.lang b/htdocs/langs/fr_FR/accountancy.lang index cdcb84304bd..640e32efe2a 100644 --- a/htdocs/langs/fr_FR/accountancy.lang +++ b/htdocs/langs/fr_FR/accountancy.lang @@ -391,6 +391,7 @@ Modelcsv_winfic=Export pour Winfic - eWinfic - WinSis Compta Modelcsv_Gestinumv3=Export vers Gestinum (v3) Modelcsv_Gestinumv5=Export vers Gestinum (v5) Modelcsv_charlemagne=Export pour Aplin Charlemagne +Modelcsv_ISTEA=Export vers ISTEA ChartofaccountsId=Id plan comptable ExportToPdf = Exporter au format PDF ExportToCsv = Exporter au format CSV diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index cc393993cd6..8f6dcfa752a 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3507,7 +3507,10 @@ class Product extends CommonObject if ($socid > 0) { $sql .= " AND p.fk_soc = ".((int) $socid); } - + // Add where from hooks + $parameters = array('socid' => $socid, 'type_element' => 'propal'); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); @@ -3616,6 +3619,7 @@ class Product extends CommonObject // phpcs:enable global $user, $hookmanager, $action; + $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; $sql .= " FROM ".$this->db->prefix()."commandedet as cd"; @@ -3634,7 +3638,10 @@ class Product extends CommonObject if ($filtrestatut != '') { $sql .= " AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).")"; } - + // Add where from hooks + $parameters = array('socid' => $socid, 'type_element' => 'order'); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); @@ -3687,7 +3694,10 @@ class Product extends CommonObject $sql .= " JOIN ".$this->db->prefix()."commande as c ON el.fk_source = c.rowid"; $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id); $sql .= " AND EXISTS (SELECT cd.fk_product FROM ".$this->db->prefix()."commandedet as cd WHERE cd.fk_product = fd.fk_product AND cd.fk_commande = c.rowid)"; // We check that the product is in order lines - + // Add where from hooks + $parameters = array('socid' => $socid, 'type_element' => 'order'); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { @@ -3720,6 +3730,10 @@ class Product extends CommonObject $sql .= " AND EXISTS (SELECT cd.fk_product FROM ".$this->db->prefix()."commandedet as cd WHERE cd.fk_product = fd.fk_product AND cd.fk_commande = c.rowid)"; // We check that the product is in order lines dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); + // Add where from hooks + $parameters = array('socid' => $socid, 'type_element' => 'order'); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { @@ -4583,7 +4597,7 @@ class Product extends CommonObject public function get_nb_propal($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter = '') { // phpcs:enable - global $user; + global $user, $hookmanager; $sql = "SELECT sum(d.qty) as qty, date_format(p.datep, '%Y%m')"; if ($mode == 'bynumber') { @@ -4615,9 +4629,11 @@ class Product extends CommonObject $sql .= " AND p.fk_soc = ".((int) $socid); } $sql .= $morefilter; + $parameters = array('socid' => $user->socid); + $hookmanager->executeHooks('productGetNbPropal', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " GROUP BY date_format(p.datep,'%Y%m')"; $sql .= " ORDER BY date_format(p.datep,'%Y%m') DESC"; - return $this->_get_stats($sql, $mode, $year); } @@ -4687,7 +4703,7 @@ class Product extends CommonObject public function get_nb_order($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter = '') { // phpcs:enable - global $user; + global $user, $hookmanager; $sql = "SELECT sum(d.qty) as qty, date_format(c.date_commande, '%Y%m')"; if ($mode == 'bynumber') { @@ -4719,6 +4735,9 @@ class Product extends CommonObject $sql .= " AND c.fk_soc = ".((int) $socid); } $sql .= $morefilter; + $parameters = array('socid' => $user->socid); + $hookmanager->executeHooks('productGetNbOrder', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= " GROUP BY date_format(c.date_commande,'%Y%m')"; $sql .= " ORDER BY date_format(c.date_commande,'%Y%m') DESC"; diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php index 06168cb5237..095f5929980 100644 --- a/htdocs/product/stats/commande.php +++ b/htdocs/product/stats/commande.php @@ -189,6 +189,10 @@ if ($id > 0 || !empty($ref)) { $sql .= " AND c.fk_statut IN (".$db->sanitize($search_status).")"; } + // Add where from hooks + $parameters = array('socid' => $socid, 'type_element' => 'order'); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); //Calcul total qty and amount for global if full scan list diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index aab6b4fdf6c..b9f6d82d6fc 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -179,6 +179,10 @@ if ($id > 0 || !empty($ref)) { if ($socid) { $sql .= " AND p.fk_soc = ".((int) $socid); } + // Add where from hooks + $parameters = array('socid' => $socid, 'type_element' => 'propal'); + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); // Calcul total qty and amount for global if full scan list diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php index f91bdf4bd07..6b0f8fd6ccb 100644 --- a/htdocs/projet/class/api_tasks.class.php +++ b/htdocs/projet/class/api_tasks.class.php @@ -196,6 +196,7 @@ class Tasks extends DolibarrApi */ public function post($request_data = null) { + global $conf; if (!DolibarrApiAccess::$user->hasRight('projet', 'creer')) { throw new RestException(403, "Insufficiant rights"); } @@ -218,6 +219,49 @@ class Tasks extends DolibarrApi } $this->project->lines = $lines; }*/ + + // Auto-generate the "ref" field if it is set to "auto" + if ($this->task->ref == -1 || $this->task->ref === 'auto') { + $reldir = ''; + $defaultref = ''; + $file = ''; + $classname = ''; + $filefound = 0; + $modele = getDolGlobalString('PROJECT_TASK_ADDON', 'mod_task_simple'); + + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/project/task/".$modele.'.php', 0); + if (file_exists($file)) { + $filefound = 1; + $classname = $modele; + break; + } + } + if ($filefound && !empty($classname)) { + $result = dol_include_once($reldir . "core/modules/project/task/" . $modele . '.php'); + if ($result !== false && class_exists($classname)) { + $modTask = new $classname(); + '@phan-var-force ModeleNumRefTask $modTask'; + $defaultref = $modTask->getNextValue(null, $this->task); + } else { + dol_syslog("Failed to include module file or invalid classname: " . $reldir . "core/modules/project/task/" . $modele . '.php', LOG_ERR); + } + } else { + dol_syslog("Module file not found or classname is empty: " . $modele, LOG_ERR); + } + + if (is_numeric($defaultref) && $defaultref <= 0) { + $defaultref = ''; + } + + if (empty($defaultref)) { + $defaultref = 'TK' . dol_print_date(dol_now(), 'dayrfc'); + } + + $this->task->ref = $defaultref; + } + if ($this->task->create(DolibarrApiAccess::$user) < 0) { throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors)); } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 41b09d5e4a4..a159c334a0f 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -5164,6 +5164,7 @@ class Societe extends CommonObject */ public function getOutstandingProposals($mode = 'customer') { + global $hookmanager; $table = 'propal'; if ($mode == 'supplier') { $table = 'supplier_proposal'; @@ -5179,6 +5180,11 @@ class Societe extends CommonObject dol_syslog("getOutstandingProposals for fk_soc = ".((int) $this->id), LOG_DEBUG); + // Add where from hooks + $parameters = array('mode' => $mode, 'table' => $table); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; + $resql = $this->db->query($sql); if ($resql) { $outstandingOpened = 0; @@ -5208,6 +5214,7 @@ class Societe extends CommonObject */ public function getOutstandingOrders($mode = 'customer') { + global $hookmanager; $table = 'commande'; if ($mode == 'supplier') { $table = 'commande_fournisseur'; @@ -5222,6 +5229,10 @@ class Societe extends CommonObject } dol_syslog("getOutstandingOrders", LOG_DEBUG); + // Add where from hooks + $parameters = array('mode' => $mode, 'table' => $table); + $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook + $sql .= $hookmanager->resPrint; $resql = $this->db->query($sql); if ($resql) { $outstandingOpened = 0; diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index 5b339b9a206..d6d8168681c 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -288,7 +288,7 @@ if ($type_element == 'propal') { $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d"; $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid); $where .= " AND d.fk_propal = c.rowid"; - $where .= " AND c.entity = ".$conf->entity; + $where .= " AND c.entity IN (".getEntity('propal').")"; $dateprint = 'c.datep'; $doc_number = 'c.ref'; $thirdTypeSelect = 'customer'; @@ -301,7 +301,7 @@ if ($type_element == 'order') { $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d"; $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid); $where .= " AND d.fk_commande = c.rowid"; - $where .= " AND c.entity = ".$conf->entity; + $where .= " AND c.entity IN (".getEntity('commande').")"; $dateprint = 'c.date_commande'; $doc_number = 'c.ref'; $thirdTypeSelect = 'customer'; @@ -439,7 +439,7 @@ if (!empty($sql_select)) { $sql .= ")"; } - $parameters = array(); + $parameters = array('type_element' => $type_element); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint;