Compare commits
29 Commits
2.2.0
...
c10f2e5912
Author | SHA1 | Date | |
---|---|---|---|
c10f2e5912 | |||
bef0a22758 | |||
092eb95f06 | |||
5f56022109 | |||
4b3397dd63 | |||
529f9e32a1 | |||
939adf126f | |||
63400af1db | |||
019974614c | |||
735c341729 | |||
444ff687fc | |||
f3a5fa2cdc | |||
2ed265dcf1 | |||
dbae630fdd | |||
d69976d015 | |||
2ccbc31ae0 | |||
e50d80560c | |||
7cc0333876 | |||
eb38236926 | |||
85ef4dd60e | |||
f1e29e3b0b | |||
6617a92f5f | |||
ca958b8a88 | |||
dc2e2c7f71 | |||
936fd2d1e1 | |||
7c6a397e31 | |||
7385225a2e | |||
9c335fd350 | |||
57f9169cc7 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,3 +10,5 @@
|
|||||||
**/.idea/
|
**/.idea/
|
||||||
**/upload?/
|
**/upload?/
|
||||||
**/informe?/
|
**/informe?/
|
||||||
|
**/.phpunit.cache/
|
||||||
|
**/coverage/
|
||||||
|
@ -9,6 +9,7 @@ RUN pecl install xdebug-3.1.3 \
|
|||||||
&& docker-php-ext-enable xdebug
|
&& docker-php-ext-enable xdebug
|
||||||
|
|
||||||
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
|
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
|
||||||
|
COPY ./php-xdebug.ini /usr/local/etc/php/conf.d/docker-php-xdebug.ini
|
||||||
|
|
||||||
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
|
13
app/.phpunit-watcher.yml
Normal file
13
app/.phpunit-watcher.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
watch:
|
||||||
|
directories:
|
||||||
|
- src
|
||||||
|
- tests
|
||||||
|
- common
|
||||||
|
fileMask: '*.php'
|
||||||
|
notifications:
|
||||||
|
passingTests: false
|
||||||
|
failingTests: false
|
||||||
|
hideManual: true
|
||||||
|
phpunit:
|
||||||
|
arguments: '--log-events-text /logs/output.txt --stop-on-failure'
|
||||||
|
timeout: 180
|
@ -5,6 +5,11 @@ use Psr\Http\Message\UploadedFileInterface;
|
|||||||
|
|
||||||
interface Banco
|
interface Banco
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Process bank movements for database inserts
|
||||||
|
* @param UploadedFileInterface $file
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function process(UploadedFileInterface $file): array;
|
public function process(UploadedFileInterface $file): array;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@ use Incoviba\Model;
|
|||||||
|
|
||||||
interface Exporter
|
interface Exporter
|
||||||
{
|
{
|
||||||
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string;
|
public function export(Model\Inmobiliaria $inmobiliaria, Model\Contabilidad\Banco $banco, DateTimeInterface $mes, array $movimientos): string;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ abstract class Banco extends Service implements Define\Cartola\Banco
|
|||||||
{
|
{
|
||||||
public function process(UploadedFileInterface $file): array
|
public function process(UploadedFileInterface $file): array
|
||||||
{
|
{
|
||||||
$data = $this->parseFile($file);
|
$data = $this->handleFile($file);
|
||||||
$temp = [];
|
$temp = [];
|
||||||
$columns = $this->columnMap();
|
$columns = $this->columnMap();
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
@ -24,11 +24,48 @@ abstract class Banco extends Service implements Define\Cartola\Banco
|
|||||||
}
|
}
|
||||||
return $temp;
|
return $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There are banks that need some post-processing
|
||||||
|
* @param array $movimientos
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function processMovimientosDiarios(array $movimientos): array
|
public function processMovimientosDiarios(array $movimientos): array
|
||||||
{
|
{
|
||||||
return $movimientos;
|
return $movimientos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the UploadedFile into a temp file from getFilename and after parseFile remove temp file
|
||||||
|
* @param UploadedFileInterface $uploadedFile
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function handleFile(UploadedFileInterface $uploadedFile): array
|
||||||
|
{
|
||||||
|
$filename = $this->getFilename($uploadedFile);
|
||||||
|
$uploadedFile->moveTo($filename);
|
||||||
|
$data = $this->parseFile($filename);
|
||||||
|
unlink($filename);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get filename where to move UploadedFile
|
||||||
|
* @param UploadedFileInterface $uploadedFile
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
abstract protected function getFilename(UploadedFileInterface $uploadedFile): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapping of uploaded file data columns to database columns
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
abstract protected function columnMap(): array;
|
abstract protected function columnMap(): array;
|
||||||
abstract protected function parseFile(UploadedFileInterface $uploadedFile): array;
|
|
||||||
|
/**
|
||||||
|
* Translate uploaded file data to database data
|
||||||
|
* @param string $filename
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
abstract protected function parseFile(string $filename): array;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "incoviba/web",
|
"name": "incoviba/web",
|
||||||
|
"version": "2.0.0",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"berrnd/slim-blade-view": "^1.0",
|
"berrnd/slim-blade-view": "^1.0",
|
||||||
|
"ext-gd": "*",
|
||||||
|
"ext-openssl": "*",
|
||||||
|
"ext-pdo": "*",
|
||||||
"guzzlehttp/guzzle": "^7.8",
|
"guzzlehttp/guzzle": "^7.8",
|
||||||
"monolog/monolog": "^3.4",
|
"monolog/monolog": "^3.4",
|
||||||
"nyholm/psr7": "^1.8",
|
"nyholm/psr7": "^1.8",
|
||||||
@ -14,8 +18,10 @@
|
|||||||
"slim/slim": "^4.11"
|
"slim/slim": "^4.11"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"fakerphp/faker": "^1.23",
|
||||||
"kint-php/kint": "^5.1",
|
"kint-php/kint": "^5.1",
|
||||||
"phpunit/phpunit": "^10.2"
|
"phpunit/phpunit": "^10.2",
|
||||||
|
"spatie/phpunit-watcher": "^1.23"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@ -30,6 +36,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"sort-packages": true
|
"sort-packages": true,
|
||||||
|
"process-timeout": 0,
|
||||||
|
"bin-dir": "bin"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
app/phpunit.xml
Normal file
43
app/phpunit.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
cacheDirectory="./cache"
|
||||||
|
executionOrder="depends,defects"
|
||||||
|
requireCoverageMetadata="false"
|
||||||
|
beStrictAboutCoverageMetadata="false"
|
||||||
|
beStrictAboutOutputDuringTests="true"
|
||||||
|
colors="true"
|
||||||
|
failOnRisky="false"
|
||||||
|
failOnWarning="false">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="unit">
|
||||||
|
<directory>tests/units</directory>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="acceptance">
|
||||||
|
<directory>tests/integration</directory>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="performance">
|
||||||
|
<directory>tests/performance</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
|
||||||
|
<include>
|
||||||
|
<directory>src</directory>
|
||||||
|
<directory>common</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
<coverage includeUncoveredFiles="true" pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
|
||||||
|
<report>
|
||||||
|
<html outputDirectory="/code/public/coverage/html" />
|
||||||
|
<php outputFile="/code/public/coverage/coverage.php" />
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
|
<logging>
|
||||||
|
<junit outputFile="/logs/junit.xml" />
|
||||||
|
<teamcity outputFile="/logs/teamcity.txt" />
|
||||||
|
<testdoxHtml outputFile="/logs/testdox.html" />
|
||||||
|
<testdoxText outputFile="/logs/testdox.txt" />
|
||||||
|
</logging>
|
||||||
|
</phpunit>
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use Incoviba\Controller\API\Base;
|
||||||
|
|
||||||
$app->group('/api', function($app) {
|
$app->group('/api', function($app) {
|
||||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'api']);
|
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'api']);
|
||||||
if (file_exists($folder)) {
|
if (file_exists($folder)) {
|
||||||
@ -10,4 +12,5 @@ $app->group('/api', function($app) {
|
|||||||
include_once $file->getRealPath();
|
include_once $file->getRealPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$app->get('[/]', Base::class);
|
||||||
})->add($app->getContainer()->get(Incoviba\Middleware\API::class));
|
})->add($app->getContainer()->get(Incoviba\Middleware\API::class));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\API\CentrosCostos;
|
|
||||||
|
use Incoviba\Controller\API\Contabilidad\CentrosCostos;
|
||||||
|
|
||||||
$app->group('/centros_costos', function($app) {
|
$app->group('/centros_costos', function($app) {
|
||||||
$app->post('/add[/]', [CentrosCostos::class, 'add']);
|
$app->post('/add[/]', [CentrosCostos::class, 'add']);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\API\Nubox;
|
|
||||||
|
use Incoviba\Controller\API\Contabilidad\Nubox;
|
||||||
|
|
||||||
$app->group('/nubox/{inmobiliaria_rut}', function($app) {
|
$app->group('/nubox/{inmobiliaria_rut}', function($app) {
|
||||||
$app->get('/token[/]', [Nubox::class, 'token']);
|
$app->get('/token[/]', [Nubox::class, 'token']);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\CentrosCostos;
|
|
||||||
|
use Incoviba\Controller\Contabilidad\CentrosCostos;
|
||||||
|
|
||||||
$app->group('/centros_costos', function($app) {
|
$app->group('/centros_costos', function($app) {
|
||||||
$app->get('/asignar[/]', [CentrosCostos::class, 'asignar']);
|
$app->get('/asignar[/]', [CentrosCostos::class, 'asignar']);
|
||||||
|
@ -14,9 +14,10 @@
|
|||||||
<i class="dropdown icon"></i>
|
<i class="dropdown icon"></i>
|
||||||
<div class="default text">Inmobiliaria</div>
|
<div class="default text">Inmobiliaria</div>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
@foreach ($inmobiliarias as $inmobiliaria)
|
@foreach ($inmobiliarias as $inmobiliaria)
|
||||||
<div class="item" data-value="{{$inmobiliaria->rut}}">{{$inmobiliaria->razon}}</div>
|
<div class="item"
|
||||||
@endforeach
|
data-value="{{$inmobiliaria->rut}}">{{$inmobiliaria->razon}}</div>
|
||||||
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -40,7 +41,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="file">Cartola</label>
|
<label for="file">Cartola</label>
|
||||||
<input type="file" name="file" id="file" class="ui invisible file input" />
|
<input type="file" name="file" id="file" class="ui invisible file input"/>
|
||||||
<label for="file" class="ui icon button">
|
<label for="file" class="ui icon button">
|
||||||
<i class="file icon"></i>
|
<i class="file icon"></i>
|
||||||
Cargar
|
Cargar
|
||||||
@ -119,20 +120,20 @@
|
|||||||
mes: '',
|
mes: '',
|
||||||
movimientos: [],
|
movimientos: [],
|
||||||
centrosCostos: {
|
centrosCostos: {
|
||||||
ingresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\CentroCosto $centroCosto) {
|
ingresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\Contabilidad\CentroCosto $centroCosto) {
|
||||||
return [
|
return [
|
||||||
'id' => $centroCosto->id,
|
'id' => $centroCosto->id,
|
||||||
'descripcion' => $centroCosto->descripcion
|
'descripcion' => $centroCosto->descripcion
|
||||||
];
|
];
|
||||||
}, array_filter($centrosCostos, function(\Incoviba\Model\CentroCosto $centroCosto) {
|
}, array_filter($centrosCostos, function(\Incoviba\Model\Contabilidad\CentroCosto $centroCosto) {
|
||||||
return $centroCosto->tipoCentro->descripcion === 'Ingreso';
|
return $centroCosto->tipoCentro->descripcion === 'Ingreso';
|
||||||
})))) !!}'),
|
})))) !!}'),
|
||||||
egresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\CentroCosto $centroCosto) {
|
egresos: JSON.parse('{!! json_encode(array_values(array_map(function(\Incoviba\Model\Contabilidad\CentroCosto $centroCosto) {
|
||||||
return [
|
return [
|
||||||
'id' => $centroCosto->id,
|
'id' => $centroCosto->id,
|
||||||
'descripcion' => $centroCosto->descripcion
|
'descripcion' => $centroCosto->descripcion
|
||||||
];
|
];
|
||||||
}, array_filter($centrosCostos, function(\Incoviba\Model\CentroCosto $centroCosto) {
|
}, array_filter($centrosCostos, function(\Incoviba\Model\Contabilidad\CentroCosto $centroCosto) {
|
||||||
return $centroCosto->tipoCentro->descripcion === 'Egreso';
|
return $centroCosto->tipoCentro->descripcion === 'Egreso';
|
||||||
})))) !!}'),
|
})))) !!}'),
|
||||||
}
|
}
|
||||||
@ -170,7 +171,11 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
$(this.ids.form.banco).dropdown('change values', json.cuentas.map(cuenta => {
|
$(this.ids.form.banco).dropdown('change values', json.cuentas.map(cuenta => {
|
||||||
return {value: cuenta.banco.id, text: cuenta.banco.nombre, name: cuenta.banco.nombre}
|
return {
|
||||||
|
value: cuenta.banco.id,
|
||||||
|
text: cuenta.banco.nombre,
|
||||||
|
name: cuenta.banco.nombre
|
||||||
|
}
|
||||||
})).dropdown('refresh')
|
})).dropdown('refresh')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -247,12 +252,12 @@
|
|||||||
const movimientos = this.data.movimientos.map((movimiento, idx) => {
|
const movimientos = this.data.movimientos.map((movimiento, idx) => {
|
||||||
const temp = structuredClone(movimiento)
|
const temp = structuredClone(movimiento)
|
||||||
temp.fecha = movimiento.fecha.toISOString()
|
temp.fecha = movimiento.fecha.toISOString()
|
||||||
let centro = $(".centro[data-index='" + (idx+1) + "']").dropdown('get value')
|
let centro = $(".centro[data-index='" + (idx + 1) + "']").dropdown('get value')
|
||||||
if (centro.length === 0) {
|
if (centro.length === 0) {
|
||||||
centro = ''
|
centro = ''
|
||||||
}
|
}
|
||||||
temp.centro_costo = centro
|
temp.centro_costo = centro
|
||||||
let detalle = $("[name='detalle" + (idx+1) + "']").val()
|
let detalle = $("[name='detalle" + (idx + 1) + "']").val()
|
||||||
if (typeof detalle === 'undefined') {
|
if (typeof detalle === 'undefined') {
|
||||||
detalle = ''
|
detalle = ''
|
||||||
}
|
}
|
||||||
@ -294,7 +299,10 @@
|
|||||||
month: 'numeric',
|
month: 'numeric',
|
||||||
day: 'numeric'
|
day: 'numeric'
|
||||||
})
|
})
|
||||||
const numberFormatter = new Intl.NumberFormat('es-CL', {minimumFractionDigits: 0, maximumFractionDigits: 0})
|
const numberFormatter = new Intl.NumberFormat('es-CL', {
|
||||||
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 0
|
||||||
|
})
|
||||||
this.data.movimientos.forEach((row, idx) => {
|
this.data.movimientos.forEach((row, idx) => {
|
||||||
tbody.append(
|
tbody.append(
|
||||||
$('<tr></tr>').append(
|
$('<tr></tr>').append(
|
||||||
@ -322,7 +330,7 @@
|
|||||||
})
|
})
|
||||||
table.DataTable(this.dataTableConfig)
|
table.DataTable(this.dataTableConfig)
|
||||||
},
|
},
|
||||||
centrosDropdown: (idx, ingreso=true) => {
|
centrosDropdown: (idx, ingreso = true) => {
|
||||||
const menu = $('<div></div>').addClass('menu')
|
const menu = $('<div></div>').addClass('menu')
|
||||||
let centros = this.data.centrosCostos.ingresos
|
let centros = this.data.centrosCostos.ingresos
|
||||||
if (!ingreso) {
|
if (!ingreso) {
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
@extends('layout.base')
|
@extends('layout.base')
|
||||||
|
|
||||||
|
@push('page_styles')
|
||||||
|
<style>
|
||||||
|
tr.bold>th {
|
||||||
|
font-weight: bold !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@endpush
|
||||||
|
|
||||||
@section('page_content')
|
@section('page_content')
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
<h1 class="ui centered header">Informe de Tesorería</h1>
|
<h1 class="ui centered header">Informe de Tesorería</h1>
|
||||||
|
@ -10,11 +10,6 @@
|
|||||||
<div class="column">
|
<div class="column">
|
||||||
Inmobiliarias
|
Inmobiliarias
|
||||||
</div>
|
</div>
|
||||||
{{--<div class="right aligned column">
|
|
||||||
<button class="ui icon button" type="button">
|
|
||||||
<i class="plus icon"></i>
|
|
||||||
</button>
|
|
||||||
</div>--}}
|
|
||||||
</h2>
|
</h2>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
<div class="ui cards">
|
<div class="ui cards">
|
||||||
@ -22,9 +17,7 @@
|
|||||||
<div class="ui card">
|
<div class="ui card">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{$inmobiliaria->abreviacion}}
|
{{$inmobiliaria->abreviacion}}
|
||||||
{{--<a href="{{$urls->base}}/inmobiliaria/{{$inmobiliaria->rut}}">
|
|
||||||
</a>--}}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad->descripcion}}</div>
|
<div class="description">{{$inmobiliaria->razon}} {{$inmobiliaria->tipoSociedad->descripcion}}</div>
|
||||||
<div class="meta">{{$inmobiliaria->rut()}}</div>
|
<div class="meta">{{$inmobiliaria->rut()}}</div>
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
function cleanNoCache() {
|
||||||
|
const url = new URL(window.location.href)
|
||||||
|
if (url.searchParams.has('nocache')) {
|
||||||
|
url.searchParams.delete('nocache')
|
||||||
|
window.location.href = url.href
|
||||||
|
}
|
||||||
|
}
|
||||||
function fetchAPI(url, options=null) {
|
function fetchAPI(url, options=null) {
|
||||||
if (options === null) {
|
if (options === null) {
|
||||||
options = {}
|
options = {}
|
||||||
@ -10,7 +17,11 @@
|
|||||||
options['headers'] = {}
|
options['headers'] = {}
|
||||||
}
|
}
|
||||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
|
@if (!$login->isIn())
|
||||||
|
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
|
||||||
|
@else
|
||||||
|
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}{{$login->getSeparator()}}{{$login->getToken()}}'
|
||||||
|
@endif
|
||||||
}
|
}
|
||||||
return fetch(url, options).then(response => {
|
return fetch(url, options).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@ -36,6 +47,7 @@
|
|||||||
date: 'DD-MM-YYYY'
|
date: 'DD-MM-YYYY'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
cleanNoCache()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@stack('page_scripts')
|
@stack('page_scripts')
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
@push('page_scripts')
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js" integrity="sha512-a+SUDuwNzXDvz4XrIcXHuCf089/iJAoN4lmrXJg18XnduKK6YlDHNRalv4yd1N40OKI80tFidF+rqTFKGPoWFQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||||
|
@endpush
|
@ -16,28 +16,33 @@
|
|||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
@include('layout.body.scripts.cryptojs')
|
||||||
|
|
||||||
@push('page_scripts')
|
@push('page_scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
function encryptPassword(password) {
|
||||||
|
const passphrase = Math.floor(Math.random() * Date.now()).toString()
|
||||||
|
const encrypted = CryptoJS.AES.encrypt(password, passphrase)
|
||||||
|
return [passphrase, encrypted.toString()].join('')
|
||||||
|
}
|
||||||
function sendLogin(name, password) {
|
function sendLogin(name, password) {
|
||||||
const data = new FormData()
|
const method = 'post'
|
||||||
data.append('name', name)
|
const headers = {
|
||||||
data.append('password', password)
|
Accept: 'json'
|
||||||
return fetch('{{$urls->base}}/login', {
|
}
|
||||||
method: 'post',
|
const body = new FormData()
|
||||||
headers: {
|
body.append('name', name)
|
||||||
Accept: 'json'
|
body.append('password', encryptPassword(password))
|
||||||
},
|
return fetch('{{$urls->base}}/login', {method, headers, body}).then(response => {
|
||||||
body: data
|
|
||||||
}).then(response => {
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return response.json()
|
||||||
}
|
}
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
if (data.login === true) {
|
if (data.login === true) {
|
||||||
@if(isset($redirect_uri))
|
@if(isset($redirect_uri))
|
||||||
window.location = '{{$redirect_uri}}'
|
window.location = '{{$redirect_uri}}?nocache=' + (new Date()).getTime()
|
||||||
@else
|
@else
|
||||||
window.location = '{{$urls->base}}'
|
window.location = '{{$urls->base}}?nocache=' + (new Date()).getTime()
|
||||||
@endif
|
@endif
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -5,6 +5,29 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('venta_content')
|
@section('venta_content')
|
||||||
|
@if (count($asociadas) > 0)
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="two wide column">Asociados</div>
|
||||||
|
<div class="six wide column">
|
||||||
|
{!! implode(' - ', array_map(function(Incoviba\Model\Venta $venta) use ($urls) {
|
||||||
|
return "<a href=\"{$urls->base}/venta/{$venta->id}\">{$venta->propiedad()->departamentos()[0]->descripcion}</a>";
|
||||||
|
}, $asociadas)) !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="column">Valor</div>
|
||||||
|
<div class="four wide column">
|
||||||
|
{{$format->ufs($venta->formaPago()->pie->valor)}}
|
||||||
|
@if (count($asociadas) > 0)
|
||||||
|
[{{$format->ufs($venta->formaPago()->pie->valor + array_reduce($asociadas, function(float $sum, Incoviba\Model\Venta $venta) {
|
||||||
|
return $sum + $venta->formaPago()->pie->valor;
|
||||||
|
}, 0.0))}}]
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
<div class="column">Cuotas</div>
|
||||||
|
<div class="column">{{$venta->formaPago()->pie->cuotas}}</div>
|
||||||
|
</div>
|
||||||
<table class="ui table" id="cuotas">
|
<table class="ui table" id="cuotas">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -37,8 +60,10 @@
|
|||||||
<td>{{$cuota->pago->identificador}}</td>
|
<td>{{$cuota->pago->identificador}}</td>
|
||||||
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
|
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
|
||||||
<td class="right aligned">
|
<td class="right aligned">
|
||||||
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now)
|
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado']) and $cuota->pago->currentEstado->fecha <= $now)
|
||||||
{{$format->ufs($cuota->pago->valor())}}
|
{{$format->ufs($cuota->pago->valor())}}
|
||||||
|
@else
|
||||||
|
~{{$format->ufs($cuota->pago->valor / $uf_venta)}}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td
|
||||||
@ -115,7 +140,7 @@
|
|||||||
}, 0.0))}}
|
}, 0.0))}}
|
||||||
</th>
|
</th>
|
||||||
<th class="right aligned">
|
<th class="right aligned">
|
||||||
{{$format->number($pagado / $total * 100, 2)}}%
|
{{$format->number(($total > 0) ? $pagado / $total * 100 : 0, 2)}}%
|
||||||
</th>
|
</th>
|
||||||
<th colspan="3"></th>
|
<th colspan="3"></th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -128,7 +153,7 @@
|
|||||||
{{$format->ufs($total - $pagado)}}
|
{{$format->ufs($total - $pagado)}}
|
||||||
</th>
|
</th>
|
||||||
<th class="right aligned">
|
<th class="right aligned">
|
||||||
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
|
{{$format->number(($total > 0) ? ($total - $pagado) / $total * 100 : 0, 2)}}%
|
||||||
</th>
|
</th>
|
||||||
<th colspan="3"></th>
|
<th colspan="3"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="right aligned">
|
<td class="right aligned">
|
||||||
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
|
@if ($unidad->proyectoTipoUnidad->tipoUnidad->descripcion === 'departamento')
|
||||||
{{$format->number(($unidad->valor ?? $precio) / $unidad->proyectoTipoUnidad->vendible(), 2)}} UF/m²
|
{{$format->number((($unidad->valor === null or $unidad->valor === 0.0) ? $precio : $unidad->valor) / $unidad->proyectoTipoUnidad->vendible(), 2)}} UF/m²
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td class="center aligned">
|
<td class="center aligned">
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
<?php
|
<?php
|
||||||
//$app->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
$app->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
||||||
|
2
app/setup/middlewares/96_cors.php
Normal file
2
app/setup/middlewares/96_cors.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
$app->add($app->getContainer()->get(Incoviba\Middleware\CORS::class));
|
@ -14,6 +14,7 @@ return [
|
|||||||
Incoviba\Middleware\API::class => function(ContainerInterface $container) {
|
Incoviba\Middleware\API::class => function(ContainerInterface $container) {
|
||||||
return new Incoviba\Middleware\API(
|
return new Incoviba\Middleware\API(
|
||||||
$container->get(Psr\Http\Message\ResponseFactoryInterface::class),
|
$container->get(Psr\Http\Message\ResponseFactoryInterface::class),
|
||||||
|
$container->get(Incoviba\Service\Login::class),
|
||||||
$container->get('API_KEY')
|
$container->get('API_KEY')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ return [
|
|||||||
$container->get('COOKIE_NAME'),
|
$container->get('COOKIE_NAME'),
|
||||||
$container->get('MAX_LOGIN_HOURS'),
|
$container->get('MAX_LOGIN_HOURS'),
|
||||||
$container->has('COOKIE_DOMAIN') ? $container->get('COOKIE_DOMAIN') : '',
|
$container->has('COOKIE_DOMAIN') ? $container->get('COOKIE_DOMAIN') : '',
|
||||||
$container->has('COOKIE_PATH') ? $container->get('COOKIE_PATH') : ''
|
$container->has('COOKIE_PATH') ? $container->get('COOKIE_PATH') : '',
|
||||||
|
$container->has('COOKIE_SEPARATOR') ? $container->get('COOKIE_SEPARATOR') : 'g'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Incoviba\Service\Money::class => function(ContainerInterface $container) {
|
Incoviba\Service\Money::class => function(ContainerInterface $container) {
|
||||||
@ -32,32 +33,33 @@ return [
|
|||||||
'port' => $container->get('REDIS_PORT')
|
'port' => $container->get('REDIS_PORT')
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
Incoviba\Service\Cartola::class => function(ContainerInterface $container) {
|
\Incoviba\Service\Contabilidad\Cartola::class => function(ContainerInterface $container) {
|
||||||
return (new Incoviba\Service\Cartola(
|
return (new \Incoviba\Service\Contabilidad\Cartola(
|
||||||
$container->get(Psr\Log\LoggerInterface::class),
|
$container->get(Psr\Log\LoggerInterface::class),
|
||||||
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
|
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
|
||||||
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class),
|
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class),
|
||||||
$container->get(Incoviba\Repository\Inmobiliaria::class),
|
$container->get(Incoviba\Repository\Inmobiliaria::class),
|
||||||
$container->get(Incoviba\Repository\Inmobiliaria\Cuenta::class),
|
$container->get(Incoviba\Repository\Inmobiliaria\Cuenta::class),
|
||||||
$container->get(Incoviba\Repository\Movimiento::class),
|
$container->get(\Incoviba\Repository\Contabilidad\Movimiento::class),
|
||||||
$container->get(Incoviba\Service\Movimiento::class),
|
$container->get(\Incoviba\Service\Contabilidad\Movimiento::class),
|
||||||
$container->get(Incoviba\Repository\Cartola::class)
|
$container->get(\Incoviba\Repository\Contabilidad\Cartola::class)
|
||||||
))
|
))
|
||||||
->register('security', $container->get(Incoviba\Service\Cartola\Security::class))
|
->register('security', $container->get(\Incoviba\Service\Contabilidad\Cartola\Security::class))
|
||||||
->register('itau', $container->get(Incoviba\Service\Cartola\Itau::class))
|
->register('itau', $container->get(\Incoviba\Service\Contabilidad\Cartola\Itau::class))
|
||||||
->register('santander', $container->get(Incoviba\Service\Cartola\Santander::class));
|
->register('santander', $container->get(\Incoviba\Service\Contabilidad\Cartola\Santander::class))
|
||||||
|
->register('bci', $container->get(\Incoviba\Service\Contabilidad\Cartola\BCI::class));
|
||||||
},
|
},
|
||||||
Incoviba\Common\Define\Contabilidad\Exporter::class => function(ContainerInterface $container) {
|
Incoviba\Common\Define\Contabilidad\Exporter::class => function(ContainerInterface $container) {
|
||||||
return $container->get(Incoviba\Service\Contabilidad\Exporter\Nubox::class);
|
return $container->get(Incoviba\Service\Contabilidad\Exporter\Nubox::class);
|
||||||
},
|
},
|
||||||
Incoviba\Service\Contabilidad\Exporter\Nubox::class => function(ContainerInterface $container) {
|
Incoviba\Service\Contabilidad\Exporter\Nubox::class => function(ContainerInterface $container) {
|
||||||
return new Incoviba\Service\Contabilidad\Exporter\Nubox($container->get(Incoviba\Repository\CentroCosto::class),
|
return new Incoviba\Service\Contabilidad\Exporter\Nubox($container->get(\Incoviba\Repository\Contabilidad\CentroCosto::class),
|
||||||
$container->get('folders')->get('uploads'));
|
$container->get('folders')->get('uploads'));
|
||||||
},
|
},
|
||||||
Incoviba\Service\Contabilidad\Nubox::class => function(ContainerInterface $container) {
|
Incoviba\Service\Contabilidad\Nubox::class => function(ContainerInterface $container) {
|
||||||
return new Incoviba\Service\Contabilidad\Nubox(
|
return new Incoviba\Service\Contabilidad\Nubox(
|
||||||
$container->get(Psr\Log\LoggerInterface::class),
|
$container->get(Psr\Log\LoggerInterface::class),
|
||||||
$container->get(Incoviba\Repository\Nubox::class),
|
$container->get(\Incoviba\Repository\Contabilidad\Nubox::class),
|
||||||
$container->get(Incoviba\Service\Redis::class),
|
$container->get(Incoviba\Service\Redis::class),
|
||||||
new GuzzleHttp\Client(),
|
new GuzzleHttp\Client(),
|
||||||
$container->get(Psr\Http\Message\RequestFactoryInterface::class),
|
$container->get(Psr\Http\Message\RequestFactoryInterface::class),
|
||||||
|
20
app/src/Controller/API/Base.php
Normal file
20
app/src/Controller/API/Base.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\API;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
|
|
||||||
|
class Base extends Controller
|
||||||
|
{
|
||||||
|
use withJson;
|
||||||
|
|
||||||
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||||
|
{
|
||||||
|
$output = [
|
||||||
|
'version' => '2.0.0',
|
||||||
|
'organization' => 'Ingenieria y Construccion Vial Balmaceda Sociedad Anonima'
|
||||||
|
];
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API\Contabilidad;
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Incoviba\Common\Ideal\Controller;
|
use Incoviba\Common\Ideal\Controller;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Cartolas extends Controller
|
class Cartolas extends Controller
|
||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
public function procesar(ServerRequestInterface $request, ResponseInterface $response,
|
public function procesar(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
Repository\Banco $bancoRepository,
|
Repository\Contabilidad\Banco $bancoRepository,
|
||||||
Service\Cartola $cartolaService): ResponseInterface
|
Service\Contabilidad\Cartola $cartolaService): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -34,10 +33,10 @@ class Cartolas extends Controller
|
|||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function exportar(ServerRequestInterface $request, ResponseInterface $response,
|
public function exportar(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
Repository\Banco $bancoRepository,
|
Repository\Contabilidad\Banco $bancoRepository,
|
||||||
Service\Cartola $cartolaService): ResponseInterface
|
Service\Contabilidad\Cartola $cartolaService): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -52,9 +51,9 @@ class Cartolas extends Controller
|
|||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function diaria(ServerRequestInterface $request, ResponseInterface $response,
|
public function diaria(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
Service\Cartola $cartolaService): ResponseInterface
|
Service\Contabilidad\Cartola $cartolaService): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -80,9 +79,9 @@ class Cartolas extends Controller
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function ayer(ServerRequestInterface $request, ResponseInterface $response,
|
public function ayer(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
Repository\Cartola $cartolaRepository): ResponseInterface
|
Repository\Contabilidad\Cartola $cartolaRepository): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API;
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Controller\API\withJson;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class CentrosCostos
|
class CentrosCostos
|
||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\CentroCosto $centroCostoRepository): ResponseInterface
|
Repository\Contabilidad\CentroCosto $centroCostoRepository): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -26,8 +27,8 @@ class CentrosCostos
|
|||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
Repository\Contabilidad\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -45,8 +46,8 @@ class CentrosCostos
|
|||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function remove(ServerRequestInterface $request, ResponseInterface $response,
|
public function remove(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
Repository\Contabilidad\CentroCosto $centroCostoRepository, int $centro_costo_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$output = [
|
$output = [
|
||||||
'centro_costo_id' => $centro_costo_id,
|
'centro_costo_id' => $centro_costo_id,
|
@ -2,23 +2,23 @@
|
|||||||
namespace Incoviba\Controller\API\Contabilidad;
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Depositos extends Ideal\Controller
|
class Depositos extends Ideal\Controller
|
||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
public function inmobiliaria(ServerRequestInterface $request, ResponseInterface $response,
|
public function inmobiliaria(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
Repository\Banco $bancoRepository,
|
Repository\Contabilidad\Banco $bancoRepository,
|
||||||
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
Repository\Deposito $dapRepository,
|
Repository\Contabilidad\Deposito $dapRepository,
|
||||||
int $inmobiliaria_rut): ResponseInterface
|
int $inmobiliaria_rut): ResponseInterface
|
||||||
{
|
{
|
||||||
$output = [
|
$output = [
|
||||||
'inmobiliaria_rut' => $inmobiliaria_rut,
|
'inmobiliaria_rut' => $inmobiliaria_rut,
|
||||||
@ -33,10 +33,10 @@ class Depositos extends Ideal\Controller
|
|||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository, Repository\Banco $bancoRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository, Repository\Contabilidad\Banco $bancoRepository,
|
||||||
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
Repository\Deposito $dapRepository): ResponseInterface
|
Repository\Contabilidad\Deposito $dapRepository): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API\Contabilidad;
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Incoviba\Common\Ideal;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Controller\API\withJson;
|
use Incoviba\Controller\API\withJson;
|
||||||
use Incoviba\Common\Ideal;
|
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Movimientos extends Ideal\Controller
|
class Movimientos extends Ideal\Controller
|
||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
public function detalles(ServerRequestInterface $request, ResponseInterface $response,
|
public function detalles(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Service\Movimiento $movimientoService,
|
Service\Contabilidad\Movimiento $movimientoService,
|
||||||
Repository\CentroCosto $centroCostoRepository, int $movimiento_id): ResponseInterface
|
Repository\Contabilidad\CentroCosto $centroCostoRepository, int $movimiento_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\API;
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Common\Implement\Exception\HttpResponse;
|
||||||
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Service;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Implement\Exception\HttpResponse;
|
|
||||||
use Incoviba\Service;
|
|
||||||
|
|
||||||
class Nubox
|
class Nubox
|
||||||
{
|
{
|
@ -12,6 +12,16 @@ class Inmobiliarias
|
|||||||
{
|
{
|
||||||
use withJson;
|
use withJson;
|
||||||
|
|
||||||
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$output = [
|
||||||
|
'inmobiliarias' => []
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$output['inmobiliarias'] = $inmobiliariaRepository->fetchAll('razon');
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
public function cuentas(ServerRequestInterface $request, ResponseInterface $response,
|
public function cuentas(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
Repository\Inmobiliaria\Cuenta $cuentaRepository, int $inmobiliaria_rut): ResponseInterface
|
Repository\Inmobiliaria\Cuenta $cuentaRepository, int $inmobiliaria_rut): ResponseInterface
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
<?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'));
|
|
||||||
}
|
|
||||||
public function asignar(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
|
||||||
Repository\CentroCosto $centroCostoRepository,
|
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
|
||||||
{
|
|
||||||
$centrosCostos = $centroCostoRepository->fetchAll();
|
|
||||||
$inmobiliarias = $inmobiliariaRepository->fetchAllActive('razon');
|
|
||||||
return $view->render($response, 'contabilidad.centros_costos.asignar', compact('centrosCostos', 'inmobiliarias'));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller;
|
namespace Incoviba\Controller;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Incoviba\Common\Ideal\Controller;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
use Incoviba\Common\Implement\Exception\{EmptyResult, EmptyRedis};
|
use Incoviba\Common\Ideal\Controller;
|
||||||
|
use Incoviba\Common\Implement\Exception\{EmptyRedis, EmptyResult};
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Contabilidad extends Controller
|
class Contabilidad extends Controller
|
||||||
{
|
{
|
||||||
use withRedis;
|
use withRedis;
|
||||||
|
|
||||||
public function diaria(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
public function diaria(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
Service\Redis $redisService,
|
Service\Redis $redisService,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
Repository\CentroCosto $centroCostoRepository): ResponseInterface
|
Repository\Contabilidad\CentroCosto $centroCostoRepository): ResponseInterface
|
||||||
{
|
{
|
||||||
$redisKey = 'inmobiliarias';
|
$redisKey = 'inmobiliarias';
|
||||||
$inmobiliarias = [];
|
$inmobiliarias = [];
|
||||||
@ -27,17 +27,17 @@ class Contabilidad extends Controller
|
|||||||
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
|
$inmobiliarias = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
try {
|
try {
|
||||||
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
$inmobiliarias = $inmobiliariaRepository->fetchAll('razon');
|
||||||
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
|
$this->saveRedis($redisService, $redisKey, $inmobiliarias, 30 * 24 * 60 * 60);
|
||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
}
|
}
|
||||||
$centrosCostos = $centroCostoRepository->fetchAll();
|
$centrosCostos = $centroCostoRepository->fetchAll();
|
||||||
return $view->render($response, 'contabilidad.cartolas.diaria', compact('inmobiliarias', 'centrosCostos'));
|
return $view->render($response, 'contabilidad.cartolas.diaria', compact('inmobiliarias', 'centrosCostos'));
|
||||||
}
|
}
|
||||||
public function depositos(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
public function depositos(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
Service\Redis $redisService,
|
Service\Redis $redisService,
|
||||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
Repository\Deposito $dapRepository): ResponseInterface
|
Repository\Contabilidad\Deposito $dapRepository): ResponseInterface
|
||||||
{
|
{
|
||||||
$redisKey = 'inmobiliarias';
|
$redisKey = 'inmobiliarias';
|
||||||
$inmobiliarias = [];
|
$inmobiliarias = [];
|
||||||
@ -54,11 +54,11 @@ class Contabilidad extends Controller
|
|||||||
$depositos = $dapRepository->fetchAll();
|
$depositos = $dapRepository->fetchAll();
|
||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
$fecha = new DateTimeImmutable('today');
|
$fecha = new DateTimeImmutable('today');
|
||||||
$activos = array_filter($depositos, function(Model\Deposito $deposito) use ($fecha) {
|
$activos = array_filter($depositos, function(Model\Contabilidad\Deposito $deposito) use ($fecha) {
|
||||||
return $deposito->termino >= $fecha;
|
return $deposito->termino >= $fecha;
|
||||||
});
|
});
|
||||||
$mes = $fecha->sub(new DateInterval('P1M'));
|
$mes = $fecha->sub(new DateInterval('P1M'));
|
||||||
$vencidos = array_filter($depositos, function(Model\Deposito $deposito) use ($fecha, $mes) {
|
$vencidos = array_filter($depositos, function(Model\Contabilidad\Deposito $deposito) use ($fecha, $mes) {
|
||||||
return $deposito->termino < $fecha and $deposito->termino >= $mes;
|
return $deposito->termino < $fecha and $deposito->termino >= $mes;
|
||||||
});
|
});
|
||||||
return $view->render($response, 'contabilidad.depositos', compact('inmobiliarias', 'activos', 'vencidos'));
|
return $view->render($response, 'contabilidad.depositos', compact('inmobiliarias', 'activos', 'vencidos'));
|
||||||
@ -73,4 +73,13 @@ class Contabilidad extends Controller
|
|||||||
$filename = "Informe de Tesorería {$fecha->format('d.m.Y')}";
|
$filename = "Informe de Tesorería {$fecha->format('d.m.Y')}";
|
||||||
return $view->render($response, 'contabilidad.informes.tesoreria', compact('fecha', 'anterior', 'informes', 'filename'));
|
return $view->render($response, 'contabilidad.informes.tesoreria', compact('fecha', 'anterior', 'informes', 'filename'));
|
||||||
}
|
}
|
||||||
|
public function cuadratura(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$inmobiliarias = [];
|
||||||
|
try {
|
||||||
|
$inmobiliarias = $inmobiliariaRepository->fetchAll('razon');
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $view->render($response, 'contabilidad.cuadratura', compact('inmobiliarias'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
32
app/src/Controller/Contabilidad/CentrosCostos.php
Normal file
32
app/src/Controller/Contabilidad/CentrosCostos.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\Contabilidad;
|
||||||
|
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
class CentrosCostos
|
||||||
|
{
|
||||||
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Repository\Contabilidad\CentroCosto $centroCostoRepository,
|
||||||
|
Repository\Contabilidad\TipoCentro $tipoCentroRepository,
|
||||||
|
Repository\Contabilidad\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'));
|
||||||
|
}
|
||||||
|
public function asignar(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
|
Repository\Contabilidad\CentroCosto $centroCostoRepository,
|
||||||
|
Repository\Inmobiliaria $inmobiliariaRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$centrosCostos = $centroCostoRepository->fetchAll();
|
||||||
|
$inmobiliarias = $inmobiliariaRepository->fetchAllActive('razon');
|
||||||
|
return $view->render($response, 'contabilidad.centros_costos.asignar', compact('centrosCostos', 'inmobiliarias'));
|
||||||
|
}
|
||||||
|
}
|
@ -20,8 +20,8 @@ class Inmobiliarias
|
|||||||
$inmobiliarias = [];
|
$inmobiliarias = [];
|
||||||
try {
|
try {
|
||||||
$inmobiliarias = array_map(function($row) use ($inmobiliariaRepository) {
|
$inmobiliarias = array_map(function($row) use ($inmobiliariaRepository) {
|
||||||
return $inmobiliariaRepository->load((array) $row);
|
return $inmobiliariaRepository->load($row);
|
||||||
}, $this->fetchRedis($redisService, $redisKey));
|
}, $this->fetchRedis($redisService, $redisKey, true));
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
try {
|
try {
|
||||||
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
$inmobiliarias = $inmobiliariaRepository->fetchAll();
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller;
|
namespace Incoviba\Controller;
|
||||||
|
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Ideal\Controller;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
|
||||||
class Login
|
class Login extends Controller
|
||||||
{
|
{
|
||||||
public function form(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
|
public function form(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Login $service): ResponseInterface
|
||||||
{
|
{
|
||||||
@ -20,14 +22,17 @@ class Login
|
|||||||
public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface
|
public function login(ServerRequestInterface $request, ResponseInterface $response, Repository\User $userRepository, Service\Login $service): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$user = $userRepository->fetchByName($body['name']);
|
|
||||||
$output = [
|
$output = [
|
||||||
'name' => $user->name,
|
'name' => $body['name'],
|
||||||
'login' => false
|
'login' => false
|
||||||
];
|
];
|
||||||
if ($user->validate($body['password'])) {
|
|
||||||
$output['login'] = $service->login($user);
|
try {
|
||||||
}
|
$user = $userRepository->fetchByName($body['name']);
|
||||||
|
if ($service->validateUser($user, $body['password'])) {
|
||||||
|
$output['login'] = $service->login($user);
|
||||||
|
}
|
||||||
|
} catch (EmptyResult) {}
|
||||||
$response->getBody()->write(json_encode($output));
|
$response->getBody()->write(json_encode($output));
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller;
|
namespace Incoviba\Controller;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Ventas
|
class Ventas
|
||||||
{
|
{
|
||||||
@ -98,17 +98,28 @@ class Ventas
|
|||||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||||
}
|
}
|
||||||
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||||
|
Repository\Venta $ventaRepository,
|
||||||
View $view, int $venta_id): ResponseInterface
|
View $view, int $venta_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$venta = $ventaService->getById($venta_id);
|
$venta = $ventaService->getById($venta_id);
|
||||||
return $view->render($response, 'ventas.pies.cuotas', compact('venta'));
|
$asociadas = [];
|
||||||
|
if (isset($venta->formaPago()->pie->asociado)) {
|
||||||
|
$asociadas []= $ventaService->getByPie($venta->formaPago()->pie->asociado->id);
|
||||||
|
foreach ($venta->formaPago()->pie->asociado->asociados() as $asociado) {
|
||||||
|
if ($venta->formaPago()->pie->id === $asociado->id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$asociadas []= $ventaService->getByPie($asociado->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas'));
|
||||||
}
|
}
|
||||||
public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||||
Repository\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface
|
Repository\Contabilidad\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$venta = $ventaService->getById($venta_id);
|
$venta = $ventaService->getById($venta_id);
|
||||||
$bancos = $bancoRepository->fetchAll();
|
$bancos = $bancoRepository->fetchAll();
|
||||||
usort($bancos, function(Model\Banco $a, Model\Banco $b) {
|
usort($bancos, function(Model\Contabilidad\Banco $a, Model\Contabilidad\Banco $b) {
|
||||||
return strcmp($a->nombre, $b->nombre);
|
return strcmp($a->nombre, $b->nombre);
|
||||||
});
|
});
|
||||||
return $view->render($response, 'ventas.escriturar', compact('venta', 'bancos'));
|
return $view->render($response, 'ventas.escriturar', compact('venta', 'bancos'));
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\Ventas;
|
namespace Incoviba\Controller\Ventas;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
use Incoviba\Common\Ideal\Controller;
|
use Incoviba\Common\Ideal\Controller;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Creditos extends Controller
|
class Creditos extends Controller
|
||||||
{
|
{
|
||||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
Repository\Venta $ventaRepository, Repository\Banco $bancoRepository,
|
Service\Venta $ventaService, Repository\Contabilidad\Banco $bancoRepository,
|
||||||
int $venta_id): ResponseInterface
|
int $venta_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$venta = $ventaRepository->fetchById($venta_id);
|
$venta = $ventaService->getById($venta_id);
|
||||||
$bancos = $bancoRepository->fetchAll('nombre');
|
$bancos = $bancoRepository->fetchAll('nombre');
|
||||||
return $view->render($response, 'ventas.creditos', compact('venta', 'bancos'));
|
return $view->render($response, 'ventas.creditos', compact('venta', 'bancos'));
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
namespace Incoviba\Controller\Ventas;
|
namespace Incoviba\Controller\Ventas;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
use Incoviba\Model;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Cuotas
|
class Cuotas
|
||||||
{
|
{
|
||||||
@ -73,12 +73,12 @@ class Cuotas
|
|||||||
$response->getBody()->write(json_encode($output));
|
$response->getBody()->write(json_encode($output));
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, Repository\Banco $bancoRepository, View $view, int $pie_id): ResponseInterface
|
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, Repository\Contabilidad\Banco $bancoRepository, View $view, int $pie_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$pie = $pieService->getById($pie_id);
|
$pie = $pieService->getById($pie_id);
|
||||||
$venta = $ventaRepository->fetchByPie($pie_id);
|
$venta = $ventaRepository->fetchByPie($pie_id);
|
||||||
$bancos = $bancoRepository->fetchAll();
|
$bancos = $bancoRepository->fetchAll();
|
||||||
usort($bancos, function(Model\Banco $a, Model\Banco $b) {
|
usort($bancos, function(Model\Contabilidad\Banco $a, Model\Contabilidad\Banco $b) {
|
||||||
return strcmp($a->nombre, $b->nombre);
|
return strcmp($a->nombre, $b->nombre);
|
||||||
});
|
});
|
||||||
return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos'));
|
return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos'));
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\Ventas;
|
namespace Incoviba\Controller\Ventas;
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class Escrituras
|
class Escrituras
|
||||||
{
|
{
|
||||||
@ -22,8 +22,8 @@ class Escrituras
|
|||||||
return $view->render($response, 'ventas.escrituras.informe', compact('venta'));
|
return $view->render($response, 'ventas.escrituras.informe', compact('venta'));
|
||||||
}
|
}
|
||||||
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||||
Service\Venta $ventaService, Repository\Banco $bancoRepository,
|
Service\Venta $ventaService, Repository\Contabilidad\Banco $bancoRepository,
|
||||||
int $venta_id): ResponseInterface
|
int $venta_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$venta = $ventaService->getById($venta_id);
|
$venta = $ventaService->getById($venta_id);
|
||||||
$bancos = $bancoRepository->fetchAll('nombre');
|
$bancos = $bancoRepository->fetchAll('nombre');
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Controller\Ventas;
|
namespace Incoviba\Controller\Ventas;
|
||||||
|
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Alias\View;
|
|
||||||
use Incoviba\Service;
|
|
||||||
use Incoviba\Repository;
|
|
||||||
use Incoviba\Model;
|
|
||||||
|
|
||||||
class Pies
|
class Pies
|
||||||
{
|
{
|
||||||
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, Repository\Banco $bancoRepository, View $view, int $pie_id): ResponseInterface
|
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService,
|
||||||
|
Repository\Venta $ventaRepository, Repository\Contabilidad\Banco $bancoRepository,
|
||||||
|
View $view, int $pie_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$pie = $pieService->getById($pie_id);
|
$pie = $pieService->getById($pie_id);
|
||||||
$venta = $ventaRepository->fetchByPie($pie_id);
|
$venta = $ventaRepository->fetchByPie($pie_id);
|
||||||
$bancos = $bancoRepository->fetchAll();
|
$bancos = $bancoRepository->fetchAll();
|
||||||
usort($bancos, function(Model\Banco $a, Model\Banco $b) {
|
usort($bancos, function(Model\Contabilidad\Banco $a, Model\Contabilidad\Banco $b) {
|
||||||
return strcmp($a->nombre, $b->nombre);
|
return strcmp($a->nombre, $b->nombre);
|
||||||
});
|
});
|
||||||
return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos'));
|
return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'ventaRepository'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@ use Incoviba\Service;
|
|||||||
|
|
||||||
trait withRedis
|
trait withRedis
|
||||||
{
|
{
|
||||||
public function fetchRedis(Service\Redis $redisService, string $redisKey): mixed
|
public function fetchRedis(Service\Redis $redisService, string $redisKey, ?bool $asArray = null): mixed
|
||||||
{
|
{
|
||||||
$jsonString = $redisService->get($redisKey);
|
$jsonString = $redisService->get($redisKey);
|
||||||
if ($jsonString === null) {
|
if ($jsonString === null) {
|
||||||
throw new EmptyRedis($redisKey);
|
throw new EmptyRedis($redisKey);
|
||||||
}
|
}
|
||||||
return json_decode($jsonString);
|
return json_decode($jsonString, $asArray);
|
||||||
}
|
}
|
||||||
public function saveRedis(Service\Redis $redisService, string $redisKey, mixed $value, ?int $expiration = null): void
|
public function saveRedis(Service\Redis $redisService, string $redisKey, mixed $value, ?int $expiration = null): void
|
||||||
{
|
{
|
||||||
|
@ -6,10 +6,12 @@ use Psr\Http\Message\ResponseInterface;
|
|||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
use Incoviba\Exception\MissingAuthorizationHeader;
|
use Incoviba\Exception\MissingAuthorizationHeader;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
class API
|
class API
|
||||||
{
|
{
|
||||||
public function __construct(protected ResponseFactoryInterface $responseFactory, protected string $key) {}
|
public function __construct(protected ResponseFactoryInterface $responseFactory, protected Service\Login $loginService,
|
||||||
|
protected string $key) {}
|
||||||
|
|
||||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
{
|
{
|
||||||
@ -18,7 +20,7 @@ class API
|
|||||||
} catch (MissingAuthorizationHeader $exception) {
|
} catch (MissingAuthorizationHeader $exception) {
|
||||||
return $this->responseFactory->createResponse(401);
|
return $this->responseFactory->createResponse(401);
|
||||||
}
|
}
|
||||||
if ($this->validate($key)) {
|
if ($this->validate($request, $key)) {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
}
|
}
|
||||||
return $this->responseFactory->createResponse(403);
|
return $this->responseFactory->createResponse(403);
|
||||||
@ -33,8 +35,26 @@ class API
|
|||||||
}
|
}
|
||||||
throw new MissingAuthorizationHeader();
|
throw new MissingAuthorizationHeader();
|
||||||
}
|
}
|
||||||
protected function validate($incoming_key): bool
|
protected function validate(ServerRequestInterface $request, $incoming_key): bool
|
||||||
{
|
{
|
||||||
|
if (str_contains($incoming_key, $this->loginService->getSeparator())) {
|
||||||
|
list($incoming_key, $selector, $token) = explode($this->loginService->getSeparator(), $incoming_key);
|
||||||
|
if (!$this->loginService->isIn()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$this->loginService->isIn() and !$this->validPermitted($request)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $incoming_key === md5($this->key);
|
return $incoming_key === md5($this->key);
|
||||||
}
|
}
|
||||||
|
protected function validPermitted(ServerRequestInterface $request): bool
|
||||||
|
{
|
||||||
|
$uri = $request->getUri();
|
||||||
|
$validPaths = [
|
||||||
|
'/api',
|
||||||
|
'/api/'
|
||||||
|
];
|
||||||
|
return in_array($uri->getPath(), $validPaths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,13 +45,22 @@ class Authentication
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$valid_paths = [
|
$valid_paths = [
|
||||||
'/',
|
'/'
|
||||||
];
|
];
|
||||||
if (in_array($current_path, $valid_paths, true)) {
|
if (in_array($current_path, $valid_paths, true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
$valid_subpaths = [
|
||||||
|
'/api/'
|
||||||
|
];
|
||||||
|
foreach ($valid_subpaths as $path) {
|
||||||
|
if (str_starts_with($current_path, $path)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
$valid_uris = [
|
$valid_uris = [
|
||||||
$this->login_url,
|
$this->login_url,
|
||||||
|
"{$this->login_url}/",
|
||||||
];
|
];
|
||||||
if (in_array($current_url, $valid_uris, true)) {
|
if (in_array($current_url, $valid_uris, true)) {
|
||||||
return true;
|
return true;
|
||||||
|
21
app/src/Middleware/CORS.php
Normal file
21
app/src/Middleware/CORS.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Middleware;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseFactoryInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
|
||||||
|
class CORS
|
||||||
|
{
|
||||||
|
public function __construct(protected ResponseFactoryInterface $responseFactory) {}
|
||||||
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
|
{
|
||||||
|
if ($request->getMethod() === 'OPTIONS') {
|
||||||
|
return $this->responseFactory->createResponse()
|
||||||
|
->withHeader('Access-Control-Allow-Origin', '*')
|
||||||
|
->withHeader('Access-Control-Allow-Methods', 'POST,GET,OPTIONS');
|
||||||
|
}
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Incoviba\Model;
|
|
||||||
|
|
||||||
class CategoriaCentro extends Tipo
|
|
||||||
{}
|
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Ideal\Model;
|
use Incoviba\Common\Ideal\Model;
|
||||||
|
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model\Inmobiliaria;
|
||||||
|
|
||||||
class Cartola extends Ideal\Model
|
class Cartola extends Ideal\Model
|
||||||
{
|
{
|
7
app/src/Model/Contabilidad/CategoriaCentro.php
Normal file
7
app/src/Model/Contabilidad/CategoriaCentro.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
|
use Incoviba\Model\Tipo;
|
||||||
|
|
||||||
|
class CategoriaCentro extends Tipo
|
||||||
|
{}
|
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model\TipoCuenta;
|
||||||
|
|
||||||
class CentroCosto extends Ideal\Model
|
class CentroCosto extends Ideal\Model
|
||||||
{
|
{
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model\Inmobiliaria;
|
||||||
|
|
||||||
class Deposito extends Ideal\Model
|
class Deposito extends Ideal\Model
|
||||||
{
|
{
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Model\Inmobiliaria;
|
||||||
use Incoviba\Model\Movimiento\Detalle;
|
use Incoviba\Model\Movimiento\Detalle;
|
||||||
|
|
||||||
class Movimiento extends Ideal\Model
|
class Movimiento extends Ideal\Model
|
||||||
@ -19,7 +21,11 @@ class Movimiento extends Ideal\Model
|
|||||||
public function getDetalles(): ?Detalle
|
public function getDetalles(): ?Detalle
|
||||||
{
|
{
|
||||||
if (!isset($this->detalles)) {
|
if (!isset($this->detalles)) {
|
||||||
$this->detalles = $this->runFactory('detalles');
|
try {
|
||||||
|
$this->detalles = $this->runFactory('detalles');
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
$this->detalles = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->detalles;
|
return $this->detalles;
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model\Inmobiliaria;
|
||||||
|
|
||||||
class Nubox extends Ideal\Model
|
class Nubox extends Ideal\Model
|
||||||
{
|
{
|
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Model;
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model\Venta;
|
||||||
|
|
||||||
class PagoCentroCosto extends Ideal\Model
|
class PagoCentroCosto extends Ideal\Model
|
||||||
{
|
{
|
7
app/src/Model/Contabilidad/TipoCentro.php
Normal file
7
app/src/Model/Contabilidad/TipoCentro.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Model\Contabilidad;
|
||||||
|
|
||||||
|
use Incoviba\Model\Tipo;
|
||||||
|
|
||||||
|
class TipoCentro extends Tipo
|
||||||
|
{}
|
@ -10,8 +10,6 @@ class Inmobiliaria extends Model
|
|||||||
public ?string $dv;
|
public ?string $dv;
|
||||||
public ?string $razon;
|
public ?string $razon;
|
||||||
public ?string $abreviacion;
|
public ?string $abreviacion;
|
||||||
public ?string $cuenta;
|
|
||||||
public ?Banco $banco;
|
|
||||||
public ?TipoSociedad $tipoSociedad;
|
public ?TipoSociedad $tipoSociedad;
|
||||||
|
|
||||||
public function rut(): string
|
public function rut(): string
|
||||||
@ -37,8 +35,6 @@ class Inmobiliaria extends Model
|
|||||||
'rut_formateado' => $this->rut(),
|
'rut_formateado' => $this->rut(),
|
||||||
'razon' => $this->razon ?? '',
|
'razon' => $this->razon ?? '',
|
||||||
'abreviacion' => $this->abreviacion ?? '',
|
'abreviacion' => $this->abreviacion ?? '',
|
||||||
'cuenta' => $this->cuenta ?? '',
|
|
||||||
'banco' => $this->banco ?? '',
|
|
||||||
'tipo_sociedad' => $this->tipoSociedad ?? ''
|
'tipo_sociedad' => $this->tipoSociedad ?? ''
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,39 @@
|
|||||||
namespace Incoviba\Model\Inmobiliaria;
|
namespace Incoviba\Model\Inmobiliaria;
|
||||||
|
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
|
||||||
class Cuenta extends Ideal\Model
|
class Cuenta extends Ideal\Model
|
||||||
{
|
{
|
||||||
public Model\Inmobiliaria $inmobiliaria;
|
public Model\Inmobiliaria $inmobiliaria;
|
||||||
public Model\Banco $banco;
|
public Model\Contabilidad\Banco $banco;
|
||||||
public string $cuenta;
|
public string $cuenta;
|
||||||
|
|
||||||
|
protected array $estados;
|
||||||
|
public function getEstados(): array
|
||||||
|
{
|
||||||
|
if (!isset($this->estados)) {
|
||||||
|
$this->estados = $this->runFactory('estados');
|
||||||
|
}
|
||||||
|
return $this->estados;
|
||||||
|
}
|
||||||
|
protected Model\Inmobiliaria\Cuenta\Estado $currentEstado;
|
||||||
|
public function currentEstado(): Model\Inmobiliaria\Cuenta\Estado
|
||||||
|
{
|
||||||
|
if (!isset($this->currentEstado)) {
|
||||||
|
$estados = $this->getEstados();
|
||||||
|
if (count($estados) === 0) {
|
||||||
|
throw new EmptyResult('Current Estado Cuenta');
|
||||||
|
}
|
||||||
|
usort($estados, function(Model\Inmobiliaria\Cuenta\Estado $a, Model\Inmobiliaria\Cuenta\Estado $b) {
|
||||||
|
return $a->id - $b->id;
|
||||||
|
});
|
||||||
|
$this->currentEstado = end($estados);
|
||||||
|
}
|
||||||
|
return $this->currentEstado;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): mixed
|
public function jsonSerialize(): mixed
|
||||||
{
|
{
|
||||||
return array_merge(parent::jsonSerialize(), [
|
return array_merge(parent::jsonSerialize(), [
|
||||||
|
22
app/src/Model/Inmobiliaria/Cuenta/Estado.php
Normal file
22
app/src/Model/Inmobiliaria/Cuenta/Estado.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Model\Inmobiliaria\Cuenta;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Model;
|
||||||
|
|
||||||
|
class Estado extends Ideal\Model
|
||||||
|
{
|
||||||
|
public Model\Inmobiliaria\Cuenta $cuenta;
|
||||||
|
public DateTimeInterface $fecha;
|
||||||
|
public bool $active;
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return array_merge(parent::jsonSerialize(), [
|
||||||
|
'cuenta_id' => $this->cuenta->id,
|
||||||
|
'fecha' => $this->fecha->format('Y-m-d'),
|
||||||
|
'active' => $this->active
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,8 @@ use Incoviba\Model;
|
|||||||
|
|
||||||
class Detalle extends Ideal\Model
|
class Detalle extends Ideal\Model
|
||||||
{
|
{
|
||||||
public Model\Movimiento $movimiento;
|
public Model\Contabilidad\Movimiento $movimiento;
|
||||||
public ?Model\CentroCosto $centroCosto;
|
public ?Model\Contabilidad\CentroCosto $centroCosto;
|
||||||
public ?string $detalle;
|
public ?string $detalle;
|
||||||
|
|
||||||
public function jsonSerialize(): mixed
|
public function jsonSerialize(): mixed
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Incoviba\Model;
|
|
||||||
|
|
||||||
class TipoCentro extends Tipo
|
|
||||||
{}
|
|
@ -3,9 +3,6 @@ namespace Incoviba\Model;
|
|||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Controller\Ventas;
|
|
||||||
use Incoviba\Model\Venta\FormaPago;
|
|
||||||
use Incoviba\Model\Venta\Pago;
|
|
||||||
|
|
||||||
class Venta extends Ideal\Model
|
class Venta extends Ideal\Model
|
||||||
{
|
{
|
||||||
@ -18,7 +15,7 @@ class Venta extends Ideal\Model
|
|||||||
public bool $relacionado;
|
public bool $relacionado;
|
||||||
protected ?Venta\Entrega $entrega;
|
protected ?Venta\Entrega $entrega;
|
||||||
public float $uf;
|
public float $uf;
|
||||||
protected ?Pago $resciliacion;
|
protected ?Venta\Pago $resciliacion;
|
||||||
|
|
||||||
public ?array $estados;
|
public ?array $estados;
|
||||||
public ?Venta\EstadoVenta $currentEstado;
|
public ?Venta\EstadoVenta $currentEstado;
|
||||||
@ -44,6 +41,11 @@ class Venta extends Ideal\Model
|
|||||||
}
|
}
|
||||||
return $this->formaPago;
|
return $this->formaPago;
|
||||||
}
|
}
|
||||||
|
public function setFormaPago(Venta\FormaPago $formaPago): Venta
|
||||||
|
{
|
||||||
|
$this->formaPago = $formaPago;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
public function entrega(): ?Venta\Entrega
|
public function entrega(): ?Venta\Entrega
|
||||||
{
|
{
|
||||||
if (!isset($this->entrega)) {
|
if (!isset($this->entrega)) {
|
||||||
@ -94,9 +96,9 @@ class Venta extends Ideal\Model
|
|||||||
}
|
}
|
||||||
return $this->valor_util;
|
return $this->valor_util;
|
||||||
}
|
}
|
||||||
public function saldo(string $moneda = Pago::UF): float
|
public function saldo(string $moneda = Venta\Pago::UF): float
|
||||||
{
|
{
|
||||||
$valor = $this->valor * (($moneda === Pago::UF) ? 1 : $this->uf);
|
$valor = $this->valor * (($moneda === Venta\Pago::UF) ? 1 : $this->uf);
|
||||||
return $valor - $this->formaPago()->total($moneda);
|
return $valor - $this->formaPago()->total($moneda);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ namespace Incoviba\Model\Venta;
|
|||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Ideal\Model;
|
use Incoviba\Common\Ideal\Model;
|
||||||
use Incoviba\Model\Banco;
|
use Incoviba\Model\Contabilidad\Banco;
|
||||||
|
|
||||||
class Cuota extends Model
|
class Cuota extends Model
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ namespace Incoviba\Model\Venta;
|
|||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Ideal\Model;
|
use Incoviba\Common\Ideal\Model;
|
||||||
use Incoviba\Model\Banco;
|
use Incoviba\Model\Contabilidad\Banco;
|
||||||
|
|
||||||
class Pago extends Model
|
class Pago extends Model
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,7 @@ use Incoviba\Model;
|
|||||||
|
|
||||||
class Propiedad extends Ideal\Model
|
class Propiedad extends Ideal\Model
|
||||||
{
|
{
|
||||||
public array $unidades;
|
public array $unidades = [];
|
||||||
|
|
||||||
protected array $departamentos;
|
protected array $departamentos;
|
||||||
public function departamentos(): array
|
public function departamentos(): array
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
@ -17,7 +17,7 @@ class Banco extends Ideal\Repository
|
|||||||
public function create(?array $data = null): Define\Model
|
public function create(?array $data = null): Define\Model
|
||||||
{
|
{
|
||||||
$map = new Implement\Repository\MapperParser(['nombre']);
|
$map = new Implement\Repository\MapperParser(['nombre']);
|
||||||
return $this->parseData(new Model\Banco(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\Banco(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Define\Model
|
public function save(Define\Model $model): Define\Model
|
||||||
{
|
{
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
@ -16,7 +16,7 @@ class Cartola extends Ideal\Repository
|
|||||||
$this->setTable('cartolas');
|
$this->setTable('cartolas');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Model\Cartola
|
public function create(?array $data = null): Model\Contabilidad\Cartola
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser(['cargos', 'abonos', 'saldo']))
|
$map = (new Implement\Repository\MapperParser(['cargos', 'abonos', 'saldo']))
|
||||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||||
@ -25,9 +25,9 @@ class Cartola extends Ideal\Repository
|
|||||||
->setFunction(function($data) {
|
->setFunction(function($data) {
|
||||||
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||||
}));
|
}));
|
||||||
return $this->parseData(new Model\Cartola(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\Cartola(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\Cartola
|
public function save(Define\Model $model): Model\Contabilidad\Cartola
|
||||||
{
|
{
|
||||||
$model->id = $this->saveNew([
|
$model->id = $this->saveNew([
|
||||||
'cuenta_id',
|
'cuenta_id',
|
||||||
@ -44,7 +44,7 @@ class Cartola extends Ideal\Repository
|
|||||||
]);
|
]);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function edit(Define\Model $model, array $new_data): Model\Cartola
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Cartola
|
||||||
{
|
{
|
||||||
return $this->update($model, ['cuenta_id', 'fecha', 'cargos', 'abonos', 'saldo'], $new_data);
|
return $this->update($model, ['cuenta_id', 'fecha', 'cargos', 'abonos', 'saldo'], $new_data);
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ class Cartola extends Ideal\Repository
|
|||||||
->where('fecha = ?');
|
->where('fecha = ?');
|
||||||
return $this->fetchMany($query, [$fecha->format('Y-m-d')]);
|
return $this->fetchMany($query, [$fecha->format('Y-m-d')]);
|
||||||
}
|
}
|
||||||
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Cartola
|
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Contabilidad\Cartola
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
->select()
|
->select()
|
||||||
@ -65,4 +65,14 @@ class Cartola extends Ideal\Repository
|
|||||||
->where('cuenta_id = ? AND fecha = ?');
|
->where('cuenta_id = ? AND fecha = ?');
|
||||||
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||||
}
|
}
|
||||||
|
public function fetchLastByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Contabilidad\Cartola
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ? AND fecha <= ?')
|
||||||
|
->order('fecha DESC')
|
||||||
|
->limit(1);
|
||||||
|
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository\Tipo;
|
||||||
|
|
||||||
class CategoriaCentro extends Tipo
|
class CategoriaCentro extends Tipo
|
||||||
{
|
{
|
||||||
@ -14,6 +15,6 @@ class CategoriaCentro extends Tipo
|
|||||||
|
|
||||||
protected function getBlank(): Define\Model
|
protected function getBlank(): Define\Model
|
||||||
{
|
{
|
||||||
return new Model\CategoriaCentro();
|
return new Model\Contabilidad\CategoriaCentro();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement\Repository\Mapper;
|
use Incoviba\Common\Implement\Repository\Mapper;
|
||||||
use Incoviba\Common\Implement\Repository\MapperParser;
|
use Incoviba\Common\Implement\Repository\MapperParser;
|
||||||
use Incoviba\Repository;
|
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository\TipoCuenta;
|
||||||
|
|
||||||
class CentroCosto extends Ideal\Repository
|
class CentroCosto extends Ideal\Repository
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ class CentroCosto extends Ideal\Repository
|
|||||||
$this->setTable('centros_costos');
|
$this->setTable('centros_costos');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Model\CentroCosto
|
public function create(?array $data = null): Model\Contabilidad\CentroCosto
|
||||||
{
|
{
|
||||||
$map = (new MapperParser(['descripcion']))
|
$map = (new MapperParser(['descripcion']))
|
||||||
->register('tipo_centro_id', (new Mapper())
|
->register('tipo_centro_id', (new Mapper())
|
||||||
@ -39,9 +39,9 @@ class CentroCosto extends Ideal\Repository
|
|||||||
->setDefault(null))
|
->setDefault(null))
|
||||||
->register('cuenta_contable', (new Mapper())
|
->register('cuenta_contable', (new Mapper())
|
||||||
->setProperty('cuentaContable'));
|
->setProperty('cuentaContable'));
|
||||||
return $this->parseData(new Model\CentroCosto(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\CentroCosto(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\CentroCosto
|
public function save(Define\Model $model): Model\Contabilidad\CentroCosto
|
||||||
{
|
{
|
||||||
$this->saveNew(
|
$this->saveNew(
|
||||||
['id', 'tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'],
|
['id', 'tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'],
|
||||||
@ -49,12 +49,12 @@ class CentroCosto extends Ideal\Repository
|
|||||||
);
|
);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function edit(Define\Model $model, array $new_data): Model\CentroCosto
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\CentroCosto
|
||||||
{
|
{
|
||||||
return $this->update($model, ['tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'], $new_data);
|
return $this->update($model, ['tipo_centro_id', 'categoria_id', 'tipo_cuenta_id', 'cuenta_contable', 'descripcion'], $new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchByDescripcion(string $descripcion): Model\CentroCosto
|
public function fetchByDescripcion(string $descripcion): Model\Contabilidad\CentroCosto
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
->select()
|
->select()
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Repository;
|
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
class Deposito extends Ideal\Repository
|
class Deposito extends Ideal\Repository
|
||||||
{
|
{
|
||||||
@ -16,7 +16,7 @@ class Deposito extends Ideal\Repository
|
|||||||
$this->setTable('depositos');
|
$this->setTable('depositos');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Model\Deposito
|
public function create(?array $data = null): Model\Contabilidad\Deposito
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser(['id', 'capital', 'futuro']))
|
$map = (new Implement\Repository\MapperParser(['id', 'capital', 'futuro']))
|
||||||
->register('cuenta_id', (new Implement\Repository\Mapper())
|
->register('cuenta_id', (new Implement\Repository\Mapper())
|
||||||
@ -26,9 +26,9 @@ class Deposito extends Ideal\Repository
|
|||||||
}))
|
}))
|
||||||
->register('inicio', new Implement\Repository\Mapper\DateTime('inicio'))
|
->register('inicio', new Implement\Repository\Mapper\DateTime('inicio'))
|
||||||
->register('termino', new Implement\Repository\Mapper\DateTime('termino'));
|
->register('termino', new Implement\Repository\Mapper\DateTime('termino'));
|
||||||
return $this->parseData(new Model\Deposito(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\Deposito(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\Deposito
|
public function save(Define\Model $model): Model\Contabilidad\Deposito
|
||||||
{
|
{
|
||||||
$this->saveNew([
|
$this->saveNew([
|
||||||
'id', 'cuenta_id', 'capital', 'futuro', 'inicio', 'termino'
|
'id', 'cuenta_id', 'capital', 'futuro', 'inicio', 'termino'
|
||||||
@ -39,7 +39,7 @@ class Deposito extends Ideal\Repository
|
|||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Define\Model $model, array $new_data): Model\Deposito
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Deposito
|
||||||
{
|
{
|
||||||
return $this->update($model, ['cuenta_id', 'capital', 'futuro', 'inicio', 'termino'], $new_data);
|
return $this->update($model, ['cuenta_id', 'capital', 'futuro', 'inicio', 'termino'], $new_data);
|
||||||
}
|
}
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository\Inmobiliaria;
|
||||||
|
|
||||||
class Movimiento extends Ideal\Repository
|
class Movimiento extends Ideal\Repository
|
||||||
{
|
{
|
||||||
@ -15,7 +16,7 @@ class Movimiento extends Ideal\Repository
|
|||||||
$this->setTable('movimientos');
|
$this->setTable('movimientos');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Model\Movimiento
|
public function create(?array $data = null): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser(['cargo', 'abono', 'saldo', 'glosa', 'documento']))
|
$map = (new Implement\Repository\MapperParser(['cargo', 'abono', 'saldo', 'glosa', 'documento']))
|
||||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||||
@ -25,9 +26,9 @@ class Movimiento extends Ideal\Repository
|
|||||||
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return $this->parseData(new Model\Movimiento(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\Movimiento(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\Movimiento
|
public function save(Define\Model $model): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
$model->id = $this->saveNew([
|
$model->id = $this->saveNew([
|
||||||
'cuenta_id',
|
'cuenta_id',
|
||||||
@ -48,7 +49,7 @@ class Movimiento extends Ideal\Repository
|
|||||||
]);
|
]);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function edit(Define\Model $model, array $new_data): Model\Movimiento
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
return $this->update($model, ['cuenta_id', 'fecha', 'glosa', 'documento', 'cargo', 'abono', 'saldo'], $new_data);
|
return $this->update($model, ['cuenta_id', 'fecha', 'glosa', 'documento', 'cargo', 'abono', 'saldo'], $new_data);
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ class Movimiento extends Ideal\Repository
|
|||||||
->where('cuenta_id = ? AND fecha = ?');
|
->where('cuenta_id = ? AND fecha = ?');
|
||||||
return $this->fetchMany($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
return $this->fetchMany($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||||
}
|
}
|
||||||
public function fetchByCuentaAndFechaAndCargoAndAbonoAndSaldo(int $cuenta_id, DateTimeInterface $fecha, int $cargo, int $abono, int $saldo): Model\Movimiento
|
public function fetchByCuentaAndFechaAndCargoAndAbonoAndSaldo(int $cuenta_id, DateTimeInterface $fecha, int $cargo, int $abono, int $saldo): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
->select()
|
->select()
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository\Inmobiliaria;
|
||||||
|
|
||||||
class Nubox extends Ideal\Repository
|
class Nubox extends Ideal\Repository
|
||||||
{
|
{
|
||||||
@ -14,7 +15,7 @@ class Nubox extends Ideal\Repository
|
|||||||
$this->setTable('inmobiliarias_nubox');
|
$this->setTable('inmobiliarias_nubox');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Model\Nubox
|
public function create(?array $data = null): Model\Contabilidad\Nubox
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser(['usuario', 'alias']))
|
$map = (new Implement\Repository\MapperParser(['usuario', 'alias']))
|
||||||
->register('inmobiliaria_rut', (new Implement\Repository\Mapper())
|
->register('inmobiliaria_rut', (new Implement\Repository\Mapper())
|
||||||
@ -24,9 +25,9 @@ class Nubox extends Ideal\Repository
|
|||||||
}))
|
}))
|
||||||
->register('contraseña', (new Implement\Repository\Mapper())
|
->register('contraseña', (new Implement\Repository\Mapper())
|
||||||
->setProperty('password'));
|
->setProperty('password'));
|
||||||
return $this->parseData(new Model\Nubox(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\Nubox(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\Nubox
|
public function save(Define\Model $model): Model\Contabilidad\Nubox
|
||||||
{
|
{
|
||||||
$this->saveNew(
|
$this->saveNew(
|
||||||
['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'],
|
['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'],
|
||||||
@ -34,12 +35,12 @@ class Nubox extends Ideal\Repository
|
|||||||
);
|
);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function edit(Define\Model $model, array $new_data): Model\Nubox
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\Nubox
|
||||||
{
|
{
|
||||||
return $this->update($model, ['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'], $new_data);
|
return $this->update($model, ['inmobiliaria_rut', 'alias', 'usuario', 'contraseña'], $new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchByInmobiliaria(int $inmobiliaria_rut): Model\Nubox
|
public function fetchByInmobiliaria(int $inmobiliaria_rut): Model\Contabilidad\Nubox
|
||||||
{
|
{
|
||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
->select()
|
->select()
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
@ -15,7 +15,7 @@ class PagoCentroCosto extends Ideal\Repository
|
|||||||
$this->setTable('pagos_centros_costos');
|
$this->setTable('pagos_centros_costos');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Model\PagoCentroCosto
|
public function create(?array $data = null): Model\Contabilidad\PagoCentroCosto
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser())
|
$map = (new Implement\Repository\MapperParser())
|
||||||
->register('pago_id', (new Implement\Repository\Mapper())
|
->register('pago_id', (new Implement\Repository\Mapper())
|
||||||
@ -28,14 +28,14 @@ class PagoCentroCosto extends Ideal\Repository
|
|||||||
->setFunction(function(array $data) {
|
->setFunction(function(array $data) {
|
||||||
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
|
return $this->centroCostoRepository->fetchById($data['centro_costo_id']);
|
||||||
}));
|
}));
|
||||||
return $this->parseData(new Model\PagoCentroCosto(), $data, $map);
|
return $this->parseData(new Model\Contabilidad\PagoCentroCosto(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Model\PagoCentroCosto
|
public function save(Define\Model $model): Model\Contabilidad\PagoCentroCosto
|
||||||
{
|
{
|
||||||
$model->id = $this->saveNew(['pago_id', 'centro_costo_id'], [$model->pago->id, $model->centroCosto->id]);
|
$model->id = $this->saveNew(['pago_id', 'centro_costo_id'], [$model->pago->id, $model->centroCosto->id]);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function edit(Define\Model $model, array $new_data): Model\PagoCentroCosto
|
public function edit(Define\Model $model, array $new_data): Model\Contabilidad\PagoCentroCosto
|
||||||
{
|
{
|
||||||
return $this->update($model, ['pago_id', 'centro_costo_id'], $new_data);
|
return $this->update($model, ['pago_id', 'centro_costo_id'], $new_data);
|
||||||
}
|
}
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository;
|
namespace Incoviba\Repository\Contabilidad;
|
||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository\Tipo;
|
||||||
|
|
||||||
class TipoCentro extends Tipo
|
class TipoCentro extends Tipo
|
||||||
{
|
{
|
||||||
@ -14,6 +15,6 @@ class TipoCentro extends Tipo
|
|||||||
|
|
||||||
protected function getBlank(): Define\Model
|
protected function getBlank(): Define\Model
|
||||||
{
|
{
|
||||||
return new Model\TipoCentro();
|
return new Model\Contabilidad\TipoCentro();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ use Incoviba\Repository;
|
|||||||
|
|
||||||
class Inmobiliaria extends Ideal\Repository
|
class Inmobiliaria extends Ideal\Repository
|
||||||
{
|
{
|
||||||
public function __construct(Define\Connection $connection, protected Repository\Banco $bancoRepository, protected Repository\Inmobiliaria\TipoSociedad $tipoSociedadRepository)
|
public function __construct(Define\Connection $connection, protected Contabilidad\Banco $bancoRepository, protected Repository\Inmobiliaria\TipoSociedad $tipoSociedadRepository)
|
||||||
{
|
{
|
||||||
parent::__construct($connection);
|
parent::__construct($connection);
|
||||||
$this->setTable('inmobiliaria');
|
$this->setTable('inmobiliaria');
|
||||||
@ -20,13 +20,9 @@ class Inmobiliaria extends Ideal\Repository
|
|||||||
return 'rut';
|
return 'rut';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Define\Model
|
public function create(?array $data = null): Model\Inmobiliaria
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser(['dv', 'razon', 'abreviacion', 'cuenta']))
|
$map = (new Implement\Repository\MapperParser(['dv', 'razon', 'abreviacion']))
|
||||||
->register('banco', (new Implement\Repository\Mapper())
|
|
||||||
->setFunction(function($data) {
|
|
||||||
return $this->bancoRepository->fetchById($data['banco']);
|
|
||||||
}))
|
|
||||||
->register('sociedad', (new Implement\Repository\Mapper())
|
->register('sociedad', (new Implement\Repository\Mapper())
|
||||||
->setProperty('tipoSociedad')
|
->setProperty('tipoSociedad')
|
||||||
->setFunction(function($data) {
|
->setFunction(function($data) {
|
||||||
@ -34,7 +30,7 @@ class Inmobiliaria extends Ideal\Repository
|
|||||||
}));
|
}));
|
||||||
return $this->parseData(new Model\Inmobiliaria(), $data, $map);
|
return $this->parseData(new Model\Inmobiliaria(), $data, $map);
|
||||||
}
|
}
|
||||||
public function save(Define\Model $model): Define\Model
|
public function save(Define\Model $model): Model\Inmobiliaria
|
||||||
{
|
{
|
||||||
$model->rut = $this->saveNew(
|
$model->rut = $this->saveNew(
|
||||||
['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'],
|
['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'],
|
||||||
@ -42,7 +38,7 @@ class Inmobiliaria extends Ideal\Repository
|
|||||||
);
|
);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria
|
||||||
{
|
{
|
||||||
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
|
return $this->update($model, ['dv', 'razon', 'abreviacion', 'cuenta', 'banco', 'sociedad'], $new_data);
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,15 @@ namespace Incoviba\Repository\Inmobiliaria;
|
|||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Repository;
|
|
||||||
use Incoviba\Model;
|
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use PhpParser\Node\Expr\BinaryOp\Mod;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
class Cuenta extends Ideal\Repository
|
class Cuenta extends Ideal\Repository
|
||||||
{
|
{
|
||||||
public function __construct(Define\Connection $connection,
|
public function __construct(Define\Connection $connection,
|
||||||
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
protected Repository\Banco $bancoRepository)
|
protected Repository\Contabilidad\Banco $bancoRepository)
|
||||||
{
|
{
|
||||||
parent::__construct($connection);
|
parent::__construct($connection);
|
||||||
$this->setTable('cuenta');
|
$this->setTable('cuenta');
|
||||||
|
62
app/src/Repository/Inmobiliaria/Cuenta/Estado.php
Normal file
62
app/src/Repository/Inmobiliaria/Cuenta/Estado.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Repository\Inmobiliaria\Cuenta;
|
||||||
|
|
||||||
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Model;
|
||||||
|
|
||||||
|
class Estado extends Ideal\Repository
|
||||||
|
{
|
||||||
|
public function __construct(Define\Connection $connection, protected Repository\Inmobiliaria\Cuenta $cuentaRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($connection);
|
||||||
|
$this->setTable('estados_cuentas');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(?array $data = null): Model\Inmobiliaria\Cuenta\Estado
|
||||||
|
{
|
||||||
|
$map = (new Implement\Repository\MapperParser())
|
||||||
|
->register('cuenta_id', (new Implement\Repository\Mapper())
|
||||||
|
->setProperty('cuenta')
|
||||||
|
->setFunction(function($data) {
|
||||||
|
return $this->cuentaRepository->fetchById($data['cuenta_id']);
|
||||||
|
}))
|
||||||
|
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||||
|
->register('active', new Implement\Repository\Mapper\Boolean('active'));
|
||||||
|
return $this->parseData(new Model\Inmobiliaria\Cuenta\Estado(), $data, $map);
|
||||||
|
}
|
||||||
|
public function save(Define\Model $model): Model\Inmobiliaria\Cuenta\Estado
|
||||||
|
{
|
||||||
|
$model->id = $this->saveNew([
|
||||||
|
'cuenta_id', 'fecha', 'active'
|
||||||
|
], [
|
||||||
|
$model->cuenta->id, $model->fecha->format('Y-m-d'), $model->active ? 1 : 0
|
||||||
|
]);
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Cuenta\Estado
|
||||||
|
{
|
||||||
|
return $this->update($model, ['cuenta_id', 'fecha', 'active'], $new_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchByCuenta(int $cuenta_id): array
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ?');
|
||||||
|
return $this->fetchMany($query, [$cuenta_id]);
|
||||||
|
}
|
||||||
|
public function fetchLastByCuenta(int $cuenta_id): Model\Inmobiliaria\Cuenta\Estado
|
||||||
|
{
|
||||||
|
$query = $this->connection->getQueryBuilder()
|
||||||
|
->select()
|
||||||
|
->from($this->getTable())
|
||||||
|
->where('cuenta_id = ?')
|
||||||
|
->order('id DESC')
|
||||||
|
->limit(1);
|
||||||
|
return $this->fetchMany($query, [$cuenta_id]);
|
||||||
|
}
|
||||||
|
}
|
@ -9,8 +9,8 @@ use Incoviba\Repository;
|
|||||||
|
|
||||||
class Detalle extends Ideal\Repository
|
class Detalle extends Ideal\Repository
|
||||||
{
|
{
|
||||||
public function __construct(Define\Connection $connection, protected Repository\Movimiento $movimientoRepository,
|
public function __construct(Define\Connection $connection, protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||||
protected Repository\CentroCosto $centroCostoRepository)
|
protected Repository\Contabilidad\CentroCosto $centroCostoRepository)
|
||||||
{
|
{
|
||||||
parent::__construct($connection);
|
parent::__construct($connection);
|
||||||
$this->setTable('movimientos_detalles');
|
$this->setTable('movimientos_detalles');
|
||||||
|
@ -132,9 +132,9 @@ class Venta extends Ideal\Repository
|
|||||||
['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||||
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
'entrega', 'entregado', 'fecha', 'valor_uf', 'estado', 'fecha_ingreso', 'avalchile', 'agente', 'uf',
|
||||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'],
|
'relacionado', 'promocion', 'resciliacion', 'devolucion'],
|
||||||
[$model->propietario()->rut, $model->propiedad()->id, $model->formaPago()->pie?->id, $model->formaPago()->bonoPie?->id,
|
[$model->propietario()->rut, $model->propiedad()->id, $model->formaPago()?->pie?->id, $model->formaPago()?->bonoPie?->id,
|
||||||
$model->formaPago()->credito?->id, $model->formaPago()->escritura?->id, $model->formaPago()->subsidio?->id,
|
$model->formaPago()?->credito?->id, $model->formaPago()?->escritura?->id, $model->formaPago()?->subsidio?->id,
|
||||||
$model->formaPago()->escritura !== null ? $model->formaPago()->escritura->pago->fecha->format('Y-m-d') : null,
|
$model->formaPago()?->escritura !== null ? $model->formaPago()?->escritura->pago->fecha->format('Y-m-d') : null,
|
||||||
null, null, $model->fecha->format('Y-m-d'), $model->valor, 1, $model->fechaIngreso->format('Y-m-d'),
|
null, null, $model->fecha->format('Y-m-d'), $model->valor, 1, $model->fechaIngreso->format('Y-m-d'),
|
||||||
null, null, $model->uf, $model->relacionado ? 1 : 0, null, null, null]
|
null, null, $model->uf, $model->relacionado ? 1 : 0, null, null, null]
|
||||||
);
|
);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Repository\Venta;
|
namespace Incoviba\Repository\Venta;
|
||||||
|
|
||||||
use PDO;
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
@ -13,10 +11,10 @@ use Incoviba\Service;
|
|||||||
class Cuota extends Ideal\Repository
|
class Cuota extends Ideal\Repository
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Define\Connection $connection,
|
Define\Connection $connection,
|
||||||
protected Pie $pieRepository,
|
protected Pie $pieRepository,
|
||||||
protected Repository\Banco $bancoRepository,
|
protected Repository\Contabilidad\Banco $bancoRepository,
|
||||||
protected Service\Venta\Pago $pagoService
|
protected Service\Venta\Pago $pagoService
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
parent::__construct($connection);
|
parent::__construct($connection);
|
||||||
|
@ -10,9 +10,9 @@ use Incoviba\Repository;
|
|||||||
class Pago extends Ideal\Repository
|
class Pago extends Ideal\Repository
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Define\Connection $connection,
|
Define\Connection $connection,
|
||||||
protected Repository\Banco $bancoRepository,
|
protected Repository\Contabilidad\Banco $bancoRepository,
|
||||||
protected TipoPago $tipoPagoRepository
|
protected TipoPago $tipoPagoRepository
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
parent::__construct($connection);
|
parent::__construct($connection);
|
||||||
|
@ -18,22 +18,23 @@ class Propiedad extends Ideal\Repository
|
|||||||
public function create(?array $data = null): Model\Venta\Propiedad
|
public function create(?array $data = null): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
$map = (new Implement\Repository\MapperParser())
|
$map = (new Implement\Repository\MapperParser())
|
||||||
->register('unidad_principal', (new Implement\Repository\Mapper())
|
|
||||||
->setProperty('unidades')
|
|
||||||
->setFunction(function($data) {
|
|
||||||
if (isset($data['id'])) {
|
|
||||||
return $this->unidadService->getByPropiedad($data['id']);
|
|
||||||
}
|
|
||||||
return [$this->unidadService->getById($data['unidad_principal'])];
|
|
||||||
}))
|
|
||||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
->register('estado', new Implement\Repository\Mapper\Boolean('estado'));
|
||||||
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
return $this->parseData(new Model\Venta\Propiedad(), $data, $map);
|
||||||
}
|
}
|
||||||
|
public function load(array $data_row): Define\Model
|
||||||
|
{
|
||||||
|
$propiedad = parent::load($data_row);
|
||||||
|
if (isset($propiedad->id)) {
|
||||||
|
$propiedad->unidades = $this->unidadService->getByPropiedad($propiedad->id);
|
||||||
|
}
|
||||||
|
return $propiedad;
|
||||||
|
}
|
||||||
|
|
||||||
public function save(Define\Model $model): Model\Venta\Propiedad
|
public function save(Define\Model $model): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
$model->id = $this->saveNew(
|
$model->id = $this->saveNew(
|
||||||
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
['unidad_principal', 'estacionamientos', 'bodegas', 'estado'],
|
||||||
[$model->departamentos()[0]->id,
|
[null,
|
||||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->estacionamientos())),
|
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->estacionamientos())),
|
||||||
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
|
implode(',', array_map(function(Model\Venta\Unidad $unidad) {return $unidad->id;}, $model->bodegas())),
|
||||||
1]
|
1]
|
||||||
|
@ -1,28 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateInterval;
|
use DateTimeInterface;
|
||||||
use Psr\Http\Message\StreamFactoryInterface;
|
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use Incoviba\Common\Ideal\Service;
|
|
||||||
use Incoviba\Common\Define\Cartola\Banco;
|
use Incoviba\Common\Define\Cartola\Banco;
|
||||||
use Incoviba\Common\Define\Contabilidad\Exporter;
|
use Incoviba\Common\Define\Contabilidad\Exporter;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement\Exception;
|
use Incoviba\Common\Implement\Exception;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
use Psr\Http\Message\StreamFactoryInterface;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Cartola extends Service
|
class Cartola extends Service
|
||||||
{
|
{
|
||||||
public function __construct(LoggerInterface $logger,
|
public function __construct(LoggerInterface $logger,
|
||||||
protected StreamFactoryInterface $streamFactory, protected Exporter $exporter,
|
protected StreamFactoryInterface $streamFactory, protected Exporter $exporter,
|
||||||
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
protected Repository\Movimiento $movimientoRepository,
|
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||||
protected Movimiento $movimientoService,
|
protected Movimiento $movimientoService,
|
||||||
protected Repository\Cartola $cartolaRepository) {
|
protected Repository\Contabilidad\Cartola $cartolaRepository) {
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,11 +31,11 @@ class Cartola extends Service
|
|||||||
$this->bancos[$name] = $banco;
|
$this->bancos[$name] = $banco;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
public function process(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, UploadedFileInterface $file): array
|
public function process(Model\Inmobiliaria $inmobiliaria, Model\Contabilidad\Banco $banco, DateTimeInterface $mes, UploadedFileInterface $file): array
|
||||||
{
|
{
|
||||||
return $this->bancos[strtolower($banco->nombre)]->process($file);
|
return $this->bancos[strtolower($banco->nombre)]->process($file);
|
||||||
}
|
}
|
||||||
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string
|
public function export(Model\Inmobiliaria $inmobiliaria, Model\Contabilidad\Banco $banco, DateTimeInterface $mes, array $movimientos): string
|
||||||
{
|
{
|
||||||
return $this->exporter->export($inmobiliaria, $banco, $mes, $movimientos);
|
return $this->exporter->export($inmobiliaria, $banco, $mes, $movimientos);
|
||||||
}
|
}
|
||||||
@ -44,27 +43,29 @@ class Cartola extends Service
|
|||||||
{
|
{
|
||||||
$ms = $this->getMovimientosDiarios($cuenta->banco, $file);
|
$ms = $this->getMovimientosDiarios($cuenta->banco, $file);
|
||||||
|
|
||||||
$cartolaData = [
|
$this->groupedMovimientos = [];
|
||||||
'cargos' => 0,
|
|
||||||
'abonos' => 0,
|
|
||||||
'saldo' => 0
|
|
||||||
];
|
|
||||||
$movimientos = [];
|
$movimientos = [];
|
||||||
foreach ($ms as $m) {
|
foreach ($ms as $m) {
|
||||||
$movimiento = $this->buildMovimiento($cuenta, $m);
|
$movimiento = $this->buildMovimiento($cuenta, $m);
|
||||||
$movimiento = $this->movimientoService->process($movimiento);
|
$movimiento = $this->movimientoService->process($movimiento);
|
||||||
|
$this->groupMovimientoByDay($movimiento);
|
||||||
if ($movimiento->fecha->getTimestamp() === $fecha->getTimestamp()) {
|
if ($movimiento->fecha->getTimestamp() === $fecha->getTimestamp()) {
|
||||||
$movimientos []= $movimiento;
|
$movimientos []= $movimiento;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($this->groupedMovimientos as $timestamp => $movimientos) {
|
||||||
|
$cartolaData = [
|
||||||
|
'cargos' => 0,
|
||||||
|
'abonos' => 0,
|
||||||
|
'saldo' => end($movimientos)->saldo
|
||||||
|
];
|
||||||
|
foreach ($movimientos as $movimiento) {
|
||||||
$cartolaData['cargos'] += $movimiento->cargo;
|
$cartolaData['cargos'] += $movimiento->cargo;
|
||||||
$cartolaData['abonos'] += $movimiento->abono;
|
$cartolaData['abonos'] += $movimiento->abono;
|
||||||
}
|
}
|
||||||
if ($movimiento->fecha->getTimestamp() > $fecha->getTimestamp()) {
|
$this->buildCartola($cuenta, end($movimientos)->fecha, $cartolaData);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$cartolaData['saldo'] = $movimiento->saldo;
|
|
||||||
}
|
}
|
||||||
$cartola = $this->buildCartola($cuenta, $fecha, $cartolaData);
|
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
return compact('cartola', 'movimientos');
|
return compact('cartola', 'movimientos');
|
||||||
}
|
}
|
||||||
public function diariaManual(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, array $data): array
|
public function diariaManual(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, array $data): array
|
||||||
@ -91,12 +92,21 @@ class Cartola extends Service
|
|||||||
return compact('cartola', 'movimientos');
|
return compact('cartola', 'movimientos');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMovimientosDiarios(Model\Banco $banco, UploadedFileInterface $file): array
|
protected function getMovimientosDiarios(Model\Contabilidad\Banco $banco, UploadedFileInterface $file): array
|
||||||
{
|
{
|
||||||
$movimientos = $this->bancos[strtolower($banco->nombre)]->process($file);
|
$movimientos = $this->bancos[strtolower($banco->nombre)]->process($file);
|
||||||
return $this->bancos[strtolower($banco->nombre)]->processMovimientosDiarios($movimientos);
|
return $this->bancos[strtolower($banco->nombre)]->processMovimientosDiarios($movimientos);
|
||||||
}
|
}
|
||||||
protected function buildCartola(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, array $data): Model\Cartola
|
protected array $groupedMovimientos = [];
|
||||||
|
protected function groupMovimientoByDay(Model\Contabilidad\Movimiento $movimiento): Cartola
|
||||||
|
{
|
||||||
|
if (!isset($this->groupedMovimientos[$movimiento->fecha->getTimestamp()])) {
|
||||||
|
$this->groupedMovimientos[$movimiento->fecha->getTimestamp()] = [];
|
||||||
|
}
|
||||||
|
$this->groupedMovimientos[$movimiento->fecha->getTimestamp()] []= $movimiento;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
protected function buildCartola(Model\Inmobiliaria\Cuenta $cuenta, DateTimeInterface $fecha, array $data): Model\Contabilidad\Cartola
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
return $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
@ -107,7 +117,7 @@ class Cartola extends Service
|
|||||||
return $this->cartolaRepository->save($cartola);
|
return $this->cartolaRepository->save($cartola);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected function buildMovimiento(Model\Inmobiliaria\Cuenta $cuenta, array $data): Model\Movimiento
|
protected function buildMovimiento(Model\Inmobiliaria\Cuenta $cuenta, array $data): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->movimientoRepository
|
return $this->movimientoRepository
|
||||||
@ -121,7 +131,12 @@ class Cartola extends Service
|
|||||||
} catch (Exception\EmptyResult $exception) {
|
} catch (Exception\EmptyResult $exception) {
|
||||||
$data['cuenta_id'] = $cuenta->id;
|
$data['cuenta_id'] = $cuenta->id;
|
||||||
$movimiento = $this->movimientoRepository->create($data);
|
$movimiento = $this->movimientoRepository->create($data);
|
||||||
return $this->movimientoRepository->save($movimiento);
|
try {
|
||||||
|
return $this->movimientoRepository->save($movimiento);
|
||||||
|
} catch (\PDOException $exception) {
|
||||||
|
$this->logger->critical(var_export($data,true));
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
86
app/src/Service/Contabilidad/Cartola/BCI.php
Normal file
86
app/src/Service/Contabilidad/Cartola/BCI.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service\Contabilidad\Cartola;
|
||||||
|
|
||||||
|
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||||
|
use PhpOffice\PhpSpreadsheet;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
|
class BCI extends Banco
|
||||||
|
{
|
||||||
|
protected function columnMap(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Fecha Transacción' => 'fecha',
|
||||||
|
'Cargo $ (-)' => 'cargo',
|
||||||
|
'Abono $ (+)' => 'abono',
|
||||||
|
'Descripción' => 'glosa',
|
||||||
|
'Saldo' => 'saldo'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
protected function getFilename(UploadedFileInterface $uploadedFile): string
|
||||||
|
{
|
||||||
|
return '/tmp/cartola.xlsx';
|
||||||
|
}
|
||||||
|
protected function parseFile(string $filename): array
|
||||||
|
{
|
||||||
|
$xlsx = @PhpSpreadsheet\IOFactory::load($filename);
|
||||||
|
$worksheet = $xlsx->getActiveSheet();
|
||||||
|
$rows = $worksheet->getRowIterator();
|
||||||
|
|
||||||
|
$rows->seek(3);
|
||||||
|
$row = $rows->current();
|
||||||
|
$columnIterator = $row->getColumnIterator();
|
||||||
|
$saldoFinal = 0;
|
||||||
|
foreach ($columnIterator as $column) {
|
||||||
|
if ($column->getValue() === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($column->getCalculatedValue() === 'Saldo Contable') {
|
||||||
|
$columnIterator->next();
|
||||||
|
$column = $columnIterator->current();
|
||||||
|
$saldoFinal = (int) str_replace('.', '', $column->getCalculatedValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$saldo = $saldoFinal;
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$columns = [];
|
||||||
|
$dataFound = false;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if (!$dataFound and $worksheet->getCell([1, $row->getRowIndex()])->getCalculatedValue() !== null
|
||||||
|
and trim($worksheet->getCell([1, $row->getRowIndex()])->getCalculatedValue()) === 'Fecha Contable') {
|
||||||
|
$dataFound = true;
|
||||||
|
$columns = $this->getRowData($row);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$dataFound) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($worksheet->getCell([1, $row->getRowIndex()])->getValue() === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$rowData = $this->getRowData($row);
|
||||||
|
$rowData = array_combine($columns, $rowData);
|
||||||
|
$rowData['Fecha Transacción'] = implode('-', array_reverse(explode('/', $rowData['Fecha Transacción'])));
|
||||||
|
$rowData['Cargo $ (-)'] = (int) str_replace('.', '', $rowData['Cargo $ (-)'] ?? 0);
|
||||||
|
$rowData['Abono $ (+)'] = (int) str_replace('.', '', $rowData['Abono $ (+)'] ?? 0);
|
||||||
|
$rowData['Saldo'] = $saldo;
|
||||||
|
$saldo = $saldo + $rowData['Cargo $ (-)'] - $rowData['Abono $ (+)'];
|
||||||
|
unset($rowData['']);
|
||||||
|
|
||||||
|
$data []= $rowData;
|
||||||
|
}
|
||||||
|
return array_reverse($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRowData(PhpSpreadsheet\Worksheet\Row $row): array
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
$cells = $row->getColumnIterator();
|
||||||
|
foreach ($cells as $cell) {
|
||||||
|
$data []= $cell->getCalculatedValue();
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Cartola;
|
namespace Incoviba\Service\Contabilidad\Cartola;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
|
||||||
use PhpOffice\PhpSpreadsheet;
|
|
||||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||||
|
use PhpOffice\PhpSpreadsheet;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
class Itau extends Banco
|
class Itau extends Banco
|
||||||
{
|
{
|
||||||
@ -29,12 +29,12 @@ class Itau extends Banco
|
|||||||
'Saldos' => 'saldo'
|
'Saldos' => 'saldo'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
protected function getFilename(UploadedFileInterface $uploadedFile): string
|
||||||
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
{
|
||||||
|
return '/tmp/cartola.xls';
|
||||||
|
}
|
||||||
|
protected function parseFile(string $filename): array
|
||||||
{
|
{
|
||||||
$filename = '/tmp/cartola.xls';
|
|
||||||
$uploadedFile->moveTo($filename);
|
|
||||||
|
|
||||||
$reader = PhpSpreadsheet\IOFactory::createReader('Xls');
|
$reader = PhpSpreadsheet\IOFactory::createReader('Xls');
|
||||||
$xlsx = $reader->load($filename);
|
$xlsx = $reader->load($filename);
|
||||||
$sheet = $xlsx->getActiveSheet();
|
$sheet = $xlsx->getActiveSheet();
|
||||||
@ -51,8 +51,6 @@ class Itau extends Banco
|
|||||||
}
|
}
|
||||||
} catch (PhpSpreadsheet\Exception $exception) {
|
} catch (PhpSpreadsheet\Exception $exception) {
|
||||||
$this->logger->critical($exception);
|
$this->logger->critical($exception);
|
||||||
} finally {
|
|
||||||
unlink($filename);
|
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
@ -1,16 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Cartola;
|
namespace Incoviba\Service\Contabilidad\Cartola;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
|
||||||
use PhpOffice\PhpSpreadsheet;
|
|
||||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||||
|
use PhpOffice\PhpSpreadsheet;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
class Santander extends Banco
|
class Santander extends Banco
|
||||||
{
|
{
|
||||||
protected function columnMap(): array
|
protected function columnMap(): array
|
||||||
{
|
{
|
||||||
// MONTO DESCRIPCIÓN MOVIMIENTO FECHA N° DOCUMENTO SUCURSAL CARGO/ABONO
|
|
||||||
return [
|
return [
|
||||||
'cargo' => 'cargo',
|
'cargo' => 'cargo',
|
||||||
'abono' => 'abono',
|
'abono' => 'abono',
|
||||||
@ -25,17 +23,26 @@ class Santander extends Banco
|
|||||||
'Saldo Diario' => 'saldo'
|
'Saldo Diario' => 'saldo'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
protected function getFilename(UploadedFileInterface $uploadedFile): string
|
||||||
{
|
{
|
||||||
$filename = '/tmp/cartola.xlsx';
|
$start = $uploadedFile->getStream()->read(10);
|
||||||
$uploadedFile->moveTo($filename);
|
if (str_starts_with($start, '<')) {
|
||||||
|
return '/tmp/cartola.html';
|
||||||
$reader = PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
|
||||||
try {
|
|
||||||
$xlsx = $reader->load($filename);
|
|
||||||
} catch (PhpSpreadsheet\Reader\Exception) {
|
|
||||||
return $this->parseHtml($filename);
|
|
||||||
}
|
}
|
||||||
|
return '/tmp/cartola.xlsx';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function parseFile(string $filename): array
|
||||||
|
{
|
||||||
|
if (str_ends_with($filename, 'xlsx')) {
|
||||||
|
return $this->parseXlsx($filename);
|
||||||
|
}
|
||||||
|
return $this->parseHtml($filename);
|
||||||
|
}
|
||||||
|
protected function parseXlsx(string $filename): array
|
||||||
|
{
|
||||||
|
$reader = PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||||
|
$xlsx = $reader->load($filename);
|
||||||
$sheet = $xlsx->getActiveSheet();
|
$sheet = $xlsx->getActiveSheet();
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
@ -65,7 +72,7 @@ class Santander extends Banco
|
|||||||
if ($mapped === 'fecha') {
|
if ($mapped === 'fecha') {
|
||||||
$value = implode('-', array_reverse(explode('/', $value)));
|
$value = implode('-', array_reverse(explode('/', $value)));
|
||||||
}
|
}
|
||||||
if ($column === 'MONTO') {
|
if ($column === 'MONTO' or $column === 'SALDO') {
|
||||||
$value = (int) $value;
|
$value = (int) $value;
|
||||||
}
|
}
|
||||||
$rowData[$column] = $value;
|
$rowData[$column] = $value;
|
||||||
@ -81,7 +88,7 @@ class Santander extends Banco
|
|||||||
$data []= $rowData;
|
$data []= $rowData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return array_reverse($data);
|
||||||
}
|
}
|
||||||
protected function parseHtml(string $filename): array
|
protected function parseHtml(string $filename): array
|
||||||
{
|
{
|
||||||
@ -108,11 +115,11 @@ class Santander extends Banco
|
|||||||
foreach (['Cargo ($)', 'Abono ($)', 'Saldo Diario'] as $column) {
|
foreach (['Cargo ($)', 'Abono ($)', 'Saldo Diario'] as $column) {
|
||||||
$row[$column] = (int) str_replace('.', '', $row[$column]);
|
$row[$column] = (int) str_replace('.', '', $row[$column]);
|
||||||
}
|
}
|
||||||
$row['Saldo Diario'] -= ($row['Abono ($)'] - $row['Cargo ($)']);
|
|
||||||
$row['N° DOCUMENTO'] = '';
|
$row['N° DOCUMENTO'] = '';
|
||||||
$data []= $row;
|
$data []= $row;
|
||||||
}
|
}
|
||||||
return $data;
|
|
||||||
|
return array_reverse($data);
|
||||||
}
|
}
|
||||||
protected function parseHtmlRow(array $lines, int &$rowIndex): array
|
protected function parseHtmlRow(array $lines, int &$rowIndex): array
|
||||||
{
|
{
|
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Cartola;
|
namespace Incoviba\Service\Contabilidad\Cartola;
|
||||||
|
|
||||||
use DOMDocument;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use DOMDocument;
|
||||||
use PhpOffice\PhpSpreadsheet;
|
|
||||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||||
|
use PhpOffice\PhpSpreadsheet;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
class Security extends Banco
|
class Security extends Banco
|
||||||
{
|
{
|
||||||
@ -16,14 +16,21 @@ class Security extends Banco
|
|||||||
return $movimientos;
|
return $movimientos;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseFile(UploadedFileInterface $uploadedFile): array
|
protected function getFilename(UploadedFileInterface $uploadedFile): string
|
||||||
{
|
{
|
||||||
$stream = $uploadedFile->getStream();
|
$stream = $uploadedFile->getStream();
|
||||||
$stream->seek(3);
|
$stream->seek(3);
|
||||||
if ($stream->read(strlen('table')) === 'table') {
|
if ($stream->read(strlen('table')) === 'table') {
|
||||||
return $this->processHtm($uploadedFile);
|
return '/tmp/cartola.htm';
|
||||||
}
|
}
|
||||||
return $this->processXls($uploadedFile);
|
return '/tmp/cartola.xls';
|
||||||
|
}
|
||||||
|
protected function parseFile(string $filename): array
|
||||||
|
{
|
||||||
|
if (str_ends_with($filename, '.htm')) {
|
||||||
|
return $this->processHtm($filename);
|
||||||
|
}
|
||||||
|
return $this->processXls($filename);
|
||||||
}
|
}
|
||||||
protected function columnMap(): array
|
protected function columnMap(): array
|
||||||
{
|
{
|
||||||
@ -38,10 +45,8 @@ class Security extends Banco
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processXls(UploadedFileInterface $file): array
|
private function processXls(string $filename): array
|
||||||
{
|
{
|
||||||
$filename = '/tmp/cartola.xls';
|
|
||||||
$file->moveTo($filename);
|
|
||||||
$xlsx = @PhpSpreadsheet\IOFactory::load($filename);
|
$xlsx = @PhpSpreadsheet\IOFactory::load($filename);
|
||||||
$worksheet = $xlsx->getActiveSheet();
|
$worksheet = $xlsx->getActiveSheet();
|
||||||
$rows = $worksheet->getRowIterator(3);
|
$rows = $worksheet->getRowIterator(3);
|
||||||
@ -82,14 +87,10 @@ class Security extends Banco
|
|||||||
$data []= $rowData;
|
$data []= $rowData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlink($filename);
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
private function processHtm(UploadedFileInterface $file): array
|
private function processHtm(string $filename): array
|
||||||
{
|
{
|
||||||
$filename = '/tmp/cartola.htm';
|
|
||||||
$file->moveTo($filename);
|
|
||||||
|
|
||||||
$domDocument = new DOMDocument();
|
$domDocument = new DOMDocument();
|
||||||
$domDocument->loadHTML('<body>' . file_get_contents($filename) . '</body>');
|
$domDocument->loadHTML('<body>' . file_get_contents($filename) . '</body>');
|
||||||
|
|
||||||
@ -122,7 +123,6 @@ class Security extends Banco
|
|||||||
}
|
}
|
||||||
$data []= $rowData;
|
$data []= $rowData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,9 +10,9 @@ use PhpOffice\PhpSpreadsheet;
|
|||||||
|
|
||||||
class Nubox implements Exporter
|
class Nubox implements Exporter
|
||||||
{
|
{
|
||||||
public function __construct(protected Repository\CentroCosto $centroCostoRepository, protected string $uploadFolder) {}
|
public function __construct(protected Repository\Contabilidad\CentroCosto $centroCostoRepository, protected string $uploadFolder) {}
|
||||||
|
|
||||||
public function export(Model\Inmobiliaria $inmobiliaria, Model\Banco $banco, DateTimeInterface $mes, array $movimientos): string
|
public function export(Model\Inmobiliaria $inmobiliaria, Model\Contabilidad\Banco $banco, DateTimeInterface $mes, array $movimientos): string
|
||||||
{
|
{
|
||||||
PhpSpreadsheet\Settings::setLocale('es-CL');
|
PhpSpreadsheet\Settings::setLocale('es-CL');
|
||||||
$workbook = new PhpSpreadsheet\Spreadsheet();
|
$workbook = new PhpSpreadsheet\Spreadsheet();
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Contabilidad\Informe;
|
namespace Incoviba\Service\Contabilidad\Informe;
|
||||||
|
|
||||||
use DateTimeInterface;
|
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Psr\Log\LoggerInterface;
|
use DateTimeInterface;
|
||||||
use PhpOffice\PhpSpreadsheet;
|
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Tesoreria extends Ideal\Service
|
class Tesoreria extends Ideal\Service
|
||||||
{
|
{
|
||||||
public function __construct(LoggerInterface $logger,
|
public function __construct(LoggerInterface $logger,
|
||||||
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
protected Repository\Inmobiliaria $inmobiliariaRepository,
|
||||||
protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
protected Service\Inmobiliaria\Cuenta $cuentaService,
|
||||||
protected Repository\Deposito $depositoRepository,
|
protected Repository\Contabilidad\Deposito $depositoRepository,
|
||||||
protected Repository\Cartola $cartolaRepository,
|
protected Repository\Contabilidad\Cartola $cartolaRepository,
|
||||||
protected Repository\Movimiento $movimientoRepository,
|
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||||
protected Service\Contabilidad\Informe\Tesoreria\Excel $excelService,
|
protected Service\Contabilidad\Informe\Tesoreria\Excel $excelService,
|
||||||
protected Service\Contabilidad\Informe\Tesoreria\PDF $pdfService)
|
protected Service\Contabilidad\Informe\Tesoreria\PDF $pdfService)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
|
|
||||||
@ -170,7 +169,7 @@ class Tesoreria extends Ideal\Service
|
|||||||
};
|
};
|
||||||
$dataInmobiliaria->inmobiliaria = $inmobiliaria;
|
$dataInmobiliaria->inmobiliaria = $inmobiliaria;
|
||||||
try {
|
try {
|
||||||
$cuentas = $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria->rut);
|
$cuentas = $this->cuentaService->getAllActiveByInmobiliaria($inmobiliaria->rut);
|
||||||
} catch (Implement\Exception\EmptyResult) {
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
return $dataInmobiliaria;
|
return $dataInmobiliaria;
|
||||||
}
|
}
|
||||||
@ -228,23 +227,25 @@ class Tesoreria extends Ideal\Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
|
$anterior = $this->getAnterior($fecha);
|
||||||
try {
|
try {
|
||||||
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
$cartola = $this->cartolaRepository->fetchLastByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
$data->actual = $cartola->saldo;
|
$data->actual = $cartola->saldo;
|
||||||
|
//$anterior = $this->getAnterior($cartola->fecha);
|
||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
try {
|
try {
|
||||||
$cartola = $this->cartolaRepository->fetchByCuentaAndFecha($cuenta->id, $this->getAnterior($fecha));
|
$cartola = $this->cartolaRepository->fetchLastByCuentaAndFecha($cuenta->id, $anterior);
|
||||||
$data->anterior = $cartola->saldo;
|
$data->anterior = $cartola->saldo;
|
||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
if ($data->diferencia() !== 0) {
|
if ($data->diferencia() !== 0) {
|
||||||
try {
|
try {
|
||||||
$movimientos = $this->movimientoRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
$movimientos = $this->movimientoRepository->fetchByCuentaAndFecha($cuenta->id, $fecha);
|
||||||
$this->addMovimientos(self::INGRESOS,
|
$this->addMovimientos(self::INGRESOS,
|
||||||
array_filter($movimientos, function(Model\Movimiento $movimiento) {
|
array_filter($movimientos, function(Model\Contabilidad\Movimiento $movimiento) {
|
||||||
return $movimiento->abono > 0;
|
return $movimiento->abono > 0;
|
||||||
}));
|
}));
|
||||||
$this->addMovimientos(self::EGRESOS,
|
$this->addMovimientos(self::EGRESOS,
|
||||||
array_filter($movimientos, function(Model\Movimiento $movimiento) {
|
array_filter($movimientos, function(Model\Contabilidad\Movimiento $movimiento) {
|
||||||
return $movimiento->cargo > 0;
|
return $movimiento->cargo > 0;
|
||||||
}));
|
}));
|
||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
@ -289,5 +290,4 @@ class Tesoreria extends Ideal\Service
|
|||||||
$this->totales->{$tipo} += $total;
|
$this->totales->{$tipo} += $total;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use Incoviba\Common\Ideal\Service;
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Repository;
|
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Movimiento extends Service
|
class Movimiento extends Service
|
||||||
{
|
{
|
||||||
public function __construct(LoggerInterface $logger, protected Repository\Movimiento $movimientoRepository,
|
public function __construct(LoggerInterface $logger,
|
||||||
|
protected Repository\Contabilidad\Movimiento $movimientoRepository,
|
||||||
protected Repository\Movimiento\Detalle $detalleRepository)
|
protected Repository\Movimiento\Detalle $detalleRepository)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getById(int $movimiento_id): Model\Movimiento
|
public function getById(int $movimiento_id): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
return $this->process($this->movimientoRepository->fetchById($movimiento_id));
|
return $this->process($this->movimientoRepository->fetchById($movimiento_id));
|
||||||
}
|
}
|
||||||
public function setDetalles(Model\Movimiento $movimiento, array $data): Model\Movimiento
|
public function setDetalles(Model\Contabilidad\Movimiento $movimiento, array $data): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$detalles = $this->detalleRepository->fetchByMovimiento($movimiento->id);
|
$detalles = $this->detalleRepository->fetchByMovimiento($movimiento->id);
|
||||||
@ -33,7 +33,7 @@ class Movimiento extends Service
|
|||||||
return $movimiento;
|
return $movimiento;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process(Model\Movimiento $movimiento): Model\Movimiento
|
public function process(Model\Contabilidad\Movimiento $movimiento): Model\Contabilidad\Movimiento
|
||||||
{
|
{
|
||||||
$movimiento->addFactory('detalles', (new Implement\Repository\Factory())->setCallable(function(int $movimiento_id) {
|
$movimiento->addFactory('detalles', (new Implement\Repository\Factory())->setCallable(function(int $movimiento_id) {
|
||||||
return $this->detalleRepository->fetchByMovimiento($movimiento_id);
|
return $this->detalleRepository->fetchByMovimiento($movimiento_id);
|
@ -2,24 +2,24 @@
|
|||||||
namespace Incoviba\Service\Contabilidad;
|
namespace Incoviba\Service\Contabilidad;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement\Exception;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
use Psr\Http\Message\RequestFactoryInterface;
|
use Psr\Http\Message\RequestFactoryInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Implement\Exception;
|
|
||||||
use Incoviba\Repository;
|
|
||||||
use Incoviba\Service;
|
|
||||||
use Incoviba\Common\Ideal;
|
|
||||||
|
|
||||||
class Nubox extends Ideal\Service
|
class Nubox extends Ideal\Service
|
||||||
{
|
{
|
||||||
public function __construct(protected LoggerInterface $logger,
|
public function __construct(protected LoggerInterface $logger,
|
||||||
protected Repository\Nubox $nuboxRepository,
|
protected Repository\Contabilidad\Nubox $nuboxRepository,
|
||||||
protected Service\Redis $redisService,
|
protected Service\Redis $redisService,
|
||||||
protected ClientInterface $client,
|
protected ClientInterface $client,
|
||||||
protected RequestFactoryInterface $requestFactory,
|
protected RequestFactoryInterface $requestFactory,
|
||||||
protected string $api_url)
|
protected string $api_url)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
}
|
}
|
||||||
|
56
app/src/Service/Inmobiliaria/Cuenta.php
Normal file
56
app/src/Service/Inmobiliaria/Cuenta.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service\Inmobiliaria;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
|
use Incoviba\Common\Implement;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
|
||||||
|
class Cuenta extends Service
|
||||||
|
{
|
||||||
|
public function __construct(LoggerInterface $logger, protected Repository\Inmobiliaria\Cuenta $cuentaRepository,
|
||||||
|
protected Repository\Inmobiliaria\Cuenta\Estado $estadoRepository)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllActive(): array
|
||||||
|
{
|
||||||
|
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchAll());
|
||||||
|
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||||
|
return $cuenta->currentEstado()->active;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
public function getAllActiveByInmobiliaria(int $inmobiliaria_rut): array
|
||||||
|
{
|
||||||
|
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria_rut));
|
||||||
|
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||||
|
return $cuenta->currentEstado()->active;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
public function add(array $data): Model\Inmobiliaria\Cuenta
|
||||||
|
{
|
||||||
|
$cuenta = $this->cuentaRepository->create($data);
|
||||||
|
$cuenta = $this->cuentaRepository->save($cuenta);
|
||||||
|
$dataEstado = [
|
||||||
|
'cuenta_id' => $cuenta->id,
|
||||||
|
'fecha' => new DateTimeImmutable(),
|
||||||
|
'active' => true
|
||||||
|
];
|
||||||
|
$estado = $this->estadoRepository->create($dataEstado);
|
||||||
|
$this->estadoRepository->save($estado);
|
||||||
|
return $this->process($cuenta);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function process(Model\Inmobiliaria\Cuenta $cuenta): Model\Inmobiliaria\Cuenta
|
||||||
|
{
|
||||||
|
$cuenta->addFactory('estados', (new Implement\Repository\Factory())
|
||||||
|
->setCallable(function($cuenta_id) {
|
||||||
|
return $this->estadoRepository->fetchByCuenta($cuenta_id);
|
||||||
|
})
|
||||||
|
->setArgs(['cuenta_id' => $cuenta->id]));
|
||||||
|
return $cuenta;
|
||||||
|
}
|
||||||
|
}
|
@ -47,7 +47,24 @@ class Login
|
|||||||
}
|
}
|
||||||
return $login->user;
|
return $login->user;
|
||||||
}
|
}
|
||||||
|
public function getToken(): string
|
||||||
|
{
|
||||||
|
return implode($this->cookie_separator, [$this->selector, $this->token]);
|
||||||
|
}
|
||||||
|
public function getSeparator(): string
|
||||||
|
{
|
||||||
|
return $this->cookie_separator;
|
||||||
|
}
|
||||||
|
public function validateUser(Model\User $user, string $encryptedPassword): bool
|
||||||
|
{
|
||||||
|
list($passphrase, $encrypted) = $this->splitPassword($encryptedPassword);
|
||||||
|
try {
|
||||||
|
$password = $this->cryptoJs_aes_decrypt($encrypted, $passphrase);
|
||||||
|
} catch (Exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $user->validate($password);
|
||||||
|
}
|
||||||
public function login(Model\User $user): bool
|
public function login(Model\User $user): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -97,6 +114,10 @@ class Login
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$cookie = $_COOKIE[$this->cookie_name];
|
$cookie = $_COOKIE[$this->cookie_name];
|
||||||
|
if (!str_contains($cookie, $this->cookie_separator)) {
|
||||||
|
$this->removeCookie();
|
||||||
|
return;
|
||||||
|
}
|
||||||
list($this->selector, $this->token) = explode($this->cookie_separator, $cookie);
|
list($this->selector, $this->token) = explode($this->cookie_separator, $cookie);
|
||||||
}
|
}
|
||||||
protected function saveCookie(string $selector, string $token, DateTimeInterface $expires): void
|
protected function saveCookie(string $selector, string $token, DateTimeInterface $expires): void
|
||||||
@ -104,9 +125,12 @@ class Login
|
|||||||
setcookie(
|
setcookie(
|
||||||
$this->cookie_name,
|
$this->cookie_name,
|
||||||
implode($this->cookie_separator, [$selector, $token]),
|
implode($this->cookie_separator, [$selector, $token]),
|
||||||
$expires->getTimestamp(),
|
[
|
||||||
$this->path,
|
'expires' => $expires->getTimestamp(),
|
||||||
$this->domain
|
'path' => $this->path,
|
||||||
|
'domain' => $this->domain,
|
||||||
|
'samesite' => 'Strict'
|
||||||
|
]
|
||||||
);
|
);
|
||||||
$this->selector = $selector;
|
$this->selector = $selector;
|
||||||
$this->token = $token;
|
$this->token = $token;
|
||||||
@ -126,10 +150,70 @@ class Login
|
|||||||
{
|
{
|
||||||
return password_verify($this->token, $login->token);
|
return password_verify($this->token, $login->token);
|
||||||
}
|
}
|
||||||
protected function generateToken(Model\Login $login)
|
protected function generateToken(Model\Login $login): array
|
||||||
{
|
{
|
||||||
$selector = bin2hex(random_bytes(12));
|
$selector = bin2hex(random_bytes(12));
|
||||||
$token = bin2hex(random_bytes(20));
|
$token = bin2hex(random_bytes(20));
|
||||||
return ['selector' => $selector, 'token' => $token];
|
return ['selector' => $selector, 'token' => $token];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function splitPassword(string $input): array
|
||||||
|
{
|
||||||
|
$ini = strpos($input, 'U');
|
||||||
|
$passphrase = substr($input, 0, $ini);
|
||||||
|
$message = substr($input, $ini);
|
||||||
|
return [$passphrase, $message];
|
||||||
|
}
|
||||||
|
protected function cryptoJs_aes_decrypt($data, $key): string
|
||||||
|
{
|
||||||
|
$data = base64_decode($data);
|
||||||
|
if (substr($data, 0, 8) != "Salted__") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$salt = substr($data, 8, 8);
|
||||||
|
$keyAndIV = $this->aes_evpKDF($key, $salt);
|
||||||
|
$decrypted = openssl_decrypt(
|
||||||
|
substr($data, 16),
|
||||||
|
"aes-256-cbc",
|
||||||
|
$keyAndIV["key"],
|
||||||
|
OPENSSL_RAW_DATA, // base64 was already decoded
|
||||||
|
$keyAndIV["iv"]
|
||||||
|
);
|
||||||
|
if ($decrypted === false) {
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
return $decrypted;
|
||||||
|
}
|
||||||
|
protected function aes_evpKDF($password, $salt, $keySize = 8, $ivSize = 4, $iterations = 1, $hashAlgorithm = "md5"): array
|
||||||
|
{
|
||||||
|
$targetKeySize = $keySize + $ivSize;
|
||||||
|
$derivedBytes = "";
|
||||||
|
$numberOfDerivedWords = 0;
|
||||||
|
$block = NULL;
|
||||||
|
$hasher = hash_init($hashAlgorithm);
|
||||||
|
while ($numberOfDerivedWords < $targetKeySize) {
|
||||||
|
if ($block != NULL) {
|
||||||
|
hash_update($hasher, $block);
|
||||||
|
}
|
||||||
|
hash_update($hasher, $password);
|
||||||
|
hash_update($hasher, $salt);
|
||||||
|
$block = hash_final($hasher, TRUE);
|
||||||
|
$hasher = hash_init($hashAlgorithm);
|
||||||
|
|
||||||
|
// Iterations
|
||||||
|
for ($i = 1; $i < $iterations; $i++) {
|
||||||
|
hash_update($hasher, $block);
|
||||||
|
$block = hash_final($hasher, TRUE);
|
||||||
|
$hasher = hash_init($hashAlgorithm);
|
||||||
|
}
|
||||||
|
|
||||||
|
$derivedBytes .= substr($block, 0, min(strlen($block), ($targetKeySize - $numberOfDerivedWords) * 4));
|
||||||
|
|
||||||
|
$numberOfDerivedWords += strlen($block) / 4;
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
"key" => substr($derivedBytes, 0, $keySize * 4),
|
||||||
|
"iv" => substr($derivedBytes, $keySize * 4, $ivSize * 4)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,10 @@ class Venta extends Service
|
|||||||
{
|
{
|
||||||
return $this->ventaRepository->fetchByIdForList($venta_id);
|
return $this->ventaRepository->fetchByIdForList($venta_id);
|
||||||
}
|
}
|
||||||
|
public function getByPie(int $pie_id): Model\Venta
|
||||||
|
{
|
||||||
|
return $this->process($this->ventaRepository->fetchByPie($pie_id));
|
||||||
|
}
|
||||||
|
|
||||||
protected function process(Model\Venta $venta): Model\Venta
|
protected function process(Model\Venta $venta): Model\Venta
|
||||||
{
|
{
|
||||||
@ -104,7 +108,7 @@ class Venta extends Service
|
|||||||
$data['uf'] = $this->moneyService->getUF($fecha);
|
$data['uf'] = $this->moneyService->getUF($fecha);
|
||||||
$propietario = $this->addPropietario($data);
|
$propietario = $this->addPropietario($data);
|
||||||
$propiedad = $this->addPropiedad($data);
|
$propiedad = $this->addPropiedad($data);
|
||||||
$forma_pago = $this->addFormaPago($data);
|
$formaPago = $this->addFormaPago($data);
|
||||||
$venta_data = [
|
$venta_data = [
|
||||||
'propietario' => $propietario->rut,
|
'propietario' => $propietario->rut,
|
||||||
'propiedad' => $propiedad->id,
|
'propiedad' => $propiedad->id,
|
||||||
@ -116,14 +120,15 @@ class Venta extends Service
|
|||||||
$map = ['pie', 'subsidio', 'credito', 'bono_pie'];
|
$map = ['pie', 'subsidio', 'credito', 'bono_pie'];
|
||||||
foreach ($map as $field) {
|
foreach ($map as $field) {
|
||||||
$name = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $field))));
|
$name = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $field))));
|
||||||
if (isset($forma_pago->{$name})) {
|
if (isset($formaPago->{$name})) {
|
||||||
$venta_data[$field] = $forma_pago->{$name}->id;
|
$venta_data[$field] = $formaPago->{$name}->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return $this->ventaRepository->fetchByPropietarioAndPropiedad($propietario->rut, $propiedad->id);
|
return $this->ventaRepository->fetchByPropietarioAndPropiedad($propietario->rut, $propiedad->id);
|
||||||
} catch (Implement\Exception\EmptyResult) {
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
$venta = $this->ventaRepository->create($venta_data);
|
$venta = $this->ventaRepository->create($venta_data);
|
||||||
|
$venta->setFormaPago($formaPago);
|
||||||
$venta = $this->ventaRepository->save($venta);
|
$venta = $this->ventaRepository->save($venta);
|
||||||
|
|
||||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('vigente');
|
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('vigente');
|
||||||
@ -231,7 +236,7 @@ class Venta extends Service
|
|||||||
protected function addPropiedad(array $data): Model\Venta\Propiedad
|
protected function addPropiedad(array $data): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
$ids = array_filter($data, function($key) {
|
$ids = array_filter($data, function($key) {
|
||||||
return str_contains($key, 'unidad');
|
return str_starts_with($key, 'unidad');
|
||||||
}, ARRAY_FILTER_USE_KEY);
|
}, ARRAY_FILTER_USE_KEY);
|
||||||
|
|
||||||
return $this->propiedadService->addPropiedad($ids);
|
return $this->propiedadService->addPropiedad($ids);
|
||||||
@ -239,85 +244,7 @@ class Venta extends Service
|
|||||||
protected function addFormaPago(array $data): Model\Venta\FormaPago
|
protected function addFormaPago(array $data): Model\Venta\FormaPago
|
||||||
{
|
{
|
||||||
return $this->formaPagoService->add($data);
|
return $this->formaPagoService->add($data);
|
||||||
/*$fields = [
|
|
||||||
'pie',
|
|
||||||
'subsidio',
|
|
||||||
'credito',
|
|
||||||
'bono_pie'
|
|
||||||
];
|
|
||||||
$forma_pago = new Model\Venta\FormaPago();
|
|
||||||
foreach ($fields as $name) {
|
|
||||||
if (isset($data["has_{$name}"])) {
|
|
||||||
$method = 'add' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
|
|
||||||
$obj = $this->{$method}($data);
|
|
||||||
$forma_pago->{$name} = $obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $forma_pago;*/
|
|
||||||
}
|
}
|
||||||
/*protected function addPie(array $data): Model\Venta\Pie
|
|
||||||
{
|
|
||||||
$fields = array_fill_keys([
|
|
||||||
'fecha_venta',
|
|
||||||
'pie',
|
|
||||||
'cuotas',
|
|
||||||
'uf'
|
|
||||||
], 0);
|
|
||||||
$filtered_data = array_intersect_key($data, $fields);
|
|
||||||
$mapped_data = array_combine([
|
|
||||||
'fecha',
|
|
||||||
'valor',
|
|
||||||
'cuotas',
|
|
||||||
'uf'
|
|
||||||
], $filtered_data);
|
|
||||||
$mapped_data['valor'] = $this->cleanValue($mapped_data['valor']);
|
|
||||||
return $this->pieService->add($mapped_data);
|
|
||||||
}
|
|
||||||
protected function addSubsidio(array $data): Model\Venta\Subsidio
|
|
||||||
{
|
|
||||||
$fields = array_fill_keys([
|
|
||||||
'fecha_venta',
|
|
||||||
'ahorro',
|
|
||||||
'subsidio',
|
|
||||||
'uf'
|
|
||||||
], 0);
|
|
||||||
$filtered_data = array_intersect_key($data, $fields);
|
|
||||||
$mapped_data = array_combine([
|
|
||||||
'fecha',
|
|
||||||
'ahorro',
|
|
||||||
'subsidio',
|
|
||||||
'uf'
|
|
||||||
], $filtered_data);
|
|
||||||
return $this->subsidioService->add($mapped_data);
|
|
||||||
}
|
|
||||||
protected function addCredito(array $data): Model\Venta\Credito
|
|
||||||
{
|
|
||||||
$fields = array_fill_keys([
|
|
||||||
'fecha_venta',
|
|
||||||
'credito',
|
|
||||||
'uf'
|
|
||||||
], 0);
|
|
||||||
$filtered_data = array_intersect_key($data, $fields);
|
|
||||||
$mapped_data = array_combine([
|
|
||||||
'fecha',
|
|
||||||
'valor',
|
|
||||||
'uf'
|
|
||||||
], $filtered_data);
|
|
||||||
return $this->creditoService->add($mapped_data);
|
|
||||||
}
|
|
||||||
protected function addBonoPie(array $data): Model\Venta\BonoPie
|
|
||||||
{
|
|
||||||
$fields = array_fill_keys([
|
|
||||||
'fecha_venta',
|
|
||||||
'bono_pie'
|
|
||||||
], 0);
|
|
||||||
$filtered_data = array_intersect_key($data, $fields);
|
|
||||||
$mapped_data = array_combine([
|
|
||||||
'fecha',
|
|
||||||
'valor'
|
|
||||||
], $filtered_data);
|
|
||||||
return $this->bonoPieService->add($mapped_data);
|
|
||||||
}*/
|
|
||||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha']);
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
@ -75,10 +75,11 @@ class Cuota
|
|||||||
}
|
}
|
||||||
public function getByPie(int $pie_id): array
|
public function getByPie(int $pie_id): array
|
||||||
{
|
{
|
||||||
return $this->cuotaRepository->fetchByPie($pie_id);
|
try {
|
||||||
/*return array_filter($this->cuotaRepository->fetchByPie($pie_id), function(Model\Venta\Cuota $cuota) {
|
return $this->cuotaRepository->fetchByPie($pie_id);
|
||||||
return !in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado']);
|
} catch (EmptyResult) {
|
||||||
});*/
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public function getVigenteByPie(int $pie_id): array
|
public function getVigenteByPie(int $pie_id): array
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,6 @@ class FormaPago extends Ideal\Service
|
|||||||
'uf'
|
'uf'
|
||||||
], 0);
|
], 0);
|
||||||
$filtered_data = array_intersect_key($data, $fields);
|
$filtered_data = array_intersect_key($data, $fields);
|
||||||
$this->logger->critical(var_export($filtered_data,true));
|
|
||||||
$mapped_data = array_combine([
|
$mapped_data = array_combine([
|
||||||
'fecha',
|
'fecha',
|
||||||
'valor',
|
'valor',
|
||||||
|
@ -30,6 +30,7 @@ class Pago
|
|||||||
try {
|
try {
|
||||||
$estado = $this->estadoPagoRepository->create($data);
|
$estado = $this->estadoPagoRepository->create($data);
|
||||||
$this->estadoPagoRepository->save($estado);
|
$this->estadoPagoRepository->save($estado);
|
||||||
|
$this->getUF($pago);
|
||||||
return true;
|
return true;
|
||||||
} catch (PDOException) {
|
} catch (PDOException) {
|
||||||
return false;
|
return false;
|
||||||
@ -162,7 +163,7 @@ class Pago
|
|||||||
protected function getUF(Model\Venta\Pago $pago): ?float
|
protected function getUF(Model\Venta\Pago $pago): ?float
|
||||||
{
|
{
|
||||||
if (($pago->uf === null or $pago->uf === 0.0)
|
if (($pago->uf === null or $pago->uf === 0.0)
|
||||||
and $pago->currentEstado->tipoEstadoPago->descripcion === 'abonado'
|
and in_array($pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado'])
|
||||||
and $pago->currentEstado->fecha <= new DateTimeImmutable()) {
|
and $pago->currentEstado->fecha <= new DateTimeImmutable()) {
|
||||||
$uf = $this->moneyService->getUF($pago->currentEstado->fecha);
|
$uf = $this->moneyService->getUF($pago->currentEstado->fecha);
|
||||||
if ($uf !== 0.0) {
|
if ($uf !== 0.0) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Service\Venta;
|
namespace Incoviba\Service\Venta;
|
||||||
|
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Common\Implement\Repository\Factory;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
|
||||||
@ -47,6 +48,9 @@ class Pie
|
|||||||
try {
|
try {
|
||||||
$pie->asociados = $this->pieRepository->fetchAsociados($pie->id);
|
$pie->asociados = $this->pieRepository->fetchAsociados($pie->id);
|
||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
|
if (isset($pie->asociado)) {
|
||||||
|
$pie->asociado = $this->getById($pie->asociado->id);
|
||||||
|
}
|
||||||
return $pie;
|
return $pie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,23 @@ namespace Incoviba\Service\Venta;
|
|||||||
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
|
||||||
class Propiedad
|
class Propiedad extends Service
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta\Propiedad $propiedadRepository,
|
protected Repository\Venta\Propiedad $propiedadRepository,
|
||||||
protected Repository\Venta\Unidad $unidadRepository,
|
protected Repository\Venta\Unidad $unidadRepository,
|
||||||
protected Define\Connection $connection
|
protected Define\Connection $connection
|
||||||
) {}
|
) {
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
public function addPropiedad(array $ids): Model\Venta\Propiedad
|
public function addPropiedad(array $ids): Model\Venta\Propiedad
|
||||||
{
|
{
|
||||||
|
17
app/tests/performance/APITest.php
Normal file
17
app/tests/performance/APITest.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Performance;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use PHPUnit\Framework;
|
||||||
|
|
||||||
|
class APITest extends Framework\TestCase
|
||||||
|
{
|
||||||
|
public function testLoad(): void
|
||||||
|
{
|
||||||
|
$client = new Client(['base_uri' => 'http://proxy']);
|
||||||
|
$start = microtime(true);
|
||||||
|
$response = $client->get('/api', ['headers' => ['Authorization' => 'Bearer ' . md5($_ENV['API_KEY'])]]);
|
||||||
|
$end = microtime(true);
|
||||||
|
$this->assertLessThanOrEqual(1000, $end - $start);
|
||||||
|
}
|
||||||
|
}
|
17
app/tests/performance/HomeTest.php
Normal file
17
app/tests/performance/HomeTest.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Performance;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use PHPUnit\Framework;
|
||||||
|
|
||||||
|
class HomeTest extends Framework\TestCase
|
||||||
|
{
|
||||||
|
public function testLoad(): void
|
||||||
|
{
|
||||||
|
$client = new Client(['base_uri' => 'http://proxy']);
|
||||||
|
$start = microtime(true);
|
||||||
|
$response = $client->get('');
|
||||||
|
$end = microtime(true);
|
||||||
|
$this->assertLessThanOrEqual(1000, $end - $start);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user