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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user