Skip to content

Commit

Permalink
Eoxia#5 [Hook] add: badge and filter between client and supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Mar 1, 2024
1 parent e742863 commit 30ea023
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
30 changes: 26 additions & 4 deletions class/actions_suppliercontract.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ 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';

// 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');

Expand All @@ -103,6 +104,10 @@ public function addMoreRecentObjects(array $parameters, &$object): int
$out .= '</tr>';

foreach ($contracts as $contract) {
if (($supplier > 0 && empty($contract->ref_supplier)) || ($supplier == 0 && empty($contract->ref_customer))) {
continue;
}

if ($countContracts == $maxList) {
break;
} else {
Expand All @@ -124,6 +129,12 @@ public function addMoreRecentObjects(array $parameters, &$object): int
$out .= '<tr class="oddeven">';
$out .= '<td class="nowraponall">';
$out .= $contract->getNomUrl(1);
if (!empty($contract->ref_customer)) {
$out .= '<span class="customer-back" title="'. $langs->trans("Client") . '">' . substr($langs->trans("Client"), 0, 1) . '</span>';
}
if (!empty($contract->ref_supplier)) {
$out .= '<span class="vendor-back" title="' . $langs->trans("Supplier") . '">' . substr($langs->trans("Supplier"), 0, 1) . '</span>';
}
// Preview
$fileDir = $conf->contrat->multidir_output[$contract->entity] . '/' . dol_sanitizeFileName($contract->ref);
$fileList = null;
Expand Down Expand Up @@ -161,8 +172,19 @@ public function addMoreRecentObjects(array $parameters, &$object): int
$out .= '</table>';
$out .= '</div>';

$this->resprints = $out;
if ($supplier > 0) {
$this->resprints = $out;
return 0;
}
}
if ($countContracts == 0) {
$out = '';
}
?>
<script>
jQuery('.fa-suitcase.infobox-contrat').closest('.div-table-responsive-no-min').replaceWith(<?php echo json_encode($out); ?>);
</script>
<?php
}
}

Expand Down
5 changes: 4 additions & 1 deletion core/modules/modSupplierContract.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public function __construct($db)
// Set this to relative path of js file if module must load a js on all pages
'js' => [],
// 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
];
Expand Down

0 comments on commit 30ea023

Please sign in to comment.