OK to add already listed material

This commit is contained in:
JBthePenguin 2021-06-06 18:41:59 +02:00
parent e2849cfcf7
commit c4f8b4fb87
8 changed files with 147 additions and 53 deletions

View File

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

View File

@ -3,6 +3,7 @@
namespace Garradin\Plugin\Materiels;
use Garradin\DB;
use Garradin\Plugin\Materiels\Category;
class Equipment
{
@ -35,4 +36,16 @@ class Equipment
{
return DB::getInstance()->get('SELECT * FROM plugin_materiels_equipment ORDER BY designation;');
}
public function listAllByCategory()
{
$cat = new Category;
$cats = $cat->listAll();
$eqmts_by_cat = array();
foreach ($cats as $cat) {
$eqmts_by_cat[$cat->name] = DB::getInstance()->get(
'SELECT * FROM plugin_materiels_equipment WHERE category_id = ? ORDER BY designation;', $cat->id);
}
return $eqmts_by_cat;
}
}

View File

@ -0,0 +1,33 @@
{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="entrees"}
<form method="post" action="{$self_url}">
<fieldset>
<legend>Ajouter une entrée d'un matériel {$legend_part} répertorié</legend>
{form_errors}
<dl>
<dt><label for="f_kind">Type</label> <b>(obligatoire)</b></dt>
<dd>
<select name="kind" id="f_kind">
{foreach from=$kinds item="kind"}
<option value="{$kind}"{if $selected_kind == $kind} selected="selected"{/if}>{$kind}</option>
{/foreach}
</select>
</dd>
{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}
</dl>
{include file="%sentrees/{$tpl_materiel_name}.tpl"|args:$plugin_tpl}
<dl>
{input type="textarea" name="additional_comment" label="Remarques" placeholder="ex: don reçu de la part de..." default=$default_comment maxlength="255" rows=4 cols=30}
</dl>
</fieldset>
<p class="submit">
{csrf_field key=$csrf_key}
{button type="submit" name="save" label="Enregistrer" shape="right" class="main"}
{linkbutton label="Annuler" shape="export" href=$cancel_link}
</p>
</form>
{include file="admin/_foot.tpl"}

View File

@ -1,7 +1,17 @@
{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="entrees"}
déjà repertorie
{include file="admin/_foot.tpl"}
<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"}
<optgroup label="-- {$cat} --">
{foreach from=$eqmts item="eqmt"}
<option value="{$eqmt.id}">{$eqmt.designation}</option>
{/foreach}
</optgroup>
{/foreach}
</select>
</dd>
</dl>
</fieldset>

View File

@ -14,6 +14,7 @@
<th><b>Type</b></th>
<th><b>Nombre</b></th>
<th><b>Matériel</b></th>
<th><b>Remarques</b></th>
</thead>
<tbody>
{foreach from=$entries item="entry"}
@ -22,6 +23,7 @@
<td>{$entry.kind}</td>
<td>{$entry.equipment_number}</td>
<td>{$entry.equipment.designation}</td>
<td>{$entry.additional_comment}</td>
</tr>
{/foreach}
</tbody>

View File

@ -1,24 +1,4 @@
{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="entrees"}
<form method="post" action="{$self_url}">
<fieldset>
<legend>Ajouter une entrée d'un matériel pas encore répertorié</legend>
{form_errors}
<dl>
<dt><label for="f_kind">Type</label> <b>(obligatoire)</b></dt>
<dd>
<select name="kind" id="f_kind">
{foreach from=$kinds item="kind"}
<option value="{$kind}"{if $selected_kind == $kind} selected="selected"{/if}>{$kind}</option>
{/foreach}
</select>
</dd>
{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}
</dl>
<fieldset>
<fieldset>
<legend><h3>Matériel</h3></legend>
<dl>
<dt><label for="f_cat">Catégorie</label> <b>(obligatoire)</b></dt>
@ -31,13 +11,4 @@
</dd>
{input type="text" name="designation" label="Désignation" required=true maxlength="255"}
</dl>
</fieldset>
</fieldset>
<p class="submit">
{csrf_field key=$csrf_key}
{button type="submit" name="save" label="Enregistrer" shape="right" class="main"}
{linkbutton label="Annuler" shape="export" href=$cancel_link}
</p>
</form>
{include file="admin/_foot.tpl"}
</fieldset>

View File

@ -2,6 +2,57 @@
namespace Garradin;
use Garradin\Plugin\Materiels\Entry;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$tpl->display(PLUGIN_ROOT . '/templates/entrees/deja_repertorie.tpl');
$entry = new Entry;
$eqmt = new Equipment;
$csrf_key = 'add_entry';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
if ($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'),
]);
$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');
}
}
$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 = "déjà";
$tpl_materiel_name = "deja_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

@ -18,6 +18,7 @@ $date->setTimestamp(time());
$default_date = $date;
$default_number = "1";
$default_comment = "";
$cat = new Category;
$cats = $cat->listAll();
@ -31,6 +32,7 @@ if (f('save'))
$default_date = f('entry_date');
$default_number = f('equipment_number');
$selected_cat = f('category_id');
$default_comment = f('additional_comment');
if ($form->check($csrf_key) && !$form->hasErrors())
{
@ -47,6 +49,7 @@ if (f('save'))
'equipment_number' => (int) f('equipment_number'),
'equipment_id' => $eqmt_id,
'entry_date' => f('entry_date'),
'additional_comment' => f('additional_comment'),
]);
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
}
@ -64,7 +67,14 @@ if (f('save'))
}
$cancel_link = PLUGIN_URL . 'entrees/index.php';
$legend_part = "pas encore";
$tpl_materiel_name = "non_repertorie";
$tpl->assign(compact('kinds', 'cats', 'selected_kind', 'default_date', 'default_number', 'selected_cat', 'cancel_link', 'csrf_key'));
$tpl->display(PLUGIN_ROOT . '/templates/entrees/non_repertorie.tpl');
$tpl->assign(compact(
'kinds', 'cats', 'selected_kind', 'default_date',
'default_number', 'default_comment', 'selected_cat',
'cancel_link', 'legend_part', 'tpl_materiel_name', 'csrf_key'
));
$tpl->display(PLUGIN_ROOT . '/templates/entrees/ajouter_entree.tpl');