ok to list equipments for a specific category, next historical entries and outputs for a specific equipment.

This commit is contained in:
JBthePenguin 2021-06-12 17:17:03 +02:00
parent 20f55add52
commit 5ee30cf9ed
9 changed files with 165 additions and 56 deletions

Binary file not shown.

View File

@ -36,5 +36,5 @@ class Category
{ {
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);
} }
} }

View File

@ -70,6 +70,37 @@ class Equipment
return $entries - $outputs; return $entries - $outputs;
} }
public function AllListsAll($eqmts)
{
$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;
} else {
$eqmt->out_of_stock = 0;
}
array_push($eqmts_owned, $eqmt);
}
$no_owned = $this->CalculateNoOwned($eqmt->id);
if ($no_owned) {
$eqmt->no_owned = $no_owned;
array_push($eqmts_no_owned, $eqmt);
}
if ($stock + $no_owned == 0) {
array_push($eqmts_just_listed, $eqmt);
}
}
return array(
$eqmts_owned, $eqmts_no_owned, $eqmts_just_listed
);
}
public function AllListsAllByCategory() public function AllListsAllByCategory()
{ {
$eqmts_by_cat = $this->listAllByCategory(); $eqmts_by_cat = $this->listAllByCategory();
@ -77,30 +108,7 @@ class Equipment
$eqmts_no_owned_by_cat = array(); $eqmts_no_owned_by_cat = array();
$eqmts_just_listed_by_cat = array(); $eqmts_just_listed_by_cat = array();
foreach ($eqmts_by_cat as $cat => $eqmts) { foreach ($eqmts_by_cat as $cat => $eqmts) {
$eqmts_owned = array(); list($eqmts_owned, $eqmts_no_owned, $eqmts_just_listed) = $this->AllListsAll($eqmts);
$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;
} else {
$eqmt->out_of_stock = 0;
}
array_push($eqmts_owned, $eqmt);
}
$no_owned = $this->CalculateNoOwned($eqmt->id);
if ($no_owned) {
$eqmt->no_owned = $no_owned;
array_push($eqmts_no_owned, $eqmt);
}
if ($stock + $no_owned == 0) {
array_push($eqmts_just_listed, $eqmt);
}
}
$eqmts_owned_by_cat[$cat] = $eqmts_owned; $eqmts_owned_by_cat[$cat] = $eqmts_owned;
$eqmts_no_owned_by_cat[$cat] = $eqmts_no_owned; $eqmts_no_owned_by_cat[$cat] = $eqmts_no_owned;
$eqmts_just_listed_by_cat[$cat] = $eqmts_just_listed; $eqmts_just_listed_by_cat[$cat] = $eqmts_just_listed;

View File

@ -4,6 +4,5 @@
<li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories/index.php"}">Catégories</a></li> <li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories/index.php"}">Catégories</a></li>
<li class="{if $current == 'entrees'}current{/if}"><a href="{plugin_url file="entrees/index.php"}">Entrées</a></li> <li class="{if $current == 'entrees'}current{/if}"><a href="{plugin_url file="entrees/index.php"}">Entrées</a></li>
<li class="{if $current == 'sorties'}current{/if}"><a href="{plugin_url file="sorties/index.php"}">Sorties</a></li> <li class="{if $current == 'sorties'}current{/if}"><a href="{plugin_url file="sorties/index.php"}">Sorties</a></li>
<li class="{if $current == 'recherche'}current{/if}"><a href="{plugin_url file="recherche.php"}">Recherche</a></li>
</ul> </ul>
</nav> </nav>

View File

@ -2,4 +2,79 @@
{include file="%s_nav.tpl"|args:$plugin_tpl current="categories"} {include file="%s_nav.tpl"|args:$plugin_tpl current="categories"}
<h2 style="text-align: center;">{$cat_name}</h2>
<br>
{if $eqmts_owned}
<table class="list">
<thead>
<tr>
<th colspan="4" style="text-align: center;"><h3>Matériel dont l'association est propriétaire</h3></th>
</tr>
<tr>
<th><b>Désignation</b></th>
<th style="text-align: center;"><b>Stock</b></th>
<th style="text-align: center;"><b>Sortie</b></th>
<th style="text-align: center;"><b>Disponible</b></th>
</tr>
</thead>
<tbody>
{foreach from=$eqmts_owned item="eqmt"}
<tr>
<td>{$eqmt.designation}</td>
<td style="text-align: center;">{$eqmt.stock}</td>
<td style="text-align: center;">{$eqmt.out_of_stock}</td>
<td style="text-align: center;">{$eqmt.stock - $eqmt.out_of_stock}</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
{if $eqmts_no_owned}
<table class="list">
<thead>
<tr>
<th colspan="2" style="text-align: center;"><h3>Matériel dont l'association n'est pas propriétaire (emprunté)</h3></th>
</tr>
<tr>
<th><b>Désignation</b></th>
<th style="text-align: center;"><b>Nombre</b></th>
</tr>
</thead>
<tbody>
{foreach from=$eqmts_no_owned item="eqmt"}
<tr>
<td>{$eqmt.designation}</td>
<td style="text-align: center;">{$eqmt.no_owned}</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
{if $eqmts_just_listed}
<table class="list">
<thead>
<tr>
<th style="text-align: center;"><h3>Matériel dont l'association n'est plus en possession</h3></th>
</tr>
<tr>
<th><b>Désignation</b></th>
</tr>
</thead>
<tbody>
{foreach from=$eqmts_just_listed item="eqmt"}
<tr>
<td>{$eqmt.designation}</td>
</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
{linkbutton label="Retour" shape="export" href=$return_link}
{include file="admin/_foot.tpl"} {include file="admin/_foot.tpl"}

View File

@ -2,17 +2,22 @@
{include file="%s_nav.tpl"|args:$plugin_tpl current="index"} {include file="%s_nav.tpl"|args:$plugin_tpl current="index"}
<h2>Matériel dont l'association est propriétaire</h2> <h2 style="text-align: center;">Matériel dont l'association est propriétaire</h2>
<br>
{foreach from=$eqmts_owned_by_cat key='cat' item="eqmts"} {foreach from=$eqmts_owned_by_cat key='cat' item="eqmts"}
{if $eqmts} {if $eqmts}
<h3>{$cat}</h3>
<table class="list"> <table class="list">
<thead> <thead>
<tr>
<th colspan="5" style="text-align: center;"><h3>{$cat}</h3></th>
</tr>
<tr> <tr>
<th><b>Désignation</b></th> <th><b>Désignation</b></th>
<th><b>Stock</b></th> <th style="text-align: center;"><b>Stock</b></th>
<th><b>Sortie</b></th> <th style="text-align: center;"><b>Sortie</b></th>
<th><b>Disponible</b></th> <th style="text-align: center;"><b>Disponible</b></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -20,10 +25,10 @@
{foreach from=$eqmts item="eqmt"} {foreach from=$eqmts item="eqmt"}
<tr> <tr>
<td>{$eqmt.designation}</td> <td>{$eqmt.designation}</td>
<td>{$eqmt.stock}</td> <td style="text-align: center;">{$eqmt.stock}</td>
<td>{$eqmt.out_of_stock}</td> <td style="text-align: center;">{$eqmt.out_of_stock}</td>
<td>{$eqmt.stock - $eqmt.out_of_stock}</td> <td style="text-align: center;">{$eqmt.stock - $eqmt.out_of_stock}</td>
<td class="actions"> <td class="actions" style="text-align: center;">
{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}
</td> </td>
</tr> </tr>
@ -33,15 +38,26 @@
{/if} {/if}
{/foreach} {/foreach}
<h2>Matériel dont l'association n'est pas propriétaire (emprunté)</h2> <br>
<hr>
<br>
<h2 style="text-align: center;">Matériel dont l'association n'est pas propriétaire (emprunté)</h2>
<br>
{foreach from=$eqmts_no_owned_by_cat key='cat' item="eqmts"} {foreach from=$eqmts_no_owned_by_cat key='cat' item="eqmts"}
{if $eqmts} {if $eqmts}
<h3>{$cat}</h3>
<table class="list"> <table class="list">
<thead> <thead>
<tr>
<th colspan="5" style="text-align: center;"><h3>{$cat}</h3></th>
</tr>
<tr> <tr>
<th><b>Désignation</b></th> <th><b>Désignation</b></th>
<th><b>Nombre</b></th> <th style="text-align: center;"><b>Nombre</b></th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -49,8 +65,8 @@
{foreach from=$eqmts item="eqmt"} {foreach from=$eqmts item="eqmt"}
<tr> <tr>
<td>{$eqmt.designation}</td> <td>{$eqmt.designation}</td>
<td>{$eqmt.no_owned}</td> <td style="text-align: center;">{$eqmt.no_owned}</td>
<td class="actions"> <td class="actions" style="text-align: center;">
{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}
</td> </td>
</tr> </tr>
@ -60,12 +76,23 @@
{/if} {/if}
{/foreach} {/foreach}
<h2>Matériel dont l'association n'est plus en possession</h2> <br>
<hr>
<br>
<h2 style="text-align: center;">Matériel dont l'association n'est plus en possession</h2>
<br>
{foreach from=$eqmts_just_listed_by_cat key='cat' item="eqmts"} {foreach from=$eqmts_just_listed_by_cat key='cat' item="eqmts"}
{if $eqmts} {if $eqmts}
<h3>{$cat}</h3>
<table class="list"> <table class="list">
<thead> <thead>
<tr>
<th colspan="5" style="text-align: center;"><h3>{$cat}</h3></th>
</tr>
<tr> <tr>
<th><b>Désignation</b></th> <th><b>Désignation</b></th>
<th></th> <th></th>
@ -75,7 +102,7 @@
{foreach from=$eqmts item="eqmt"} {foreach from=$eqmts item="eqmt"}
<tr> <tr>
<td>{$eqmt.designation}</td> <td>{$eqmt.designation}</td>
<td class="actions"> <td class="actions" style="text-align: center;">
{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}
</td> </td>
</tr> </tr>

View File

@ -1,5 +0,0 @@
{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
{include file="%s_nav.tpl"|args:$plugin_tpl current="recherche"}
{include file="admin/_foot.tpl"}

View File

@ -3,6 +3,7 @@
namespace Garradin; namespace Garradin;
use Garradin\Plugin\Materiels\Category; use Garradin\Plugin\Materiels\Category;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils; use Garradin\Utils;
require_once __DIR__ . '/../_inc.php'; require_once __DIR__ . '/../_inc.php';
@ -15,6 +16,17 @@ if (!$c) {
throw new UserException("Cette catégorie n'existe pas."); throw new UserException("Cette catégorie n'existe pas.");
} }
$tpl->assign(compact('c')); $eqmts = $cat->listAllEquipments($c->id);
$eqmt = new Equipment;
list($eqmts_owned, $eqmts_no_owned, $eqmts_just_listed) = $eqmt->AllListsAll($eqmts);
$cat_name = $c->name;
$return_link = PLUGIN_URL . 'categories/index.php';
$tpl->assign(compact(
'cat_name', 'eqmts_owned', 'eqmts_no_owned', 'eqmts_just_listed', 'return_link'));
$tpl->display(PLUGIN_ROOT . '/templates/categories/materiels_par_categorie.tpl'); $tpl->display(PLUGIN_ROOT . '/templates/categories/materiels_par_categorie.tpl');

View File

@ -1,7 +0,0 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$tpl->display(PLUGIN_ROOT . '/templates/recherche.tpl');