add comments in some Equipment function
This commit is contained in:
parent
4bb7e7d3b9
commit
5c85f04581
|
@ -7,32 +7,38 @@ use Garradin\DB;
|
||||||
class Category
|
class Category
|
||||||
{
|
{
|
||||||
public function add($data = [])
|
public function add($data = [])
|
||||||
|
// add new category
|
||||||
{
|
{
|
||||||
DB::getInstance()->insert('plugin_materiels_category', $data);
|
DB::getInstance()->insert('plugin_materiels_category', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id, $data = [])
|
public function edit($id, $data = [])
|
||||||
|
// edit a specific category
|
||||||
{
|
{
|
||||||
$db = DB::getInstance();
|
$db = DB::getInstance();
|
||||||
$db->update('plugin_materiels_category', $data, $db->where('id', $id));
|
$db->update('plugin_materiels_category', $data, $db->where('id', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
|
// delete a specific category
|
||||||
{
|
{
|
||||||
DB::getInstance()->delete('plugin_materiels_category', 'id = ' . $id);
|
DB::getInstance()->delete('plugin_materiels_category', 'id = ' . $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($id)
|
public function get($id)
|
||||||
|
// get and return a specific category
|
||||||
{
|
{
|
||||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_category WHERE id = ?;', $id);
|
return DB::getInstance()->first('SELECT * FROM plugin_materiels_category WHERE id = ?;', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listAll()
|
public function listAll()
|
||||||
|
// return a list of all categories ordered by name
|
||||||
{
|
{
|
||||||
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)
|
public function listAllEquipments($id)
|
||||||
|
// return a list of all equipments for a specific category ordered by equipments's designation
|
||||||
{
|
{
|
||||||
return DB::getInstance()->get(
|
return DB::getInstance()->get(
|
||||||
'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $id);
|
'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $id);
|
||||||
|
|
|
@ -41,7 +41,8 @@ class Equipment
|
||||||
return $eqmts_by_cat;
|
return $eqmts_by_cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CalculateStock($id)
|
public function CalculateOwned($id)
|
||||||
|
// return number of equipments owned
|
||||||
{
|
{
|
||||||
$entries = DB::getInstance()->firstColumn(
|
$entries = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind IN (
|
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind IN (
|
||||||
|
@ -52,7 +53,8 @@ class Equipment
|
||||||
return $entries - $outputs;
|
return $entries - $outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CalculateOutOfStock($id)
|
public function CalculateOwnedOut($id)
|
||||||
|
// return number of equipments owned out
|
||||||
{
|
{
|
||||||
$entries = DB::getInstance()->firstColumn(
|
$entries = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Retour de location / prêt' AND equipment_id = ?;", $id);
|
"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)
|
public function CalculateNoOwned($id)
|
||||||
|
// return number of equipments no owned
|
||||||
{
|
{
|
||||||
$entries = DB::getInstance()->firstColumn(
|
$entries = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Location / Prêt' AND equipment_id = ?;", $id);
|
"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)
|
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_owned = array();
|
||||||
$eqmts_no_owned = array();
|
$eqmts_no_owned = array();
|
||||||
$eqmts_just_listed = array();
|
$eqmts_just_listed = array();
|
||||||
foreach ($eqmts as $eqmt) {
|
foreach ($eqmts as $eqmt) {
|
||||||
$stock = $this->CalculateStock($eqmt->id);
|
$owned = $this->CalculateOwned($eqmt->id);
|
||||||
if ($stock) {
|
if ($owned) {
|
||||||
$eqmt->stock = $stock;
|
// add equipment to list of equiments owned with his number and number of out
|
||||||
$out_of_stock = $this->CalculateOutOfStock($eqmt->id);
|
$eqmt->owned = $owned;
|
||||||
if ($out_of_stock) {
|
$owned_out = $this->CalculateOwnedOut($eqmt->id);
|
||||||
$eqmt->out_of_stock = $out_of_stock;
|
if ($owned_out) {
|
||||||
|
$eqmt->owned_out = $owned_out;
|
||||||
} else {
|
} else {
|
||||||
$eqmt->out_of_stock = 0;
|
$eqmt->owned_out = 0;
|
||||||
}
|
}
|
||||||
array_push($eqmts_owned, $eqmt);
|
array_push($eqmts_owned, $eqmt);
|
||||||
}
|
}
|
||||||
$no_owned = $this->CalculateNoOwned($eqmt->id);
|
$no_owned = $this->CalculateNoOwned($eqmt->id);
|
||||||
if ($no_owned) {
|
if ($no_owned) {
|
||||||
|
// add equipment to list of equiments no owned with his number
|
||||||
$eqmt->no_owned = $no_owned;
|
$eqmt->no_owned = $no_owned;
|
||||||
array_push($eqmts_no_owned, $eqmt);
|
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);
|
array_push($eqmts_just_listed, $eqmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +180,7 @@ class Equipment
|
||||||
foreach ($eqmts_by_cat as $cat => $eqmts) {
|
foreach ($eqmts_by_cat as $cat => $eqmts) {
|
||||||
$eqmts_released = array();
|
$eqmts_released = array();
|
||||||
foreach ($eqmts as $eqmt) {
|
foreach ($eqmts as $eqmt) {
|
||||||
$released = $this->CalculateOutOfStock($eqmt->id);
|
$released = $this->CalculateOwnedOut($eqmt->id);
|
||||||
if ($released) {
|
if ($released) {
|
||||||
$eqmt->released = $released;
|
$eqmt->released = $released;
|
||||||
array_push($eqmts_released, $eqmt);
|
array_push($eqmts_released, $eqmt);
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
{foreach from=$eqmts_owned item="eqmt"}
|
{foreach from=$eqmts_owned item="eqmt"}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$eqmt.designation}</td>
|
<td>{$eqmt.designation}</td>
|
||||||
<td style="text-align: center;">{$eqmt.stock}</td>
|
<td style="text-align: center;">{$eqmt.owned}</td>
|
||||||
<td style="text-align: center;">{$eqmt.out_of_stock}</td>
|
<td style="text-align: center;">{$eqmt.owned_out}</td>
|
||||||
<td style="text-align: center;">{$eqmt.stock - $eqmt.out_of_stock}</td>
|
<td style="text-align: center;">{$eqmt.owned - $eqmt.owned_out}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
{foreach from=$eqmts item="eqmt"}
|
{foreach from=$eqmts item="eqmt"}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$eqmt.designation}</td>
|
<td>{$eqmt.designation}</td>
|
||||||
<td style="text-align: center;">{$eqmt.stock}</td>
|
<td style="text-align: center;">{$eqmt.owned}</td>
|
||||||
<td style="text-align: center;">{$eqmt.out_of_stock}</td>
|
<td style="text-align: center;">{$eqmt.owned_out}</td>
|
||||||
<td style="text-align: center;">{$eqmt.stock - $eqmt.out_of_stock}</td>
|
<td style="text-align: center;">{$eqmt.owned - $eqmt.owned_out}</td>
|
||||||
<td class="actions" style="text-align: center;">
|
<td class="actions" style="text-align: center;">
|
||||||
{linkbutton shape="edit" label="Historique des entrées / sorties" href="historique.php?id=%d"|args:$eqmt.id}
|
{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}
|
{linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}
|
||||||
|
|
Loading…
Reference in New Issue