diff --git a/src/lib/Movement.php b/src/lib/Movement.php index cc9cd6e..64755c2 100644 --- a/src/lib/Movement.php +++ b/src/lib/Movement.php @@ -157,4 +157,15 @@ class Movement $entry->equipment_id, $entry->equipment_number, $entry->mvt_date); } } + + public function PossibilityDeleteOutput($output) + // return true if it's possible to delete this entry, else return false + { + if ($output->kind == 'Location / Prêt') + { + return $this->PossibilityRentEqmtEntry( + $output->equipment_id, $output->equipment_number, $output->mvt_date); + } + return true; + } } diff --git a/src/templates/mouvements/sorties/supprimer_sortie.tpl b/src/templates/mouvements/sorties/supprimer_sortie.tpl new file mode 100644 index 0000000..8173333 --- /dev/null +++ b/src/templates/mouvements/sorties/supprimer_sortie.tpl @@ -0,0 +1,13 @@ + +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="sorties"} + + +{include file="%scommon/delete_form.tpl"|args:$plugin_tpl + legend="Supprimer cette sortie de matériels ?" + warning="Êtes-vous sûr de vouloir supprimer la sortie de « %s » ?"|args:$output_string + alert="" +} + + +{include file="admin/_foot.tpl"} + diff --git a/src/www/admin/mouvements/sorties/supprimer_sortie.php b/src/www/admin/mouvements/sorties/supprimer_sortie.php new file mode 100644 index 0000000..8d6eda3 --- /dev/null +++ b/src/www/admin/mouvements/sorties/supprimer_sortie.php @@ -0,0 +1,48 @@ +get((int) qg('id')); +if (!$output_to_delete) +{ + throw new UserException("Cette sortie n'existe pas."); +} + +// check if delete form is submitted +$csrf_key = 'delete_output_' . $output_to_delete->id; + +if (f('delete') && $form->check($csrf_key) && !$form->hasErrors()) +{ + // delete the movement required + $mvt->delete($output_to_delete->id); + Utils::redirect(PLUGIN_URL . 'mouvements/sorties/index.php'); +} + +$eqmt = new Equipment; +$corresponding_eqmt = $eqmt->get($output_to_delete->equipment_id); + +// check if it's possible to delete this output +if ($mvt->PossibilityDeleteOutput($output_to_delete)) +{ + // it's possible + $cancel_link = PLUGIN_URL . 'mouvements/sorties/index.php'; + // construct string to send to template + $output_string = (string) $output_to_delete->equipment_number . " " . $corresponding_eqmt->designation . " à la date du " . date_create_from_format( + "Y-m-d", $output_to_delete->mvt_date)->format("d/m/y"); + + $tpl->assign(compact('output_string', 'csrf_key', 'cancel_link')); + + $tpl->display(PLUGIN_ROOT . '/templates/mouvements/sorties/supprimer_sortie.tpl'); + +} else { + throw new UserException( + "Cette sortie ne peut pas être supprimée car ça rendrait impossible l'historique des entrées et sorties de « " . $corresponding_eqmt->designation . " ». --- plus de 'retour de location / prêt' en entrée que de 'location / prêt' en sortie ! ---"); +}