diff --git a/materiels.tar.gz b/materiels.tar.gz
index 5f50f54..25040da 100644
Binary files a/materiels.tar.gz and b/materiels.tar.gz differ
diff --git a/src/lib/Entry.php b/src/lib/Entry.php
index eb4df77..2613520 100644
--- a/src/lib/Entry.php
+++ b/src/lib/Entry.php
@@ -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);
diff --git a/src/lib/Output.php b/src/lib/Output.php
index d7e4b57..f346e8a 100644
--- a/src/lib/Output.php
+++ b/src/lib/Output.php
@@ -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;
+ }
}
diff --git a/src/templates/common/delete_form.tpl b/src/templates/common/delete_form.tpl
index c3be6dd..c9c01d7 100644
--- a/src/templates/common/delete_form.tpl
+++ b/src/templates/common/delete_form.tpl
@@ -3,7 +3,9 @@
{csrf_field key=$csrf_key}
diff --git a/src/templates/sorties/index.tpl b/src/templates/sorties/index.tpl
index 07a1a05..e924a95 100644
--- a/src/templates/sorties/index.tpl
+++ b/src/templates/sorties/index.tpl
@@ -16,6 +16,7 @@
Nombre |
Matériel |
Remarques |
+ |
{foreach from=$outputs item="output"}
@@ -25,6 +26,9 @@
{$output.equipment_number} |
{$output.equipment} |
{$output.additional_comment} |
+
+ {linkbutton shape="delete" label="Supprimer" href="supprimer_sortie.php?id=%d"|args:$output.id}
+ |
{/foreach}
diff --git a/src/templates/sorties/supprimer_sortie.tpl b/src/templates/sorties/supprimer_sortie.tpl
new file mode 100644
index 0000000..86ab081
--- /dev/null
+++ b/src/templates/sorties/supprimer_sortie.tpl
@@ -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"}
diff --git a/src/www/admin/sorties/supprimer_sortie.php b/src/www/admin/sorties/supprimer_sortie.php
new file mode 100644
index 0000000..ed72312
--- /dev/null
+++ b/src/www/admin/sorties/supprimer_sortie.php
@@ -0,0 +1,44 @@
+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 ! ---");
+}