Proveedores en movimientos

This commit is contained in:
Juan Pablo Vial
2024-12-03 20:32:29 -03:00
parent 0766cf7e94
commit fe74619482
16 changed files with 158 additions and 286 deletions

View File

@ -1,62 +0,0 @@
<?php
namespace Incoviba\Repository\Contabilidad\Movimiento;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
class Auxiliar extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Contabilidad\Movimiento $movimientoRepository)
{
parent::__construct($connection);
$this->setTable('movimientos_auxiliares');
}
public function create(?array $data = null): Model\Contabilidad\Movimiento\Auxiliar
{
$map = (new Implement\Repository\MapperParser(['cargo', 'abono']))
->register('movimiento_id', (new Implement\Repository\Mapper())
->setProperty('movimiento')
->setFunction(function($data) {
return $this->movimientoRepository->fetchById($data['movimiento_id']);
}));
return $this->parseData(new Model\Contabilidad\Movimiento\Auxiliar(), $data, $map);
}
public function save(Define\Model $model): Model\Contabilidad\Movimiento\Auxiliar
{
$model->id = $this->saveNew([
'movimiento_id',
'cargo',
'abono'
],[
$model->movimiento->id,
$model->cargo,
$model->abono
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento\Auxiliar
{
return $this->update($model, [
'movimiento_id',
'cargo',
'abono'
], $new_data);
}
/**
* @throws EmptyResult
*/
public function fetchByMovimiento(int $movimiento_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('movimiento_id = :movimiento_id');
return $this->fetchMany($query, ['movimiento_id' => $movimiento_id]);
}
}

View File

@ -1,72 +0,0 @@
<?php
namespace Incoviba\Repository\Contabilidad\Movimiento\Auxiliar;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
class Detalle extends Ideal\Repository
{
public function __construct(Define\Connection $connection,
protected Repository\Contabilidad\Movimiento\Auxiliar $auxiliarRepository,
protected Repository\Contabilidad\CentroCosto $centroCostoRepository)
{
parent::__construct($connection);
$this->setTable('auxiliar_detalles');
}
public function create(?array $data = null): Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombre', 'categoria', 'detalle']))
->register('auxiliar_id', (new Implement\Repository\Mapper())
->setProperty('auxiliar')
->setFunction(function($data) {
return $this->auxiliarRepository->fetchById($data['auxiliar_id']);
}))
->register('centro_costo_id', (new Implement\Repository\Mapper())
->setProperty('centroCosto')
->setFunction(function($data) {
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
})
->setDefault(null));
return $this->parseData(new Model\Contabilidad\Movimiento\Auxiliar\Detalle(), $data, $map);
}
public function save(Define\Model $model): Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
$this->saveNew([
'auxiliar_id',
'rut',
'digito',
'nombre',
'categoria',
'detalle'
], [
$model->auxiliar->id,
$model->rut,
$model->digito,
$model->nombre,
$model->categoria,
$model->detalle
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento\Auxiliar\Detalle
{
return $this->update($model, ['rut', 'digito', 'nombre', 'categoria', 'detalle'], $new_data);
}
/**
* @throws EmptyResult
*/
public function fetchByAuxiliar(int $auxiliar_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('auxiliar_id = :auxiliar_id');
return $this->fetchMany($query, ['auxiliar_id' => $auxiliar_id]);
}
}

View File

@ -20,15 +20,18 @@ class Proveedor extends Ideal\Repository
public function create(?array $data = null): Model\Inmobiliaria\Proveedor
{
$map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombre', 'razon']))
->register('contacto_rut', (new Implement\Repository\Mapper())->setProperty('contacto')->setFunction(function($data) {
return $this->personaService->getById($data['contacto_rut']);
}));
->register('contacto_rut', (new Implement\Repository\Mapper())
->setProperty('contacto')
->setFunction(function($data) {
return $this->personaService->getById($data['contacto_rut']);
})
->setDefault(null));
return $this->parseData(new Model\Inmobiliaria\Proveedor(), $data, $map);
}
public function save(Define\Model $model): Model\Inmobiliaria\Proveedor
{
$this->saveNew(['rut', 'digito', 'nombre', 'razon', 'contacto_rut'], [
$model->rut, $model->digito, $model->nombre, $model->razon, $model->contacto->rut
$model->rut, $model->digito, $model->nombre, $model->razon, $model->contacto?->rut
]);
return $model;
}