Skip to content

Commit ec0f67f

Browse files
NeoRazorXclaude
andcommitted
Filtrar informe de servicios por empresa y añadir gráficos de importes
- Añade selector de empresa en el encabezado de ReportServicioAT (por defecto la empresa predeterminada vía Core\DataSrc\Empresas). - Filtra todas las consultas del informe por idempresa. - Reduce las sombras de los cards (shadow → shadow-sm). - Nuevos gráficos de importes (neto) por mes y por año. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 37c5ff6 commit ec0f67f

16 files changed

Lines changed: 263 additions & 138 deletions

Controller/ReportServicioAT.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
namespace FacturaScripts\Plugins\Servicios\Controller;
2121

2222
use DateTime;
23+
use FacturaScripts\Core\DataSrc\Empresas;
2324
use FacturaScripts\Core\Template\Controller;
25+
use FacturaScripts\Dinamic\Model\Empresa;
2426

2527
/**
2628
* Informe de servicios: abiertos totales, del último mes, del último año y desglose por estado.
@@ -50,6 +52,12 @@ class ReportServicioAT extends Controller
5052
/** @var array */
5153
public $servicesByYear = [];
5254

55+
/** @var array */
56+
public $amountsByMonth = [];
57+
58+
/** @var array */
59+
public $amountsByYear = [];
60+
5361
/** @var int */
5462
public $openServices;
5563

@@ -62,6 +70,12 @@ class ReportServicioAT extends Controller
6270
/** @var int */
6371
public $totalServices;
6472

73+
/** @var int */
74+
public $idempresa;
75+
76+
/** @var Empresa[] */
77+
public $empresas = [];
78+
6579
public function getPageData(): array
6680
{
6781
$data = parent::getPageData();
@@ -75,6 +89,9 @@ public function run(): void
7589
{
7690
parent::run();
7791

92+
$this->empresas = Empresas::all();
93+
$this->idempresa = (int)$this->request()->get('idempresa', Empresas::default()->idempresa);
94+
7895
$this->loadTotalServices();
7996
$this->loadOpenServices();
8097
$this->loadOpenServicesLastMonth();
@@ -92,7 +109,8 @@ public function run(): void
92109

93110
protected function loadTotalServices(): void
94111
{
95-
$sql = 'SELECT COUNT(*) as total FROM serviciosat';
112+
$sql = 'SELECT COUNT(*) as total FROM serviciosat'
113+
. ' WHERE idempresa = ' . $this->db()->var2str($this->idempresa);
96114
$result = $this->db()->select($sql);
97115
$this->totalServices = (int)($result[0]['total'] ?? 0);
98116
}
@@ -101,6 +119,7 @@ protected function loadServicesByNick(): void
101119
{
102120
$sql = 'SELECT nick, COUNT(*) as total'
103121
. ' FROM serviciosat'
122+
. ' WHERE idempresa = ' . $this->db()->var2str($this->idempresa)
104123
. ' GROUP BY nick'
105124
. ' ORDER BY total DESC';
106125
$this->servicesByNick = $this->db()->select($sql);
@@ -111,6 +130,7 @@ protected function loadServicesByAgent(): void
111130
$sql = 'SELECT s.codagente, a.nombre, COUNT(s.idservicio) as total'
112131
. ' FROM serviciosat s'
113132
. ' LEFT JOIN agentes a ON a.codagente = s.codagente'
133+
. ' WHERE s.idempresa = ' . $this->db()->var2str($this->idempresa)
114134
. ' GROUP BY s.codagente, a.nombre'
115135
. ' ORDER BY total DESC';
116136
$this->servicesByAgent = $this->db()->select($sql);
@@ -120,6 +140,7 @@ protected function loadServicesByAssigned(): void
120140
{
121141
$sql = 'SELECT asignado, COUNT(*) as total'
122142
. ' FROM serviciosat'
143+
. ' WHERE idempresa = ' . $this->db()->var2str($this->idempresa)
123144
. ' GROUP BY asignado'
124145
. ' ORDER BY total DESC';
125146
$this->servicesByAssigned = $this->db()->select($sql);
@@ -130,6 +151,7 @@ protected function loadServicesByClient(): void
130151
$sql = 'SELECT s.codcliente, c.nombre, COUNT(s.idservicio) as total'
131152
. ' FROM serviciosat s'
132153
. ' LEFT JOIN clientes c ON c.codcliente = s.codcliente'
154+
. ' WHERE s.idempresa = ' . $this->db()->var2str($this->idempresa)
133155
. ' GROUP BY s.codcliente, c.nombre'
134156
. ' ORDER BY total DESC';
135157
$this->servicesByClient = $this->db()->select($sql);
@@ -138,23 +160,26 @@ protected function loadServicesByClient(): void
138160
protected function loadOpenServices(): void
139161
{
140162
$sql = 'SELECT COUNT(*) as total FROM serviciosat'
141-
. ' WHERE editable = ' . $this->db()->var2str(true);
163+
. ' WHERE editable = ' . $this->db()->var2str(true)
164+
. ' AND idempresa = ' . $this->db()->var2str($this->idempresa);
142165
$result = $this->db()->select($sql);
143166
$this->openServices = (int)($result[0]['total'] ?? 0);
144167
}
145168

146169
protected function loadOpenServicesLastMonth(): void
147170
{
148171
$since = date('Y-m-d', strtotime('-1 month'));
149-
$sql = "SELECT COUNT(*) as total FROM serviciosat WHERE fecha >= '" . $since . "'";
172+
$sql = "SELECT COUNT(*) as total FROM serviciosat WHERE fecha >= '" . $since . "'"
173+
. ' AND idempresa = ' . $this->db()->var2str($this->idempresa);
150174
$result = $this->db()->select($sql);
151175
$this->openServicesLastMonth = (int)($result[0]['total'] ?? 0);
152176
}
153177

154178
protected function loadOpenServicesLastYear(): void
155179
{
156180
$since = date('Y-m-d', strtotime('-1 year'));
157-
$sql = "SELECT COUNT(*) as total FROM serviciosat WHERE fecha >= '" . $since . "'";
181+
$sql = "SELECT COUNT(*) as total FROM serviciosat WHERE fecha >= '" . $since . "'"
182+
. ' AND idempresa = ' . $this->db()->var2str($this->idempresa);
158183
$result = $this->db()->select($sql);
159184
$this->openServicesLastYear = (int)($result[0]['total'] ?? 0);
160185
}
@@ -167,29 +192,36 @@ protected function loadServicesByMonth(): void
167192
$date = clone $now;
168193
$date->modify("-$i months");
169194
$this->servicesByMonth[$date->format('Y-m')] = 0;
195+
$this->amountsByMonth[$date->format('Y-m')] = 0.0;
170196
}
171197

172198
$since = (clone $now)->modify('-11 months')->format('Y-m-01');
173-
$sql = "SELECT DATE_FORMAT(fecha, '%Y-%m') as periodo, COUNT(*) as total"
199+
$sql = "SELECT DATE_FORMAT(fecha, '%Y-%m') as periodo, COUNT(*) as total,"
200+
. ' COALESCE(SUM(neto), 0) as neto'
174201
. ' FROM serviciosat'
175202
. " WHERE fecha >= '" . $since . "'"
203+
. ' AND idempresa = ' . $this->db()->var2str($this->idempresa)
176204
. " GROUP BY DATE_FORMAT(fecha, '%Y-%m')"
177205
. ' ORDER BY periodo ASC';
178206
foreach ($this->db()->select($sql) as $row) {
179207
if (isset($this->servicesByMonth[$row['periodo']])) {
180208
$this->servicesByMonth[$row['periodo']] = (int)$row['total'];
209+
$this->amountsByMonth[$row['periodo']] = (float)$row['neto'];
181210
}
182211
}
183212
}
184213

185214
protected function loadServicesByYear(): void
186215
{
187-
$sql = 'SELECT YEAR(fecha) as periodo, COUNT(*) as total'
216+
$sql = 'SELECT YEAR(fecha) as periodo, COUNT(*) as total,'
217+
. ' COALESCE(SUM(neto), 0) as neto'
188218
. ' FROM serviciosat'
219+
. ' WHERE idempresa = ' . $this->db()->var2str($this->idempresa)
189220
. ' GROUP BY YEAR(fecha)'
190221
. ' ORDER BY periodo ASC';
191222
foreach ($this->db()->select($sql) as $row) {
192223
$this->servicesByYear[(string)$row['periodo']] = (int)$row['total'];
224+
$this->amountsByYear[(string)$row['periodo']] = (float)$row['neto'];
193225
}
194226
}
195227

@@ -199,6 +231,7 @@ protected function loadServicesByStatus(): void
199231
. ' COALESCE(SUM(s.neto), 0) as neto'
200232
. ' FROM serviciosat_estados e'
201233
. ' LEFT JOIN serviciosat s ON s.idestado = e.id'
234+
. ' AND s.idempresa = ' . $this->db()->var2str($this->idempresa)
202235
. ' GROUP BY e.id, e.nombre, e.color, e.editable'
203236
. ' ORDER BY total DESC';
204237
$this->servicesByStatus = $this->db()->select($sql);

Translation/ca_ES.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"notify-customer": "Notificar al client",
4848
"notify-user": "Notificar a l'usuari",
4949
"open-services": "Obert",
50-
"open-services-last-month": "Abiertos último mes",
51-
"open-services-last-year": "Abiertos último año",
52-
"open-services-total": "Servicios abiertos",
50+
"open-services-last-month": "Oberts l'últim mes",
51+
"open-services-last-year": "Oberts l'últim any",
52+
"open-services-total": "Serveis oberts",
5353
"print-agent": "Imprimir agent",
5454
"print-assigned": "Imprimir assignat",
5555
"print-description": "Imprimir descripció",
@@ -62,15 +62,15 @@
6262
"print-services": "Imprimir serveis",
6363
"print-solution": "Imprimeix solució",
6464
"print-ticket-desc": "Aquesta configuració només s'aplica als tiquets de servei. Cal tenir el plugin Tickets instal·lat.",
65-
"services-by-agent": "Por agente",
66-
"services-by-assigned": "Por asignado",
67-
"services-by-client": "Por cliente",
68-
"services-by-month": "Servicios por mes (últimos 12 meses)",
69-
"services-by-nick": "Por usuario creador",
70-
"services-by-status": "Por estado",
71-
"services-by-year": "Servicios por año",
65+
"services-by-agent": "Per agent",
66+
"services-by-assigned": "Serveis assignats",
67+
"services-by-client": "Per clients",
68+
"services-by-month": "Serveis per mes (últims 12 mesos)",
69+
"services-by-nick": "Per usuari creador",
70+
"services-by-status": "Per estat",
71+
"services-by-year": "Serveis per any",
7272
"ticket-footer-text": "Text del peu del tiquet",
73-
"total-net": "Neto total",
74-
"total-services": "Total de servicios",
73+
"total-net": "Total net",
74+
"total-services": "Total de serveis",
7575
"verifications": "Verificacions"
7676
}

Translation/cs_CZ.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"notify-customer": "Notificar al cliente",
4848
"notify-user": "Notificar al usuario",
4949
"open-services": "otevřít",
50-
"open-services-last-month": "Abiertos último mes",
51-
"open-services-last-year": "Abiertos último año",
52-
"open-services-total": "Servicios abiertos",
50+
"open-services-last-month": "Otevřené v posledním měsíci",
51+
"open-services-last-year": "Otevřené služby za poslední rok",
52+
"open-services-total": "Otevřené služby",
5353
"print-agent": "Tisknout agenta",
5454
"print-assigned": "Tisknout přiřazené",
5555
"print-description": "Tisknout popis",
@@ -62,15 +62,15 @@
6262
"print-services": "Tisk služeb",
6363
"print-solution": "Tiskové řešení",
6464
"print-ticket-desc": "Toto nastavení se použije pouze na servisní lístky. Je nutné mít nainstalovaný plugin Tickets.",
65-
"services-by-agent": "Por agente",
65+
"services-by-agent": "Podle agenta",
6666
"services-by-assigned": "Por asignado",
67-
"services-by-client": "Por cliente",
68-
"services-by-month": "Servicios por mes (últimos 12 meses)",
69-
"services-by-nick": "Por usuario creador",
70-
"services-by-status": "Por estado",
71-
"services-by-year": "Servicios por año",
67+
"services-by-client": "Podle zákazníka",
68+
"services-by-month": "Služby podle měsíce (posledních 12 měsíců)",
69+
"services-by-nick": "Podle uživatele (tvůrce)",
70+
"services-by-status": "Podle stavu",
71+
"services-by-year": "Služby podle roku",
7272
"ticket-footer-text": "Text patičky lístku",
73-
"total-net": "Neto total",
74-
"total-services": "Total de servicios",
73+
"total-net": "Celkem netto",
74+
"total-services": "Celkem služeb",
7575
"verifications": "Ověření"
7676
}

Translation/de_DE.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"notify-customer": "Kunden benachrichtigen",
4848
"notify-user": "Benutzer benachrichtigen",
4949
"open-services": "offen",
50-
"open-services-last-month": "Abiertos último mes",
51-
"open-services-last-year": "Abiertos último año",
52-
"open-services-total": "Servicios abiertos",
50+
"open-services-last-month": "Offene Dienstleistungen im letzten Monat",
51+
"open-services-last-year": "Offene Dienstleistungen im letzten Jahr",
52+
"open-services-total": "Offene Dienstleistungen",
5353
"print-agent": "Agent drucken.",
5454
"print-assigned": "Zuordnung drucken",
5555
"print-description": "Beschreibung drucken",
@@ -62,15 +62,15 @@
6262
"print-services": "Dienste drucken.",
6363
"print-solution": "Drucklösung",
6464
"print-ticket-desc": "Diese Einstellung gilt nur für Service-Tickets. Das Ticket-Plugin muss installiert sein.",
65-
"services-by-agent": "Por agente",
66-
"services-by-assigned": "Por asignado",
67-
"services-by-client": "Por cliente",
68-
"services-by-month": "Servicios por mes (últimos 12 meses)",
69-
"services-by-nick": "Por usuario creador",
70-
"services-by-status": "Por estado",
71-
"services-by-year": "Servicios por año",
65+
"services-by-agent": "Nach Agenten",
66+
"services-by-assigned": "Nach Zuständigkeit",
67+
"services-by-client": "Nach Kunden",
68+
"services-by-month": "Dienstleistungen pro Monat (letzte 12 Monate)",
69+
"services-by-nick": "Nach Ersteller",
70+
"services-by-status": "Nach Status",
71+
"services-by-year": "Dienstleistungen pro Jahr",
7272
"ticket-footer-text": "Text der Fußzeile des Tickets",
73-
"total-net": "Neto total",
73+
"total-net": "Gesamtnettobetrag",
7474
"total-services": "Total de servicios",
7575
"verifications": "Überprüfungen"
7676
}

Translation/en_EN.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"notify-customer": "Notify customer",
4848
"notify-user": "Notify user",
4949
"open-services": "open",
50-
"open-services-last-month": "Abiertos último mes",
51-
"open-services-last-year": "Abiertos último año",
52-
"open-services-total": "Servicios abiertos",
50+
"open-services-last-month": "Open services last month",
51+
"open-services-last-year": "Open services last year",
52+
"open-services-total": "Open services",
5353
"print-agent": "Print agent",
5454
"print-assigned": "Print assigned",
5555
"print-description": "Print description",
@@ -62,15 +62,15 @@
6262
"print-services": "Print services",
6363
"print-solution": "Print solution",
6464
"print-ticket-desc": "This setting will only apply to service tickets. It is necessary to have the Tickets plugin installed.",
65-
"services-by-agent": "Por agente",
66-
"services-by-assigned": "Por asignado",
67-
"services-by-client": "Por cliente",
68-
"services-by-month": "Servicios por mes (últimos 12 meses)",
69-
"services-by-nick": "Por usuario creador",
70-
"services-by-status": "Por estado",
71-
"services-by-year": "Servicios por año",
65+
"services-by-agent": "By agent",
66+
"services-by-assigned": "By assignee",
67+
"services-by-client": "By client",
68+
"services-by-month": "Services by month (last 12 months)",
69+
"services-by-nick": "By creating user",
70+
"services-by-status": "By status",
71+
"services-by-year": "Services by year",
7272
"ticket-footer-text": "Ticket footer text",
73-
"total-net": "Neto total",
74-
"total-services": "Total de servicios",
73+
"total-net": "Net total",
74+
"total-services": "Total services",
7575
"verifications": "Verifications"
7676
}

Translation/eu_ES.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
"notify-user": "Erabiltzaileari jakinarazi",
4949
"open-services": "Abiertos",
5050
"open-services-last-month": "Abiertos último mes",
51-
"open-services-last-year": "Abiertos último año",
52-
"open-services-total": "Servicios abiertos",
51+
"open-services-last-year": "Azken urtean irekita",
52+
"open-services-total": "Irekitako zerbitzuak",
5353
"print-agent": "Agentearen inprimaketa",
5454
"print-assigned": "Inprimatu izendatuta",
5555
"print-description": "Deskribapena inprimatu",
5656
"print-machine-info": "Makinaren informazioa inprimatu",
57-
"print-materials": "Imprimir materiales",
57+
"print-materials": "Materialak inprimatu",
5858
"print-observations": "Oharrak inprimatu",
5959
"print-pdf": "PDF inprimatu",
6060
"print-pdf-desc": "Konfigurazio honek zerbitzuko PDF-etan bakarrik aplikatuko da. Core-ko pdf-a edo PlantillasPDF plugin-a erabil dezakezu.",
@@ -64,7 +64,7 @@
6464
"print-ticket-desc": "Konfigurazio honek zerbitzuko tiketetan bakarrik aplikatuko da. Tiketak plugin-a instalatuta izan behar du.",
6565
"services-by-agent": "Por agente",
6666
"services-by-assigned": "Por asignado",
67-
"services-by-client": "Por cliente",
67+
"services-by-client": "Bezeroaren arabera",
6868
"services-by-month": "Servicios por mes (últimos 12 meses)",
6969
"services-by-nick": "Por usuario creador",
7070
"services-by-status": "Por estado",

Translation/fr_FR.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"notify-customer": "Notification au client",
4848
"notify-user": "Notification à l'utilisateur",
4949
"open-services": "ouvrir",
50-
"open-services-last-month": "Abiertos último mes",
51-
"open-services-last-year": "Abiertos último año",
52-
"open-services-total": "Servicios abiertos",
50+
"open-services-last-month": "Services ouverts le mois dernier",
51+
"open-services-last-year": "Services ouverts l'année dernière",
52+
"open-services-total": "Services ouverts",
5353
"print-agent": "Imprimer l'agent",
5454
"print-assigned": "Imprimer assigné",
5555
"print-description": "Imprimer la description",
@@ -62,15 +62,15 @@
6262
"print-services": "Imprimer les services",
6363
"print-solution": "Imprimer la solution",
6464
"print-ticket-desc": "Cette configuration ne s'appliquera qu'aux tickets de service. Il est nécessaire d'avoir le plugin Tickets installé.",
65-
"services-by-agent": "Por agente",
66-
"services-by-assigned": "Por asignado",
67-
"services-by-client": "Por cliente",
68-
"services-by-month": "Servicios por mes (últimos 12 meses)",
69-
"services-by-nick": "Por usuario creador",
70-
"services-by-status": "Por estado",
71-
"services-by-year": "Servicios por año",
65+
"services-by-agent": "Par agent",
66+
"services-by-assigned": "Par affectation",
67+
"services-by-client": "Par client",
68+
"services-by-month": "Services par mois (12 derniers mois)",
69+
"services-by-nick": "Par utilisateur créateur",
70+
"services-by-status": "Par statut",
71+
"services-by-year": "Services par année",
7272
"ticket-footer-text": "Texte du pied de ticket",
73-
"total-net": "Neto total",
74-
"total-services": "Total de servicios",
73+
"total-net": "Total net",
74+
"total-services": "Total des services",
7575
"verifications": "Vérifications"
7676
}

0 commit comments

Comments
 (0)