Skip to content

Commit f3a51df

Browse files
committed
Añadido gráfico de clientes activos por año
- Se ha implementado la función `loadActiveCustomersByYear()` en `ReportCustomers.php` para cargar datos de clientes activos por año. - Se ha añadido la opción `COUNT_DISTINCT` en `Chart.php` para contar clientes únicos. - Se ha actualizado la plantilla `ReportCustomers.html.twig` para incluir un nuevo gráfico que muestra la distribución de clientes activos por año.
1 parent eee729c commit f3a51df

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

Controller/ReportCustomers.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function run(): void
9999
$this->loadTotalCustomers();
100100
$this->loadActiveCustomers();
101101
$this->loadInactiveCustomers();
102+
$this->loadActiveCustomersByYear();
102103
$this->loadActiveCustomersYear();
103104
$this->loadNewCustomers30Days();
104105
$this->loadCustomersWithDebt();
@@ -121,6 +122,23 @@ protected function loadActiveCustomers(): void
121122
$this->activeCustomers = $this->db()->select($sqlActive)[0]['total'];
122123
}
123124

125+
protected function loadActiveCustomersByYear(): void
126+
{
127+
$report = new Report();
128+
$report->type = Report::TYPE_BAR;
129+
$report->table = 'facturascli';
130+
$report->xcolumn = 'fecha';
131+
$report->ycolumn = 'codcliente';
132+
$report->xoperation = 'YEAR';
133+
$report->yoperation = 'COUNT_DISTINCT';
134+
$report->addFieldXName('');
135+
136+
Report::activateAdvancedReport(true);
137+
$report->addCustomFilter('idempresa', '=', (int)$this->idempresa);
138+
139+
$this->charts['activeCustomersByYear'] = $report;
140+
}
141+
124142
protected function loadActiveCustomersYear(): void
125143
{
126144
$sqlActiveYear = "SELECT COUNT(DISTINCT codcliente) as total FROM facturascli WHERE fecha >= '$this->currentYear-01-01'" . $this->whereEmpresaFacturas;

Lib/ReportChart/Chart.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ protected function getSqlMySQL(Report $report): string
180180
'MAXIMUM' => "MAX(" . $report->ycolumn . ")",
181181
'MINIMUM' => "MIN(" . $report->ycolumn . ")",
182182
'COUNT' => "COUNT(" . $report->ycolumn . ")",
183+
'COUNT_DISTINCT' => "COUNT(DISTINCT " . $report->ycolumn . ")",
183184
default => empty($report->ycolumn) ? 'COUNT(*)' : 'SUM(' . $report->ycolumn . ')',
184185
};
185186

@@ -249,6 +250,7 @@ protected function getSqlPostgreSQL(Report $report): string
249250
'MAXIMUM' => "MAX(" . $report->ycolumn . ")",
250251
'MINIMUM' => "MIN(" . $report->ycolumn . ")",
251252
'COUNT' => "COUNT(" . $report->ycolumn . ")",
253+
'COUNT_DISTINCT' => "COUNT(DISTINCT " . $report->ycolumn . ")",
252254
default => empty($report->ycolumn) ? 'COUNT(*)' : 'SUM(' . $report->ycolumn . ')',
253255
};
254256

View/ReportCustomers.html.twig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@
150150
</div>
151151
</div>
152152

153+
<div class="row">
154+
<div class="col-12">
155+
<div class="card shadow-sm mb-4">
156+
<div class="card-header py-3">
157+
<h6 class="m-0 font-weight-bold text-primary">
158+
<i class="fa-solid fa-chart-column me-1"></i>
159+
{{ trans('active-customers') }}
160+
({{ trans('year') }})
161+
</h6>
162+
</div>
163+
<div class="card-body">
164+
{{ fsc.charts.activeCustomersByYear.getChart().render({'height':250}) | raw }}
165+
</div>
166+
</div>
167+
</div>
168+
</div>
169+
153170
{# Distribución Geográfica y Grupos #}
154171
<div class="row mb-4">
155172
<div class="col-lg-4 d-flex">

0 commit comments

Comments
 (0)