Guardar factura
This commit is contained in:
@ -11,7 +11,8 @@ class Persona extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Persona $personaRepository,
|
||||
protected Repository\Persona\Datos $datosPersonaRepository)
|
||||
protected Repository\Persona\Datos $datosPersonaRepository,
|
||||
protected Repository\Venta\Propietario $propietarioRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -25,11 +26,21 @@ class Persona extends Ideal\Service
|
||||
try {
|
||||
$persona = $this->personaRepository->fetchById($data['rut']);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
try {
|
||||
$propietario = $this->propietarioRepository->fetchById($data['rut']);
|
||||
$data['nombres'] = $propietario->nombres;
|
||||
$data['apellido_paterno'] = $propietario->apellidos['paterno'];
|
||||
$data['apellido_materno'] = $propietario->apellidos['materno'];
|
||||
$data['direccion_id'] = $propietario->datos->direccion->id;
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
$persona = $this->personaRepository->create($data);
|
||||
$persona = $this->personaRepository->save($persona);
|
||||
}
|
||||
if (isset($data['email']) or isset($data['telefono'])) {
|
||||
if (isset($data['direccion_id']) or isset($data['email']) or isset($data['telefono'])) {
|
||||
$datosData = ['persona_rut' => $persona->rut];
|
||||
if (isset($data['direccion_id'])) {
|
||||
$datosData['direccion_id'] = $data['direccion_id'];
|
||||
}
|
||||
if (isset($data['email'])) {
|
||||
$datosData['email'] = $data['email'];
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Service;
|
||||
|
||||
use Predis\ClientInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||
use Predis\Connection\ConnectionException;
|
||||
|
||||
class Redis
|
||||
{
|
||||
@ -10,13 +11,21 @@ class Redis
|
||||
|
||||
public function get(string $name): mixed
|
||||
{
|
||||
if (!$this->client->exists($name)) {
|
||||
throw new EmptyRedis($name);
|
||||
try {
|
||||
if (!$this->client->exists($name)) {
|
||||
throw new EmptyRedis($name);
|
||||
}
|
||||
return $this->client->get($name);
|
||||
} catch (ConnectionException $exception) {
|
||||
throw new EmptyRedis($name, $exception);
|
||||
}
|
||||
return $this->client->get($name);
|
||||
}
|
||||
public function set(string $name, mixed $value, int $expirationTTL = 60 * 60 * 24): void
|
||||
{
|
||||
$this->client->set($name, $value, 'EX', $expirationTTL);
|
||||
try {
|
||||
$this->client->set($name, $value, 'EX', $expirationTTL);
|
||||
} catch (ConnectionException) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ class Factura extends Ideal\Service
|
||||
$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->create($data);
|
||||
$factura = $this->facturaRepository->save($factura);
|
||||
$tipo = $this->tipoRepository->fetchByDescripcion('generada');
|
||||
$this->estadoRepository->save($this->estadoRepository->create([
|
||||
'factura_id' => $factura->id,
|
||||
|
Reference in New Issue
Block a user