feature/cierres (#25)

Varios cambios

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #25
This commit is contained in:
2025-07-22 13:18:00 +00:00
parent ba57cad514
commit 307f2ac7d7
418 changed files with 20045 additions and 984 deletions

View File

@ -1,12 +1,15 @@
<?php
namespace Incoviba\Service\Venta;
use PDOException;
use DateTimeImmutable;
use DateInterval;
use Incoviba\Common\Implement\Exception\EmptyResult;
use IntlDateFormatter;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Model;
@ -21,6 +24,20 @@ class Cuota extends Ideal\Service
parent::__construct($logger);
}
/**
* @param int $cuota_id
* @return Model\Venta\Cuota
* @throws Read
*/
public function getById(int $cuota_id): Model\Venta\Cuota
{
try {
return $this->process($this->cuotaRepository->fetchById($cuota_id));
} catch (EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
}
public function pendientes(): array
{
$cuotas = $this->cuotaRepository->fetchPendientes();
@ -92,9 +109,18 @@ class Cuota extends Ideal\Service
return $this->cuotaRepository->fetchVigenteByPie($pie_id);
}
/**
* @param array $data
* @return Model\Venta\Cuota
* @throws Create
*/
public function add(array $data): Model\Venta\Cuota
{
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque');
try {
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque');
} catch (EmptyResult $exception) {
throw new Create(__CLASS__, $exception);
}
$fields = array_flip([
'fecha',
'banco',
@ -112,8 +138,16 @@ class Cuota extends Ideal\Service
$mapped_data = $filtered_data;
$mapped_data['valor_$'] = $mapped_data['valor'];
unset($mapped_data['valor']);
$cuota = $this->cuotaRepository->create($mapped_data);
$this->cuotaRepository->save($cuota);
try {
$cuota = $this->cuotaRepository->create($mapped_data);
return $this->cuotaRepository->save($cuota);
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);
}
}
protected function process(Model\Venta\Cuota $cuota): Model\Venta\Cuota
{
return $cuota;
}
}