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"} - -
+{form_errors}