diff --git a/lib/Client.php b/lib/Client.php index 1881c82..d914047 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -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(); diff --git a/templates/clients.tpl b/templates/clients.tpl index aff2899..3923fef 100644 --- a/templates/clients.tpl +++ b/templates/clients.tpl @@ -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"} - -
- -{if !empty($clients)} - - + {foreach from=$list->iterate() item="row"} - {* FIXME - {if $session->canAccess($session::SECTION_USERS, $session::ACCESS_ADMIN)} - - {/if} - *} - {foreach from=$champs key="c" item="champ"} - + + + + {foreach from=$row item="value" key="key"} + {if $key == 'id' || $key == 'nom'} + + {/if} + {/foreach} - - - - - {foreach from=$clients item="membre"} - - {* FIXME - {if $session->canAccess($session::SECTION_USERS, $session::ACCESS_ADMIN)} - - {/if} - *} - {foreach from=$champs key="c" item="cfg"} - - {/foreach} - - - {/foreach} + + {/foreach} + - {* 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} - *}
{if $c == "numero"}#{else}{$champ.title}{/if} {$row.id}{$row.nom}{$value}
- {input type="checkbox" name="selected" value=$membre.id default=0} + + {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:$row.id label="Modifier"} + {/if} - {if $c == 'nom'}{/if} - {$membre->$c} - {if $c == 'nom'}{/if} - - {linkbutton shape="user" href="client.php?id=%d"|args:$membre.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"} - {/if} -
+ +

+ Export de la liste : + {linkbutton href="?export=csv" label="Export CSV" shape="download"} + {linkbutton href="?export=ods" label="Export tableur" shape="download"} +

+ {else}

Aucun client trouvé.

{/if} -
+{form_errors}
diff --git a/www/admin/clients.php b/www/admin/clients.php index 8dcd5f2..a470ee7 100644 --- a/www/admin/clients.php +++ b/www/admin/clients.php @@ -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');