From 5c85f0458132c431a400618c1130bfa4728f16a0 Mon Sep 17 00:00:00 2001 From: JBthePenguin Date: Tue, 31 Aug 2021 19:15:55 +0200 Subject: [PATCH] add comments in some Equipment function --- src/lib/Category.php | 6 ++++ src/lib/Equipment.php | 30 ++++++++++++------- .../categories/materiels_par_categorie.tpl | 6 ++-- src/templates/index.tpl | 6 ++-- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/lib/Category.php b/src/lib/Category.php index 46ad77c..37d4d85 100644 --- a/src/lib/Category.php +++ b/src/lib/Category.php @@ -7,32 +7,38 @@ use Garradin\DB; class Category { public function add($data = []) + // add new category { DB::getInstance()->insert('plugin_materiels_category', $data); } public function edit($id, $data = []) + // edit a specific category { $db = DB::getInstance(); $db->update('plugin_materiels_category', $data, $db->where('id', $id)); } public function delete($id) + // delete a specific category { DB::getInstance()->delete('plugin_materiels_category', 'id = ' . $id); } public function get($id) + // get and return a specific category { return DB::getInstance()->first('SELECT * FROM plugin_materiels_category WHERE id = ?;', $id); } public function listAll() + // return a list of all categories ordered by name { return DB::getInstance()->get('SELECT * FROM plugin_materiels_category ORDER BY name;'); } public function listAllEquipments($id) + // return a list of all equipments for a specific category ordered by equipments's designation { return DB::getInstance()->get( 'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $id); diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index f0e8368..f113477 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -41,7 +41,8 @@ class Equipment return $eqmts_by_cat; } - public function CalculateStock($id) + public function CalculateOwned($id) + // return number of equipments owned { $entries = DB::getInstance()->firstColumn( "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind IN ( @@ -52,7 +53,8 @@ class Equipment return $entries - $outputs; } - public function CalculateOutOfStock($id) + public function CalculateOwnedOut($id) + // return number of equipments owned out { $entries = DB::getInstance()->firstColumn( "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Retour de location / prêt' AND equipment_id = ?;", $id); @@ -62,6 +64,7 @@ class Equipment } public function CalculateNoOwned($id) + // return number of equipments no owned { $entries = DB::getInstance()->firstColumn( "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Location / Prêt' AND equipment_id = ?;", $id); @@ -71,28 +74,33 @@ class Equipment } public function AllListsAll($eqmts) + // construct and return 3 lists with a specific list of equipments: + // equipments owned, equipments no owned and equipments just listed { $eqmts_owned = array(); $eqmts_no_owned = array(); $eqmts_just_listed = array(); foreach ($eqmts as $eqmt) { - $stock = $this->CalculateStock($eqmt->id); - if ($stock) { - $eqmt->stock = $stock; - $out_of_stock = $this->CalculateOutOfStock($eqmt->id); - if ($out_of_stock) { - $eqmt->out_of_stock = $out_of_stock; + $owned = $this->CalculateOwned($eqmt->id); + if ($owned) { + // add equipment to list of equiments owned with his number and number of out + $eqmt->owned = $owned; + $owned_out = $this->CalculateOwnedOut($eqmt->id); + if ($owned_out) { + $eqmt->owned_out = $owned_out; } else { - $eqmt->out_of_stock = 0; + $eqmt->owned_out = 0; } array_push($eqmts_owned, $eqmt); } $no_owned = $this->CalculateNoOwned($eqmt->id); if ($no_owned) { + // add equipment to list of equiments no owned with his number $eqmt->no_owned = $no_owned; array_push($eqmts_no_owned, $eqmt); } - if ($stock + $no_owned == 0) { + if ($owned + $no_owned == 0) { + // add equipment to list of equiments just listed array_push($eqmts_just_listed, $eqmt); } } @@ -172,7 +180,7 @@ class Equipment foreach ($eqmts_by_cat as $cat => $eqmts) { $eqmts_released = array(); foreach ($eqmts as $eqmt) { - $released = $this->CalculateOutOfStock($eqmt->id); + $released = $this->CalculateOwnedOut($eqmt->id); if ($released) { $eqmt->released = $released; array_push($eqmts_released, $eqmt); diff --git a/src/templates/categories/materiels_par_categorie.tpl b/src/templates/categories/materiels_par_categorie.tpl index 2051f97..e2eae6c 100644 --- a/src/templates/categories/materiels_par_categorie.tpl +++ b/src/templates/categories/materiels_par_categorie.tpl @@ -23,9 +23,9 @@ {foreach from=$eqmts_owned item="eqmt"} {$eqmt.designation} - {$eqmt.stock} - {$eqmt.out_of_stock} - {$eqmt.stock - $eqmt.out_of_stock} + {$eqmt.owned} + {$eqmt.owned_out} + {$eqmt.owned - $eqmt.owned_out} {/foreach} diff --git a/src/templates/index.tpl b/src/templates/index.tpl index b2234da..9ed0d5d 100644 --- a/src/templates/index.tpl +++ b/src/templates/index.tpl @@ -23,9 +23,9 @@ {foreach from=$eqmts item="eqmt"} {$eqmt.designation} - {$eqmt.stock} - {$eqmt.out_of_stock} - {$eqmt.stock - $eqmt.out_of_stock} + {$eqmt.owned} + {$eqmt.owned_out} + {$eqmt.owned - $eqmt.owned_out} {linkbutton shape="edit" label="Historique des entrées / sorties" href="historique.php?id=%d"|args:$eqmt.id} {linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}