Proveedores en movimientos
This commit is contained in:
@ -2,8 +2,10 @@
|
||||
namespace Incoviba\Service\Contabilidad;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -13,7 +15,7 @@ class Movimiento extends Service
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||
protected Repository\Contabilidad\Movimiento\Detalle $detalleRepository,
|
||||
protected Movimiento\Auxiliar $auxiliarService)
|
||||
protected Movimiento\Detalle $detalleService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -76,12 +78,20 @@ class Movimiento extends Service
|
||||
$this->movimientoRepository->remove($movimiento);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function findRut(int $rut): Define\Model
|
||||
{
|
||||
return $this->detalleService->findRut($rut);
|
||||
}
|
||||
|
||||
public function process(Model\Contabilidad\Movimiento $movimiento): Model\Contabilidad\Movimiento
|
||||
{
|
||||
$movimiento->addFactory('detalles', (new Implement\Repository\Factory())
|
||||
->setCallable(function(int $movimiento_id) {
|
||||
try {
|
||||
return $this->detalleRepository->fetchByMovimiento($movimiento_id);
|
||||
return $this->detalleService->getByMovimiento($movimiento_id);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad\Movimiento;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Auxiliar extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Contabilidad\Movimiento\Auxiliar $auxiliarRepository,
|
||||
protected Repository\Contabilidad\Movimiento\Auxiliar\Detalle $detalleRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByMovimiento(int $movimiento_id): ?array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->auxiliarRepository->fetchByMovimiento($movimiento_id));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Contabilidad\Movimiento\Auxiliar $auxiliar): Model\Contabilidad\Movimiento\Auxiliar
|
||||
{
|
||||
$auxiliar->addFactory('detalles', (new Implement\Repository\Factory())
|
||||
->setCallable(function(int $auxiliar_id) {
|
||||
try {
|
||||
return $this->detalleRepository->fetchByAuxiliar($auxiliar_id);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
->setArgs(['auxiliar_id' => $auxiliar->id]));
|
||||
return $auxiliar;
|
||||
}
|
||||
}
|
63
app/src/Service/Contabilidad/Movimiento/Detalle.php
Normal file
63
app/src/Service/Contabilidad/Movimiento/Detalle.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad\Movimiento;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Detalle extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Contabilidad\Movimiento\Detalle $detalleRepository,
|
||||
protected Repository\Venta\Propietario $propietarioRepository,
|
||||
protected Repository\Inmobiliaria\Proveedor $proveedorRepository,
|
||||
protected Repository\Inmobiliaria $inmobiliariaRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getByMovimiento(int $movimiento_id): ?Model\Contabilidad\Movimiento\Detalle
|
||||
{
|
||||
try {
|
||||
return $this->process($this->detalleRepository->fetchByMovimiento($movimiento_id));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function findRut(int $rut): Define\Model
|
||||
{
|
||||
try {
|
||||
return $this->inmobiliariaRepository->fetchById($rut);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
return $this->proveedorRepository->fetchById($rut);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
return $this->propietarioRepository->fetchById($rut);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
|
||||
throw new Implement\Exception\EmptyResult("{$rut} no encontrado.");
|
||||
}
|
||||
|
||||
protected function process(Model\Contabilidad\Movimiento\Detalle $detalle): Model\Contabilidad\Movimiento\Detalle
|
||||
{
|
||||
if (empty($detalle->rut)) {
|
||||
return $detalle;
|
||||
}
|
||||
|
||||
try {
|
||||
$detalle->relacionado = $this->findRut($detalle->rut);
|
||||
$detalle->relacionadoType = strtolower(last(explode('\\', get_class($detalle->relacionado))));
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
|
||||
return $detalle;
|
||||
}
|
||||
}
|
@ -42,14 +42,16 @@ class Proveedor extends Ideal\Service
|
||||
$filteredData = $this->proveedorRepository->filterData($data);
|
||||
try {
|
||||
$proveedor = $this->process($this->proveedorRepository->fetchByNombre($filteredData['nombre']));
|
||||
if ($proveedor->contacto->rut !== $data['contacto']['rut']) {
|
||||
if (!empty($data['contacto']['rut']) and $proveedor->contacto->rut !== $data['contacto']['rut']) {
|
||||
$contacto = $this->contactoService->add($data['contacto']);
|
||||
return $this->proveedorRepository->edit($proveedor, ['contacto_rut' => $contacto->rut]);
|
||||
}
|
||||
return $proveedor;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$contacto = $this->contactoService->add($data['contacto']);
|
||||
$filteredData['contacto_rut'] = $contacto->rut;
|
||||
if (!empty($data['contacto']['rut'])) {
|
||||
$contacto = $this->contactoService->add($data['contacto']);
|
||||
$filteredData['contacto_rut'] = $contacto->rut;
|
||||
}
|
||||
$proveedor = $this->proveedorRepository->create($filteredData);
|
||||
return $this->process($this->proveedorRepository->save($proveedor));
|
||||
}
|
||||
@ -61,12 +63,15 @@ class Proveedor extends Ideal\Service
|
||||
*/
|
||||
public function edit(Model\Inmobiliaria\Proveedor $proveedor, array $data): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
$filteredData = $this->proveedorRepository->filterData($data);
|
||||
try {
|
||||
if ($proveedor->contacto->rut !== $data['contacto']['rut']) {
|
||||
if (!empty($data['contacto']['rut'])) {
|
||||
$contacto = $this->contactoService->getById($data['contacto']['rut']);
|
||||
$this->contactoService->edit($contacto, $data['contacto']);
|
||||
$contacto = $this->contactoService->edit($contacto, $data['contacto']);
|
||||
$data['contacto_rut'] = $contacto->rut;
|
||||
} elseif ($proveedor->contacto !== null) {
|
||||
$data['contacto_rut'] = $proveedor->contacto->rut;
|
||||
}
|
||||
$filteredData = $this->proveedorRepository->filterData($data);
|
||||
return $this->process($this->proveedorRepository->edit($proveedor, $filteredData));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return $proveedor;
|
||||
|
Reference in New Issue
Block a user