Liste dynamique triable des clients + export CSV/ODS

This commit is contained in:
bohwaz 2021-12-17 13:01:05 +01:00
parent 6db516f5b2
commit 440b2e3e66
3 changed files with 70 additions and 59 deletions

View File

@ -3,6 +3,7 @@
namespace Garradin\Plugin\Facturation;
use Garradin\DB;
use Garradin\DynamicList;
use Garradin\Plugin;
use Garradin\UserException;
use Garradin\Utils;
@ -103,6 +104,44 @@ class Client
return DB::getInstance()->get('SELECT *, strftime(\'%s\', date_creation) AS date_creation FROM plugin_facturation_clients');
}
public function list(): DynamicList
{
$columns = [
'id' => [
'label' => 'Numéro',
],
'nom' => [
'label' => 'Nom',
],
'adresse' => [
'label' => 'Adresse',
],
'code_postal' => [
'label' => 'Code postal',
],
'ville' => [
'label' => 'Ville',
],
'telephone' => [
'label' => 'Téléphone',
],
'email' => [
'label' => 'E-Mail',
],
'nb_documents' => [
'label' => 'Nombre de documents',
'select' => '(SELECT COUNT(*) FROM plugin_facturation_factures WHERE receveur_id = c.id)',
],
];
$tables = 'plugin_facturation_clients AS c';
$list = new DynamicList($columns, $tables);
$list->orderBy('id', false);
$list->setPageSize(1000);
return $list;
}
public function edit($id, $data = [])
{
$db = DB::getInstance();

View File

@ -1,65 +1,45 @@
{include file="admin/_head.tpl" title="Clients — %s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id js=1}
{include file="%s/templates/_menu.tpl"|args:$plugin_root current="clients"}
{form_errors}
{if $list->count()}
{include file="common/dynamic_list_head.tpl"}
<form method="post" action="{$self_url}" class="memberList">
{if !empty($clients)}
<table class="list">
<thead class="userOrder">
{foreach from=$list->iterate() item="row"}
<tr>
{* FIXME
{if $session->canAccess($session::SECTION_USERS, $session::ACCESS_ADMIN)}
<td class="check"><input type="checkbox" title="Tout cocher / décocher" /></td>
<td>{$row.id}</td>
<th><a href="client.php?id={$row.id}">{$row.nom}</a></th>
{foreach from=$row item="value" key="key"}
{if $key == 'id' || $key == 'nom'}
<?php continue; ?>
{/if}
*}
{foreach from=$champs key="c" item="champ"}
<td>{if $c == "numero"}#{else}{$champ.title}{/if} </td>
<td>{$value}</td>
{/foreach}
<td></td>
</tr>
</thead>
<tbody>
{foreach from=$clients item="membre"}
<tr>
{* FIXME
{if $session->canAccess($session::SECTION_USERS, $session::ACCESS_ADMIN)}
<td class="check">
{input type="checkbox" name="selected" value=$membre.id default=0}
</td>
{/if}
*}
{foreach from=$champs key="c" item="cfg"}
<td>
{if $c == 'nom'}<a href="{plugin_url file="client.php"}?id={$membre.id}">{/if}
{$membre->$c}
{if $c == 'nom'}</a>{/if}
</td>
{/foreach}
<td class="tabs">
{linkbutton shape="user" href="client.php?id=%d"|args:$membre.id label="Fiche client"}
<td class="actions">
{linkbutton shape="user" href="client.php?id=%d"|args:$row.id label="Fiche client"}
{if $session->canAccess($session::SECTION_USERS, $session::ACCESS_WRITE)}
{linkbutton shape="edit" href="client_modifier.php?id=%d"|args:$membre.id label="Modifier"}
{linkbutton shape="edit" href="client_modifier.php?id=%d"|args:$row.id label="Modifier"}
{/if}
</td>
</tr>
{/foreach}
</tbody>
{* FIXME
{if $session->canAccess($session::SECTION_USERS, $session::ACCESS_ADMIN)}
{include file="%s/templates/_list_actions.tpl"|args:$plugin_root colspan=count((array)$champs)}
{/if}
*}
</table>
<p class="help">
Export de la liste&nbsp;:
{linkbutton href="?export=csv" label="Export CSV" shape="download"}
{linkbutton href="?export=ods" label="Export tableur" shape="download"}
</p>
{else}
<p class="alert block">
Aucun client trouvé.
</p>
{/if}
</form>
{form_errors}
<form method="post" action="{$self_url}">
<fieldset>

View File

@ -40,17 +40,9 @@ if(f('add'))
}
$tpl->assign('clients', $client->listAll());
$tpl->assign('champs',
[
'id' => 'id',
'nom' => 'Nom',
'adresse' => 'Adresse',
'code_postal' => 'Code postal',
'ville' => 'Ville',
'telephone' => 'Numéro de téléphone',
'email' => 'Adresse mail'
]
);
$list = $client->list();
$list->loadFromQueryString();
$tpl->assign(compact('list'));
$tpl->display(PLUGIN_ROOT . '/templates/clients.tpl');