diff --git a/app/src/Service/Venta/Factura.php b/app/src/Service/Venta/Factura.php index 7715810..8f5bc4b 100644 --- a/app/src/Service/Venta/Factura.php +++ b/app/src/Service/Venta/Factura.php @@ -7,13 +7,15 @@ use Incoviba\Common\Ideal; use Incoviba\Common\Implement; use Incoviba\Model; use Incoviba\Repository; +use Incoviba\Service; class Factura extends Ideal\Service { public function __construct(LoggerInterface $logger, protected Repository\Venta\Factura $facturaRepository, 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); } @@ -57,6 +59,11 @@ class Factura extends Ideal\Service if ($factura !== null) { 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)); $tipo = $this->tipoRepository->fetchByDescripcion('generada'); $this->estadoRepository->save($this->estadoRepository->create([