remove location

This commit is contained in:
JBthePenguin 2021-06-05 13:08:55 +02:00
parent bd2c6f25f5
commit c74ba5ed85
17 changed files with 39 additions and 287 deletions

View File

@ -9,7 +9,6 @@ class Equipment
protected $columns_order = array( protected $columns_order = array(
'id', 'id',
'category_id', 'category_id',
'location_id',
'number_of_equipments', 'number_of_equipments',
'designation' 'designation'
); );
@ -20,4 +19,9 @@ class Equipment
$db->insert('plugin_materiels_equipment', $data); $db->insert('plugin_materiels_equipment', $data);
return $db->lastInsertRowId(); return $db->lastInsertRowId();
} }
public function listAll()
{
return DB::getInstance()->get('SELECT * FROM plugin_materiels_equipment ORDER BY designation;');
}
} }

View File

@ -1,40 +0,0 @@
<?php
namespace Garradin\Plugin\Materiels;
use Garradin\DB;
class Location
{
protected $columns_order = array(
'id',
'name',
);
public function add($data = [])
{
DB::getInstance()->insert('plugin_materiels_location', $data);
}
public function edit($id, $data = [])
{
$db = DB::getInstance();
$db->update('plugin_materiels_location', $data, $db->where('id', $id));
}
public function delete($id)
{
DB::getInstance()->delete('plugin_materiels_location', 'id = ' . $id);
}
public function get($id)
{
return DB::getInstance()->first('SELECT * FROM plugin_materiels_location WHERE id = ?;', $id);
}
public function listAll()
{
return DB::getInstance()->get('SELECT * FROM plugin_materiels_location ORDER BY name;');
}
}

View File

@ -4,21 +4,13 @@ CREATE TABLE IF NOT EXISTS plugin_materiels_category (
CONSTRAINT u_category_name UNIQUE ( name ) CONSTRAINT u_category_name UNIQUE ( name )
); );
CREATE TABLE IF NOT EXISTS plugin_materiels_location (
id integer NOT NULL PRIMARY KEY autoincrement,
name varchar(100) NOT NULL,
CONSTRAINT u_location_name UNIQUE ( name )
);
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,
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 ),
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
); );
CREATE TABLE IF NOT EXISTS plugin_materiels_entry ( CREATE TABLE IF NOT EXISTS plugin_materiels_entry (

View File

@ -2,7 +2,6 @@
<ul> <ul>
<li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">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 == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees/definitives/index.php"}">Entrées définitives</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>

View File

@ -28,14 +28,6 @@
<option value="{$cat.id}"{if $selected_cat == $cat.id} selected="selected"{/if}>{$cat.name}</option> <option value="{$cat.id}"{if $selected_cat == $cat.id} selected="selected"{/if}>{$cat.name}</option>
{/foreach} {/foreach}
</select> </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> </dd>
{input type="text" name="designation" label="Désignation" required=true maxlength="255"} {input type="text" name="designation" label="Désignation" required=true maxlength="255"}
</dl> </dl>

View File

@ -2,4 +2,22 @@
{include file="%s_nav.tpl"|args:$plugin_tpl current="index"} {include file="%s_nav.tpl"|args:$plugin_tpl current="index"}
<table class="list">
<caption>Matériels</caption>
<thead>
<th>Nombre en stock</th>
<td>Categorie</td>
<td>Désignation</td>
</thead>
<tbody>
{foreach from=$eqmts item="eqmt"}
<tr>
<th>{$eqmt.number_of_equipments}</th>
<th>{$eqmt.category.name}</th>
<th>{$eqmt.designation}</th>
</tr>
{/foreach}
</tbody>
</table>
{include file="admin/_foot.tpl"} {include file="admin/_foot.tpl"}

View File

@ -1,38 +0,0 @@
{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="localisations"}
<form method="post" action="{$self_url}">
<fieldset>
<legend>Ajouter une localisation</legend>
{form_errors}
<dl>
{input type="text" name="name" label="Nom" required=true maxlength="100"}
</dl>
<p class="submit">
{csrf_field key=$csrf_key}
{button type="submit" name="save" label="Ajouter" shape="right" class="main"}
</p>
</fieldset>
</form>
<table class="list">
<thead>
<th>Nom</th>
<td></td>
</thead>
<tbody>
{foreach from=$list item="loc"}
<tr>
<th>{$loc.name}</th>
<td class="actions">
{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="delete" label="Supprimer" href="supprimer_localisation.php?id=%d"|args:$loc.id}
</td>
</tr>
{/foreach}
</tbody>
</table>
{include file="admin/_foot.tpl"}

View File

@ -1,5 +0,0 @@
{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="localisations"}
{include file="admin/_foot.tpl"}

View File

@ -1,20 +0,0 @@
{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="localisations"}
<form method="post" action="{$self_url}" data-focus="1">
{form_errors}
<fieldset>
<legend>Modifier cette localisation</legend>
<dl>
{input type="text" name="name" label="Nom" required=true source=$l maxlength="100"}
</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,11 +0,0 @@
{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="localisations"}
{include file="%scommon/delete_form.tpl"|args:$plugin_tpl
legend="Supprimer cette localisation de matériels ?"
warning="Êtes-vous sûr de vouloir supprimer la localisation « %s » ?"|args:$l.name
alert="Attention, la localisation ne doit plus contenir de matériels pour pouvoir être supprimée."
}
{include file="admin/_foot.tpl"}

View File

@ -4,7 +4,6 @@ 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\Equipment; use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils; use Garradin\Utils;
@ -24,10 +23,6 @@ $cat = new Category;
$cats = $cat->listAll(); $cats = $cat->listAll();
$selected_cat = $cats[0]->id; $selected_cat = $cats[0]->id;
$loc = new Location;
$locs = $loc->listAll();
$selected_loc = $locs[0]->id;
$csrf_key = 'add_entry'; $csrf_key = 'add_entry';
if (f('save')) if (f('save'))
@ -36,7 +31,6 @@ if (f('save'))
$default_date = f('date_entree'); $default_date = f('date_entree');
$default_number = f('number'); $default_number = f('number');
$selected_cat = f('category_id'); $selected_cat = f('category_id');
$selected_loc = f('location_id');
if ($form->check($csrf_key) && !$form->hasErrors()) if ($form->check($csrf_key) && !$form->hasErrors())
{ {
@ -45,7 +39,6 @@ if (f('save'))
$eqmt = new Equipment; $eqmt = new Equipment;
$eqmt_id = $eqmt->add([ $eqmt_id = $eqmt->add([
'category_id' => (int) f('category_id'), 'category_id' => (int) f('category_id'),
'location_id' => (int) f('location_id'),
'number_of_equipments' => (int) f('number'), 'number_of_equipments' => (int) f('number'),
'designation' => ucfirst(strtolower(f('designation'))), 'designation' => ucfirst(strtolower(f('designation'))),
]); ]);
@ -72,6 +65,6 @@ if (f('save'))
$cancel_link = PLUGIN_URL . 'entrees/definitives/index.php'; $cancel_link = PLUGIN_URL . 'entrees/definitives/index.php';
$tpl->assign(compact('kinds', 'date', 'cats', 'locs', 'selected_kind', 'default_date', 'default_number', 'selected_cat', 'selected_loc', 'cancel_link', 'csrf_key')); $tpl->assign(compact('kinds', 'date', 'cats', 'selected_kind', 'default_date', 'default_number', 'selected_cat', 'cancel_link', 'csrf_key'));
$tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/non_repertorie.tpl'); $tpl->display(PLUGIN_ROOT . '/templates/entrees/definitives/non_repertorie.tpl');

View File

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

View File

@ -7,6 +7,20 @@ if ($plugin->needUpgrade())
$plugin->upgrade(); $plugin->upgrade();
} }
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Plugin\Materiels\Category;
require_once __DIR__ . '/_inc.php'; require_once __DIR__ . '/_inc.php';
$eqmt = new Equipment;
$cat = new Category;
$eqmts = $eqmt->listAll();
foreach ($eqmts as $key => $value) {
$eqmts[$key]->category = $cat->get($value->category_id);
}
$tpl->assign(compact('eqmts'));
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl'); $tpl->display(PLUGIN_ROOT . '/templates/index.tpl');

View File

@ -1,39 +0,0 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Location;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$loc = new Location;
$csrf_key = 'loc_create';
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
try
{
$loc->add([
'name' => ucfirst(f('name'))
]);
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
}
catch (\RuntimeException $e)
{
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
{
$form->addError('Cette localisation existe déjà.');
} else
{
$form->addError($e->getMessage());
}
}
}
$list = $loc->listAll();
$tpl->assign(compact('csrf_key', 'list'));
$tpl->display(PLUGIN_ROOT . '/templates/localisations/index.tpl');

View File

@ -1,20 +0,0 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Location;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$loc = new Location;
$l = $loc->get((int) qg('id'));
if (!$l) {
throw new UserException("Cette localisation n'existe pas.");
}
$tpl->assign(compact('l'));
$tpl->display(PLUGIN_ROOT . '/templates/localisations/materiels_par_localisation.tpl');

View File

@ -1,44 +0,0 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Location;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$loc = new Location;
$l = $loc->get((int) qg('id'));
if (!$l) {
throw new UserException("Cette localisation n'existe pas.");
}
$csrf_key = 'edit_location_' . $l->id;
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
try
{
$loc->edit($l->id, [
'name' => ucfirst(f('name'))
]);
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
}
catch (\RuntimeException $e)
{
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
{
$form->addError('Cette localisation existe déjà.');
} else
{
$form->addError($e->getMessage());
}
}
}
$cancel_link = PLUGIN_URL . 'localisations/index.php';
$tpl->assign(compact('l', 'csrf_key', 'cancel_link'));
$tpl->display(PLUGIN_ROOT . '/templates/localisations/modifier_localisation.tpl');

View File

@ -1,36 +0,0 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Location;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$loc = new Location;
$l = $loc->get((int) qg('id'));
if (!$l) {
throw new UserException("Cette localisation n'existe pas.");
}
$csrf_key = 'delete_location_' . $l->id;
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
{
try
{
$loc->delete($l->id);
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
}
catch (\RuntimeException $e)
{
$form->addError($e->getMessage());
}
}
$cancel_link = PLUGIN_URL . 'localisations/index.php';
$tpl->assign(compact('l', 'csrf_key', 'cancel_link'));
$tpl->display(PLUGIN_ROOT . '/templates/localisations/supprimer_localisation.tpl');