2023-08-08 23:53:49 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Service\Venta;
|
|
|
|
|
2023-12-20 08:44:49 -03:00
|
|
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Repository;
|
|
|
|
use Incoviba\Model;
|
|
|
|
|
|
|
|
class Pie
|
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
protected Repository\Venta\Pie $pieRepository,
|
2023-12-20 08:44:49 -03:00
|
|
|
protected Cuota $cuotaService,
|
|
|
|
protected Pago $pagoService
|
2023-08-08 23:53:49 -04:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public function getById(int $pie_id): Model\Venta\Pie
|
|
|
|
{
|
2023-12-20 08:44:49 -03:00
|
|
|
return $this->process($this->pieRepository->fetchById($pie_id));
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
2024-03-13 14:38:44 -03:00
|
|
|
public function getByVenta(int $venta_id): Model\Venta\Pie
|
|
|
|
{
|
|
|
|
return $this->process($this->pieRepository->fetchByVenta($venta_id));
|
|
|
|
}
|
2023-09-13 18:51:46 -03:00
|
|
|
|
|
|
|
public function add(array $data): Model\Venta\Pie
|
|
|
|
{
|
|
|
|
$pie = $this->pieRepository->create($data);
|
|
|
|
return $this->pieRepository->save($pie);
|
|
|
|
}
|
|
|
|
public function addCuota(array $data): Model\Venta\Cuota
|
|
|
|
{
|
|
|
|
return $this->cuotaService->add($data);
|
|
|
|
}
|
2023-11-29 22:21:46 -03:00
|
|
|
public function edit(Model\Venta\Pie $pie, array $data): Model\Venta\Pie
|
|
|
|
{
|
|
|
|
return $this->pieRepository->edit($pie, $data);
|
|
|
|
}
|
2023-12-20 08:44:49 -03:00
|
|
|
public function reajustar(Model\Venta\Pie $pie, array $data): Model\Venta\Pie
|
|
|
|
{
|
|
|
|
$pago = $this->pagoService->add($data);
|
|
|
|
return $this->pieRepository->edit($pie, ['reajuste' => $pago->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function process(Model\Venta\Pie $pie): Model\Venta\Pie
|
|
|
|
{
|
2023-12-20 15:37:47 -03:00
|
|
|
$pie->cuotasArray = $this->cuotaService->getByPie($pie->id);
|
2023-12-20 08:44:49 -03:00
|
|
|
try {
|
|
|
|
$pie->asociados = $this->pieRepository->fetchAsociados($pie->id);
|
|
|
|
} catch (EmptyResult) {}
|
|
|
|
return $pie;
|
|
|
|
}
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|