ok to delete output, next list equipments for a specific category.
This commit is contained in:
parent
cb2c3f4565
commit
20f55add52
BIN
materiels.tar.gz
BIN
materiels.tar.gz
Binary file not shown.
@ -23,12 +23,6 @@ class Entry
|
||||
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)
|
||||
{
|
||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id);
|
||||
|
@ -4,6 +4,7 @@ namespace Garradin\Plugin\Materiels;
|
||||
|
||||
use Garradin\DB;
|
||||
use Garradin\Plugin\Materiels\Equipment;
|
||||
use Garradin\Plugin\Materiels\Entry;
|
||||
|
||||
class Output
|
||||
{
|
||||
@ -23,10 +24,14 @@ class Output
|
||||
DB::getInstance()->insert('plugin_materiels_output', $data);
|
||||
}
|
||||
|
||||
public function edit($id, $data = [])
|
||||
public function get($id)
|
||||
{
|
||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_output WHERE id = ?;', $id);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
$db->update('plugin_materiels_output', $data, $db->where('id', $id));
|
||||
DB::getInstance()->delete('plugin_materiels_output', 'id = ' . $id);
|
||||
}
|
||||
|
||||
public function listAll()
|
||||
@ -75,4 +80,15 @@ class Output
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
<fieldset>
|
||||
<legend>{$legend}</legend>
|
||||
<h3 class="warning">{$warning}</h3>
|
||||
<p class="block alert">{$alert}</p>
|
||||
{if $alert != ""}
|
||||
<p class="block alert">{$alert}</p>
|
||||
{/if}
|
||||
</fieldset>
|
||||
<p class="submit">
|
||||
{csrf_field key=$csrf_key}
|
||||
|
@ -16,6 +16,7 @@
|
||||
<th><b>Nombre</b></th>
|
||||
<th><b>Matériel</b></th>
|
||||
<th><b>Remarques</b></th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$outputs item="output"}
|
||||
@ -25,6 +26,9 @@
|
||||
<td>{$output.equipment_number}</td>
|
||||
<td>{$output.equipment}</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>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
|
11
src/templates/sorties/supprimer_sortie.tpl
Normal file
11
src/templates/sorties/supprimer_sortie.tpl
Normal 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"}
|
44
src/www/admin/sorties/supprimer_sortie.php
Normal file
44
src/www/admin/sorties/supprimer_sortie.php
Normal 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 ! ---");
|
||||
}
|
Loading…
Reference in New Issue
Block a user