Compare commits
4 Commits
a405b15410
...
878b02ee52
Author | SHA1 | Date | |
---|---|---|---|
878b02ee52 | |||
f3e15b34a8 | |||
3903551176 | |||
43eb8ec758 |
@ -13,9 +13,9 @@ class CreateCartolas extends Phinx\Migration\AbstractMigration
|
||||
$this->table('cartolas')
|
||||
->addColumn('cuenta_id', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
|
||||
->addColumn('fecha', 'date', ['null' => false])
|
||||
->addColumn('cargos', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abonos', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'bigint', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addColumn('cargos', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abonos', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addForeignKey('cuenta_id', 'cuenta', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -15,7 +15,7 @@ class CreateCentrosCostos extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('categoria_id', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
|
||||
->addColumn('tipo_cuenta_id', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addColumn('cuenta_contable', 'string', ['length' => 100, 'null' => false])
|
||||
->addColumn('descripcion', 'mediumtext', ['null' => false])
|
||||
->addColumn('descripcion', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->addForeignKey('tipo_centro_id', 'tipos_centros_costos', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('categoria_id', 'categorias_centros_costos', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
|
@ -19,7 +19,7 @@ class CreateCobro extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('iva', 'float', ['default' => 0])
|
||||
->addColumn('uf', 'float', ['default' => null, 'null' => true])
|
||||
->addColumn('identificador', 'string', ['length' => 50, 'default' => null, 'null' => true])
|
||||
->addColumn('glosa', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('glosa', 'text', ['default' => null, 'null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class CreateEscritura extends Phinx\Migration\AbstractMigration
|
||||
$this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';");
|
||||
|
||||
$this->table('escritura')
|
||||
->addColumn('valor', 'bigint', ['length' => 20, 'null' => false])
|
||||
->addColumn('valor', 'biginteger', ['length' => 20, 'null' => false])
|
||||
->addColumn('fecha', 'date', ['null' => false])
|
||||
->addColumn('uf', 'float', ['default' => null, 'null' => true])
|
||||
->addColumn('abonado', 'integer', ['length' => 11, 'default' => 0])
|
||||
|
@ -13,7 +13,7 @@ class CreateEstadoProblema extends Phinx\Migration\AbstractMigration
|
||||
$this->table('estado_problema')
|
||||
->addColumn('problema', 'integer', ['length' => 11, 'default' => null, 'null' => true])
|
||||
->addColumn('fecha', 'date', ['default' => null, 'null' => true])
|
||||
->addColumn('estado', 'enum', ['length' => 'ingreso','revision','correccion','ok', 'default' => null, 'null' => true])
|
||||
->addColumn('estado', 'enum', ['values' => ['ingreso','revision','correccion','ok'], 'default' => null, 'null' => true])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class CreateInmobiliariasNubox extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('alias', 'string', ['length' => 100, 'null' => false])
|
||||
->addColumn('usuario', 'string', ['length' => 100, 'null' => false])
|
||||
->addColumn('contraseña', 'string', ['length' => 100, 'null' => false])
|
||||
->addForeignKey('inmobiliaria_rut', 'inmobiliaria', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
#->addForeignKey('inmobiliaria_rut', 'inmobiliaria', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ class CreateMovimientos extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('fecha', 'date', ['null' => false])
|
||||
->addColumn('glosa', 'text', ['null' => false])
|
||||
->addColumn('documento', 'string', ['length' => 50, 'null' => false])
|
||||
->addColumn('cargo', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abono', 'bigint', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'bigint', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addColumn('cargo', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('abono', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('saldo', 'biginteger', ['length' => 20, 'default' => 0, 'null' => false])
|
||||
->addForeignKey('cuenta_id', 'cuenta', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -12,7 +12,7 @@ class CreateProblema extends Phinx\Migration\AbstractMigration
|
||||
|
||||
$this->table('problema')
|
||||
->addColumn('venta', 'integer', ['length' => 11, 'default' => null, 'null' => true])
|
||||
->addColumn('descripcion', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('descripcion', 'text', ['default' => null, 'null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class CreateProyecto extends Phinx\Migration\AbstractMigration
|
||||
|
||||
$this->table('proyecto')
|
||||
->addColumn('inmobiliaria', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addColumn('descripcion', 'mediumtext', ['null' => false])
|
||||
->addColumn('descripcion', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->addColumn('direccion', 'integer', ['length' => 10, 'null' => false, 'signed' => false])
|
||||
->addColumn('superficie_terreno', 'float', ['default' => 0, 'null' => false, 'signed' => false])
|
||||
->addColumn('valor_terreno', 'float', ['default' => 0, 'null' => false, 'signed' => false])
|
||||
|
@ -18,7 +18,7 @@ class CreateProyectoTipoUnidad extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('m2', 'float', ['default' => null, 'null' => true])
|
||||
->addColumn('logia', 'float', ['default' => 0])
|
||||
->addColumn('terraza', 'float', ['default' => 0])
|
||||
->addColumn('descripcion', 'mediumtext', ['default' => null, 'null' => true])
|
||||
->addColumn('descripcion', 'text', ['default' => null, 'null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM])
|
||||
->addForeignKey('proyecto', 'proyecto', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
|
@ -33,7 +33,7 @@ class CreateVenta extends Phinx\Migration\AbstractMigration
|
||||
->addColumn('resciliacion', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addColumn('devolucion', 'integer', ['length' => 10, 'default' => null, 'null' => true, 'signed' => false])
|
||||
->addForeignKey('propiedad', 'propiedad', 'id', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->addForeignKey('propietario', 'propietario', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
#->addForeignKey('propietario', 'propietario', 'rut', ['delete' => 'cascade', 'update' => 'cascade'])
|
||||
->create();
|
||||
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model\Persona\Datos;
|
||||
|
||||
@ -31,6 +32,20 @@ class Persona extends Ideal\Model
|
||||
return $this->datos;
|
||||
}
|
||||
|
||||
public function __get(string $name): mixed
|
||||
{
|
||||
if (property_exists($this, $name)) {
|
||||
return $this->{$name};
|
||||
}
|
||||
if ($name === 'datos') {
|
||||
return $this->datos();
|
||||
}
|
||||
if ($name === 'dv') {
|
||||
return $this->digito;
|
||||
}
|
||||
throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
|
@ -38,6 +38,10 @@ class SII implements Define\Money\Provider
|
||||
$dateTime = new DateTimeImmutable();
|
||||
}
|
||||
$year = $this->getUFYear($dateTime);
|
||||
|
||||
if (!isset($year[$dateTime->format('Y-m-d')])) {
|
||||
throw new EmptyResponse("{$dateTime->format('Y-m-d')} not found");
|
||||
}
|
||||
return $year[$dateTime->format('Y-m-d')];
|
||||
}
|
||||
|
||||
@ -51,6 +55,9 @@ class SII implements Define\Money\Provider
|
||||
if ($dateTime === null) {
|
||||
$dateTime = new DateTimeImmutable();
|
||||
}
|
||||
if ($dateTime->format('Y') > (new DateTimeImmutable())->format('Y')) {
|
||||
throw new EmptyResponse("{$dateTime->format('Y')} not found");
|
||||
}
|
||||
$request_uri = "uf/uf{$dateTime->format('Y')}.htm";
|
||||
try {
|
||||
$response = $this->client->get($request_uri);
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction\Create;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Persona extends Ideal\Service
|
||||
{
|
||||
@ -21,16 +23,27 @@ class Persona extends Ideal\Service
|
||||
/**
|
||||
* @param int $rut
|
||||
* @return Model\Persona
|
||||
* @throws Read
|
||||
* @throws Read|Create
|
||||
*/
|
||||
public function getById(int $rut): Model\Persona
|
||||
{
|
||||
try {
|
||||
return $this->process($this->personaRepository->fetchById($rut));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
try {
|
||||
$this->propietarioRepository->fetchById($rut);
|
||||
return $this->add(compact('rut'));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Model\Persona
|
||||
* @throws Create
|
||||
*/
|
||||
public function add(array $data): Model\Persona
|
||||
{
|
||||
try {
|
||||
@ -42,9 +55,19 @@ class Persona extends Ideal\Service
|
||||
$data['apellido_paterno'] = $propietario->apellidos['paterno'];
|
||||
$data['apellido_materno'] = $propietario->apellidos['materno'];
|
||||
$data['direccion_id'] = $propietario->datos->direccion->id;
|
||||
if (isset($propietario->datos?->email)) {
|
||||
$data['email'] = $propietario->datos->email;
|
||||
}
|
||||
if (isset($propietario->datos?->telefono)) {
|
||||
$data['telefono'] = $propietario->datos->telefono;
|
||||
}
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
$persona = $this->personaRepository->create($data);
|
||||
$persona = $this->personaRepository->save($persona);
|
||||
try {
|
||||
$persona = $this->personaRepository->save($persona);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
if (isset($data['direccion_id']) or isset($data['email']) or isset($data['telefono'])) {
|
||||
$datosData = ['persona_rut' => $persona->rut];
|
||||
@ -62,7 +85,11 @@ class Persona extends Ideal\Service
|
||||
$this->datosPersonaRepository->edit($datos, $data);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$datos = $this->datosPersonaRepository->create($datosData);
|
||||
$this->datosPersonaRepository->save($datos);
|
||||
try {
|
||||
$this->datosPersonaRepository->save($datos);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->process($persona);
|
||||
|
@ -52,12 +52,16 @@ class TestBootstrap
|
||||
{
|
||||
public function __construct(protected array $configuration) {}
|
||||
|
||||
public function run(): void
|
||||
public function run(bool $resetDatabase = false): void
|
||||
{
|
||||
if (Benchmark::execute([$this, 'isMigrated'])) {
|
||||
Benchmark::execute([$this, 'resetDatabase']);
|
||||
if ($resetDatabase) {
|
||||
if (Benchmark::execute([$this, 'isMigrated'])) {
|
||||
Benchmark::execute([$this, 'resetDatabase']);
|
||||
}
|
||||
}
|
||||
if (!Benchmark::execute([$this, 'isMigrated'])) {
|
||||
Benchmark::execute([$this, 'migrate']);
|
||||
}
|
||||
Benchmark::execute([$this, 'migrate']);
|
||||
}
|
||||
|
||||
protected string $baseCommand = "bin/phinx";
|
||||
@ -67,7 +71,7 @@ class TestBootstrap
|
||||
$output = shell_exec($cmd);
|
||||
$status = json_decode($output, true);
|
||||
|
||||
return $status['missing_count'] > 0;
|
||||
return $status['missing_count'] === 0;
|
||||
}
|
||||
public function migrate(): void
|
||||
{
|
||||
@ -162,7 +166,8 @@ spl_autoload_register(function($className) {
|
||||
});
|
||||
|
||||
$bootstrap = new TestBootstrap($_ENV);
|
||||
Benchmark::execute([$bootstrap, 'run']);
|
||||
$resetDatabase = $_ENV['RESET_DATABASE'] ?? false;
|
||||
Benchmark::execute([$bootstrap, 'run'], ['resetDatabase' => $resetDatabase]);
|
||||
Benchmark::print();
|
||||
|
||||
register_shutdown_function(function() use ($bootstrap) {
|
||||
|
@ -5,6 +5,7 @@ use PDO;
|
||||
use PDOStatement;
|
||||
use GuzzleHttp\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Common\Define;
|
||||
@ -53,4 +54,13 @@ class SIITest extends TestCase
|
||||
|
||||
$this->assertEquals($expected, $provider->get(Service\Money::UF, $date));
|
||||
}
|
||||
public function testGetNoValid(): void
|
||||
{
|
||||
$provider = new Service\Money\SII($this->client, $this->ufRepository);
|
||||
|
||||
$date = (new \DateTimeImmutable())->add(new \DateInterval("P1Y"));
|
||||
|
||||
$this->expectException(EmptyResponse::class);
|
||||
$provider->get(Service\Money::UF, $date);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user