@@ -36,6 +36,7 @@ protected function getFields(): array
3636 {
3737 return [
3838 'codsubcuenta ' => 'partidas.codsubcuenta ' ,
39+ 'idsubcuenta ' => 'partidas.idsubcuenta ' ,
3940 'iva ' => 'COALESCE(partidas.iva, 0) ' ,
4041 'recargo ' => 'COALESCE(partidas.recargo, 0) ' ,
4142
@@ -44,10 +45,10 @@ protected function getFields(): array
4445 'codcuentaesp ' => 'COALESCE(subcuentas.codcuentaesp, cuentas.codcuentaesp) ' ,
4546 'tipo_desc ' => 'cuentasesp.descripcion ' ,
4647
47- 'baseimponible ' => ' ROUND(SUM( partidas.baseimponible), 2) ' ,
48- 'debe ' => ' ROUND(SUM( partidas.debe), 2) ' ,
49- 'haber ' => ' ROUND(SUM( partidas.haber), 2) ' ,
50- 'cuota ' => ' ROUND(SUM( ' . $ this ->sqlForCuota () . ' ), 2) ' ,
48+ 'baseimponible ' => $ this -> sqlForRoundedSum ( ' partidas.baseimponible ' ) ,
49+ 'debe ' => $ this -> sqlForRoundedSum ( ' partidas.debe ' ) ,
50+ 'haber ' => $ this -> sqlForRoundedSum ( ' partidas.haber ' ) ,
51+ 'cuota ' => $ this -> sqlForRoundedSum ( $ this ->sqlForCuota ()) ,
5152 ];
5253 }
5354
@@ -59,6 +60,7 @@ protected function getFields(): array
5960 protected function getGroupFields (): string
6061 {
6162 return 'partidas.codsubcuenta '
63+ . ', partidas.idsubcuenta '
6264 . ', partidas.iva '
6365 . ', partidas.recargo '
6466 . ', subcuentas.descripcion '
@@ -98,6 +100,19 @@ protected function getTables(): array
98100 ];
99101 }
100102
103+ /**
104+ * Assign derived compatibility fields used by existing consumers.
105+ *
106+ * @param array $data
107+ */
108+ protected function loadFromData (array $ data )
109+ {
110+ parent ::loadFromData ($ data );
111+
112+ $ this ->cuotaiva = $ this ->codcuentaesp === 'IVARRE ' ? 0.0 : (float )$ this ->cuota ;
113+ $ this ->cuotarecargo = $ this ->codcuentaesp === 'IVARRE ' ? (float )$ this ->cuota : 0.0 ;
114+ }
115+
101116 /**
102117 * SQL snippet to calculate the cuota field.
103118 *
@@ -110,4 +125,16 @@ private function sqlForCuota(): string
110125 ELSE partidas.debe + partidas.haber
111126 END ' ;
112127 }
128+
129+ /**
130+ * SQL snippet to round aggregated amounts on PostgreSQL and MySQL.
131+ *
132+ * @param string $field
133+ *
134+ * @return string
135+ */
136+ private function sqlForRoundedSum (string $ field ): string
137+ {
138+ return 'ROUND(CAST(SUM( ' . $ field . ') AS DECIMAL(20, 6)), 2) ' ;
139+ }
113140}
0 commit comments