add tpl and php for return of rent in entries

This commit is contained in:
JBthePenguin 2021-06-09 15:23:16 +02:00
parent 54858e2d18
commit 08e2af1f1d
12 changed files with 100 additions and 30 deletions

Binary file not shown.

View File

@ -13,7 +13,6 @@ class Entry
'Don', 'Don',
'Récupération', 'Récupération',
'Location / Prêt', 'Location / Prêt',
'Retour de location / prêt',
); );
} }

View File

@ -4,9 +4,10 @@
<form method="post" action="{$self_url}"> <form method="post" action="{$self_url}">
<fieldset> <fieldset>
<legend>Ajouter une entrée d'un matériel {$legend_part} répertorié</legend> <legend>Ajouter une entrée d'un matériel {$legend_part}</legend>
{form_errors} {form_errors}
<dl> <dl>
{if $tpl_materiel_name != 'retour'}
<dt><label for="f_kind">Type</label> <b>(obligatoire)</b></dt> <dt><label for="f_kind">Type</label> <b>(obligatoire)</b></dt>
<dd> <dd>
<select name="kind" id="f_kind"> <select name="kind" id="f_kind">
@ -15,6 +16,7 @@
{/foreach} {/foreach}
</select> </select>
</dd> </dd>
{/if}
{input type="date" name="entry_date" default=$default_date label="Date d'entrée" required=true } {input type="date" name="entry_date" default=$default_date label="Date d'entrée" required=true }
{input type="number" name="equipment_number" label="Nombre" required=true step="1" min="1" default=$default_number} {input type="number" name="equipment_number" label="Nombre" required=true step="1" min="1" default=$default_number}
</dl> </dl>

View File

@ -4,8 +4,9 @@
<fieldset> <fieldset>
<legend>Ajouter une entrée pour du </legend> <legend>Ajouter une entrée pour du </legend>
{linkbutton shape="plus" label="Matériel pas encore répertorié" href="non_repertorie.php"} {linkbutton shape="plus" label="Matériel répertorié" href="repertorie.php"}
{linkbutton shape="plus" label="Matériel déjà répertorié" href="deja_repertorie.php"} {linkbutton shape="plus" label="Matériel non répertorié" href="non_repertorie.php"}
{linkbutton shape="plus" label="Matériel en retour de location / prêt" href="retour.php"}
</fieldset> </fieldset>
{if $entries} {if $entries}
@ -23,7 +24,7 @@
<td>{$entry.entry_date}</td> <td>{$entry.entry_date}</td>
<td>{$entry.kind}</td> <td>{$entry.kind}</td>
<td>{$entry.equipment_number}</td> <td>{$entry.equipment_number}</td>
<td>{$entry.equipment.designation}</td> <td>{$entry.equipment}</td>
<td>{$entry.additional_comment}</td> <td>{$entry.additional_comment}</td>
</tr> </tr>
{/foreach} {/foreach}

View File

@ -0,0 +1,19 @@
<fieldset>
<legend><h3>Matériel</h3></legend>
<dl>
<dt><label for="f_eqmt"></label> <b>(obligatoire)</b></dt>
<dd>
<select name="equipment_id" id="f_eqmt">
{foreach from=$eqmts_by_cat key='cat' item="eqmts"}
{if $eqmts}
<optgroup label="-- {$cat} --">
{foreach from=$eqmts item="eqmt"}
<option value="{$eqmt.id}">{$eqmt.designation}</option>
{/foreach}
</optgroup>
{/if}
{/foreach}
</select>
</dd>
</dl>
</fieldset>

View File

@ -23,7 +23,7 @@
<td>{$output.output_date}</td> <td>{$output.output_date}</td>
<td>{$output.kind}</td> <td>{$output.kind}</td>
<td>{$output.equipment_number}</td> <td>{$output.equipment_number}</td>
<td>{$output.equipment.designation}</td> <td>{$output.equipment}</td>
<td>{$output.additional_comment}</td> <td>{$output.additional_comment}</td>
</tr> </tr>
{/foreach} {/foreach}

View File

@ -13,7 +13,8 @@ $entry = new Entry;
$entries = $entry->listAll(); $entries = $entry->listAll();
foreach ($entries as $key => $value) { foreach ($entries as $key => $value) {
$entries[$key]->equipment = $eqmt->get($value->equipment_id); $entry_eqmt = $eqmt->get($value->equipment_id);
$entries[$key]->equipment = $entry_eqmt->designation;
} }
$tpl->assign(compact('entries')); $tpl->assign(compact('entries'));

View File

@ -10,6 +10,7 @@ use Garradin\Utils;
require_once __DIR__ . '/../_inc.php'; require_once __DIR__ . '/../_inc.php';
$entry = new Entry; $entry = new Entry;
$kinds = $entry->listKinds(); $kinds = $entry->listKinds();
$selected_kind = $kinds[0]; $selected_kind = $kinds[0];
@ -66,7 +67,7 @@ if (f('save'))
} }
$cancel_link = PLUGIN_URL . 'entrees/index.php'; $cancel_link = PLUGIN_URL . 'entrees/index.php';
$legend_part = "pas encore"; $legend_part = "non répertorié";
$tpl_materiel_name = "non_repertorie"; $tpl_materiel_name = "non_repertorie";

View File

@ -0,0 +1,51 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Entry;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$entry = new Entry;
$csrf_key = 'add_entry';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
$entry->add([
'kind' => f('kind'),
'equipment_number' => (int) f('equipment_number'),
'equipment_id' => f('equipment_id'),
'entry_date' => f('entry_date'),
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
}
$eqmt = new Equipment;
$eqmts_by_cat = $eqmt->listAllByCategory();
$kinds = $entry->listKinds();
$selected_kind = $kinds[0];
$date = new \DateTime;
$date->setTimestamp(time());
$default_date = $date;
$default_number = "1";
$default_comment = "";
$cancel_link = PLUGIN_URL . 'entrees/index.php';
$legend_part = "répertorié";
$tpl_materiel_name = "repertorie";
$tpl->assign(compact(
'kinds', 'eqmts_by_cat', 'selected_kind', 'default_date',
'default_number', 'default_comment', 'cancel_link',
'legend_part', 'tpl_materiel_name', 'csrf_key'
));
$tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl');

View File

@ -8,17 +8,15 @@ use Garradin\Utils;
require_once __DIR__ . '/../_inc.php'; require_once __DIR__ . '/../_inc.php';
$entry = new Entry;
$eqmt = new Equipment;
$csrf_key = 'add_entry'; $csrf_key = 'add_entry';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors()) if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{ {
if ($form->check($csrf_key) && !$form->hasErrors()) if ($form->check($csrf_key) && !$form->hasErrors())
{ {
$entry = new Entry;
$entry->add([ $entry->add([
'kind' => f('kind'), 'kind' => 'Retour de location / prêt',
'equipment_number' => (int) f('equipment_number'), 'equipment_number' => (int) f('equipment_number'),
'equipment_id' => f('equipment_id'), 'equipment_id' => f('equipment_id'),
'entry_date' => f('entry_date'), 'entry_date' => f('entry_date'),
@ -28,11 +26,9 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
} }
} }
$eqmt = new Equipment;
$eqmts_by_cat = $eqmt->listAllByCategory(); $eqmts_by_cat = $eqmt->listAllByCategory();
$kinds = $entry->listKinds();
$selected_kind = $kinds[0];
$date = new \DateTime; $date = new \DateTime;
$date->setTimestamp(time()); $date->setTimestamp(time());
$default_date = $date; $default_date = $date;
@ -41,14 +37,13 @@ $default_number = "1";
$default_comment = ""; $default_comment = "";
$cancel_link = PLUGIN_URL . 'entrees/index.php'; $cancel_link = PLUGIN_URL . 'entrees/index.php';
$legend_part = "déjà"; $legend_part = "en retour de location / prêt";
$tpl_materiel_name = "deja_repertorie"; $tpl_materiel_name = "retour";
$tpl->assign(compact( $tpl->assign(compact(
'kinds', 'eqmts_by_cat', 'selected_kind', 'default_date', 'eqmts_by_cat', 'default_date', 'default_number',
'default_number', 'default_comment', 'cancel_link', 'default_comment', 'cancel_link', 'legend_part',
'legend_part', 'tpl_materiel_name', 'csrf_key' 'tpl_materiel_name', 'csrf_key'
)); ));
$tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl'); $tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl');

View File

@ -13,7 +13,8 @@ $output = new Output;
$outputs = $output->listAll(); $outputs = $output->listAll();
foreach ($outputs as $key => $value) { foreach ($outputs as $key => $value) {
$outputs[$key]->equipment = $eqmt->get($value->equipment_id); $output_eqmt = $eqmt->get($value->equipment_id);
$outputs[$key]->equipment = $output_eqmt->designation;
} }
$tpl->assign(compact('outputs')); $tpl->assign(compact('outputs'));