562 lines
18 KiB
PHP
562 lines
18 KiB
PHP
@extends('layout.base')
|
|
|
|
@section('content')
|
|
<div class="row page-heading">
|
|
<div class="col-md-12 h3">Nueva Venta</div>
|
|
</div>
|
|
<br />
|
|
<form method="post" class="form-horizontal" action="{{url('', ['p' => 'ventas', 'a' => 'agregar'])}}">
|
|
<div class="form-group">
|
|
<div class="col-md-2">Fecha de Venta</div>
|
|
<?php $f = \Carbon\Carbon::today(config('app.timezone')) ?>
|
|
<div class="col-md-1"><select name="day" class="form-control">
|
|
@for ($i = 0; $i < 31; $i ++)
|
|
<option value="{{$i + 1}}"
|
|
@if ($i + 1 == $f->day)
|
|
selected="selected"
|
|
@endif
|
|
>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
|
|
@endfor
|
|
</select></div>
|
|
<div class="col-md-1"><select name="month" class="form-control">
|
|
@for ($i = 0; $i < 12; $i ++)
|
|
<option value="{{$i + 1}}"
|
|
@if ($i + 1 == $f->month)
|
|
selected="selected"
|
|
@endif
|
|
>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
|
|
@endfor
|
|
</select></div>
|
|
<div class="col-md-2"><select name="year" class="form-control">
|
|
@for ($i = $f->year; $i > $f->year - 5; $i --)
|
|
<option value="{{$i}}">{{$i}}</option>
|
|
@endfor
|
|
</select></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 class="col-md-1"><input type="checkbox" name="otro" /></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="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 id="unidades">
|
|
<input type="hidden" name="unidades" value="0" />
|
|
<div class="form-group">
|
|
<div class="col-md-2">Unidades</div>
|
|
<div class="col-md-4">
|
|
<div class="btn-group" role="group" id="tipo_unidad"></div>
|
|
</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="subsidio">
|
|
<div class="col-md-2">Subsidio</div>
|
|
<div class="col-md-1"><span class="glyphicon glyphicon-plus agregar" id="agregar_subsidio"></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">OTRAS CONDICIONES</div>
|
|
<br />
|
|
<div class="form-group" id="bono">
|
|
<div class="col-md-2">Bono Pie</div>
|
|
<div class="col-md-1"><span class="glyphicon glyphicon-plus agregar" id="agregar_bono"></span></div>
|
|
</div>
|
|
<div class="form-group">
|
|
<div class="col-md-2">Operador</div>
|
|
<div class="col-md-3"><select name="operador" class="form-control">
|
|
</select></div>
|
|
</div>
|
|
<div id="promociones">
|
|
<input type="hidden" name="promociones" value="0" />
|
|
<div class="form-group">
|
|
<div class="col-md-2">Promociones</div>
|
|
<div class="col-md-1"><span class="glyphicon glyphicon-plus agregar" id="agregar_promocion"></span></div>
|
|
</div>
|
|
</div>
|
|
<hr />
|
|
<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 subsidio = false;
|
|
var credito = false;
|
|
var bono = false;
|
|
var promociones = [];
|
|
$(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_pie').click(function(e) {
|
|
agregarPie();
|
|
});
|
|
$('#agregar_subsidio').click(function(e) {
|
|
agregarSubsidio();
|
|
});
|
|
$('#agregar_credito').click(function(e) {
|
|
agregarCredito();
|
|
});
|
|
$('#agregar_bono').click(function(e) {
|
|
agregarBonoPie();
|
|
});
|
|
$('#agregar_promocion').click(function(e) {
|
|
agregarPromocion();
|
|
});
|
|
});
|
|
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 = $("#tipo_unidad");
|
|
tipo.html('');
|
|
var info = $.parseJSON(data);
|
|
$.each(info, function(i, e) {
|
|
tipo.append($('<button></button>')
|
|
.attr('data-value', e.id)
|
|
.attr('class', 'btn btn-default tipo_unidad_')
|
|
.html('<span class="glyphicon glyphicon-plus"></span><br />' + e.descripcion.ucwords())
|
|
);
|
|
});
|
|
$('.tipo_unidad_').click(function(e) {
|
|
e.preventDefault();
|
|
|
|
var val = $(this).attr('data-value');
|
|
var name = $(this).text();
|
|
agregarUnidad(val, name);
|
|
|
|
return false;
|
|
});
|
|
$('#unidades').show();
|
|
});
|
|
$.ajax({
|
|
url: 'https://provm.cl:8001/proyecto/' + proyecto + '/operadores',
|
|
method: 'get',
|
|
dataType: 'json'
|
|
}).then(function(data) {
|
|
var operadoress = $("select[name='operador']");
|
|
operadores.html('').append($('<option></option>').attr('value', 0).html('---'));
|
|
$.each(data.operadores, function(i, e) {
|
|
operadores.append($('<option></option>').attr('value', e.id).html(e.operador.abreviacion));
|
|
});
|
|
|
|
});
|
|
/*$.getJSON('http://provm.cl:8001/proyecto/' + proyecto + '/operadores', function(data) {
|
|
var operadores = $("select[name='operador']");
|
|
operadores.html('').append($('<option></option>').attr('value', 0).html('---'));
|
|
$.each(data.operadores, function(i, e) {
|
|
operadores.append($('<option></option>').attr('value', e.id).html(e.operador.abreviacion));
|
|
});
|
|
});
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'operadores', 'ajax' => true])!!}', {"proyecto": proyecto}, function(data) {
|
|
var operadores = $("select[name='operador']");
|
|
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(tipo, name) {
|
|
var proyecto = $("select[name='proyecto']").val();
|
|
if (proyecto == '0') {
|
|
$('#unidades').hide();
|
|
}
|
|
|
|
$.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.tipologia.tipologia.descripcion));
|
|
});
|
|
ntipo = name;
|
|
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')
|
|
).after(
|
|
$('<div></div>').attr('class', 'form-group').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Cuotas')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<input/>').attr('type', 'text').attr('name', 'cuotas').attr('maxlength', '2').attr('class', 'form-control')
|
|
)
|
|
).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 agregarSubsidio() {
|
|
if (subsidio) {
|
|
return;
|
|
}
|
|
subsidio = true;
|
|
$('#subsidio').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Subsidio')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-3').append(
|
|
$('<input/>').attr('type', 'text').attr('name', 'subsidio').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_subsidio')
|
|
)
|
|
);
|
|
$('#remove_subsidio').click(function(e) {
|
|
removeSubsidio();
|
|
});
|
|
}
|
|
function removeSubsidio() {
|
|
if (!subsidio) {
|
|
return;
|
|
}
|
|
subsidio = false;
|
|
$('#subsidio').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Subsidio')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-plus agregar').attr('id', 'agregar_subsidio')
|
|
)
|
|
);
|
|
$('#agregar_subsidio').click(function(e) {
|
|
agregarSubsidio();
|
|
});
|
|
}
|
|
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 agregarBonoPie() {
|
|
if (bono) {
|
|
return;
|
|
}
|
|
bono = true;
|
|
$('#bono').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Bono Pie')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-3').append(
|
|
$('<input/>').attr('type', 'text').attr('name', 'bono_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', 'remove_bono')
|
|
)
|
|
);
|
|
$('#remove_bono').click(function(e) {
|
|
removeBonoPie();
|
|
});
|
|
}
|
|
function removeBonoPie() {
|
|
if (!bono) {
|
|
return;
|
|
}
|
|
bono = false;
|
|
$('#bono').html('').append(
|
|
$('<div></div>').attr('class', 'col-md-2').html('Bono Pie')
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-plus agregar').attr('id', 'agregar_bono')
|
|
)
|
|
);
|
|
$('#agregar_bono').click(function(e) {
|
|
agregarBonoPie();
|
|
});
|
|
}
|
|
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)
|
|
);
|
|
});
|
|
});
|
|
}
|
|
function agregarPromocion() {
|
|
var proyecto = $("select[name='proyecto']").val();
|
|
if (proyecto == '0') {
|
|
return;
|
|
}
|
|
|
|
$.post('{!!url('', ['p' => 'ajax', 'a' => 'promociones', 'ajax' => true])!!}', {"proyecto": proyecto}, function(data) {
|
|
var info = $.parseJSON(data);
|
|
var promos = $('#promociones');
|
|
var n = promociones[promociones.length - 1] + 1;
|
|
if (promociones.length == 0) {
|
|
n = 1
|
|
}
|
|
promociones[promociones.length] = n;
|
|
|
|
var select = $('<select></select>').attr('name', 'promocion' + n).attr('class', 'form-control');
|
|
$.each(info, function(i, e) {
|
|
select.append($('<option></option>').attr('value', e.id).html(e.titulo));
|
|
});
|
|
|
|
promos.append(
|
|
$('<div></div>').attr('class', 'form-group').append(
|
|
$('<div></div>').attr('class', 'col-md-2').append(
|
|
select
|
|
)
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-3').append(
|
|
$('<input/>').attr('type', 'text').attr('name', 'promo' + n).attr('class', 'form-control')
|
|
)
|
|
).append(
|
|
$('<div></div>').attr('class', 'col-md-1').append(
|
|
$('<span></span>').attr('class', 'glyphicon glyphicon-minus remover').attr('data-id', n).attr('id', 'remover_promociones' + n)
|
|
)
|
|
)
|
|
);
|
|
|
|
$("input[name='promociones']").val(JSON.stringify(promociones));
|
|
$('#remover_promociones' + n).click(function(e) {
|
|
i = $(this).attr('data-id');
|
|
removePromocion(i);
|
|
});
|
|
});
|
|
}
|
|
function removePromocion(n) {
|
|
var promos = $('#promociones');
|
|
promos.find("select[name='promocion" + n + "']").parent().parent().remove();
|
|
i = promociones.binaryIndexOf(n);
|
|
promociones.splice(i, 1);
|
|
$("input[name='promociones']").val(JSON.stringify(promociones));
|
|
}
|
|
</script>
|
|
@endpush
|