Skip to content

Commit c4f5a50

Browse files
authored
Merge pull request #87 from FacturaScripts/Tarea-4642-informe-clientes-activos
Añadido gráfico de clientes activos por año
2 parents eee729c + 05e986b commit c4f5a50

4 files changed

Lines changed: 40 additions & 3 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/BarChart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function render(array $dataChart = []): string
7373
. ' },'
7474
. ' xaxis: {'
7575
. ' categories: ' . json_encode($data['labels']) . ','
76-
. ' position: "' . ($horizontal ? 'bottom' : 'top') . '",'
76+
. ' position: "bottom",'
7777
. ' axisBorder: {'
7878
. ' show: false'
7979
. ' },'
@@ -109,8 +109,8 @@ public function render(array $dataChart = []): string
109109
. ' },'
110110
. ' title: {'
111111
. ' text: "' . $this->report->name . '",'
112-
. ' floating: ' . ($horizontal ? 'false' : 'true') . ','
113-
. ' offsetY: ' . ($horizontal ? 0 : ($chartHeight - 20)) . ','
112+
. ' floating: false,'
113+
. ' offsetY: 0,'
114114
. ' align: "' . ($horizontal ? 'left' : 'center') . '",'
115115
. ' style: {'
116116
. ' color: "#444"'

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)