2020namespace FacturaScripts \Plugins \Informes \Controller ;
2121
2222use FacturaScripts \Core \Base \Controller ;
23+ use FacturaScripts \Core \Plugins ;
2324use FacturaScripts \Plugins \Informes \Model \Report ;
2425
2526class ReportAgentes extends Controller
@@ -30,6 +31,21 @@ class ReportAgentes extends Controller
3031 /** @var Report gráfica de albaranes por agente */
3132 public $ albaranes ;
3233
34+ /** @var Report gráfica de comisiones por mes */
35+ public $ comisionesByMonth ;
36+
37+ /** @var Report gráfica de comisiones por año */
38+ public $ comisionesByYear ;
39+
40+ /** @var bool indica si el plugin Comisiones está activo */
41+ public $ comisionesEnabled = false ;
42+
43+ /** @var Report gráfica de liquidaciones por mes */
44+ public $ liquidacionesByMonth ;
45+
46+ /** @var Report gráfica de liquidaciones por año */
47+ public $ liquidacionesByYear ;
48+
3349 /** @var Report gráfica de albaranes por mes (último año) */
3450 public $ albaranesByMonth ;
3551
@@ -76,6 +92,8 @@ public function privateCore(&$response, $user, $permissions)
7692 {
7793 parent ::privateCore ($ response , $ user , $ permissions );
7894
95+ $ this ->comisionesEnabled = Plugins::isEnabled ('Comisiones ' );
96+
7997 $ this ->loadAgentes ();
8098 $ this ->loadAlbaranes ();
8199 $ this ->loadAlbaranesByMonth ();
@@ -89,6 +107,13 @@ public function privateCore(&$response, $user, $permissions)
89107 $ this ->loadPresupuestos ();
90108 $ this ->loadPresupuestosByMonth ();
91109 $ this ->loadPresupuestosByYear ();
110+
111+ if ($ this ->comisionesEnabled ) {
112+ $ this ->loadComisionesByMonth ();
113+ $ this ->loadComisionesByYear ();
114+ $ this ->loadLiquidacionesByMonth ();
115+ $ this ->loadLiquidacionesByYear ();
116+ }
92117 }
93118
94119 protected function loadAgentes (): void
@@ -145,6 +170,68 @@ protected function loadAlbaranesByYear(): void
145170 $ this ->albaranesByYear = $ report ;
146171 }
147172
173+ protected function loadComisionesByMonth (): void
174+ {
175+ $ report = new Report ();
176+ $ report ->type = Report::TYPE_BAR ;
177+ $ report ->table = 'facturascli ' ;
178+ $ report ->xcolumn = 'fecha ' ;
179+ $ report ->ycolumn = 'totalcomision ' ;
180+ $ report ->xoperation = 'MONTHS ' ;
181+ $ report ->yoperation = 'SUM ' ;
182+ $ report ->addFieldXName ('' );
183+ $ report ->addCustomFilter ('fecha ' , '>= ' , '{-1 year} ' );
184+ $ report ->addCustomFilter ('fecha ' , '<= ' , '{today} ' );
185+ $ report ->addCustomFilter ('codagente ' , 'IS NOT NULL ' , '' );
186+
187+ $ this ->comisionesByMonth = $ report ;
188+ }
189+
190+ protected function loadComisionesByYear (): void
191+ {
192+ $ report = new Report ();
193+ $ report ->type = Report::TYPE_BAR ;
194+ $ report ->table = 'facturascli ' ;
195+ $ report ->xcolumn = 'fecha ' ;
196+ $ report ->ycolumn = 'totalcomision ' ;
197+ $ report ->xoperation = 'YEAR ' ;
198+ $ report ->yoperation = 'SUM ' ;
199+ $ report ->addFieldXName ('' );
200+ $ report ->addCustomFilter ('codagente ' , 'IS NOT NULL ' , '' );
201+
202+ $ this ->comisionesByYear = $ report ;
203+ }
204+
205+ protected function loadLiquidacionesByMonth (): void
206+ {
207+ $ report = new Report ();
208+ $ report ->type = Report::TYPE_BAR ;
209+ $ report ->table = 'liquidacionescomisiones ' ;
210+ $ report ->xcolumn = 'fecha ' ;
211+ $ report ->ycolumn = 'total ' ;
212+ $ report ->xoperation = 'MONTHS ' ;
213+ $ report ->yoperation = 'SUM ' ;
214+ $ report ->addFieldXName ('' );
215+ $ report ->addCustomFilter ('fecha ' , '>= ' , '{-1 year} ' );
216+ $ report ->addCustomFilter ('fecha ' , '<= ' , '{today} ' );
217+
218+ $ this ->liquidacionesByMonth = $ report ;
219+ }
220+
221+ protected function loadLiquidacionesByYear (): void
222+ {
223+ $ report = new Report ();
224+ $ report ->type = Report::TYPE_BAR ;
225+ $ report ->table = 'liquidacionescomisiones ' ;
226+ $ report ->xcolumn = 'fecha ' ;
227+ $ report ->ycolumn = 'total ' ;
228+ $ report ->xoperation = 'YEAR ' ;
229+ $ report ->yoperation = 'SUM ' ;
230+ $ report ->addFieldXName ('' );
231+
232+ $ this ->liquidacionesByYear = $ report ;
233+ }
234+
148235 protected function loadFacturas (): void
149236 {
150237 $ report = new Report ();
0 commit comments