ok to add entry and new equipment in db.
This commit is contained in:
parent
cd22b2a759
commit
bd2c6f25f5
|
@ -4,7 +4,7 @@ namespace Garradin\Plugin\Materiels;
|
||||||
|
|
||||||
use Garradin\DB;
|
use Garradin\DB;
|
||||||
|
|
||||||
class Entry
|
class Entry // entrées définitives
|
||||||
{
|
{
|
||||||
protected $columns_order = array(
|
protected $columns_order = array(
|
||||||
'id',
|
'id',
|
||||||
|
@ -23,8 +23,8 @@ class Entry
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listEquipmentIds()
|
public function add($data = [])
|
||||||
{
|
{
|
||||||
// return $this->kinds;
|
DB::getInstance()->insert('plugin_materiels_entry', $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,15 @@ class Equipment
|
||||||
protected $columns_order = array(
|
protected $columns_order = array(
|
||||||
'id',
|
'id',
|
||||||
'category_id',
|
'category_id',
|
||||||
'localisation_id',
|
'location_id',
|
||||||
'number_of_equipments',
|
'number_of_equipments',
|
||||||
'designation'
|
'designation'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function add($data = [])
|
||||||
|
{
|
||||||
|
$db = DB::getInstance();
|
||||||
|
$db->insert('plugin_materiels_equipment', $data);
|
||||||
|
return $db->lastInsertRowId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ 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,
|
||||||
localisation_id integer NOT NULL,
|
location_id integer NOT NULL,
|
||||||
number_of_equipments integer NOT NULL,
|
number_of_equipments integer NOT NULL,
|
||||||
designation varchar(255) NOT NULL,
|
designation varchar(255) NOT NULL,
|
||||||
CONSTRAINT u_equipment_designation UNIQUE ( designation ),
|
CONSTRAINT u_equipment_designation UNIQUE ( designation ),
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
</dd>
|
</dd>
|
||||||
{input type="date" name="date_entree" default=$date label="Date d'entrée" required=true }
|
{input type="date" name="date_entree" default=$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"}
|
{input type="number" name="number" label="Nombre d'entrée" required=true step="1" min="1" default=$default_number}
|
||||||
</dl>
|
</dl>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><h3>Matériel</h3></legend>
|
<legend><h3>Matériel</h3></legend>
|
||||||
|
|
|
@ -5,6 +5,8 @@ namespace Garradin;
|
||||||
use Garradin\Plugin\Materiels\Entry;
|
use Garradin\Plugin\Materiels\Entry;
|
||||||
use Garradin\Plugin\Materiels\Category;
|
use Garradin\Plugin\Materiels\Category;
|
||||||
use Garradin\Plugin\Materiels\Location;
|
use Garradin\Plugin\Materiels\Location;
|
||||||
|
use Garradin\Plugin\Materiels\Equipment;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../_inc.php';
|
require_once __DIR__ . '/../../_inc.php';
|
||||||
|
|
||||||
|
@ -12,6 +14,12 @@ $entry = new Entry;
|
||||||
$kinds = $entry->listKinds();
|
$kinds = $entry->listKinds();
|
||||||
$selected_kind = $kinds[0];
|
$selected_kind = $kinds[0];
|
||||||
|
|
||||||
|
$date = new \DateTime;
|
||||||
|
$date->setTimestamp(time());
|
||||||
|
$default_date = $date;
|
||||||
|
|
||||||
|
$default_number = "1";
|
||||||
|
|
||||||
$cat = new Category;
|
$cat = new Category;
|
||||||
$cats = $cat->listAll();
|
$cats = $cat->listAll();
|
||||||
$selected_cat = $cats[0]->id;
|
$selected_cat = $cats[0]->id;
|
||||||
|
@ -22,11 +30,48 @@ $selected_loc = $locs[0]->id;
|
||||||
|
|
||||||
$csrf_key = 'add_entry';
|
$csrf_key = 'add_entry';
|
||||||
|
|
||||||
$date = new \DateTime;
|
if (f('save'))
|
||||||
$date->setTimestamp(time());
|
{
|
||||||
|
$selected_kind = f('kind');
|
||||||
|
$default_date = f('date_entree');
|
||||||
|
$default_number = f('number');
|
||||||
|
$selected_cat = f('category_id');
|
||||||
|
$selected_loc = f('location_id');
|
||||||
|
|
||||||
|
if ($form->check($csrf_key) && !$form->hasErrors())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$eqmt = new Equipment;
|
||||||
|
$eqmt_id = $eqmt->add([
|
||||||
|
'category_id' => (int) f('category_id'),
|
||||||
|
'location_id' => (int) f('location_id'),
|
||||||
|
'number_of_equipments' => (int) f('number'),
|
||||||
|
'designation' => ucfirst(strtolower(f('designation'))),
|
||||||
|
]);
|
||||||
|
$entry->add([
|
||||||
|
'kind' => f('kind'),
|
||||||
|
'number_of_equipments' => (int) f('number'),
|
||||||
|
'equipment_id' => $eqmt_id,
|
||||||
|
'date_of_entry' => f('date_entree'),
|
||||||
|
]);
|
||||||
|
Utils::redirect(PLUGIN_URL . 'entrees/definitives/index.php');
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $e)
|
||||||
|
{
|
||||||
|
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
|
||||||
|
{
|
||||||
|
$form->addError('Un matériel avec cette désignation est déjà répertorié.');
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$form->addError($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$cancel_link = PLUGIN_URL . 'entrees/definitives/index.php';
|
$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->assign(compact('kinds', 'date', 'cats', 'locs', 'selected_kind', 'default_date', 'default_number', 'selected_cat', 'selected_loc', 'cancel_link', 'csrf_key'));
|
||||||
|
|
||||||
$tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/non_repertorie.tpl');
|
$tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/non_repertorie.tpl');
|
||||||
|
|
Loading…
Reference in New Issue