develop (#45)
Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #45
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
<div class="inline field">
|
||||
<div class="ui calendar" id="fecha_venta_calendar">
|
||||
<div class="ui icon input">
|
||||
<input type="text" name="fecha_venta" id="fecha_venta" />
|
||||
<input type="text" name="fecha_venta" id="fecha_venta" required />
|
||||
<i class="calendar icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
@ -34,6 +34,7 @@
|
||||
<div class="four wide field">
|
||||
<div class="ui fluid search selection dropdown" id="proyecto">
|
||||
<input type="hidden" name="proyecto" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach($proyectos as $proyecto)
|
||||
@ -42,27 +43,32 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button" type="button" id="agregar_departamento">
|
||||
<button class="ui button" type="button" id="agregar_departamento" title="Agregar Departamento">
|
||||
<i class="plus icon"></i>
|
||||
<i class="building icon"></i>
|
||||
{{--Departamento--}}
|
||||
</button>
|
||||
<button class="ui button" type="button" id="agregar_estacionamiento">
|
||||
<button class="ui button" type="button" id="agregar_estacionamiento" title="Agregar Estacionamiento">
|
||||
<i class="plus icon"></i>
|
||||
<i class="car icon"></i>
|
||||
{{--Estacionamiento--}}
|
||||
</button>
|
||||
<button class="ui button" type="button" id="agregar_bodega">
|
||||
<button class="ui button" type="button" id="agregar_bodega" title="Agregar Bodega">
|
||||
<i class="plus icon"></i>
|
||||
<i class="warehouse icon"></i>
|
||||
{{--Bodega--}}
|
||||
</button>
|
||||
<button class="ui button" type="button" id="agregar_terraza" title="Agregar Terraza">
|
||||
<i class="plus icon"></i>
|
||||
<i class="vector square icon"></i>
|
||||
|
||||
</button>
|
||||
<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">
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="valor" id="valor" />
|
||||
<input type="text" name="valor" id="valor" required />
|
||||
<div class="ui label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -144,15 +150,17 @@
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const regiones = [
|
||||
@foreach ($regiones as $region)
|
||||
'<div class="item" data-value="{{$region->id}}">{{$region->descripcion}}</div>',
|
||||
'<div class="item" data-value="{{$region->id}}">{{$region->numeral}} - {{$region->descripcion}}</div>',
|
||||
@endforeach
|
||||
]
|
||||
|
||||
class Rut {
|
||||
class RutHandler {
|
||||
ids
|
||||
patterns
|
||||
valid
|
||||
@ -181,7 +189,7 @@
|
||||
}
|
||||
clean() {
|
||||
return {
|
||||
rut: rut => rut.includes('-') ? rut.split('-').join('') : rut
|
||||
rut: rut => rut.includes('-') || rut.includes('.') ? rut.replaceAll('-', '').replaceAll('.', '') : rut
|
||||
}
|
||||
}
|
||||
get() {
|
||||
@ -195,26 +203,20 @@
|
||||
verifier: digits => {
|
||||
let sum = 0
|
||||
let mul = 2
|
||||
|
||||
let i = digits.length
|
||||
while (i--) {
|
||||
sum = sum + parseInt(digits.charAt(i)) * mul
|
||||
if (mul % 7 === 0) {
|
||||
mul = 2
|
||||
} else {
|
||||
mul++
|
||||
}
|
||||
sum = sum + parseInt(digits.charAt(i)) * mul;
|
||||
(mul % 7 === 0) ? mul = 2 : mul++
|
||||
}
|
||||
|
||||
const res = sum % 11
|
||||
|
||||
if (res === 0) {
|
||||
return '0'
|
||||
} else if (res === 1) {
|
||||
return 'k'
|
||||
switch (res) {
|
||||
case 0:
|
||||
case 1:
|
||||
return res.toString()
|
||||
default:
|
||||
return `${11 - res}`
|
||||
}
|
||||
|
||||
return `${11 - res}`
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -222,9 +224,10 @@
|
||||
if (!this.is().like(rut) || (not_suspicious && this.is().suspicious(rut))) {
|
||||
return false
|
||||
}
|
||||
return this.get().verifier(rut).toLowerCase() === this.calculate().verifier(this.get().digits(rut))
|
||||
return Rut.validar(this.get().digits(rut), this.get().verifier(rut))
|
||||
}
|
||||
verify(event) {
|
||||
this.alert().valid()
|
||||
const input = $(event.currentTarget)
|
||||
const val = input.val()
|
||||
let new_val = this.clean().rut(val)
|
||||
@ -237,7 +240,6 @@
|
||||
this.alert().invalid()
|
||||
return
|
||||
}
|
||||
this.alert().valid()
|
||||
this.valid(new_val)
|
||||
}
|
||||
alert() {
|
||||
@ -262,7 +264,9 @@
|
||||
provincias: []
|
||||
}
|
||||
|
||||
$(this.id).dropdown()
|
||||
$(this.id).dropdown({
|
||||
forceSelection: true
|
||||
})
|
||||
}
|
||||
|
||||
get() {
|
||||
@ -332,6 +336,7 @@
|
||||
const dd = $(this.id)
|
||||
dd.dropdown({
|
||||
fireOnInit: true,
|
||||
forceSelection: true,
|
||||
onChange: value => {
|
||||
this.comuna.data.region = value
|
||||
this.comuna.get().provincias()
|
||||
@ -349,60 +354,71 @@
|
||||
const lines = [
|
||||
'<label for="rut">RUT</label>',
|
||||
'<div class="inline field">',
|
||||
'<input type="text" id="rut" name="rut" placeholder="00000000-0" />',
|
||||
'<span class="ui error message" id="alert_rut">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
'</span>',
|
||||
'<input type="text" id="rut" name="rut" placeholder="00000000-0" required />',
|
||||
'<span class="ui error message" id="alert_rut">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
'</span>',
|
||||
'</div>',
|
||||
'<label for="nombres">Nombre</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="nombres" id="nombres" placeholder="Nombre(s)" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_paterno" placeholder="Apellido Paterno" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_materno" placeholder="Apellido Materno" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="nombres" id="nombres" placeholder="Nombre(s)" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_paterno" placeholder="Apellido Paterno" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_materno" placeholder="Apellido Materno" required />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label for="calle">Dirección</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle" id="calle" size="16" placeholder="Calle" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero" size="5" placeholder="Número" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra" placeholder="Otros Detalles" />',
|
||||
'</div>',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle" id="calle" size="16" placeholder="Calle" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero" size="5" placeholder="Número" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra" placeholder="Otros Detalles" />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="two wide field"></div>',
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="comuna">',
|
||||
'<input type="hidden" name="comuna" />',
|
||||
'<div class="default text">Comuna</div>',
|
||||
'<div class="menu"></div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="six wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="region">',
|
||||
'<input type="hidden" name="region" />',
|
||||
'<div class="default text">Región</div>',
|
||||
'<div class="menu">',
|
||||
...regiones,
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div class="two wide field"></div>',
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid 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="six wide field">',
|
||||
'<div class="ui fluid 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">',
|
||||
...regiones,
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label>Otros Datos</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="four wide field">',
|
||||
'<input type="email" name="email" placeholder="Email" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="telefono" placeholder="Teléfono" />',
|
||||
'</div>',
|
||||
'</div>'
|
||||
]
|
||||
return lines.join("\n")
|
||||
}
|
||||
activate() {
|
||||
new Rut({id: '#rut', alert_id: '#alert_rut', valid: this.valid})
|
||||
new RutHandler({id: '#rut', alert_id: '#alert_rut', valid: this.valid})
|
||||
const comuna = new Comuna('#comuna')
|
||||
new Region({id: '#region', comuna})
|
||||
}
|
||||
@ -416,7 +432,7 @@
|
||||
const lines = [
|
||||
'<label for="rut">RUT Sociedad</label>',
|
||||
'<div class="inline field">',
|
||||
'<input type="text" id="rut_sociedad" name="rut_sociedad" />',
|
||||
'<input type="text" id="rut_sociedad" name="rut_sociedad" required />',
|
||||
'<span class="ui error message" id="alert_rut_sociedad">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
@ -424,15 +440,15 @@
|
||||
'</div>',
|
||||
'<label for="razon_social">Razón Social</label>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="razon_social" id="razon_social" />',
|
||||
'<input type="text" name="razon_social" id="razon_social" required />',
|
||||
'</div>',
|
||||
'<label for="calle_comercial">Dirección Comercial</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle_comercial" id="calle_comercial" size="16" />',
|
||||
'<input type="text" name="calle_comercial" id="calle_comercial" size="16" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero_comercial" size="5" />',
|
||||
'<input type="text" name="numero_comercial" size="5" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra_comercial" />',
|
||||
@ -443,6 +459,7 @@
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="comuna_sociedad">',
|
||||
'<input type="hidden" name="comuna_sociedad" />',
|
||||
'<i class="dropdown icon"></i>',
|
||||
'<div class="default text">Comuna</div>',
|
||||
'<div class="menu"></div>',
|
||||
'</div>',
|
||||
@ -450,6 +467,7 @@
|
||||
'<div class="six wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="region_sociedad">',
|
||||
'<input type="hidden" name="region_sociedad" />',
|
||||
'<i class="dropdown icon"></i>',
|
||||
'<div class="default text">Región</div>',
|
||||
'<div class="menu">',
|
||||
...regiones,
|
||||
@ -458,11 +476,13 @@
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div>Representante Legal</div>',
|
||||
'<div class="ui divider"></div>',
|
||||
this.persona.draw()
|
||||
]
|
||||
return [lines.join("\n"), this.persona.draw()].join("\n")
|
||||
return lines.join("\n")
|
||||
}
|
||||
activate() {
|
||||
new Rut({id: '#rut_sociedad', alert_id: '#alert_rut_sociedad'})
|
||||
new RutHandler({id: '#rut_sociedad', alert_id: '#alert_rut_sociedad'})
|
||||
const comuna = new Comuna('#comuna_sociedad')
|
||||
new Region({id: '#region_sociedad', comuna})
|
||||
this.persona.activate()
|
||||
@ -477,9 +497,10 @@
|
||||
draw() {
|
||||
let lines = [
|
||||
this.persona.draw(),
|
||||
'<div class="ui divider"></div>',
|
||||
'<label for="rut">RUT Otro</label>',
|
||||
'<div class="inline field">',
|
||||
'<input type="text" id="rut_otro" name="rut_otro" />',
|
||||
'<input type="text" id="rut_otro" name="rut_otro" required />',
|
||||
'<span class="ui error message" id="alert_rut_otro">',
|
||||
'<i class="exclamation triangle icon"></i>',
|
||||
'RUT Inválido',
|
||||
@ -488,22 +509,22 @@
|
||||
'<label for="nombres_otro">Nombre Otro</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="nombres_otro" id="nombres_otro" />',
|
||||
'<input type="text" name="nombres_otro" id="nombres_otro" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_paterno_otro" />',
|
||||
'<input type="text" name="apellido_paterno_otro" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="apellido_materno_otro" />',
|
||||
'<input type="text" name="apellido_materno_otro" required />',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label for="calle_otro">Dirección Otro</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="eight wide field">',
|
||||
'<input type="text" name="calle_otro" id="calle_otro" size="16" />',
|
||||
'<input type="text" name="calle_otro" id="calle_otro" size="16" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="numero_otro" size="5" />',
|
||||
'<input type="text" name="numero_otro" size="5" required />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="extra_otro" />',
|
||||
@ -514,6 +535,7 @@
|
||||
'<div class="four wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="comuna_otro">',
|
||||
'<input type="hidden" name="comuna_otro" />',
|
||||
'<i class="dropdown icon"></i>',
|
||||
'<div class="default text">Comuna</div>',
|
||||
'<div class="menu"></div>',
|
||||
'</div>',
|
||||
@ -521,19 +543,29 @@
|
||||
'<div class="six wide field">',
|
||||
'<div class="ui fluid search selection dropdown" id="region_otro">',
|
||||
'<input type="hidden" name="region_otro" />',
|
||||
'<i class="dropdown icon"></i>',
|
||||
'<div class="default text">Región</div>',
|
||||
'<div class="menu">',
|
||||
...regiones,
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<label>Otros Datos para Otro</label>',
|
||||
'<div class="inline fields">',
|
||||
'<div class="four wide field">',
|
||||
'<input type="email" name="email_otro" placeholder="Email" />',
|
||||
'</div>',
|
||||
'<div class="field">',
|
||||
'<input type="text" name="telefono_otro" placeholder="Teléfono" />',
|
||||
'</div>',
|
||||
'</div>'
|
||||
]
|
||||
return lines.join("\n")
|
||||
}
|
||||
activate() {
|
||||
this.persona.activate()
|
||||
new Rut({id: '#rut_otro', alert_id: '#alert_rut_otro'})
|
||||
new RutHandler({id: '#rut_otro', alert_id: '#alert_rut_otro'})
|
||||
const comuna = new Comuna('#comuna_otro')
|
||||
new Region({id: '#region_otro', comuna})
|
||||
}
|
||||
@ -596,6 +628,8 @@
|
||||
parent.find("[name='extra']").val(data.propietario.direccion.extra)
|
||||
parent.find('#region').dropdown('set selected', data.propietario.direccion.comuna.provincia.region.id)
|
||||
parent.find('#comuna').dropdown('set selected', data.propietario.direccion.comuna.id)
|
||||
parent.find("[name='email']").val(data.propietario.email)
|
||||
parent.find("[name='telefono']").val(data.propietario.telefono)
|
||||
|
||||
if (data.propietario.representante !== '') {
|
||||
document.getElementById(this.ids.tipo).trigger('check')
|
||||
@ -634,6 +668,7 @@
|
||||
|
||||
$(this.ids.proyecto).dropdown({
|
||||
fireOnInit: true,
|
||||
forceSelection: true,
|
||||
onChange: (value, text, $choice) => {
|
||||
this.data.id = value
|
||||
this.ids.buttons.forEach(button => {
|
||||
@ -641,8 +676,10 @@
|
||||
})
|
||||
this.reset()
|
||||
this.fetch().unidades().then(() => {
|
||||
this.ids.buttons.forEach(button => {
|
||||
$(button).prop('disabled', false)
|
||||
Object.keys(this.unidades).forEach(name => {
|
||||
if (this.unidades[name].length > 0) {
|
||||
$(`#agregar_${name}`).prop('disabled', false)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -650,10 +687,11 @@
|
||||
const buttons = [
|
||||
'departamento',
|
||||
'estacionamiento',
|
||||
'bodega'
|
||||
'bodega',
|
||||
'terraza'
|
||||
]
|
||||
buttons.forEach(name => {
|
||||
const id = '#agregar_' + name
|
||||
const id = `#agregar_${name}`
|
||||
this.ids.buttons.push(id)
|
||||
$(id).click(event => {
|
||||
this.add(name)
|
||||
@ -770,7 +808,9 @@
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
$('#fecha_venta_calendar').calendar(calendar_date_options)
|
||||
const cdo = structuredClone(calendar_date_options)
|
||||
cdo['maxDate'] = new Date()
|
||||
$('#fecha_venta_calendar').calendar(cdo)
|
||||
new Propietario({id: '#propietario', id_tipo: 'persona_propietario', id_cantidad: 'cantidad_propietario'})
|
||||
new Proyecto({unidades_id: '#unidades', proyecto_id: '#proyecto'})
|
||||
|
||||
@ -789,7 +829,22 @@
|
||||
|
||||
$('#add_form').submit(event => {
|
||||
event.preventDefault()
|
||||
const button = $(event.currentTarget).find(".ui.button[type='submit']")
|
||||
button.prop('disabled', true)
|
||||
button.css('cursor', 'wait')
|
||||
const body = new FormData(event.currentTarget)
|
||||
const unidades = event.currentTarget.querySelectorAll("[name^='unidad']")
|
||||
const emptyUnidades = []
|
||||
unidades.forEach(unidad => {
|
||||
if (unidad.value.trim() === '') {
|
||||
emptyUnidades.push(unidad)
|
||||
body.delete(unidad.name)
|
||||
}
|
||||
})
|
||||
if (unidades.length === emptyUnidades.length) {
|
||||
alert("No hay unidades seleccionadas")
|
||||
return;
|
||||
}
|
||||
const uri = '{{$urls->api}}/ventas/add'
|
||||
return fetchAPI(uri, {method: 'post', body}).then(response => {
|
||||
if (!response) {
|
||||
@ -800,6 +855,8 @@
|
||||
window.location = '{{$urls->base}}/venta/' + data.venta_id
|
||||
return true
|
||||
}
|
||||
button.prop('disabled', false)
|
||||
button.css('cursor', 'pointer')
|
||||
showErrors(data.errors)
|
||||
return false
|
||||
})
|
||||
|
Reference in New Issue
Block a user