From 00b6aee6fd9376ea5369c0049bf732f9a154ea93 Mon Sep 17 00:00:00 2001 From: JBthePenguin Date: Fri, 11 Jun 2021 13:09:43 +0200 Subject: [PATCH] ok for output of borrowed equipment template, next validate form in php file --- src/lib/Equipment.php | 40 ++++++++++++++++------ src/templates/index.tpl | 2 +- src/templates/sorties/ajouter_sortie.tpl | 2 +- src/templates/sorties/emprunte.tpl | 17 +++++++++ src/templates/sorties/index.tpl | 2 +- src/templates/sorties/pas_proprietaire.tpl | 7 ---- src/www/admin/sorties/emprunte.php | 35 +++++++++++++++++++ src/www/admin/sorties/pas_proprietaire.php | 21 ------------ 8 files changed, 85 insertions(+), 41 deletions(-) create mode 100644 src/templates/sorties/emprunte.tpl delete mode 100644 src/templates/sorties/pas_proprietaire.tpl create mode 100644 src/www/admin/sorties/emprunte.php delete mode 100644 src/www/admin/sorties/pas_proprietaire.php diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index fd23201..eafd9e1 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -153,13 +153,42 @@ class Equipment } public function listAllReleasedRentByCategory() + { + $eqmts_by_cat = $this->listAllByCategory(); + $eqmts_released_by_cat = array(); + foreach ($eqmts_by_cat as $cat => $eqmts) { + $eqmts_released = array(); + foreach ($eqmts as $eqmt) { + $released = $this->CalculateOutOfStock($eqmt->id); + if ($released) { + $eqmt->released = $released; + array_push($eqmts_released, $eqmt); + } + } + if ($eqmts_released) { + $eqmts_released_by_cat[$cat] = $eqmts_released; + } + } + return $eqmts_released_by_cat; + } + + public function CalculateOutOfStockByDate($id, $date) + { + $entries = DB::getInstance()->firstColumn( + "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND entry_date <= '{$date}';"); + $outputs = DB::getInstance()->firstColumn( + "SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind = 'Location / Prêt' AND equipment_id = '{$id}' AND output_date <= '{$date}';"); + return $outputs - $entries; + } + + public function ListAllBorrowedByCategory() { $eqmts_by_cat = $this->listAllByCategory(); $eqmts_borrowed_by_cat = array(); foreach ($eqmts_by_cat as $cat => $eqmts) { $eqmts_borrowed = array(); foreach ($eqmts as $eqmt) { - $borrowed = $this->CalculateOutOfStock($eqmt->id); + $borrowed = $this->CalculateNoOwned($eqmt->id); if ($borrowed) { $eqmt->borrowed = $borrowed; array_push($eqmts_borrowed, $eqmt); @@ -171,13 +200,4 @@ class Equipment } return $eqmts_borrowed_by_cat; } - - public function CalculateOutOfStockByDate($id, $date) - { - $entries = DB::getInstance()->firstColumn( - "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Retour de location / prêt' AND equipment_id = '{$id}' AND entry_date <= '{$date}';"); - $outputs = DB::getInstance()->firstColumn( - "SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind = 'Location / Prêt' AND equipment_id = '{$id}' AND output_date <= '{$date}';"); - return $outputs - $entries; - } } diff --git a/src/templates/index.tpl b/src/templates/index.tpl index e90de43..a4690fe 100644 --- a/src/templates/index.tpl +++ b/src/templates/index.tpl @@ -11,7 +11,7 @@ Désignation Stock - Sorti en location / prêt + Sortie Disponible diff --git a/src/templates/sorties/ajouter_sortie.tpl b/src/templates/sorties/ajouter_sortie.tpl index fbfdcaa..a1cd178 100644 --- a/src/templates/sorties/ajouter_sortie.tpl +++ b/src/templates/sorties/ajouter_sortie.tpl @@ -7,7 +7,7 @@ Ajouter une sortie d'un matériel {$legend_part} {form_errors}
- {if $tpl_materiel_name != 'retour'} + {if $tpl_materiel_name != 'emprunte'}
(obligatoire)
+ {foreach from=$eqmts_by_cat key='cat' item="eqmts"} + + {foreach from=$eqmts item="eqmt"} + + {/foreach} + + {/foreach} + +
+
+ diff --git a/src/templates/sorties/index.tpl b/src/templates/sorties/index.tpl index cecde2c..07a1a05 100644 --- a/src/templates/sorties/index.tpl +++ b/src/templates/sorties/index.tpl @@ -5,7 +5,7 @@
Ajouter une sortie pour du {linkbutton shape="plus" label="Matériel en stock disponible" href="stock_disponible.php"} - {linkbutton shape="plus" label="Matériel emprunté" href="pas_proprietaire.php"} + {linkbutton shape="plus" label="Matériel emprunté" href="emprunte.php"}
{if $outputs} diff --git a/src/templates/sorties/pas_proprietaire.tpl b/src/templates/sorties/pas_proprietaire.tpl deleted file mode 100644 index 4c30ce2..0000000 --- a/src/templates/sorties/pas_proprietaire.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{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"} - -pas propriétaire sortie - -{include file="admin/_foot.tpl"} diff --git a/src/www/admin/sorties/emprunte.php b/src/www/admin/sorties/emprunte.php new file mode 100644 index 0000000..cdc3522 --- /dev/null +++ b/src/www/admin/sorties/emprunte.php @@ -0,0 +1,35 @@ +setTimestamp(time()); +$default_date = $date; + +$default_comment = ""; + +$csrf_key = 'add_output'; + +$eqmts_by_cat = $eqmt->ListAllBorrowedByCategory(); + +$cancel_link = PLUGIN_URL . 'sorties/index.php'; +$legend_part = "emprunté"; +$tpl_materiel_name = "emprunte"; + +$tpl->assign(compact( + 'csrf_key', 'cancel_link', 'legend_part', 'tpl_materiel_name', + 'selected_eqmt', 'default_date', 'default_comment', + 'eqmts_by_cat')); + +$tpl->display(PLUGIN_ROOT . '/templates/sorties/ajouter_sortie.tpl'); diff --git a/src/www/admin/sorties/pas_proprietaire.php b/src/www/admin/sorties/pas_proprietaire.php deleted file mode 100644 index 7b32f79..0000000 --- a/src/www/admin/sorties/pas_proprietaire.php +++ /dev/null @@ -1,21 +0,0 @@ -assign(compact('csrf_key')); - -$tpl->display(PLUGIN_ROOT . '/templates/sorties/pas_proprietaire.tpl');