diff --git a/src/lib/Entry.php b/src/lib/Entry.php
index 8cd3942..9ea865f 100644
--- a/src/lib/Entry.php
+++ b/src/lib/Entry.php
@@ -21,6 +21,10 @@ class Entry
'Achat',
'Don',
'Récupération',
+ 'Location',
+ 'Retour de location',
+ 'Prêt',
+ 'Retour de prêt',
);
}
diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php
index 565a94b..91f9320 100644
--- a/src/lib/Equipment.php
+++ b/src/lib/Equipment.php
@@ -3,6 +3,7 @@
namespace Garradin\Plugin\Materiels;
use Garradin\DB;
+use Garradin\Plugin\Materiels\Category;
class Equipment
{
@@ -35,4 +36,16 @@ class Equipment
{
return DB::getInstance()->get('SELECT * FROM plugin_materiels_equipment ORDER BY designation;');
}
+
+ public function listAllByCategory()
+ {
+ $cat = new Category;
+ $cats = $cat->listAll();
+ $eqmts_by_cat = array();
+ foreach ($cats as $cat) {
+ $eqmts_by_cat[$cat->name] = DB::getInstance()->get(
+ 'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $cat->id);
+ }
+ return $eqmts_by_cat;
+ }
}
diff --git a/src/templates/entrees/ajouter_entree.tpl b/src/templates/entrees/ajouter_entree.tpl
new file mode 100644
index 0000000..4cc9400
--- /dev/null
+++ b/src/templates/entrees/ajouter_entree.tpl
@@ -0,0 +1,33 @@
+{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="entrees"}
+
+
+
+{include file="admin/_foot.tpl"}
diff --git a/src/templates/entrees/deja_repertorie.tpl b/src/templates/entrees/deja_repertorie.tpl
index a9f7c70..64bf151 100644
--- a/src/templates/entrees/deja_repertorie.tpl
+++ b/src/templates/entrees/deja_repertorie.tpl
@@ -1,7 +1,17 @@
-{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="entrees"}
-
-déjà repertorie
-
-{include file="admin/_foot.tpl"}
+
diff --git a/src/templates/entrees/index.tpl b/src/templates/entrees/index.tpl
index 9b2854d..8f85de4 100644
--- a/src/templates/entrees/index.tpl
+++ b/src/templates/entrees/index.tpl
@@ -14,6 +14,7 @@
Type |
Nombre |
Matériel |
+ Remarques |
{foreach from=$entries item="entry"}
@@ -22,6 +23,7 @@
{$entry.kind} |
{$entry.equipment_number} |
{$entry.equipment.designation} |
+ {$entry.additional_comment} |
{/foreach}
diff --git a/src/templates/entrees/non_repertorie.tpl b/src/templates/entrees/non_repertorie.tpl
index e741bbd..51a6579 100644
--- a/src/templates/entrees/non_repertorie.tpl
+++ b/src/templates/entrees/non_repertorie.tpl
@@ -1,43 +1,14 @@
-{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="entrees"}
-
-
-
-{include file="admin/_foot.tpl"}
+
diff --git a/src/www/admin/entrees/deja_repertorie.php b/src/www/admin/entrees/deja_repertorie.php
index dea103d..7ea6867 100644
--- a/src/www/admin/entrees/deja_repertorie.php
+++ b/src/www/admin/entrees/deja_repertorie.php
@@ -2,6 +2,57 @@
namespace Garradin;
+use Garradin\Plugin\Materiels\Entry;
+use Garradin\Plugin\Materiels\Equipment;
+use Garradin\Utils;
+
require_once __DIR__ . '/../_inc.php';
-$tpl->display(PLUGIN_ROOT . '/templates/entrees/deja_repertorie.tpl');
+$entry = new Entry;
+$eqmt = new Equipment;
+
+$csrf_key = 'add_entry';
+
+if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
+{
+ if ($form->check($csrf_key) && !$form->hasErrors())
+ {
+ $entry->add([
+ 'kind' => f('kind'),
+ 'equipment_number' => (int) f('equipment_number'),
+ 'equipment_id' => f('equipment_id'),
+ 'entry_date' => f('entry_date'),
+ 'additional_comment' => f('additional_comment'),
+ ]);
+ $eq = $eqmt->get((int) f('equipment_id'));
+ $eqmt->edit($eq->id, [
+ 'stock_number' => (int) $eq->stock_number + (int) f('equipment_number'),
+ ]);
+ Utils::redirect(PLUGIN_URL . 'entrees/index.php');
+ }
+}
+
+$eqmts_by_cat = $eqmt->listAllByCategory();
+
+$kinds = $entry->listKinds();
+$selected_kind = $kinds[0];
+
+$date = new \DateTime;
+$date->setTimestamp(time());
+$default_date = $date;
+
+$default_number = "1";
+$default_comment = "";
+
+$cancel_link = PLUGIN_URL . 'entrees/index.php';
+$legend_part = "déjà";
+$tpl_materiel_name = "deja_repertorie";
+
+
+$tpl->assign(compact(
+ 'kinds', 'eqmts_by_cat', 'selected_kind', 'default_date',
+ 'default_number', 'default_comment', 'cancel_link',
+ 'legend_part', 'tpl_materiel_name', 'csrf_key'
+));
+
+$tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl');
diff --git a/src/www/admin/entrees/non_repertorie.php b/src/www/admin/entrees/non_repertorie.php
index eb4c043..3c9ecc0 100644
--- a/src/www/admin/entrees/non_repertorie.php
+++ b/src/www/admin/entrees/non_repertorie.php
@@ -18,6 +18,7 @@ $date->setTimestamp(time());
$default_date = $date;
$default_number = "1";
+$default_comment = "";
$cat = new Category;
$cats = $cat->listAll();
@@ -31,6 +32,7 @@ if (f('save'))
$default_date = f('entry_date');
$default_number = f('equipment_number');
$selected_cat = f('category_id');
+ $default_comment = f('additional_comment');
if ($form->check($csrf_key) && !$form->hasErrors())
{
@@ -47,6 +49,7 @@ if (f('save'))
'equipment_number' => (int) f('equipment_number'),
'equipment_id' => $eqmt_id,
'entry_date' => f('entry_date'),
+ 'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
}
@@ -64,7 +67,14 @@ if (f('save'))
}
$cancel_link = PLUGIN_URL . 'entrees/index.php';
+$legend_part = "pas encore";
+$tpl_materiel_name = "non_repertorie";
-$tpl->assign(compact('kinds', 'cats', 'selected_kind', 'default_date', 'default_number', 'selected_cat', 'cancel_link', 'csrf_key'));
-$tpl->display(PLUGIN_ROOT . '/templates/entrees/non_repertorie.tpl');
+$tpl->assign(compact(
+ 'kinds', 'cats', 'selected_kind', 'default_date',
+ 'default_number', 'default_comment', 'selected_cat',
+ 'cancel_link', 'legend_part', 'tpl_materiel_name', 'csrf_key'
+));
+
+$tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl');