diff --git a/src/lib/Category.php b/src/lib/Category.php
index ca69d87..84562f1 100644
--- a/src/lib/Category.php
+++ b/src/lib/Category.php
@@ -6,11 +6,6 @@ use Garradin\DB;
class Category
{
- protected $columns_order = array(
- 'id',
- 'name',
- );
-
public function add($data = [])
{
DB::getInstance()->insert('plugin_materiels_category', $data);
@@ -37,4 +32,10 @@ class Category
{
return DB::getInstance()->get('SELECT * FROM plugin_materiels_category ORDER BY name;');
}
+
+ public function listAllEquipments($id)
+ {
+ return DB::getInstance()->get(
+ 'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $id);
+ }
}
diff --git a/src/lib/Entry.php b/src/lib/Entry.php
index 9ea865f..21e6a86 100644
--- a/src/lib/Entry.php
+++ b/src/lib/Entry.php
@@ -6,25 +6,14 @@ use Garradin\DB;
class Entry
{
- protected $columns_order = array(
- 'id',
- 'kind',
- 'equipment_number',
- 'equipment_id',
- 'entry_date',
- 'additional_comment',
- );
-
public function listKinds()
{
return array(
'Achat',
'Don',
'Récupération',
- 'Location',
- 'Retour de location',
- 'Prêt',
- 'Retour de prêt',
+ 'Location / Prêt',
+ 'Retour de location / prêt',
);
}
diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php
index 91f9320..7073614 100644
--- a/src/lib/Equipment.php
+++ b/src/lib/Equipment.php
@@ -7,13 +7,6 @@ use Garradin\Plugin\Materiels\Category;
class Equipment
{
- protected $columns_order = array(
- 'id',
- 'category_id',
- 'stock_number',
- 'designation',
- );
-
public function add($data = [])
{
$db = DB::getInstance();
@@ -32,20 +25,43 @@ class Equipment
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
}
- public function listAll()
- {
- return DB::getInstance()->get('SELECT * FROM plugin_materiels_equipment ORDER BY designation;');
- }
-
public function listAllByCategory()
{
- $cat = new Category;
- $cats = $cat->listAll();
+ $category = new Category;
+ $cats = $category->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);
+ $eqmts_by_cat[$cat->name] = $category->listAllEquipments($cat->id);
}
return $eqmts_by_cat;
}
+
+ public function CalculateStock($id)
+ {
+ $entries = DB::getInstance()->firstColumn(
+ "SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind IN (
+ 'Achat', 'Don', 'Récupération') 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, ...)') AND equipment_id = ?;", $id);
+ return $entries - $outputs;
+ }
+
+ public function listAllOwnedByCategory()
+ {
+ $eqmts_by_cat = $this->listAllByCategory();
+ $eqmts_owned_by_cat = array();
+ foreach ($eqmts_by_cat as $cat => $eqmts) {
+ $eqmts_owned = array();
+ foreach ($eqmts as $eqmt) {
+ $stock = $this->CalculateStock($eqmt->id);
+ if ($stock) {
+ $eqmt->stock = $this->CalculateStock($eqmt->id);
+ array_push($eqmts_owned, $eqmt);
+ }
+ }
+ $eqmts_owned_by_cat[$cat] = $eqmts_owned;
+ }
+ return $eqmts_owned_by_cat;
+ }
}
diff --git a/src/lib/Output.php b/src/lib/Output.php
new file mode 100644
index 0000000..fa81984
--- /dev/null
+++ b/src/lib/Output.php
@@ -0,0 +1,20 @@
+
-
- Nombre en stock
- Désignation
- Categorie
-
-
-
Désignation | +Stock | +Sorti en location / prêt | +Disponible | ++ |
---|---|---|---|---|
{$eqmt.designation} | +{$eqmt.stock} | +0 | +0 | ++ {linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id} + | +