ok for add entry for materiel listed in movement
This commit is contained in:
parent
02489e4550
commit
b9abf86388
|
@ -8,6 +8,7 @@ use Garradin\Plugin\Materiels\Category;
|
||||||
class Equipment
|
class Equipment
|
||||||
{
|
{
|
||||||
public function add($data = [])
|
public function add($data = [])
|
||||||
|
// add new equipment and return his id
|
||||||
{
|
{
|
||||||
$db = DB::getInstance();
|
$db = DB::getInstance();
|
||||||
$db->insert('plugin_materiels_equipment', $data);
|
$db->insert('plugin_materiels_equipment', $data);
|
||||||
|
@ -15,25 +16,31 @@ class Equipment
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id, $data = [])
|
public function edit($id, $data = [])
|
||||||
|
// edit a specific equipment
|
||||||
{
|
{
|
||||||
$db = DB::getInstance();
|
$db = DB::getInstance();
|
||||||
$db->update('plugin_materiels_equipment', $data, $db->where('id', $id));
|
$db->update('plugin_materiels_equipment', $data, $db->where('id', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($id)
|
public function get($id)
|
||||||
|
// get and return a specific category
|
||||||
{
|
{
|
||||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
|
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
|
// delete a specific equipment
|
||||||
{
|
{
|
||||||
DB::getInstance()->delete('plugin_materiels_equipment', 'id = ' . $id);
|
DB::getInstance()->delete('plugin_materiels_equipment', 'id = ' . $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listAllByCategory()
|
public function listAllByCategory()
|
||||||
|
// return list of all equipments ordered by category name
|
||||||
{
|
{
|
||||||
|
// get list of all category
|
||||||
$category = new Category;
|
$category = new Category;
|
||||||
$cats = $category->listAll();
|
$cats = $category->listAll();
|
||||||
|
// construct list of all equipments ordered by category name and return it
|
||||||
$eqmts_by_cat = array();
|
$eqmts_by_cat = array();
|
||||||
foreach ($cats as $cat) {
|
foreach ($cats as $cat) {
|
||||||
$eqmts_by_cat[$cat->name] = $category->listAllEquipments($cat->id);
|
$eqmts_by_cat[$cat->name] = $category->listAllEquipments($cat->id);
|
||||||
|
@ -45,10 +52,10 @@ class Equipment
|
||||||
// return number of equipments owned
|
// return number of equipments owned
|
||||||
{
|
{
|
||||||
$entries = DB::getInstance()->firstColumn(
|
$entries = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind IN (
|
"SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '0' AND kind IN (
|
||||||
'Achat', 'Don', 'Récupération') AND equipment_id = ?;", $id);
|
'Achat', 'Don', 'Récupération') AND equipment_id = ?;", $id);
|
||||||
$outputs = DB::getInstance()->firstColumn(
|
$outputs = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind IN (
|
"SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '1' AND kind IN (
|
||||||
'Vente', 'Don', 'Besoin', 'Autre (perte, vol, ...)') AND equipment_id = ?;", $id);
|
'Vente', 'Don', 'Besoin', 'Autre (perte, vol, ...)') AND equipment_id = ?;", $id);
|
||||||
return $entries - $outputs;
|
return $entries - $outputs;
|
||||||
}
|
}
|
||||||
|
@ -57,9 +64,9 @@ class Equipment
|
||||||
// return number of equipments owned out
|
// return number of equipments owned out
|
||||||
{
|
{
|
||||||
$entries = DB::getInstance()->firstColumn(
|
$entries = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Retour de location / prêt' AND equipment_id = ?;", $id);
|
"SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '0' AND kind = 'Retour de location / prêt' AND equipment_id = ?;", $id);
|
||||||
$outputs = DB::getInstance()->firstColumn(
|
$outputs = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind = 'Location / Prêt' AND equipment_id = ?;", $id);
|
"SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '1' AND kind = 'Location / Prêt' AND equipment_id = ?;", $id);
|
||||||
return $outputs - $entries;
|
return $outputs - $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +74,9 @@ class Equipment
|
||||||
// return number of equipments no owned
|
// return number of equipments no owned
|
||||||
{
|
{
|
||||||
$entries = DB::getInstance()->firstColumn(
|
$entries = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_entry WHERE kind = 'Location / Prêt' AND equipment_id = ?;", $id);
|
"SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '0' AND kind = 'Location / Prêt' AND equipment_id = ?;", $id);
|
||||||
$outputs = DB::getInstance()->firstColumn(
|
$outputs = DB::getInstance()->firstColumn(
|
||||||
"SELECT sum(equipment_number) FROM plugin_materiels_output WHERE kind = 'Retour de location / prêt' AND equipment_id = ?;", $id);
|
"SELECT sum(equipment_number) FROM plugin_materiels_movement WHERE side = '1' AND kind = 'Retour de location / prêt' AND equipment_id = ?;", $id);
|
||||||
return $entries - $outputs;
|
return $entries - $outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,23 @@ use Garradin\Plugin\Materiels\Equipment;
|
||||||
|
|
||||||
class Movement
|
class Movement
|
||||||
{
|
{
|
||||||
|
public function add($data = [])
|
||||||
|
// add new movement
|
||||||
|
{
|
||||||
|
DB::getInstance()->insert('plugin_materiels_movement', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listEntryKinds()
|
||||||
|
// return list of entry's kinds
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'Achat',
|
||||||
|
'Don',
|
||||||
|
'Récupération',
|
||||||
|
'Location / Prêt',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function listAllOneSide($side)
|
public function listAllOneSide($side)
|
||||||
// return all entries if side is 0 or all outputs if side is 1 ordered by date
|
// return all entries if side is 0 or all outputs if side is 1 ordered by date
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<!-- nav bar -->
|
||||||
|
{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="entrees"}
|
||||||
|
<!-- -->
|
||||||
|
<!-- add entry form -->
|
||||||
|
{include file="%smouvements/formulaire_mouvement.tpl"|args:$plugin_tpl legend="entrée d'un matériel %s"|args:$legend_part tpl_materiel_name=$tpl_materiel_name kinds=$kinds selected_kind=$selected_kind default_date=$default_date label_date="Date d'entrée" default_number=$default_number tpl_materiel_path="entrees" default_comment=$default_comment comment_placeholder="ex: don reçu de la part de..." csrf_key=$csrf_key cancel_link=$cancel_link}
|
||||||
|
<!-- -->
|
||||||
|
<!-- footer -->
|
||||||
|
{include file="admin/_foot.tpl"}
|
||||||
|
<!-- -->
|
|
@ -0,0 +1,21 @@
|
||||||
|
<!-- materiel listed part for add movement form -->
|
||||||
|
<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>
|
||||||
|
<!-- -->
|
|
@ -0,0 +1,47 @@
|
||||||
|
<!-- add movement form -->
|
||||||
|
<form method="post" action="{$self_url}">
|
||||||
|
<fieldset>
|
||||||
|
<!-- legend -->
|
||||||
|
<legend>Ajouter une {$legend}</legend>
|
||||||
|
<!-- -->
|
||||||
|
<!-- errors -->
|
||||||
|
{form_errors}
|
||||||
|
<!-- -->
|
||||||
|
<dl>
|
||||||
|
{if $tpl_materiel_name != 'retour'}
|
||||||
|
<!-- kind -->
|
||||||
|
<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>
|
||||||
|
<!-- -->
|
||||||
|
{/if}
|
||||||
|
<!-- date -->
|
||||||
|
{input type="date" name="mvt_date" default=$default_date label=$label_date required=true}
|
||||||
|
<!-- -->
|
||||||
|
<!-- number -->
|
||||||
|
{input type="number" name="equipment_number" label="Nombre" required=true step="1" min="1" default=$default_number}
|
||||||
|
<!-- -->
|
||||||
|
</dl>
|
||||||
|
<!-- materiel -->
|
||||||
|
{include file="%smouvements/{$tpl_materiel_path}/{$tpl_materiel_name}.tpl"|args:$plugin_tpl}
|
||||||
|
<!-- -->
|
||||||
|
<!-- comment -->
|
||||||
|
<dl>
|
||||||
|
{input type="textarea" name="additional_comment" label="Remarques" placeholder=$comment_placeholder default=$default_comment maxlength="255" rows=4 cols=30}
|
||||||
|
</dl>
|
||||||
|
<!-- -->
|
||||||
|
</fieldset>
|
||||||
|
<!-- submit and cancel buttons-->
|
||||||
|
<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>
|
||||||
|
<!-- -->
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../_inc.php';
|
||||||
|
|
||||||
|
use Garradin\Plugin\Materiels\Equipment;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
// check if add form is submitted
|
||||||
|
|
||||||
|
$csrf_key = 'add_entry';
|
||||||
|
|
||||||
|
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
|
{
|
||||||
|
// make the entry date in the good format
|
||||||
|
$mvt_date_format = date_create_from_format(
|
||||||
|
"d/m/Y", f('mvt_date'))->format("Y-m-d");
|
||||||
|
// add new entry
|
||||||
|
$mvt->add([
|
||||||
|
'side' => 0,
|
||||||
|
'kind' => f('kind'),
|
||||||
|
'equipment_number' => (int) f('equipment_number'),
|
||||||
|
'equipment_id' => f('equipment_id'),
|
||||||
|
'mvt_date' => $mvt_date_format,
|
||||||
|
'additional_comment' => f('additional_comment'),
|
||||||
|
]);
|
||||||
|
Utils::redirect(PLUGIN_URL . 'mouvements/entrees/index.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the list of all equipments ordered by category
|
||||||
|
$eqmt = new Equipment;
|
||||||
|
$eqmts_by_cat = $eqmt->listAllByCategory();
|
||||||
|
|
||||||
|
// get the list of entry's kinds
|
||||||
|
|
||||||
|
$kinds = $mvt->listEntryKinds();
|
||||||
|
$selected_kind = $kinds[0];
|
||||||
|
|
||||||
|
// make default date (now), default number (1), and default comment (empty)
|
||||||
|
$date = new \DateTime;
|
||||||
|
$date->setTimestamp(time());
|
||||||
|
$default_date = $date;
|
||||||
|
|
||||||
|
$default_number = "1";
|
||||||
|
$default_comment = "";
|
||||||
|
|
||||||
|
// make cancel link, legend for the title of the form
|
||||||
|
// and the template name for equipment to use in form
|
||||||
|
|
||||||
|
$cancel_link = PLUGIN_URL . 'mouvements/entrees/index.php';
|
||||||
|
$legend_part = "répertorié";
|
||||||
|
$tpl_materiel_name = "repertorie";
|
||||||
|
|
||||||
|
// send all to template
|
||||||
|
|
||||||
|
$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/mouvements/entrees/ajouter_entree.tpl');
|
Loading…
Reference in New Issue