From 7cc0333876af5c8dad6f63eea118c1be2af938fb Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Wed, 20 Mar 2024 20:22:54 -0300 Subject: [PATCH] Informe tesoreria busca ultima cartola ingresada --- app/src/Repository/Cartola.php | 10 ++++++++++ app/src/Service/Contabilidad/Informe/Tesoreria.php | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/Repository/Cartola.php b/app/src/Repository/Cartola.php index 23e9cc1..4271ad7 100644 --- a/app/src/Repository/Cartola.php +++ b/app/src/Repository/Cartola.php @@ -65,4 +65,14 @@ class Cartola extends Ideal\Repository ->where('cuenta_id = ? AND fecha = ?'); return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]); } + public function fetchLastByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Cartola + { + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where('cuenta_id = ? AND fecha <= ?') + ->order('fecha DESC') + ->limit(1); + return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]); + } } diff --git a/app/src/Service/Contabilidad/Informe/Tesoreria.php b/app/src/Service/Contabilidad/Informe/Tesoreria.php index 63ff55c..f6d85e6 100644 --- a/app/src/Service/Contabilidad/Informe/Tesoreria.php +++ b/app/src/Service/Contabilidad/Informe/Tesoreria.php @@ -228,12 +228,14 @@ class Tesoreria extends Ideal\Service } } } catch (Implement\Exception\EmptyResult) {} + $anterior = $this->getAnterior($fecha); try { - $cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha); + $cartola = $this->cartolaRepository->fetchLastByCuentaAndFecha($cuenta->id, $fecha); $data->actual = $cartola->saldo; + //$anterior = $this->getAnterior($cartola->fecha); } catch (Implement\Exception\EmptyResult) {} try { - $cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $this->getAnterior($fecha)); + $cartola = $this->cartolaRepository->fetchLastByCuentaAndFecha($cuenta->id, $anterior); $data->anterior = $cartola->saldo; } catch (Implement\Exception\EmptyResult) {} if ($data->diferencia() !== 0) { @@ -289,5 +291,4 @@ class Tesoreria extends Ideal\Service $this->totales->{$tipo} += $total; return $this; } - }