Ventas
This commit is contained in:
@ -102,7 +102,7 @@ abstract class Repository implements Define\Repository
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->connection->getPDO()->lastInsertId();
|
||||
}
|
||||
protected function update(Model $model, array $columns, array $data): Define\Model
|
||||
protected function update(Define\Model $model, array $columns, array $data): Define\Model
|
||||
{
|
||||
$changes = [];
|
||||
$values = [];
|
||||
@ -119,10 +119,7 @@ abstract class Repository implements Define\Repository
|
||||
$query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?";
|
||||
$values []= $model->id;
|
||||
$this->connection->execute($query, $values);
|
||||
$id = $model->id;
|
||||
$model = $this->create($data);
|
||||
$model->id = $id;
|
||||
return $model;
|
||||
return $this->fetchById($model->id);
|
||||
}
|
||||
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
||||
{
|
||||
|
@ -8,6 +8,8 @@ try {
|
||||
$app->run();
|
||||
} catch (Error $error) {
|
||||
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->error($error);
|
||||
header('Location: /construccion');
|
||||
} catch (Exception $exception) {
|
||||
$app->getContainer()->get(Psr\Log\LoggerInterface::class)->notice($exception);
|
||||
header('Location: /construccion');
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ $app->group('/ventas', function($app) {
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
$app->get('/add', [Ventas::class, 'add']);
|
||||
$app->get('[/]', Ventas::class);
|
||||
});
|
||||
$app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Base;
|
||||
|
||||
$app->get('/construccion', [Base::class, 'construccion'])->setName('construccion');
|
||||
$app->get('[/]', Base::class);
|
||||
|
6
app/resources/routes/api/provincias.php
Normal file
6
app/resources/routes/api/provincias.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Provincias;
|
||||
|
||||
$app->group('/provincia/{provincia_id}', function($app) {
|
||||
$app->get('/comunas', [Provincias::class, 'comunas']);
|
||||
});
|
@ -4,3 +4,6 @@ use Incoviba\Controller\Proyectos;
|
||||
$app->group('/proyectos', function($app) {
|
||||
$app->get('[/]', [Proyectos::class, 'list']);
|
||||
});
|
||||
$app->group('/proyecto/{proyecto_id}', function($app) {
|
||||
$app->get('/unidades[/]', [Proyectos::class, 'unidades']);
|
||||
});
|
||||
|
7
app/resources/routes/api/regiones.php
Normal file
7
app/resources/routes/api/regiones.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Regiones;
|
||||
|
||||
//$app->group('/regiones', function($app) {});
|
||||
$app->group('/region/{region_id}', function($app) {
|
||||
$app->get('/provincias[/]', [Regiones::class, 'provincias']);
|
||||
});
|
@ -1,6 +1,11 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Pagos;
|
||||
|
||||
$app->group('/pagos', function($app) {
|
||||
$app->get('/pendientes', [Pagos::class, 'para_pendientes']);
|
||||
$app->get('/abonar', [Pagos::class, 'para_abonar']);
|
||||
$app->get('/rebotes', [Pagos::class, 'rebotes']);
|
||||
});
|
||||
$app->group('/pago/{pago_id:[0-9]+}', function($app) {
|
||||
$app->put('/depositar[/]', [Pagos::class, 'depositar']);
|
||||
$app->put('/abonar[/]', [Pagos::class, 'abonar']);
|
||||
|
6
app/resources/routes/api/ventas/propietarios.php
Normal file
6
app/resources/routes/api/ventas/propietarios.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Propietarios;
|
||||
|
||||
$app->group('/propietario/{propietario_rut}', function($app) {
|
||||
$app->get('[/]', [Propietarios::class, 'get']);
|
||||
});
|
@ -3,7 +3,10 @@ use Incoviba\Controller\Ventas\Cuotas;
|
||||
|
||||
$app->group('/cuotas', function($app) {
|
||||
$app->get('/pendientes[/]', [Cuotas::class, 'pendientes']);
|
||||
$app->get('/abonar[/]', [Cuotas::class, 'depositadas']);
|
||||
});
|
||||
$app->group('/cuota', function($app) {
|
||||
$app->post('/depositar[/]', [Cuotas::class, 'depositar']);
|
||||
$app->post('/abonar[/]', [Cuotas::class, 'abonar']);
|
||||
$app->post('/devolver[/]', [Cuotas::class, 'devolver']);
|
||||
});
|
||||
|
6
app/resources/routes/ventas/pagos.php
Normal file
6
app/resources/routes/ventas/pagos.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Incoviba\Controller\Ventas\Pagos;
|
||||
|
||||
$app->group('/pagos', function($app) {
|
||||
$app->get('/pendientes', [Pagos::class, 'pendientes']);
|
||||
});
|
14
app/resources/views/construccion.blade.php
Normal file
14
app/resources/views/construccion.blade.php
Normal file
@ -0,0 +1,14 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Construcción
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui warning message">
|
||||
<i class="hammer icon"></i>
|
||||
Esta parte del sitio está en construcción.
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -4,9 +4,9 @@
|
||||
@include('layout.body.header.menu.ventas')
|
||||
@include('layout.body.header.menu.proyectos')
|
||||
@include('layout.body.header.menu.inmobiliarias')
|
||||
@include('layout.body.header.menu.contabilidad')
|
||||
@include('layout.body.header.menu.operadores')
|
||||
@include('layout.body.header.menu.herramientas')
|
||||
{{--@include('layout.body.header.menu.contabilidad')--}}
|
||||
{{--@include('layout.body.header.menu.operadores')--}}
|
||||
{{--@include('layout.body.header.menu.herramientas')--}}
|
||||
<div class="right aligned menu">
|
||||
@include('layout.body.header.menu.user')
|
||||
@include('layout.body.header.menu.search')
|
||||
|
@ -2,7 +2,7 @@
|
||||
Proyectos
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}">Listado</a>
|
||||
<a class="item" href="{{$urls->base}}/unidades">Unidades</a>
|
||||
<a class="item" href="{{$urls->base}}/proyectos">Listado</a>
|
||||
<a class="item" href="{{$urls->base}}/proyectos/unidades">Unidades</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -17,11 +17,11 @@
|
||||
<a class="item" href="{{$urls->base}}/ventas/cuotas/abonar">Abonar</a>
|
||||
</div>
|
||||
</div>
|
||||
<a class="item" href="{{$urls->base}}/ventas/pagos/pendientes">Pagos Pendientes</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas/consolidado">Consolidado Ventas</a>
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/pagos/pendientes">Pagos Pendientes</a>--}}
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/consolidado">Consolidado Ventas</a>--}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="item">
|
||||
{{--<div class="item">
|
||||
Informes
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
@ -30,9 +30,9 @@
|
||||
<a class="item" href="{{$urls->base}}/informes/entregas/gantt">Gantt de Entregas</a>
|
||||
<a class="item" href="{{$urls->base}}/informes/resciliaciones">Resciliaciones</a>
|
||||
</div>
|
||||
</div>
|
||||
<a class="item" href="{{$urls->base}}/ventas/precios/importar">Importar Precios</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas/cierres/evaluar">Evaluar Cierre</a>
|
||||
</div>--}}
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/precios/importar">Importar Precios</a>--}}
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/cierres/evaluar">Evaluar Cierre</a>--}}
|
||||
<a class="item" href="{{$urls->base}}/ventas/add">
|
||||
Nueva Venta
|
||||
<i class="plus icon"></i>
|
||||
|
@ -0,0 +1,3 @@
|
||||
@push('page_scripts')
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
@endpush
|
799
app/resources/views/ventas/add.blade.php
Normal file
799
app/resources/views/ventas/add.blade.php
Normal file
@ -0,0 +1,799 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Nueva Venta</h2>
|
||||
<form class="ui form" action="{{$urls->base}}/ventas/add" method="post">
|
||||
<label for="fecha_venta">Fecha de Venta</label>
|
||||
<div class="inline field">
|
||||
<div class="ui calendar" id="fecha_venta_calendar">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha_venta" id="fecha_venta" />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="ui dividing header">PROPIETARIO</h4>
|
||||
<div class="inline fields">
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" id="persona_propietario" name="natural_uno" checked="checked" />
|
||||
<label>Personal Natural</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" id="cantidad_propietario" name="natural_multiple" />
|
||||
<label>Multiples Propietarios</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span id="propietario"></span>
|
||||
<h4 class="ui dividing header">PROPIEDAD</h4>
|
||||
<label for="proyecto">Proyecto</label>
|
||||
<div class="four wide field">
|
||||
<div class="ui fluid search selection dropdown" id="proyecto">
|
||||
<input type="hidden" name="proyecto" />
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach($proyectos as $proyecto)
|
||||
<div class="item" data-value="{{$proyecto->id}}">{{$proyecto->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button" type="button" id="agregar_departamento">
|
||||
<i class="plus icon"></i>
|
||||
<i class="building icon"></i>
|
||||
{{--Departamento--}}
|
||||
</button>
|
||||
<button class="ui button" type="button" id="agregar_estacionamiento">
|
||||
<i class="plus icon"></i>
|
||||
<i class="car icon"></i>
|
||||
{{--Estacionamiento--}}
|
||||
</button>
|
||||
<button class="ui button" type="button" id="agregar_bodega">
|
||||
<i class="plus icon"></i>
|
||||
<i class="warehouse icon"></i>
|
||||
{{--Bodega--}}
|
||||
</button>
|
||||
<table id="unidades" class="ui very basic compact collapsing table"></table>
|
||||
<h4 class="ui dividing header">FORMA DE PAGO</h4>
|
||||
<label for="valor">Valor</label>
|
||||
<div class="inline field">
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="valor" id="valor" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<label for="has_pie">Pie</label>
|
||||
<div class="inline fields">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="has_pie" id="has_pie" />
|
||||
<label></label>
|
||||
</div>
|
||||
<span id="pie">
|
||||
<div class="inline fields">
|
||||
<div class="inline field">
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="pie" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="four wide inline field">
|
||||
<label for="cuotas">Cuotas</label>
|
||||
<input type="text" name="cuotas" id="cuotas" />
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<label for="has_subsidio">Subsidio</label>
|
||||
<div class="inline fields">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="has_subsidio" id="has_subsidio" />
|
||||
<label></label>
|
||||
</div>
|
||||
<span id="subsidio">
|
||||
<div class="inline fields">
|
||||
<div class="inline field">
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="subsidio" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inline field">
|
||||
<label for="ahorro">Ahorro</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="ahorro" id="ahorro" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<label for="has_credito">Crédito</label>
|
||||
<div class="inline fields">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="has_credito" id="has_credito" />
|
||||
<label></label>
|
||||
</div>
|
||||
<span id="credito">
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="credito" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<h4 class="ui dividing header">OTRAS CONDICIONES</h4>
|
||||
<label for="has_bono_pie">Bono Pie</label>
|
||||
<div class="inline fields">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="has_bono_pie" id="has_bono_pie" />
|
||||
<label></label>
|
||||
</div>
|
||||
<span id="bono_pie">
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="bono_pie" />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<button class="ui button" type="submit">Agregar</button>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const regiones = [
|
||||
@foreach ($regiones as $region)
|
||||
'<div class="item" data-value="{{$region->id}}">{{$region->descripcion}}</div>',
|
||||
@endforeach
|
||||
]
|
||||
|
||||
class Rut {
|
||||
ids
|
||||
patterns
|
||||
valid
|
||||
|
||||
constructor({id, alert_id, valid}) {
|
||||
this.ids = {
|
||||
input: id,
|
||||
alert: alert_id
|
||||
}
|
||||
this.patterns = {
|
||||
like: /^(\d{0,2})\.?(\d{3})\.?(\d{3})-?(\d|k)$/gi,
|
||||
suspicious: /^(\d)\1?\.?(\1{3})\.?(\1{3})-?(\d|k)?$/gi
|
||||
}
|
||||
this.valid = valid
|
||||
|
||||
$(this.ids.alert).hide()
|
||||
$(this.ids.input).change(event => {
|
||||
this.verify(event)
|
||||
})
|
||||
}
|
||||
is() {
|
||||
return {
|
||||
like: rut => this.patterns.like.test(rut),
|
||||
suspicious: rut => this.patterns.suspicious.test(rut)
|
||||
}
|
||||
}
|
||||
clean() {
|
||||
return {
|
||||
rut: rut => rut.includes('-') ? rut.split('-').join('') : rut
|
||||
}
|
||||
}
|
||||
get() {
|
||||
return {
|
||||
digits: rut => this.clean().rut(rut).slice(0, -1),
|
||||
verifier: rut => this.clean().rut(rut).slice(-1)
|
||||
}
|
||||
}
|
||||
calculate() {
|
||||
return {
|
||||
verifier: digits => {
|
||||
let sum = 0
|
||||
let mul = 2
|
||||
|
||||
let i = digits.length
|
||||
while (i--) {
|
||||
sum = sum + parseInt(digits.charAt(i)) * mul
|
||||
if (mul % 7 === 0) {
|
||||
mul = 2
|
||||
} else {
|
||||
mul++
|
||||
}
|
||||
}
|
||||
|
||||
const res = sum % 11
|
||||
|
||||
if (res === 0) {
|
||||
return '0'
|
||||
} else if (res === 1) {
|
||||
return 'k'
|
||||
}
|
||||
|
||||
return `${11 - res}`
|
||||
}
|
||||
}
|
||||
}
|
||||
validate(rut, not_suspicious = true) {
|
||||
if (!this.is().like(rut) || (not_suspicious && this.is().suspicious(rut))) {
|
||||
return false
|
||||
}
|
||||
return this.get().verifier(rut).toLowerCase() === this.calculate().verifier(this.get().digits(rut))
|
||||
}
|
||||
verify(event) {
|
||||
const input = $(event.currentTarget)
|
||||
const val = input.val()
|
||||
let new_val = this.clean().rut(val)
|
||||
if (new_val.length < 3) {
|
||||
return
|
||||
}
|
||||
new_val = [this.get().digits(new_val), this.get().verifier(new_val)].join('-')
|
||||
input.val(new_val)
|
||||
if (!this.validate(new_val)) {
|
||||
this.alert().invalid()
|
||||
return
|
||||
}
|
||||
this.alert().valid()
|
||||
this.valid(new_val)
|
||||
}
|
||||
alert() {
|
||||
return {
|
||||
valid: () => {
|
||||
$(this.ids.alert).hide()
|
||||
},
|
||||
invalid: () => {
|
||||
$(this.ids.alert).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Comuna {
|
||||
id
|
||||
data
|
||||
|
||||
constructor(id) {
|
||||
this.id = id
|
||||
this.data = {
|
||||
region: 0,
|
||||
provincias: []
|
||||
}
|
||||
|
||||
$(this.id).dropdown()
|
||||
}
|
||||
|
||||
get() {
|
||||
return {
|
||||
provincias: () => {
|
||||
const uri = '{{$urls->api}}/region/' + this.data.region + '/provincias'
|
||||
return fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.data.provincias = data.provincias
|
||||
const promises = []
|
||||
this.data.provincias.forEach(provincia => {
|
||||
promises.push(this.get().comunas(provincia.id))
|
||||
})
|
||||
Promise.all(promises).then(() => {
|
||||
this.draw().comunas()
|
||||
})
|
||||
})
|
||||
},
|
||||
comunas: provincia_id => {
|
||||
const uri = '{{$urls->api}}/provincia/' + provincia_id + '/comunas'
|
||||
return fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
const i = this.data.provincias.findIndex(provincia => provincia.id === data.provincia_id)
|
||||
this.data.provincias[i].comunas = data.comunas
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
draw() {
|
||||
return {
|
||||
comunas: () => {
|
||||
const dropdown = $(this.id)
|
||||
const menu = dropdown.find('.menu')
|
||||
menu.html('')
|
||||
this.data.provincias.forEach(provincia => {
|
||||
menu.append(
|
||||
$('<div></div>').addClass('header').html(provincia.descripcion)
|
||||
)
|
||||
menu.append(
|
||||
$('<div></div>').addClass('divider')
|
||||
)
|
||||
provincia.comunas.forEach(comuna => {
|
||||
menu.append(
|
||||
$('<div></div>').addClass('item').attr('data-value', comuna.id).html(comuna.descripcion)
|
||||
)
|
||||
})
|
||||
})
|
||||
dropdown.dropdown('refresh')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Region {
|
||||
id
|
||||
comuna
|
||||
|
||||
constructor({id, comuna}) {
|
||||
this.id = id
|
||||
this.comuna = comuna
|
||||
|
||||
const dd = $(this.id)
|
||||
dd.dropdown({
|
||||
fireOnInit: true,
|
||||
onChange: value => {
|
||||
this.comuna.data.region = value
|
||||
this.comuna.get().provincias()
|
||||
}
|
||||
})
|
||||
dd.dropdown('set selected', 13)
|
||||
}
|
||||
}
|
||||
class PersonaNatural {
|
||||
valid
|
||||
constructor({valid}) {
|
||||
this.valid = valid
|
||||
}
|
||||
draw() {
|
||||
const lines = [
|
||||
'<label for="rut">RUT</label>',
|
||||
'<div class="inline field">',
|
||||
'<input type="text" id="rut" name="rut" />',
|
||||
'<span class="ui error message" id="alert_rut">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
'</span>',
|
||||
'</div>',
|
||||
'<label for="nombres">Nombre</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="nombres" id="nombres" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_paterno" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_materno" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label for="calle">Dirección</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle" id="calle" size="16" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero" size="5" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="two wide field"></div>',
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="comuna">',
|
||||
'<input type="hidden" name="comuna" />',
|
||||
'<div class="default text">Comuna</div>',
|
||||
'<div class="menu"></div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="six wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="region">',
|
||||
'<input type="hidden" name="region" />',
|
||||
'<div class="default text">Región</div>',
|
||||
'<div class="menu">',
|
||||
...regiones,
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
]
|
||||
return lines.join("\n")
|
||||
}
|
||||
activate() {
|
||||
new Rut({id: '#rut', alert_id: '#alert_rut', valid: this.valid})
|
||||
const comuna = new Comuna('#comuna')
|
||||
new Region({id: '#region', comuna})
|
||||
}
|
||||
}
|
||||
class PersonaTributaria {
|
||||
persona
|
||||
constructor({valid}) {
|
||||
this.persona = new PersonaNatural({valid})
|
||||
}
|
||||
draw() {
|
||||
const lines = [
|
||||
'<label for="rut">RUT Sociedad</label>',
|
||||
'<div class="inline field">',
|
||||
'<input type="text" id="rut_sociedad" name="rut_sociedad" />',
|
||||
'<span class="ui error message" id="alert_rut_sociedad">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
'</span>',
|
||||
'</div>',
|
||||
'<label for="razon_social">Razón Social</label>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="razon_social" id="razon_social" />',
|
||||
'</div>',
|
||||
'<label for="calle_comercial">Dirección Comercial</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle_comercial" id="calle_comercial" size="16" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero_comercial" size="5" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra_comercial" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="two wide field"></div>',
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="comuna_sociedad">',
|
||||
'<input type="hidden" name="comuna_sociedad" />',
|
||||
'<div class="default text">Comuna</div>',
|
||||
'<div class="menu"></div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="six wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="region_sociedad">',
|
||||
'<input type="hidden" name="region_sociedad" />',
|
||||
'<div class="default text">Región</div>',
|
||||
'<div class="menu">',
|
||||
...regiones,
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div>Representante Legal</div>',
|
||||
]
|
||||
return [lines.join("\n"), this.persona.draw()].join("\n")
|
||||
}
|
||||
activate() {
|
||||
new Rut({id: '#rut_sociedad', alert_id: '#alert_rut_sociedad'})
|
||||
const comuna = new Comuna('#comuna_sociedad')
|
||||
new Region({id: '#region_sociedad', comuna})
|
||||
this.persona.activate()
|
||||
}
|
||||
}
|
||||
class MultiplesPersonas {
|
||||
persona
|
||||
constructor({valid}) {
|
||||
this.persona = new PersonaNatural({valid})
|
||||
}
|
||||
|
||||
draw() {
|
||||
let lines = [
|
||||
this.persona.draw(),
|
||||
'<label for="rut">RUT Otro</label>',
|
||||
'<div class="inline field">',
|
||||
'<input type="text" id="rut_otro" name="rut_otro" />',
|
||||
'<span class="ui error message" id="alert_rut_otro">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
'</span>',
|
||||
'</div>',
|
||||
'<label for="nombres_otro">Nombre Otro</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="nombres_otro" id="nombres_otro" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_paterno_otro" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_materno_otro" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label for="calle_otro">Dirección Otro</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle_otro" id="calle_otro" size="16" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero_otro" size="5" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra_otro" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="two wide field"></div>',
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="comuna_otro">',
|
||||
'<input type="hidden" name="comuna_otro" />',
|
||||
'<div class="default text">Comuna</div>',
|
||||
'<div class="menu"></div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="six wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="region_otro">',
|
||||
'<input type="hidden" name="region_otro" />',
|
||||
'<div class="default text">Región</div>',
|
||||
'<div class="menu">',
|
||||
...regiones,
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
]
|
||||
return lines.join("\n")
|
||||
}
|
||||
activate() {
|
||||
this.persona.activate()
|
||||
new Rut({id: '#rut_otro', alert_id: '#alert_rut_otro'})
|
||||
const comuna = new Comuna('#comuna_otro')
|
||||
new Region({id: '#region_otro', comuna})
|
||||
}
|
||||
}
|
||||
class Propietario {
|
||||
ids
|
||||
|
||||
constructor({id, id_tipo, id_cantidad}) {
|
||||
this.ids = {
|
||||
span: id,
|
||||
tipo: id_tipo,
|
||||
cantidad: id_cantidad
|
||||
}
|
||||
|
||||
document.getElementById(this.ids.tipo).onchange = event => {
|
||||
const cantidad = document.getElementById(this.ids.cantidad)
|
||||
cantidad.disabled = !event.currentTarget.checked;
|
||||
this.draw()
|
||||
}
|
||||
document.getElementById(this.ids.cantidad).onchange = event => {
|
||||
this.draw()
|
||||
}
|
||||
document.getElementById(this.ids.cantidad).disabled = !document.getElementById(this.ids.tipo).checked
|
||||
|
||||
this.draw()
|
||||
|
||||
$(this.ids.span).find('#rut')
|
||||
}
|
||||
get tipo() {
|
||||
return document.getElementById(this.ids.tipo).checked ? (document.getElementById(this.ids.cantidad).checked ? 2 : 0) : 1
|
||||
}
|
||||
get() {
|
||||
return {
|
||||
propietario: tipo => {
|
||||
const map = {
|
||||
0: new PersonaNatural({valid: rut => this.fetch().propietario(rut)}),
|
||||
1: new PersonaTributaria({valid: () => {}}),
|
||||
2: new MultiplesPersonas({valid: () => {}})
|
||||
}
|
||||
return map[tipo]
|
||||
}
|
||||
}
|
||||
}
|
||||
fetch() {
|
||||
return {
|
||||
propietario: rut => {
|
||||
const uri = '{{$urls->api}}/ventas/propietario/' + rut.split('-')[0]
|
||||
return fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.propietario !== null) {
|
||||
const parent = $(this.ids.span)
|
||||
parent.find("[name='nombres']").val(data.propietario.nombres)
|
||||
parent.find("[name='apellido_paterno']").val(data.propietario.apellidos.paterno)
|
||||
parent.find("[name='apellido_materno']").val(data.propietario.apellidos.materno)
|
||||
parent.find("[name='calle']").val(data.propietario.direccion.calle)
|
||||
parent.find("[name='numero']").val(data.propietario.direccion.numero)
|
||||
parent.find("[name='extra']").val(data.propietario.direccion.extra)
|
||||
parent.find('#region').dropdown('set selected', data.propietario.direccion.comuna.provincia.region.id)
|
||||
parent.find('#comuna').dropdown('set selected', data.propietario.direccion.comuna.id)
|
||||
|
||||
if (data.propietario.representante !== '') {
|
||||
document.getElementById(this.ids.tipo).trigger('check')
|
||||
} else {
|
||||
if (data.propietario.otro) {
|
||||
document.getElementById(this.ids.cantidad).trigger('check')
|
||||
}
|
||||
}
|
||||
}
|
||||
console.debug(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
draw() {
|
||||
const propietario = this.get().propietario(this.tipo)
|
||||
$(this.ids.span).html(propietario.draw())
|
||||
propietario.activate()
|
||||
}
|
||||
}
|
||||
|
||||
class Proyecto {
|
||||
ids
|
||||
data
|
||||
unidades
|
||||
added
|
||||
|
||||
constructor({unidades_id, proyecto_id}) {
|
||||
this.ids = {
|
||||
proyecto: proyecto_id,
|
||||
unidades: unidades_id,
|
||||
buttons: []
|
||||
}
|
||||
this.data = {id: 0}
|
||||
this.unidades = []
|
||||
this.added = []
|
||||
|
||||
$(this.ids.proyecto).dropdown({
|
||||
fireOnInit: true,
|
||||
onChange: (value, text, $choice) => {
|
||||
this.data.id = value
|
||||
this.ids.buttons.forEach(button => {
|
||||
$(button).prop('disabled', true)
|
||||
})
|
||||
this.reset()
|
||||
this.fetch().unidades().then(() => {
|
||||
this.ids.buttons.forEach(button => {
|
||||
$(button).prop('disabled', false)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
const buttons = [
|
||||
'departamento',
|
||||
'estacionamiento',
|
||||
'bodega'
|
||||
]
|
||||
buttons.forEach(name => {
|
||||
const id = '#agregar_' + name
|
||||
this.ids.buttons.push(id)
|
||||
$(id).click(event => {
|
||||
this.add(name)
|
||||
})
|
||||
})
|
||||
}
|
||||
fetch() {
|
||||
return {
|
||||
unidades: () => {
|
||||
const uri = '{{$urls->api}}/proyecto/' + this.data.id + '/unidades'
|
||||
return fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.total === 0) {
|
||||
return
|
||||
}
|
||||
this.unidades = data.unidades
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
add(tipo) {
|
||||
const number = Math.floor(Math.random() * 1000)
|
||||
const unidad = new Unidad({number})
|
||||
this.added.push(unidad)
|
||||
$(this.ids.unidades).append(
|
||||
$('<tr></tr>').attr('data-number', number).append(
|
||||
$('<td></td>').append(
|
||||
unidad.draw(this.unidades[tipo])
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<button></button>').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append(
|
||||
$('<i></i>').addClass('remove icon')
|
||||
).click(event => {
|
||||
const number = $(event.currentTarget).attr('data-number')
|
||||
this.remove(number)
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
remove(number) {
|
||||
number = parseInt(number)
|
||||
const index = this.added.findIndex(unidad => unidad.number === number)
|
||||
if (index === -1) {
|
||||
return
|
||||
}
|
||||
$(this.ids.unidades).find("tr[data-number='" + number + "']").remove()
|
||||
this.added.splice(index, 1)
|
||||
}
|
||||
reset() {
|
||||
this.added = []
|
||||
$(this.ids.unidades).html('')
|
||||
}
|
||||
}
|
||||
class Unidad{
|
||||
number
|
||||
constructor({number}) {
|
||||
this.number = number
|
||||
}
|
||||
|
||||
draw(unidades) {
|
||||
const dropdown = $('<div></div>').addClass('ui search selection dropdown')
|
||||
const tipo = unidades[0].proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
dropdown.append(
|
||||
$('<input />').attr('type', 'hidden').attr('name', 'unidad' + this.number)
|
||||
).append(
|
||||
$('<div></div>').addClass('default text').html(tipo.charAt(0).toUpperCase() + tipo.slice(1))
|
||||
).append(
|
||||
$('<i></i>').addClass('dropdown icon')
|
||||
)
|
||||
const menu = $('<div></div>').addClass('menu')
|
||||
unidades.forEach(unidad => {
|
||||
menu.append(
|
||||
$('<div></div>').addClass('item').attr('data-value', unidad.id).html(unidad.descripcion)
|
||||
)
|
||||
})
|
||||
dropdown.append(menu)
|
||||
dropdown.dropdown()
|
||||
return $('<div></div>').addClass('inline fields').attr('data-number', this.number).append(dropdown)
|
||||
}
|
||||
}
|
||||
|
||||
const unidades = {
|
||||
data: []
|
||||
}
|
||||
|
||||
class Payment {
|
||||
ids
|
||||
|
||||
constructor({id, checkbox_id}) {
|
||||
this.ids = {
|
||||
base: id,
|
||||
checkbox: checkbox_id
|
||||
}
|
||||
|
||||
$(this.ids.base).hide()
|
||||
document.getElementById(this.ids.checkbox).onchange = event => {
|
||||
this.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
get status() {
|
||||
return document.getElementById(this.ids.checkbox).checked
|
||||
}
|
||||
toggle() {
|
||||
if (this.status) {
|
||||
$(this.ids.base).show()
|
||||
return
|
||||
}
|
||||
$(this.ids.base).hide()
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
$('#fecha_venta_calendar').calendar({
|
||||
type: 'date',
|
||||
formatter: {
|
||||
date: 'DD-MM-YYYY'
|
||||
}
|
||||
})
|
||||
new Propietario({id: '#propietario', id_tipo: 'persona_propietario', id_cantidad: 'cantidad_propietario'})
|
||||
new Proyecto({unidades_id: '#unidades', proyecto_id: '#proyecto'})
|
||||
|
||||
const payments = [
|
||||
'pie',
|
||||
'subsidio',
|
||||
'credito',
|
||||
'bono_pie'
|
||||
]
|
||||
payments.forEach(payment => {
|
||||
new Payment({
|
||||
id: '#' + payment,
|
||||
checkbox_id: 'has_' + payment
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
144
app/resources/views/ventas/cuotas/abonar.blade.php
Normal file
144
app/resources/views/ventas/cuotas/abonar.blade.php
Normal file
@ -0,0 +1,144 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h3 class="ui header">Abonar Cuotas</h3>
|
||||
<div class="ui grid">
|
||||
<div class="two wide column">Total</div>
|
||||
<div class="column">{{count($cuotas_depositadas)}}</div>
|
||||
<div class="two wide column">{{$format->pesos(array_reduce($cuotas_depositadas, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}</div>
|
||||
</div>
|
||||
<table class="ui striped table" id="cuotas">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="two wide column">Proyecto</th>
|
||||
<th class="column">Departamento</th>
|
||||
<th>Departamento Sort</th>
|
||||
<th class="two wide column">Propietario</th>
|
||||
<th class="column">Valor Cuota</th>
|
||||
<th class="column">Fecha Cuota</th>
|
||||
<th>Fecha ISO</th>
|
||||
<th class="column">Fecha Depositada</th>
|
||||
<th class="two wide column">Fecha Abono / Devolución</th>
|
||||
<th class="column">Acción</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($cuotas_depositadas as $cuota)
|
||||
<tr>
|
||||
<td>{{$cuota['Proyecto']}}</td>
|
||||
<td>
|
||||
<a href="{{$urls->base}}/venta/{{$cuota['venta_id']}}">{{$cuota['Departamento']}}</a>
|
||||
</td>
|
||||
<td>{{str_pad($cuota['Departamento'], 4, 0, STR_PAD_LEFT)}}</td>
|
||||
<td>{{$cuota['Propietario']}}</td>
|
||||
<td>{{$format->pesos($cuota['Valor'])}}</td>
|
||||
<td>{{$cuota['Fecha Cheque']}}</td>
|
||||
<td>{{$cuota['Fecha ISO']}}</td>
|
||||
<td>{{$cuota['Fecha Depositada']}}</td>
|
||||
<td>
|
||||
<div class="ui calendar" data-cuota="{{$cuota['id']}}">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha_abono{{$cuota['id']}}" />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="ui vertical buttons">
|
||||
<button class="ui green icon button abonar" title="Abonar">
|
||||
<i class="check icon"></i>
|
||||
</button>
|
||||
<button class="ui red icon button devolver" title="Devolver">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(() => {
|
||||
const cuotas_tables = new DataTable('#cuotas', {
|
||||
language: {
|
||||
info: 'Mostrando página _PAGE_ de _PAGES_',
|
||||
infoEmpty: 'No hay cuotas depositadas por abonar',
|
||||
infoFiltered: '(filtrado de _MAX_ cuotas)',
|
||||
lengthMenu: 'Mostrando de a _MENU_ cuotas',
|
||||
zeroRecords: 'No se encotró cuotas con ese criterio',
|
||||
search: 'Buscar: '
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
target: 6,
|
||||
visible: false
|
||||
},
|
||||
{
|
||||
target: 2,
|
||||
visible: false,
|
||||
searchable: false
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[6, 'desc'],
|
||||
[0, 'asc'],
|
||||
[2, 'asc']
|
||||
]
|
||||
})
|
||||
$('.ui.calendar').calendar({
|
||||
type: 'date',
|
||||
formatter: {
|
||||
date: 'DD-MM-YYYY'
|
||||
}
|
||||
})
|
||||
$('.abonar.button').click(event => {
|
||||
const button = $(event.currentTarget)
|
||||
const cuota_id = button.data('cuota')
|
||||
const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date')
|
||||
const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-')
|
||||
fetch('{{$urls->api}}/ventas/cuota/abonar', {
|
||||
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha})
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.depositada) {
|
||||
const button = $(".depositar.button[data-cuota='" + data.cuota_id + "']")
|
||||
const cell = button.parent()
|
||||
const row = cell.parent()
|
||||
cuotas_tables.row(row).remove().draw()
|
||||
}
|
||||
})
|
||||
})
|
||||
$('.devolver.button').click(event => {
|
||||
const button = $(event.currentTarget)
|
||||
const cuota_id = button.data('cuota')
|
||||
const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date')
|
||||
const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-')
|
||||
fetch('{{$urls->api}}/ventas/cuota/devolver', {
|
||||
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha})
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
if (data.depositada) {
|
||||
const button = $(".depositar.button[data-cuota='" + data.cuota_id + "']")
|
||||
const cell = button.parent()
|
||||
const row = cell.parent()
|
||||
cuotas_tables.row(row).remove().draw()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -6,7 +6,7 @@
|
||||
<div class="ui grid">
|
||||
<div class="two wide column">Total</div>
|
||||
<div class="column">{{count($cuotas_pendientes)}}</div>
|
||||
<div class="column">{{$format->pesos(array_reduce($cuotas_pendientes, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}</div>
|
||||
<div class="two wide column">{{$format->pesos(array_reduce($cuotas_pendientes, function($sum, $cuota) {return $sum + $cuota['Valor'];}, 0))}}</div>
|
||||
</div>
|
||||
<table class="ui striped table" id="cuotas">
|
||||
<thead>
|
||||
@ -14,13 +14,14 @@
|
||||
<th class="two wide column">Proyecto</th>
|
||||
<th class="column">Departamento</th>
|
||||
<th>Departamento Sort</th>
|
||||
<th class="two wide column">Propietario</th>
|
||||
<th class="column">Cuota</th>
|
||||
<th class="column">Banco</th>
|
||||
<th class="column">Valor</th>
|
||||
<th class="column">Día</th>
|
||||
<th class="column">Cuota</th>
|
||||
<th class="two wide column">Propietario</th>
|
||||
<th class="column">Banco</th>
|
||||
<th class="two wide column">Fecha Cheque (Días)</th>
|
||||
<th>Fecha ISO</th>
|
||||
<th class="two wide column">Fecha Deposito</th>
|
||||
<th class="column">Depositar</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -34,16 +35,24 @@
|
||||
</a>
|
||||
</td>
|
||||
<td>{{str_pad($cuota['Departamento'], 4, '0', STR_PAD_LEFT)}}</td>
|
||||
<td>{{$cuota['Propietario']}}</td>
|
||||
<td>{{$cuota['Numero']}}</td>
|
||||
<td>{{$cuota['Banco']}}</td>
|
||||
<td>{{$format->pesos($cuota['Valor'])}}</td>
|
||||
<td>{{$cuota['Dia']}}</td>
|
||||
<td>{{$cuota['Numero']}}</td>
|
||||
<td>{{$cuota['Propietario']}}</td>
|
||||
<td>{{$cuota['Banco']}}</td>
|
||||
<td>{{$cuota['Fecha Cheque']}} ({{$cuota['Vencida']}})</td>
|
||||
<td>{{$cuota['Fecha ISO']}}</td>
|
||||
<td>
|
||||
<div class="ui calendar" data-cuota="{{$cuota['id']}}">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha_deposito{{$cuota['id']}}" />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button class="ui icon button depositar" data-cuota="{{$cuota['id']}}">
|
||||
<i class="currency icon"></i>
|
||||
<i class="dollar icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@ -85,11 +94,19 @@
|
||||
[2, 'asc']
|
||||
]
|
||||
})
|
||||
$('.ui.calendar').calendar({
|
||||
type: 'date',
|
||||
formatter: {
|
||||
date: 'DD-MM-YYYY'
|
||||
}
|
||||
})
|
||||
$('.depositar.button').click(event => {
|
||||
const button = $(event.currentTarget)
|
||||
const cuota_id = button.data('cuota')
|
||||
fetch('{{$urls->base}}/ventas/cuota/depositar', {
|
||||
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id})
|
||||
const calendar = $(".ui.calendar[data-cuota='" + cuota_id + "']").calendar('get date')
|
||||
const fecha = [calendar.getFullYear(), calendar.getMonth()+1, calendar.getDate()].join('-')
|
||||
fetch('{{$urls->api}}/ventas/cuota/depositar', {
|
||||
method: 'post', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({cuota_id, fecha})
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
|
@ -117,7 +117,11 @@
|
||||
this.data.venta_ids = data.ventas
|
||||
const promises = []
|
||||
data.ventas.forEach(venta_id => {
|
||||
promises.push(this.get().venta(venta_id))
|
||||
const promise = this.get().venta(venta_id)
|
||||
/*promise.then(() => {
|
||||
this.draw().ventas(true)
|
||||
})*/
|
||||
promises.push(promise)
|
||||
})
|
||||
Promise.all(promises).then(() => {
|
||||
this.draw().ventas()
|
||||
@ -181,7 +185,7 @@
|
||||
parent.show()
|
||||
parent.find('.item.proyecto').click(this.actions().get)
|
||||
},
|
||||
ventas: () => {
|
||||
ventas: (loading = false) => {
|
||||
const title = $(this.ids.title)
|
||||
const parent = $(this.ids.proyectos)
|
||||
const table = $(this.ids.table)
|
||||
@ -195,6 +199,11 @@
|
||||
}
|
||||
|
||||
title.html('Ventas de ' + this.data.proyecto + ' [' + this.data.ventas.length + ']')
|
||||
if (loading) {
|
||||
title.append(
|
||||
$('<span></span>').addClass('ui active inline loader')
|
||||
)
|
||||
}
|
||||
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.data.ventas.forEach(venta => {
|
||||
|
257
app/resources/views/ventas/pagos/pendientes.blade.php
Normal file
257
app/resources/views/ventas/pagos/pendientes.blade.php
Normal file
@ -0,0 +1,257 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
Pagos Pendientes
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">Pagos Pendientes</h2>
|
||||
<div class="ui basic segment" id="pendientes"></div>
|
||||
<h2 class="ui header">Para Abonar<span id="total_abonar"></span></h2>
|
||||
<div class="ui basic segment" id="abonar"></div>
|
||||
<h2 class="ui header">Pagos Devueltos<span id="total_devueltos"></span></h2>
|
||||
<div class="ui basic segment" id="devueltos"></div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.chartjs')
|
||||
@include('layout.head.styles.datatables')
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const historicos = {
|
||||
id: '',
|
||||
data: {
|
||||
total: {
|
||||
pendientes: 0,
|
||||
depositados: 0
|
||||
},
|
||||
graph: {}
|
||||
},
|
||||
get: function() {
|
||||
return {
|
||||
pagos: () => {
|
||||
const uri = '{{$urls->api}}/ventas/pagos/pendientes'
|
||||
fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.data.total.pendientes = data.pagos.historicos
|
||||
this.data.total.depositados = data.abonos.historicos
|
||||
this.data.graph = data
|
||||
|
||||
this.draw().all()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
all: () => {
|
||||
const parent = $(this.id)
|
||||
parent.append(this.draw().table())
|
||||
this.draw().graph(parent)
|
||||
},
|
||||
table: () => {
|
||||
return $('<table></table>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').attr('rowspan', 2).html('Históricos')
|
||||
).append(
|
||||
$('<td></td>').html('Pendientes')
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/ventas/cuotas/pendientes').html(this.data.total.pendientes)
|
||||
)
|
||||
)
|
||||
).append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').html('Depositadas')
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/ventas/cuotas/abonar').html(this.data.total.depositados)
|
||||
)
|
||||
)
|
||||
)
|
||||
},
|
||||
graph: parent => {
|
||||
const canvas = $('<canvas></canvas>').attr('id', 'pagos_historicos')
|
||||
parent.append(canvas)
|
||||
const chart = new Chart(canvas, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: this.data.graph.fechas,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Pagos',
|
||||
data: this.data.graph.pagos.data,
|
||||
backgroundColor: this.data.graph.pagos.backgroundColor
|
||||
},
|
||||
{
|
||||
label: 'Abonos',
|
||||
data: this.data.graph.abonos.data,
|
||||
backgroundColor: this.data.graph.abonos.backgroundColor
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
legend: {
|
||||
display: false
|
||||
},
|
||||
scales: {
|
||||
x: [
|
||||
{
|
||||
stacked: true
|
||||
}
|
||||
],
|
||||
y: [
|
||||
{
|
||||
stacked: true
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: {
|
||||
chartJSPluginBarchartBackground: {
|
||||
color: 'rgb(100, 100, 100)'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function(id) {
|
||||
this.id = id
|
||||
this.get().pagos()
|
||||
}
|
||||
}
|
||||
const depositados = {
|
||||
ids: {
|
||||
data: '',
|
||||
total: ''
|
||||
},
|
||||
data: [],
|
||||
total: 0,
|
||||
get: function() {
|
||||
return {
|
||||
pendientes: () => {
|
||||
const uri = '{{$urls->api}}/ventas/pagos/abonar'
|
||||
fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.data = data.pagos
|
||||
this.total = data.total
|
||||
this.draw().all()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
all: () => {
|
||||
this.draw().total()
|
||||
this.draw().table($(this.ids.data))
|
||||
},
|
||||
total: () => {
|
||||
$(this.ids.total).html(' [' + this.total + ']')
|
||||
},
|
||||
table: parent => {
|
||||
const header_row = $('<tr></tr>')
|
||||
['Proyecto', 'Departamento', 'Propietario', 'Tipo', 'Fecha Deposito', 'Valor'].forEach(title => {
|
||||
header_row.append(
|
||||
$('<th></th>').html(title)
|
||||
)
|
||||
})
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.data.forEach(pago => {
|
||||
tbody.append(
|
||||
$('<tr></tr>').append(
|
||||
$('<td></td>').html(pago.proyecto)
|
||||
).append(
|
||||
$('<td></td>').html(pago.departamento)
|
||||
).append(
|
||||
$('<td></td>').html(pago.propietario)
|
||||
).append(
|
||||
$('<td></td>').html(pago.tipo)
|
||||
).append(
|
||||
$('<td></td>').html(pago.fecha)
|
||||
).append(
|
||||
$('<td></td>').html(pago.valor)
|
||||
)
|
||||
)
|
||||
})
|
||||
const table = $('<table></table>').attr('id', 'pendientes_table').append(
|
||||
$('<thead></thead>').append(header_row)
|
||||
).append(tbody)
|
||||
parent.append(table)
|
||||
const dt = new DataTable('#pendientes_table', {
|
||||
language: {
|
||||
info: 'Mostrando página _PAGE_ de _PAGES_',
|
||||
infoEmpty: 'No hay cuotas depositadas por abonar',
|
||||
infoFiltered: '(filtrado de _MAX_ cuotas)',
|
||||
lengthMenu: 'Mostrando de a _MENU_ cuotas',
|
||||
zeroRecords: 'No se encotró cuotas con ese criterio',
|
||||
search: 'Buscar: '
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function(id, total_id) {
|
||||
this.ids.data = id
|
||||
this.ids.total = total_id
|
||||
this.get().pendientes()
|
||||
}
|
||||
}
|
||||
const devueltos = {
|
||||
ids: {
|
||||
data: '',
|
||||
total: ''
|
||||
},
|
||||
data: [],
|
||||
total: 0,
|
||||
get: function() {
|
||||
return {
|
||||
devueltos: () => {
|
||||
const uri = '{{$urls->api}}/ventas/pagos/rebotes'
|
||||
fetch(uri).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(data => {
|
||||
this.data = data.pagos
|
||||
this.total = data.total
|
||||
this.draw().all()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
all: () => {
|
||||
this.draw().total()
|
||||
this.draw().table($(this.ids.data))
|
||||
},
|
||||
total: () => {
|
||||
$(this.ids.total).html(' [' + this.total + ']')
|
||||
},
|
||||
table: parent => {}
|
||||
}
|
||||
},
|
||||
setup: function(id, total_id) {
|
||||
this.ids.data = id
|
||||
this.ids.total = total_id
|
||||
this.get().devueltos()
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
historicos.setup('#pendientes')
|
||||
depositados.setup('#abonar', '#total_abonar')
|
||||
devueltos.setup('#devueltos', '#total_devueltos')
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -18,7 +18,10 @@ class Base
|
||||
}
|
||||
return $this->login($response, $view);
|
||||
}
|
||||
|
||||
public function construccion(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'construccion');
|
||||
}
|
||||
protected function home(ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository, Repository\Venta\Cierre $cierreRepository): ResponseInterface
|
||||
{
|
||||
$cuotas_hoy = count($cuotaRepository->fetchHoy()) ?? 0;
|
||||
|
28
app/src/Controller/Provincias.php
Normal file
28
app/src/Controller/Provincias.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Provincias
|
||||
{
|
||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Repository\Comuna $comunaRepository, int $provincia_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'provincia_id' => $provincia_id,
|
||||
'comunas' => []
|
||||
];
|
||||
try {
|
||||
$comunas = $comunaRepository->fetchByProvincia($provincia_id);
|
||||
usort($comunas, function(Model\Comuna $a, Model\Comuna $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['comunas'] = $comunas;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Proyectos
|
||||
{
|
||||
@ -24,4 +25,27 @@ class Proyectos
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function unidades(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Unidad $unidadRepository, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = ['proyecto_id' => $proyecto_id, 'unidades' => [], 'total' => 0];
|
||||
try {
|
||||
$unidades = $unidadRepository->fetchByProyecto($proyecto_id);
|
||||
$tipos = [];
|
||||
foreach ($unidades as $unidad) {
|
||||
if (!isset($tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion])) {
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] = [];
|
||||
}
|
||||
$tipos[$unidad->proyectoTipoUnidad->tipoUnidad->descripcion] []= $unidad;
|
||||
}
|
||||
foreach ($tipos as &$subtipo) {
|
||||
usort($subtipo, function(Model\Venta\Unidad $a, Model\Venta\Unidad $b) {
|
||||
return strcmp(str_pad($a->descripcion, 4, '0', STR_PAD_LEFT), str_pad($b->descripcion, 4, '0', STR_PAD_LEFT));
|
||||
});
|
||||
}
|
||||
$output['unidades'] = $tipos;
|
||||
$output['total'] = count($unidades);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
28
app/src/Controller/Regiones.php
Normal file
28
app/src/Controller/Regiones.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Regiones
|
||||
{
|
||||
public function provincias(ServerRequestInterface $request, ResponseInterface $response, Repository\Provincia $provinciaRepository, int $region_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'region_id' => $region_id,
|
||||
'provincias' => []
|
||||
];
|
||||
try {
|
||||
$provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||
usort($provincias, function(Model\Provincia $a, Model\Provincia $b) {
|
||||
return strcmp($a->descripcion, $b->descripcion);
|
||||
});
|
||||
$output['provincias'] = $provincias;
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@ -102,4 +102,13 @@ class Ventas
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Region $regionRepository, Repository\Proyecto $proyectoRepository): ResponseInterface
|
||||
{
|
||||
$regiones = $regionRepository->fetchAll();
|
||||
usort($regiones, function(Model\Region $a, Model\Region $b) {
|
||||
return $a->numeracion - $b->numeracion;
|
||||
});
|
||||
$proyectos = $proyectoRepository->fetchAllActive();
|
||||
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
|
||||
}
|
||||
}
|
||||
|
@ -2,61 +2,72 @@
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuotas
|
||||
{
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Repository\Venta\Cuota $cuotaRepository): ResponseInterface
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface
|
||||
{
|
||||
$cuotas = $cuotaRepository->fetchPendientes();
|
||||
$cuotas_pendientes = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$day = clone $date;
|
||||
$weekday = $date->format('N');
|
||||
if ($weekday > 5) {
|
||||
$diff = 7 - $weekday + 1;
|
||||
$day = $day->add(new DateInterval("P{$diff}D"));
|
||||
}
|
||||
$cuotas_pendientes []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Dia' => $formatter->format($day),
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Vencida' => $today->diff($date)->days,
|
||||
'Fecha ISO' => $date->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
$cuotas_pendientes = $cuotaService->pendientes();
|
||||
return $view->render($response, 'ventas.cuotas.pendientes', compact('cuotas_pendientes'));
|
||||
}
|
||||
public function depositadas(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta\Cuota $cuotaService): ResponseInterface
|
||||
{
|
||||
$cuotas_depositadas = $cuotaService->depositadas();
|
||||
return $view->render($response, 'ventas.cuotas.abonar', compact('cuotas_depositadas'));
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$fecha = new DateTimeImmutable($json->fecha);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'depositada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago);
|
||||
$output['depositada'] = $pagoService->depositar($cuota->pago, $fecha);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$fecha = new DateTimeImmutable($json->fecha);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'abonada' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['abonada'] = $pagoService->abonar($cuota->pago, $fecha);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function devolver(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Cuota $cuotaRepository, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
$cuota_id = $json->cuota_id;
|
||||
$fecha = new DateTimeImmutable($json->fecha);
|
||||
$output = [
|
||||
'cuota_id' => $cuota_id,
|
||||
'devuelta' => false
|
||||
];
|
||||
try{
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['devuelta'] = $pagoService->devolver($cuota->pago, $fecha);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
|
@ -4,10 +4,16 @@ namespace Incoviba\Controller\Ventas;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Pagos
|
||||
{
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
public function pendientes(ServerRequestInterface $request, ResponseInterface $response, View $view): ResponseInterface
|
||||
{
|
||||
return $view->render($response, 'ventas.pagos.pendientes');
|
||||
}
|
||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
@ -15,7 +21,7 @@ class Pagos
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
|
||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = json_decode($body->getContents());
|
||||
@ -23,4 +29,40 @@ class Pagos
|
||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getPendientes();
|
||||
$pagos_pendientes = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$pagos_pendientes []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getDepositados();
|
||||
$pagos_depositados = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$pagos_depositados []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||
{
|
||||
$pagos = $pagoService->getRebotes();
|
||||
$rebotes = [];
|
||||
foreach ($pagos as $pago) {
|
||||
$rebotes []= [
|
||||
'id' => $pago->id
|
||||
];
|
||||
}
|
||||
$response->getBody()->write(json_encode(['pagos' => $rebotes, 'total' => count($rebotes)]));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
@ -12,4 +13,16 @@ class Propietarios
|
||||
$propietario = $propietarioRepository->fetchById($propietario_rut);
|
||||
return $view->render($response, 'ventas.propietarios.show', compact('propietario'));
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Propietario $propietarioRepository, int $propietario_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'rut' => $propietario_rut,
|
||||
'propietario' => null
|
||||
];
|
||||
try {
|
||||
$output['propietario'] = $propietarioRepository->fetchById($propietario_rut);
|
||||
} catch (EmptyResult) {}
|
||||
$response->getBody()->write(json_encode($output));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
7
app/src/Model/Menu.php
Normal file
7
app/src/Model/Menu.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
|
||||
class Menu extends Ideal\Model
|
||||
{}
|
@ -22,7 +22,7 @@ class Inmobiliaria extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['db', 'razon', 'abreviacion', 'cuenta']))
|
||||
$map = (new Implement\Repository\MapperParser(['dv', 'razon', 'abreviacion', 'cuenta']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
|
62
app/src/Repository/Menu.php
Normal file
62
app/src/Repository/Menu.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Menu extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('menus');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['title']))
|
||||
->register('url', (new Implement\Repository\Mapper())
|
||||
->setDefault(''));
|
||||
$model = $this->parseData(new Model\Menu(), $data, $map);
|
||||
$model->children = $this->fetchChildren($model->id);
|
||||
return $model;
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['title', 'url'],
|
||||
[$model->title, $model->url]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['title', 'url'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUser(int $user_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `menu_permissions` mp ON mp.`menu_id` = a.`id`
|
||||
JOIN `permissions` ON `permissions`.`id` = mp.`permission_id`
|
||||
LEFT JOIN `users` u1 ON u1.`id` = `permissions`.`'ext_id` AND `permissions`.`type` = 2
|
||||
LEFT JOIN (SELECT u2.* FROM `roles` ON `roles`.`id` = `permissions`.`ext_id` AND `permissions`.`type` = 1
|
||||
JOIN `user_roles` ur ON ur.`role` = `role`.`id`
|
||||
JOIN `users` u2 ON u2.`id` = ur.`user`) us
|
||||
LEFT JOIN `menu_relations` mr ON mr.`child_id` = a.`id`
|
||||
WHERE u1.`id` = ? OR us.`id` = ? AND mr.`id` IS NULL";
|
||||
return $this->fetchMany($query, [$user_id, $user_id]);
|
||||
}
|
||||
public function fetchChildren(int $menu_id): array
|
||||
{
|
||||
$query = "SELECT sm.* FROM `menu_relations` mr WHERE mr.`parent_id` = ?";
|
||||
try {
|
||||
return $this->fetchMany($query, [$menu_id]);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
15
app/src/Repository/Permission.php
Normal file
15
app/src/Repository/Permission.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Permission extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('permissions');
|
||||
}
|
||||
}
|
@ -23,8 +23,8 @@ class Proyecto extends Ideal\Repository
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->setCallable([$this->direccionRepository, 'fetchById'])
|
||||
->setArgs([$data['direccion']])))
|
||||
->register('superficie_terreno', (new Implement\Repository\Mapper())
|
||||
->setProperty('terreno')
|
||||
->setFunction(function($data) {
|
||||
|
@ -106,6 +106,30 @@ FROM `{$this->getTable()}` a
|
||||
JOIN `banco` ON `banco`.`id` = `pago`.`banco`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
public function fetchDepositadas(): array
|
||||
{
|
||||
$query = "SELECT a.`id` AS 'cuota_id', `venta`.`id` AS 'venta_id', `proyecto`.`descripcion` AS 'Proyecto', `unidad`.`descripcion` AS 'Departamento',
|
||||
`pago`.`valor` AS 'Valor', `pago`.`fecha`, CONCAT_WS(' - ', a.`numero`, `pie`.`cuotas`) AS 'Numero', `banco`.`nombre` AS 'Banco', ep.`fecha` AS 'Fecha Depositada',
|
||||
CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) AS 'Propietario'
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
JOIN `pie` ON `pie`.`id` = a.`pie`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
JOIN `propietario` ON `propietario`.`rut` = `venta`.`propietario`
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
JOIN `banco` ON `banco`.`id` = `pago`.`banco`
|
||||
WHERE tep.`descripcion` = 'depositado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
|
44
app/src/Service/Menu.php
Normal file
44
app/src/Service/Menu.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public function __construct(protected Repository\Menu $menuRepository, protected Permission $permissionService, protected object $urls) {}
|
||||
|
||||
public function build(int $user_id): string
|
||||
{
|
||||
$menus = $this->getValid($user_id);
|
||||
$output = [];
|
||||
foreach ($menus as $menu) {
|
||||
$output []= $this->buildItem($menu);
|
||||
}
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
protected function buildItem(mixed $item): string
|
||||
{
|
||||
if (isset($item->submenus)) {
|
||||
return $this->buildDropdown($item);
|
||||
}
|
||||
return "<a class=\"item\" href=\"{{$this->urls->base}}/{{$item->url}}\">{{$item->title}}</a>";
|
||||
}
|
||||
protected function buildDropdown(mixed $item): string
|
||||
{
|
||||
$output []= '<div class="ui simple dropdown item">';
|
||||
$output []= $item->title;
|
||||
$output []= '<i class="dropdown icon"></i>';
|
||||
$output []= '<div class="menu">';
|
||||
foreach ($item->submenus as $menu) {
|
||||
$output []= $this->buildItem($menu);
|
||||
}
|
||||
$output []= '</div>';
|
||||
$output []= '</div>';
|
||||
return implode(PHP_EOL, $output);
|
||||
}
|
||||
|
||||
public function getValid(int $user_id): array
|
||||
{
|
||||
return $this->menuRepository->fetchByUser($user_id);
|
||||
}
|
||||
}
|
9
app/src/Service/Permission.php
Normal file
9
app/src/Service/Permission.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Permission
|
||||
{
|
||||
public function __construct(protected Repository\Permission $permissionRepository) {}
|
||||
}
|
71
app/src/Service/Venta/Cuota.php
Normal file
71
app/src/Service/Venta/Cuota.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use IntlDateFormatter;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuota
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Cuota $cuotaRepository) {}
|
||||
|
||||
public function pendientes(): array
|
||||
{
|
||||
$cuotas = $this->cuotaRepository->fetchPendientes();
|
||||
$cuotas_pendientes = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$day = clone $date;
|
||||
$weekday = $date->format('N');
|
||||
if ($weekday > 5) {
|
||||
$diff = 7 - $weekday + 1;
|
||||
$day = $day->add(new DateInterval("P{$diff}D"));
|
||||
}
|
||||
$cuotas_pendientes []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Dia' => $formatter->format($day),
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Vencida' => $today->diff($date)->days,
|
||||
'Fecha ISO' => $date->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
return $cuotas_pendientes;
|
||||
}
|
||||
public function depositadas(): array
|
||||
{
|
||||
$cuotas = $this->cuotaRepository->fetchDepositadas();
|
||||
$cuotas_depositadas = [];
|
||||
$today = new DateTimeImmutable();
|
||||
$formatter = new IntlDateFormatter('es_ES');
|
||||
$formatter->setPattern('EEEE dd');
|
||||
foreach ($cuotas as $cuota) {
|
||||
$date = new DateTimeImmutable($cuota['fecha']);
|
||||
$deposito = new DateTimeImmutable($cuota['Fecha Depositada']);
|
||||
$cuotas_depositadas []= [
|
||||
'id' => $cuota['cuota_id'],
|
||||
'venta_id' => $cuota['venta_id'],
|
||||
'Proyecto' => $cuota['Proyecto'],
|
||||
'Departamento' => $cuota['Departamento'],
|
||||
'Valor' => $cuota['Valor'],
|
||||
'Numero' => $cuota['Numero'],
|
||||
'Propietario' => $cuota['Propietario'],
|
||||
'Banco' => $cuota['Banco'],
|
||||
'Fecha Cheque' => $date->format('d-m-Y'),
|
||||
'Fecha ISO' => $date->format('Y-m-d'),
|
||||
'Fecha Depositada' => $deposito->format('d-m-Y')
|
||||
];
|
||||
}
|
||||
return $cuotas_depositadas;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use PDOException;
|
||||
use Incoviba\Repository;
|
||||
@ -12,13 +13,45 @@ class Pago
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago): bool
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('depositado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => (new DateTimeImmutable())->format('Y-m-d')
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function abonar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('abonado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function devolver(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('devuelto');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
@ -35,4 +68,17 @@ class Pago
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
return $pago;
|
||||
}
|
||||
|
||||
public function getPendientes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getDepositados(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
public function getRebotes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
BIN
incoviba.sql.gz
Normal file
BIN
incoviba.sql.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user