10 Commits

Author SHA1 Message Date
ad3285efd9 FIX: find ventas por proyecto y unidad 2024-01-30 12:07:43 -03:00
9d7857621e FIX: findPago sin numero 2024-01-22 12:10:16 -03:00
029cd095cb Base Log cli 2024-01-19 23:27:06 -03:00
c1792907c0 Basic Controller and Service 2024-01-19 23:12:13 -03:00
fa11f5b240 Cleanup logs, fixed add Venta, fixed search 2024-01-19 23:10:20 -03:00
f55e4dbd5f ventas.base 2024-01-18 17:15:32 -03:00
ca83472012 Informe escritura 2024-01-18 16:41:16 -03:00
01af47fba1 FIX: escriturar 2024-01-18 15:18:07 -03:00
e1462657fc Clave -> Contraseña 2024-01-18 13:20:02 -03:00
72f63c5e6c Cleanup 2024-01-18 13:17:23 -03:00
37 changed files with 1044 additions and 733 deletions

View File

@ -0,0 +1,9 @@
<?php
namespace Incoviba\Common\Ideal;
use Psr\Log\LoggerInterface;
abstract class Controller
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Incoviba\Common\Ideal;
use Psr\Log\LoggerInterface;
abstract class Service
{
public function __construct(protected LoggerInterface $logger) {}
}

View File

@ -1,4 +1,4 @@
<?php
use Incoviba\Controller\Search;
use Incoviba\Controller\API\Search;
$app->post('/search', [Search::class, 'query']);

View File

@ -8,4 +8,5 @@ $app->group('/unidad/{unidad_id}', function($app) {
$app->group('/prorrateo', function($app) {
$app->post('[/]', [Unidades::class, 'prorrateo']);
});
$app->get('[/]', [Unidades::class, 'get']);
});

View File

@ -2,5 +2,6 @@
use Incoviba\Controller\Ventas\Escrituras;
$app->group('/escritura/{venta_id}', function($app) {
$app->get('/informe[/]', [Escrituras::class, 'informe']);
$app->get('[/]', [Escrituras::class, 'show']);
});

View File

@ -8,7 +8,7 @@
<input type="text" id="name" name="name" />
</div>
<div class="six wide field">
<label for="password">Clave</label>
<label for="password">Contraseña</label>
<input type="password" id="password" name="password" />
</div>
<button class="ui button" id="enter">Ingresar</button>

View File

@ -107,9 +107,10 @@
const uri = '{{$urls->api}}/search'
this.data = []
return fetchAPI(uri, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
if (!response) {
return
}
return response.json()
}).catch(error => {
this.draw().clear()
this.draw().error(error)
@ -123,7 +124,11 @@
const promises = []
data.results.forEach(row => {
if (row.tipo === 'venta') {
promises.push(this.get().venta(row.id).then(json => {
return promises.push(this.get().venta(row.id).then(json => {
if (json.venta === null) {
console.debug(json)
return
}
const venta = json.venta
progress.progress('increment')
const r = new Row({unidad: venta.propiedad.unidades[0], proyecto: venta.proyecto})
@ -134,7 +139,6 @@
console.error(row)
console.error(error)
}))
return
}
promises.push(this.get().unidad(row.id).then(json => {
const unidad = json.unidad
@ -164,9 +168,10 @@
venta: id => {
const url = '{{$urls->api}}/venta/' + id
return fetchAPI(url).then(response => {
if (response.ok) {
return response.json()
if (!response) {
return
}
return response.json()
})
}
}

View File

@ -3,7 +3,7 @@
@section('page_content')
<div class="ui container">
<h2 class="ui header">Nueva Venta</h2>
<form class="ui form" id="add_form" action="{{$urls->api}}/ventas/add" method="post">
<form class="ui form" id="add_form" method="post">
<label for="fecha_venta">Fecha de Venta</label>
<div class="inline field">
<div class="ui calendar" id="fecha_venta_calendar">
@ -686,7 +686,7 @@
$('<div></div>').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append(
unidad.draw(this.unidades[tipo])
).append(
$('<button></button>').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append(
$('<button></button>').addClass('ui basic red icon button').attr('type', 'button').attr('data-number', number).append(
$('<i></i>').addClass('remove icon')
).click(event => {
const number = $(event.currentTarget).attr('data-number')
@ -766,7 +766,7 @@
}
function showErrors(errors) {
console.debug(errors)
console.error(errors)
}
$(document).ready(() => {
@ -789,20 +789,21 @@
$('#add_form').submit(event => {
event.preventDefault()
const data = new FormData(event.currentTarget)
const uri = $(event.currentTarget).attr('action')
fetch(uri, {method: 'post', body: data}).then(response => {
if (response.ok) {
return response.json()
const body = new FormData(event.currentTarget)
const uri = '{{$urls->api}}/ventas/add'
return fetchAPI(uri, {method: 'post', body}).then(response => {
if (!response) {
return false
}
}).then(data => {
if (data.status) {
window.location = '{{$urls->base}}'
return true
}
showErrors(data.errors)
return response.json().then(data => {
if (data.status) {
window.location = '{{$urls->base}}/venta/' + data.venta_id
return true
}
showErrors(data.errors)
return false
})
})
return false
})
})
</script>

View File

@ -0,0 +1,36 @@
@extends('layout.base')
@section('page_title')
Venta {{$venta->proyecto()->descripcion}} {{$venta->propiedad()->summary()}}
@endsection
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<div class="row">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</div>
</h1>
@if (isset($showPropietario) and $showPropietario)
<div class="right floated column">
@include('ventas.show.propietario')
</div>
@endif
</div>
@hasSection('venta_subtitle')
<div class="row">
<h2 class="ui sub header column">
@yield('venta_subtitle')
</h2>
</div>
@endif
</div>
<br />
@yield('venta_content')
</div>
@endsection

View File

@ -1,47 +1,43 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Desistida - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</h1>
<form class="ui form" id="desistida_form">
<div class="fields">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
@section('venta_subtitle')
Desistida
@endsection
@section('venta_content')
<form class="ui form" id="desistida_form">
<div class="fields">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
<div class="one wide field">
<div id="loading-spinner-fecha" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
<div class="one wide field">
<div id="loading-spinner-fecha" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
</div>
<div class="fields">
<div class="three wide field">
<label for="devolucion">Devolución</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
</div>
</div>
<div class="fields">
<div class="three wide field">
<label for="devolucion">Devolución</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
</div>
</div>
<div class="one wide field">
<div id="loading-spinner-devolucion" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
<div class="one wide field">
<div id="loading-spinner-devolucion" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</div>
<button class="ui red icon button" type="button" id="eliminar_desistimiento">
<i class="ban icon"></i>
Elmininar desistimiento
</button>
<div id="loading-spinner-eliminar" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</form>
</div>
</div>
<button class="ui red icon button" type="button" id="eliminar_desistimiento">
<i class="ban icon"></i>
Elmininar desistimiento
</button>
<div id="loading-spinner-eliminar" class="ui tiny blue active inline elastic loader" style="display: none;"></div>
</form>
@endsection
@push('page_scripts')

View File

@ -1,51 +1,49 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Desistir - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
</h1>
<div class="ui list">
<div class="item">
<div class="header">Valor Pagado</div>
<div class="content">
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
<div class="ui left pointing small label">
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div>
</div>
<div class="item">
<div class="header">
Multa Estandar
<div class="ui left pointing small label">5%</div>
</div>
<div class="content">
{{$format->pesos($venta->valor * 0.05 * $UF->get())}}
@section('venta_subtitle')
Desistir
@endsection
@section('venta_content')
<div class="ui list">
<div class="item">
<div class="header">Valor Pagado</div>
<div class="content">
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
<div class="ui left pointing small label">
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
</div>
</div>
</div>
<form class="ui form" id="desistir_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
<div class="item">
<div class="header">
Multa Estandar
<div class="ui left pointing small label">5%</div>
</div>
<div class="three wide field">
<label for="devolucion">Devolución [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="devolucion" />
</div>
<div class="content">
{{$format->pesos($venta->valor * 0.05 * $UF->get())}}
</div>
<button class="ui button">Desistir</button>
</form>
</div>
</div>
<form class="ui form" id="desistir_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" />
</div>
</div>
</div>
<div class="three wide field">
<label for="devolucion">Devolución [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="devolucion" />
</div>
</div>
<button class="ui button">Desistir</button>
</form>
@endsection
@push('page_scripts')

View File

@ -1,33 +1,31 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">Editar Venta -
{{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
</h2>
<form class="ui form" id="edit_form">
<div class="inline field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" id="valor" name="valor" value="{{$venta->valor}}" />
<div class="ui label">UF</div>
@section('venta_subtitle')
Editar Venta
@endsection
@section('venta_content')
<form class="ui form" id="edit_form">
<div class="inline field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" id="valor" name="valor" value="{{$venta->valor}}" />
<div class="ui label">UF</div>
</div>
</div>
<div class="inline field">
<label for="fecha">Fecha Promesa</label>
<div class="ui calendar" id="fecha_calendar">
<div class="ui icon input">
<input type="text" name="fecha" id="fecha" />
<i class="calendar icon"></i>
</div>
</div>
<div class="inline field">
<label for="fecha">Fecha Promesa</label>
<div class="ui calendar" id="fecha_calendar">
<div class="ui icon input">
<input type="text" name="fecha" id="fecha" />
<i class="calendar icon"></i>
</div>
</div>
</div>
<button class="ui button">
Guardar
</button>
</form>
</div>
</div>
<button class="ui button">
Guardar
</button>
</form>
@endsection
@push('page_scripts')

View File

@ -1,210 +1,206 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h1 class="ui header">
Escriturar - {{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</h1>
<div class="ui basic segment">
<div class="ui four columns grid">
<div class="column">Faltante</div>
<div class="column">{{$format->pesos($venta->saldo('pesos'))}}</div>
<div class="column">{{$format->ufs($venta->saldo())}}</div>
@section('venta_subtitle')
Escriturar
@endsection
@section('venta_content')
<div class="ui basic segment">
<div class="ui four columns grid">
<div class="column">Faltante</div>
<div class="column">{{$format->pesos($venta->saldo('pesos'))}}</div>
<div class="column">{{$format->ufs($venta->saldo())}}</div>
</div>
</div>
<div class="ui divider"></div>
<form class="ui form" id="escriturar_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
</div>
</div>
</div>
<div class="ui divider"></div>
<form class="ui form" id="escriturar_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha" />
@if ($venta->formaPago()->pie->reajuste === null)
<h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4>
<div class="fields optional" id="reajuste">
<div class="field">
<label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_reajuste" id="valor_reajuste" />
</div>
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui calendar" id="fecha_reajuste">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_reajuste" />
</div>
</div>
</div>
</div>
@if ($venta->formaPago()->pie->reajuste === null)
<h4 class="ui header optional" data-name="reajuste">Reajuste <i class="small plus icon"></i></h4>
<div class="fields optional" id="reajuste">
<div class="field">
<label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_reajuste" id="valor_reajuste" />
</div>
@else
<h4 class="ui header" data-name="reajuste">Reajuste</h4>
<div class="fields" id="reajuste">
<div class="field">
<label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" />
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui calendar" id="fecha_reajuste">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_reajuste" />
</div>
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" />
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->escritura))
<h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4>
<div class="fields optional" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_pago_pesos" id="valor_pago_pesos" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled input">
<input type="text" name="valor_pago_ufs" id="valor_pago_ufs" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui calendar" id="fecha_pago">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_pago" />
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="reajuste">Reajuste</h4>
<div class="fields" id="reajuste">
<div class="field">
<label for="valor_reajuste">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->pie->reajuste->valor)}}" />
</div>
</div>
@else
<h4 class="ui header" data-name="pago">Pago en Escritura</h4>
<div class="fields" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor)}}" />
</div>
<div class="field">
<label for="fecha_reajuste">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->pie->reajuste->fecha->format('d-m-Y')}}" />
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor(),2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->escritura->pago->fecha->format('d-m-Y')}}">
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->subsidio))
<h4 class="ui header optional" data-name="subsidio">Subsidio <i class="small plus icon"></i></h4>
<div class="fields optional" id="subsidio">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_ahorro" id="valor_ahorro" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_subsidio" id="valor_subsidio" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="total_subsidio">Total</label>
<div class="ui right labeled disabled input">
<input type="text" id="total_subsidio" value="0,00" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="subsidio">Subsidio</h4>
<div class="fields">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subsidio->ahorro->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subidio->pago->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->credito) or $venta->formaPago()->credito->pago->banco === null)
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled input">
<input type="text" id="valor_credito" name="valor_credito" value="{{$venta->formaPago()->credito?->pago->valor() ?? ''}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui selection dropdown" id="banco_credito">
<input type="hidden" name="banco_credito" />
<div class="default text">Banco</div>
<i class="dropdown icon"></i>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</div>
</div>
@endif
@if (!isset($venta->formaPago()->escritura))
<h4 class="ui header optional" data-name="pago">Pago en Escritura <i class="small plus icon"></i></h4>
<div class="fields optional" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled input">
<div class="ui basic label">$</div>
<input type="text" name="valor_pago_pesos" id="valor_pago_pesos" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled input">
<input type="text" name="valor_pago_ufs" id="valor_pago_ufs" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui calendar" id="fecha_pago">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" class="fecha_pago" />
</div>
</div>
</div>
@else
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
@else
<h4 class="ui header" data-name="pago">Pago en Escritura</h4>
<div class="fields" id="pago">
<div class="field">
<label for="valor_pago_pesos">Valor [$]</label>
<div class="ui left labeled disabled input">
<div class="ui basic label">$</div>
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor)}}" />
</div>
</div>
<div class="field">
<label for="valor_pago_ufs">(Valor [UF])</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->escritura->pago->valor(),2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="fecha_pago">Fecha</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->escritura->pago->fecha->format('d-m-Y')}}">
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->credito->pago->banco->nombre}}" />
</div>
</div>
@endif
@if (!isset($venta->formaPago()->subsidio))
<h4 class="ui header optional" data-name="subsidio">Subsidio <i class="small plus icon"></i></h4>
<div class="fields optional" id="subsidio">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_ahorro" id="valor_ahorro" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio [UF]</label>
<div class="ui right labeled input">
<input type="text" name="valor_subsidio" id="valor_subsidio" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="total_subsidio">Total</label>
<div class="ui right labeled disabled input">
<input type="text" id="total_subsidio" value="0,00" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@else
<h4 class="ui header" data-name="subsidio">Subsidio</h4>
<div class="fields">
<div class="field">
<label for="valor_ahorro">Valor Ahorrado</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subsidio->ahorro->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="field">
<label for="valor_subsidio">Valor Subsidio</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$venta->formaPago()->subidio->pago->valor()}}" />
<div class="ui basic label">UF</div>
</div>
</div>
</div>
@endif
@if (isset($venta->formaPago()->credito) and $venta->formaPago()->credito->pago->banco === null)
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui selection dropdown" id="banco_credito">
<input type="hidden" name="banco_credito" />
<div class="default text">Banco</div>
<i class="dropdown icon"></i>
<div class="menu">
@foreach ($bancos as $banco)
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</div>
</div>
</div>
@else
<h4 class="ui header">Crédito</h4>
<div class="fields">
<div class="field">
<label for="valor_credito">Valor [UF]</label>
<div class="ui right labeled disabled input">
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
<div class="ui basic label">UF</div>
</div>
</div>
<div class="four wide field">
<label for="banco_credito">Banco</label>
<div class="ui disabled input">
<input type="text" value="{{$venta->formaPago()->credito->pago->banco->nombre}}" />
</div>
</div>
</div>
@endif
<button class="ui button">Escriturar</button>
</form>
</div>
</div>
@endif
<button class="ui button">Escriturar</button>
</form>
@endsection
@push('page_scripts')
@ -254,9 +250,15 @@
$('#escriturar_form').submit(event => {
event.preventDefault()
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
const data = new FormData(event.currentTarget)
data.set('fecha', $('#fecha').calendar('get date').toISOString())
fetchAPI(url, {method: 'post', body: data}).then(response => {
const body = new FormData(event.currentTarget)
body.set('fecha', $('#fecha').calendar('get date').toISOString())
if (body.get('fecha_pago') !== '') {
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
}
if (body.get('fecha_reajuste') !== '') {
body.set('fecha_reajuste', $('#fecha_reajuste').calendar('get date').toISOString())
}
fetchAPI(url, {method: 'post', body}).then(response => {
if (response.ok) {
return response.json()
}
@ -267,6 +269,8 @@
})
return false
})
$('#fecha_pago').calendar(calendar_date_options)
$('#fecha_reajuste').calendar(calendar_date_options)
})
</script>
@endpush

View File

@ -0,0 +1,88 @@
@extends('ventas.base')
@section('venta_subtitle')
Resumen Escritura
@endsection
@section('venta_content')
<div class="ui segment">
El departamento {{$venta->propiedad()->departamentos()[0]->descripcion}}:<br />
@php
$estacionamientos = $venta->propiedad()->estacionamientos();
@endphp
@if (count($estacionamientos) === 0)
no tiene estacionamientos
@else
tiene
{{count($estacionamientos) === 1 ? 'el' : 'los'}}
estacionamiento{{count($estacionamientos) === 1 ? '': 's'}}
{{implode(', ', array_map(function(Incoviba\Model\Venta\Unidad $unidad) {
return $unidad->descripcion;
}, $estacionamientos))}}
@endif
y
@php
$bodegas = $venta->propiedad()->bodegas();
@endphp
@if (count($bodegas) === 0)
no tiene bodegas
@else
tiene
{{count($bodegas) === 1 ? 'la' : 'las'}}
bodega{{count($bodegas) === 1 ? '' : 's'}}
{{implode(', ', array_map(function(Incoviba\Model\Venta\Unidad $unidad) {
return $unidad->descripcion;
}, $bodegas))}}
@endif
<br />
<br />
<strong>PRECIO</strong>
{{$format->ufs($venta->valor)}}
<div class="ui fitted divider"></div>
<br />
@if (isset($venta->formaPago()->pie))
@php($pie = $venta->formaPago()->pie)
<strong>PIE</strong>
{{$pie->cuotas}} cuotas que suman
{{$format->pesos($pie->pagado('pesos'))}}
equivalente a
{{$format->ufs($pie->pagado())}}.
<br />
@endif
@if (isset($venta->formaPago()->escritura))
@php($escritura = $venta->formaPago()->escritura)
<strong>ESCRITURA</strong>
{{$format->pesos($escritura->pago->valor)}}
el
{{$escritura->fecha->format('d-m-Y')}}
equivalente a
{{$format->ufs($escritura->pago->valor())}}
<br />
@endif
<div class="ui fitted divider"></div>
<strong>TOTAL ANTICIPO</strong>
{{$format->ufs($venta->formaPago()->anticipo())}}
<br />
@if (isset($venta->formaPago()->bonoPie))
@php($bono = $venta->formaPago()->bonoPie)
<strong>BONO PIE</strong>
{{$format->ufs($bono->pago->valor())}}
<br />
@endif
@if (isset($venta->formaPago()->credito))
@php($credito = $venta->formaPago()->credito)
<strong>CRÉDITO</strong>
{{$format->ufs($credito->pago->valor())}}
en Banco {{$credito->pago->banco->nombre}}
<br />
@endif
<div class="ui fitted divider"></div>
<strong>TOTAL</strong>
{{$format->ufs($venta->formaPago()->total())}}
@if (($venta->formaPago()->total() - $venta->valor) !== 0)
<br />
<br />
Diferencia {{$format->ufs($venta->formaPago()->total() - $venta->valor)}}. ({{$format->percent(($venta->formaPago()->total() - $venta->valor) / $venta->valor * 100)}})
@endif
</div>
@endsection

View File

@ -1,27 +1,22 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">
Escritura -
{{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">
{{$venta->propiedad()->summary()}}
</a>
</h2>
<form class="ui form" id="edit_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" placeholder="Fecha" />
</div>
@section('venta_subtitle')
Escritura
@endsection
@section('venta_content')
<form class="ui form" id="edit_form">
<div class="three wide field">
<label for="fecha">Fecha</label>
<div class="ui calendar" id="fecha">
<div class="ui left icon input">
<i class="calendar icon"></i>
<input type="text" placeholder="Fecha" />
</div>
</div>
<button class="ui button">Guardar</button>
</form>
</div>
</div>
<button class="ui button">Guardar</button>
</form>
@endsection
@push('page_scripts')

View File

@ -234,6 +234,7 @@
this.table = new DataTable(table, {
order: [[0, 'asc']],
pageLength: 50
})
},
table: () => {

View File

@ -1,146 +1,139 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
</div>
</h1>
</div>
<h2>Cuotas - Pie</h2>
<table class="ui table" id="cuotas">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Fecha ISO</th>
<th>Banco</th>
<th>Identificador</th>
<th class="right aligned">Valor</th>
<th class="right aligned">Valor UF</th>
<th>Estado</th>
<th>Fecha Estado</th>
<th>Fecha Estado ISO</th>
<th></th>
</tr>
</thead>
<tbody>@php
$now = new DateTimeImmutable();
$uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
@endphp
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tr data-pago="{{$cuota->pago->id}}"
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
class="disabled"
@endif >
<td>{{$cuota->numero}}</td>
<td>{{$cuota->pago->fecha->format('d-m-Y')}}</td>
<td>{{$cuota->pago->fecha->format('Y-m-d')}}</td>
<td>{{$cuota->pago->banco->nombre}}</td>
<td>{{$cuota->pago->identificador}}</td>
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
<td class="right aligned">
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now)
{{$format->ufs($cuota->pago->valor())}}
@endif
</td>
<td
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado')
class="green"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
class="yellow"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1)
class="red"
@endif
>{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
<td>
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado']))
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
@elseif (!in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
<div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
<div class="ui action left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_estado" />
<button class="ui green basic icon button accept_estado" data-pago="{{$cuota->pago->id}}" data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
<i class="check icon"></i>
</button>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button reject_estado" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</div>
</div>
@endif
</td>
<td>{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}</td>
<td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'anulado')
<button class="ui mini red icon basic button anular" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@section('venta_subtitle')
Cuotas - Pie
@endsection
@section('venta_content')
<table class="ui table" id="cuotas">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Fecha ISO</th>
<th>Banco</th>
<th>Identificador</th>
<th class="right aligned">Valor</th>
<th class="right aligned">Valor UF</th>
<th>Estado</th>
<th>Fecha Estado</th>
<th>Fecha Estado ISO</th>
<th></th>
</tr>
</thead>
<tbody>@php
$now = new DateTimeImmutable();
$uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
@endphp
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tr data-pago="{{$cuota->pago->id}}"
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
class="disabled"
@endif >
<td>{{$cuota->numero}}</td>
<td>{{$cuota->pago->fecha->format('d-m-Y')}}</td>
<td>{{$cuota->pago->fecha->format('Y-m-d')}}</td>
<td>{{$cuota->pago->banco->nombre}}</td>
<td>{{$cuota->pago->identificador}}</td>
<td class="right aligned">{{$format->pesos($cuota->pago->valor)}}</td>
<td class="right aligned">
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now)
{{$format->ufs($cuota->pago->valor())}}
@endif
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th class="right aligned">
{{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) {
return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ?
$cuota->pago->valor / $uf_venta :
$cuota->pago->valor());
}, 0.0))}}
</th>
<th colspan="4"></th>
</td>
<td
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado')
class="green"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
class="yellow"
@elseif ($cuota->pago->currentEstado->tipoEstadoPago->activo !== 1)
class="red"
@endif
>{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
<td>
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'anulado', 'reemplazado']))
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
@elseif (!in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
<div class="ui calendar fecha_estado" data-date="{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}">
<div class="ui action left icon input">
<i class="calendar icon"></i>
<input type="text" name="fecha_estado" />
<button class="ui green basic icon button accept_estado" data-pago="{{$cuota->pago->id}}" data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
<i class="check icon"></i>
</button>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
<button class="ui red basic icon button reject_estado" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</div>
</div>
@endif
</td>
<td>{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}</td>
<td>
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion !== 'anulado')
<button class="ui mini red icon basic button anular" data-pago="{{$cuota->pago->id}}">
<i class="remove icon"></i>
</button>
@endif
</td>
</tr>
<tr>
<th colspan="5">TOTAL PAGADO</th>
<th class="right aligned">
{{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(true),
function(int $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(true),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor();
}, 0.0))}}
</th>
<th class="right aligned">
{{$format->number($pagado / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
<tr>
<th colspan="5">POR PAGAR</th>
<th class="right aligned">
{{$format->pesos($total_pesos - $pagado_pesos)}}
</th>
<th class="right aligned">
{{$format->ufs($total - $pagado)}}
</th>
<th class="right aligned">
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
</tfoot>
</table>
</div>
@endforeach
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th class="right aligned">
{{$format->pesos($total_pesos = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($total = array_reduce($venta->formaPago()->pie->cuotas(),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) use ($now, $uf_venta) {
return $sum + (($cuota->pago->fecha > $now or $cuota->pago->uf === null) ?
$cuota->pago->valor / $uf_venta :
$cuota->pago->valor());
}, 0.0))}}
</th>
<th colspan="4"></th>
</tr>
<tr>
<th colspan="5">TOTAL PAGADO</th>
<th class="right aligned">
{{$format->pesos($pagado_pesos = array_reduce($venta->formaPago()->pie->cuotas(true),
function(int $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor;
}, 0))}}
</th>
<th class="right aligned">
{{$format->ufs($pagado = array_reduce($venta->formaPago()->pie->cuotas(true),
function(float $sum, Incoviba\Model\Venta\Cuota $cuota) {
return $sum + $cuota->pago->valor();
}, 0.0))}}
</th>
<th class="right aligned">
{{$format->number($pagado / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
<tr>
<th colspan="5">POR PAGAR</th>
<th class="right aligned">
{{$format->pesos($total_pesos - $pagado_pesos)}}
</th>
<th class="right aligned">
{{$format->ufs($total - $pagado)}}
</th>
<th class="right aligned">
{{$format->number(($total - $pagado) / $total * 100, 2)}}%
</th>
<th colspan="3"></th>
</tr>
</tfoot>
</table>
@endsection
@include('layout.body.scripts.datatables')

View File

@ -1,93 +1,86 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<h1 class="four wide column header">
<div class="content">
<div class="ui dividing sub header">{{$venta->proyecto()->descripcion}}</div>
{{$venta->propiedad()->summary()}}
</div>
</h1>
</div>
<h2>Agregar Cuotas - Pie</h2>
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add" method="post">
<table class="ui table">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Banco</th>
<th>Identificador</th>
<th>Valor</th>
</tr>
</thead>
<tbody id="cuotas">
@for ($i = count($pie->cuotas(vigentes: true)); $i < $pie->cuotas; $i ++)
<tr>
<td>{{$i + 1}}</td>
<td>
<div class="inline field">
<div class="ui calendar fecha" data-index="{{$i}}">
<div class="ui icon input">
<input type="text" name="fecha{{$i}}" />
<i class="calendar icon"></i>
</div>
</div>
<button class="ui mini compact basic icon button copy fecha" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</div>
</td>
<td>
<div class="ui search selection dropdown banco" data-index="{{$i}}">
<input type="hidden" name="banco{{$i}}" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
@if ($banco->nombre === '')
@continue
@endif
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
@section('venta_subtitle')
Agregar Cuotas - Pie
@endsection
@section('venta_content')
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add" method="post">
<table class="ui table">
<thead>
<tr>
<th>#</th>
<th>Fecha</th>
<th>Banco</th>
<th>Identificador</th>
<th>Valor</th>
</tr>
</thead>
<tbody id="cuotas">
@for ($i = count($pie->cuotas(vigentes: true)); $i < $pie->cuotas; $i ++)
<tr>
<td>{{$i + 1}}</td>
<td>
<div class="inline field">
<div class="ui calendar fecha" data-index="{{$i}}">
<div class="ui icon input">
<input type="text" name="fecha{{$i}}" />
<i class="calendar icon"></i>
</div>
</div>
<button class="ui mini compact basic icon button copy banco" type="button" data-index="{{$i}}">
<button class="ui mini compact basic icon button copy fecha" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</td>
<td>
<div class="ui input">
<input type="text" name="identificador{{$i}}" />
</div>
</td>
<td>
<div class="ui search selection dropdown banco" data-index="{{$i}}">
<input type="hidden" name="banco{{$i}}" />
<i class="dropdown icon"></i>
<div class="default text">Banco</div>
<div class="menu">
@foreach ($bancos as $banco)
@if ($banco->nombre === '')
@continue
@endif
<div class="item" data-value="{{$banco->id}}">{{$banco->nombre}}</div>
@endforeach
</div>
</td>
<td>
<div class="inline field">
<div class="ui left labeled input">
<div class="ui label">$</div>
<input type="text" name="valor{{$i}}" />
</div>
<button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</div>
<button class="ui mini compact basic icon button copy banco" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</td>
<td>
<div class="ui input">
<input type="text" name="identificador{{$i}}" />
</div>
</td>
<td>
<div class="inline field">
<div class="ui left labeled input">
<div class="ui label">$</div>
<input type="text" name="valor{{$i}}" />
</div>
</td>
</tr>
@endfor
</tbody>
<tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
<button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</td>
</tr>
</tfoot>
</table>
</form>
</div>
</div>
</td>
</tr>
@endfor
</tbody>
<tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
</button>
</td>
</tr>
</tfoot>
</table>
</form>
@endsection
@include('layout.body.scripts.dayjs')

View File

@ -1,27 +1,24 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_content')
<div class="ui container">
<h2 class="ui header">
Pie -
{{$venta->proyecto()->descripcion}} -
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
</h2>
<form class="ui form" id="edit_pie">
<div class="three wide field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->pie->valor}}" />
<div class="ui basic label">UF</div>
</div>
@section('venta_subtitle')
Pie
@endsection
@section('venta_content')
<form class="ui form" id="edit_pie">
<div class="three wide field">
<label for="valor">Valor</label>
<div class="ui right labeled input">
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->pie->valor}}" />
<div class="ui basic label">UF</div>
</div>
<div class="three wide field">
<label for="cuotas"># Cuotas</label>
<input type="number" name="cuotas" id="cuotas" value="{{$venta->formaPago()->pie->cuotas}}" />
</div>
<button class="ui button">Editar</button>
</form>
</div>
</div>
<div class="three wide field">
<label for="cuotas"># Cuotas</label>
<input type="number" name="cuotas" id="cuotas" value="{{$venta->formaPago()->pie->cuotas}}" />
</div>
<button class="ui button">Editar</button>
</form>
@endsection
@push('page_scripts')

View File

@ -1,10 +1,39 @@
@extends('layout.base')
@extends('ventas.base')
@section('page_title')
Venta {{$venta->proyecto()->descripcion}} {{$venta->propiedad()->summary()}}
@php
$showPropietario = true;
@endphp
@section('venta_content')
<div class="ui fitted basic mini segment">
@if ($venta->currentEstado()->tipoEstadoVenta->activa)
<a href="{{$urls->base}}/venta/{{$venta->id}}/desistir">
Desistir <i class="minus icon"></i>
</a>
<a href="{{$urls->base}}/venta/{{$venta->id}}/ceder">
Ceder <i clasS="right chevron icon"></i>
</a>
@else
<div class="ui red icon label">
<i class="ban icon"></i>
{{ucwords($venta->currentEstado()->tipoEstadoVenta->descripcion)}}
(<a href="{{$urls->base}}/venta/{{$venta->id}}/desistida">
{{$format->pesos($venta->resciliacion()->valor)}}
</a>)
</div>
@endif
</div>
<div class="ui segments">
@include('ventas.show.propiedad')
@include('ventas.show.detalle')
@include('ventas.show.forma_pago', ['formaPago' => $venta->formaPago()])
@include('ventas.show.escritura')
@include('ventas.show.entrega')
@include('ventas.show.comentarios')
</div>
@endsection
@section('page_content')
{{--@section('page_content')
<div class="ui container">
<div class="ui two column grid">
<h1 class="four wide column header">
@ -45,4 +74,4 @@
@include('ventas.show.comentarios')
</div>
</div>
@endsection
@endsection--}}

View File

@ -9,7 +9,7 @@
<i class="small edit icon"></i>
</a>
</sub>
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/informe">
<a href="{{$urls->base}}/ventas/escritura/{{$venta->id}}/informe">
Informe
<i class="right chevron icon"></i>
</a>

View File

@ -8,12 +8,18 @@ return [
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Debug,
Monolog\Level::Notice
Monolog\Level::Debug
),
new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/info.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Info,
Monolog\Level::Warning,
),
new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Warning,
Monolog\Level::Error,
Monolog\Level::Error
),
new Monolog\Handler\FilterHandler(

View File

@ -0,0 +1,20 @@
<?php
namespace Incoviba\Controller\API;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Service;
class Search
{
use withJson;
public function query(ServerRequestInterface $request, ResponseInterface $response,
Service\Search $service): ResponseInterface
{
$data = $request->getParsedBody();
$results = $service->query($data['query'], $data['tipo']);
$output = compact('results');
return $this->withJson($response, $output);
}
}

View File

@ -1,17 +1,19 @@
<?php
namespace Incoviba\Controller\API;
use PDOException;
use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Ideal\Controller;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\withRedis;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class Ventas
class Ventas extends Controller
{
use withJson, withRedis;
@ -55,6 +57,9 @@ class Ventas
Service\Venta $service, int $venta_id): ResponseInterface
{
$redisKey = "venta:{$venta_id}";
$output = [
'venta' => null
];
try {
$venta = $this->fetchRedis($redisService, $redisKey);
$output = compact('venta');
@ -64,12 +69,7 @@ class Ventas
$output = compact('venta');
$this->saveRedis($redisService, $redisKey, $venta);
} catch (EmptyResult $exception) {
$output = [
'error' => [
'code' => $exception->getCode(),
'message' => str_replace([PHP_EOL, "\r"], [' ', ''], $exception->getMessage())
]
];
$this->logger->notice($exception);
}
}
return $this->withJson($response, $output);
@ -178,14 +178,20 @@ class Ventas
$data = $request->getParsedBody();
$output = [
'status' => false,
'venta_id' => null,
'errors' => []
];
try {
$venta = $ventaService->add($data);
$this->saveRedis($redisService, "venta:{$venta->id}", $venta);
$output['venta_id'] = $venta->id;
$output['status'] = true;
} catch (\Exception $exception) {
$output['errors'] = $exception;
} catch (EmptyResult | PDOException $exception) {
$output['errors'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'stack' => $exception->getTraceAsString()
];
}
return $this->withJson($response, $output);
}

View File

@ -13,11 +13,4 @@ class Search
$post = $request->getParsedBody() ?? '';
return $view->render($response, 'search', compact('post', 'query', 'tipo'));
}
public function query(ServerRequestInterface $request, ResponseInterface $response, Service\Search $service): ResponseInterface
{
$data = $request->getParsedBody();
$results = $service->query($data['query'], $data['tipo']);
$response->getBody()->write(json_encode(compact('results')));
return $response->withHeader('Content-Type', 'application/json');
}
}

View File

@ -8,9 +8,16 @@ use Incoviba\Service;
class Escrituras
{
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view, Service\Venta $ventaService, int $venta_id): ResponseInterface
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.escrituras.show', compact('venta'));
}
public function informe(ServerRequestInterface $request, ResponseInterface $response, View $view,
Service\Venta $ventaService, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
return $view->render($response, 'ventas.escrituras.informe', compact('venta'));
}
}

View File

@ -17,7 +17,7 @@ class NotFound
try {
return $handler->handle($request);
} catch (HttpNotFoundException $exception) {
$this->logger->warning($exception);
$this->logger->notice($exception);
$response = $this->responseFactory->createResponse(404);
if (str_contains($request->getUri()->getPath(), '/api')) {
return $response;

View File

@ -19,8 +19,8 @@ class Venta extends Ideal\Model
public float $uf;
protected ?Pago $resciliacion;
public array $estados;
public Venta\EstadoVenta $currentEstado;
public ?array $estados;
public ?Venta\EstadoVenta $currentEstado;
public function propietario(): Venta\Propietario
{
@ -63,7 +63,7 @@ class Venta extends Ideal\Model
if (!isset($this->estados)) {
$this->estados = $this->runFactory('estados');
}
return $this->estados;
return $this->estados ?? [];
}
public function currentEstado(): ?Venta\EstadoVenta
{

View File

@ -115,13 +115,15 @@ class Venta extends Ideal\Repository
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
//->register('avalchile')
//->register('agente')
->register('resciliacion', (new Implement\Repository\Mapper())
->setFactory((new Implement\Repository\Factory())
->setCallable([$this->pagoService, 'getById'])
->setArgs(['pago_id' => $data['resciliacion']])))
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
//->register('promocion')
//->register('devolucion');
if (array_key_exists('resciliacion', $data)) {
$map = $map->register('resciliacion', (new Implement\Repository\Mapper())
->setFactory((new Implement\Repository\Factory())
->setCallable([$this->pagoService, 'getById'])
->setArgs(['pago_id' => $data['resciliacion']])));
}
return $this->parseData(new Model\Venta(), $data, $map);
}
public function save(Define\Model $model): Model\Venta
@ -147,7 +149,17 @@ class Venta extends Ideal\Repository
public function fetchByProyecto(int $proyecto_id): array
{
$query = "SELECT a.*
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
->joined('JOIN unidad ON unidad.id = pu.unidad AND pu.principal = 1')
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
->joined('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 = a.id')
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
->where('ptu.proyecto = ? AND tev.activa')
->group('a.id');
/*$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
@ -155,129 +167,158 @@ FROM `{$this->getTable()}` a
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE ptu.`proyecto` = ? AND tev.`activa`
GROUP BY a.`id`";
GROUP BY a.`id`";*/
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchIdsByProyecto(int $proyecto_id): array
{
$query = "SELECT a.`id`
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE ptu.`proyecto` = ? AND tev.`activa`
GROUP BY a.`id`";
return $this->connection->execute($query, [$proyecto_id])->fetchAll(PDO::FETCH_ASSOC);
$query = $this->connection->getQueryBuilder()
->select('a.id')
->from("{$this->getTable()} a")
->joined('JOIN propiedad_unidad pu ON pu.propiedad = a.propiedad')
->joined('JOIN unidad ON unidad.id = pu.unidad AND unidad.pt')
->joined('JOIN proyecto_tipo_unidad ptu ON ptu.id = unidad.pt')
->joined('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 = a.id')
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
->where('ptu.proyecto = ? AND tev.activa')
->group('a.id');
return $this->fetchIds($query, [$proyecto_id]);
}
public function fetchActivaByProyecto(int $proyecto_id): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE ptu.`proyecto` = ? AND tev.`activa`
GROUP BY a.`id`";
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1')
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
->joined("JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`")
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
->where('ptu.`proyecto` = ? AND tev.`activa`')
->group('a.id');
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`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 (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE `proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`";
$query = $this->connection->getQueryBuilder()
->select("a.*")
->from("`{$this->getTable()}` a")
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1')
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
->joined('JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`')
->joined("JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`")
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
->where('`proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`');
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
}
public function fetchByPie(int $pie_id): Model\Venta
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pie` = ?";
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pie = ?');
return $this->fetchOne($query, [$pie_id]);
}
public function fetchIdByPie(int $pie_id): array
{
$query = "SELECT `id` FROM `{$this->getTable()}` WHERE `pie` = ?";
return $this->connection->execute($query, [$pie_id])->fetch(PDO::FETCH_ASSOC);
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('pie = ?');
return $this->fetchId($query, [$pie_id]);
}
public function fetchByUnidad(string $unidad, string $tipo): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?";
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
->joined('JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`')
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
return $this->fetchMany($query, [$unidad, $tipo]);
}
public function fetchIdsByUnidad(string $unidad, string $tipo): array
{
$query = "SELECT a.id
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
WHERE `unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?";
return $this->connection->execute($query, [$unidad, $tipo])->fetchAll(PDO::FETCH_ASSOC);
$query = $this->connection->getQueryBuilder()
->select('a.id')
->from("{$this->getTable()} a")
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`')
->joined('JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`')
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
return $this->fetchIds($query, [$unidad, $tipo]);
}
public function fetchByPrecio(string $precio): array
{
$query = "SELECT * FROM `{$this->getTable()}` WHERE `valor_uf` = ?";
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor_uf = ?');
return $this->fetchMany($query, [$precio]);
}
public function fetchIdsByPrecio(string $precio): array
{
$query = "SELECT `id` FROM `{$this->getTable()}` WHERE `valor_uf` = ?";
return $this->connection->execute($query, [$precio])->fetchAll(PDO::FETCH_ASSOC);
$query = $this->connection->getQueryBuilder()
->select('id')
->from($this->getTable())
->where('valor_uf = ?');
return $this->fetchIds($query, [$precio]);
}
public function fetchByPropietarioAndPropiedad(int $propietario_rut, int $propiedad_id): Model\Venta
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('propietario = ? AND propiedad = ?');
return $this->fetchOne($query, [$propietario_rut, $propiedad_id]);
}
public function fetchByPropietario(string $propietario): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propietario` ON `propietario`.`rut` = a.`propietario`
WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
->where("CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario";
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario");
return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]);
}
public function fetchIdsByPropietario(string $propietario): array
{
$query = "SELECT a.id
FROM `{$this->getTable()}` a
JOIN `propietario` ON `propietario`.`rut` = a.`propietario`
WHERE CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
$query = $this->connection->getQueryBuilder()
->select('a.id')
->from("{$this->getTable()} a")
->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
->where("CONCAT_WS('-', `propietario`.`rut`, `propietario`.`dv`) LIKE :propietario OR `propietario`.`nombres` LIKE :propietario
OR `propietario`.`apellido_paterno` LIKE :propietario OR `propietario`.`apellido_materno` LIKE :propietario
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario";
return $this->connection->execute($query, [':propietario' => "%{$propietario}%"])->fetchAll(PDO::FETCH_ASSOC);
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario");
return $this->fetchIds($query, [':propietario' => "%{$propietario}%"]);
}
public function fetchByPropietarioNombreCompleto(string $propietario): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN `propietario` ON `propietario`.`rut` = a.`propietario`
WHERE CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?";
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN `propietario` ON `propietario`.`rut` = a.`propietario`')
->where("CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?");
return $this->fetchMany($query, [$propietario]);
}
public function fetchEscriturasByProyecto(int $proyecto_id): array
{
$query = "SELECT DISTINCT a.*
FROM `{$this->getTable()}` a
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
JOIN `unidad` ON `unidad`.`id` = pu.`unidad`
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id`
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
WHERE ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')
GROUP BY a.`id`";
$query = $this->connection->getQueryBuilder()
->select('DISTINCT a.*')
->from("{$this->getTable()} a")
->joined('JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`')
->joined('JOIN `unidad` ON `unidad`.`id` = pu.`unidad`')
->joined('JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`id`')
->joined("JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`")
->joined('JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`')
->where("ptu.`proyecto` = ? AND tev.`descripcion` IN ('firmado por inmobiliaria', 'escriturando')")
->group('a.id');
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchIdByEscritura(int $escritura_id): array
@ -286,7 +327,7 @@ GROUP BY a.`id`";
->select('id')
->from($this->getTable())
->where('escritura = ?');
return $this->connection->execute($query, [$escritura_id])->fetch(PDO::FETCH_ASSOC);
return $this->fetchId($query, [$escritura_id]);
}
public function fetchIdBySubsidio(int $subsidio_id): array
{
@ -294,7 +335,7 @@ GROUP BY a.`id`";
->select('id')
->from($this->getTable())
->where('subsidio = ?');
return $this->connection->execute($query, [$subsidio_id])->fetch(PDO::FETCH_ASSOC);
return $this->fetchId($query, [$subsidio_id]);
}
public function fetchIdByCredito(int $credito_id): array
{
@ -302,7 +343,7 @@ GROUP BY a.`id`";
->select('id')
->from($this->getTable())
->where('credito = ?');
return $this->connection->execute($query, [$credito_id])->fetch(PDO::FETCH_ASSOC);
return $this->fetchId($query, [$credito_id]);
}
public function fetchIdByBono(int $bono_id): array
{
@ -310,6 +351,23 @@ GROUP BY a.`id`";
->select('id')
->from($this->getTable())
->where('bono_pie = ?');
return $this->connection->execute($query, [$bono_id])->fetch(PDO::FETCH_ASSOC);
return $this->fetchId($query, [$bono_id]);
}
protected function fetchIds(string $query, ?array $data = null): array
{
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
if ($results === false) {
throw new Implement\Exception\EmptyResult($query);
}
return $results;
}
protected function fetchId(string $query, ?array $data = null): array
{
$results = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
if ($results === false) {
throw new Implement\Exception\EmptyResult($query);
}
return $results;
}
}

View File

@ -21,12 +21,16 @@ class Format
{
return number_format($number, $decimal_places, ',', '.');
}
public function percent(float|string $number, int $decimal_places = 2): string
{
return "{$this->number($number, $decimal_places)}%";
}
public function pesos(string $valor): string
{
return '$ ' . $this->number($valor);
return "$ {$this->number($valor)}";
}
public function ufs(string $valor): string
{
return $this->number($valor, 2) . ' UF';
return "{$this->number($valor, 2)} UF";
}
}

View File

@ -5,12 +5,11 @@ use DateTimeInterface;
use DateTimeImmutable;
use DateInterval;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Psr\Log\LoggerInterface;
class IPC
{
protected string $redisKey = 'ipc';
public function __construct(protected Redis $redisService, protected Money $moneyService, protected LoggerInterface $logger) {}
public function __construct(protected Redis $redisService, protected Money $moneyService) {}
public function get(DateTimeInterface $from, DateTimeInterface $to = new DateTimeImmutable()): float
{

View File

@ -65,7 +65,11 @@ class Search
foreach ($queries as $q) {
$this->add($results, $this->findVentas($q, $tipo));
if (in_array($tipo, $tiposUnidades)) {
$this->add($results, $this->findUnidadesDisponibles($q, $tipo), false);
$disponibles = $this->findUnidadesDisponibles($q, $tipo);
if (count($disponibles) === 0) {
continue;
}
$this->add($results, $disponibles, false);
}
}
return $results;
@ -138,6 +142,9 @@ class Search
}
protected function findPago(string $query): array
{
if ($query != 0) {
return [];
}
$methods = [
'findPie',
'findEscritura',
@ -148,7 +155,7 @@ class Search
$valor = str_replace(['$', '.', ','], ['', '', '.'], $query);
$pagos = [];
try {
$pagos = $this->pagoRepository->fetchByValue($valor);
$pagos = $this->pagoRepository->fetchByValue((int) $valor);
} catch (EmptyResult) {}
$results = [];
foreach ($methods as $method) {
@ -160,7 +167,7 @@ class Search
{
$results = [];
try {
$pies = $this->pieRepository->fetchByValue($query);
$pies = $this->pieRepository->fetchByValue((float) $query);
foreach ($pies as $pie) {
try {
$this->add($results, [$this->ventaRepository->fetchIdByPie($pie->id)]);
@ -176,7 +183,7 @@ class Search
$results = [];
foreach ($pagos as $pago) {
try {
$pie = $this->pieRepository->fetchByReajuste($pago->id);
$pie = $this->pieRepository->fetchByReajuste((int) $pago->id);
$this->add($results, [$this->ventaRepository->fetchIdByPie($pie->id)]);
} catch (EmptyResult) {}
}
@ -197,7 +204,7 @@ class Search
{
$results = [];
try {
$escrituras = $this->escrituraRepository->fetchByValue($query);
$escrituras = $this->escrituraRepository->fetchByValue((int) $query);
foreach ($escrituras as $escritura) {
try {
$this->add($results, [$this->ventaRepository->fetchIdByEscritura($escritura->id)]);
@ -227,7 +234,7 @@ class Search
{
$results = [];
try {
$creditos = $this->creditoRepository->fetchByValue($query);
$creditos = $this->creditoRepository->fetchByValue((int) $query);
foreach ($creditos as $credito) {
try {
$this->add($results, [$this->ventaRepository->fetchIdByCredito($credito->id)]);
@ -252,7 +259,7 @@ class Search
{
$results = [];
try {
$bonos = $this->bonoPieRepository->fetchByValue($query);
$bonos = $this->bonoPieRepository->fetchByValue((float) $query);
foreach ($bonos as $bono) {
try {
$this->add($results, [$this->ventaRepository->fetchIdByBono($bono->id)]);
@ -281,11 +288,10 @@ class Search
protected function add(array &$results, array $found, bool $is_venta = true): void
{
foreach ($found as $item) {
if (!isset($item['tipo'])) {
$item['tipo'] = ($is_venta) ? 'venta' : 'unidad';
}
if (!$this->inResults($item, $results)) {
$item['tipo'] = 'venta';
if (!$is_venta) {
$item['tipo'] = 'unidad';
}
$results []= $item;
}
}

View File

@ -5,6 +5,7 @@ use DateTimeImmutable;
use Incoviba\Common\Implement;
use Incoviba\Repository;
use Incoviba\Model;
use PhpParser\Node\Expr\AssignOp\Mod;
class Venta
{
@ -14,6 +15,8 @@ class Venta
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
protected Repository\Venta\Credito $creditoRepository,
protected Repository\Venta\Escritura $escrituraRepository,
protected Repository\Venta\Pago $pagoRepository,
protected Repository\Venta\EstadoPago $estadoPagoRepository,
protected Venta\Propietario $propietarioService,
protected Venta\Propiedad $propiedadService,
protected Venta\Pie $pieService,
@ -97,17 +100,22 @@ class Venta
$venta_data[$field] = $forma_pago->{$name}->id;
}
}
$venta = $this->ventaRepository->create($venta_data);
$venta = $this->ventaRepository->save($venta);
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('vigente');
$estado = $this->estadoVentaRepository->create([
'venta' => $venta->id,
'estado' => $tipoEstado->id,
'fecha' => $venta->fecha->format('Y-m-d')
]);
$this->estadoVentaRepository->save($estado);
try {
return $this->ventaRepository->fetchByPropietarioAndPropiedad($propietario->rut, $propiedad->id);
} catch (Implement\Exception\EmptyResult) {
$venta = $this->ventaRepository->create($venta_data);
$venta = $this->ventaRepository->save($venta);
return $venta;
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('vigente');
$estado = $this->estadoVentaRepository->create([
'venta' => $venta->id,
'estado' => $tipoEstado->id,
'fecha' => $venta->fecha->format('Y-m-d')
]);
$this->estadoVentaRepository->save($estado);
return $venta;
}
}
protected function addPropietario(array $data): Model\Venta\Propietario
{
@ -312,8 +320,8 @@ class Venta
if ($this->validarData($data, ['fecha_pago'], ['valor_pago_pesos', 'valor_pago_ufs'])) {
$this->abonoEscritura($venta, $data);
}
if ($this->validarData($data, ['banco_credito'])) {
$this->creditoRepository->edit($venta->formaPago()->credito, ['banco' => $data['banco_credito']]);
if ($this->validarData($data, ['banco_credito'], ['valor_credito'])) {
$this->editCredito($venta, $data);
}
if ($this->validarData($data, ['valor_subsidio', 'valor_ahorro', 'fecha'])) {
$this->subsidioEscritura($venta, $data);
@ -357,11 +365,18 @@ class Venta
$fecha = new DateTimeImmutable($data['fecha_pago']);
$uf = $this->moneyService->getUF($fecha);
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
$escrituraData = [
$pagoData = [
'valor' => $valor,
'fecha' => $fecha->format('Y-m-d'),
'uf' => $uf
];
$pago = $this->pagoService->add($pagoData);
$escrituraData = [
'valor' => $valor,
'fecha' => $fecha->format('Y-m-d'),
'uf' => $uf,
'pago' => $pago->id
];
$escritura = $this->escrituraRepository->create($escrituraData);
$escritura = $this->escrituraRepository->save($escritura);
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
@ -379,6 +394,42 @@ class Venta
$subsidio = $this->addSubsidio($subsidioData);
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
}
protected function editCredito(Model\Venta $venta, array $data): void
{
$fecha = new DateTimeImmutable($data['fecha']);
$uf = $this->moneyService->getUF($fecha);
$valor = $data['valor_credito'] * $uf;
if ($venta->formaPago()->credito === null) {
$pagoData = [
'valor' => $valor,
'fecha' => $fecha->format('Y-m-d'),
'uf' => $uf
];
$pago = $this->pagoService->add($pagoData);
$creditoData = [
'banco' => $data['banco_credito'],
'valor' => $valor,
'pago' => $pago->id
];
$credito = $this->creditoRepository->create($creditoData);
$credito = $this->creditoRepository->save($credito);
$this->ventaRepository->edit($venta, ['credito' => $credito->id]);
return;
}
$this->pagoRepository->edit($venta->formaPago()->credito->pago, [
'valor' => $valor,
'banco' => $data['banco_credito'],
'uf' => $uf
]);
$this->estadoPagoRepository->edit($venta->formaPago()->credito->pago->currentEstado, [
'fecha' => $fecha->format('Y-m-d')
]);
$this->creditoRepository->edit($venta->formaPago()->credito, [
'valor' => $valor,
'fecha' => $fecha->format('Y-m-d'),
'uf' => $uf
]);
}
public function desistir(Model\Venta $venta, array $data): bool
{

View File

@ -78,7 +78,7 @@ class Propiedad
if (count($diff) === 0) {
return;
}
$query = "DELECT FROM `propiedad_unidad` WHERE `propiedad` = ? AND `unidad` = ?";
$query = "DELETE FROM `propiedad_unidad` WHERE `propiedad` = ? AND `unidad` = ?";
$statement = $this->connection->prepare($query);
foreach ($diff as $id) {
$statement->execute([$propiedad->id, $id]);

View File

@ -0,0 +1,2 @@
<?php
Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface::class));

View File

@ -8,12 +8,18 @@ return [
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Debug,
Monolog\Level::Notice
Monolog\Level::Debug
),
new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/info.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Info,
Monolog\Level::Warning,
),
new Monolog\Handler\FilterHandler(
(new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
Monolog\Level::Warning,
Monolog\Level::Error,
Monolog\Level::Error
),
new Monolog\Handler\FilterHandler(
@ -23,7 +29,6 @@ return [
)
], [
$container->get(Monolog\Processor\PsrLogMessageProcessor::class),
$container->get(Monolog\Processor\WebProcessor::class),
$container->get(Monolog\Processor\IntrospectionProcessor::class),
$container->get(Monolog\Processor\MemoryUsageProcessor::class),
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class)

View File

@ -1,3 +1,3 @@
display_errors=no
log_errors=yes
error_log=/logs/errors.log
#error_log=/logs/errors.log