Merge branch 'develop' into feature/cierres
This commit is contained in:
@ -9,3 +9,7 @@ $app->group('/direcciones', function($app) {
|
|||||||
$app->post('/find[/]', [Direcciones::class, 'findComunas']);
|
$app->post('/find[/]', [Direcciones::class, 'findComunas']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$app->group('/direccion/{direccion_id:[0-9]+}', function($app) {
|
||||||
|
$app->post('/edit[/]', [Direcciones::class, 'edit']);
|
||||||
|
$app->get('[/]', [Direcciones::class, 'get']);
|
||||||
|
});
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
use Incoviba\Controller\API\Regiones;
|
use Incoviba\Controller\API\Regiones;
|
||||||
|
|
||||||
//$app->group('/regiones', function($app) {});
|
$app->group('/regiones', function($app) {
|
||||||
|
$app->get('[/]', Regiones::class);
|
||||||
|
});
|
||||||
$app->group('/region/{region_id}', function($app) {
|
$app->group('/region/{region_id}', function($app) {
|
||||||
$app->get('/provincias[/]', [Regiones::class, 'provincias']);
|
$app->get('/provincias[/]', [Regiones::class, 'provincias']);
|
||||||
|
$app->get('/comunas[/]', [Regiones::class, 'comunas']);
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<table class="ui striped table">
|
<table class="ui striped table">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Dirección</td>
|
<td>Dirección</td>
|
||||||
<td>{{$proyecto->direccion()}}</td>
|
<td>{{$proyecto->direccion()}} <a href="#" id="edit_direccion_button"><i class="small edit icon"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Inmobiliaria</td>
|
<td>Inmobiliaria</td>
|
||||||
@ -137,6 +137,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
@include('proyectos.show.edit_direccion')
|
||||||
@include('layout.body.scripts.chartjs')
|
@include('layout.body.scripts.chartjs')
|
||||||
|
|
||||||
@push('page_scripts')
|
@push('page_scripts')
|
||||||
@ -485,6 +486,11 @@
|
|||||||
ventas.setup({id_ventas: '#ventas', id_stock: '#stock', id_proyeccion: '#proyeccion',
|
ventas.setup({id_ventas: '#ventas', id_stock: '#stock', id_proyeccion: '#proyeccion',
|
||||||
id_chart_general: '#chart_venta_general', id_chart_tipologias: '#chart_venta_tipologia',
|
id_chart_general: '#chart_venta_general', id_chart_tipologias: '#chart_venta_tipologia',
|
||||||
id_chart_velocidad: '#chart_venta_velocidad'})
|
id_chart_velocidad: '#chart_venta_velocidad'})
|
||||||
|
|
||||||
|
document.getElementById('edit_direccion_button').addEventListener('click', event => {
|
||||||
|
event.preventDefault()
|
||||||
|
$('#edit_direccion_modal').modal('show')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
136
app/resources/views/proyectos/show/edit_direccion.blade.php
Normal file
136
app/resources/views/proyectos/show/edit_direccion.blade.php
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<div class="ui modal" id="edit_direccion_modal">
|
||||||
|
<div class="header">
|
||||||
|
Editar Dirección
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<form class="ui form" id="edit_direccion_form">
|
||||||
|
<input type="hidden" name="id" />
|
||||||
|
<div class="fields">
|
||||||
|
<div class="field">
|
||||||
|
<label>Calle</label>
|
||||||
|
<input type="text" name="calle" value="{{ $proyecto->direccion()->calle }}" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>Número</label>
|
||||||
|
<input type="text" name="numero" value="{{ $proyecto->direccion()->numero }}" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>Extra</label>
|
||||||
|
<input type="text" name="extra" value="{{ $proyecto->direccion()->extra }}" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="fields">
|
||||||
|
<div class="field">
|
||||||
|
<label>Comuna</label>
|
||||||
|
<div class="ui search selection dropdown" id="comuna">
|
||||||
|
<input type="hidden" name="comuna" />
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
<div class="default text">Comuna</div>
|
||||||
|
<div class="menu"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>Región</label>
|
||||||
|
<div class="ui search selection dropdown" id="region">
|
||||||
|
<input type="hidden" name="region" />
|
||||||
|
<i class="dropdown icon"></i>
|
||||||
|
<div class="default text">Región</div>
|
||||||
|
<div class="menu"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<div class="ui black deny button">
|
||||||
|
Cancelar
|
||||||
|
</div>
|
||||||
|
<div class="ui green ok button">
|
||||||
|
Guardar
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@push('page_scripts')
|
||||||
|
<script>
|
||||||
|
function submitForm() {
|
||||||
|
const form = document.getElementById('edit_direccion_form')
|
||||||
|
const body = new FormData(form)
|
||||||
|
const url = '{{$urls->api}}/direccion/{{ $proyecto->direccion()->id }}/edit'
|
||||||
|
const method = 'post'
|
||||||
|
APIClient.fetch(url, {method, body}).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json().then(json => {
|
||||||
|
if (json.success) {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function fetchComunas(region_id) {
|
||||||
|
const url = `{{ $urls->api }}/region/${region_id}/comunas`
|
||||||
|
APIClient.fetch(url).then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return response.json().then(json => {
|
||||||
|
const dropdown = $('#comuna')
|
||||||
|
const values = []
|
||||||
|
json.comunas.forEach(comuna => {
|
||||||
|
values.push({
|
||||||
|
name: comuna.descripcion,
|
||||||
|
value: comuna.id,
|
||||||
|
text: comuna.descripcion
|
||||||
|
})
|
||||||
|
})
|
||||||
|
dropdown.dropdown('change values', values)
|
||||||
|
|
||||||
|
if (json.region_id === {{ $proyecto->direccion()->comuna->provincia->region->id }}) {
|
||||||
|
dropdown.dropdown('set selected', {{ $proyecto->direccion()->comuna->id }})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function fetchRegiones() {
|
||||||
|
const url = '{{ $urls->api }}/regiones'
|
||||||
|
APIClient.fetch(url).then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return response.json().then(json => {
|
||||||
|
const dropdown = $('#region')
|
||||||
|
const values = []
|
||||||
|
json.regiones.forEach(region => {
|
||||||
|
values.push({
|
||||||
|
name: region.descripcion,
|
||||||
|
value: region.id,
|
||||||
|
text: region.descripcion
|
||||||
|
})
|
||||||
|
})
|
||||||
|
dropdown.dropdown({
|
||||||
|
values,
|
||||||
|
onChange: (value, text, $choice) => {
|
||||||
|
fetchComunas(value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$('#comuna').dropdown()
|
||||||
|
dropdown.dropdown('set selected', {{ $proyecto->direccion()->comuna->provincia->region->id }})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$(document).ready(function() {
|
||||||
|
fetchRegiones()
|
||||||
|
$('#edit_direccion_modal').modal({
|
||||||
|
onApprove: function() {
|
||||||
|
submitForm()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
document.getElementById('edit_direccion_form').addEventListener('submit', event => {
|
||||||
|
event.preventDefault()
|
||||||
|
submitForm()
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
@ -251,12 +251,21 @@
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
|
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
|
||||||
const body = new FormData(event.currentTarget)
|
const body = new FormData(event.currentTarget)
|
||||||
body.set('fecha', $('#fecha').calendar('get date').toISOString())
|
const fecha = $('#fecha').calendar('get date')
|
||||||
if (body.get('fecha_pago') !== '') {
|
body.set('fecha', [fecha.getFullYear(), fecha.getMonth()+1, fecha.getDate()].join('-'))
|
||||||
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
|
const $fechaPago = $('#fecha_pago')
|
||||||
|
if ($fechaPago.length > 0) {
|
||||||
|
const fechaPago = $fechaPago.calendar('get date')
|
||||||
|
if (fechaPago !== null) {
|
||||||
|
body.set('fecha_pago', [fechaPago.getFullYear(), fechaPago.getMonth()+1, fechaPago.getDate()].join('-'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (body.get('fecha_reajuste') !== '') {
|
const $fechaReajuste = $('#fecha_reajuste')
|
||||||
body.set('fecha_reajuste', $('#fecha_reajuste').calendar('get date').toISOString())
|
if ($fechaReajuste.length > 0) {
|
||||||
|
const fechaReajuste = $fechaReajuste.calendar('get date')
|
||||||
|
if (fechaReajuste !== null) {
|
||||||
|
body.set('fecha_reajuste', [fechaReajuste.getFullYear(), fechaReajuste.getMonth()+1, fechaReajuste.getDate()].join('-'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fetchAPI(url, {method: 'post', body}).then(response => {
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<label for="valor">Valor</label>
|
<label for="valor">Valor</label>
|
||||||
<div class="ui left labeled input">
|
<div class="ui left labeled input">
|
||||||
<div class="ui basic label">$</div>
|
<div class="ui basic label">$</div>
|
||||||
<input type="text" name="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
|
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="three wide field">
|
<div class="three wide field">
|
||||||
@ -62,9 +62,9 @@
|
|||||||
function editEscritura() {
|
function editEscritura() {
|
||||||
const url = '{{$urls->api}}/ventas/escritura/{{$venta->id}}/edit'
|
const url = '{{$urls->api}}/ventas/escritura/{{$venta->id}}/edit'
|
||||||
const data = new FormData()
|
const data = new FormData()
|
||||||
data.set('venta', {{$venta->id}})
|
|
||||||
const fecha = $('#fecha').calendar('get date')
|
const fecha = $('#fecha').calendar('get date')
|
||||||
data.set('fecha', fecha.toISOString())
|
data.set('fecha', fecha.toISOString())
|
||||||
|
data.set('valor', $('#valor').val())
|
||||||
data.set('estado', $('#estado').dropdown('get value'))
|
data.set('estado', $('#estado').dropdown('get value'))
|
||||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@ -78,10 +78,11 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
calendar_date_options.initialDate = new Date({{$venta->currentEstado()->fecha->format('Y, m-1, j')}})
|
calendar_date_options.initialDate = new Date({{$venta->formaPago()->escritura->pago->currentEstado->fecha->format('Y, m-1, j')}})
|
||||||
$('#fecha').calendar(calendar_date_options)
|
$('#fecha').calendar(calendar_date_options)
|
||||||
$('#estado').dropdown()
|
const $estado = $('#estado')
|
||||||
$('#estado').dropdown('set selected', '{{$venta->currentEstado()->id}}')
|
$estado.dropdown()
|
||||||
|
$estado.dropdown('set selected', '{{$venta->formaPago()->escritura->pago->currentEstado->tipoEstadoPago->id}}')
|
||||||
$('#edit_form').submit(event => {
|
$('#edit_form').submit(event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
editEscritura()
|
editEscritura()
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
new Unidad({
|
new Unidad({
|
||||||
id: {{$unidad->id}},
|
id: {{$unidad->id}},
|
||||||
tipo: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
tipo: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
||||||
descripcion: '{{ucwords($unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{ $unidad->descripcion }} (UF {{ number_format($unidad->precio($venta->currentEstado()->fecha)->valor, 2) }})',
|
descripcion: '{{ $unidad->descripcion }}',
|
||||||
prorrateo: {{$unidad->prorrateo}},
|
prorrateo: {{$unidad->prorrateo}},
|
||||||
propiedad_unidad_id: {{$unidad->pu_id}},
|
propiedad_unidad_id: {{$unidad->pu_id}},
|
||||||
valor: {{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->currentEstado()->fecha)->valor}}
|
valor: {{($unidad->valor > 0) ? $unidad->valor : $unidad->precio($venta->currentEstado()->fecha)->valor}}
|
||||||
@ -96,7 +96,7 @@
|
|||||||
@if ($terreno->fecha != null) fecha: new Date('{{$terreno->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
@if ($terreno->fecha != null) fecha: new Date('{{$terreno->fecha->add(new DateInterval('P1D'))->format('Y-m-d')}}'),
|
||||||
@else fecha: null,
|
@else fecha: null,
|
||||||
@endif
|
@endif
|
||||||
valor: {{($terreno->valor ?? 0) * (1+$ipc)}}
|
valor: {{($terreno->valor ?? 0) * (1 + $ipc)}}
|
||||||
},
|
},
|
||||||
facturas: []
|
facturas: []
|
||||||
}
|
}
|
||||||
@ -110,9 +110,9 @@
|
|||||||
this.venta.props.facturas.facturas[{{$factura->index - 1}}] = new Factura({
|
this.venta.props.facturas.facturas[{{$factura->index - 1}}] = new Factura({
|
||||||
id: {{ $factura->id }},
|
id: {{ $factura->id }},
|
||||||
venta: this.venta.props,
|
venta: this.venta.props,
|
||||||
|
proporcion: {{ $factura->proporcion }},
|
||||||
index: {{$factura->index}},
|
index: {{$factura->index}},
|
||||||
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
|
fecha: new Date('{{$factura->fecha->format('Y-m-d')}}'),
|
||||||
proporcion: {{$factura->proporcion}},
|
|
||||||
emisor: {
|
emisor: {
|
||||||
rut: '{{$factura->venta->proyecto()->inmobiliaria()->rut}}',
|
rut: '{{$factura->venta->proyecto()->inmobiliaria()->rut}}',
|
||||||
nombre: '{{$factura->venta->proyecto()->inmobiliaria()->razon}}',
|
nombre: '{{$factura->venta->proyecto()->inmobiliaria()->razon}}',
|
||||||
@ -137,7 +137,7 @@
|
|||||||
unidad: new Unidad({
|
unidad: new Unidad({
|
||||||
id: {{$unidad->unidad->id}},
|
id: {{$unidad->unidad->id}},
|
||||||
tipo: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
tipo: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}}',
|
||||||
descripcion: '{{ucwords($unidad->unidad->proyectoTipoUnidad->tipoUnidad->descripcion)}} {{ $unidad->unidad->descripcion }} (UF {{ number_format(array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad, $factura) {return $uni->id === $unidad->unidad->id;}))[0]->precio($venta->currentEstado()->fecha)->valor * $factura->proporcion, 2) }})',
|
descripcion: '{{ $unidad->unidad->descripcion }}',
|
||||||
prorrateo: {{$unidad->prorrateo}},
|
prorrateo: {{$unidad->prorrateo}},
|
||||||
propiedad_unidad_id: {{ array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad) {return $uni->id === $unidad->unidad->id;}))[0]->pu_id }},
|
propiedad_unidad_id: {{ array_values(array_filter($venta->propiedad()->unidades, function($uni) use ($unidad) {return $uni->id === $unidad->unidad->id;}))[0]->pu_id }},
|
||||||
valor: {{$unidad->precio}}
|
valor: {{$unidad->precio}}
|
||||||
@ -150,7 +150,7 @@
|
|||||||
],
|
],
|
||||||
detalle: {
|
detalle: {
|
||||||
base: {{ $factura->base() }},
|
base: {{ $factura->base() }},
|
||||||
terreno: {{ $factura->terreno * $factura->proporcion }},
|
terreno: {{ $factura->terreno * $factura->proporcion * $factura->prorrateo }},
|
||||||
neto: {{ $factura->neto() }},
|
neto: {{ $factura->neto() }},
|
||||||
iva: {{ $factura->iva() }},
|
iva: {{ $factura->iva() }},
|
||||||
bruto: {{ $factura->bruto() }},
|
bruto: {{ $factura->bruto() }},
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
venta: null,
|
venta: null,
|
||||||
index: 0,
|
index: 0,
|
||||||
proporcion: 0,
|
proporcion: 0,
|
||||||
|
terreno: {
|
||||||
|
fecha: null,
|
||||||
|
valor: 0
|
||||||
|
},
|
||||||
emisor: {
|
emisor: {
|
||||||
rut: '',
|
rut: '',
|
||||||
nombre: '',
|
nombre: '',
|
||||||
@ -50,6 +54,9 @@
|
|||||||
get saved() {
|
get saved() {
|
||||||
return this.props.id > 0
|
return this.props.id > 0
|
||||||
}
|
}
|
||||||
|
get prorrateo() {
|
||||||
|
return this.props.unidades.reduce((sum, unidad) => sum + unidad.prorrateo, 0)
|
||||||
|
}
|
||||||
draw() {
|
draw() {
|
||||||
return {
|
return {
|
||||||
divider: () => {
|
divider: () => {
|
||||||
@ -186,7 +193,7 @@
|
|||||||
return unidadesData.join("\n")
|
return unidadesData.join("\n")
|
||||||
},
|
},
|
||||||
unidad: ({unidad, no, classes, formatters}) => {
|
unidad: ({unidad, no, classes, formatters}) => {
|
||||||
const descuento = this.props.detalle.terreno * unidad.prorrateo
|
const descuento = this.props.terreno.valor * unidad.prorrateo * this.props.proporcion
|
||||||
const bruto = unidad.precio - descuento
|
const bruto = unidad.precio - descuento
|
||||||
const neto = bruto / 1.19
|
const neto = bruto / 1.19
|
||||||
const data = [
|
const data = [
|
||||||
@ -240,6 +247,20 @@
|
|||||||
return row.join('')
|
return row.join('')
|
||||||
},
|
},
|
||||||
totales: ({formatters}) => {
|
totales: ({formatters}) => {
|
||||||
|
let tooltips = {
|
||||||
|
neto: null,
|
||||||
|
iva: null,
|
||||||
|
total: null
|
||||||
|
}
|
||||||
|
if (this.props.total.neto !== this.props.detalle.neto) {
|
||||||
|
tooltips.neto = ` data-tooltip="No coinciden netos! Promesa: ${formatters.pesos.format(this.props.detalle.neto)} - Unidades: ${formatters.pesos.format(this.props.total.neto)}"`
|
||||||
|
}
|
||||||
|
if (this.props.total.iva !== this.props.detalle.iva) {
|
||||||
|
tooltips.iva = ` data-tooltip="No coinciden ivas! Promesa: ${formatters.pesos.format(this.props.detalle.iva)} - Unidades: ${formatters.pesos.format(this.props.total.iva)}"`
|
||||||
|
}
|
||||||
|
if (this.props.total.total !== this.props.detalle.total) {
|
||||||
|
tooltips.total = ` data-tooltip="No coinciden totales! Promesa: ${formatters.pesos.format(this.props.detalle.total)} - Unidades: ${formatters.pesos.format(this.props.total.total)}"`
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'<div class="row">',
|
'<div class="row">',
|
||||||
'<div class="ten wide column"></div>',
|
'<div class="ten wide column"></div>',
|
||||||
@ -253,7 +274,7 @@
|
|||||||
'<tbody>',
|
'<tbody>',
|
||||||
'<tr>',
|
'<tr>',
|
||||||
'<td class="grey">Monto Neto</td>',
|
'<td class="grey">Monto Neto</td>',
|
||||||
'<td class="right aligned" id="neto">'+formatters.pesos.format(this.props.total.neto)+'</td>',
|
`<td class="right aligned${this.props.total.neto !== this.props.detalle.neto ? ' red' : ''}"${this.props.total.neto !== this.props.detalle.neto ? tooltips.neto : ''} id="neto">${formatters.pesos.format(this.props.total.neto)}</td>`,
|
||||||
'</tr>',
|
'</tr>',
|
||||||
'<tr>',
|
'<tr>',
|
||||||
'<td class="grey">Monto Exento</td>',
|
'<td class="grey">Monto Exento</td>',
|
||||||
@ -261,11 +282,11 @@
|
|||||||
'</tr>',
|
'</tr>',
|
||||||
'<tr>',
|
'<tr>',
|
||||||
'<td class="grey">19% IVA</td>',
|
'<td class="grey">19% IVA</td>',
|
||||||
'<td class="right aligned" id="iva">'+formatters.pesos.format(this.props.total.iva)+'</td>',
|
`<td class="right aligned${this.props.total.iva !== this.props.detalle.iva ? ' red' : ''}"${this.props.total.iva !== this.props.detalle.iva ? tooltips.iva : ''} id="iva">${formatters.pesos.format(this.props.total.iva)}</td>`,
|
||||||
'</tr>',
|
'</tr>',
|
||||||
'<tr>',
|
'<tr>',
|
||||||
'<td class="grey">Monto Total</td>',
|
'<td class="grey">Monto Total</td>',
|
||||||
'<td class="right aligned"><strong id="total">'+formatters.pesos.format(this.props.total.total)+'</strong></td>',
|
`<td class="right aligned${(this.props.total.total !== this.props.detalle.total) ? ' red' : ''}"${(this.props.total.total !== this.props.detalle.total) ? tooltips.total : ''}><strong id="total">${formatters.pesos.format(this.props.total.total)}</strong></td>`,
|
||||||
'</tr>',
|
'</tr>',
|
||||||
'</tbody>',
|
'</tbody>',
|
||||||
'</table>',
|
'</table>',
|
||||||
@ -364,12 +385,10 @@
|
|||||||
this.props.uf.valor = venta.props.uf.valor
|
this.props.uf.valor = venta.props.uf.valor
|
||||||
this.update().propietario(venta.props.propietarios.find(propietario => propietario.props.index === this.props.index))
|
this.update().propietario(venta.props.propietarios.find(propietario => propietario.props.index === this.props.index))
|
||||||
this.update().unidades(venta.props.unidades)
|
this.update().unidades(venta.props.unidades)
|
||||||
this.props.total.total = this.props.detalle.total = venta.props.valor * this.props.proporcion * venta.props.uf.valor
|
this.props.detalle.total = venta.props.valor * this.props.proporcion * venta.props.uf.valor
|
||||||
this.update().detalle(venta.props.facturas.terreno.valor * venta.prorrateo)
|
this.update().detalle(venta.props.facturas.terreno.valor * this.prorrateo)
|
||||||
this.props.total.exento = this.props.detalle.terreno
|
|
||||||
this.props.total.iva = this.props.detalle.iva
|
|
||||||
this.props.total.neto = this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0)
|
|
||||||
this.props.detalle.descuento = venta.prorrateo * this.props.proporcion
|
this.props.detalle.descuento = venta.prorrateo * this.props.proporcion
|
||||||
|
this.update().total()
|
||||||
},
|
},
|
||||||
detalle: terreno => {
|
detalle: terreno => {
|
||||||
this.props.detalle.terreno = terreno * this.props.proporcion
|
this.props.detalle.terreno = terreno * this.props.proporcion
|
||||||
@ -378,14 +397,20 @@
|
|||||||
this.props.detalle.iva = this.props.detalle.neto * 0.19
|
this.props.detalle.iva = this.props.detalle.neto * 0.19
|
||||||
this.props.detalle.base = this.props.detalle.neto + this.props.detalle.terreno
|
this.props.detalle.base = this.props.detalle.neto + this.props.detalle.terreno
|
||||||
},
|
},
|
||||||
|
total: () => {
|
||||||
|
this.props.total.exento = this.props.detalle.terreno
|
||||||
|
this.props.total.neto = (this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0) - this.props.total.exento) / 1.19
|
||||||
|
this.props.total.iva = this.props.total.neto * 0.19
|
||||||
|
this.props.total.total = this.props.total.neto + this.props.total.iva + this.props.total.exento
|
||||||
|
},
|
||||||
unidades: unidades => {
|
unidades: unidades => {
|
||||||
this.props.unidades = []
|
this.props.unidades = []
|
||||||
unidades.forEach(unidad => {
|
unidades.forEach(unidad => {
|
||||||
this.props.unidades.push({
|
this.props.unidades.push({
|
||||||
unidad: unidad,
|
unidad: unidad,
|
||||||
descripcion: unidad.changeDescripcion(this.props.proporcion || 1),
|
descripcion: unidad.changeDescripcion(this.props.proporcion || 1),
|
||||||
precio: unidad.props.valor * this.props.uf.valor * this.props.proporcion,
|
precio: unidad.props.valor * this.props.uf.valor,
|
||||||
prorrateo: unidad.props.prorrateo * this.props.proporcion
|
prorrateo: unidad.props.prorrateo
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeDescripcion(proporcion = 1) {
|
changeDescripcion(proporcion = 1) {
|
||||||
return this.descripcion = [this.props.tipo, this.props.descripcion, `[UF ${facturas.formatters.ufs.format(this.props.valor * proporcion)}]`].join(' ')
|
return this.descripcion = [this.props.tipo, this.props.descripcion, `(UF ${facturas.formatters.ufs.format(this.props.valor * proporcion)})`].join(' ')
|
||||||
}
|
}
|
||||||
update() {
|
update() {
|
||||||
return {
|
return {
|
||||||
|
@ -403,6 +403,7 @@
|
|||||||
venta: this.props,
|
venta: this.props,
|
||||||
index: propietario.props.index,
|
index: propietario.props.index,
|
||||||
proporcion: propietario.props.proporcion,
|
proporcion: propietario.props.proporcion,
|
||||||
|
terreno: this.props.facturas.terreno,
|
||||||
emisor: {
|
emisor: {
|
||||||
rut: this.props.inmobiliaria.rut,
|
rut: this.props.inmobiliaria.rut,
|
||||||
nombre: this.props.inmobiliaria.nombre,
|
nombre: this.props.inmobiliaria.nombre,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
$app->add($app->getContainer()->get(Incoviba\Middleware\NotFound::class));
|
$app->add($app->getContainer()->get(Incoviba\Middleware\NotFound::class));
|
||||||
|
$app->add($app->getContainer()->get(Incoviba\Middleware\NotAllowed::class));
|
||||||
$app->add($app->getContainer()->get(Incoviba\Middleware\Errors::class));
|
$app->add($app->getContainer()->get(Incoviba\Middleware\Errors::class));
|
||||||
|
@ -14,6 +14,24 @@ class Direcciones
|
|||||||
{
|
{
|
||||||
use withRedis, withJson;
|
use withRedis, withJson;
|
||||||
|
|
||||||
|
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
|
Repository\Direccion $direccionRepository, int $direccion_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$output = ['direccion_id' => $direccion_id, 'direccion' => null];
|
||||||
|
$redisKey = "direcciones:{$direccion_id}";
|
||||||
|
try {
|
||||||
|
$direccion = $this->fetchRedis($redisService, $redisKey);
|
||||||
|
$output['direccion'] = $direccion;
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
try {
|
||||||
|
$direccion = $direccionRepository->fetchById($direccion_id);
|
||||||
|
$output['direccion'] = $direccion;
|
||||||
|
$this->saveRedis($redisService, $redisKey, $direccion, 60 * 60 * 24 * 30);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
Repository\Region $regionRepository, Repository\Comuna $comunaRepository,
|
Repository\Region $regionRepository, Repository\Comuna $comunaRepository,
|
||||||
int $region_id) : ResponseInterface
|
int $region_id) : ResponseInterface
|
||||||
@ -64,7 +82,7 @@ class Direcciones
|
|||||||
$body = $request->getBody();
|
$body = $request->getBody();
|
||||||
$json = json_decode($body->getContents());
|
$json = json_decode($body->getContents());
|
||||||
$output = ['input' => $json, 'total' => 0, 'comunas' => []];
|
$output = ['input' => $json, 'total' => 0, 'comunas' => []];
|
||||||
$redisKey = "comunas:direccion:{$json->direccion}";
|
$redisKey = "direcciones:{$json->direccion}:comuna";
|
||||||
try {
|
try {
|
||||||
$output['comunas'] = $this->fetchRedis($redisService, $redisKey);
|
$output['comunas'] = $this->fetchRedis($redisService, $redisKey);
|
||||||
} catch (EmptyRedis) {
|
} catch (EmptyRedis) {
|
||||||
@ -77,4 +95,21 @@ class Direcciones
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
|
Repository\Direccion $direccionRepository, int $direccion_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = ['direccion_id' => $direccion_id, 'input' => $body, 'direccion' => [], 'success' => false];
|
||||||
|
$redisKey = "direcciones:{$direccion_id}";
|
||||||
|
try {
|
||||||
|
$direccion = $direccionRepository->fetchById($direccion_id);
|
||||||
|
$filteredData = $direccionRepository->filterData($body);
|
||||||
|
$output['direccion'] = $direccionRepository->edit($direccion, $filteredData);
|
||||||
|
$output['success'] = true;
|
||||||
|
$this->saveRedis($redisService, $redisKey, $output['direccion'], 60 * 60 * 24 * 30);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,21 @@ class Regiones
|
|||||||
{
|
{
|
||||||
use withRedis, withJson;
|
use withRedis, withJson;
|
||||||
|
|
||||||
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
|
Repository\Region $regionRepository): ResponseInterface
|
||||||
|
{
|
||||||
|
$regiones = [];
|
||||||
|
try {
|
||||||
|
$regiones = $this->fetchRedis($redisService, 'regiones');
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
try {
|
||||||
|
$regiones = $regionRepository->fetchAll();
|
||||||
|
$this->saveRedis($redisService, 'regiones', $regiones, 60 * 60 * 24 * 30);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
}
|
||||||
|
return $this->withJson($response, compact('regiones'));
|
||||||
|
}
|
||||||
|
|
||||||
public function provincias(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
public function provincias(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
Repository\Provincia $provinciaRepository, int $region_id): ResponseInterface
|
Repository\Provincia $provinciaRepository, int $region_id): ResponseInterface
|
||||||
{
|
{
|
||||||
@ -36,4 +51,54 @@ class Regiones
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
public function comunas(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService,
|
||||||
|
Repository\Provincia $provinciaRepository,
|
||||||
|
Repository\Comuna $comunaRepository, int $region_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$output = [
|
||||||
|
'region_id' => $region_id,
|
||||||
|
'comunas' => []
|
||||||
|
];
|
||||||
|
$comunas = [];
|
||||||
|
try {
|
||||||
|
$redisKey = "provincias:region:{$region_id}";
|
||||||
|
$provincias = $this->fetchRedis($redisService, $redisKey);
|
||||||
|
foreach ($provincias as $provincia) {
|
||||||
|
$comunas = array_merge($comunas, $this->fetchComunasByProvincia($redisService, $comunaRepository, $provincia->id));
|
||||||
|
}
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
try {
|
||||||
|
$provincias = $provinciaRepository->fetchByRegion($region_id);
|
||||||
|
usort($provincias, function (Model\Provincia $a, Model\Provincia $b) {
|
||||||
|
return strcmp($a->descripcion, $b->descripcion);
|
||||||
|
});
|
||||||
|
$this->saveRedis($redisService, $redisKey, $provincias, 60 * 60 * 24 * 30);
|
||||||
|
foreach ($provincias as $provincia) {
|
||||||
|
$comunas = array_merge($comunas, $this->fetchComunasByProvincia($redisService, $comunaRepository, $provincia->id));
|
||||||
|
}
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
} finally {
|
||||||
|
usort($comunas, function ($a, $b) {
|
||||||
|
return strcmp($a->descripcion, $b->descripcion);
|
||||||
|
});
|
||||||
|
$output['comunas'] = $comunas;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fetchComunasByProvincia(Service\Redis $redisService, Repository\Comuna $comunaRepository, int $provincia_id): array
|
||||||
|
{
|
||||||
|
$redisKey = "comunas:provincia:{$provincia_id}";
|
||||||
|
try {
|
||||||
|
$comunas = $this->fetchRedis($redisService, $redisKey);
|
||||||
|
} catch (EmptyRedis) {
|
||||||
|
$comunas = $comunaRepository->fetchByProvincia($provincia_id);
|
||||||
|
usort($comunas, function (Model\Comuna $a, Model\Comuna $b) {
|
||||||
|
return strcmp($a->descripcion, $b->descripcion);
|
||||||
|
});
|
||||||
|
$this->saveRedis($redisService, $redisKey, $comunas, 60 * 60 * 24 * 30);
|
||||||
|
}
|
||||||
|
return $comunas;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,11 @@ class Escrituras
|
|||||||
$output = [
|
$output = [
|
||||||
'venta_id' => $venta_id,
|
'venta_id' => $venta_id,
|
||||||
'input' => $body,
|
'input' => $body,
|
||||||
'edited' => false
|
'success' => false
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$escrituraService->edit($venta_id, $body);
|
$escrituraService->edit($venta_id, $body);
|
||||||
$output['edited'] = true;
|
$output['success'] = true;
|
||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
22
app/src/Middleware/NotAllowed.php
Normal file
22
app/src/Middleware/NotAllowed.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Middleware;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseFactoryInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
use Slim\Exception\HttpMethodNotAllowedException;
|
||||||
|
|
||||||
|
class NotAllowed
|
||||||
|
{
|
||||||
|
public function __construct(protected ResponseFactoryInterface $responseFactory) {}
|
||||||
|
|
||||||
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $handler->handle($request);
|
||||||
|
} catch (HttpMethodNotAllowedException) {
|
||||||
|
return $this->responseFactory->createResponse(405, 'Method Not Allowed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,10 @@ class Propietario extends Ideal\Repository
|
|||||||
{
|
{
|
||||||
return 'rut';
|
return 'rut';
|
||||||
}
|
}
|
||||||
|
protected function getIndex(Define\Model $model): mixed
|
||||||
|
{
|
||||||
|
return $model->rut;
|
||||||
|
}
|
||||||
|
|
||||||
public function create(?array $data = null): Define\Model
|
public function create(?array $data = null): Define\Model
|
||||||
{
|
{
|
||||||
|
@ -285,12 +285,13 @@ class Venta extends Service
|
|||||||
return $this->formaPagoService->add($data);
|
return $this->formaPagoService->add($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha']);
|
try {
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
}
|
||||||
$estadoData = [
|
$estadoData = [
|
||||||
'venta' => $venta->id,
|
'venta' => $venta->id,
|
||||||
'estado' => $tipoEstadoVenta->id,
|
'estado' => $tipoEstadoVenta->id,
|
||||||
@ -343,12 +344,13 @@ class Venta extends Service
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function reajustarEscritura(Model\Venta $venta, array $data): void
|
protected function reajustarEscritura(Model\Venta $venta, array $data): void
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
try {
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
}
|
||||||
$reajusteData = [
|
$reajusteData = [
|
||||||
'valor' => $this->valorService->clean($data['valor_reajuste']),
|
'valor' => $this->valorService->clean($data['valor_reajuste']),
|
||||||
'fecha' => $fecha->format('Y-m-d')
|
'fecha' => $fecha->format('Y-m-d')
|
||||||
@ -357,12 +359,13 @@ class Venta extends Service
|
|||||||
$this->pieService->reajustar($pie, $reajusteData);
|
$this->pieService->reajustar($pie, $reajusteData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function abonoEscritura(Model\Venta $venta, array $data): void
|
protected function abonoEscritura(Model\Venta $venta, array $data): void
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
try {
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
}
|
||||||
$uf = $this->moneyService->getUF($fecha);
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
$valor = $data['valor_pago_ufs'] !== '' ? $this->valorService->clean($data['valor_pago_ufs']) * $uf : $this->valorService->clean($data['valor_pago_pesos']);
|
$valor = $data['valor_pago_ufs'] !== '' ? $this->valorService->clean($data['valor_pago_ufs']) * $uf : $this->valorService->clean($data['valor_pago_pesos']);
|
||||||
$pagoData = [
|
$pagoData = [
|
||||||
@ -382,12 +385,13 @@ class Venta extends Service
|
|||||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function subsidioEscritura(Model\Venta $venta, array $data): void
|
protected function subsidioEscritura(Model\Venta $venta, array $data): void
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha']);
|
try {
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
}
|
||||||
$uf = $this->moneyService->getUF($fecha);
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
$subsidioData = [
|
$subsidioData = [
|
||||||
'fecha_venta' => $fecha->format('Y-m-d'),
|
'fecha_venta' => $fecha->format('Y-m-d'),
|
||||||
@ -399,15 +403,19 @@ class Venta extends Service
|
|||||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function editCredito(Model\Venta $venta, array $data): void
|
protected function editCredito(Model\Venta $venta, array $data): void
|
||||||
{
|
{
|
||||||
$fecha = new DateTimeImmutable($data['fecha']);
|
try {
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$fecha = new DateTimeImmutable();
|
||||||
|
}
|
||||||
$uf = $this->moneyService->getUF($fecha);
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
$valor = $this->valorService->clean($data['valor_credito']) * $uf;
|
$valor = $this->valorService->clean($data['valor_credito']) * $uf;
|
||||||
if ($venta->formaPago()->credito === null) {
|
if ($venta->formaPago()->credito === null) {
|
||||||
|
if ($data['valor_credito'] === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$pagoData = [
|
$pagoData = [
|
||||||
'valor' => $valor,
|
'valor' => $valor,
|
||||||
'fecha' => $fecha->format('Y-m-d'),
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
@ -424,6 +432,12 @@ class Venta extends Service
|
|||||||
$this->ventaRepository->edit($venta, ['credito' => $credito->id]);
|
$this->ventaRepository->edit($venta, ['credito' => $credito->id]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($data['valor_credito'] === 0) {
|
||||||
|
$this->pagoRepository->remove($venta->formaPago()->credito->pago);
|
||||||
|
$this->creditoRepository->remove($venta->formaPago()->credito);
|
||||||
|
$this->ventaRepository->edit($venta, ['credito' => null]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->pagoRepository->edit($venta->formaPago()->credito->pago, [
|
$this->pagoRepository->edit($venta->formaPago()->credito->pago, [
|
||||||
'valor' => $valor,
|
'valor' => $valor,
|
||||||
'banco' => $data['banco_credito'],
|
'banco' => $data['banco_credito'],
|
||||||
|
@ -55,16 +55,27 @@ class Escritura extends Ideal\Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws EmptyResult
|
* @throws EmptyResult
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function edit(int $venta_id, array $data): Model\Venta\EstadoVenta
|
public function edit(int $venta_id, array $data): Model\Venta\Escritura
|
||||||
{
|
{
|
||||||
$venta = $this->ventaService->getById($venta_id);
|
$venta = $this->ventaService->getById($venta_id);
|
||||||
$estado = $venta->currentEstado();
|
$estado = $venta->currentEstado();
|
||||||
if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) {
|
if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) {
|
||||||
throw new EmptyResult('');
|
throw new EmptyResult('');
|
||||||
}
|
}
|
||||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
try {
|
||||||
return $this->estadoVentaRepository->edit($estado, $data);
|
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
unset($data['fecha']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$escritura = $venta->formaPago()->escritura;
|
||||||
|
$pagoData = array_intersect_key($data, array_flip(['valor', 'fecha']));
|
||||||
|
$pago = $escritura->pago;
|
||||||
|
$this->escrituraRepository->edit($escritura, $pagoData);
|
||||||
|
$this->pagoService->edit($pago, $pagoData);
|
||||||
|
$this->pagoService->updateEstado($pago, $data);
|
||||||
|
|
||||||
|
return $this->escrituraRepository->fetchById($escritura->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,13 +117,14 @@ class Pago
|
|||||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function add(array $data): Model\Venta\Pago
|
public function add(array $data): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
if (!isset($data['uf'])) {
|
if (!isset($data['uf'])) {
|
||||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
try {
|
||||||
|
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$data['uf'] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$filtered_data = $this->pagoRepository->filterData($data);
|
$filtered_data = $this->pagoRepository->filterData($data);
|
||||||
$filtered_data['valor'] = round($this->valorService->clean($filtered_data['valor']));
|
$filtered_data['valor'] = round($this->valorService->clean($filtered_data['valor']));
|
||||||
@ -141,16 +142,21 @@ class Pago
|
|||||||
return $pago;
|
return $pago;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
if (array_key_exists('fecha', $data)) {
|
if (array_key_exists('fecha', $data)) {
|
||||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
try {
|
||||||
|
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$data['fecha'] = (new DateTimeImmutable())->format('Y-m-d');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (array_key_exists('uf', $data)) {
|
if (array_key_exists('uf', $data)) {
|
||||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
try {
|
||||||
|
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||||
|
} catch (\DateMalformedStringException) {
|
||||||
|
$data['uf'] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$filteredData = $this->pagoRepository->filterData($data);
|
$filteredData = $this->pagoRepository->filterData($data);
|
||||||
if (array_key_exists('valor', $filteredData)) {
|
if (array_key_exists('valor', $filteredData)) {
|
||||||
@ -169,6 +175,18 @@ class Pago
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function updateEstado(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||||
|
{
|
||||||
|
if ($pago->currentEstado->tipoEstadoPago->id === $data['estado']) {
|
||||||
|
return $pago;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['pago'] = $pago->id;
|
||||||
|
$estado = $this->estadoPagoRepository->create($data);
|
||||||
|
$this->estadoPagoRepository->save($estado);
|
||||||
|
|
||||||
|
return $this->process($this->pagoRepository->fetchById($pago->id));
|
||||||
|
}
|
||||||
|
|
||||||
protected function process($pago): Model\Venta\Pago
|
protected function process($pago): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user