Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 [Hook] add: badge and filter between client and supplier #8

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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