begin to calculate stock, next calculate outputed
This commit is contained in:
parent
c4f8b4fb87
commit
71775c0f67
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
20
src/lib/Output.php
Normal file
20
src/lib/Output.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Garradin\Plugin\Materiels;
|
||||
|
||||
use Garradin\DB;
|
||||
|
||||
class Output
|
||||
{
|
||||
public function listKinds()
|
||||
{
|
||||
return array(
|
||||
'Vente',
|
||||
'Don',
|
||||
'Besoin',
|
||||
'Autre (perte, vol, ...)',
|
||||
'Location / Prêt',
|
||||
'Retour de location / prêt',
|
||||
);
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_category (
|
||||
CREATE TABLE IF NOT EXISTS plugin_materiels_equipment (
|
||||
id integer NOT NULL PRIMARY KEY autoincrement,
|
||||
category_id integer NOT NULL,
|
||||
stock_number integer NOT NULL,
|
||||
designation varchar(255) NOT NULL,
|
||||
CONSTRAINT u_equipment_designation UNIQUE ( designation ),
|
||||
FOREIGN KEY ( category_id ) REFERENCES plugin_materiels_category( id ) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
|
@ -2,25 +2,39 @@
|
||||
|
||||
{include file="%s_nav.tpl"|args:$plugin_tpl current="index"}
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<th><b>Nombre en stock</b></th>
|
||||
<th><b>Désignation</b></th>
|
||||
<th><b>Categorie</b></th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$eqmts item="eqmt"}
|
||||
<tr>
|
||||
<td>{$eqmt.stock_number}</td>
|
||||
<td>{$eqmt.designation}</td>
|
||||
<td>{$eqmt.category.name}</td>
|
||||
<td class="actions">
|
||||
{linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
<h2>Matériel dont l'association est propriétaire</h2>
|
||||
{foreach from=$eqmts_owned_by_cat key='cat' item="eqmts"}
|
||||
{if $eqmts}
|
||||
<h3>{$cat}</h3>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><b>Désignation</b></th>
|
||||
<th><b>Stock</b></th>
|
||||
<th><b>Sorti en location / prêt</b></th>
|
||||
<th><b>Disponible</b></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$eqmts item="eqmt"}
|
||||
<tr>
|
||||
<td>{$eqmt.designation}</td>
|
||||
<td>{$eqmt.stock}</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td class="actions">
|
||||
{linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
<h2>Matériel dont l'association n'est pas propriétaire</h2>
|
||||
|
||||
<h2>Matériel déjà répertorié qui n'est plus en possession de l'association</h2>
|
||||
|
||||
{include file="admin/_foot.tpl"}
|
||||
|
@ -24,10 +24,6 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||
'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');
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ if (f('save'))
|
||||
$eqmt = new Equipment;
|
||||
$eqmt_id = $eqmt->add([
|
||||
'category_id' => (int) f('category_id'),
|
||||
'stock_number' => (int) f('equipment_number'),
|
||||
'designation' => ucfirst(strtolower(f('designation'))),
|
||||
]);
|
||||
$entry->add([
|
||||
|
@ -8,19 +8,13 @@ if ($plugin->needUpgrade())
|
||||
}
|
||||
|
||||
use Garradin\Plugin\Materiels\Equipment;
|
||||
use Garradin\Plugin\Materiels\Category;
|
||||
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$eqmt = new Equipment;
|
||||
$cat = new Category;
|
||||
|
||||
$eqmts = $eqmt->listAll();
|
||||
$eqmts_owned_by_cat = $eqmt->listAllOwnedByCategory();
|
||||
|
||||
foreach ($eqmts as $key => $value) {
|
||||
$eqmts[$key]->category = $cat->get($value->category_id);
|
||||
}
|
||||
|
||||
$tpl->assign(compact('eqmts'));
|
||||
$tpl->assign(compact('eqmts_owned_by_cat'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');
|
||||
|
Loading…
Reference in New Issue
Block a user