Ajout suppression doc + amélioration ui

This commit is contained in:
Noizette 2021-11-06 22:02:47 +01:00
parent d852c3c680
commit 2fda7a9db3
7 changed files with 81 additions and 5 deletions

View File

@ -344,4 +344,9 @@ class Facture
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);
}
}

View File

@ -4,12 +4,12 @@
{form_errors}
{if $session->canAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE)}
<a href="{plugin_url file="facture_modifier.php"}?id={$facture.id}">
<button type="button" class="btn btn-primary">Modifier ce document</button></a>
{linkbutton shape="edit" href="%sfacture_modifier.php?id=%d"|args:$plugin_url,$facture.id label="Modifier ce document"}
{/if}
<a href="{plugin_url file="pdf.php"}?d&id={$facture.id}">
<button type="button" class="btn btn-primary">Télécharger ce document</button></a>
{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"}
<div>
<embed src="pdf.php?id={$id}" type="application/pdf" width="100%" height="800px;" style="max-width: 900px;">

View File

@ -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}
<form method="post" action="{$self_url}">
<fieldset>
<legend>Supprimer ce document ?</legend>
<h3 class="warning">
Êtes-vous sûr de vouloir supprimer le document numéro «&nbsp;{$doc.numero}&nbsp;» ?
</h3>
<p class="alert">
<strong>Attention</strong> : cette action est irréversible.
</p>
</fieldset>
<p class="submit">
{csrf_field key="delete_doc_"|cat:$doc.id}
<input type="submit" name="delete" value="Supprimer &rarr;" />
</p>
</form>
{include file="admin/_foot.tpl"}

View File

@ -17,6 +17,7 @@
<td>Moyen paiement</td>
<td>Contenu</td>
<td>Total</td>
<td></td>
</thead>
<tbody>
{foreach from=$factures item=facture}
@ -50,11 +51,17 @@
<td><?= $facture->archivee?'Archivée':'Non' ?></td>
<td>{$facture.moyen_paiement}</td>
<td>
{if $facture.type_facture == 3}
<p>Cotisation {$facture.contenu.intitule}</p>
<p>Souscrite le {$facture.contenu.souscription|date_short}</p>
{else}
{foreach from=$facture.contenu item=contenu}
<p>{$contenu.designation} : {$contenu.prix|escape|money:false}&nbsp;{$config.monnaie}</p>
{/foreach}
{/if}
</td>
<td>{$facture.total|escape|money}&nbsp;{$config.monnaie}</td>
<td>{linkbutton shape="delete" href="%sfacture_supprimer.php?id=%d"|args:$plugin_url,$facture.id label="Supprimer"}</td>
</tr>
{/foreach}
</tbody>

View File

@ -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');

View File

@ -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');

View File

@ -0,0 +1,38 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->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');