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
|
class Category
|
||||||
{
|
{
|
||||||
protected $columns_order = array(
|
|
||||||
'id',
|
|
||||||
'name',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function add($data = [])
|
public function add($data = [])
|
||||||
{
|
{
|
||||||
DB::getInstance()->insert('plugin_materiels_category', $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;');
|
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
|
class Entry
|
||||||
{
|
{
|
||||||
protected $columns_order = array(
|
|
||||||
'id',
|
|
||||||
'kind',
|
|
||||||
'equipment_number',
|
|
||||||
'equipment_id',
|
|
||||||
'entry_date',
|
|
||||||
'additional_comment',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function listKinds()
|
public function listKinds()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'Achat',
|
'Achat',
|
||||||
'Don',
|
'Don',
|
||||||
'Récupération',
|
'Récupération',
|
||||||
'Location',
|
'Location / Prêt',
|
||||||
'Retour de location',
|
'Retour de location / prêt',
|
||||||
'Prêt',
|
|
||||||
'Retour de prêt',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,6 @@ use Garradin\Plugin\Materiels\Category;
|
||||||
|
|
||||||
class Equipment
|
class Equipment
|
||||||
{
|
{
|
||||||
protected $columns_order = array(
|
|
||||||
'id',
|
|
||||||
'category_id',
|
|
||||||
'stock_number',
|
|
||||||
'designation',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function add($data = [])
|
public function add($data = [])
|
||||||
{
|
{
|
||||||
$db = DB::getInstance();
|
$db = DB::getInstance();
|
||||||
|
@ -32,20 +25,43 @@ class Equipment
|
||||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
|
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()
|
public function listAllByCategory()
|
||||||
{
|
{
|
||||||
$cat = new Category;
|
$category = new Category;
|
||||||
$cats = $cat->listAll();
|
$cats = $category->listAll();
|
||||||
$eqmts_by_cat = array();
|
$eqmts_by_cat = array();
|
||||||
foreach ($cats as $cat) {
|
foreach ($cats as $cat) {
|
||||||
$eqmts_by_cat[$cat->name] = DB::getInstance()->get(
|
$eqmts_by_cat[$cat->name] = $category->listAllEquipments($cat->id);
|
||||||
'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $cat->id);
|
|
||||||
}
|
}
|
||||||
return $eqmts_by_cat;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 (
|
CREATE TABLE IF NOT EXISTS plugin_materiels_equipment (
|
||||||
id integer NOT NULL PRIMARY KEY autoincrement,
|
id integer NOT NULL PRIMARY KEY autoincrement,
|
||||||
category_id integer NOT NULL,
|
category_id integer NOT NULL,
|
||||||
stock_number integer NOT NULL,
|
|
||||||
designation varchar(255) NOT NULL,
|
designation varchar(255) NOT NULL,
|
||||||
CONSTRAINT u_equipment_designation UNIQUE ( designation ),
|
CONSTRAINT u_equipment_designation UNIQUE ( designation ),
|
||||||
FOREIGN KEY ( category_id ) REFERENCES plugin_materiels_category( id ) ON DELETE RESTRICT ON UPDATE CASCADE
|
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"}
|
{include file="%s_nav.tpl"|args:$plugin_tpl current="index"}
|
||||||
|
|
||||||
<table class="list">
|
<h2>Matériel dont l'association est propriétaire</h2>
|
||||||
<thead>
|
{foreach from=$eqmts_owned_by_cat key='cat' item="eqmts"}
|
||||||
<th><b>Nombre en stock</b></th>
|
{if $eqmts}
|
||||||
<th><b>Désignation</b></th>
|
<h3>{$cat}</h3>
|
||||||
<th><b>Categorie</b></th>
|
<table class="list">
|
||||||
<th></th>
|
<thead>
|
||||||
</thead>
|
<tr>
|
||||||
<tbody>
|
<th><b>Désignation</b></th>
|
||||||
{foreach from=$eqmts item="eqmt"}
|
<th><b>Stock</b></th>
|
||||||
<tr>
|
<th><b>Sorti en location / prêt</b></th>
|
||||||
<td>{$eqmt.stock_number}</td>
|
<th><b>Disponible</b></th>
|
||||||
<td>{$eqmt.designation}</td>
|
<th></th>
|
||||||
<td>{$eqmt.category.name}</td>
|
</tr>
|
||||||
<td class="actions">
|
</thead>
|
||||||
{linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}
|
<tbody>
|
||||||
</td>
|
{foreach from=$eqmts item="eqmt"}
|
||||||
</tr>
|
<tr>
|
||||||
{/foreach}
|
<td>{$eqmt.designation}</td>
|
||||||
</tbody>
|
<td>{$eqmt.stock}</td>
|
||||||
</table>
|
<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"}
|
{include file="admin/_foot.tpl"}
|
||||||
|
|
|
@ -24,10 +24,6 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
'entry_date' => f('entry_date'),
|
'entry_date' => f('entry_date'),
|
||||||
'additional_comment' => f('additional_comment'),
|
'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');
|
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ if (f('save'))
|
||||||
$eqmt = new Equipment;
|
$eqmt = new Equipment;
|
||||||
$eqmt_id = $eqmt->add([
|
$eqmt_id = $eqmt->add([
|
||||||
'category_id' => (int) f('category_id'),
|
'category_id' => (int) f('category_id'),
|
||||||
'stock_number' => (int) f('equipment_number'),
|
|
||||||
'designation' => ucfirst(strtolower(f('designation'))),
|
'designation' => ucfirst(strtolower(f('designation'))),
|
||||||
]);
|
]);
|
||||||
$entry->add([
|
$entry->add([
|
||||||
|
|
|
@ -8,19 +8,13 @@ if ($plugin->needUpgrade())
|
||||||
}
|
}
|
||||||
|
|
||||||
use Garradin\Plugin\Materiels\Equipment;
|
use Garradin\Plugin\Materiels\Equipment;
|
||||||
use Garradin\Plugin\Materiels\Category;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/_inc.php';
|
require_once __DIR__ . '/_inc.php';
|
||||||
|
|
||||||
$eqmt = new Equipment;
|
$eqmt = new Equipment;
|
||||||
$cat = new Category;
|
|
||||||
|
|
||||||
$eqmts = $eqmt->listAll();
|
$eqmts_owned_by_cat = $eqmt->listAllOwnedByCategory();
|
||||||
|
|
||||||
foreach ($eqmts as $key => $value) {
|
$tpl->assign(compact('eqmts_owned_by_cat'));
|
||||||
$eqmts[$key]->category = $cat->get($value->category_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tpl->assign(compact('eqmts'));
|
|
||||||
|
|
||||||
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');
|
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');
|
||||||
|
|
Loading…
Reference in New Issue