Informe tesoreria busca ultima cartola ingresada

This commit is contained in:
Juan Pablo Vial
2024-03-20 20:22:54 -03:00
parent eb38236926
commit 7cc0333876
2 changed files with 14 additions and 3 deletions

View File

@ -65,4 +65,14 @@ class Cartola extends Ideal\Repository
->where('cuenta_id = ? AND fecha = ?'); ->where('cuenta_id = ? AND fecha = ?');
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]); 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')]);
}
} }

View File

@ -228,12 +228,14 @@ class Tesoreria extends Ideal\Service
} }
} }
} catch (Implement\Exception\EmptyResult) {} } catch (Implement\Exception\EmptyResult) {}
$anterior = $this->getAnterior($fecha);
try { try {
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha); $cartola = $this->cartolaRepository->fetchLastByCuentaAndFecha($cuenta->id, $fecha);
$data->actual = $cartola->saldo; $data->actual = $cartola->saldo;
//$anterior = $this->getAnterior($cartola->fecha);
} catch (Implement\Exception\EmptyResult) {} } catch (Implement\Exception\EmptyResult) {}
try { try {
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $this->getAnterior($fecha)); $cartola = $this->cartolaRepository->fetchLastByCuentaAndFecha($cuenta->id, $anterior);
$data->anterior = $cartola->saldo; $data->anterior = $cartola->saldo;
} catch (Implement\Exception\EmptyResult) {} } catch (Implement\Exception\EmptyResult) {}
if ($data->diferencia() !== 0) { if ($data->diferencia() !== 0) {
@ -289,5 +291,4 @@ class Tesoreria extends Ideal\Service
$this->totales->{$tipo} += $total; $this->totales->{$tipo} += $total;
return $this; return $this;
} }
} }