From 30ea0231259b86602122673a2ea77b99003b532c Mon Sep 17 00:00:00 2001 From: evarisk-micka Date: Fri, 1 Mar 2024 17:17:13 +0100 Subject: [PATCH] #5 [Hook] add: badge and filter between client and supplier --- class/actions_suppliercontract.class.php | 30 +++++++++++++++++++--- core/modules/modSupplierContract.class.php | 5 +++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/class/actions_suppliercontract.class.php b/class/actions_suppliercontract.class.php index afbfda6..3904d04 100644 --- a/class/actions_suppliercontract.class.php +++ b/class/actions_suppliercontract.class.php @@ -77,7 +77,7 @@ public function addMoreRecentObjects(array $parameters, &$object): int { global $conf, $user, $langs; - if (strpos($parameters['context'], 'thirdpartysupplier') !== false) { + if (preg_match('/thirdpartycomm|thirdpartysupplier/', $parameters['context'])) { if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire') && isModEnabled('saturne')) { // Load Dolibarr libraries require_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; @@ -85,9 +85,10 @@ public function addMoreRecentObjects(array $parameters, &$object): int // Load Saturne libraries require_once __DIR__ . '/../../saturne/lib/object.lib.php'; - $contracts = saturne_fetch_all_object_type('Contrat', 'DESC', 'datec', 0, 0, ['customsql' => 't.fk_soc = ' . $object->id]); + $countContracts = 0; + $supplier = strpos($parameters['context'], 'thirdpartysupplier'); + $contracts = saturne_fetch_all_object_type('Contrat', 'DESC', 'datec', 0, 0, ['customsql' => 't.fk_soc = ' . $object->id]); if (is_array($contracts) && !empty($contracts)) { - $countContracts = 0; $nbContracts = count($contracts); $maxList = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT'); @@ -103,6 +104,10 @@ public function addMoreRecentObjects(array $parameters, &$object): int $out .= ''; foreach ($contracts as $contract) { + if (($supplier > 0 && empty($contract->ref_supplier)) || ($supplier == 0 && empty($contract->ref_customer))) { + continue; + } + if ($countContracts == $maxList) { break; } else { @@ -124,6 +129,12 @@ public function addMoreRecentObjects(array $parameters, &$object): int $out .= ''; $out .= ''; $out .= $contract->getNomUrl(1); + if (!empty($contract->ref_customer)) { + $out .= '' . substr($langs->trans("Client"), 0, 1) . ''; + } + if (!empty($contract->ref_supplier)) { + $out .= '' . substr($langs->trans("Supplier"), 0, 1) . ''; + } // Preview $fileDir = $conf->contrat->multidir_output[$contract->entity] . '/' . dol_sanitizeFileName($contract->ref); $fileList = null; @@ -161,8 +172,19 @@ public function addMoreRecentObjects(array $parameters, &$object): int $out .= ''; $out .= ''; - $this->resprints = $out; + if ($supplier > 0) { + $this->resprints = $out; + return 0; + } + } + if ($countContracts == 0) { + $out = ''; } + ?> + + [], // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all' - 'hooks' => ['thirdpartysupplier'], + 'hooks' => [ + 'thirdpartysupplier', + 'thirdpartycomm' + ], // Set this to 1 if features of module are opened to external users 'moduleforexternal' => 0 ];