OK to add already listed material
This commit is contained in:
parent
e2849cfcf7
commit
c4f8b4fb87
@ -21,6 +21,10 @@ class Entry
|
|||||||
'Achat',
|
'Achat',
|
||||||
'Don',
|
'Don',
|
||||||
'Récupération',
|
'Récupération',
|
||||||
|
'Location',
|
||||||
|
'Retour de location',
|
||||||
|
'Prêt',
|
||||||
|
'Retour de prêt',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Garradin\Plugin\Materiels;
|
namespace Garradin\Plugin\Materiels;
|
||||||
|
|
||||||
use Garradin\DB;
|
use Garradin\DB;
|
||||||
|
use Garradin\Plugin\Materiels\Category;
|
||||||
|
|
||||||
class Equipment
|
class Equipment
|
||||||
{
|
{
|
||||||
@ -35,4 +36,16 @@ class Equipment
|
|||||||
{
|
{
|
||||||
return DB::getInstance()->get('SELECT * FROM plugin_materiels_equipment ORDER BY designation;');
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
33
src/templates/entrees/ajouter_entree.tpl
Normal file
33
src/templates/entrees/ajouter_entree.tpl
Normal 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"}
|
@ -1,7 +1,17 @@
|
|||||||
{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
|
<fieldset>
|
||||||
|
<legend><h3>Matériel</h3></legend>
|
||||||
{include file="%s_nav.tpl"|args:$plugin_tpl current="entrees"}
|
<dl>
|
||||||
|
<dt><label for="f_eqmt"></label> <b>(obligatoire)</b></dt>
|
||||||
déjà repertorie
|
<dd>
|
||||||
|
<select name="equipment_id" id="f_eqmt">
|
||||||
{include file="admin/_foot.tpl"}
|
{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>
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<th><b>Type</b></th>
|
<th><b>Type</b></th>
|
||||||
<th><b>Nombre</b></th>
|
<th><b>Nombre</b></th>
|
||||||
<th><b>Matériel</b></th>
|
<th><b>Matériel</b></th>
|
||||||
|
<th><b>Remarques</b></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{foreach from=$entries item="entry"}
|
{foreach from=$entries item="entry"}
|
||||||
@ -22,6 +23,7 @@
|
|||||||
<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.designation}</td>
|
||||||
|
<td>{$entry.additional_comment}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -1,43 +1,14 @@
|
|||||||
{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id}
|
<fieldset>
|
||||||
|
<legend><h3>Matériel</h3></legend>
|
||||||
{include file="%s_nav.tpl"|args:$plugin_tpl current="entrees"}
|
<dl>
|
||||||
|
<dt><label for="f_cat">Catégorie</label> <b>(obligatoire)</b></dt>
|
||||||
<form method="post" action="{$self_url}">
|
<dd>
|
||||||
<fieldset>
|
<select name="category_id" id="f_cat">
|
||||||
<legend>Ajouter une entrée d'un matériel pas encore répertorié</legend>
|
{foreach from=$cats item="cat"}
|
||||||
{form_errors}
|
<option value="{$cat.id}"{if $selected_cat == $cat.id} selected="selected"{/if}>{$cat.name}</option>
|
||||||
<dl>
|
{/foreach}
|
||||||
<dt><label for="f_kind">Type</label> <b>(obligatoire)</b></dt>
|
</select>
|
||||||
<dd>
|
</dd>
|
||||||
<select name="kind" id="f_kind">
|
{input type="text" name="designation" label="Désignation" required=true maxlength="255"}
|
||||||
{foreach from=$kinds item="kind"}
|
</dl>
|
||||||
<option value="{$kind}"{if $selected_kind == $kind} selected="selected"{/if}>{$kind}</option>
|
</fieldset>
|
||||||
{/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>
|
|
||||||
<legend><h3>Matériel</h3></legend>
|
|
||||||
<dl>
|
|
||||||
<dt><label for="f_cat">Catégorie</label> <b>(obligatoire)</b></dt>
|
|
||||||
<dd>
|
|
||||||
<select name="category_id" id="f_cat">
|
|
||||||
{foreach from=$cats item="cat"}
|
|
||||||
<option value="{$cat.id}"{if $selected_cat == $cat.id} selected="selected"{/if}>{$cat.name}</option>
|
|
||||||
{/foreach}
|
|
||||||
</select>
|
|
||||||
</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"}
|
|
||||||
|
@ -2,6 +2,57 @@
|
|||||||
|
|
||||||
namespace Garradin;
|
namespace Garradin;
|
||||||
|
|
||||||
|
use Garradin\Plugin\Materiels\Entry;
|
||||||
|
use Garradin\Plugin\Materiels\Equipment;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
require_once __DIR__ . '/../_inc.php';
|
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');
|
||||||
|
@ -18,6 +18,7 @@ $date->setTimestamp(time());
|
|||||||
$default_date = $date;
|
$default_date = $date;
|
||||||
|
|
||||||
$default_number = "1";
|
$default_number = "1";
|
||||||
|
$default_comment = "";
|
||||||
|
|
||||||
$cat = new Category;
|
$cat = new Category;
|
||||||
$cats = $cat->listAll();
|
$cats = $cat->listAll();
|
||||||
@ -31,6 +32,7 @@ if (f('save'))
|
|||||||
$default_date = f('entry_date');
|
$default_date = f('entry_date');
|
||||||
$default_number = f('equipment_number');
|
$default_number = f('equipment_number');
|
||||||
$selected_cat = f('category_id');
|
$selected_cat = f('category_id');
|
||||||
|
$default_comment = f('additional_comment');
|
||||||
|
|
||||||
if ($form->check($csrf_key) && !$form->hasErrors())
|
if ($form->check($csrf_key) && !$form->hasErrors())
|
||||||
{
|
{
|
||||||
@ -47,6 +49,7 @@ if (f('save'))
|
|||||||
'equipment_number' => (int) f('equipment_number'),
|
'equipment_number' => (int) f('equipment_number'),
|
||||||
'equipment_id' => $eqmt_id,
|
'equipment_id' => $eqmt_id,
|
||||||
'entry_date' => f('entry_date'),
|
'entry_date' => f('entry_date'),
|
||||||
|
'additional_comment' => f('additional_comment'),
|
||||||
]);
|
]);
|
||||||
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
|
Utils::redirect(PLUGIN_URL . 'entrees/index.php');
|
||||||
}
|
}
|
||||||
@ -64,7 +67,14 @@ if (f('save'))
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cancel_link = PLUGIN_URL . 'entrees/index.php';
|
$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');
|
||||||
|
Loading…
Reference in New Issue
Block a user