ok for delete output in movement
This commit is contained in:
parent
46e6fe8330
commit
0b97418682
@ -157,4 +157,15 @@ class Movement
|
|||||||
$entry->equipment_id, $entry->equipment_number, $entry->mvt_date);
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
13
src/templates/mouvements/sorties/supprimer_sortie.tpl
Normal file
13
src/templates/mouvements/sorties/supprimer_sortie.tpl
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!-- nav bar -->
|
||||||
|
{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="sorties"}
|
||||||
|
<!-- -->
|
||||||
|
<!-- delete form -->
|
||||||
|
{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=""
|
||||||
|
}
|
||||||
|
<!-- -->
|
||||||
|
<!-- footer -->
|
||||||
|
{include file="admin/_foot.tpl"}
|
||||||
|
<!-- -->
|
48
src/www/admin/mouvements/sorties/supprimer_sortie.php
Normal file
48
src/www/admin/mouvements/sorties/supprimer_sortie.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// delete a specific entry
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../_inc.php';
|
||||||
|
|
||||||
|
use Garradin\Plugin\Materiels\Equipment;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
// get the output to delete
|
||||||
|
$output_to_delete = $mvt->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 ! ---");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user