374 lines
13 KiB
PHP
374 lines
13 KiB
PHP
@extends('layout.base')
|
|
|
|
@section('content')
|
|
<div class="row page-heading">
|
|
<h3>Nuevo Cierre</h3>
|
|
</div>
|
|
<br />
|
|
<form class="form-horizontal" method="post" action="{{url('', ['p' => 'cierres', 'a' => 'agregar'])}}">
|
|
<div class="form-group">
|
|
<div class="col-md-2">Fecha</div>
|
|
@include('form.fecha')
|
|
</div>
|
|
<div class="section-heading">PROPIEDAD</div>
|
|
</br>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Proyecto</div>
|
|
<div class="col-md-4"><select name="proyecto" class="form-control">
|
|
<option value="0">---</option>
|
|
@foreach ($proyectos as $proyecto)
|
|
<option value="{{$proyecto->id}}">{{$proyecto->descripcion}}</option>
|
|
@endforeach
|
|
</select></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Agente</div>
|
|
<div class="col-md-4"><select name="agente" class="form-control" id="agente">
|
|
</select></div>
|
|
</div>
|
|
<div id="unidades">
|
|
<input type="hidden" name="unidades" value="0" />
|
|
<div class="form-group">
|
|
<div class="col-md-2">Unidades</div>
|
|
<div class="col-md-1"><span class="glyphicon glyphicon-plus agregar" id="agregar_unidad"></span></div>
|
|
<div class="col-md-2"><select name="tipo_unidad" class="form-control"></select></div>
|
|
</div>
|
|
</div>
|
|
<div class="section-heading">FORMA DE PAGO</div>
|
|
<br />
|
|
<div class="form-group">
|
|
<div class="col-md-2">Valor</div>
|
|
<div class="col-md-3"><input type="text" name="valor" class="form-control"/></div>
|
|
<div class="col-md-1">UF</div>
|
|
</div>
|
|
<div class="form-group" id="pie">
|
|
<div class="col-md-2">Pie</div>
|
|
<div class="col-md-1"><span class="glyphicon glyphicon-plus agregar" id="agregar_pie"></span></div>
|
|
</div>
|
|
<div class="form-group" id="credito">
|
|
<div class="col-md-2">Crédito</div>
|
|
<div class="col-md-1"><span class="glyphicon glyphicon-plus agregar" id="agregar_credito"></span></div>
|
|
</div>
|
|
<div class="section-heading">PROPIETARIO</div>
|
|
<br />
|
|
<div class="form-group">
|
|
<div class="col-md-2">RUT</div>
|
|
<div class="col-md-2"><input type="text" name="rut" class="form-control" /></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Nombre</div>
|
|
<div class="col-md-3"><input type="text" name="nombres" class="form-control" autocomplete="off" /></div>
|
|
<div class="col-md-3"><input type="text" name="paterno" class="form-control" autocomplete="off" /></div>
|
|
<div class="col-md-3"><input type="text" name="materno" class="form-control" autocomplete="off" /></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Sexo</div>
|
|
<div class="col-md-1"><input type="radio" name="sexo" value="m" class="form-radio" /> Hombre</div>
|
|
<div class="col-md-1"><input type="radio" name="sexo" value="f" class="form-radio" /> Mujer</div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Estado Civil</div>
|
|
<div class="col-md-3"><select name="estado_civil" class="form-control">
|
|
<option value="soltero">Soltero/a</option>
|
|
<option value="casado">Casado/a</option>
|
|
<option value="divorciado">Divorciado/a</option>
|
|
<option value="viudo">Viudo/a</option>
|
|
</select></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Profesión</div>
|
|
<div class="col-md-3"><input type="text" name="profesion" class="form-control" /></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Teléfono</div>
|
|
<div class="col-md-1">+56</div>
|
|
<div class="col-md-1"><input type="text" name="codigo_telefono" maxlength="1" class="form-control" /></div>
|
|
<div class="col-md-3"><input type="text" name="telefono" class="form-control" maxlength="8" /></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">E-Mail</div>
|
|
<div class="col-md-3"><input type="text" name="email" class="form-control" /></div>
|
|
<div class="col-md-1">@</div>
|
|
<div clasS="col-md-3"><input type="text" name="email_domain" class="form-control" /></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Dirección</div>
|
|
<div class="col-md-4"><input type="text" name="calle" class="form-control" autocomplete="off" /></div>
|
|
<div class="col-md-2"><input type="text" name="numero" class="form-control" /></div>
|
|
<div class="col-md-3"><input type="text" name="extra" class="form-control" autocomplete="off" /></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-offset-2 col-md-5"><select name="region" class="form-control">
|
|
@foreach ($regiones as $region)
|
|
<option value="{{$region->id}}"
|
|
@if ($region->numeral == 'RM')
|
|
selected="selected"
|
|
@endif
|
|
>{{$region->descripcion}}</option>
|
|
@endforeach
|
|
</select></div>
|
|
<div class="col-md-4"><select name="comuna" class="form-control"></select></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-offset-2 col-md-2"><input type="submit" value="Agregar" class="form-control" /></div>
|
|
</div>
|
|
</form>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script type="text/javascript">
|
|
var unidades = [];
|
|
var pie = false;
|
|
var credito = false;
|
|
$(document).ready(function() {
|
|
$("input[name='rut']").rut({"formatOn": 'keyup', "validateOn": 'blur'}).on('rutInvalido', function(e) {
|
|
$(this).parent().next().remove();
|
|
$(this).parent().after($('<div></div>').attr('class', 'col-md-2 alert-danger').html('Rut inválido'));
|
|
}).on('rutValido', function(e, rut, dv) {
|
|
$(this).parent().next().remove();
|
|
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'propietario', 'ajax' => true])!!}', {"rut": rut}, function(data) {
|
|
if (data.trim() != '' || data != 'false') {
|
|
info = $.parseJSON(data);
|
|
|
|
$("input[name='nombres']").val(info.nombres);
|
|
$("input[name='paterno']").val(info.apellido_paterno);
|
|
$("input[name='materno']").val(info.apellido_materno);
|
|
|
|
if (info.direccion) {
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'direccion', 'ajax' => true])!!}', {"direccion": info.direccion}, function(info) {
|
|
$("input[name='calle']").val(info.calle);
|
|
$("input[name='numero']").val(info.numero);
|
|
$("input[name='extra']").val(info.extra);
|
|
$("select[name='region']").val(info.comuna.provincia.region.id);
|
|
changeRegion().done(function() {
|
|
$("select[name='comuna']").val(info.comuna.id);
|
|
});
|
|
}, 'json');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'nombres', 'ajax' => true])!!}', function(data) {
|
|
$("input[name='nombres']").typeahead({
|
|
"source": data,
|
|
"updater": function(item) {
|
|
return this.$element.val().replace(/[^ ]*$/,'') + item + ' ';
|
|
},
|
|
"matcher": function (item) {
|
|
var tquery = extractor(this.query);
|
|
if(!tquery) return false;
|
|
return ~item.toLowerCase().indexOf(tquery.toLowerCase())
|
|
},
|
|
"highlighter": function (item) {
|
|
var query = extractor(this.query).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
|
|
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
|
|
return '<strong>' + match + '</strong>'
|
|
});
|
|
}
|
|
});
|
|
}, 'json');
|
|
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'apellidos', 'ajax' => true])!!}', function(data) {
|
|
$("input[name='paterno']").typeahead({"source": data});
|
|
$("input[name='materno']").typeahead({"source": data});
|
|
}, 'json');
|
|
|
|
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'calles', 'ajax' => true])!!}', function(data) {
|
|
$("input[name='calle']").typeahead({"source": data});
|
|
}, 'json');
|
|
|
|
$("input[name='extra']").typeahead({"source": ['Casa', 'Departamento', 'Oficina', 'Villa']});
|
|
|
|
$("select[name='region']").change(function(e) {
|
|
changeRegion($(this).val());
|
|
});
|
|
changeRegion($("select[name='region']").val());
|
|
|
|
$("select[name='proyecto']").change(function(e) {
|
|
changeProyecto();
|
|
});
|
|
changeProyecto();
|
|
$('#agregar_unidad').click(function(e) {
|
|
agregarUnidad();
|
|
});
|
|
$('#agregar_pie').click(function(e) {
|
|
agregarPie();
|
|
});
|
|
$('#agregar_credito').click(function(e) {
|
|
agregarCredito();
|
|
});
|
|
});
|
|
function extractor(query) {
|
|
var result = /([^ ]+)$/.exec(query);
|
|
if(result && result[1])
|
|
return result[1].trim();
|
|
return '';
|
|
}
|
|
function changeProyecto() {
|
|
var proyecto = $("select[name='proyecto']").val();
|
|
if (proyecto == '0') {
|
|
$('#unidades').hide();
|
|
return;
|
|
}
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'tipo_unidades', 'ajax' => true])!!}', {"proyecto": proyecto}, function(data) {
|
|
var tipo = $("select[name='tipo_unidad']");
|
|
tipo.html('');
|
|
var info = $.parseJSON(data);
|
|
$.each(info, function(i, e) {
|
|
tipo.append($('<option></option>').attr('value', e.id).html(e.descripcion.ucwords()));
|
|
});
|
|
$('#unidades').show();
|
|
});
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'operadores', 'ajax' => true])!!}', {"proyecto": proyecto}, function(data) {
|
|
var operadores = $("select[name='agente']");
|
|
operadores.html('').append($('<option></option>').attr('value', 0).html('---'));
|
|
var info = $.parseJSON(data);
|
|
$.each(info, function(i, e) {
|
|
operadores.append($('<option></option>').attr('value', e.id).html(e.abreviacion));
|
|
});
|
|
});
|
|
}
|
|
function agregarUnidad() {
|
|
var proyecto = $("select[name='proyecto']").val();
|
|
if (proyecto == '0') {
|
|
$('#unidades').hide();
|
|
}
|
|
var tipo = $("select[name='tipo_unidad']").val();
|
|
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'unidades', 'ajax' => true])!!}', {"proyecto": proyecto, "tipo": tipo}, function(data) {
|
|
var info = $.parseJSON(data);
|
|
var unis = $('#unidades');
|
|
var n = unidades[unidades.length - 1] + 1;
|
|
if (unidades.length == 0) {
|
|
n = 1
|
|
}
|
|
unidades[unidades.length] = n;
|
|
var select = $('<select></select>').attr('name', 'unidad' + n).attr('class', 'form-control');
|
|
|
|
$.each(info, function(i, e) {
|
|
select.append($('<option></option>').attr('value', e.id).html(e.descripcion + ' - ' + e.abreviacion));
|
|
});
|
|
var ntipo = $("select[name='tipo_unidad'] option[value='" + tipo + "']").text();
|
|
unis.append(
|
|
$('<div></div>').attr('class', 'form-group').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html(ntipo)
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-3').append(
|
|
select
|
|
)
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-minus remover').attr('data-id', n).attr('id', 'remover_unidad' + n)
|
|
)
|
|
)
|
|
);
|
|
|
|
$("input[name='unidades']").val(JSON.stringify(unidades));
|
|
$('#remover_unidad' + n).click(function(e) {
|
|
i = $(this).attr('data-id');
|
|
removeUnidad(i);
|
|
});
|
|
});
|
|
}
|
|
function removeUnidad(n) {
|
|
var unis = $('#unidades');
|
|
unis.find("select[name='unidad" + n + "']").parent().parent().remove();
|
|
i = unidades.binaryIndexOf(n);
|
|
unidades.splice(i, 1);
|
|
$("input[name='unidades']").val(JSON.stringify(unidades));
|
|
}
|
|
function agregarPie() {
|
|
if (pie) {
|
|
return;
|
|
}
|
|
pie = true;
|
|
$('#pie').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Pie')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-3').append(
|
|
$('<input/>').attr('type', 'text').attr('name', 'pie').attr('class', 'form-control')
|
|
)
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').html('UF')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-minus remover').attr('id', 'remover_pie')
|
|
)
|
|
);
|
|
$('#remover_pie').click(function(e) {
|
|
removePie();
|
|
});
|
|
}
|
|
function removePie() {
|
|
if (!pie) {
|
|
return;
|
|
}
|
|
pie = false;
|
|
$('#pie').next().remove();
|
|
$('#pie').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Pie')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-plus agregar').attr('id', 'agregar_pie')
|
|
)
|
|
);
|
|
$('#agregar_pie').click(function(e) {
|
|
agregarPie();
|
|
});
|
|
}
|
|
function agregarCredito() {
|
|
if (credito) {
|
|
return;
|
|
}
|
|
credito = true;
|
|
$('#credito').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Crédito')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-3').append(
|
|
$('<input/>').attr('type', 'text').attr('name', 'credito').attr('class', 'form-control')
|
|
)
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').html('UF')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-minus remover').attr('id', 'remove_credito')
|
|
)
|
|
);
|
|
$('#remove_credito').click(function(e) {
|
|
removeCredito();
|
|
});
|
|
}
|
|
function removeCredito() {
|
|
if (!credito) {
|
|
return;
|
|
}
|
|
credito = false;
|
|
$('#credito').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Crédito')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-plus agregar').attr('id', 'agregar_credito')
|
|
)
|
|
);
|
|
$('#agregar_credito').click(function(e) {
|
|
agregarCredito();
|
|
});
|
|
}
|
|
function changeRegion(region) {
|
|
var jq_comunas = $("select[name='comuna']");
|
|
var region = $("select[name='region']").val();
|
|
jq_comunas.html('');
|
|
return $.post('{!!url('', ['p' => 'ajax', 'a' => 'comunas', 'ajax' => true])!!}', {"region": region}, function(data) {
|
|
info = $.parseJSON(data);
|
|
$.each(info, function(i, e) {
|
|
jq_comunas.append(
|
|
$('<option></option>').attr('value', e.id).html(e.descripcion)
|
|
);
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
@endpush |