diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index 6b3253d..738a67b 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -65,6 +65,19 @@ class Equipment return $entries - $outputs; } + public function CalculateAvailable($id) + { + $entries = DB::getInstance()->firstColumn( + "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind IN ( + 'Achat', 'Don', 'Récupération', + 'Retour de location / prêt') AND equipment_id = ?;", $id); + $outputs = DB::getInstance()->firstColumn( + "SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind IN ( + 'Vente', 'Don', 'Besoin', 'Autre (perte, vol, ...)', + 'Location / Prêt') AND equipment_id = ?;", $id); + return $entries - $outputs; + } + public function GetAllListByCategory() { $eqmts_by_cat = $this->listAllByCategory(); @@ -105,4 +118,22 @@ class Equipment $eqmts_just_listed_by_cat ); } + + public function GetAvailableListByCategory() + { + $eqmts_by_cat = $this->listAllByCategory(); + $eqmts_available_by_cat = array(); + foreach ($eqmts_by_cat as $cat => $eqmts) { + $eqmts_available = array(); + foreach ($eqmts as $eqmt) { + $available = $this->CalculateAvailable($eqmt->id); + if ($available) { + $eqmt->available = $available; + array_push($eqmts_available, $eqmt); + } + } + $eqmts_available_by_cat[$cat] = $eqmts_available; + } + return $eqmts_available_by_cat; + } } diff --git a/src/lib/Output.php b/src/lib/Output.php index edccd08..de94cec 100644 --- a/src/lib/Output.php +++ b/src/lib/Output.php @@ -14,7 +14,6 @@ class Output 'Besoin', 'Autre (perte, vol, ...)', 'Location / Prêt', - 'Retour de location / prêt', ); } diff --git a/src/templates/sorties/ajouter_sortie.tpl b/src/templates/sorties/ajouter_sortie.tpl new file mode 100644 index 0000000..fbfdcaa --- /dev/null +++ b/src/templates/sorties/ajouter_sortie.tpl @@ -0,0 +1,35 @@ +{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"} + +
+
+ Ajouter une sortie d'un matériel {$legend_part} + {form_errors} +
+ {if $tpl_materiel_name != 'retour'} +
(obligatoire)
+
+ +
+ {/if} + {input type="date" name="output_date" default=$default_date label="Date de sortie" required=true } + {input type="number" name="equipment_number" label="Nombre" required=true step="1" min="1" default="1"} +
+ {include file="%ssorties/{$tpl_materiel_name}.tpl"|args:$plugin_tpl} +
+ {input type="textarea" name="additional_comment" label="Remarques" placeholder="ex: don fait à..." default=$default_comment maxlength="255" rows=4 cols=30} +
+
+

+ {csrf_field key=$csrf_key} + {button type="submit" name="save" label="Enregistrer" shape="right" class="main"} + {linkbutton label="Annuler" shape="export" href=$cancel_link} +

+
+ +{include file="admin/_foot.tpl"} diff --git a/src/templates/sorties/en_stock.tpl b/src/templates/sorties/en_stock.tpl deleted file mode 100644 index d099546..0000000 --- a/src/templates/sorties/en_stock.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"} - -en stock sortie - -{include file="admin/_foot.tpl"} diff --git a/src/templates/sorties/index.tpl b/src/templates/sorties/index.tpl index 21b944d..c7d089f 100644 --- a/src/templates/sorties/index.tpl +++ b/src/templates/sorties/index.tpl @@ -4,7 +4,7 @@
Ajouter une sortie pour du - {linkbutton shape="plus" label="Matériel en stock" href="en_stock.php"} + {linkbutton shape="plus" label="Matériel en stock disponible" href="stock_disponible.php"} {linkbutton shape="plus" label="Matériel emprunté" href="pas_proprietaire.php"}
diff --git a/src/templates/sorties/stock_disponible.tpl b/src/templates/sorties/stock_disponible.tpl new file mode 100644 index 0000000..d08f7ce --- /dev/null +++ b/src/templates/sorties/stock_disponible.tpl @@ -0,0 +1,19 @@ +
+

Matériel

+
+
(obligatoire)
+
+ +
+
+
diff --git a/src/www/admin/sorties/en_stock.php b/src/www/admin/sorties/en_stock.php deleted file mode 100644 index f4cc7a2..0000000 --- a/src/www/admin/sorties/en_stock.php +++ /dev/null @@ -1,21 +0,0 @@ -assign(compact('csrf_key')); - -$tpl->display(PLUGIN_ROOT . '/templates/sorties/en_stock.tpl'); diff --git a/src/www/admin/sorties/stock_disponible.php b/src/www/admin/sorties/stock_disponible.php new file mode 100644 index 0000000..98ae594 --- /dev/null +++ b/src/www/admin/sorties/stock_disponible.php @@ -0,0 +1,35 @@ +GetAvailableListByCategory(); + +$csrf_key = 'add_output'; + +$kinds = $output->listKinds(); +$selected_kind = $kinds[0]; + +$date = new \DateTime; +$date->setTimestamp(time()); +$default_date = $date; + +$default_comment = ""; + +$cancel_link = PLUGIN_URL . 'sorties/index.php'; +$legend_part = "en stock disponible"; +$tpl_materiel_name = "stock_disponible"; + +$tpl->assign(compact( + 'csrf_key', 'cancel_link', 'legend_part', 'tpl_materiel_name', + 'kinds', 'selected_kind', 'default_date', 'default_comment', + 'eqmts_by_cat')); + +$tpl->display(PLUGIN_ROOT . '/templates/sorties/ajouter_sortie.tpl');