ok for form to add entry for equipment not listed, next save entry and equipment in db

This commit is contained in:
JBthePenguin 2021-06-05 00:30:48 +02:00
parent 5b47a9d0ba
commit cd22b2a759
17 changed files with 178 additions and 25 deletions

Binary file not shown.

View File

@ -6,13 +6,10 @@ use Garradin\DB;
class Category class Category
{ {
protected $id; protected $columns_order = array(
protected $name; 'id',
'name',
protected $_types = [ );
'id' => 'int',
'name' => 'string',
];
public function add($data = []) public function add($data = [])
{ {

30
src/lib/Entry.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace Garradin\Plugin\Materiels;
use Garradin\DB;
class Entry
{
protected $columns_order = array(
'id',
'kind',
'number_of_equipments',
'equipment_id',
'date_of_entry',
);
public function listKinds()
{
return array(
'Achat',
'Don',
'Récupération',
);
}
public function listEquipmentIds()
{
// return $this->kinds;
}
}

16
src/lib/Equipment.php Normal file
View File

@ -0,0 +1,16 @@
<?php
namespace Garradin\Plugin\Materiels;
use Garradin\DB;
class Equipment
{
protected $columns_order = array(
'id',
'category_id',
'localisation_id',
'number_of_equipments',
'designation'
);
}

View File

@ -6,13 +6,10 @@ use Garradin\DB;
class Location class Location
{ {
protected $id; protected $columns_order = array(
protected $name; 'id',
'name',
protected $_types = [ );
'id' => 'int',
'name' => 'string',
];
public function add($data = []) public function add($data = [])
{ {

View File

@ -13,10 +13,9 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_location (
CREATE TABLE IF NOT EXISTS plugin_materiels_equipment ( CREATE TABLE IF NOT EXISTS plugin_materiels_equipment (
id integer NOT NULL PRIMARY KEY autoincrement, id integer NOT NULL PRIMARY KEY autoincrement,
category_id integer NOT NULL, category_id integer NOT NULL,
designation varchar(255) NOT NULL,
localisation_id integer NOT NULL, localisation_id integer NOT NULL,
current_value decimal NOT NULL DEFAULT 0, number_of_equipments integer NOT NULL,
number_of_materiels integer NOT NULL DEFAULT 1, designation varchar(255) NOT NULL,
CONSTRAINT u_equipment_designation UNIQUE ( designation ), CONSTRAINT u_equipment_designation UNIQUE ( designation ),
FOREIGN KEY ( category_id ) REFERENCES plugin_materiels_category( id ) ON DELETE RESTRICT ON UPDATE CASCADE, FOREIGN KEY ( category_id ) REFERENCES plugin_materiels_category( id ) ON DELETE RESTRICT ON UPDATE CASCADE,
FOREIGN KEY ( localisation_id ) REFERENCES plugin_materiels_location( id ) ON DELETE RESTRICT ON UPDATE CASCADE FOREIGN KEY ( localisation_id ) REFERENCES plugin_materiels_location( id ) ON DELETE RESTRICT ON UPDATE CASCADE
@ -25,6 +24,7 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_equipment (
CREATE TABLE IF NOT EXISTS plugin_materiels_entry ( CREATE TABLE IF NOT EXISTS plugin_materiels_entry (
id integer NOT NULL PRIMARY KEY autoincrement, id integer NOT NULL PRIMARY KEY autoincrement,
kind varchar(20) NOT NULL, kind varchar(20) NOT NULL,
number_of_equipments integer NOT NULL,
equipment_id integer NOT NULL, equipment_id integer NOT NULL,
date_of_entry date NOT NULL, date_of_entry date NOT NULL,
FOREIGN KEY ( equipment_id ) REFERENCES plugin_materiels_equipment( id ) ON DELETE RESTRICT ON UPDATE CASCADE FOREIGN KEY ( equipment_id ) REFERENCES plugin_materiels_equipment( id ) ON DELETE RESTRICT ON UPDATE CASCADE
@ -33,6 +33,7 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_entry (
CREATE TABLE IF NOT EXISTS plugin_materiels_temporary_entry ( CREATE TABLE IF NOT EXISTS plugin_materiels_temporary_entry (
id integer NOT NULL PRIMARY KEY autoincrement, id integer NOT NULL PRIMARY KEY autoincrement,
kind varchar(20) NOT NULL, kind varchar(20) NOT NULL,
number_of_equipments integer NOT NULL,
equipment_id integer NOT NULL, equipment_id integer NOT NULL,
start_date date NOT NULL, start_date date NOT NULL,
end_date date, end_date date,
@ -42,6 +43,7 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_temporary_entry (
CREATE TABLE IF NOT EXISTS plugin_materiels_output ( CREATE TABLE IF NOT EXISTS plugin_materiels_output (
id integer NOT NULL PRIMARY KEY autoincrement, id integer NOT NULL PRIMARY KEY autoincrement,
kind varchar(20) NOT NULL, kind varchar(20) NOT NULL,
number_of_equipments integer NOT NULL,
equipment_id integer NOT NULL, equipment_id integer NOT NULL,
output_date date NOT NULL, output_date date NOT NULL,
FOREIGN KEY ( equipment_id ) REFERENCES plugin_materiels_entry( equipment_id ) ON DELETE RESTRICT ON UPDATE CASCADE FOREIGN KEY ( equipment_id ) REFERENCES plugin_materiels_entry( equipment_id ) ON DELETE RESTRICT ON UPDATE CASCADE
@ -50,6 +52,7 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_output (
CREATE TABLE IF NOT EXISTS plugin_materiels_temporary_output ( CREATE TABLE IF NOT EXISTS plugin_materiels_temporary_output (
id integer NOT NULL PRIMARY KEY autoincrement, id integer NOT NULL PRIMARY KEY autoincrement,
kind varchar(20) NOT NULL, kind varchar(20) NOT NULL,
number_of_equipments integer NOT NULL,
equipment_id integer NOT NULL, equipment_id integer NOT NULL,
start_date date NOT NULL, start_date date NOT NULL,
end_date date, end_date date,

View File

@ -1,9 +1,9 @@
<nav class="tabs"> <nav class="tabs">
<ul> <ul>
<li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">Matériels en stock</a></li> <li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">Stock</a></li>
<li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories/index.php"}">Catégories</a></li> <li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories/index.php"}">Catégories</a></li>
<li class="{if $current == 'localisations'}current{/if}"><a href="{plugin_url file="localisations/index.php"}">Localisations</a></li> <li class="{if $current == 'localisations'}current{/if}"><a href="{plugin_url file="localisations/index.php"}">Localisations</a></li>
<li class="{if $current == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees_definitives.php"}"><b>Entrées définitives</b></a></li> <li class="{if $current == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees/definitives/index.php"}">Entrées définitives</a></li>
<li class="{if $current == 'entrees_provisoires'}current{/if}"><a href="{plugin_url file="entrees_provisoires.php"}">Entrées provisoires</a></li> <li class="{if $current == 'entrees_provisoires'}current{/if}"><a href="{plugin_url file="entrees_provisoires.php"}">Entrées provisoires</a></li>
<li class="{if $current == 'sorties_definitives'}current{/if}"><a href="{plugin_url file="sorties_definitives.php"}">Sorties définitives</a></li> <li class="{if $current == 'sorties_definitives'}current{/if}"><a href="{plugin_url file="sorties_definitives.php"}">Sorties définitives</a></li>
<li class="{if $current == 'sorties_provisoires'}current{/if}"><a href="{plugin_url file="sorties_provisoires.php"}">Sorties provisoires</a></li> <li class="{if $current == 'sorties_provisoires'}current{/if}"><a href="{plugin_url file="sorties_provisoires.php"}">Sorties provisoires</a></li>

View File

@ -7,7 +7,7 @@
<legend>Ajouter une catégorie</legend> <legend>Ajouter une catégorie</legend>
{form_errors} {form_errors}
<dl> <dl>
{input type="text" name="name" label="Nom" required=true} {input type="text" name="name" label="Nom" required=true maxlength="100"}
</dl> </dl>
<p class="submit"> <p class="submit">
{csrf_field key=$csrf_key} {csrf_field key=$csrf_key}
@ -26,7 +26,7 @@
<tr> <tr>
<th>{$cat.name}</th> <th>{$cat.name}</th>
<td class="actions"> <td class="actions">
{linkbutton shape="upload" label="Liste des materiels" href="materiels_par_categorie.php?id=%d"|args:$cat.id} {linkbutton shape="upload" label="Liste des matériels" href="materiels_par_categorie.php?id=%d"|args:$cat.id}
{linkbutton shape="edit" label="Modifier" href="modifier_categorie.php?id=%d"|args:$cat.id} {linkbutton shape="edit" label="Modifier" href="modifier_categorie.php?id=%d"|args:$cat.id}
{linkbutton shape="delete" label="Supprimer" href="supprimer_categorie.php?id=%d"|args:$cat.id} {linkbutton shape="delete" label="Supprimer" href="supprimer_categorie.php?id=%d"|args:$cat.id}
</td> </td>

View File

@ -7,7 +7,7 @@
<fieldset> <fieldset>
<legend>Modifier cette catégorie</legend> <legend>Modifier cette catégorie</legend>
<dl> <dl>
{input type="text" name="name" label="Nom" required=true source=$c} {input type="text" name="name" label="Nom" required=true source=$c maxlength="100"}
</dl> </dl>
</fieldset> </fieldset>
<p class="submit"> <p class="submit">

View File

@ -2,4 +2,6 @@
{include file="%s_nav.tpl"|args:$plugin_tpl current="entrees_definitives"} {include file="%s_nav.tpl"|args:$plugin_tpl current="entrees_definitives"}
déjà repertorie
{include file="admin/_foot.tpl"} {include file="admin/_foot.tpl"}

View File

@ -0,0 +1,11 @@
{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_definitives"}
<fieldset>
<legend>Ajouter une entrée définitive pour du </legend>
{linkbutton shape="plus" label="Matériel pas encore répertorié" href="non_repertorie.php"}
{linkbutton shape="plus" label="Matériel déjà répertorié" href="deja_repertorie.php"}
</fieldset>
{include file="admin/_foot.tpl"}

View File

@ -0,0 +1,51 @@
{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_definitives"}
<form method="post" action="{$self_url}">
<fieldset>
<legend>Ajouter une entrée définitive 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="date_entree" default=$date label="Date d'entrée" required=true }
{input type="number" name="number" label="Nombre d'entrée" required=true step="1" min="1" default="1"}
</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>
<dt><label for="f_cat">Localisation</label> <b>(obligatoire)</b></dt>
<dd>
<select name="location_id" id="f_loc">
{foreach from=$locs item="loc"}
<option value="{$loc.id}"{if $selected_loc == $loc.id} selected="selected"{/if}>{$loc.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"}

View File

@ -7,7 +7,7 @@
<legend>Ajouter une localisation</legend> <legend>Ajouter une localisation</legend>
{form_errors} {form_errors}
<dl> <dl>
{input type="text" name="name" label="Nom" required=true} {input type="text" name="name" label="Nom" required=true maxlength="100"}
</dl> </dl>
<p class="submit"> <p class="submit">
{csrf_field key=$csrf_key} {csrf_field key=$csrf_key}
@ -26,7 +26,7 @@
<tr> <tr>
<th>{$loc.name}</th> <th>{$loc.name}</th>
<td class="actions"> <td class="actions">
{linkbutton shape="upload" label="Liste des materiels" href="materiels_par_localisation.php?id=%d"|args:$loc.id} {linkbutton shape="upload" label="Liste des matériels" href="materiels_par_localisation.php?id=%d"|args:$loc.id}
{linkbutton shape="edit" label="Modifier" href="modifier_localisation.php?id=%d"|args:$loc.id} {linkbutton shape="edit" label="Modifier" href="modifier_localisation.php?id=%d"|args:$loc.id}
{linkbutton shape="delete" label="Supprimer" href="supprimer_localisation.php?id=%d"|args:$loc.id} {linkbutton shape="delete" label="Supprimer" href="supprimer_localisation.php?id=%d"|args:$loc.id}
</td> </td>

View File

@ -7,7 +7,7 @@
<fieldset> <fieldset>
<legend>Modifier cette localisation</legend> <legend>Modifier cette localisation</legend>
<dl> <dl>
{input type="text" name="name" label="Nom" required=true source=$l} {input type="text" name="name" label="Nom" required=true source=$l maxlength="100"}
</dl> </dl>
</fieldset> </fieldset>
<p class="submit"> <p class="submit">

View File

@ -0,0 +1,7 @@
<?php
namespace Garradin;
require_once __DIR__ . '/../../_inc.php';
$tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/deja_repertorie.tpl');

View File

@ -0,0 +1,7 @@
<?php
namespace Garradin;
require_once __DIR__ . '/../../_inc.php';
$tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/index.tpl');

View File

@ -0,0 +1,32 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Entry;
use Garradin\Plugin\Materiels\Category;
use Garradin\Plugin\Materiels\Location;
require_once __DIR__ . '/../../_inc.php';
$entry = new Entry;
$kinds = $entry->listKinds();
$selected_kind = $kinds[0];
$cat = new Category;
$cats = $cat->listAll();
$selected_cat = $cats[0]->id;
$loc = new Location;
$locs = $loc->listAll();
$selected_loc = $locs[0]->id;
$csrf_key = 'add_entry';
$date = new \DateTime;
$date->setTimestamp(time());
$cancel_link = PLUGIN_URL . 'entrees/definitives/index.php';
$tpl->assign(compact('kinds', 'cats', 'locs', 'date', 'selected_kind', 'selected_cat', 'selected_loc', 'cancel_link', 'csrf_key'));
$tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/non_repertorie.tpl');