ok to delete output, next list equipments for a specific category.

This commit is contained in:
JBthePenguin 2021-06-12 11:30:20 +02:00
parent cb2c3f4565
commit 20f55add52
7 changed files with 81 additions and 10 deletions

Binary file not shown.

View File

@ -23,12 +23,6 @@ class Entry
DB::getInstance()->insert('plugin_materiels_entry', $data); DB::getInstance()->insert('plugin_materiels_entry', $data);
} }
public function edit($id, $data = [])
{
$db = DB::getInstance();
$db->update('plugin_materiels_entry', $data, $db->where('id', $id));
}
public function get($id) public function get($id)
{ {
return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id); return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id);

View File

@ -4,6 +4,7 @@ namespace Garradin\Plugin\Materiels;
use Garradin\DB; use Garradin\DB;
use Garradin\Plugin\Materiels\Equipment; use Garradin\Plugin\Materiels\Equipment;
use Garradin\Plugin\Materiels\Entry;
class Output class Output
{ {
@ -23,10 +24,14 @@ class Output
DB::getInstance()->insert('plugin_materiels_output', $data); DB::getInstance()->insert('plugin_materiels_output', $data);
} }
public function edit($id, $data = []) public function get($id)
{ {
$db = DB::getInstance(); return DB::getInstance()->first('SELECT * FROM plugin_materiels_output WHERE id = ?;', $id);
$db->update('plugin_materiels_output', $data, $db->where('id', $id)); }
public function delete($id)
{
DB::getInstance()->delete('plugin_materiels_output', 'id = ' . $id);
} }
public function listAll() public function listAll()
@ -75,4 +80,15 @@ class Output
} }
return true; return true;
} }
public function PossibilityDeleteOutput($output)
{
$entry = new Entry;
if ($output->kind == 'Location / Prêt')
{
return $entry->PossibilityRentEqmtEntry(
$output->equipment_id, $output->equipment_number, $output->output_date);
}
return true;
}
} }

View File

@ -3,7 +3,9 @@
<fieldset> <fieldset>
<legend>{$legend}</legend> <legend>{$legend}</legend>
<h3 class="warning">{$warning}</h3> <h3 class="warning">{$warning}</h3>
{if $alert != ""}
<p class="block alert">{$alert}</p> <p class="block alert">{$alert}</p>
{/if}
</fieldset> </fieldset>
<p class="submit"> <p class="submit">
{csrf_field key=$csrf_key} {csrf_field key=$csrf_key}

View File

@ -16,6 +16,7 @@
<th><b>Nombre</b></th> <th><b>Nombre</b></th>
<th><b>Matériel</b></th> <th><b>Matériel</b></th>
<th><b>Remarques</b></th> <th><b>Remarques</b></th>
<th></th>
</thead> </thead>
<tbody> <tbody>
{foreach from=$outputs item="output"} {foreach from=$outputs item="output"}
@ -25,6 +26,9 @@
<td>{$output.equipment_number}</td> <td>{$output.equipment_number}</td>
<td>{$output.equipment}</td> <td>{$output.equipment}</td>
<td>{$output.additional_comment}</td> <td>{$output.additional_comment}</td>
<td class="actions">
{linkbutton shape="delete" label="Supprimer" href="supprimer_sortie.php?id=%d"|args:$output.id}
</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>

View File

@ -0,0 +1,11 @@
{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
{include file="%s_nav.tpl"|args:$plugin_tpl current="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"}

View File

@ -0,0 +1,44 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Output;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$output = new Output;
$o_to_delete = $output->get((int) qg('id'));
if (!$o_to_delete)
{
throw new UserException("Cette sortie n'existe pas.");
}
$csrf_key = 'delete_output_' . $o_to_delete->id;
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
{
$output->delete($o_to_delete->id);
Utils::redirect(PLUGIN_URL . 'sorties/index.php');
}
$eqmt = new Equipment;
$equipment = $eqmt->get($o_to_delete->equipment_id);
if ($output->PossibilityDeleteOutput($o_to_delete))
{
$cancel_link = PLUGIN_URL . 'sorties/index.php';
$output_string = (string) $o_to_delete->equipment_number . " " . $equipment->designation . " à la date du " . date_create_from_format(
"Y-m-d", $o_to_delete->output_date)->format("d/m/y");
$tpl->assign(compact('output_string', 'csrf_key', 'cancel_link'));
$tpl->display(PLUGIN_ROOT . '/templates/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 « " . $equipment->designation . " ». --- plus de 'retour de location / prêt' en entrée que de 'location / prêt' en sortie ! ---");
}