Liste dynamique des documents
This commit is contained in:
parent
440b2e3e66
commit
fa35d7479d
108
lib/Facture.php
108
lib/Facture.php
@ -3,12 +3,22 @@
|
||||
namespace Garradin\Plugin\Facturation;
|
||||
|
||||
use DateTime;
|
||||
use Garradin\Config;
|
||||
use Garradin\DB;
|
||||
use Garradin\DynamicList;
|
||||
use Garradin\UserException;
|
||||
use Garradin\Utils;
|
||||
use Garradin\Services\Services_User;
|
||||
|
||||
class Facture
|
||||
{
|
||||
const TYPES_NAMES = [
|
||||
DEVIS => 'Devis',
|
||||
FACT => 'Facture',
|
||||
CERFA => 'Reçu fiscal',
|
||||
COTIS => 'Reçu de cotisation',
|
||||
];
|
||||
|
||||
private $keys = [
|
||||
'type_facture', // 0 : devis, 1 : facture, 2 : reçu cerfa, 3 : reçu cotis
|
||||
'numero',
|
||||
@ -235,6 +245,103 @@ class Facture
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function list(): DynamicList
|
||||
{
|
||||
$id_field = Config::getInstance()->champ_identite;
|
||||
|
||||
$columns = [
|
||||
// Sélectionner cette colonne, mais ne pas la mettre dans la liste des colonnes
|
||||
// (absence de label)
|
||||
'id' => [
|
||||
'select' => 'f.id',
|
||||
],
|
||||
'type_facture' => [
|
||||
],
|
||||
'receveur_membre' => [
|
||||
],
|
||||
'receveur_id' => [
|
||||
],
|
||||
// Créer une colonne virtuelle
|
||||
'type' => [
|
||||
'label' => 'Type',
|
||||
'select' => null,
|
||||
],
|
||||
'numero' => [
|
||||
'label' => 'Numéro',
|
||||
'select' => 'f.numero',
|
||||
],
|
||||
'receveur' => [
|
||||
'label' => 'Receveur',
|
||||
'select' => sprintf('CASE WHEN receveur_membre THEN u.%s ELSE c.nom END', $id_field),
|
||||
],
|
||||
'receveur_adresse' => [
|
||||
'label' => 'Son adresse',
|
||||
'select' => 'CASE WHEN receveur_membre THEN u.adresse ELSE c.adresse END',
|
||||
],
|
||||
'receveur_ville' => [
|
||||
'label' => 'Sa ville',
|
||||
'select' => 'CASE WHEN receveur_membre THEN u.ville ELSE c.ville END',
|
||||
],
|
||||
'date_emission' => [
|
||||
'label' => 'Émission',
|
||||
],
|
||||
'date_echeance' => [
|
||||
'label' => 'Échéance',
|
||||
],
|
||||
'reglee' => [
|
||||
'label' => 'Réglée',
|
||||
],
|
||||
'archivee' => [
|
||||
'label' => 'Archivée',
|
||||
],
|
||||
'moyen_paiement' => [
|
||||
'label' => 'Moyen de paiement',
|
||||
'select' => 'mp.nom',
|
||||
],
|
||||
'contenu' => [
|
||||
'label' => 'Contenu',
|
||||
],
|
||||
'total' => [
|
||||
'label' => 'Total',
|
||||
],
|
||||
];
|
||||
|
||||
$tables = 'plugin_facturation_factures AS f
|
||||
INNER JOIN plugin_facturation_paiement AS mp ON mp.code = f.moyen_paiement
|
||||
LEFT JOIN membres AS u ON f.receveur_membre = 1 AND u.id = f.receveur_id
|
||||
LEFT JOIN plugin_facturation_clients AS c ON f.receveur_membre = 0 AND c.id = f.receveur_id';
|
||||
|
||||
$list = new DynamicList($columns, $tables);
|
||||
$list->orderBy('numero', true);
|
||||
|
||||
$currency = Config::getInstance()->monnaie;
|
||||
|
||||
$list->setModifier(function ($row) use ($currency) {
|
||||
// Remplir la colonne virtuelle
|
||||
$row->type = self::TYPES_NAMES[$row->type_facture] ?? null;
|
||||
$row->reglee = $row->reglee ? 'Réglée' : 'Non';
|
||||
$row->archivee = $row->archivee ? 'Archivée' : 'Non';
|
||||
|
||||
// Remplir le contenu
|
||||
$content = json_decode((string)$row->contenu);
|
||||
|
||||
if ($row->type_facture == FACT && isset($content->intitule, $content->souscription)) {
|
||||
$row->contenu = sprintf("Cotisation %s\nSouscrite le %s",
|
||||
$content->intitule,
|
||||
Utils::date_fr($content->souscription, 'd/m/Y')
|
||||
);
|
||||
}
|
||||
else {
|
||||
$row->contenu = implode("\n", array_map(function ($row) use ($currency) {
|
||||
return sprintf('%s : %s %s', $row->designation, Utils::money_format($row->prix), $currency);
|
||||
}, (array)$content));
|
||||
}
|
||||
});
|
||||
|
||||
$list->setPageSize(1000);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function edit($id, $data = [])
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
@ -348,5 +455,4 @@ class Facture
|
||||
{
|
||||
return DB::getInstance()->delete('plugin_facturation_factures', 'id = '. (int)$id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,71 +3,42 @@
|
||||
|
||||
{form_errors}
|
||||
|
||||
{if count($factures)}
|
||||
<table class="list">
|
||||
<thead>
|
||||
<td>Type</td>
|
||||
<td>Numéro</td>
|
||||
<td>Receveur</td>
|
||||
<td>Son adresse</td>
|
||||
<td>Sa ville</td>
|
||||
<td>Emission</td>
|
||||
<td>Echéance</td>
|
||||
<td>Réglée</td>
|
||||
<td>Archivée</td>
|
||||
<td>Moyen paiement</td>
|
||||
<td>Contenu</td>
|
||||
<td>Total</td>
|
||||
<td></td>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$factures item=facture}
|
||||
<tr>
|
||||
<td><?php switch($facture->type_facture) {
|
||||
case 0:
|
||||
echo 'Devis';
|
||||
break;
|
||||
case 1:
|
||||
echo 'Facture';
|
||||
break;
|
||||
case 2:
|
||||
echo 'Reçu fiscal';
|
||||
break;
|
||||
case 3:
|
||||
echo 'Reçu cotisation';
|
||||
break;
|
||||
}
|
||||
?></td>
|
||||
<td><a href="{plugin_url file="facture.php"}?id={$facture.id}">{$facture.numero}</a></td>
|
||||
{if $list->count()}
|
||||
{include file="common/dynamic_list_head.tpl"}
|
||||
|
||||
{foreach from=$list->iterate() item="facture"}
|
||||
<tr>
|
||||
<td>{$facture.type}</td>
|
||||
<th><a href="facture.php?id={$facture.id}">{$facture.numero}</a></th>
|
||||
{if $facture.receveur_membre}
|
||||
<td><a href="{$admin_url}membres/fiche.php?id={$facture.receveur.id}">{$facture.receveur->$identite}</a></td>
|
||||
<td>{link href="!membres/fiche.php?id=%d"|args:$facture.receveur_id label=$facture.receveur}</td>
|
||||
{else}
|
||||
<td><a href="{plugin_url file="client.php"}?id={$facture.receveur.id}">{$facture.receveur.nom}</a></td>
|
||||
<td>{link href="client.php?id=%d"|args:$facture.receveur_id label=$facture.receveur}</td>
|
||||
{/if}
|
||||
<td>{$facture.receveur.adresse}</td>
|
||||
<td>{$facture.receveur.ville}</td>
|
||||
<td>{$facture.receveur_adresse}</td>
|
||||
<td>{$facture.receveur_ville}</td>
|
||||
<td>{$facture.date_emission|date:'d/m/Y'}</td>
|
||||
<td>{$facture.date_echeance|date:'d/m/Y'}</td>
|
||||
<td><?= $facture->reglee?'Réglée':'Non' ?></td>
|
||||
<td><?= $facture->archivee?'Archivée':'Non' ?></td>
|
||||
<td>{$facture.reglee}</td>
|
||||
<td>{$facture.archivee}</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} {$config.monnaie}</p>
|
||||
{/foreach}
|
||||
{/if}
|
||||
<td>{$facture.contenu|escape|nl2br}</td>
|
||||
<td>{$facture.total|escape|money_currency}</td>
|
||||
<td class="actions">
|
||||
{linkbutton shape="download" href="pdf.php?id=%d&d"|args:$facture.id label="Télécharger"}
|
||||
{linkbutton shape="menu" href="facture.php?id=%d"|args:$facture.id label="Voir"}
|
||||
</td>
|
||||
<td>{$facture.total|escape|money} {$config.monnaie}</td>
|
||||
{* <td>{linkbutton shape="delete" href="%sfacture_supprimer.php?id=%d"|args:$plugin_url,$facture.id label="Supprimer"}</td> *}
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="help">
|
||||
Export de la liste :
|
||||
{linkbutton href="?export=csv" label="Export CSV" shape="download"}
|
||||
{linkbutton href="?export=ods" label="Export tableur" shape="download"}
|
||||
</p>
|
||||
{else}
|
||||
<p class="help">Aucun document, vous pouvez commencer par {link href="facture_ajouter.php" label="créer un nouveau document"}.</p>
|
||||
{/if}
|
||||
|
@ -6,18 +6,10 @@ require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
|
||||
|
||||
$membres = new Membres;
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$list = $facture->list();
|
||||
$list->loadFromQueryString();
|
||||
|
||||
foreach($factures = $facture->listAll() as $k=>$f)
|
||||
{
|
||||
$factures[$k]->receveur = $f->receveur_membre? $membres->get($f->receveur_id) : $client->get($f->receveur_id);
|
||||
$factures[$k]->moyen_paiement = $facture->getMoyenPaiement($f->moyen_paiement);
|
||||
}
|
||||
|
||||
$tpl->assign('identite', $identite);
|
||||
$tpl->assign('factures', $factures);
|
||||
$tpl->assign('clients', $client->listAll());
|
||||
$tpl->assign(compact('list'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');
|
||||
|
Loading…
Reference in New Issue
Block a user