begin to historic for an equipment

This commit is contained in:
JBthePenguin 2021-09-02 19:35:54 +02:00
parent 1e9c8d8553
commit 8f3caadde1
5 changed files with 73 additions and 19 deletions

View File

@ -34,7 +34,7 @@
| *| mvt_date| date | |
| | additional_comment| varchar(255) | |
| Indexes |
| 🔑 primary key | pk_plugin_materiels_entry | |
| 🔑 primary key | pk_plugin_materiels_movement | |
| Foreign Keys |
| | Fk_plugin_materiels_movement | ( equipment_id ) ref plugin_materiels_equipment (id) | |

View File

@ -117,12 +117,18 @@ class Equipment
}
public function AllListsAllByCategory()
// construct and return 3 lists with all equipments:
// equipments owned, equipments no owned and equipments just listed
// ordered by category
{
// get list of all equipments ordered by category
$eqmts_by_cat = $this->listAllByCategory();
// construct the 3 lists
$eqmts_owned_by_cat = array();
$eqmts_no_owned_by_cat = array();
$eqmts_just_listed_by_cat = array();
foreach ($eqmts_by_cat as $cat => $eqmts) {
// for each category construct the 3 lists with all of his equipments
list($eqmts_owned, $eqmts_no_owned, $eqmts_just_listed) = $this->AllListsAll($eqmts);
$eqmts_owned_by_cat[$cat] = $eqmts_owned;
$eqmts_no_owned_by_cat[$cat] = $eqmts_no_owned;

View File

@ -168,4 +168,12 @@ class Movement
}
return true;
}
public function AllEqmtMovements($eqmt_id)
// return list of all movements for a specific equipments
// ordered by date and side
{
return DB::getInstance()->get(
"SELECT * FROM plugin_materiels_movement WHERE equipment_id = '{$eqmt_id}' ORDER BY mvt_date DESC, side DESC;");
}
}

View File

@ -1,9 +1,47 @@
{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
<!-- nav bar-->
{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="index"}
<!-- -->
<!-- -->
<h2 style="text-align: center;">Historique des entrées / sorties</h2>
{include file="%s_nav.tpl"|args:$plugin_tpl current="index"}
{foreach from=$all_dates item='date'}
<p>{$date}</p>
{/foreach}
<br>
<!-- table of movements -->
{if $mvts}
<table class="list">
<thead>
<tr>
<th colspan="5" style="text-align: center;">
<h3>{$eqmt_requested.designation} - {$eqmt_requested.category} -</h3>
</th>
</tr>
<tr>
<th><b>Date</b></th>
<th><b>Sens</b></th>
<th><b>Type</b></th>
<th><b>Nombre</b></th>
<th><b>Remarques</b></th>
</tr>
</thead>
<tbody>
{foreach from=$mvts item="mvt"}
<tr>
<td>{$mvt.mvt_date|date_format:'%d/%m/%y'}</td>
{if $mvt.side}
<td>Sortie</td>
{else}
<td>Entrée</td>
{/if}
<td>{$mvt.kind}</td>
<td>{$mvt.equipment_number}</td>
<td>{$mvt.additional_comment}</td>
</tr>
{/foreach}
</tbody>
</table>
{/if}
<!-- -->
{linkbutton label="Retour" shape="export" href=$return_link}
<!-- footer -->
{include file="admin/_foot.tpl"}
<!-- -->

View File

@ -1,25 +1,27 @@
<?php
// historic of movements (entry and output) for a specific Equipment
namespace Garradin;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Plugin\Materiels\Entry;
use Garradin\Plugin\Materiels\Output;
use Garradin\Plugin\Materiels\Category;
use Garradin\Plugin\Materiels\Movement;
require_once __DIR__ . '/_inc.php';
$eqmt = new Equipment;
$entry = new Entry;
$output = new Output;
$cat = new Category;
$mvt = new Movement;
$eq = $eqmt->get((int) qg('id'));
// get equipment requested, his category's name and all of his movements
$eqmt_requested = $eqmt->get((int) qg('id'));
$eqmt_cat = $cat->get($eqmt_requested->category_id);
$eqmt_requested->category = $eqmt_cat->name;
$mvts = $mvt->AllEqmtMovements($eqmt_requested->id);
$entry_dates = $entry->AllDatesByEquipment($eq->id);
$output_dates = $output->AllDatesByEquipment($eq->id);
$all_dates = array_unique(array_merge(
$entry_dates, $output_dates), SORT_REGULAR);
$return_link = PLUGIN_URL . 'index.php';
sort($all_dates);
$tpl->assign(compact('all_dates'));
// send all to template
$tpl->assign(compact('eqmt_requested', 'mvts', 'return_link'));
$tpl->display(PLUGIN_ROOT . '/templates/historique.tpl');