FormaPago Service
This commit is contained in:
@ -6,7 +6,6 @@ use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use PhpParser\Node\Expr\AssignOp\Mod;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Venta extends Service
|
||||
@ -20,6 +19,7 @@ class Venta extends Service
|
||||
protected Repository\Venta\Escritura $escrituraRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Venta\FormaPago $formaPagoService,
|
||||
protected Venta\Propietario $propietarioService,
|
||||
protected Venta\Propiedad $propiedadService,
|
||||
protected Venta\Pie $pieService,
|
||||
@ -82,6 +82,9 @@ class Venta extends Service
|
||||
|
||||
protected function process(Model\Venta $venta): Model\Venta
|
||||
{
|
||||
$venta->addFactory('formaPago', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->formaPagoService, 'getByVenta'])
|
||||
->setArgs(['venta_id' => $venta->id]));
|
||||
$venta->addFactory('estados', (new Implement\Repository\Factory())
|
||||
->setCallable([$this->estadoVentaRepository, 'fetchByVenta'])
|
||||
->setArgs([$venta->id]));
|
||||
@ -231,7 +234,8 @@ class Venta extends Service
|
||||
}
|
||||
protected function addFormaPago(array $data): Model\Venta\FormaPago
|
||||
{
|
||||
$fields = [
|
||||
return $this->formaPagoService->add($data);
|
||||
/*$fields = [
|
||||
'pie',
|
||||
'subsidio',
|
||||
'credito',
|
||||
@ -245,9 +249,9 @@ class Venta extends Service
|
||||
$forma_pago->{$name} = $obj;
|
||||
}
|
||||
}
|
||||
return $forma_pago;
|
||||
return $forma_pago;*/
|
||||
}
|
||||
protected function addPie(array $data): Model\Venta\Pie
|
||||
/*protected function addPie(array $data): Model\Venta\Pie
|
||||
{
|
||||
$fields = array_fill_keys([
|
||||
'fecha_venta',
|
||||
@ -309,7 +313,7 @@ class Venta extends Service
|
||||
'valor'
|
||||
], $filtered_data);
|
||||
return $this->bonoPieService->add($mapped_data);
|
||||
}
|
||||
}*/
|
||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
|
@ -12,4 +12,8 @@ class BonoPie
|
||||
{
|
||||
return new Model\Venta\BonoPie();
|
||||
}
|
||||
public function getByVenta(int $venta_id): Model\Venta\BonoPie
|
||||
{
|
||||
return $this->bonoPieRepository->fetchByVenta($venta_id);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,11 @@ class Credito extends Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByVenta(int $venta_id): Model\Venta\Credito
|
||||
{
|
||||
return $this->creditoRepository->fetchByVenta($venta_id);
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Credito
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
|
143
app/src/Service/Venta/FormaPago.php
Normal file
143
app/src/Service/Venta/FormaPago.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class FormaPago extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Pie $pieService,
|
||||
protected BonoPie $bonoPieService,
|
||||
protected Credito $creditoService,
|
||||
protected Repository\Venta\Escritura $escrituraRepository,
|
||||
protected Subsidio $subsidioService,
|
||||
protected Pago $pagoService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByVenta(int $venta_id): Model\Venta\FormaPago
|
||||
{
|
||||
$formaPago = new Model\Venta\FormaPago();
|
||||
try {
|
||||
$formaPago->pie = $this->pieService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
$formaPago->bonoPie = $this->bonoPieService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
$formaPago->credito = $this->creditoService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
$formaPago->escritura = $this->escrituraRepository->fetchByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
$formaPago->subsidio = $this->subsidioService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
$formaPago->devolucion = $this->pagoService->getDevolucionByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
|
||||
return $formaPago;
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\FormaPago
|
||||
{
|
||||
$fields = [
|
||||
'pie',
|
||||
'subsidio',
|
||||
'credito',
|
||||
'bono_pie'
|
||||
];
|
||||
$forma_pago = new Model\Venta\FormaPago();
|
||||
foreach ($fields as $name) {
|
||||
if (isset($data["has_{$name}"])) {
|
||||
try {
|
||||
$method = 'add' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
|
||||
$obj = $this->{$method}($data);
|
||||
$forma_pago->{$name} = $obj;
|
||||
} catch (\Error $error) {
|
||||
$this->logger->critical($error);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $forma_pago;
|
||||
}
|
||||
|
||||
protected function addPie(array $data): Model\Venta\Pie
|
||||
{
|
||||
$fields = array_fill_keys([
|
||||
'fecha_venta',
|
||||
'pie',
|
||||
'cuotas',
|
||||
'uf'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$this->logger->critical(var_export($filtered_data,true));
|
||||
$mapped_data = array_combine([
|
||||
'fecha',
|
||||
'valor',
|
||||
'cuotas',
|
||||
'uf'
|
||||
], $filtered_data);
|
||||
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
|
||||
return $this->pieService->add($mapped_data);
|
||||
}
|
||||
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
||||
{
|
||||
$fields = array_fill_keys([
|
||||
'fecha_venta',
|
||||
'ahorro',
|
||||
'subsidio',
|
||||
'uf'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$mapped_data = array_combine([
|
||||
'fecha',
|
||||
'ahorro',
|
||||
'subsidio',
|
||||
'uf'
|
||||
], $filtered_data);
|
||||
return $this->subsidioService->add($mapped_data);
|
||||
}
|
||||
protected function addCredito(array $data): Model\Venta\Credito
|
||||
{
|
||||
$fields = array_fill_keys([
|
||||
'fecha_venta',
|
||||
'credito',
|
||||
'uf'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$mapped_data = array_combine([
|
||||
'fecha',
|
||||
'valor',
|
||||
'uf'
|
||||
], $filtered_data);
|
||||
return $this->creditoService->add($mapped_data);
|
||||
}
|
||||
protected function addBonoPie(array $data): Model\Venta\BonoPie
|
||||
{
|
||||
$fields = array_fill_keys([
|
||||
'fecha_venta',
|
||||
'bono_pie'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$mapped_data = array_combine([
|
||||
'fecha',
|
||||
'valor'
|
||||
], $filtered_data);
|
||||
return $this->bonoPieService->add($mapped_data);
|
||||
}
|
||||
|
||||
protected function cleanValue($value): float
|
||||
{
|
||||
if ((float) $value == $value) {
|
||||
return (float) $value;
|
||||
}
|
||||
return (float) str_replace(['.', ','], ['', '.'], $value);
|
||||
}
|
||||
}
|
@ -109,6 +109,10 @@ class Pago
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getDevolucionByVenta(int $venta_id): Model\Venta\Pago
|
||||
{
|
||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
{
|
||||
|
@ -17,6 +17,10 @@ class Pie
|
||||
{
|
||||
return $this->process($this->pieRepository->fetchById($pie_id));
|
||||
}
|
||||
public function getByVenta(int $venta_id): Model\Venta\Pie
|
||||
{
|
||||
return $this->process($this->pieRepository->fetchByVenta($venta_id));
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Pie
|
||||
{
|
||||
|
@ -17,6 +17,11 @@ class Subsidio
|
||||
protected Service\Money $moneyService
|
||||
) {}
|
||||
|
||||
public function getByVenta(int $venta_id): Model\Venta\Subsidio
|
||||
{
|
||||
return $this->subsidioRepository->fetchByVenta($venta_id);
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Subsidio
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
|
Reference in New Issue
Block a user