Files
oficial/app/resources/views/inmobiliarias/proveedores.blade.php

167 lines
6.0 KiB
PHP
Raw Normal View History

2024-06-18 22:41:03 -04:00
@extends('layout.base')
@section('page_content')
<div class="ui container">
<table class="ui table">
<thead>
<tr>
<th>Nombre</th>
<th>Contacto</th>
<th class="right aligned">
2024-12-03 16:45:20 -03:00
<button class="ui tertiary green icon button" id="add_button">
2024-06-18 22:41:03 -04:00
<i class="plus icon"></i>
</button>
</th>
</tr>
</thead>
<tbody id="proveedores">
2024-11-29 17:47:12 -03:00
@foreach ($proveedores as $proveedor)
2024-06-18 22:41:03 -04:00
<tr>
2024-11-29 17:47:12 -03:00
<td>{{$proveedor->nombre}}</td>
<td>{{$proveedor->contacto->nombreCompleto()}}</td>
2024-06-18 22:41:03 -04:00
<td class="right aligned">
2024-12-03 16:45:20 -03:00
<button class="ui tertiary icon button" data-proveedor="{{$proveedor->rut}}">
2024-06-18 22:41:03 -04:00
<i class="edit icon"></i>
</button>
2024-12-03 16:45:20 -03:00
<button class="ui tertiary red icon button" data-proveedor="{{$proveedor->rut}}">
2024-06-18 22:41:03 -04:00
<i class="remove icon"></i>
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
2024-12-03 16:45:20 -03:00
@include('inmobiliarias.proveedores.add_modal')
2024-06-18 22:41:03 -04:00
@endsection
2024-12-03 16:45:20 -03:00
@include('layout.body.scripts.rut')
2024-06-18 22:41:03 -04:00
@push('page_scripts')
<script>
const proveedores = {
ids: {
buttons: {
add: '',
edit: '',
remove: ''
},
add: {
form: '',
rut: '',
dv: '',
nombre: '',
razon: '',
contacto: {
rut: '',
dv: '',
nombre: '',
apellido_paterno: '',
apellido_materno: '',
email: '',
telefono: ''
}
},
proveedores: ''
},
2024-11-29 17:47:12 -03:00
data: JSON.parse('{!! json_encode($proveedores) !!}'),
edit() {
},
2024-06-18 22:41:03 -04:00
remove() {
return {
2024-12-03 16:45:20 -03:00
proveedor: rut => {
const url = `{{$urls->api}}/inmobiliarias/proveedor/${rut}/delete`
const method = 'delete'
APIClient.fetch(url, {method})
2024-06-18 22:41:03 -04:00
.then(response => (response) ? response.json() : null)
.then(data => {
2024-12-03 16:45:20 -03:00
if (data.success) {
window.location.reload()
2024-06-18 22:41:03 -04:00
}
})
}
}
},
draw() {
return {
2024-12-03 16:45:20 -03:00
proveedores: () => {
2024-06-18 22:41:03 -04:00
$(this.ids.proveedores).empty()
2024-12-03 16:45:20 -03:00
this.data.forEach(proveedor => {
2024-06-18 22:41:03 -04:00
$(this.ids.proveedores).append(`
<tr>
2024-12-03 16:45:20 -03:00
<td>${proveedor.nombre}</td>
<td>${proveedor.contacto.nombreCompleto}</td>
2024-06-18 22:41:03 -04:00
<td class="right aligned">
2024-12-03 16:45:20 -03:00
<button class="ui icon button" data-proveedor="${proveedor.rut}">
2024-06-18 22:41:03 -04:00
<i class="edit icon"></i>
</button>
2024-12-03 16:45:20 -03:00
<button class="ui red icon button" data-proveedor="${proveedor.rut}">
2024-06-18 22:41:03 -04:00
<i class="remove icon"></i>
</button>
</td>
</tr>
`)
})
$(this.ids.buttons.remove).click((e) => {
2024-12-03 16:45:20 -03:00
this.remove().proveedor($(e.target).data('proveedor'))
2024-06-18 22:41:03 -04:00
})
}
}
},
formatters() {
return {
rut: value => {
2024-12-03 16:45:20 -03:00
return Rut.format(value)
2024-06-18 22:41:03 -04:00
},
telefono: value => {
const phone = value.replace(/[^0-9]/g, '')
if (phone.length <= 1) {
return phone
}
return phone.replace(/(\d{2})(\d{3})(\d{4})/, '$1 $2 $3')
}
}
},
setup(ids) {
this.ids = ids
2024-12-03 16:45:20 -03:00
const addModal = new AddModal(this.ids.add, this.formatters())
2024-06-18 22:41:03 -04:00
$(this.ids.buttons.add).click(() => {
2024-12-03 16:45:20 -03:00
addModal.show()
2024-06-18 22:41:03 -04:00
})
$(this.ids.buttons.remove).click((e) => {
2024-12-03 16:45:20 -03:00
this.remove().proveedor(e.currentTarget.parentNode.dataset.proveedor)
2024-06-18 22:41:03 -04:00
})
}
}
$(document).ready(() => {
proveedores.setup({
buttons: {
add: '#add_button',
edit: '.edit',
remove: '.remove'
},
add: {
2024-12-03 16:45:20 -03:00
modal: '#add_modal',
form: 'add_form',
2024-06-18 22:41:03 -04:00
rut: '#rut',
2024-12-03 16:45:20 -03:00
digito: '#dv',
2024-06-18 22:41:03 -04:00
nombre: '#nombre',
razon: '#razon',
contacto: {
rut: '#rut_contacto',
2024-12-03 16:45:20 -03:00
digito: '#dv_contacto',
nombres: '#nombre_contacto',
2024-06-18 22:41:03 -04:00
apellido_paterno: '#apellido_paterno_contacto',
apellido_materno: '#apellido_materno_contacto',
email: '#email_contacto',
telefono: '#telefono_contacto'
}
},
proveedores: '#proveedores'
})
})
</script>
@endpush