2023-09-12

This commit is contained in:
Juan Pablo Vial
2023-09-13 18:51:46 -03:00
parent fa15da1ee2
commit 0cd357b6cb
47 changed files with 1225 additions and 102 deletions

View File

@ -9,7 +9,10 @@ $app->group('/ventas', function($app) {
}
include_once $file->getRealPath();
}
$app->get('/add', [Ventas::class, 'add']);
$app->group('/add', function($app) {
$app->post('[/]', [Ventas::class, 'doAdd']);
$app->get('[/]', [Ventas::class, 'add']);
});
$app->get('[/]', Ventas::class);
});
$app->group('/venta/{proyecto_nombre:[A-za-zÑñ\+\ %0-9]+}/{unidad_descripcion:[0-9]+}', function($app) {
@ -22,6 +25,11 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
$app->group('/propiedad', function($app) {
$app->get('[/]', [Ventas::class, 'propiedad']);
});
$app->group('/pie', function($app) {
$app->group('/cuotas', function($app) {
$app->get('[/]', [Ventas::class, 'cuotas']);
});
});
$app->get('/edit[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'show']);
});

View File

@ -0,0 +1,13 @@
<?php
use Incoviba\Controller\Ventas\Pies;
use Incoviba\Controller\Ventas\Cuotas;
$app->group('/pie/{pie_id}', function($app) {
$app->group('/cuotas', function($app) {
$app->group('/add', function($app) {
$app->get('[/]', [Cuotas::class, 'add']);
$app->post('[/]', [Cuotas::class, 'doAdd']);
});
$app->get('[/]', [Pies::class, 'cuotas']);
});
});

View File

@ -1,4 +1,22 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js" integrity="sha512-5cguXwRllb+6bcc2pogwIeQmQPXEzn2ddsqAexIBhh7FO1z5Hkek1J9mrK2+rmZCTU6b6pERxI7acnp1MpAg4Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
const calendar_date_options = {
type: 'date',
firstDayOfWeek: 1,
today: true,
monthFirst: false,
text: {
days: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthsShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
today: 'Hoy'
},
formatter: {
date: 'DD-MM-YYYY'
},
}
</script>
@stack('page_scripts')

View File

@ -0,0 +1 @@
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>

View File

@ -3,7 +3,7 @@
@section('page_content')
<div class="ui container">
<h2 class="ui header">Nueva Venta</h2>
<form class="ui form" action="{{$urls->base}}/ventas/add" method="post">
<form class="ui form" id="add_form" action="{{$urls->base}}/ventas/add" method="post">
<label for="fecha_venta">Fecha de Venta</label>
<div class="inline field">
<div class="ui calendar" id="fecha_venta_calendar">
@ -57,7 +57,7 @@
<i class="warehouse icon"></i>
{{--Bodega--}}
</button>
<table id="unidades" class="ui very basic compact collapsing table"></table>
<div id="unidades" class="ui ordered list"></div>
<h4 class="ui dividing header">FORMA DE PAGO</h4>
<label for="valor">Valor</label>
<div class="inline field">
@ -605,7 +605,6 @@
}
}
}
console.debug(data)
})
}
}
@ -683,12 +682,10 @@
const unidad = new Unidad({number})
this.added.push(unidad)
$(this.ids.unidades).append(
$('<tr></tr>').attr('data-number', number).append(
$('<td></td>').append(
$('<div></div>').addClass('item').attr('data-number', number).append(
$('<div></div>').addClass('content').append(tipo.charAt(0).toUpperCase() + tipo.slice(1) + ' ').append(
unidad.draw(this.unidades[tipo])
)
).append(
$('<td></td>').append(
).append(
$('<button></button>').addClass('ui icon button').attr('type', 'button').attr('data-number', number).append(
$('<i></i>').addClass('remove icon')
).click(event => {
@ -705,7 +702,7 @@
if (index === -1) {
return
}
$(this.ids.unidades).find("tr[data-number='" + number + "']").remove()
$(this.ids.unidades).find("div.item[data-number='" + number + "']").remove()
this.added.splice(index, 1)
}
reset() {
@ -737,14 +734,10 @@
})
dropdown.append(menu)
dropdown.dropdown()
return $('<div></div>').addClass('inline fields').attr('data-number', this.number).append(dropdown)
return dropdown
}
}
const unidades = {
data: []
}
class Payment {
ids
@ -754,10 +747,10 @@
checkbox: checkbox_id
}
$(this.ids.base).hide()
document.getElementById(this.ids.checkbox).onchange = event => {
this.toggle()
}
this.toggle()
}
get status() {
@ -772,13 +765,12 @@
}
}
function showErrors(errors) {
console.debug(errors)
}
$(document).ready(() => {
$('#fecha_venta_calendar').calendar({
type: 'date',
formatter: {
date: 'DD-MM-YYYY'
}
})
$('#fecha_venta_calendar').calendar(calendar_date_options)
new Propietario({id: '#propietario', id_tipo: 'persona_propietario', id_cantidad: 'cantidad_propietario'})
new Proyecto({unidades_id: '#unidades', proyecto_id: '#proyecto'})
@ -794,6 +786,24 @@
checkbox_id: 'has_' + payment
})
})
$('#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()
}
}).then(data => {
if (data.status) {
window.location = '{{$urls->base}}'
return true
}
showErrors(data.errors)
})
return false
})
})
</script>
@endpush

View File

@ -79,7 +79,8 @@
columnDefs: [
{
target: 6,
visible: false
visible: false,
searchable: false
},
{
target: 2,

View File

@ -0,0 +1,79 @@
@extends('layout.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>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>Valor</th>
</tr>
</thead>
<tbody>
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
<tr>
<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>
{{$format->pesos($cuota->pago->valor)}}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
@include('layout.body.scripts.datatables')
@push('page_scripts')
<script type="text/javascript">
$(document).ready(() => {
new DataTable('#cuotas', {
language: {
info: 'Mostrando página _PAGE_ de _PAGES_',
infoEmpty: 'No hay cuotas ingresadas',
infoFiltered: '(filtrado de _MAX_ cuotas)',
lengthMenu: 'Mostrando de a _MENU_ cuotas',
zeroRecords: 'No se encotró cuotas con ese criterio',
search: 'Buscar: '
},
columnDefs: [
{
target: 2,
visible: false,
searchable: false
}
],
order: [
[0, 'asc'],
[2, 'asc']
]
})
})
</script>
@endpush

View File

@ -0,0 +1,142 @@
@extends('layout.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()); $i < $pie->cuotas - count($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
</div>
</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>
<button class="ui mini compact basic icon button copy valor" type="button" data-index="{{$i}}">
<i class="down arrow icon"></i>
</button>
</div>
</td>
</tr>
@endfor
</tbody>
<tfoot>
<tr>
<td colspan="5">
<button class="ui button" type="submit">
Agregar
</button>
</td>
</tr>
</tfoot>
</table>
</form>
</div>
@endsection
@include('layout.body.scripts.dayjs')
@push('page_scripts')
<script type="text/javascript">
function setDate(index, calendar, date = new Date()) {
const d = dayjs(date)
$(calendar).calendar('set date', new Date(d.add(index, 'M').valueOf()))
}
function formatValor(valor) {
if (valor.length < 3) {
return valor
}
let new_valor = parseInt(valor.split('.').join(''))
const formatter = new Intl.NumberFormat('es-CL', {style: 'decimal', maximumFractionDigits: 0})
return formatter.format(new_valor)
}
$(document).ready(() => {
$('.fecha.calendar').calendar(calendar_date_options).each(setDate)
$('.copy.fecha').click(event => {
const index = $(event.currentTarget).data('index')
const calendar = $(".fecha.calendar[data-index='" + index + "']")
const fecha = calendar.calendar('get date')
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) {
setDate(i - index, $(".fecha.calendar[data-index='" + i + "']"), fecha)
}
})
$('.banco.ui.dropdown').dropdown()
$('.copy.banco').click(event => {
const index = $(event.currentTarget).data('index')
const banco = $(".banco.dropdown[data-index='" + index + "']").dropdown('get value')
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) {
$(".banco.dropdown[data-index='" + i + "']").dropdown('set selected', banco)
}
})
$("input[name^='valor']").each((index, input) => {
$(input).change(event => {
const valor = $(event.currentTarget).val()
$(event.currentTarget).val(formatValor(valor))
})
})
$('.copy.valor').click(event => {
const index = $(event.currentTarget).data('index')
const valor = $("[name='valor" + index + "']").val()
for (let i = index + 1; i < {{$pie->cuotas - count($pie->cuotas())}}; i ++) {
$("[name='valor" + i + "']").val(valor)
}
})
})
</script>
@endpush