Agregando o buscando el cliente primero

This commit is contained in:
Juan Pablo Vial
2025-01-17 16:56:47 -03:00
parent 5f31b6857e
commit 71615050f3

View File

@ -7,13 +7,15 @@ use Incoviba\Common\Ideal;
use Incoviba\Common\Implement; use Incoviba\Common\Implement;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service;
class Factura extends Ideal\Service class Factura extends Ideal\Service
{ {
public function __construct(LoggerInterface $logger, public function __construct(LoggerInterface $logger,
protected Repository\Venta\Factura $facturaRepository, protected Repository\Venta\Factura $facturaRepository,
protected Repository\Venta\Factura\Estado $estadoRepository, protected Repository\Venta\Factura\Estado $estadoRepository,
protected Repository\Venta\Factura\Estado\Tipo $tipoRepository) protected Repository\Venta\Factura\Estado\Tipo $tipoRepository,
protected Service\Persona $personaService)
{ {
parent::__construct($logger); parent::__construct($logger);
} }
@ -57,6 +59,11 @@ class Factura extends Ideal\Service
if ($factura !== null) { if ($factura !== null) {
return $factura; return $factura;
} }
list($data['cliente']['rut'], $data['cliente']['digito']) = explode('-', $data['cliente']['rut']);
$data['cliente']['rut'] = (int) str_replace('.', '', $data['cliente']['rut']);
$client = $this->personaService->add($data['cliente']);
$data['cliente_rut'] = $client->rut;
unset($data['cliente']);
$factura = $this->facturaRepository->save($this->facturaRepository->create($data)); $factura = $this->facturaRepository->save($this->facturaRepository->create($data));
$tipo = $this->tipoRepository->fetchByDescripcion('generada'); $tipo = $this->tipoRepository->fetchByDescripcion('generada');
$this->estadoRepository->save($this->estadoRepository->create([ $this->estadoRepository->save($this->estadoRepository->create([