Skip to content

Commit 016e7ea

Browse files
committed
Soluciona resultado en balance de cierre
1 parent aee6ccb commit 016e7ea

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

Lib/Accounting/BalanceSheet.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,19 @@ protected function formatValue(string $value, string $type = 'money', bool $bold
200200

201201
protected function getAccountAmounts(BalanceCode $balance, BalanceAccount $model, string $codejercicio, array $params): float
202202
{
203-
$key = $codejercicio . '-' . $model->codcuenta;
203+
$key = $codejercicio . '-' . $balance->id . '-' . $model->codcuenta;
204204
if (array_key_exists($key, $this->amounts)) {
205205
return $this->amounts[$key];
206206
}
207207

208+
if ($model->codcuenta === '129') {
209+
$total = $this->getRegularizationResult($balance, $model, $codejercicio, $params);
210+
if ($total !== null) {
211+
$this->amounts[$key] = $total;
212+
return $total;
213+
}
214+
}
215+
208216
$total = 0.00;
209217
$sql = "SELECT SUM(partidas.debe) AS debe, SUM(partidas.haber) AS haber"
210218
. " FROM partidas"
@@ -247,6 +255,41 @@ protected function getAccountAmounts(BalanceCode $balance, BalanceAccount $model
247255
return $total;
248256
}
249257

258+
protected function getRegularizationResult(
259+
BalanceCode $balance,
260+
BalanceAccount $model,
261+
string $codejercicio,
262+
array $params
263+
): ?float {
264+
$sql = "SELECT SUM(partidas.debe) AS debe, SUM(partidas.haber) AS haber"
265+
. " FROM partidas"
266+
. " LEFT JOIN asientos ON partidas.idasiento = asientos.idasiento"
267+
. " WHERE asientos.codejercicio = " . $this->dataBase->var2str($codejercicio)
268+
. " AND partidas.codsubcuenta LIKE '" . $model->codcuenta . "%'"
269+
. " AND asientos.operacion = " . $this->dataBase->var2str(Asiento::OPERATION_REGULARIZATION);
270+
271+
if ($codejercicio === $this->exercise->codejercicio) {
272+
$sql .= ' AND asientos.fecha BETWEEN ' . $this->dataBase->var2str($this->dateFrom)
273+
. ' AND ' . $this->dataBase->var2str($this->dateTo);
274+
} elseif ($codejercicio === $this->exercisePrev->codejercicio) {
275+
$sql .= ' AND asientos.fecha BETWEEN ' . $this->dataBase->var2str($this->dateFromPrev)
276+
. ' AND ' . $this->dataBase->var2str($this->dateToPrev);
277+
}
278+
279+
$channel = $params['channel'] ?? '';
280+
if (!empty($channel)) {
281+
$sql .= ' AND asientos.canal = ' . $this->dataBase->var2str($channel);
282+
}
283+
284+
foreach ($this->dataBase->select($sql) as $row) {
285+
$debe = (float)$row['debe'];
286+
$haber = (float)$row['haber'];
287+
return empty($debe) && empty($haber) ? null : $balance->calculate($debe, $haber);
288+
}
289+
290+
return null;
291+
}
292+
250293
protected function getAmounts(BalanceCode $balance, string $codejercicio, array $params): float
251294
{
252295
$total = 0.00;

facturascripts.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = 'Informes'
22
description = 'Muestras informes de resultados anual, tesorería y desgloses de compras y ventas.'
3-
version = 3.92
3+
version = 3.93
44
min_version = 2025.6
5-
compatible = 'Modelo303,Modelo115,Modelo111,CRM'
5+
compatible = 'Modelo303,Modelo115,Modelo111,CRM'

0 commit comments

Comments
 (0)