diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index f113477..56cb647 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -8,6 +8,7 @@ use Garradin\Plugin\Materiels\Category; class Equipment { public function add($data = []) + // add new equipment and return his id { $db = DB::getInstance(); $db->insert('plugin_materiels_equipment', $data); @@ -15,25 +16,31 @@ class Equipment } public function edit($id, $data = []) + // edit a specific equipment { $db = DB::getInstance(); $db->update('plugin_materiels_equipment', $data, $db->where('id', $id)); } public function get($id) + // get and return a specific category { return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id); } public function delete($id) + // delete a specific equipment { DB::getInstance()->delete('plugin_materiels_equipment', 'id = ' . $id); } public function listAllByCategory() + // return list of all equipments ordered by category name { + // get list of all category $category = new Category; $cats = $category->listAll(); + // construct list of all equipments ordered by category name and return it $eqmts_by_cat = array(); foreach ($cats as $cat) { $eqmts_by_cat[$cat->name] = $category->listAllEquipments($cat->id); @@ -45,10 +52,10 @@ class Equipment // return number of equipments owned { $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); $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); return $entries - $outputs; } @@ -57,9 +64,9 @@ class Equipment // return number of equipments owned out { $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( - "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; } @@ -67,9 +74,9 @@ class Equipment // return number of equipments no owned { $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( - "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; } diff --git a/src/lib/Movement.php b/src/lib/Movement.php index 413e9ea..cffa604 100644 --- a/src/lib/Movement.php +++ b/src/lib/Movement.php @@ -7,6 +7,23 @@ use Garradin\Plugin\Materiels\Equipment; 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) // return all entries if side is 0 or all outputs if side is 1 ordered by date { diff --git a/src/templates/mouvements/entrees/ajouter_entree.tpl b/src/templates/mouvements/entrees/ajouter_entree.tpl new file mode 100644 index 0000000..3104a2d --- /dev/null +++ b/src/templates/mouvements/entrees/ajouter_entree.tpl @@ -0,0 +1,9 @@ + +{include file="%s_nav.tpl"|args:$plugin_tpl current_nav="entrees"} + + +{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} + + +{include file="admin/_foot.tpl"} + diff --git a/src/templates/mouvements/entrees/repertorie.tpl b/src/templates/mouvements/entrees/repertorie.tpl new file mode 100644 index 0000000..4736b64 --- /dev/null +++ b/src/templates/mouvements/entrees/repertorie.tpl @@ -0,0 +1,21 @@ + +
+ diff --git a/src/templates/mouvements/formulaire_mouvement.tpl b/src/templates/mouvements/formulaire_mouvement.tpl new file mode 100644 index 0000000..d9c5ec1 --- /dev/null +++ b/src/templates/mouvements/formulaire_mouvement.tpl @@ -0,0 +1,47 @@ + + + diff --git a/src/www/admin/mouvements/entrees/repertorie.php b/src/www/admin/mouvements/entrees/repertorie.php new file mode 100644 index 0000000..23e56e4 --- /dev/null +++ b/src/www/admin/mouvements/entrees/repertorie.php @@ -0,0 +1,63 @@ +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');