Centros de Costos
This commit is contained in:
10
app/resources/routes/05_contabilidad.php
Normal file
10
app/resources/routes/05_contabilidad.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$app->group('/contabilidad', function($app) {
|
||||
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
});
|
10
app/resources/routes/api/contabilidad.php
Normal file
10
app/resources/routes/api/contabilidad.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$app->group('/contabilidad', function($app) {
|
||||
$files = new FilesystemIterator(implode(DIRECTORY_SEPARATOR, [__DIR__, 'contabilidad']));
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
});
|
10
app/resources/routes/api/contabilidad/centros_costos.php
Normal file
10
app/resources/routes/api/contabilidad/centros_costos.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\CentrosCostos;
|
||||
|
||||
$app->group('/centros_costos', function($app) {
|
||||
$app->post('/add[/]', [CentrosCostos::class, 'add']);
|
||||
});
|
||||
$app->group('/centro_costo/{centro_costo_id}', function($app) {
|
||||
$app->post('/edit[/]', [CentrosCostos::class, 'edit']);
|
||||
$app->delete('[/]', [CentrosCostos::class, 'remove']);
|
||||
});
|
6
app/resources/routes/contabilidad/centros_costos.php
Normal file
6
app/resources/routes/contabilidad/centros_costos.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\CentrosCostos;
|
||||
|
||||
$app->group('/centros_costos', function($app) {
|
||||
$app->get('[/]', CentrosCostos::class);
|
||||
});
|
329
app/resources/views/contabilidad/centros_costos.blade.php
Normal file
329
app/resources/views/contabilidad/centros_costos.blade.php
Normal file
@ -0,0 +1,329 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h1 class="ui header">
|
||||
Centros de Costos
|
||||
</h1>
|
||||
<div class="ui top attached right aligned basic segment">
|
||||
<button class="ui tiny green icon button" id="add_button">
|
||||
Agregar
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
<table class="ui table" id="centros_costos">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo de Centro</th>
|
||||
<th>Categoría</th>
|
||||
<th>Tipo de Cuenta</th>
|
||||
<th>Cuenta Contable</th>
|
||||
<th>Centro de Costo</th>
|
||||
<th>Descripción</th>
|
||||
<th>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($centrosCostos as $centroCosto)
|
||||
<tr data-id="{{$centroCosto->id}}">
|
||||
<td data-id="{{$centroCosto->tipoCentro->id}}">{{$centroCosto->tipoCentro->descripcion}}</td>
|
||||
<td data-id="{{$centroCosto->categoria->id}}">{{$centroCosto->categoria->descripcion}}</td>
|
||||
<td data-id="{{$centroCosto->tipoCuenta?->id}}">{{$centroCosto->tipoCuenta?->descripcion}}</td>
|
||||
<td>{{$centroCosto->cuentaContable}}</td>
|
||||
<td>{{$centroCosto->id}}</td>
|
||||
<td>{{$centroCosto->descripcion}}</td>
|
||||
<td>
|
||||
<div class="ui mini buttons">
|
||||
<button class="ui icon button edit_button" data-id="{{$centroCosto->id}}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui red icon button remove_button" data-id="{{$centroCosto->id}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="ui modal" id="modal_add">
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_form">
|
||||
<div class="fields">
|
||||
<div class="three wide field">
|
||||
<label for="tipo_centro">Tipo de Centro</label>
|
||||
<div class="ui selection search dropdown" id="tipo_centro">
|
||||
<input type="hidden" name="tipo_centro_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo</div>
|
||||
<div class="menu">
|
||||
@foreach ($tiposCentros as $tipoCentro)
|
||||
<div class="item" data-value="{{$tipoCentro->id}}">{{$tipoCentro->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="tipo_cuenta">Tipo de Cuenta</label>
|
||||
<div class="ui selection search dropdown" id="tipo_cuenta">
|
||||
<input type="hidden" name="tipo_cuenta_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo de Cuenta</div>
|
||||
<div class="menu">
|
||||
<div class="item" data-value="">---</div>
|
||||
@foreach ($tiposCuentas as $tipoCuenta)
|
||||
<div class="item" data-value="{{$tipoCuenta->id}}">{{$tipoCuenta->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="five wide field">
|
||||
<label for="categoria">Categoría</label>
|
||||
<div class="ui selection search dropdown" id="categoria">
|
||||
<input type="hidden" name="categoria_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Categoría</div>
|
||||
<div class="menu">
|
||||
@foreach ($categorias as $categoria)
|
||||
<div class="item" data-value="{{$categoria->id}}">{{$categoria->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="cuenta_contable">Cuenta Contable</label>
|
||||
<input type="text" name="cuenta_contable" id="cuenta_contable" />
|
||||
</div>
|
||||
<div class="two wide field">
|
||||
<label for="identificador">Centro de Costo</label>
|
||||
<input type="number" name="id" id="identificador" maxlength="3" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="descripcion">Descripción</label>
|
||||
<textarea id="descripcion" name="descripcion" class="ui textarea" rows="1" cols="10"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui positive icon button">
|
||||
<i class="plus icon"></i>
|
||||
Agregar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui modal" id="modal_edit">
|
||||
<div class="header">
|
||||
Centro de Costo <span id="id"></span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="edit_form">
|
||||
<input type="hidden" name="id" id="identificador" />
|
||||
<div class="fields">
|
||||
<div class="three wide field">
|
||||
<label for="tipo_centro">Tipo de Centro</label>
|
||||
<div class="ui selection search dropdown" id="tipo_centro">
|
||||
<input type="hidden" name="tipo_centro_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo</div>
|
||||
<div class="menu">
|
||||
@foreach ($tiposCentros as $tipoCentro)
|
||||
<div class="item" data-value="{{$tipoCentro->id}}">{{$tipoCentro->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="tipo_cuenta">Tipo de Cuenta</label>
|
||||
<div class="ui selection search dropdown" id="tipo_cuenta">
|
||||
<input type="hidden" name="tipo_cuenta_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo de Cuenta</div>
|
||||
<div class="menu">
|
||||
<div class="item" data-value="">---</div>
|
||||
@foreach ($tiposCuentas as $tipoCuenta)
|
||||
<div class="item" data-value="{{$tipoCuenta->id}}">{{$tipoCuenta->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="five wide field">
|
||||
<label for="categoria">Categoría</label>
|
||||
<div class="ui selection search dropdown" id="categoria">
|
||||
<input type="hidden" name="categoria_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Categoría</div>
|
||||
<div class="menu">
|
||||
@foreach ($categorias as $categoria)
|
||||
<div class="item" data-value="{{$categoria->id}}">{{$categoria->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="cuenta_contable">Cuenta Contable</label>
|
||||
<input type="text" name="cuenta_contable" id="cuenta_contable" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="descripcion">Descripción</label>
|
||||
<textarea id="descripcion" name="descripcion" class="ui textarea" rows="1" cols="10"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui positive icon button">
|
||||
<i class="plus icon"></i>
|
||||
Editar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const centros = {
|
||||
ids: {
|
||||
table: '',
|
||||
modals: {
|
||||
add: '',
|
||||
edit: ''
|
||||
},
|
||||
buttons: {
|
||||
add: '',
|
||||
edit: '',
|
||||
remove: ''
|
||||
},
|
||||
forms: {
|
||||
add: '',
|
||||
edit: ''
|
||||
}
|
||||
},
|
||||
setup: function({ids}) {
|
||||
this.ids = ids
|
||||
|
||||
Object.keys(this.ids.modals).forEach(name => {
|
||||
$(this.ids.modals[name]).modal({
|
||||
onApprove: ($element) => {
|
||||
this.actions()[name]()
|
||||
},
|
||||
onHidden: (modal) => {
|
||||
document.getElementById(this.ids.forms[name]).reset()
|
||||
}
|
||||
})
|
||||
$(this.ids.modals[name]).find('.dropdown').each((idx, item) => {
|
||||
$(item).dropdown()
|
||||
})
|
||||
})
|
||||
Object.keys(this.ids.buttons).forEach(name => {
|
||||
if (name === 'remove') {
|
||||
return
|
||||
}
|
||||
$(this.ids.buttons[name]).click(event => {
|
||||
if (name === 'edit') {
|
||||
const id = $(event.currentTarget).data('id')
|
||||
const row = $("tr[data-id='" + id + "']")
|
||||
const data = {
|
||||
id,
|
||||
tipo_centro_id: row.find(':nth-child(1)').data('id'),
|
||||
categoria_id: row.find(':nth-child(2)').data('id'),
|
||||
tipo_cuenta_id: row.find(':nth-child(3)').data('id'),
|
||||
cuenta_contable: row.find(':nth-child(4)').html(),
|
||||
descripcion: row.find(':nth-child(6)').html()
|
||||
}
|
||||
$(this.ids.modals[name]).find('#id').html(id)
|
||||
const form = $('#' + this.ids.forms[name])
|
||||
form.find("[name='id']").val(data.id)
|
||||
form.find('#tipo_centro').dropdown('set selected', data.tipo_centro_id)
|
||||
form.find('#categoria').dropdown('set selected', data.categoria_id)
|
||||
form.find('#tipo_cuenta').dropdown('set selected', data.tipo_cuenta_id)
|
||||
form.find('#cuenta_contable').val(data.cuenta_contable)
|
||||
form.find('#descripcion').val(data.descripcion)
|
||||
}
|
||||
$(this.ids.modals[name]).modal('show')
|
||||
})
|
||||
})
|
||||
$(this.ids.buttons.remove).click(event => {
|
||||
const id = $(event.currentTarget).data('id')
|
||||
this.actions().remove(id)
|
||||
})
|
||||
$(this.ids.table).dataTable({
|
||||
order: [
|
||||
[0, 'desc'],
|
||||
[1, 'asc'],
|
||||
[4, 'asc']
|
||||
]
|
||||
})
|
||||
},
|
||||
actions: function() {
|
||||
return {
|
||||
add: () => {
|
||||
const body = new FormData(document.getElementById(this.ids.forms.add))
|
||||
const url = '{{$urls->api}}/contabilidad/centros_costos/add'
|
||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
response.json().then(json => {
|
||||
if (json.added) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
edit: () => {
|
||||
const body = new FormData(document.getElementById(this.ids.forms.edit))
|
||||
const url = '{{$urls->api}}/contabilidad/centro_costo/' + body.get('id') + '/edit'
|
||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
response.json().then(json => {
|
||||
if (json.edited) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
remove: id => {
|
||||
const url = '{{$urls->api}}/contabilidad/centro_costo/' + id
|
||||
fetchAPI(url, {method: 'delete'}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
response.json().then(json => {
|
||||
if (json.removed) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
centros.setup({ids: {
|
||||
table: '#centros_costos',
|
||||
modals: {
|
||||
add: '#modal_add',
|
||||
edit: '#modal_edit'
|
||||
},
|
||||
buttons: {
|
||||
add: '#add_button',
|
||||
edit: '.edit_button',
|
||||
remove: '.remove_button'
|
||||
},
|
||||
forms: {
|
||||
add: 'add_form',
|
||||
edit: 'edit_form'
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
62
app/src/Controller/API/CentrosCostos.php
Normal file
62
app/src/Controller/API/CentrosCostos.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class CentrosCostos
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\CentroCosto $centroCostoRepository): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'added' => false
|
||||
];
|
||||
try {
|
||||
$centroCosto = $centroCostoRepository->create($body);
|
||||
$centroCosto->id = $body['id'];
|
||||
$centroCostoRepository->save($centroCosto);
|
||||
$output['added'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'centro_costo_id' => $centro_costo_id,
|
||||
'input' => $body,
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
|
||||
if ($body['tipo_cuenta_id'] === '') {
|
||||
$body['tipo_cuenta_id'] = null;
|
||||
}
|
||||
$centroCostoRepository->edit($centroCosto, $body);
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function remove(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'centro_costo_id' => $centro_costo_id,
|
||||
'removed' => false
|
||||
];
|
||||
try {
|
||||
$centroCosto = $centroCostoRepository->fetchById($centro_costo_id);
|
||||
$centroCostoRepository->remove($centroCosto);
|
||||
$output['removed'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
24
app/src/Controller/CentrosCostos.php
Normal file
24
app/src/Controller/CentrosCostos.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Common\Alias\View;
|
||||
|
||||
class CentrosCostos
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Repository\CentroCosto $centroCostoRepository,
|
||||
Repository\TipoCentro $tipoCentroRepository,
|
||||
Repository\CategoriaCentro $categoriaCentroRepository,
|
||||
Repository\TipoCuenta $tipoCuentaRepository): ResponseInterface
|
||||
{
|
||||
$centrosCostos = $centroCostoRepository->fetchAll();
|
||||
$tiposCentros = $tipoCentroRepository->fetchAll();
|
||||
$categorias = $categoriaCentroRepository->fetchAll('descripcion');
|
||||
$tiposCuentas = $tipoCuentaRepository->fetchAll();
|
||||
return $view->render($response, 'contabilidad.centros_costos', compact('centrosCostos',
|
||||
'tiposCentros', 'categorias', 'tiposCuentas'));
|
||||
}
|
||||
}
|
5
app/src/Model/CategoriaCentro.php
Normal file
5
app/src/Model/CategoriaCentro.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
class CategoriaCentro extends Tipo
|
||||
{}
|
24
app/src/Model/CentroCosto.php
Normal file
24
app/src/Model/CentroCosto.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class CentroCosto extends Ideal\Model
|
||||
{
|
||||
public TipoCentro $tipoCentro;
|
||||
public CategoriaCentro $categoria;
|
||||
public ?TipoCuenta $tipoCuenta;
|
||||
public string $cuentaContable;
|
||||
public string $descripcion;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_map(parent::jsonSerialize(), [
|
||||
'tipo_centro' => $this->tipoCentro,
|
||||
'categoria' => $this->categoria,
|
||||
'tipo_cuenta' => $this->tipoCuenta,
|
||||
'cuenta_contable' => $this->cuentaContable,
|
||||
'descripcion' => $this->descripcion
|
||||
]);
|
||||
}
|
||||
}
|
18
app/src/Model/PagoCentroCosto.php
Normal file
18
app/src/Model/PagoCentroCosto.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class PagoCentroCosto extends Ideal\Model
|
||||
{
|
||||
public Venta\Pago $pago;
|
||||
public CentroCosto $centroCosto;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'pago' => $this->pago,
|
||||
'centro_costo' => $this->centroCosto
|
||||
]);
|
||||
}
|
||||
}
|
5
app/src/Model/TipoCentro.php
Normal file
5
app/src/Model/TipoCentro.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
class TipoCentro extends Tipo
|
||||
{}
|
5
app/src/Model/TipoCuenta.php
Normal file
5
app/src/Model/TipoCuenta.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
class TipoCuenta extends Tipo
|
||||
{}
|
19
app/src/Repository/CategoriaCentro.php
Normal file
19
app/src/Repository/CategoriaCentro.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class CategoriaCentro extends Tipo
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('categorias_centros_costos');
|
||||
}
|
||||
|
||||
protected function getBlank(): Define\Model
|
||||
{
|
||||
return new Model\CategoriaCentro();
|
||||
}
|
||||
}
|
81
app/src/Repository/CentroCosto.php
Normal file
81
app/src/Repository/CentroCosto.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Repository\Mapper;
|
||||
use Incoviba\Common\Implement\Repository\MapperParser;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class CentroCosto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected TipoCentro $tipoCentroRepository,
|
||||
protected CategoriaCentro $categoriaCentroRepository,
|
||||
protected TipoCuenta $tipoCuentaRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('centros_costos');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\CentroCosto
|
||||
{
|
||||
$map = (new MapperParser(['descripcion']))
|
||||
->register('tipo_centro_id', (new Mapper())
|
||||
->setProperty('tipoCentro')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->tipoCentroRepository->fetchById($data['tipo_centro_id']);
|
||||
}))
|
||||
->register('categoria_id', (new Mapper())
|
||||
->setProperty('categoria')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->categoriaCentroRepository->fetchById($data['categoria_id']);
|
||||
}))
|
||||
->register('tipo_cuenta', (new Mapper())
|
||||
->setProperty('tipoCuenta')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->tipoCuentaRepository->fetchById($data['tipo_cuenta_id']);
|
||||
})
|
||||
->setDefault(null))
|
||||
->register('cuenta_contable', (new Mapper())
|
||||
->setProperty('cuentaContable'));
|
||||
return $this->parseData(new Model\CentroCosto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\CentroCosto
|
||||
{
|
||||
$this->saveNew(
|
||||
['id', 'tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'],
|
||||
[$model->id, $model->tipoCentro->id, $model->categoria->id, $model->tipoCuenta?->id, $model->cuentaContable, $model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\CentroCosto
|
||||
{
|
||||
return $this->update($model, ['tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Model\CentroCosto
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('descripcion LIKE ?');
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
public function fetchByTipoCuenta(string $tipo_cuenta): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('tipo_cuenta_id LIKE ?');
|
||||
return $this->fetchMany($query, [$tipo_cuenta]);
|
||||
}
|
||||
public function fetchByCategoria(string $categoria): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('categoria_id LIKE ?');
|
||||
return $this->fetchMany($query, [$categoria]);
|
||||
}
|
||||
}
|
42
app/src/Repository/PagoCentroCosto.php
Normal file
42
app/src/Repository/PagoCentroCosto.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class PagoCentroCosto extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Pago $pagoRepository, protected CentroCosto $centroCostoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pagos_centros_costos');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\PagoCentroCosto
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('pago')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->pagoRepository->fetchById($data['pago_id']);
|
||||
}))
|
||||
->register('centro_costo_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('centroCosto')
|
||||
->setFunction(function(array $data) {
|
||||
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
|
||||
}));
|
||||
return $this->parseData(new Model\PagoCentroCosto(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Model\PagoCentroCosto
|
||||
{
|
||||
$model->id = $this->saveNew(['pago_id', 'centro_costo_id'], [$model->pago->id, $model->centroCosto->id]);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\PagoCentroCosto
|
||||
{
|
||||
return $this->update($model, ['pago_id', 'centro_costo_id'], $new_data);
|
||||
}
|
||||
}
|
37
app/src/Repository/Tipo.php
Normal file
37
app/src/Repository/Tipo.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
|
||||
abstract class Tipo extends Ideal\Repository
|
||||
{
|
||||
abstract protected function getBlank(): Define\Model;
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = new Implement\Repository\MapperParser(['descripcion']);
|
||||
return $this->parseData($this->getBlank(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion'],
|
||||
[$model->descripcion]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByDescripcion(string $descripcion): Define\Model
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('descripcion LIKE ?');
|
||||
return $this->fetchOne($query, [$descripcion]);
|
||||
}
|
||||
}
|
19
app/src/Repository/TipoCentro.php
Normal file
19
app/src/Repository/TipoCentro.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoCentro extends Tipo
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipos_centros_costos');
|
||||
}
|
||||
|
||||
protected function getBlank(): Define\Model
|
||||
{
|
||||
return new Model\TipoCentro();
|
||||
}
|
||||
}
|
19
app/src/Repository/TipoCuenta.php
Normal file
19
app/src/Repository/TipoCuenta.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoCuenta extends Tipo
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipos_cuentas_costos');
|
||||
}
|
||||
|
||||
protected function getBlank(): Define\Model
|
||||
{
|
||||
return new Model\TipoCuenta();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user