Skip to content
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
14 changes: 11 additions & 3 deletions core/tpl/registrationcertificatefr_vehicle_history.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
* $catLabels (array id => ['label' => string, 'data-html' => string])
* $eventsList (array of ActionComm)
* $evtCatById (array evtId => Categorie)
* $alreadyLinkedFactureIds (array of facture ids already linked to an event)
* $alreadyLinkedPropalIds (array of propal ids already linked to an event)
* $alreadyLinkedControlIds (array of control ids already linked to an event)
*/

require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
Expand All @@ -45,6 +48,11 @@

// === Add event form ===
if (!empty($permissiontoadd)) {
// Exclude elements already linked to an existing event so the same one cannot be assigned twice
$factureFilter = !empty($alreadyLinkedFactureIds) ? ':0:(t.rowid:notin:' . implode(',', $alreadyLinkedFactureIds) . ')' : '';
$propalFilter = !empty($alreadyLinkedPropalIds) ? ':0:(t.rowid:notin:' . implode(',', $alreadyLinkedPropalIds) . ')' : '';
$controlFilter = !empty($alreadyLinkedControlIds) ? ':0:(t.rowid:notin:' . implode(',', $alreadyLinkedControlIds) . ')' : '';

$out .= load_fiche_titre($langs->transnoentities('AddVehicleEvent'), '', 'dolicar_color@dolicar');

$out .= '<form method="POST" action="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?id=' . $object->id . '">';
Expand Down Expand Up @@ -75,17 +83,17 @@

$out .= '<tr>';
$out .= '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->transnoentities('Invoices') . '</td>';
$out .= '<td>' . $form->selectForForms('Facture:compta/facture/class/facture.class.php', 'event_fk_facture', GETPOSTINT('event_fk_facture'), 1, '', '', 'minwidth300') . '</td>';
$out .= '<td>' . $form->selectForForms('Facture:compta/facture/class/facture.class.php' . $factureFilter, 'event_fk_facture', GETPOSTINT('event_fk_facture'), 1, '', '', 'minwidth300') . '</td>';
$out .= '</tr>';

$out .= '<tr>';
$out .= '<td>' . img_picto('', 'propal', 'class="pictofixedwidth"') . $langs->transnoentities('Proposals') . '</td>';
$out .= '<td>' . $form->selectForForms('Propal:comm/propal/class/propal.class.php', 'event_fk_propal', GETPOSTINT('event_fk_propal'), 1, '', '', 'minwidth300') . '</td>';
$out .= '<td>' . $form->selectForForms('Propal:comm/propal/class/propal.class.php' . $propalFilter, 'event_fk_propal', GETPOSTINT('event_fk_propal'), 1, '', '', 'minwidth300') . '</td>';
$out .= '</tr>';

$out .= '<tr>';
$out .= '<td><i class="fas fa-tasks pictofixedwidth"></i>' . $langs->transnoentities('Controls') . '</td>';
$out .= '<td>' . $form->selectForForms('Control:custom/digiquali/class/control.class.php', 'event_fk_control', GETPOSTINT('event_fk_control'), 1, '', '', 'minwidth300') . '</td>';
$out .= '<td>' . $form->selectForForms('Control:custom/digiquali/class/control.class.php' . $controlFilter, 'event_fk_control', GETPOSTINT('event_fk_control'), 1, '', '', 'minwidth300') . '</td>';
$out .= '</tr>';

$out .= '</table>';
Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/dolicar.lang
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ VehicleEventType = Type d'événement
VehicleHistory = Historique du véhicule
NoVehicleHistory = Aucun événement enregistré
VehicleEventAdded = Événement véhicule ajouté avec succès
VehicleEventElementAlreadyLinked = Cet élément (%s) est déjà associé à un autre événement de ce véhicule
LinkedDocuments = Documents liés
Invoices = Factures
Proposals = Devis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@
}
}

// Collect elements already linked to an existing event to prevent assigning the same one twice
$alreadyLinkedFactureIds = [];
$alreadyLinkedPropalIds = [];
$alreadyLinkedControlIds = [];
foreach ($eventsList as $linkedEvt) {
$linkedEvt->fetchObjectLinked(null, null, null, null, 'OR', 1, 'sourcetype', 0);
foreach (($linkedEvt->linkedObjectsIds['facture'] ?? []) as $facId) {
$alreadyLinkedFactureIds[(int) $facId] = (int) $facId;
}
foreach (($linkedEvt->linkedObjectsIds['propal'] ?? []) as $propalId) {
$alreadyLinkedPropalIds[(int) $propalId] = (int) $propalId;
}
foreach (($linkedEvt->linkedObjectsIds['control'] ?? []) as $controlId) {
$alreadyLinkedControlIds[(int) $controlId] = (int) $controlId;
}
}

/*
* Actions
*/
Expand All @@ -185,6 +202,20 @@
$error++;
}

// Prevent assigning an element already linked to another event of this vehicle
if (!$error && $fkFacture > 0 && isset($alreadyLinkedFactureIds[$fkFacture])) {
setEventMessages($langs->transnoentities('VehicleEventElementAlreadyLinked', $langs->transnoentities('Invoices')), null, 'errors');
$error++;
}
if (!$error && $fkPropal > 0 && isset($alreadyLinkedPropalIds[$fkPropal])) {
setEventMessages($langs->transnoentities('VehicleEventElementAlreadyLinked', $langs->transnoentities('Proposals')), null, 'errors');
$error++;
}
if (!$error && $fkControl > 0 && isset($alreadyLinkedControlIds[$fkControl])) {
setEventMessages($langs->transnoentities('VehicleEventElementAlreadyLinked', $langs->transnoentities('Controls')), null, 'errors');
$error++;
}

if (!$error) {
$actionComm = new ActionComm($db);
$actionComm->code = 'AC_OTH';
Expand Down