From 2fda7a9db33f02ca1adedbda0a3e98a7ad99d747 Mon Sep 17 00:00:00 2001 From: Noizette Date: Sat, 6 Nov 2021 22:02:47 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20suppression=20doc=20+=20am=C3=A9liorati?= =?UTF-8?q?on=20ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Facture.php | 5 +++++ templates/facture.tpl | 8 +++---- templates/facture_supprimer.tpl | 25 ++++++++++++++++++++++ templates/index.tpl | 7 ++++++ www/admin/_inc.php | 1 + www/admin/client_supprimer.php | 2 +- www/admin/facture_supprimer.php | 38 +++++++++++++++++++++++++++++++++ 7 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 templates/facture_supprimer.tpl create mode 100644 www/admin/facture_supprimer.php diff --git a/lib/Facture.php b/lib/Facture.php index 619b34c..dedf83b 100644 --- a/lib/Facture.php +++ b/lib/Facture.php @@ -343,5 +343,10 @@ class Facture $db = DB::getInstance(); return $db->firstColumn('SELECT nom FROM plugin_facturation_paiement WHERE code = ?;', $code); } + + public function delete($id) + { + return DB::getInstance()->delete('plugin_facturation_factures', 'id = '. (int)$id); + } } diff --git a/templates/facture.tpl b/templates/facture.tpl index a3f1dbc..6aec27e 100644 --- a/templates/facture.tpl +++ b/templates/facture.tpl @@ -4,12 +4,12 @@ {form_errors} {if $session->canAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE)} - - +{linkbutton shape="edit" href="%sfacture_modifier.php?id=%d"|args:$plugin_url,$facture.id label="Modifier ce document"} {/if} - - +{linkbutton shape="download" href="%spdf.php?d&id=%d"|args:$plugin_url,$facture.id label="Télécharger ce document"} + +{linkbutton shape="delete" href="%sfacture_supprimer.php?id=%d"|args:$plugin_url,$facture.id label="Supprimer ce document"}
diff --git a/templates/facture_supprimer.tpl b/templates/facture_supprimer.tpl new file mode 100644 index 0000000..0d8eb88 --- /dev/null +++ b/templates/facture_supprimer.tpl @@ -0,0 +1,25 @@ +{include file="admin/_head.tpl" title="Supprimer un document — %s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id js=0} +{include file="%s/templates/_menu.tpl"|args:$plugin_root current="index"} + +{form_errors} + +
+ +
+ Supprimer ce document ? +

+ Êtes-vous sûr de vouloir supprimer le document numéro « {$doc.numero} » ? +

+

+ Attention : cette action est irréversible. +

+
+ +

+ {csrf_field key="delete_doc_"|cat:$doc.id} + +

+ +
+ +{include file="admin/_foot.tpl"} \ No newline at end of file diff --git a/templates/index.tpl b/templates/index.tpl index 44c7812..a143788 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -17,6 +17,7 @@ Moyen paiement Contenu Total + {foreach from=$factures item=facture} @@ -50,11 +51,17 @@ archivee?'Archivée':'Non' ?> {$facture.moyen_paiement} + {if $facture.type_facture == 3} +

Cotisation {$facture.contenu.intitule}

+

Souscrite le {$facture.contenu.souscription|date_short}

+ {else} {foreach from=$facture.contenu item=contenu}

{$contenu.designation} : {$contenu.prix|escape|money:false} {$config.monnaie}

{/foreach} + {/if} {$facture.total|escape|money} {$config.monnaie} + {linkbutton shape="delete" href="%sfacture_supprimer.php?id=%d"|args:$plugin_url,$facture.id label="Supprimer"} {/foreach} diff --git a/www/admin/_inc.php b/www/admin/_inc.php index 5031b36..1a10bc7 100644 --- a/www/admin/_inc.php +++ b/www/admin/_inc.php @@ -15,6 +15,7 @@ $client = new Client; $facture = new Facture; $tpl->assign('f_obj', $facture); +$tpl->assign('plugin_url', Utils::plugin_url()); $identite = (string) Config::getInstance()->get('champ_identite'); diff --git a/www/admin/client_supprimer.php b/www/admin/client_supprimer.php index b91cb80..a66f135 100644 --- a/www/admin/client_supprimer.php +++ b/www/admin/client_supprimer.php @@ -36,5 +36,5 @@ if (f('delete')) $tpl->assign('deletable', $client->isDeletable($id)); -$tpl->assign('client', $client->get($id)); +$tpl->assign('client', $c); $tpl->display(PLUGIN_ROOT . '/templates/client_supprimer.tpl'); diff --git a/www/admin/facture_supprimer.php b/www/admin/facture_supprimer.php new file mode 100644 index 0000000..f12f48e --- /dev/null +++ b/www/admin/facture_supprimer.php @@ -0,0 +1,38 @@ +requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE); + +qv(['id' => 'required|numeric']); + +$id = (int) qg('id'); + +$f = $facture->get($id); + +if (!$client) +{ + throw new UserException("Ce document n'existe pas."); +} + +if (f('delete')) +{ + $form->check('delete_doc_'.$f->id); + + if (!$form->hasErrors()) + { + try { + $facture->delete($f->id); + Utils::redirect(PLUGIN_URL . 'index.php'); + } + catch (UserException $e) + { + $form->addError($e->getMessage()); + } + } +} + +$tpl->assign('doc', $f); +$tpl->display(PLUGIN_ROOT . '/templates/facture_supprimer.tpl'); \ No newline at end of file