Cambio en queue para que no quede pegado esperando respuesta en cli.
Chequeo de servicios externos para agregar elementos pendientes.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -45,6 +47,67 @@ class Persona extends Ideal\Repository
|
||||
return array_intersect_key($data, array_flip(['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ruts
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByRuts(array $ruts): array
|
||||
{
|
||||
$rutsQuery = implode(', ', array_fill(0, count($ruts), '?'));
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where("rut IN ({$rutsQuery})");
|
||||
return $this->fetchMany($query, $ruts);
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchMissing(): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select('a.rut')
|
||||
->from("propietario a")
|
||||
->joined("LEFT OUTER JOIN {$this->getTable()} b WHERE a.rut = b.rut")
|
||||
->where('b.rut IS NULL');
|
||||
try {
|
||||
$statement = $this->connection->query($query);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
try {
|
||||
$results = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
if (!$results or empty($results)) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function saveMissing(array $data): array
|
||||
{
|
||||
$valueArray = array_fill(0, count($data), ['?', '?', '?', '?', '?']);
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into($this->getTable())
|
||||
->columns(['rut', 'digito', 'nombres', 'apellido_paterno', 'apellido_materno'])
|
||||
->values($valueArray);
|
||||
$flattened = array_merge(...$data);
|
||||
$this->connection->execute($query, $flattened);
|
||||
|
||||
return $this->fetchByRuts(array_column($data, 'rut'));
|
||||
}
|
||||
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Persona;
|
||||
|
||||
use PDOException;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -85,4 +86,31 @@ class Datos extends Ideal\Repository
|
||||
->where('persona_rut = ?');
|
||||
return $this->fetchOne($query, [$persona_rut]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function saveMissing(array $data): void
|
||||
{
|
||||
$dataQuery = array_fill(0, count($data), ['?', '?', '?', '?', '?', '?', '?', '?', '?']);
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into($this->getTable())
|
||||
->columns([
|
||||
'direccion_id', 'telefono', 'email', 'fecha_nacimiento', 'sexo', 'estado_civil',
|
||||
'nacionalidad', 'ocupacion'
|
||||
])
|
||||
->values($dataQuery);
|
||||
$flattened = [];
|
||||
foreach ($data as $col => $value) {
|
||||
$row = [
|
||||
$value['direccion_id'] ?? null, $value['telefono'] ?? null, $value['email'] ?? null, $value['fecha_nacimiento'] ?? null,
|
||||
$value['sexo'] ?? null, $value['estado_civil'] ?? null, $value['nacionalidad'] ?? null, $value['ocupacion'] ?? null
|
||||
];
|
||||
$flattened = array_merge($flattened, $row);
|
||||
}
|
||||
$this->connection->execute($query, $flattened);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,11 @@ class Subscription extends Ideal\Repository
|
||||
return $this->update($model, ['venta_id', 'toku_id', 'updated_at'], array_merge($new_data, ['updated_at' => (new DateTimeImmutable())->format('Y-m-d H:i:s')]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\MediosPago\Toku\Subscription
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): Model\Venta\MediosPago\Toku\Subscription
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -51,6 +56,12 @@ class Subscription extends Ideal\Repository
|
||||
->where('venta_id = :venta_id');
|
||||
return $this->fetchOne($query, compact('venta_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $toku_id
|
||||
* @return Model\Venta\MediosPago\Toku\Subscription
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByTokuId(string $toku_id): Model\Venta\MediosPago\Toku\Subscription
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -59,4 +70,19 @@ class Subscription extends Ideal\Repository
|
||||
->where('toku_id = :toku_id');
|
||||
return $this->fetchOne($query, compact('toku_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ventas_ids
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVentas(array $ventas_ids): array
|
||||
{
|
||||
$idsQuery = implode(', ', array_fill(0, count($ventas_ids), '?'));
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where("venta_id IN ({$idsQuery})");
|
||||
return $this->fetchMany($query, $ventas_ids);
|
||||
}
|
||||
}
|
||||
|
@ -90,4 +90,19 @@ class Propietario extends Ideal\Repository
|
||||
{
|
||||
return array_intersect_key($data, array_flip(['rut', 'dv', 'nombres', 'apellido_paterno', 'apellido_materno', 'direccion', 'email', 'telefono', 'otro', 'representante']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ruts
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByRuts(array $ruts): array
|
||||
{
|
||||
$rutsQuery = implode(', ', array_fill(0, count($ruts), '?'));
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where("rut IN ({$rutsQuery})");
|
||||
return $this->fetchMany($query, $ruts);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user