Agregar Pie

This commit is contained in:
Juan Pablo Vial
2025-03-26 16:41:54 -03:00
parent 4ce83fb270
commit db36549699
8 changed files with 195 additions and 44 deletions

View File

@ -1,17 +1,22 @@
<?php
namespace Incoviba\Service\Venta;
use PDOException;
use DateTimeImmutable;
use DateMalformedStringException;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Exception\ServiceAction\{Create, Read};
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service\UF;
class Pie
{
public function __construct(
protected Repository\Venta\Pie $pieRepository,
protected Cuota $cuotaService,
protected Pago $pagoService
protected Pago $pagoService,
protected UF $ufService
) {}
public function getById(int $pie_id): Model\Venta\Pie
@ -27,11 +32,26 @@ class Pie
}
}
/**
* @param array $data
* @return Model\Venta\Pie
* @throws Create
*/
public function add(array $data): Model\Venta\Pie
{
$filteredData = $this->pieRepository->filterData($data);
$pie = $this->pieRepository->create($filteredData);
return $this->pieRepository->save($pie);
try {
$filteredData = $this->pieRepository->filterData($data);
if (!isset($filteredData['uf'])) {
try {
$date = new DateTimeImmutable($filteredData['fecha']);
$filteredData['uf'] = $this->ufService->get($date);
} catch (DateMalformedStringException) {}
}
$pie = $this->pieRepository->create($filteredData);
return $this->pieRepository->save($pie);
} catch (PDOException $exception) {
throw new Create(__CLASS__, $exception);
}
}
public function addCuota(array $data): Model\Venta\Cuota
{