feature/cierres (#25)
Varios cambios Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #25
This commit is contained in:
@ -14,15 +14,15 @@
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="users">
|
||||
@foreach($users as $user)
|
||||
<tr>
|
||||
<tr data-user="{{ $user->id }}">
|
||||
<td>{{ $user->name }}</td>
|
||||
<td class="right aligned">
|
||||
<button class="ui mini blue icon button">
|
||||
<button class="ui mini blue icon button edit" data-user="{{ $user->id }}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui mini red icon button">
|
||||
<button class="ui mini red icon button remove" data-user="{{ $user->id }}">
|
||||
<i class="trash icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
@ -50,6 +50,10 @@
|
||||
<label>Contraseña</label>
|
||||
<input type="password" name="password" placeholder="Contraseña">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Confirmar contraseña</label>
|
||||
<input type="password" name="password_confirmation" placeholder="Confirmar contraseña">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
@ -62,6 +66,45 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui modal" id="edit-user-modal">
|
||||
<i class="close icon"></i>
|
||||
<div class="header">
|
||||
Editar usuario
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form">
|
||||
<input type="hidden" name="id" />
|
||||
<div class="field">
|
||||
<label>Contraseña Antigua</label>
|
||||
<input type="password" name="old_password" placeholder="Contraseña Antigua">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Force Change?</label>
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="force" >
|
||||
<label>Yes</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Contraseña</label>
|
||||
<input type="password" name="password" placeholder="Contraseña">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Confirmar contraseña</label>
|
||||
<input type="password" name="password_confirmation" placeholder="Confirmar contraseña">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Guardar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.cryptojs')
|
||||
@ -74,12 +117,20 @@
|
||||
return [passphrase, encrypted.toString()].join('')
|
||||
}
|
||||
$(document).ready(function () {
|
||||
$('#create-user-modal').modal({
|
||||
const $createUserModal = $('#create-user-modal')
|
||||
$createUserModal.modal({
|
||||
onApprove: function() {
|
||||
const form = document.querySelector('#create-user-modal form')
|
||||
const password = form.querySelector('[name="password"]').value
|
||||
const password_confirmation = form.querySelector('[name="password_confirmation"]').value
|
||||
if (password !== password_confirmation) {
|
||||
alert('Las contraseñas no coinciden')
|
||||
return
|
||||
}
|
||||
const url = '{{$urls->api}}/admin/users/add'
|
||||
const method = 'post'
|
||||
const body = new FormData(document.querySelector('#create-user-modal form'))
|
||||
body.set('password', encryptPassword(body.get('password')))
|
||||
const body = new FormData(form)
|
||||
body.set('password', encryptPassword(password))
|
||||
fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return;
|
||||
@ -92,8 +143,64 @@
|
||||
})
|
||||
}
|
||||
})
|
||||
$('#create-user-button').on('click', function () {
|
||||
$('#create-user-modal').modal('show')
|
||||
const $editUserModal = $('#edit-user-modal')
|
||||
$editUserModal.modal({
|
||||
onApprove: function() {
|
||||
const form = document.querySelector('#edit-user-modal form')
|
||||
const user_id = form.querySelector('[name="id"]').value
|
||||
const old_password = form.querySelector('[name="old_password"]').value
|
||||
const password = form.querySelector('[name="password"]').value
|
||||
const password_confirmation = form.querySelector('[name="password_confirmation"]').value
|
||||
if (password !== password_confirmation) {
|
||||
alert('Las nuevas contraseñas no coinciden')
|
||||
return
|
||||
}
|
||||
const url = `{{$urls->api}}/admin/user/${user_id}/edit`
|
||||
const method = 'post'
|
||||
const body = new FormData(form)
|
||||
body.set('old_password', encryptPassword(old_password))
|
||||
body.set('password', encryptPassword(password))
|
||||
if (form.querySelector('[name="force"]').checked) {
|
||||
body.set('force', 'true')
|
||||
}
|
||||
fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
response.json().then(result => {
|
||||
if (result.success) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
document.getElementById('create-user-modal').addEventListener('submit', event => {
|
||||
$createUserModal.modal('show')
|
||||
})
|
||||
document.querySelectorAll('.button.edit').forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const user_id = clickEvent.currentTarget.dataset.user
|
||||
$editUserModal.find('input[name="id"]').val(user_id)
|
||||
$editUserModal.modal('show')
|
||||
})
|
||||
})
|
||||
document.querySelectorAll('.button.remove').forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const user_id = clickEvent.currentTarget.dataset.user
|
||||
const url = `{{$urls->api}}/admin/user/${user_id}`
|
||||
const method = 'delete'
|
||||
fetchAPI(url, {method}).then(response => {
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
response.json().then(result => {
|
||||
if (result.success) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
@ -96,26 +96,7 @@
|
||||
columnDefs,
|
||||
order,
|
||||
language: Object.assign(dtD.language, {
|
||||
searchBuilder: {
|
||||
add: 'Filtrar',
|
||||
condition: 'Comparador',
|
||||
clearAll: 'Resetear',
|
||||
delete: 'Eliminar',
|
||||
deleteTitle: 'Eliminar Titulo',
|
||||
data: 'Columna',
|
||||
left: 'Izquierda',
|
||||
leftTitle: 'Titulo Izquierdo',
|
||||
logicAnd: 'Y',
|
||||
logicOr: 'O',
|
||||
right: 'Derecha',
|
||||
rightTitle: 'Titulo Derecho',
|
||||
title: {
|
||||
0: 'Filtros',
|
||||
_: 'Filtros (%d)'
|
||||
},
|
||||
value: 'Opciones',
|
||||
valueJoiner: 'y'
|
||||
}
|
||||
searchBuilder
|
||||
}),
|
||||
layout: {
|
||||
top1: {
|
||||
|
@ -20,7 +20,7 @@
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const cuotas = {
|
||||
get: function() {
|
||||
return {
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="ui divided list" id="alertas_escrituras"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const alertas_escrituras = {
|
||||
id: '#alertas_escrituras',
|
||||
data: {
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="ui divided list" id="cierres_vigentes"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const cierres_vigentes = {
|
||||
get: function() {
|
||||
const list = $('#cierres_vigentes')
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="ui divided list" id="cuotas_por_vencer"></div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const cuotas_por_vencer = {
|
||||
get: function() {
|
||||
const list = $('#cuotas_por_vencer')
|
||||
|
@ -3,5 +3,6 @@
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/proyectos/unidades">Unidades</a>
|
||||
<a class="item" href="{{ $urls->base }}/proyectos/brokers">Operadores</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -11,7 +11,7 @@
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
function logout() {
|
||||
return fetch('{{$urls->base}}/logout').then(response => {
|
||||
if (response.ok) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{$urls->base}}/ventas/precios">Precios</a>
|
||||
<a class="item" href="{{ $urls->base }}/ventas/promotions">Promociones</a>
|
||||
<a class="item" href="{{$urls->base}}/ventas/cierres">Cierres</a>
|
||||
<div class="item">
|
||||
Cuotas
|
||||
@ -33,6 +34,7 @@
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/precios/importar">Importar Precios</a>--}}
|
||||
{{--<a class="item" href="{{$urls->base}}/ventas/cierres/evaluar">Evaluar Cierre</a>--}}
|
||||
<a class="item" href="{{$urls->base}}/ventas/facturacion">Facturación</a>
|
||||
<div class="divider"></div>
|
||||
<a class="item" href="{{$urls->base}}/ventas/add">
|
||||
Nueva Venta
|
||||
<i class="plus icon"></i>
|
||||
|
@ -1,33 +1,9 @@
|
||||
<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.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
class APIClient {
|
||||
static fetch(url, options=null, showErrors=false) {
|
||||
return fetchAPI(url, options, showErrors)
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null, showErrors=false) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
}
|
||||
if (!Object.hasOwn(options, 'headers')) {
|
||||
options['headers'] = {}
|
||||
}
|
||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}{{($login->isIn()) ? $login->getSeparator() . $login->getToken() : ''}}'
|
||||
}
|
||||
return fetch(url, options).then(response => {
|
||||
if (response.ok) {
|
||||
return response
|
||||
}
|
||||
throw new Error(JSON.stringify({code: response.status, message: response.statusText, url}))
|
||||
}).catch(error => {
|
||||
if (showErrors) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
@include('layout.body.scripts.api')
|
||||
|
||||
<script>
|
||||
const datatables_defaults = {
|
||||
language: {
|
||||
emptyTable: 'No hay datos disponibles',
|
||||
|
32
app/resources/views/layout/body/scripts/api.blade.php
Normal file
32
app/resources/views/layout/body/scripts/api.blade.php
Normal file
@ -0,0 +1,32 @@
|
||||
<script>
|
||||
class APIClient {
|
||||
static getApiKey() {
|
||||
return '{{md5($API_KEY)}}{{($login->isIn()) ? $login->getSeparator() . $login->getToken() : ''}}'
|
||||
}
|
||||
|
||||
static fetch(url, options=null, showErrors=false) {
|
||||
if (options === null) {
|
||||
options = {}
|
||||
}
|
||||
if (!Object.hasOwn(options, 'headers')) {
|
||||
options['headers'] = {}
|
||||
}
|
||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||
options['headers']['Authorization'] = `Bearer ${APIClient.getApiKey()}`
|
||||
}
|
||||
return fetch(url, options).then(response => {
|
||||
if (response.ok) {
|
||||
return response
|
||||
}
|
||||
throw new Error(JSON.stringify({code: response.status, message: response.statusText, url}))
|
||||
}).catch(error => {
|
||||
if (showErrors) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function fetchAPI(url, options=null, showErrors=false) {
|
||||
return APIClient.fetch(url, options, showErrors)
|
||||
}
|
||||
</script>
|
@ -1,4 +1,4 @@
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/2.0.3/js/dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.semanticui.min.js"></script>
|
||||
@endpush
|
||||
|
@ -2,4 +2,26 @@
|
||||
<script src="https://cdn.datatables.net/datetime/1.5.2/js/dataTables.dateTime.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/searchbuilder/1.7.0/js/dataTables.searchBuilder.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/searchbuilder/1.7.0/js/searchBuilder.semanticui.js"></script>
|
||||
<script>
|
||||
const searchBuilder = {
|
||||
add: 'Filtrar',
|
||||
condition: 'Comparador',
|
||||
clearAll: 'Resetear',
|
||||
delete: 'Eliminar',
|
||||
deleteTitle: 'Eliminar Titulo',
|
||||
data: 'Columna',
|
||||
left: 'Izquierda',
|
||||
leftTitle: 'Titulo Izquierdo',
|
||||
logicAnd: 'Y',
|
||||
logicOr: 'O',
|
||||
right: 'Derecha',
|
||||
rightTitle: 'Titulo Derecho',
|
||||
title: {
|
||||
0: 'Filtros',
|
||||
_: 'Filtros (%d)'
|
||||
},
|
||||
value: 'Opciones',
|
||||
valueJoiner: 'y'
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -0,0 +1,45 @@
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
Intl.NumberFormat.prototype.parse = function(valueString) {
|
||||
const format = new Intl.NumberFormat(this.resolvedOptions().locale);
|
||||
const parts = format.formatToParts(-12345.6);
|
||||
const numerals = Array.from({ length: 10 }).map((_, i) => format.format(i));
|
||||
const index = new Map(numerals.map((d, i) => [d, i]));
|
||||
_minusSign = new RegExp(`[${parts.find(d => d.type === 'minusSign').value}]`);
|
||||
_group = new RegExp(`[${parts.find(d => d.type === 'group').value}]`, 'g');
|
||||
_decimal = new RegExp(`[${parts.find(d => d.type === 'decimal').value}]`);
|
||||
_numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
||||
_index = d => index.get(d);
|
||||
|
||||
const DIRECTION_MARK = /\u061c|\u200e/g
|
||||
return +(
|
||||
valueString.trim()
|
||||
.replace(DIRECTION_MARK, '')
|
||||
.replace(_group, '')
|
||||
.replace(_decimal, '.')
|
||||
.replace(_numeral, _index)
|
||||
.replace(_minusSign, '-')
|
||||
)
|
||||
}
|
||||
Intl.NumberFormat.prototype.isLocale = function(stringValue) {
|
||||
const format = new Intl.NumberFormat(this.resolvedOptions().locale);
|
||||
const parts = format.formatToParts(-12345.6);
|
||||
const group = parts.find(d => d.type === 'group').value;
|
||||
const decimal = parts.find(d => d.type === 'decimal').value;
|
||||
|
||||
if (stringValue.includes(group)) {
|
||||
if (stringValue.includes(decimal)) {
|
||||
return stringValue.indexOf(group) < stringValue.indexOf(decimal)
|
||||
}
|
||||
if (stringValue.split(group).map(d => d.length).filter(d => d > 3).length > 0) {
|
||||
return false
|
||||
}
|
||||
return stringValue.split(group).length > 2;
|
||||
}
|
||||
if (stringValue.includes(decimal)) {
|
||||
return stringValue.split(decimal).length <= 2;
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,76 @@
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
if (typeof Intl.NumberFormat.isLocale === 'undefined' || typeof Intl.NumberFormat.isLocale !== 'function') {
|
||||
// Load Intl.NumberFormat custom methods
|
||||
@include('layout.body.scripts.number_format')
|
||||
}
|
||||
class NumberInput {
|
||||
input
|
||||
isRational
|
||||
outputLocale
|
||||
currentValue
|
||||
formatters
|
||||
|
||||
constructor({input, isRational, outputLocale}) {
|
||||
this.input = input
|
||||
this.isRational = isRational
|
||||
this.outputLocale = outputLocale || 'es-CL'
|
||||
|
||||
this.formatters = {}
|
||||
const locales = ['es-CL', 'en-US']
|
||||
locales.forEach(locale => {
|
||||
this.formatters[locale] = {
|
||||
rational: new Intl.NumberFormat(locale, {minimumFractionDigits: 2, maximumFractionDigits: 2}),
|
||||
integer: new Intl.NumberFormat(locale)
|
||||
}
|
||||
})
|
||||
|
||||
if (this.input.value !== '') {
|
||||
this.currentValue = this.process(this.input.value)
|
||||
this.input.value = this.format(this.currentValue)
|
||||
}
|
||||
}
|
||||
watch() {
|
||||
this.input.addEventListener('change', event => {
|
||||
this.currentValue = this.process(event.currentTarget.value)
|
||||
this.input.value = this.format(this.currentValue)
|
||||
})
|
||||
}
|
||||
process(stringValue) {
|
||||
if (stringValue === '') {
|
||||
return ''
|
||||
}
|
||||
if (typeof stringValue !== 'string') {
|
||||
return stringValue
|
||||
}
|
||||
return this.formatters[this.detectLocale(stringValue)][this.isRational ? 'rational' : 'integer'].parse(stringValue)
|
||||
}
|
||||
detectLocale(stringValue) {
|
||||
if (stringValue === '') {
|
||||
return ''
|
||||
}
|
||||
if (typeof stringValue !== 'string') {
|
||||
return stringValue
|
||||
}
|
||||
const outputFormat = this.formatters[this.outputLocale][this.isRational ? 'rational' : 'integer'].isLocale(stringValue)
|
||||
const otherFormats = Object.entries(this.formatters).filter(formatter => formatter[0] !== this.outputLocale).map(formatter => {
|
||||
return {
|
||||
locale: formatter[0],
|
||||
value: formatter[1][this.isRational ? 'rational' : 'integer'].isLocale(stringValue)
|
||||
}
|
||||
}).filter(formatter => formatter.value)
|
||||
|
||||
if (outputFormat) {
|
||||
return this.outputLocale
|
||||
}
|
||||
if (otherFormats.length > 0) {
|
||||
return otherFormats[0].locale
|
||||
}
|
||||
return 'en-US'
|
||||
}
|
||||
format(value) {
|
||||
return this.formatters[this.outputLocale][this.isRational ? 'rational' : 'integer'].format(value)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -28,7 +28,7 @@
|
||||
if (!(typeof digito === 'string' || digito instanceof String)) {
|
||||
digito = digito.toString()
|
||||
}
|
||||
return Rut.digitoVerificador(rut) === digito
|
||||
return Rut.digitoVerificador(rut).toString().toUpperCase() === digito.toUpperCase()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
6
app/resources/views/layout/body/scripts/stats.blade.php
Normal file
6
app/resources/views/layout/body/scripts/stats.blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
@prepend('page_scripts')
|
||||
<script src='https://unpkg.com/simple-statistics@7.8.8/dist/simple-statistics.min.js'></script>
|
||||
<script>
|
||||
const Stat = ss
|
||||
</script>
|
||||
@endprepend
|
@ -1,9 +1,9 @@
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
@hasSection('page_title')
|
||||
<title>Incoviba - @yield('page_title')</title>
|
||||
<title>Incoviba - @yield('page_title')</title>
|
||||
@else
|
||||
<title>Incoviba</title>
|
||||
<title>Incoviba</title>
|
||||
@endif
|
||||
<link rel="icon" href="{{$urls->images}}/Isotipo 16.png" />
|
||||
@include('layout.head.styles')
|
||||
|
@ -19,7 +19,7 @@
|
||||
@include('layout.body.scripts.cryptojs')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
function encryptPassword(password) {
|
||||
const passphrase = Math.floor(Math.random() * Date.now()).toString()
|
||||
const encrypted = CryptoJS.AES.encrypt(password, passphrase)
|
||||
|
14
app/resources/views/not_allowed.blade.php
Normal file
14
app/resources/views/not_allowed.blade.php
Normal file
@ -0,0 +1,14 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
405 - Método No Permitido
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<div class="ui message">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
No se ha encontrado la página solicitada para el método solicitado.
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
219
app/resources/views/proyectos/brokers.blade.php
Normal file
219
app/resources/views/proyectos/brokers.blade.php
Normal file
@ -0,0 +1,219 @@
|
||||
@extends('proyectos.brokers.base')
|
||||
|
||||
@section('brokers_content')
|
||||
<table id="brokers" class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>RUT</th>
|
||||
<th>Nombre</th>
|
||||
<th>Contacto</th>
|
||||
<th>Contratos</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui small tertiary green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach($brokers as $broker)
|
||||
<tr>
|
||||
<td class="top aligned">
|
||||
<span
|
||||
@if ($broker->data()?->legalName !== '')
|
||||
data-tooltip="{{ $broker->data()?->legalName }}" data-position="right center"
|
||||
@endif
|
||||
>
|
||||
{{$broker->rutFull()}}
|
||||
</span>
|
||||
</td>
|
||||
<td class="top aligned">
|
||||
<a href="{{ $urls->base }}/proyectos/broker/{{ $broker->rut }}">
|
||||
{{$broker->name}}
|
||||
<i class="angle right icon"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td class="top aligned">
|
||||
<span
|
||||
@if ($broker->data()?->representative?->email !== '' || $broker->data()?->representative?->phone !== '')
|
||||
data-tooltip="{{ ($broker->data()?->representative?->email !== '') ? "Email: " . $broker->data()?->representative?->email : '' }}{{ ($broker->data()?->representative?->phone !== '') ? ' Teléfono: ' . $broker->data()?->representative?->phone : '' }}" data-position="right center"
|
||||
@endif
|
||||
>
|
||||
{{ $broker->data()?->representative?->name }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="top aligned">
|
||||
<div class="ui list">
|
||||
@foreach($broker->contracts() as $contract)
|
||||
<div class="item">
|
||||
<a href="{{$urls->base}}/proyectos/broker/{{$broker->rut}}/contract/{{$contract->id}}" data-tooltip="{{$contract->current()->date->format('d-m-Y')}}" data-position="right center">
|
||||
{{$contract->project->descripcion}} ({{$format->percent($contract->commission, 2, true)}})
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</td>
|
||||
<td class="top aligned right aligned">
|
||||
<button class="ui small tertiary icon button edit_button" data-index="{{$broker->rut}}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button class="ui small tertiary red icon button remove_button" data-index="{{$broker->rut}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
@include('proyectos.brokers.add_modal')
|
||||
@include('proyectos.brokers.edit_modal')
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
function storeBrokers() {
|
||||
localStorage.setItem('brokers', '{!! json_encode(array_map(function($broker) {
|
||||
$arr = json_decode(json_encode($broker), true);
|
||||
array_walk_recursive($arr, function(&$val, $key) {
|
||||
if ($val === null) {
|
||||
$val = '';
|
||||
}
|
||||
});
|
||||
$arr['contracts'] = $broker->contracts();
|
||||
return $arr;
|
||||
}, $brokers)) !!}')
|
||||
}
|
||||
const brokersHandler = {
|
||||
ids: {
|
||||
buttons: {
|
||||
add: 'add_button',
|
||||
edit: 'edit_button',
|
||||
remove: 'remove_button'
|
||||
},
|
||||
modals: {
|
||||
add: '',
|
||||
edit: ''
|
||||
},
|
||||
forms: {
|
||||
add: '',
|
||||
edit: ''
|
||||
}
|
||||
},
|
||||
modals: {
|
||||
add: null,
|
||||
edit: null
|
||||
},
|
||||
events() {
|
||||
return {
|
||||
add: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
brokersHandler.actions().add()
|
||||
},
|
||||
edit: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
const broker_rut = parseInt(clickEvent.currentTarget.dataset.index)
|
||||
brokersHandler.actions().edit(broker_rut)
|
||||
},
|
||||
delete: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
const broker_rut = clickEvent.currentTarget.dataset.index
|
||||
brokersHandler.actions().delete(broker_rut)
|
||||
}
|
||||
}
|
||||
},
|
||||
buttonWatch() {
|
||||
document.getElementById(brokersHandler.ids.buttons.add).addEventListener('click', brokersHandler.events().add)
|
||||
Array.from(document.getElementsByClassName(brokersHandler.ids.buttons.edit)).forEach(button => {
|
||||
button.addEventListener('click', brokersHandler.events().edit)
|
||||
})
|
||||
Array.from(document.getElementsByClassName(brokersHandler.ids.buttons.remove)).forEach(button => {
|
||||
button.addEventListener('click', brokersHandler.events().delete)
|
||||
})
|
||||
},
|
||||
actions() {
|
||||
return {
|
||||
add: () => {
|
||||
this.modals.add.show()
|
||||
},
|
||||
edit: broker_rut => {
|
||||
const localData = JSON.parse(localStorage.getItem('brokers'))
|
||||
const broker = localData.find(broker => broker.rut === broker_rut)
|
||||
const data = {
|
||||
rut: broker_rut,
|
||||
name: broker.name,
|
||||
legal_name: broker.data?.legal_name || '',
|
||||
contact: broker.data?.representative?.name || '',
|
||||
email: broker.data?.representative?.email || '',
|
||||
phone: broker.data?.representative?.phone || '',
|
||||
address: broker.data?.representative?.address || '',
|
||||
contracts: broker.contracts
|
||||
}
|
||||
this.modals.edit.load(data)
|
||||
},
|
||||
delete: broker_rut => {
|
||||
brokersHandler.execute().delete(broker_rut)
|
||||
}
|
||||
}
|
||||
},
|
||||
execute() {
|
||||
return {
|
||||
add: data => {
|
||||
const url = '{{$urls->api}}/proyectos/brokers/add'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.append('brokers[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo agregar operador.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
},
|
||||
edit: data => {
|
||||
const url = '{{$urls->api}}/proyectos/brokers/edit'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.append('brokers[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo editar operador.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
},
|
||||
delete: broker_rut => {
|
||||
const url = '{{$urls->api}}/proyectos/broker/' + broker_rut
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo eliminar operador.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup(ids) {
|
||||
brokersHandler.ids = ids
|
||||
brokersHandler.buttonWatch()
|
||||
|
||||
this.modals.add = new AddModal(brokersHandler)
|
||||
this.modals.edit = new EditModal(brokersHandler)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
storeBrokers()
|
||||
brokersHandler.setup({
|
||||
buttons: {
|
||||
add: 'add_button',
|
||||
edit: 'edit_button',
|
||||
remove: 'remove_button',
|
||||
},
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
115
app/resources/views/proyectos/brokers/add_modal.blade.php
Normal file
115
app/resources/views/proyectos/brokers/add_modal.blade.php
Normal file
@ -0,0 +1,115 @@
|
||||
<div class="ui modal" id="add_broker_modal">
|
||||
<div class="header">
|
||||
Agregar Operador
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_broker_form">
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>RUT</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut" placeholder="RUT" maxlength="10" required />
|
||||
<div class="ui basic label">-<span id="digit"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="name" placeholder="Nombre" required />
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Razón Social</label>
|
||||
<input type="text" name="legal_name" placeholder="Razón Social" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Contacto</label>
|
||||
<input type="text" name="contact" placeholder="Contacto" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Correo</label>
|
||||
<input type="email" name="email" placeholder="Correo" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Teléfono</label>
|
||||
<input type="text" name="phone" placeholder="Teléfono" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Agregar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class AddModal {
|
||||
ids
|
||||
modal
|
||||
handler
|
||||
constructor(handler) {
|
||||
this.handler = handler
|
||||
this.ids = {
|
||||
modal: 'add_broker_modal',
|
||||
form: 'add_broker_form',
|
||||
digit: 'digit'
|
||||
}
|
||||
this.modal = $(`#${this.ids.modal}`)
|
||||
this.modal.modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById(this.ids.form)
|
||||
const data = {
|
||||
rut: form.querySelector('[name="rut"]').value.replace(/\D/g, ''),
|
||||
digit: Rut.digitoVerificador(form.querySelector('[name="rut"]').value),
|
||||
name: form.querySelector('[name="name"]').value,
|
||||
legal_name: form.querySelector('[name="legal_name"]').value,
|
||||
contact: form.querySelector('[name="contact"]').value || '',
|
||||
email: form.querySelector('[name="email"]').value || '',
|
||||
phone: form.querySelector('[name="phone"]').value || ''
|
||||
}
|
||||
this.handler.execute().add(data)
|
||||
}
|
||||
})
|
||||
this.modal.modal('hide')
|
||||
const value = document.querySelector(`#${this.ids.form} input[name="rut"]`).value
|
||||
this.update().digit(value)
|
||||
this.watch().rut()
|
||||
}
|
||||
update() {
|
||||
return {
|
||||
digit: value => {
|
||||
if (value.length > 3) {
|
||||
document.getElementById(this.ids.digit).textContent = Rut.digitoVerificador(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
watch() {
|
||||
return {
|
||||
rut: () => {
|
||||
document.querySelector(`#${this.ids.form} input[name="rut"]`).addEventListener('input', event => {
|
||||
const value = event.currentTarget.value
|
||||
this.update().digit(value)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
show() {
|
||||
this.modal.modal('show')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
22
app/resources/views/proyectos/brokers/base.blade.php
Normal file
22
app/resources/views/proyectos/brokers/base.blade.php
Normal file
@ -0,0 +1,22 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
@hasSection('brokers_title')
|
||||
Operadores - @yield('brokers_title')
|
||||
@else
|
||||
Operadores
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">
|
||||
@hasSection('brokers_header')
|
||||
Operador - @yield('brokers_header')
|
||||
@else
|
||||
Operadores
|
||||
@endif
|
||||
</h2>
|
||||
@yield('brokers_content')
|
||||
</div>
|
||||
@endsection
|
489
app/resources/views/proyectos/brokers/contracts/show.blade.php
Normal file
489
app/resources/views/proyectos/brokers/contracts/show.blade.php
Normal file
@ -0,0 +1,489 @@
|
||||
@extends('proyectos.brokers.base')
|
||||
|
||||
@section('brokers_title')
|
||||
{{ $contract->broker->name }} - {{ $contract->project->descripcion }}
|
||||
@endsection
|
||||
|
||||
@section('brokers_header')
|
||||
{{ $contract->broker->name }} - {{ $contract->project->descripcion }}
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.stats')
|
||||
|
||||
@prepend('page_scripts')
|
||||
<script>
|
||||
class TableHandler {
|
||||
commission
|
||||
constructor(commission) {
|
||||
this.commission = commission
|
||||
}
|
||||
draw() {}
|
||||
prices(units) {
|
||||
return units.map(unit => {
|
||||
let price = unit.valor ?? (unit.precio?.valor ?? 0)
|
||||
const broker = price / (1 - this.commission)
|
||||
const promotions = unit.promotions?.map(promotion => {
|
||||
if (promotion.type === 1) {
|
||||
return {
|
||||
name: promotion.description,
|
||||
type: promotion.type,
|
||||
amount: promotion.amount,
|
||||
final: broker + promotion.amount
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: promotion.description,
|
||||
type: promotion.type,
|
||||
amount: promotion.amount,
|
||||
final: broker / (1 - promotion.amount)
|
||||
}
|
||||
}) ?? []
|
||||
return {
|
||||
id: unit.id,
|
||||
base: price,
|
||||
commission: this.commission,
|
||||
broker,
|
||||
promotions
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
class GroupedTableHandler extends TableHandler {
|
||||
promotions = {
|
||||
names: new Set(),
|
||||
values: []
|
||||
}
|
||||
process() {
|
||||
return {
|
||||
prices: prices => {
|
||||
let promotions = {}
|
||||
prices.map(price => price.promotions).forEach(promotionArray => {
|
||||
promotionArray.forEach(p => {
|
||||
if (!Object.hasOwn(promotions, p.name)) {
|
||||
promotions[p.name] = {
|
||||
name: p.name,
|
||||
type: p.type,
|
||||
amount: [],
|
||||
final: []
|
||||
}
|
||||
}
|
||||
promotions[p.name].amount.push(p.amount)
|
||||
promotions[p.name].final.push(p.final)
|
||||
})
|
||||
})
|
||||
return promotions
|
||||
},
|
||||
promotions: () => {
|
||||
return {
|
||||
names: promotions => {
|
||||
Object.keys(promotions).forEach(name => {
|
||||
this.add().promotion().name(name)
|
||||
})
|
||||
},
|
||||
values: ({promotions, formatters}) => {
|
||||
const temp = Object.values(promotions)
|
||||
if (temp.length > 0) {
|
||||
const data = temp.map(p => {
|
||||
return {
|
||||
name: p.name,
|
||||
type: p.type,
|
||||
amount: {
|
||||
min: Math.min(...p.amount),
|
||||
max: Math.max(...p.amount),
|
||||
desv: Stat.standardDeviation(p.amount),
|
||||
mean: Stat.mean(p.amount)
|
||||
},
|
||||
final: {
|
||||
min: Math.min(...p.final),
|
||||
max: Math.max(...p.final),
|
||||
desv: Stat.standardDeviation(p.final),
|
||||
mean: Stat.mean(p.final)
|
||||
}
|
||||
}
|
||||
})
|
||||
this.add().promotion().values({promotions: data, formatters})
|
||||
return
|
||||
}
|
||||
this.promotions.values.push([])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add() {
|
||||
return {
|
||||
promotion: () => {
|
||||
return {
|
||||
name: name => {
|
||||
this.promotions.names.add(name)
|
||||
},
|
||||
values: ({promotions, formatters}) => {
|
||||
this.promotions.values.push(promotions.map(promotion => {
|
||||
const amount_tooltip = [
|
||||
`Min: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.min) : formatters.percent.format(promotion.amount.min)}`,
|
||||
`Max: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.max) : formatters.percent.format(promotion.amount.max)}`,
|
||||
`Desv: ${promotion.type === 1 ? 'UF ' + formatters.ufs.format(promotion.amount.desv) : formatters.percent.format(promotion.amount.desv)}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const final_tooltip = [
|
||||
`Min: UF ${formatters.ufs.format(promotion.final.min)}`,
|
||||
`Max: UF ${formatters.ufs.format(promotion.final.max)}`,
|
||||
`Desv: UF ${formatters.ufs.format(promotion.final.desv)}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
return {
|
||||
name: promotion.name,
|
||||
value: [
|
||||
`<td class="right aligned"><span data-tooltip="${amount_tooltip}" data-position="right center" data-variation="wide multiline">${promotion.type === 1 ? formatters.ufs.format(promotion.amount.mean) : formatters.percent.format(promotion.amount.mean)}</td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${final_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(promotion.final.mean)}</td></td>`,
|
||||
].join("\n")
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
build() {
|
||||
return {
|
||||
promotions: (table, tbody) => {
|
||||
if (this.promotions.names.size > 0) {
|
||||
const title = document.getElementById(this.ids.promotions)
|
||||
title.innerHTML = this.promotions.names.size > 0 ? Array.from(this.promotions.names)[0] : ''
|
||||
title.setAttribute('colspan', '2')
|
||||
if (this.promotions.names.size > 1) {
|
||||
const thead = table.querySelector('thead')
|
||||
Array.from(this.promotions.names).slice(1).forEach(name => {
|
||||
thead.insertAdjacentHTML('beforeend', `<th class="right aligned" style="text-decoration: overline" colspan="2">${name}</th>`)
|
||||
})
|
||||
}
|
||||
const trs = tbody.querySelectorAll('tr')
|
||||
this.promotions.values.forEach((row, i) => {
|
||||
const tr = trs[i]
|
||||
const td = tr.querySelector('td.promotions')
|
||||
if (row.length === 0) {
|
||||
td.setAttribute('colspan', 2 * this.promotions.names.size)
|
||||
return
|
||||
}
|
||||
td.remove()
|
||||
this.promotions.names.forEach(name => {
|
||||
const index = row.findIndex(r => r.name === name)
|
||||
if (index === -1) {
|
||||
tr.insertAdjacentHTML('beforeend', '<td colspan="2"></td>')
|
||||
return
|
||||
}
|
||||
tr.insertAdjacentHTML('beforeend', row[index].value)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endprepend
|
||||
|
||||
@section('brokers_content')
|
||||
<div class="ui statistic">
|
||||
<div class="value">{{ $format->percent($contract->commission ?? 0, 2, true) }}</div>
|
||||
<div class="label">
|
||||
Comisión desde {{ $contract->current()?->date?->format('d/m/Y') }}
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="ui card">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
Promociones Aplicadas
|
||||
</div>
|
||||
<div class="description">
|
||||
@if (count($contract->promotions()) === 0)
|
||||
- Ninguna
|
||||
@else
|
||||
<div class="ui list">
|
||||
@foreach ($contract->promotions() as $promotion)
|
||||
<div class="item">
|
||||
{{ $promotion->description }} {{ $format->percent($promotion->amount, 2, true) }} {{ ucwords($promotion->type->name()) }}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui very basic segment">
|
||||
<div class="ui active inline loader" id="loader"></div>
|
||||
<div class="ui indicating progress" id="load_progress">
|
||||
<div class="bar">
|
||||
<div class="progress"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="results">
|
||||
<div class="ui top attached tabular menu">
|
||||
<a class="item active" data-tab="tipos">Tipos</a>
|
||||
<a class="item" data-tab="lineas">Líneas</a>
|
||||
<a class="item" data-tab="unidades">Unidades</a>
|
||||
</div>
|
||||
<div class="ui top attached indicating progress" id="values_progress">
|
||||
<div class="bar"></div>
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic fitted segment active" data-tab="tipos">
|
||||
@include('proyectos.brokers.contracts.show.tipo')
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic fitted segment" data-tab="lineas">
|
||||
@include('proyectos.brokers.contracts.show.linea')
|
||||
</div>
|
||||
<div class="ui bottom attached tab basic fitted segment" data-tab="unidades">
|
||||
@include('proyectos.brokers.contracts.show.unidades')
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.datatables')
|
||||
@include('layout.body.scripts.datatables.searchbuilder')
|
||||
@include('layout.body.scripts.datatables.buttons')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const units = {
|
||||
ids: {
|
||||
units: '',
|
||||
loader: '',
|
||||
progress: '',
|
||||
load_progress: ''
|
||||
},
|
||||
data: {
|
||||
project_id: {{ $contract->project->id }},
|
||||
commission: {{ $contract->commission }},
|
||||
units: []
|
||||
},
|
||||
formatters: {
|
||||
ufs: new Intl.NumberFormat('es-CL', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
||||
percent: new Intl.NumberFormat('es-CL', { style: 'percent', minimumFractionDigits: 2 })
|
||||
},
|
||||
handlers: {
|
||||
tipo: null,
|
||||
linea: null,
|
||||
unit: null
|
||||
},
|
||||
get() {
|
||||
return {
|
||||
units: () => {
|
||||
const url = `{{ $urls->api }}/proyecto/${units.data.project_id}/unidades`
|
||||
return APIClient.fetch(url).then(response => response.json()).then(json => {
|
||||
if (json.unidades.length === 0) {
|
||||
console.error(json.errors)
|
||||
return
|
||||
}
|
||||
units.data.units = []
|
||||
Object.entries(json.unidades).forEach(([tipo, unidades]) => {
|
||||
units.data.units = [...units.data.units, ...unidades]
|
||||
})
|
||||
})
|
||||
},
|
||||
promotions: progress_bar => {
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyectos/broker/{{ $contract->broker->rut }}/contract/{{ $contract->id }}/promotions`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.unidades.length === 0) {
|
||||
return
|
||||
}
|
||||
json.unidades.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].promotions = unidad.promotions
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
prices: progress_bar => {
|
||||
/*const unsold = [...units.data.units.filter(unit => !unit.sold), ...units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')]
|
||||
const current_total = progress_bar.progress('get total')
|
||||
progress_bar.progress('set total', current_total + unsold.length)*/
|
||||
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyecto/{{ $contract->project->id }}/unidades/precios`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.precios.length === 0) {
|
||||
return
|
||||
}
|
||||
json.precios.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].precio = unidad.precio
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
values: progress_bar => {
|
||||
const sold = units.data.units.filter(unit => unit.sold && unit.proyecto_tipo_unidad.tipo_unidad.descripcion === 'departamento')
|
||||
progress_bar.progress('set total', sold.length)
|
||||
|
||||
const chunkSize = 10
|
||||
const chunks = []
|
||||
for (let i = 0; i < sold.length; i += chunkSize) {
|
||||
chunks.push(sold.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/ventas/by/unidades`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.ventas.length === 0) {
|
||||
return
|
||||
}
|
||||
json.ventas.forEach(({unidad_id, venta}) => {
|
||||
const unidades = venta.propiedad.unidades
|
||||
const otras_unidades = unidades.filter(unit => unit.id !== parseInt(unidad_id) && unit.proyecto_tipo_unidad.tipo_unidad.descripcion !== 'departamento')
|
||||
const departamentos = unidades.filter(unit => unit.proyecto_tipo_unidad.tipo_unidad.descripcion === 'departamento' && unit.id !== parseInt(unidad_id))
|
||||
const precios = otras_unidades.map(unit => {
|
||||
const idx = units.data.units.findIndex(u => u.id === unit.id)
|
||||
return units.data.units[idx].precio?.valor ?? 0
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
if (departamentos.length === 0) {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === parseInt(unidad_id))
|
||||
units.data.units[idx].valor = venta.valor - precios
|
||||
units.data.units[idx].venta = venta
|
||||
return
|
||||
}
|
||||
const sum_precios = departamentos.map(departamento => {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
return units.data.units[idx].precio
|
||||
}).reduce((sum, precio) => sum + precio, 0)
|
||||
departamentos.forEach(departamento => {
|
||||
const idx = units.data.units.findIndex(unit => unit.id === departamento.id)
|
||||
const saldo = venta.valor - precios
|
||||
units.data.units[idx].valor = saldo / sum_precios * departamento.precio
|
||||
units.data.units[idx].venta = venta
|
||||
})
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
sold: progress_bar => {
|
||||
const chunkSize = 100
|
||||
const chunks = []
|
||||
for (let i = 0; i < units.data.units.length; i += chunkSize) {
|
||||
chunks.push(units.data.units.slice(i, i + chunkSize).map(u => u.id))
|
||||
}
|
||||
const promises = []
|
||||
const url = `{{ $urls->api }}/proyecto/{{ $contract->project->id }}/unidades/estados`
|
||||
const method = 'post'
|
||||
chunks.forEach(chunk => {
|
||||
const body = new FormData()
|
||||
chunk.forEach(id => body.append('unidad_ids[]', id))
|
||||
promises.push(APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
progress_bar.progress('increment', json.input.unidad_ids.length)
|
||||
if (json.estados.length === 0) {
|
||||
return
|
||||
}
|
||||
json.estados.forEach(unidad => {
|
||||
const idx = units.data.units.findIndex(u => u.id === parseInt(unidad.id))
|
||||
units.data.units[idx].sold = unidad.sold
|
||||
})
|
||||
}))
|
||||
})
|
||||
return Promise.all(promises)
|
||||
},
|
||||
}
|
||||
},
|
||||
draw() {
|
||||
return {
|
||||
units: () => {
|
||||
units.handlers.units.draw({units: units.data.units, formatters: units.formatters})
|
||||
},
|
||||
tipos: () => {
|
||||
units.handlers.tipo.draw({units: units.data.units, formatters: units.formatters})
|
||||
},
|
||||
lineas: () => {
|
||||
units.handlers.lineas.draw({units: units.data.units, formatters: units.formatters})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup(ids) {
|
||||
units.ids = ids
|
||||
|
||||
units.handlers.tipo = new TipoTable(units.data.commission)
|
||||
units.handlers.lineas = new LineasTable(units.data.commission)
|
||||
units.handlers.units = new UnitsTable(units.data.commission)
|
||||
|
||||
$(`#${units.ids.results}`).find('.tabular.menu .item').tab({
|
||||
onVisible: function(tabPath) {
|
||||
if (tabPath !== 'unidades') {
|
||||
return
|
||||
}
|
||||
$(this.querySelector('table')).DataTable().columns.adjust().draw()
|
||||
this.querySelector('table').style.width = ''
|
||||
}
|
||||
})
|
||||
document.getElementById(units.ids.results).style.visibility = 'hidden'
|
||||
document.getElementById(units.ids.progress).style.visibility = 'hidden'
|
||||
document.getElementById(units.ids.load_progress).style.visibility = 'hidden'
|
||||
|
||||
const loader = $(`#${units.ids.loader}`)
|
||||
|
||||
units.get().units().then(() => {
|
||||
document.getElementById(units.ids.load_progress).style.visibility = 'visible'
|
||||
|
||||
const units_length = units.data.units.length
|
||||
const progress_bar = $(`#${units.ids.load_progress}`)
|
||||
progress_bar.progress({ total: units_length * 3 })
|
||||
|
||||
loader.hide()
|
||||
|
||||
units.get().promotions(progress_bar).then(() => {
|
||||
units.get().sold(progress_bar).then(() => {
|
||||
units.get().prices(progress_bar).then(() => {
|
||||
document.getElementById(units.ids.results).style.visibility = 'visible'
|
||||
|
||||
loader.parent().remove()
|
||||
|
||||
units.draw().units()
|
||||
units.draw().tipos()
|
||||
units.draw().lineas()
|
||||
|
||||
document.getElementById(units.ids.progress).style.visibility = 'visible'
|
||||
const progress_bar = $(`#${units.ids.progress}`)
|
||||
progress_bar.progress()
|
||||
|
||||
units.get().values(progress_bar).then(() => {
|
||||
document.getElementById(units.ids.progress).remove()
|
||||
|
||||
units.draw().units()
|
||||
units.draw().tipos()
|
||||
units.draw().lineas()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(function () {
|
||||
units.setup({results: 'results', loader: 'loader', progress: 'values_progress', load_progress: 'load_progress'})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,91 @@
|
||||
<table class="ui table" id="lineas">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th class="center aligned">Línea</th>
|
||||
<th class="center aligned">Orientación</th>
|
||||
<th class="center aligned">Cantidad</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Base</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Comisión</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
||||
<th class="center aligned" style="text-decoration: overline" id="linea_promociones">Promociones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class LineasTable extends GroupedTableHandler {
|
||||
ids = {
|
||||
lineas: 'lineas',
|
||||
promotions: 'linea_promociones'
|
||||
}
|
||||
constructor(commission) {
|
||||
super(commission)
|
||||
}
|
||||
draw({units, formatters}) {
|
||||
const table = document.getElementById(this.ids.lineas)
|
||||
const tbody = table.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
const lineas = Object.groupBy(units, unit => {
|
||||
return [unit.proyecto_tipo_unidad.tipo_unidad.descripcion, unit.proyecto_tipo_unidad.nombre, unit.orientacion]
|
||||
})
|
||||
this.promotions.names = new Set()
|
||||
this.promotions.values = []
|
||||
Object.entries(lineas).sort(([linea1, unidades1], [linea2, unidades2]) => {
|
||||
const split1 = linea1.split(',')
|
||||
const split2 = linea2.split(',')
|
||||
const ct = unidades1[0].proyecto_tipo_unidad.tipo_unidad.orden - unidades2[0].proyecto_tipo_unidad.tipo_unidad.orden
|
||||
if (ct === 0) {
|
||||
const cl = split1[1].localeCompare(split2[1])
|
||||
if (cl === 0) {
|
||||
return split1[2].localeCompare(split2[2])
|
||||
}
|
||||
return cl
|
||||
}
|
||||
return ct
|
||||
}).forEach(([linea, unidades]) => {
|
||||
const parts = linea.split(',')
|
||||
const tipo = parts[0]
|
||||
const orientacion = parts[2]
|
||||
const prices = this.prices(unidades)
|
||||
|
||||
const base_tooltip = [
|
||||
`Min: UF ${formatters.ufs.format(Math.min(...prices.map(p => p.base)))}`,
|
||||
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
|
||||
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const commission_tooltip = [
|
||||
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
|
||||
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
|
||||
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const broker_tooltip = [
|
||||
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
|
||||
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
|
||||
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
|
||||
const promotions = this.process().prices(prices)
|
||||
this.process().promotions().names(promotions)
|
||||
this.process().promotions().values({promotions, formatters})
|
||||
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td class="center aligned"><span data-tooltip="${unidades[0].proyecto_tipo_unidad.tipologia}" data-position="right center">${parts[1]}</span></td>`,
|
||||
`<td class="center aligned">${orientacion}</td>`,
|
||||
`<td class="center aligned">${unidades.length}</td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
|
||||
`<td class="right aligned promotions"></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
this.build().promotions(table, tbody)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,71 @@
|
||||
<table class="ui table" id="tipos">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tipo</th>
|
||||
<th class="center aligned">Cantidad</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Base</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Comisión</th>
|
||||
<th class="right aligned" style="text-decoration: overline">Precio Operador</th>
|
||||
<th class="center aligned" style="text-decoration: overline" id="tipo_promociones">Promociones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class TipoTable extends GroupedTableHandler {
|
||||
ids = {
|
||||
tipos: 'tipos',
|
||||
promotions: 'tipo_promociones'
|
||||
}
|
||||
constructor(commission) {
|
||||
super(commission)
|
||||
}
|
||||
draw({units, formatters}) {
|
||||
const table = document.getElementById(this.ids.tipos)
|
||||
const tbody = table.querySelector('tbody')
|
||||
tbody.innerHTML = ''
|
||||
const groups = Object.groupBy(units, unit => {
|
||||
return unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
})
|
||||
this.promotions.names = new Set()
|
||||
this.promotions.values = []
|
||||
Object.entries(groups).forEach(([tipo, unidades]) => {
|
||||
const prices = this.prices(unidades)
|
||||
const base_tooltip = [
|
||||
`Min: UF ${formatters.ufs.format(Math.min(...prices.map(p => p.base)))}`,
|
||||
`Max: UF ${formatters.ufs.format(Math.max(...prices.map(p => p.base)))}`,
|
||||
`Desv: UF ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.base)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const commission_tooltip = [
|
||||
`Min: ${formatters.percent.format(Math.min(...prices.map(p => p.commission)))}`,
|
||||
`Max: ${formatters.percent.format(Math.max(...prices.map(p => p.commission)))}`,
|
||||
`Desv: ${formatters.percent.format(Stat.standardDeviation(prices.map(p => p.commission)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
const broker_tooltip = [
|
||||
`Min: ${formatters.ufs.format(Math.min(...prices.map(p => p.broker)))}`,
|
||||
`Max: ${formatters.ufs.format(Math.max(...prices.map(p => p.broker)))}`,
|
||||
`Desv: ${formatters.ufs.format(Stat.standardDeviation(prices.map(p => p.broker)))}`
|
||||
].join("\n").replaceAll(' ', ' ')
|
||||
|
||||
const promotions = this.process().prices(prices)
|
||||
this.process().promotions().names(promotions)
|
||||
this.process().promotions().values({promotions, formatters})
|
||||
|
||||
tbody.innerHTML += [
|
||||
`<tr>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td class="center aligned">${unidades.length}</td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${base_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.base)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${commission_tooltip}" data-position="right center" data-variation="wide multiline">${formatters.percent.format(Stat.mean(prices.map(p => p.commission)))}</span></td>`,
|
||||
`<td class="right aligned"><span data-tooltip="${broker_tooltip}" data-position="right center" data-variation="wide multiline">UF ${formatters.ufs.format(Stat.mean(prices.map(p => p.broker)))}</span></td>`,
|
||||
`<td class="right aligned promotions"></td>`,
|
||||
`</tr>`
|
||||
].join("\n")
|
||||
})
|
||||
this.build().promotions(table, tbody)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,254 @@
|
||||
<table class="ui table" id="unidades">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Estado</th>
|
||||
<th>Tipo</th>
|
||||
<th>Tipo Order</th>
|
||||
<th class="right aligned">Unidad</th>
|
||||
<th>Unidad Orden</th>
|
||||
<th>Tipología</th>
|
||||
<th>Piso</th>
|
||||
<th>Orientación</th>
|
||||
<th>m² Interior</th>
|
||||
<th>m² Terraza</th>
|
||||
<th>m² Vendibles</th>
|
||||
<th>m² Total</th>
|
||||
<th class="right aligned">Precio Base</th>
|
||||
<th class="right aligned">Comisión</th>
|
||||
<th class="right aligned">Precio Operador</th>
|
||||
<th class="right aligned">UF/m²</th>
|
||||
<th class="center aligned" id="unit_promotions">Promociones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class UnitsTable extends TableHandler {
|
||||
ids = {
|
||||
units: 'unidades',
|
||||
}
|
||||
columns = [
|
||||
'estado',
|
||||
'tipo',
|
||||
'tipo_order',
|
||||
'unidad',
|
||||
'unidad_order',
|
||||
'tipologia',
|
||||
'piso',
|
||||
'orientacion',
|
||||
'metros_interior',
|
||||
'metros_terraza',
|
||||
'metros',
|
||||
'metros_total',
|
||||
'precio_base',
|
||||
'commission',
|
||||
'precio_operador',
|
||||
'UF/m²',
|
||||
'promociones',
|
||||
]
|
||||
set = {
|
||||
table: false,
|
||||
titles: false
|
||||
}
|
||||
table
|
||||
constructor(commission) {
|
||||
super(commission)
|
||||
}
|
||||
setup() {
|
||||
return {
|
||||
titles: promotions_names => {
|
||||
if (this.set.titles || promotions_names.size === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const nameArray = Array.from(promotions_names)
|
||||
|
||||
this.columns.pop()
|
||||
this.columns.push(`${nameArray[0].toLowerCase().replaceAll(' ', '_')}.amount`)
|
||||
this.columns.push(`${nameArray[0].toLowerCase().replaceAll(' ', '_')}.final`)
|
||||
|
||||
const table = document.getElementById(this.ids.units)
|
||||
const thead = table.querySelector('thead')
|
||||
const tr = thead.querySelector('tr')
|
||||
const th = tr.querySelector('th#unit_promotions')
|
||||
th.innerHTML = `${nameArray[0]}<br />Porcentaje`
|
||||
tr.insertAdjacentHTML('beforeend', `<th class="right aligned">${nameArray[0]}<br />Precio Final</th>`)
|
||||
|
||||
if (promotions_names.size > 1) {
|
||||
nameArray.slice(1).forEach(name => {
|
||||
this.columns.push(`${name.toLowerCase().replaceAll(' ', '_')}.amount`)
|
||||
this.columns.push(`${name.toLowerCase().replaceAll(' ', '_')}.final`)
|
||||
|
||||
tr.insertAdjacentHTML('beforeend', `<th class="right aligned">${name}<br />Porcentaje</th>`)
|
||||
tr.insertAdjacentHTML('beforeend', `<th class="right aligned">${name}<br />Precio Final</th>`)
|
||||
})
|
||||
}
|
||||
this.set.titles = true
|
||||
},
|
||||
table: () => {
|
||||
if (typeof this.table !== 'undefined' || this.set.table) {
|
||||
return
|
||||
}
|
||||
|
||||
const dto = structuredClone(datatables_defaults)
|
||||
dto.pageLength = 100
|
||||
dto.columnDefs = [
|
||||
{
|
||||
target: ['tipo_order', 'unidad_order', 'tipologia', 'piso', 'orientacion', 'metros'].map(column => this.columns.indexOf(column)),
|
||||
visible: false
|
||||
},
|
||||
{
|
||||
target: ['tipo'].map(column => this.columns.indexOf(column)),
|
||||
orderData: ['tipo_order'].map(column => this.columns.indexOf(column)),
|
||||
},
|
||||
{
|
||||
target: ['unidad'].map(column => this.columns.indexOf(column)),
|
||||
orderData: ['unidad_order'].map(column => this.columns.indexOf(column)),
|
||||
},
|
||||
{
|
||||
target: ['unidad', 'precio_base', 'commission', 'precio_operador', 'UF/m²', 'porcentaje', 'precio_final']
|
||||
.map(column => this.columns.indexOf(column)),
|
||||
className: 'dt-right right aligned'
|
||||
}
|
||||
]
|
||||
dto.order = ['tipo_order', 'unidad_order'].map(column => [this.columns.indexOf(column), 'asc'])
|
||||
dto.language.searchBuilder = searchBuilder
|
||||
const exportColumns = ['tipo', 'unidad', 'tipologia', 'piso', 'orientacion', 'metros_interior', 'metros_terraza', 'metros', 'metros_total', 'precio_operador', 'promociones']
|
||||
if (typeof this.columns['promotions'] === 'undefined') {
|
||||
exportColumns.pop()
|
||||
this.columns.slice(this.columns.indexOf('UF/m²')+1).forEach(name => {
|
||||
exportColumns.push(name)
|
||||
})
|
||||
}
|
||||
dto.layout = {
|
||||
top1Start: {
|
||||
searchBuilder: {
|
||||
columns: this.columns.filter(column => !['tipo_order', 'unidad_order'].includes(column))
|
||||
.map(column => this.columns.indexOf(column)),
|
||||
}
|
||||
},
|
||||
top1End: {
|
||||
buttons: [
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
className: 'green',
|
||||
text: 'Exportar a Excel <i class="file excel icon"></i>',
|
||||
title: 'Lista de Precios - {{ $contract->broker->name }} - {{ $contract->project->descripcion }} - {{ (new DateTime())->format('Y-m-d') }}',
|
||||
download: 'open',
|
||||
exportOptions: {
|
||||
columns: exportColumns
|
||||
.map(column => this.columns.indexOf(column)),
|
||||
rows: (idx, data, node) => {
|
||||
return data[this.columns.indexOf('estado')] === 'Libre'
|
||||
},
|
||||
format: {
|
||||
body: (data, row, columnIdx, node) => {
|
||||
if (typeof data === 'string' && data.includes('<span')) {
|
||||
return data.replace(/<span.*>(.*)<\/span>/, '$1')
|
||||
}
|
||||
if (typeof data === 'string' && data.includes('UF ')) {
|
||||
return data.replace('UF ', '').replaceAll('.', '').replaceAll(',', '.')
|
||||
}
|
||||
const formatColumns = ['metros', 'metros_interior', 'metros_terraza', 'metros_total']
|
||||
if (this.set.titles) {
|
||||
this.columns.filter(column => column.includes('.amount') || column.includes('.final')).forEach(name => {
|
||||
formatColumns.push(name)
|
||||
})
|
||||
}
|
||||
if (formatColumns.map(column => this.columns.indexOf(column)).includes(columnIdx)) {
|
||||
return data.replaceAll('.', '').replaceAll(',', '.')
|
||||
}
|
||||
return data
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
this.table = $(`#${this.ids.units}`).DataTable(dto)
|
||||
|
||||
this.set.table = true
|
||||
}
|
||||
}
|
||||
}
|
||||
draw({units, formatters}) {
|
||||
const prices = this.prices(units)
|
||||
|
||||
const promotions_names = new Set()
|
||||
const tableData = []
|
||||
units.forEach(unidad => {
|
||||
const tipo = unidad.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
const price = prices.find(p => p.id === unidad.id)
|
||||
|
||||
let promotions = []
|
||||
price.promotions.forEach(p => {
|
||||
if (Object.hasOwn(promotions, p.name)) {
|
||||
return
|
||||
}
|
||||
promotions[p.name] = {
|
||||
name: p.name,
|
||||
type: p.type,
|
||||
amount: p.type === 1 ? 'UF ' + formatters.ufs.format(p.amount) : formatters.percent.format(p.amount),
|
||||
final: `UF ${formatters.ufs.format(p.final)}`
|
||||
}
|
||||
})
|
||||
|
||||
Object.keys(promotions).forEach(name => {
|
||||
promotions_names.add(name)
|
||||
})
|
||||
const temp = Object.values(promotions)
|
||||
|
||||
const data = [
|
||||
unidad.sold ? `<span class="ui yellow text">Vendida</span>` : 'Libre',
|
||||
tipo.charAt(0).toUpperCase() + tipo.slice(1),
|
||||
unidad.proyecto_tipo_unidad.tipo_unidad.orden,
|
||||
unidad.sold && unidad.venta ? `<a href="{{ $urls->base }}/venta/${unidad.venta?.id }" data-tooltip="Valor Promesa: UF ${formatters.ufs.format(unidad.venta?.valor ?? 0)}" data-position="left center">${unidad.descripcion}</a>` : unidad.descripcion,
|
||||
unidad.descripcion.padStart(4, '0'),
|
||||
unidad.proyecto_tipo_unidad.tipologia,
|
||||
unidad.piso,
|
||||
unidad.orientacion,
|
||||
formatters.ufs.format(unidad.proyecto_tipo_unidad.util) ?? 0,
|
||||
formatters.ufs.format(unidad.proyecto_tipo_unidad.terraza) ?? 0,
|
||||
formatters.ufs.format(unidad.proyecto_tipo_unidad.vendible) ?? 0,
|
||||
formatters.ufs.format(unidad.proyecto_tipo_unidad.superficie) ?? 0,
|
||||
'UF ' + formatters.ufs.format(price.base ?? 0),
|
||||
formatters.percent.format(price.commission ?? 0),
|
||||
'UF ' + formatters.ufs.format(price.broker ?? 0),
|
||||
formatters.ufs.format(price.broker / unidad.proyecto_tipo_unidad.vendible),
|
||||
''
|
||||
]
|
||||
|
||||
if (temp.length > 0) {
|
||||
data.pop()
|
||||
temp.forEach((p, i) => {
|
||||
data.push(p.amount)
|
||||
data.push(p.final)
|
||||
})
|
||||
} else {
|
||||
if (promotions_names.size > 0) {
|
||||
Array.from(promotions_names).forEach(name => {
|
||||
data.push('')
|
||||
data.push('')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
tableData.push(data)
|
||||
})
|
||||
|
||||
this.setup().titles(promotions_names)
|
||||
this.setup().table()
|
||||
|
||||
const table = this.table
|
||||
table.clear()
|
||||
|
||||
table.rows.add(tableData)
|
||||
table.draw()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
113
app/resources/views/proyectos/brokers/edit_modal.blade.php
Normal file
113
app/resources/views/proyectos/brokers/edit_modal.blade.php
Normal file
@ -0,0 +1,113 @@
|
||||
<div class="ui modal" id="edit_broker_modal">
|
||||
<div class="header">
|
||||
Editar Operador
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="edit_broker_form">
|
||||
<input type="hidden" name="broker_rut" value="" />
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Rut</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="rut" placeholder="Rut" value="" disabled />
|
||||
<div class="ui basic label">-<span id="edit_digit"></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="name" placeholder="Nombre" value="" />
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Razón Social</label>
|
||||
<input type="text" name="legal_name" placeholder="Razón Social" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Contacto</label>
|
||||
<input type="text" name="contact" placeholder="Contacto" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Correo</label>
|
||||
<input type="email" name="email" placeholder="Correo" value="" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Teléfono</label>
|
||||
<input type="text" name="phone" placeholder="Teléfono" value="" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Guardar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class EditModal
|
||||
{
|
||||
ids
|
||||
modal
|
||||
handler
|
||||
data
|
||||
|
||||
constructor(handler)
|
||||
{
|
||||
this.handler = handler
|
||||
this.ids = {
|
||||
modal: 'edit_broker_modal',
|
||||
form: 'edit_broker_form',
|
||||
digit: 'edit_digit',
|
||||
}
|
||||
this.modal = $(`#${this.ids.modal}`)
|
||||
this.modal.modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById(this.ids.form)
|
||||
const broker_rut = form.querySelector('[name="broker_rut"]').value
|
||||
const data = {
|
||||
rut: form.querySelector('[name="rut"]').value.replace(/\D/g, ''),
|
||||
name: form.querySelector('[name="name"]').value,
|
||||
contact: form.querySelector('[name="contact"]').value || '',
|
||||
legal_name: form.querySelector('[name="legal_name"]').value,
|
||||
email: form.querySelector('[name="email"]').value || '',
|
||||
phone: form.querySelector('[name="phone"]').value || ''
|
||||
}
|
||||
this.handler.execute().edit(data)
|
||||
}
|
||||
})
|
||||
this.modal.modal('hide')
|
||||
}
|
||||
load(data) {
|
||||
this.data = data
|
||||
const form = document.getElementById(this.ids.form)
|
||||
form.querySelector('input[name="broker_rut"]').value = data.rut
|
||||
form.querySelector('input[name="rut"]').value = data.rut
|
||||
form.querySelector('input[name="name"]').value = data.name
|
||||
form.querySelector('input[name="legal_name"]').value = data.legal_name
|
||||
form.querySelector('input[name="contact"]').value = data.contact
|
||||
form.querySelector('input[name="email"]').value = data.email
|
||||
form.querySelector('input[name="phone"]').value = data.phone
|
||||
this.update().digit(data.rut)
|
||||
this.modal.modal('show')
|
||||
}
|
||||
update() {
|
||||
return {
|
||||
digit: value => {
|
||||
document.getElementById(this.ids.digit).textContent = Rut.digitoVerificador(value)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
52
app/resources/views/proyectos/brokers/proyectos.blade.php
Normal file
52
app/resources/views/proyectos/brokers/proyectos.blade.php
Normal file
@ -0,0 +1,52 @@
|
||||
<div class="ui top attached right aligned basic segment">
|
||||
<button type="button" class="ui mini tertiary icon button" id="refresh_button">
|
||||
<i class="sync alternate icon"></i>
|
||||
</button>
|
||||
<button type="button" class="ui mini tertiary icon button" id="up_button">
|
||||
<i class="arrow up icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
<table class="ui table" id="projects">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Proyecto</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($projects as $project)
|
||||
<tr data-index="{{$project->id}}">
|
||||
<td class="link" colspan="2">{{$project->descripcion}}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
document.querySelectorAll('#projects td.link').forEach(column => {
|
||||
column.style.cursor = 'pointer'
|
||||
column.addEventListener('click', () => {
|
||||
const index = column.parentNode.dataset.index
|
||||
if (typeof brokers.data.contracts[index] !== 'undefined') {
|
||||
brokers.data.project_id = index
|
||||
brokers.draw().brokers(index)
|
||||
return
|
||||
}
|
||||
brokers.get().contracts(index)
|
||||
})
|
||||
})
|
||||
|
||||
document.getElementById('refresh_button').addEventListener('click', () => {
|
||||
if (brokers.data.project_id === null) {
|
||||
return
|
||||
}
|
||||
brokers.actions().refresh()
|
||||
})
|
||||
|
||||
document.getElementById('up_button').addEventListener('click', () => {
|
||||
brokers.actions().up()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
170
app/resources/views/proyectos/brokers/show.blade.php
Normal file
170
app/resources/views/proyectos/brokers/show.blade.php
Normal file
@ -0,0 +1,170 @@
|
||||
@extends('proyectos.brokers.base')
|
||||
|
||||
@section('brokers_title')
|
||||
{{ $broker->name }}
|
||||
@endsection
|
||||
|
||||
@section('brokers_header')
|
||||
{{ $broker->name }}
|
||||
@endsection
|
||||
|
||||
@section('brokers_content')
|
||||
<div class="ui compact segment">
|
||||
<b>RUT:</b> {{ $broker->rutFull() }} <br />
|
||||
<b>Razón Social:</b> {{ $broker->data()?->legalName }}
|
||||
</div>
|
||||
@if ($broker->data()?->representative->name !== null)
|
||||
<div class="ui card">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
Contacto
|
||||
</div>
|
||||
<div class="description">
|
||||
Nombre: {{ $broker->data()?->representative?->name }}<br />
|
||||
Email: {{ $broker->data()?->representative?->email }}<br />
|
||||
Teléfono: {{ $broker->data()?->representative?->phone }}<br />
|
||||
Dirección: {{ $broker->data()?->representative?->address }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Proyecto</th>
|
||||
<th>Comisión</th>
|
||||
<th>Fecha Inicio</th>
|
||||
<th class="right aligned">
|
||||
<button type="button" class="ui small tertiary green icon button" id="add_contract_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="contracts">
|
||||
@foreach($broker->contracts() as $contract)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ $urls->base }}/proyectos/broker/{{ $broker->rut }}/contract/{{ $contract->id }}">
|
||||
{{ $contract->project->descripcion }}
|
||||
<i class="angle right icon"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ $format->percent($contract->commission, 2, true) }}</td>
|
||||
<td>{{ $contract->current()->date->format('d-m-Y') }}</td>
|
||||
<td class="right aligned">
|
||||
<button type="button" class="ui small tertiary red icon button remove_button" data-index="{{$contract->id}}">
|
||||
<i class="remove icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@include('proyectos.brokers.show.add_modal')
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const brokerHandler = {
|
||||
ids: {
|
||||
buttons: {
|
||||
add: '',
|
||||
remove: ''
|
||||
}
|
||||
},
|
||||
modals: {
|
||||
add: null,
|
||||
},
|
||||
execute() {
|
||||
return {
|
||||
add: data => {
|
||||
const url = '{{ $urls->api }}/proyectos/broker/{{ $broker->rut }}/contracts/add'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('contracts[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
console.error(response.errors)
|
||||
alert('No se pudo agregar contrato.')
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo agregar contrato.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
},
|
||||
remove: index => {
|
||||
const url = `{{ $urls->api }}/proyectos/brokers/contract/${index}`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => {
|
||||
if (!response) {
|
||||
console.error(response.errors)
|
||||
alert('No se pudo eliminar contrato.')
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo eliminar contrato.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
events() {
|
||||
return {
|
||||
add: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
brokerHandler.modals.add.show()
|
||||
},
|
||||
remove: clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
const index = $(clickEvent.currentTarget).data('index')
|
||||
brokerHandler.execute().remove(index)
|
||||
}
|
||||
}
|
||||
},
|
||||
buttonWatch() {
|
||||
document.getElementById(brokerHandler.ids.buttons.add).addEventListener('click', brokerHandler.events().add)
|
||||
Array.from(document.getElementsByClassName(brokerHandler.ids.buttons.remove)).forEach(button => {
|
||||
button.addEventListener('click', brokerHandler.events().remove)
|
||||
})
|
||||
},
|
||||
setup(ids) {
|
||||
brokerHandler.ids = ids
|
||||
brokerHandler.buttonWatch()
|
||||
|
||||
this.modals.add = new AddModal(brokerHandler)
|
||||
const dto = structuredClone(datatables_defaults)
|
||||
dto.order = [[0, 'asc']]
|
||||
dto.columnDefs = [
|
||||
{
|
||||
targets: 3,
|
||||
orderable: false
|
||||
}
|
||||
]
|
||||
$('#contracts').parent().DataTable(dto)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
brokerHandler.setup({
|
||||
buttons: {
|
||||
add: 'add_contract_button',
|
||||
remove: 'remove_button'
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -0,0 +1,96 @@
|
||||
<div class="ui modal" id="add_contract_modal">
|
||||
<div class="header">
|
||||
Agregar Contrato
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_contract_form">
|
||||
<input type="hidden" name="broker_rut" value="{{$broker->rut}}" />
|
||||
<div class="fields">
|
||||
<div class="six wide field">
|
||||
<label>Proyecto</label>
|
||||
<div class="ui search selection dropdown" id="project">
|
||||
<input type="hidden" name="project_id" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach($projects as $project)
|
||||
<div class="item" data-value="{{ $project->id }}">{{ $project->descripcion }}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Comisión</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="commission" placeholder="Comisión" />
|
||||
<div class="ui basic label">%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label>Fecha Inicio</label>
|
||||
<div class="ui calendar" id="add_fecha_inicio">
|
||||
<div class="ui icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="date" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Agregar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class AddModal {
|
||||
ids
|
||||
modal
|
||||
handler
|
||||
constructor(handler) {
|
||||
this.handler = handler
|
||||
this.ids = {
|
||||
modal: 'add_contract_modal',
|
||||
form: 'add_contract_form',
|
||||
proyecto: 'project',
|
||||
date: 'add_fecha_inicio'
|
||||
}
|
||||
$(`#${this.ids.proyecto}`).dropdown()
|
||||
const cdo = structuredClone(calendar_date_options)
|
||||
cdo['initialDate'] = new Date()
|
||||
$(`#${this.ids.date}`).calendar(cdo)
|
||||
this.modal = $(`#${this.ids.modal}`)
|
||||
this.modal.modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById(this.ids.form)
|
||||
let commission = parseFloat(form.querySelector('[name="commission"]').value)
|
||||
if (commission > 1) {
|
||||
commission /= 100
|
||||
}
|
||||
const date = $(`#${this.ids.date}`).calendar('get date')
|
||||
const data = {
|
||||
broker_rut: form.querySelector('[name="broker_rut"]').value,
|
||||
project_id: form.querySelector('[name="project_id"]').value,
|
||||
commission: commission,
|
||||
date: [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-')
|
||||
}
|
||||
this.handler.execute().add(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
show() {
|
||||
this.modal.modal('show')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -35,7 +35,7 @@
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Proyecto {
|
||||
id
|
||||
estados
|
||||
|
@ -141,7 +141,7 @@
|
||||
@include('layout.body.scripts.chartjs')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const superficies = {
|
||||
ids: {
|
||||
vendible: '',
|
||||
|
@ -39,7 +39,7 @@
|
||||
@endpush
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Unidad
|
||||
{
|
||||
id
|
||||
|
@ -31,7 +31,7 @@
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Row
|
||||
{
|
||||
proyecto
|
||||
|
@ -150,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>',
|
||||
@endforeach
|
||||
]
|
||||
|
||||
class Rut {
|
||||
class RutHandler {
|
||||
ids
|
||||
patterns
|
||||
valid
|
||||
@ -222,7 +224,7 @@
|
||||
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()
|
||||
@ -352,62 +354,71 @@
|
||||
const lines = [
|
||||
'<label for="rut">RUT</label>',
|
||||
'<div class="inline field">',
|
||||
'<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>',
|
||||
'<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)" 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 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" 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 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" />',
|
||||
'<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 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})
|
||||
}
|
||||
@ -465,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()
|
||||
@ -484,6 +497,7 @@
|
||||
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" required />',
|
||||
@ -536,13 +550,22 @@
|
||||
'</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})
|
||||
}
|
||||
@ -605,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')
|
||||
@ -783,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'})
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
@endpush
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Cierre {
|
||||
id
|
||||
proyecto_id
|
||||
|
@ -120,7 +120,7 @@
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
function action(action, cierre_id) {
|
||||
const url = '{{$urls->base}}/api/cierre/' + cierre_id + '/' + action
|
||||
console.debug(url)
|
||||
|
@ -65,7 +65,7 @@
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
const cuotas_tables = new DataTable('#cuotas', {
|
||||
language: {
|
||||
|
@ -66,7 +66,7 @@
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
const cuotas_tables = new DataTable('#cuotas', {
|
||||
language: {
|
||||
|
@ -54,22 +54,23 @@
|
||||
}
|
||||
$(document).ready(() => {
|
||||
const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}'
|
||||
let old = new Date({{$venta->resciliacion()?->fecha->format('Y') ?? date('Y')}},
|
||||
{{$venta->resciliacion()?->fecha->format('n') ?? date('n')}}-1, {{$venta->resciliacion()?->fecha->format('j') ?? date('j')}})
|
||||
let old = new Date(Date.parse('{{$venta->resciliacion()?->fecha->format('Y-m-d') ?? $venta->currentEstado()->fecha->format('Y-m-d') ?? $venta->fecha->format('Y-m-d')}}') + 24 * 60 * 60 * 1000)
|
||||
calendar_date_options['initialDate'] = old
|
||||
calendar_date_options['onChange'] = function(date, text, mode) {
|
||||
if (date.getTime() === old.getTime()) {
|
||||
return
|
||||
}
|
||||
const body = new FormData()
|
||||
body.set('fecha', date.toISOString())
|
||||
const fecha = new Date(date.getTime())
|
||||
fecha.setDate(fecha.getDate() - 1)
|
||||
body.set('fecha', fecha.toISOString())
|
||||
$('#loading-spinner-fecha').show()
|
||||
APIClient.fetch(url, {method: 'post', body}).then(response => {
|
||||
$('#loading-spinner-fecha').hide()
|
||||
if (!response) {
|
||||
return
|
||||
}
|
||||
old = date
|
||||
old = new Date(date.getTime())
|
||||
alertResponse('Fecha cambiada correctamente.')
|
||||
})
|
||||
}
|
||||
|
@ -6,15 +6,26 @@
|
||||
|
||||
@section('venta_content')
|
||||
<div class="ui list">
|
||||
<div class="item">
|
||||
<div class="header">Valor Pagado</div>
|
||||
<div class="content">
|
||||
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
|
||||
<div class="ui left pointing small label">
|
||||
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
|
||||
@if (isset($venta->formaPago()->pie))
|
||||
<div class="item">
|
||||
<div class="header">Valor Pagado</div>
|
||||
<div class="content">
|
||||
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
|
||||
<div class="ui left pointing small label">
|
||||
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="item">
|
||||
<div class="ui compact warning message">
|
||||
<div class="content">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
No tiene valor pagado
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<div class="item">
|
||||
<div class="header">
|
||||
Multa Estandar
|
||||
|
@ -29,7 +29,7 @@
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const editVenta = {
|
||||
getMonthsList() {
|
||||
const formatter = new Intl.DateTimeFormat('es-CL', {month: 'long'})
|
||||
|
@ -18,6 +18,8 @@
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@push('page_scripts')
|
||||
@include('ventas.facturacion.show.factura')
|
||||
@include('ventas.facturacion.show.propietario')
|
||||
|
@ -194,7 +194,8 @@
|
||||
},
|
||||
unidad: ({unidad, no, classes, formatters}) => {
|
||||
const descuento = this.props.terreno.valor * unidad.prorrateo * this.props.proporcion
|
||||
const bruto = unidad.precio - descuento
|
||||
const precio = unidad.precio * this.props.proporcion
|
||||
const bruto = precio - descuento
|
||||
const neto = bruto / 1.19
|
||||
const data = [
|
||||
no,
|
||||
@ -256,7 +257,7 @@
|
||||
tooltips.neto = ` data-tooltip="No coinciden netos! Promesa: ${formatters.pesos.format(this.props.detalle.neto)} - Unidades: ${formatters.pesos.format(this.props.total.neto)}"`
|
||||
}
|
||||
if (this.props.total.iva !== this.props.detalle.iva) {
|
||||
tooltips.iva = ` data-tooltip="No coinciden ivas! Promesa: ${formatters.pesos.format(this.props.detalle.iva)} - Unidades: ${formatters.pesos.format(this.props.total.iva)}"`
|
||||
tooltips.iva = ` data-tooltip="No coinciden IVAs! Promesa: ${formatters.pesos.format(this.props.detalle.iva)} - Unidades: ${formatters.pesos.format(this.props.total.iva)}"`
|
||||
}
|
||||
if (this.props.total.total !== this.props.detalle.total) {
|
||||
tooltips.total = ` data-tooltip="No coinciden totales! Promesa: ${formatters.pesos.format(this.props.detalle.total)} - Unidades: ${formatters.pesos.format(this.props.total.total)}"`
|
||||
@ -399,7 +400,7 @@
|
||||
},
|
||||
total: () => {
|
||||
this.props.total.exento = this.props.detalle.terreno
|
||||
this.props.total.neto = (this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0) - this.props.total.exento) / 1.19
|
||||
this.props.total.neto = (this.props.unidades.reduce((sum, unidad) => sum + unidad.precio, 0) * this.props.proporcion - this.props.total.exento) / 1.19
|
||||
this.props.total.iva = this.props.total.neto * 0.19
|
||||
this.props.total.total = this.props.total.neto + this.props.total.iva + this.props.total.exento
|
||||
},
|
||||
|
@ -28,7 +28,11 @@
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
rut: rut => {
|
||||
this.props.rut = rut
|
||||
rut = rut.replaceAll(/~\d|\.|-/g, '')
|
||||
const digito = rut.slice(-1)
|
||||
rut = rut.slice(0, -1)
|
||||
this.props.rut = Rut.format(rut) + '-' + digito
|
||||
document.getElementById('rut'+this.props.index).value = this.props.rut
|
||||
facturas.venta.update().facturas()
|
||||
facturas.draw().facturas()
|
||||
},
|
||||
@ -72,7 +76,7 @@
|
||||
})
|
||||
},
|
||||
rut: () => {
|
||||
document.getElementById('rut'+this.props.index).addEventListener('input', inputEvent => {
|
||||
document.getElementById('rut'+this.props.index).addEventListener('change', inputEvent => {
|
||||
const rut = inputEvent.currentTarget.value
|
||||
if (rut === this.props.rut) {
|
||||
return
|
||||
@ -81,7 +85,7 @@
|
||||
})
|
||||
},
|
||||
nombre: () => {
|
||||
document.getElementById('propietario'+this.props.index).addEventListener('input', inputEvent => {
|
||||
document.getElementById('propietario'+this.props.index).addEventListener('change', inputEvent => {
|
||||
const nombre = inputEvent.currentTarget.value
|
||||
if (nombre === this.props.nombre) {
|
||||
return
|
||||
@ -90,7 +94,7 @@
|
||||
})
|
||||
},
|
||||
direccion: () => {
|
||||
document.getElementById('direccion_propietario'+this.props.index).addEventListener('input', inputEvent => {
|
||||
document.getElementById('direccion_propietario'+this.props.index).addEventListener('change', inputEvent => {
|
||||
const direccion = inputEvent.currentTarget.value
|
||||
if (direccion === this.props.direccion) {
|
||||
return
|
||||
|
@ -40,7 +40,7 @@
|
||||
const url = '{{$urls->api}}/ventas/unidad/' + this.props.id + '/prorrateo'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('prorrateo', newValue)
|
||||
body.set('prorrateo', (parseFloat(newValue) / 100).toFixed(8))
|
||||
return fetchAPI(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
return
|
||||
|
@ -31,7 +31,7 @@
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Venta {
|
||||
id
|
||||
propiedad
|
||||
@ -52,8 +52,12 @@
|
||||
draw(formatter, dateFormatter) {
|
||||
const tipo = this.estado.tipo_estado_venta.descripcion
|
||||
const date = new Date(this.fecha)
|
||||
let unidad = this.propiedad.unidades[0]
|
||||
if (this.propiedad.departamentos.length > 0) {
|
||||
unidad = this.propiedad.departamentos[0]
|
||||
}
|
||||
return $('<tr></tr>').append(
|
||||
$('<td></td>').attr('data-order', this.propiedad.departamentos[0].descripcion).append(
|
||||
$('<td></td>').attr('data-order', unidad.descripcion).append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/venta/' + this.id).html(this.propiedad.summary)
|
||||
)
|
||||
).append(
|
||||
@ -63,9 +67,9 @@
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.valor) + ' UF')
|
||||
).append(
|
||||
$('<td></td>').html(this.propiedad.departamentos[0].proyecto_tipo_unidad.abreviacion + ' (' + formatter.format(this.propiedad.departamentos[0].proyecto_tipo_unidad.vendible) + ' m²)')
|
||||
$('<td></td>').html(unidad.proyecto_tipo_unidad.abreviacion + ' (' + formatter.format(unidad.proyecto_tipo_unidad.vendible) + ' m²)')
|
||||
).append(
|
||||
$('<td></td>').html(formatter.format(this.valor / this.propiedad.departamentos[0].proyecto_tipo_unidad.vendible) + ' UF/m²')
|
||||
$('<td></td>').html(formatter.format(this.valor / unidad.proyecto_tipo_unidad.vendible) + ' UF/m²')
|
||||
).append(
|
||||
$('<td></td>').attr('data-order', this.fecha).html(dateFormatter.format(date))
|
||||
).append(
|
||||
@ -237,7 +241,12 @@
|
||||
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.data.ventas.forEach(venta => {
|
||||
tbody.append(venta.draw(this.formatters.number, this.formatters.date))
|
||||
try {
|
||||
tbody.append(venta.draw(this.formatters.number, this.formatters.date))
|
||||
} catch (error) {
|
||||
console.debug(venta)
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
table.append(this.draw().header()).append(tbody)
|
||||
table.show()
|
||||
|
@ -20,7 +20,7 @@
|
||||
@include('layout.body.scripts.datatables')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const historicos = {
|
||||
id: '',
|
||||
data: {
|
||||
|
50
app/resources/views/ventas/pies/add.blade.php
Normal file
50
app/resources/views/ventas/pies/add.blade.php
Normal file
@ -0,0 +1,50 @@
|
||||
@extends('ventas.base')
|
||||
|
||||
@section('venta_subtitle')
|
||||
Pie
|
||||
@endsection
|
||||
|
||||
@section('venta_content')
|
||||
<div class="ui basic compact segment">
|
||||
Valor Promesa: {{ $format->ufs($venta->valor) }} <br />
|
||||
10% {{ $format->ufs($venta->valor * 0.1) }}
|
||||
</div>
|
||||
<form class="ui form" id="add_pie">
|
||||
<input type="hidden" name="venta" value="{{ $venta->id }}" />
|
||||
<input type="hidden" name="fecha" value="{{ $venta->fecha->format('Y-m-d') }}" />
|
||||
<div class="three wide field">
|
||||
<label for="valor">Valor</label>
|
||||
<div class="ui right labeled input">
|
||||
<input type="text" name="valor" id="valor" value="{{ round($venta->valor * 0.1, 2) }}" />
|
||||
<div class="ui basic label">UF</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="cuotas"># Cuotas</label>
|
||||
<input type="number" name="cuotas" id="cuotas" />
|
||||
</div>
|
||||
<button class="ui button">Agregar</button>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
$('#add_pie').submit(event => {
|
||||
event.preventDefault()
|
||||
const data = new FormData(event.currentTarget)
|
||||
return fetchAPI('{{ $urls->api }}/venta/{{ $venta->id }}/pie/add', {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (json.success) {
|
||||
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -33,6 +33,8 @@
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.number_input')
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
@ -40,13 +42,17 @@
|
||||
fecha.calendar(calendar_date_options)
|
||||
fecha.calendar('set date', new Date({{$venta->formaPago()->bonoPie->pago->fecha->format('Y, m-1, j')}}))
|
||||
|
||||
const numberInput = new NumberInput({input: document.querySelector('input[name="valor"]'), isRational: true})
|
||||
numberInput.watch()
|
||||
|
||||
$('#add_bono').submit(submitEvent => {
|
||||
submitEvent.preventDefault()
|
||||
const url = '{{$urls->api}}/venta/{{$venta->id}}/bono_pie/edit'
|
||||
const data = new FormData()
|
||||
data.set('fecha', $('#fecha').calendar('get date').toISOString())
|
||||
data.set('valor', $('#valor').val())
|
||||
return APIClient.fetch(url, {method: 'post', body: data}).then(response => {
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('fecha', $('#fecha').calendar('get date').toISOString())
|
||||
body.set('valor', numberInput.currentValue)
|
||||
return APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
|
@ -61,6 +61,9 @@
|
||||
<tbody>@php
|
||||
$now = new DateTimeImmutable();
|
||||
$uf_venta = $venta->uf === 0.0 ? $UF->get($venta->currentEstado()->fecha) : $venta->uf;
|
||||
if ($uf_venta === 0.0) {
|
||||
$uf_venta = $UF->get();
|
||||
}
|
||||
@endphp
|
||||
@foreach ($venta->formaPago()->pie->cuotas() as $cuota)
|
||||
<tr data-pago="{{$cuota->pago->id}}"
|
||||
@ -201,7 +204,7 @@
|
||||
@include('layout.body.scripts.datatables.buttons')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
function updateRow({pago_id, valor, fecha, color, estado, remove_fecha=false, add_reject=false, disable=false}) {
|
||||
const tr = $("tr[data-pago='" + pago_id + "']")
|
||||
|
@ -86,7 +86,7 @@
|
||||
@include('layout.body.scripts.dayjs')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
function setDate(index, calendar, date = new Date()) {
|
||||
const d = dayjs(date)
|
||||
$(calendar).calendar('set date', new Date(d.add(index, 'M').valueOf()))
|
||||
|
@ -73,7 +73,7 @@
|
||||
@endpush
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Unidad {
|
||||
id
|
||||
nombre
|
||||
|
176
app/resources/views/ventas/promotions.blade.php
Normal file
176
app/resources/views/ventas/promotions.blade.php
Normal file
@ -0,0 +1,176 @@
|
||||
@extends('ventas.promotions.base')
|
||||
|
||||
@section('promotions_content')
|
||||
<table class="ui table" id="promotions">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Promoción</th>
|
||||
<th>Tipo</th>
|
||||
<th>Valor</th>
|
||||
<th>Fecha Inicio</th>
|
||||
<th>Fecha Término</th>
|
||||
<th>Válido Hasta</th>
|
||||
<th>Contratos</th>
|
||||
<th class="right aligned">
|
||||
<button type="button" class="ui small tertiary green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($promotions as $promotion)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ $urls->base }}/ventas/promotion/{{ $promotion->id }}">
|
||||
{{ $promotion->description }}
|
||||
<i class="angle right icon"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ ucwords($promotion->type->name()) }}</td>
|
||||
<td>{{ ($promotion->type === Incoviba\Model\Venta\Promotion\Type::FIXED) ? $format->ufs($promotion->amount) : $format->percent($promotion->amount, 2, true) }}</td>
|
||||
<td>{{ $promotion->startDate->format('d-m-Y') }}</td>
|
||||
<td>{{ $promotion->endDate?->format('d-m-Y') }}</td>
|
||||
<td>{{ $promotion->validUntil?->format('d-m-Y') }}</td>
|
||||
<td>
|
||||
Proyectos: {{ count($promotion->projects()) +
|
||||
count(array_unique(array_map(function($unitType) {return $unitType->project;},$promotion->unitTypes()))) +
|
||||
count(array_unique(array_map(function($unitLine) {return $unitLine->proyecto;},$promotion->unitLines()))) +
|
||||
count($promotion->units()) }} <br />
|
||||
Operadores: {{ count($promotion->brokers()) }}
|
||||
</td>
|
||||
<td class="right aligned">
|
||||
<button type="button" class="ui small tertiary icon button edit_button" data-id="{{ $promotion->id }}">
|
||||
<i class="edit icon"></i>
|
||||
</button>
|
||||
<button type="button" class="ui red small tertiary icon button remove_button" data-id="{{ $promotion->id }}">
|
||||
<i class="trash icon"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@include('ventas.promotions.add_modal')
|
||||
@include('ventas.promotions.edit_modal')
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
const promotions = {
|
||||
ids: {
|
||||
buttons: {
|
||||
add: '',
|
||||
edit: '',
|
||||
remove: ''
|
||||
},
|
||||
},
|
||||
handlers: {
|
||||
add: null,
|
||||
edit: null,
|
||||
},
|
||||
data: JSON.parse('{!! json_encode($promotions) !!}'),
|
||||
execute() {
|
||||
return {
|
||||
add: data => {
|
||||
const url = '{{$urls->api}}/ventas/promotions/add'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('promotions[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
console.error(response.errors)
|
||||
alert('No se pudo agregar promoción.')
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo agregar promoción.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
},
|
||||
edit: data => {
|
||||
const url = '{{$urls->api}}/ventas/promotions/edit'
|
||||
const method = 'post'
|
||||
const body = new FormData()
|
||||
body.set('promotions[]', JSON.stringify(data))
|
||||
return APIClient.fetch(url, {method, body}).then(response => {
|
||||
if (!response) {
|
||||
console.error(response.errors)
|
||||
alert('No se pudo editar promoción.')
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo editar promoción.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
},
|
||||
remove: promotion_id => {
|
||||
const url = `{{$urls->api}}/ventas/promotion/${promotion_id}/remove`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => {
|
||||
if (!response) {
|
||||
console.error(response.errors)
|
||||
alert('No se pudo eliminar promoción.')
|
||||
return
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.success) {
|
||||
console.error(json.errors)
|
||||
alert('No se pudo eliminar promoción.')
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
watch() {
|
||||
document.getElementById(promotions.ids.buttons.add).addEventListener('click', clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
promotions.handlers.add.show()
|
||||
})
|
||||
Array.from(document.getElementsByClassName(promotions.ids.buttons.edit)).forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
const id = clickEvent.currentTarget.dataset.id
|
||||
promotions.handlers.edit.load(id)
|
||||
})
|
||||
})
|
||||
Array.from(document.getElementsByClassName(promotions.ids.buttons.remove)).forEach(button => {
|
||||
button.addEventListener('click', clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
const id = clickEvent.currentTarget.dataset.id
|
||||
promotions.execute().remove(id)
|
||||
})
|
||||
})
|
||||
},
|
||||
setup(ids) {
|
||||
promotions.ids = ids
|
||||
|
||||
promotions.handlers.add = new AddModal()
|
||||
promotions.handlers.edit = new EditModal(promotions.data)
|
||||
|
||||
promotions.watch()
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
promotions.setup({
|
||||
buttons: {
|
||||
add: 'add_button',
|
||||
edit: 'edit_button',
|
||||
remove: 'remove_button'
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
100
app/resources/views/ventas/promotions/add_modal.blade.php
Normal file
100
app/resources/views/ventas/promotions/add_modal.blade.php
Normal file
@ -0,0 +1,100 @@
|
||||
<div class="ui modal" id="add_promotion_modal">
|
||||
<div class="header">
|
||||
Agregar Promoción
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_promotion_form">
|
||||
<div class="field">
|
||||
<label for="description">Descripción</label>
|
||||
<input type="text" id="description" name="description" placeholder="Descripción" required />
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="type">Tipo</label>
|
||||
<select id="type" name="type" class="ui select dropdown" required>
|
||||
<option value="1">Valor Fijo</option>
|
||||
<option value="2">Valor Variable</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="value">Valor</label>
|
||||
<input type="text" id="value" name="value" placeholder="Valor" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="start_date">Fecha de Inicio</label>
|
||||
<div class="ui calendar" id="start_date">
|
||||
<div class="ui left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="start_date" placeholder="Fecha de Inicio" required />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="end_date">Fecha de Término</label>
|
||||
<div class="ui calendar" id="end_date">
|
||||
<div class="ui left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="end_date" placeholder="Fecha de Término" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="valid_range">Válido por N Días Después del Término</label>
|
||||
<input type="text" id="valid_range" name="valid_range" placeholder="Válido por N Días" value="7" required />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Agregar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class AddModal {
|
||||
ids = {
|
||||
modal: '#add_promotion_modal',
|
||||
}
|
||||
modal
|
||||
|
||||
constructor() {
|
||||
this.modal = $(this.ids.modal)
|
||||
this.modal.find('.ui.dropdown').dropdown()
|
||||
this.modal.find('.ui.calendar').calendar(calendar_date_options)
|
||||
this.modal.modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById('add_promotion_form')
|
||||
const type = $(form.querySelector('[name="type"]')).dropdown('get value')
|
||||
const start_date = $(form.querySelector('#start_date')).calendar('get date')
|
||||
const end_date = $(form.querySelector('#end_date')).calendar('get date')
|
||||
let valid_until = null
|
||||
if (end_date !== null) {
|
||||
valid_until = new Date(end_date)
|
||||
valid_until.setDate(valid_until.getDate() + parseInt(form.querySelector('[name="valid_range"]').value))
|
||||
}
|
||||
const data = {
|
||||
description: form.querySelector('[name="description"]').value,
|
||||
type,
|
||||
value: form.querySelector('[name="value"]').value,
|
||||
start_date: [start_date.getFullYear(), start_date.getMonth() + 1, start_date.getDate()].join('-'),
|
||||
end_date: end_date === null ? null : [end_date.getFullYear(), end_date.getMonth() + 1, end_date.getDate()].join('-'),
|
||||
valid_until: valid_until === null ? null : [valid_until.getFullYear(), valid_until.getMonth() + 1, valid_until.getDate()].join('-'),
|
||||
}
|
||||
promotions.execute().add(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
show() {
|
||||
this.modal.modal('show')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
22
app/resources/views/ventas/promotions/base.blade.php
Normal file
22
app/resources/views/ventas/promotions/base.blade.php
Normal file
@ -0,0 +1,22 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
@hasSection('promotions_title')
|
||||
Promoción - @yield('promotions_title')
|
||||
@else
|
||||
Promociones
|
||||
@endif
|
||||
@endsection
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h2 class="ui header">
|
||||
@hasSection('promotions_header')
|
||||
Promoción - @yield('promotions_header')
|
||||
@else
|
||||
Promociones
|
||||
@endif
|
||||
</h2>
|
||||
@yield('promotions_content')
|
||||
</div>
|
||||
@endsection
|
126
app/resources/views/ventas/promotions/edit_modal.blade.php
Normal file
126
app/resources/views/ventas/promotions/edit_modal.blade.php
Normal file
@ -0,0 +1,126 @@
|
||||
<div class="ui modal" id="edit_promotion_modal">
|
||||
<div class="header">
|
||||
Editar Promoción - <span class="description"></span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="edit_promotion_form">
|
||||
<input type="hidden" name="id" />
|
||||
<div class="field">
|
||||
<label for="description">Descripción</label>
|
||||
<input type="text" id="description" name="description" placeholder="Descripción" required />
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="type">Tipo</label>
|
||||
<select id="type" name="type" class="ui select dropdown" required>
|
||||
<option value="1">Valor Fijo</option>
|
||||
<option value="2">Valor Variable</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="value">Valor</label>
|
||||
<input type="text" id="value" name="value" placeholder="Valor" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="edit_start_date">Fecha de Inicio</label>
|
||||
<div class="ui calendar" id="edit_start_date">
|
||||
<div class="ui left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="edit_start_date" placeholder="Fecha de Inicio" required />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="edit_end_date">Fecha de Término</label>
|
||||
<div class="ui calendar" id="edit_end_date">
|
||||
<div class="ui left icon input">
|
||||
<i class="calendar icon"></i>
|
||||
<input type="text" name="edit_end_date" placeholder="Fecha de Término" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="valid_range">Válido por N Días Después del Término</label>
|
||||
<input type="text" id="valid_range" name="valid_range" placeholder="Válido por N Días" value="7" required />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Editar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class EditModal {
|
||||
ids = {
|
||||
modal: '#edit_promotion_modal',
|
||||
}
|
||||
modal
|
||||
promotions
|
||||
|
||||
constructor(data) {
|
||||
this.promotions = data
|
||||
this.modal = $(this.ids.modal)
|
||||
this.modal.find('.ui.dropdown').dropdown()
|
||||
this.modal.find('.ui.calendar').calendar(calendar_date_options)
|
||||
this.modal.modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById('edit_promotion_form')
|
||||
const type = $(form.querySelector('[name="type"]')).dropdown('get value')
|
||||
const start_date = $(form.querySelector('#edit_start_date')).calendar('get date')
|
||||
const end_date = $(form.querySelector('#edit_end_date')).calendar('get date')
|
||||
let valid_until = null
|
||||
if (end_date !== null) {
|
||||
valid_until = new Date(end_date)
|
||||
valid_until.setDate(valid_until.getDate() + parseInt(form.querySelector('[name="valid_range"]').value))
|
||||
}
|
||||
const data = {
|
||||
id: form.querySelector('[name="id"]').value,
|
||||
description: form.querySelector('[name="description"]').value,
|
||||
type,
|
||||
value: form.querySelector('[name="value"]').value,
|
||||
start_date: [start_date.getFullYear(), start_date.getMonth() + 1, start_date.getDate()].join('-'),
|
||||
end_date: end_date === null ? null : [end_date.getFullYear(), end_date.getMonth() + 1, end_date.getDate()].join('-'),
|
||||
valid_until: valid_until === null ? null : [valid_until.getFullYear(), valid_until.getMonth() + 1, valid_until.getDate()].join('-'),
|
||||
}
|
||||
promotions.execute().edit(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
load(promotion_id) {
|
||||
const promotion = this.promotions.find(promotion => promotion.id === parseInt(promotion_id))
|
||||
const form = document.getElementById('edit_promotion_form')
|
||||
form.reset()
|
||||
form.querySelector('[name="id"]').value = promotion.id
|
||||
form.querySelector('[name="description"]').value = promotion.description
|
||||
form.querySelector('[name="type"]').value = promotion.type
|
||||
form.querySelector('[name="value"]').value = promotion.amount
|
||||
const start_date_parts = promotion.start_date.split('-')
|
||||
const start_date = new Date(start_date_parts[0], start_date_parts[1] - 1, start_date_parts[2])
|
||||
$('#edit_start_date').calendar('set date', start_date)
|
||||
if (promotion.end_date !== null) {
|
||||
const end_date_parts = promotion.end_date.split('-')
|
||||
const end_date = new Date(end_date_parts[0], end_date_parts[1] - 1, end_date_parts[2])
|
||||
$('#edit_end_date').calendar('set date', end_date)
|
||||
|
||||
if (promotion.valid_until !== null) {
|
||||
const valid_until_parts = promotion.valid_until.split('-')
|
||||
const valid_until = new Date(valid_until_parts[0], valid_until_parts[1] - 1, valid_until_parts[2])
|
||||
form.querySelector('[name="valid_range"]').value = valid_until.getDate() - end_date.getDate()
|
||||
}
|
||||
}
|
||||
|
||||
this.modal.modal('show')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
310
app/resources/views/ventas/promotions/show.blade.php
Normal file
310
app/resources/views/ventas/promotions/show.blade.php
Normal file
@ -0,0 +1,310 @@
|
||||
@extends('ventas.promotions.base')
|
||||
|
||||
@section('promotions_title')
|
||||
{{ $promotion->description }}
|
||||
@endsection
|
||||
|
||||
@section('promotions_header')
|
||||
{{ $promotion->description }}
|
||||
@endsection
|
||||
|
||||
@section('promotions_content')
|
||||
<div class="ui card">
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
<p>
|
||||
{{ ucwords($promotion->type->name()) }} {{ ($promotion->type === Incoviba\Model\Venta\Promotion\Type::FIXED) ? $format->ufs($promotion->amount) : $format->percent($promotion->amount, 2, true) }}
|
||||
</p>
|
||||
<p>
|
||||
{{ $promotion->startDate->format('d-m-Y') }} -> {!! $promotion->endDate?->format('d-m-Y') ?? '∞' !!}
|
||||
</p>
|
||||
<p>Válido hasta: {!! $promotion->validUntil?->format('d-m-Y') ?? '∅' !!}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui right aligned basic segment">
|
||||
<button class="ui green tertiary icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ui top attached tabular menu" id="tables_tab_menu">
|
||||
<div class="active item" data-tab="projects_table">Proyectos</div>
|
||||
<div class="item" data-tab="brokers_table">Operadores</div>
|
||||
<div class="item" data-tab="unit-types_table">Tipos</div>
|
||||
<div class="item" data-tab="unit-lines_table">Líneas</div>
|
||||
<div class="item" data-tab="units_table">Unidades</div>
|
||||
</div>
|
||||
<div class="ui bottom attached tab fitted segment" data-tab="projects_table"></div>
|
||||
<div class="ui bottom attached tab fitted segment" data-tab="brokers_table"></div>
|
||||
<div class="ui bottom attached tab fitted segment" data-tab="unit-types_table"></div>
|
||||
<div class="ui bottom attached tab fitted segment" data-tab="unit-lines_table"></div>
|
||||
<div class="ui bottom attached tab fitted segment" data-tab="units_table"></div>
|
||||
@include('ventas.promotions.show.add_modal')
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class ConnectionTable {
|
||||
table
|
||||
constructor(tab) {
|
||||
const parent = document.querySelector(`.ui.tab.segment[data-tab="${tab}"]`)
|
||||
this.table = document.createElement('table')
|
||||
this.table.className = 'ui table'
|
||||
this.table.innerHTML = [
|
||||
'<thead>',
|
||||
'<tr>',
|
||||
'<th>Proyecto</th>',
|
||||
'<th>Operador</th>',
|
||||
'<th class="center aligned" colspan="3">Unidad</th>',
|
||||
'</tr>',
|
||||
'<tr>',
|
||||
'<th colspan="2"></th>',
|
||||
'<th>Tipo</th>',
|
||||
'<th>Línea</th>',
|
||||
'<th>#</th>',
|
||||
'<th></th>',
|
||||
'</tr>',
|
||||
'</thead>',
|
||||
'<tbody></tbody>'
|
||||
].join("\n")
|
||||
parent.appendChild(this.table)
|
||||
}
|
||||
static fromProjects(data) {
|
||||
const table = new ConnectionTable('projects_table')
|
||||
data.forEach(project => {
|
||||
const row = document.createElement('tr')
|
||||
row.innerHTML = [
|
||||
`<td>${project.descripcion}</td>`,
|
||||
'<td>Todos los Operadores</td>',
|
||||
'<td colspan="3">Todas las Unidades</td>',
|
||||
`<td class="right aligned">`,
|
||||
`<button class="ui red icon button remove_button project" data-id="${project.id}">`,
|
||||
'<i class="plus icon"></i>',
|
||||
'</button>',
|
||||
`</td>`
|
||||
].join("\n")
|
||||
table.table.querySelector('tbody').appendChild(row)
|
||||
})
|
||||
document.querySelectorAll('.remove_button.project').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const project_id = button.dataset.id
|
||||
promotion.remove().project(project_id)
|
||||
})
|
||||
})
|
||||
}
|
||||
static fromBrokers(data) {
|
||||
const table = new ConnectionTable('brokers_table')
|
||||
data.forEach(broker => {
|
||||
const row = document.createElement('tr')
|
||||
row.innerHTML = [
|
||||
`<td>Todos los Proyectos</td>`,
|
||||
`<td>${broker.name}</td>`,
|
||||
'<td colspan="3">Todas las Unidades</td>',
|
||||
`<td class="right aligned">`,
|
||||
`<button class="ui red icon button remove_button broker" data-id="${broker.rut}">`,
|
||||
'<i class="plus icon"></i>',
|
||||
'</button>',
|
||||
`</td>`
|
||||
].join("\n")
|
||||
table.table.querySelector('tbody').appendChild(row)
|
||||
})
|
||||
document.querySelectorAll('.remove_button.broker').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const broker_rut = button.dataset.id
|
||||
promotion.remove().broker(broker_rut)
|
||||
})
|
||||
})
|
||||
}
|
||||
static fromUnitTypes(data) {
|
||||
const table = new ConnectionTable('unit-types_table')
|
||||
data.forEach(unitType => {
|
||||
const row = document.createElement('tr')
|
||||
const tipo = unitType.unitType.descripcion
|
||||
row.innerHTML = [
|
||||
`<td>${unitType.project.descripcion}</td>`,
|
||||
'<td>Todos los Operadores</td>',
|
||||
`<td colspan="3">Todos l@s ${tipo.charAt(0).toUpperCase() + tipo.slice(1)}s</td>`,
|
||||
`<td class="right aligned">`,
|
||||
`<button class="ui red icon button remove_button unit-type" data-project="${unitType.project.id}" data-id="${unitType.unitType.id}">`,
|
||||
'<i class="plus icon"></i>',
|
||||
'</button>',
|
||||
`</td>`
|
||||
].join("\n")
|
||||
table.table.querySelector('tbody').appendChild(row)
|
||||
})
|
||||
document.querySelectorAll('.remove_button.unit-type').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const project_id = button.dataset.project
|
||||
const unit_type_id = button.dataset.id
|
||||
promotion.remove().unitType(project_id, unit_type_id)
|
||||
})
|
||||
})
|
||||
}
|
||||
static fromUnitLines(data) {
|
||||
const table = new ConnectionTable('unit-lines_table')
|
||||
data.forEach(unitLine => {
|
||||
const row = document.createElement('tr')
|
||||
const tipo = unitLine.tipo_unidad.descripcion
|
||||
row.innerHTML = [
|
||||
`<td>${unitLine.proyecto.descripcion}</td>`,
|
||||
'<td>Todos los Operadores</td>',
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td colspan="2">Todas las unidades de la línea ${unitLine.nombre} - ${unitLine.tipologia}</td>`,
|
||||
`<td class="right aligned">`,
|
||||
`<button class="ui red icon button remove_button unit-line" data-id="${unitLine.id}">`,
|
||||
'<i class="plus icon"></i>',
|
||||
'</button>',
|
||||
`</td>`
|
||||
].join("\n")
|
||||
table.table.querySelector('tbody').appendChild(row)
|
||||
})
|
||||
document.querySelectorAll('.remove_button.unit-line').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const unit_line_id = button.dataset.id
|
||||
promotion.remove().unitLine(unit_line_id)
|
||||
})
|
||||
})
|
||||
}
|
||||
static fromUnits(data) {
|
||||
const table = new ConnectionTable('units_table')
|
||||
data.forEach(unit => {
|
||||
const row = document.createElement('tr')
|
||||
const tipo = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
row.innerHTML = [
|
||||
`<td>${unit.proyecto_tipo_unidad.proyecto.descripcion}</td>`,
|
||||
`<td>Todos los Operadores</td>`,
|
||||
`<td>${tipo.charAt(0).toUpperCase() + tipo.slice(1)}</td>`,
|
||||
`<td>${unit.proyecto_tipo_unidad.nombre} - ${unit.proyecto_tipo_unidad.tipologia}</td>`,
|
||||
`<td>${unit.descripcion}</td>`,
|
||||
`<td class="right aligned">`,
|
||||
`<button class="ui red icon button remove_button unit" data-id="${unit.id}">`,
|
||||
'<i class="plus icon"></i>',
|
||||
'</button>',
|
||||
`</td>`
|
||||
].join("\n")
|
||||
table.table.querySelector('tbody').appendChild(row)
|
||||
})
|
||||
document.querySelectorAll('.remove_button.unit').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const unit_id = button.dataset.id
|
||||
promotion.remove().unit(unit_id)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
const promotion = {
|
||||
ids: {
|
||||
table: '',
|
||||
button: {
|
||||
add: ''
|
||||
}
|
||||
},
|
||||
handlers: {
|
||||
add: null
|
||||
},
|
||||
watch() {
|
||||
return {
|
||||
add: () => {
|
||||
document.getElementById(promotion.ids.button.add).addEventListener('click', clickEvent => {
|
||||
clickEvent.preventDefault()
|
||||
promotion.handlers.add.show()
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
remove() {
|
||||
return {
|
||||
project: project_id => {
|
||||
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/project/${project_id}`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
},
|
||||
broker: broker_rut => {
|
||||
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/broker/${broker_rut}`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
},
|
||||
unitType: (project_id, unit_type_id) => {
|
||||
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/unit-type/${project_id}/${unit_type_id}`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
},
|
||||
unitLine: unit_line_id => {
|
||||
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/unit-line/${unit_line_id}`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
},
|
||||
unit: unit_id => {
|
||||
const url = `{{$urls->api}}/ventas/promotion/{{ $promotion->id }}/connections/unit/${unit_id}`
|
||||
const method = 'delete'
|
||||
return APIClient.fetch(url, {method}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
execute() {},
|
||||
setup(ids) {
|
||||
this.ids = ids
|
||||
|
||||
this.handlers.add = new AddModal()
|
||||
$(`#${this.ids.menu} .item`).tab()
|
||||
|
||||
this.watch().add()
|
||||
|
||||
@if (count($promotion->projects()) > 0)
|
||||
ConnectionTable.fromProjects({!! json_encode($promotion->projects()) !!})
|
||||
@else
|
||||
ConnectionTable.fromProjects([])
|
||||
@endif
|
||||
@if (count($promotion->brokers()) > 0)
|
||||
ConnectionTable.fromBrokers({!! json_encode($promotion->brokers()) !!})
|
||||
@else
|
||||
ConnectionTable.fromBrokers([])
|
||||
@endif
|
||||
@if (count($promotion->unitTypes()) > 0)
|
||||
ConnectionTable.fromUnitTypes({!! json_encode($promotion->unitTypes()) !!})
|
||||
@else
|
||||
ConnectionTable.fromUnitTypes([])
|
||||
@endif
|
||||
@if (count($promotion->unitLines()) > 0)
|
||||
ConnectionTable.fromUnitLines({!! json_encode($promotion->unitLines()) !!})
|
||||
@else
|
||||
ConnectionTable.fromUnitLines([])
|
||||
@endif
|
||||
@if (count($promotion->units()) > 0)
|
||||
ConnectionTable.fromUnits({!! json_encode($promotion->units()) !!})
|
||||
@else
|
||||
ConnectionTable.fromUnits([])
|
||||
@endif
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
promotion.setup({
|
||||
menu: 'tables_tab_menu',
|
||||
table: 'connections',
|
||||
button: {
|
||||
add: 'add_button'
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@endpush
|
288
app/resources/views/ventas/promotions/show/add_modal.blade.php
Normal file
288
app/resources/views/ventas/promotions/show/add_modal.blade.php
Normal file
@ -0,0 +1,288 @@
|
||||
<div class="ui modal" id="add_connection_modal">
|
||||
<div class="header">
|
||||
Agregar
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_connection_form">
|
||||
<input type="hidden" name="promotion_id" value="{{$promotion->id}}" />
|
||||
<div class="field" id="type">
|
||||
<label>Tipo</label>
|
||||
@foreach (['Proyecto' => 'project', 'Operador' => 'broker', 'Tipo' => 'type', 'Línea' => 'line', 'Unidad' => 'unit'] as $type => $value)
|
||||
<div class="ui radio checkbox type" data-tab="{{ $value }}">
|
||||
<input type="radio" name="type" value="{{$value}}" @if ($value === 'project') checked="checked"@endif />
|
||||
<label>{{$type}}</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="ui active tab segment" data-tab="project">
|
||||
<div class="field">
|
||||
<label>Proyecto</label>
|
||||
<div class="ui search multiple selection dropdown" id="project">
|
||||
<input type="hidden" name="project[]" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach ($projects as $project)
|
||||
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui tab segment" data-tab="broker">
|
||||
<div class="field">
|
||||
<label>Operador</label>
|
||||
<div class="ui search multiple selection dropdown" id="broker">
|
||||
<input type="hidden" name="broker[]" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Operador</div>
|
||||
<div class="menu">
|
||||
@foreach ($brokers as $broker)
|
||||
<div class="item" data-value="{{$broker->rut}}">{{$broker->name}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui tab segment" data-tab="type">
|
||||
<div class="fields">
|
||||
<div class="six wide field">
|
||||
<label>Proyecto</label>
|
||||
<div class="ui search selection dropdown" id="type_project">
|
||||
<input type="hidden" name="type_project" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach ($projects as $project)
|
||||
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Tipo</label>
|
||||
<div class="ui search multiple selection dropdown" id="unit_type">
|
||||
<input type="hidden" name="unit_type[]" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Tipo</div>
|
||||
<div class="menu"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui tab segment" data-tab="line">
|
||||
<div class="fields">
|
||||
<div class="six wide field">
|
||||
<label>Proyecto</label>
|
||||
<div class="ui search selection dropdown" id="line_project">
|
||||
<input type="hidden" name="line_project" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach ($projects as $project)
|
||||
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Línea</label>
|
||||
<div class="ui search multiple selection dropdown" id="line">
|
||||
<input type="hidden" name="line[]" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Línea</div>
|
||||
<div class="menu"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui tab segment" data-tab="unit">
|
||||
<div class="fields">
|
||||
<div class="six wide field">
|
||||
<label>Proyecto</label>
|
||||
<div class="ui search selection dropdown" id="unit_project">
|
||||
<input type="hidden" name="unit_project" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Proyecto</div>
|
||||
<div class="menu">
|
||||
@foreach ($projects as $project)
|
||||
<div class="item" data-value="{{$project->id}}">{{$project->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="six wide field">
|
||||
<label>Unidad</label>
|
||||
<div class="ui search multiple selection dropdown" id="unit">
|
||||
<input type="hidden" name="unit[]" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Unidad</div>
|
||||
<div class="menu"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui black deny button">
|
||||
Cancelar
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
Guardar
|
||||
<i class="checkmark icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script>
|
||||
class AddModal {
|
||||
ids
|
||||
modal
|
||||
units = []
|
||||
constructor() {
|
||||
this.ids = {
|
||||
form: 'add_connection_form',
|
||||
modal: 'add_connection_modal',
|
||||
radios: '#type .ui.radio.checkbox.type',
|
||||
type_project: 'type_project',
|
||||
unit_type: 'unit_type',
|
||||
line_project: 'line_project',
|
||||
line: 'line',
|
||||
unit_project: 'unit_project',
|
||||
unit: 'unit',
|
||||
broker: 'broker'
|
||||
}
|
||||
this.modal = $(`#${this.ids.modal}`).modal({
|
||||
onApprove: () => {
|
||||
const form = document.getElementById(this.ids.form)
|
||||
const body = new FormData(form)
|
||||
const url = `{{$urls->api}}/ventas/promotion/{{$promotion->id}}/connections/add`
|
||||
const method = 'post'
|
||||
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
$(`#${this.ids.form} ${this.ids.radios}`).checkbox({
|
||||
fireOnInit: true,
|
||||
onChecked: () => {
|
||||
$(`#${this.ids.form} ${this.ids.radios}`).each((index, radio) => {
|
||||
if ($(radio).checkbox('is checked')) {
|
||||
const tab = radio.dataset.tab
|
||||
$.tab('change tab', tab)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
$('.ui.dropdown').dropdown()
|
||||
|
||||
const typeProject = $(`#${this.ids.type_project}`)
|
||||
typeProject.dropdown('clear', false)
|
||||
typeProject.dropdown({
|
||||
onChange: (value, text, $choice) => {
|
||||
this.draw().types(value)
|
||||
}
|
||||
})
|
||||
const lineProject = $(`#${this.ids.line_project}`)
|
||||
lineProject.dropdown('clear', false)
|
||||
lineProject.dropdown({
|
||||
onChange: (value, text, $choice) => {
|
||||
this.draw().lines(value)
|
||||
}
|
||||
})
|
||||
const unitProject = $(`#${this.ids.unit_project}`)
|
||||
unitProject.dropdown('clear', false)
|
||||
unitProject.dropdown({
|
||||
onChange: (value, text, $choice) => {
|
||||
this.draw().units(value)
|
||||
}
|
||||
})
|
||||
}
|
||||
show() {
|
||||
this.modal.modal('show')
|
||||
}
|
||||
draw() {
|
||||
return {
|
||||
types: project_id => {
|
||||
this.load().units(project_id).then(() => {
|
||||
const values = []
|
||||
this.units[project_id].forEach(unit => {
|
||||
const tipo = unit.proyecto_tipo_unidad.tipo_unidad
|
||||
if (values.find(value => value.value === tipo.id)) return
|
||||
const label = `${tipo.descripcion.charAt(0).toUpperCase() + tipo.descripcion.slice(1)}`
|
||||
values.push( {
|
||||
value: tipo.id,
|
||||
text: label,
|
||||
name: label
|
||||
} )
|
||||
})
|
||||
$(`#${this.ids.unit_type}`).dropdown('change values', values)
|
||||
})
|
||||
},
|
||||
lines: project_id => {
|
||||
this.load().units(project_id).then(() => {
|
||||
const values = []
|
||||
this.units[project_id].forEach(unit => {
|
||||
const tipo = unit.proyecto_tipo_unidad.tipo_unidad
|
||||
const linea = unit.proyecto_tipo_unidad
|
||||
if (values.find(value => value.value === linea.id)) return
|
||||
let name = linea.nombre
|
||||
if (!linea.nombre.includes(tipo.descripcion.charAt(0).toUpperCase() + tipo.descripcion.slice(1))) {
|
||||
name = `${tipo.descripcion.charAt(0).toUpperCase() + tipo.descripcion.slice(1)} ${name}`
|
||||
}
|
||||
const label = `${name} - ${linea.tipologia}`
|
||||
values.push( {
|
||||
value: linea.id,
|
||||
text: label,
|
||||
name: label
|
||||
} )
|
||||
})
|
||||
$(`#${this.ids.line}`).dropdown('change values', values)
|
||||
})
|
||||
},
|
||||
units: project_id => {
|
||||
this.load().units(project_id).then(() => {
|
||||
const values = this.units[project_id].map(unit => {
|
||||
const tipo = unit.proyecto_tipo_unidad.tipo_unidad.descripcion
|
||||
const label = `${tipo.charAt(0).toUpperCase() + tipo.slice(1)} - ${unit.descripcion}`
|
||||
return {
|
||||
value: unit.id,
|
||||
text: label,
|
||||
name: label
|
||||
}
|
||||
})
|
||||
$(`#${this.ids.unit}`).dropdown('change values', values)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
load() {
|
||||
return {
|
||||
units: project_id => {
|
||||
if (typeof this.units[project_id] !== 'undefined' && this.units[project_id].length > 0) {
|
||||
return new Promise( resolve => resolve(this.units[project_id]) )
|
||||
}
|
||||
const url = `{{ $urls->api }}/proyecto/${project_id}/unidades`
|
||||
return APIClient.fetch(url).then(response => response.json()).then(json => {
|
||||
if (json.unidades.length === 0) {
|
||||
throw new Error('No se encontraron unidades')
|
||||
}
|
||||
const units = []
|
||||
Object.values(json.unidades).forEach(unidades => {
|
||||
unidades.forEach(unit => {
|
||||
units.push(unit)
|
||||
})
|
||||
})
|
||||
this.units[project_id] = units
|
||||
return units
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
@ -71,7 +71,7 @@
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
const propiedad = {
|
||||
unidades: [
|
||||
@foreach($propiedad->unidades as $unidad)
|
||||
|
@ -27,13 +27,13 @@ Editar Propietario
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="apellido_materno">Apellido Materno</label>
|
||||
<input type="text" id="apellido_materno" name="apellido_materno" value="{{$propietario->apellidos['materno']}}" />
|
||||
<input type="text" id="apellido_materno" name="apellido_materno" value="{{$propietario->apellidos['materno'] ?? ''}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="field">
|
||||
<label for="calle">Dirección</label>
|
||||
<input type="text" name="calle" id="calle" value="{{$propietario->datos->direccion->calle}}" />
|
||||
<input type="text" name="calle" id="calle" value="{'{$propietario->datos->direccion->calle}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="numero">Número</label>
|
||||
@ -58,16 +58,28 @@ Editar Propietario
|
||||
<select class="ui search selection dropdown" name="comuna" id="comunas"></select>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button" id="guardar_button">Guardar</button>
|
||||
<div class="fields">
|
||||
<div class="four wide field">
|
||||
<label>Email</label>
|
||||
<input type="email" name="email" value="{{$propietario->datos?->email}}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Teléfono</label>
|
||||
<input type="text" name="telefono" value="{{$propietario->datos?->telefono}}" />
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="ui button" id="guardar_button">Guardar</button>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@include('layout.body.scripts.rut')
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Propietario {
|
||||
props
|
||||
constructor({rut, digito, nombres, apellidos: {paterno, materno}, direccion: {calle, numero, extra, comuna, region}}) {
|
||||
constructor({rut, digito, nombres, apellidos: {paterno, materno}, direccion: {calle, numero, extra, comuna, region}, email, telefono}) {
|
||||
this.props = {
|
||||
rut,
|
||||
digito,
|
||||
@ -83,6 +95,8 @@ Editar Propietario
|
||||
comuna,
|
||||
region
|
||||
},
|
||||
email,
|
||||
telefono
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +104,7 @@ Editar Propietario
|
||||
return {
|
||||
rut: rut => {
|
||||
this.props.rut = rut
|
||||
this.update().digito(Rut.digito(this.props.rut))
|
||||
this.update().digito(Rut.digitoVerificador(this.props.rut))
|
||||
},
|
||||
digito: digito => {
|
||||
this.props.digito = digito
|
||||
@ -126,6 +140,12 @@ Editar Propietario
|
||||
this.props.direccion.region = region
|
||||
}
|
||||
}
|
||||
},
|
||||
email: email => {
|
||||
this.props.email = email
|
||||
},
|
||||
telefono: telefono => {
|
||||
this.props.telefono = telefono
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,14 +156,16 @@ Editar Propietario
|
||||
nombres: '{{trim($propietario->nombres)}}',
|
||||
apellidos: {
|
||||
paterno: '{{trim($propietario->apellidos['paterno'])}}',
|
||||
materno: '{{trim($propietario->apellidos['materno'])}}'
|
||||
materno: '{{trim($propietario->apellidos['materno'] ?? '')}}'
|
||||
},
|
||||
direccion: {
|
||||
calle: '{{trim($propietario->datos->direccion->calle)}}',
|
||||
numero: '{{$propietario->datos->direccion->numero}}',
|
||||
extra: '{{trim($propietario->datos->direccion->extra)}}',
|
||||
comuna: '{{$propietario->datos->direccion->comuna->id}}'
|
||||
}
|
||||
},
|
||||
email: '{{trim($propietario->datos?->email)}}',
|
||||
telefono: '{{trim($propietario->datos?->telefono)}}'
|
||||
}
|
||||
const data = {}
|
||||
const collator = new Intl.Collator('es')
|
||||
@ -187,7 +209,7 @@ Editar Propietario
|
||||
return
|
||||
}
|
||||
if ('rut' in data) {
|
||||
data['dv'] = Rut.digito(data['rut'])
|
||||
data['dv'] = Rut.digitoVerificador(data['rut'])
|
||||
}
|
||||
return fetchAPI(uri,
|
||||
{method: 'put', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
|
||||
@ -297,6 +319,16 @@ Editar Propietario
|
||||
propietario.props.data.update().direccion().comuna(comuna_id)
|
||||
})
|
||||
}
|
||||
static email() {
|
||||
$("[name='email']").change(event => {
|
||||
propietario.props.data.update().email(event.currentTarget.value)
|
||||
})
|
||||
}
|
||||
static telefono() {
|
||||
$("[name='telefono']").change(event => {
|
||||
propietario.props.data.update().telefono($(event.currentTarget).val())
|
||||
})
|
||||
}
|
||||
|
||||
static run() {
|
||||
Watcher.rut()
|
||||
@ -305,6 +337,8 @@ Editar Propietario
|
||||
Watcher.direccion()
|
||||
Watcher.region()
|
||||
Watcher.comuna()
|
||||
Watcher.email()
|
||||
Watcher.telefono()
|
||||
}
|
||||
}
|
||||
class EventHandler {
|
||||
@ -360,22 +394,7 @@ Editar Propietario
|
||||
}
|
||||
}
|
||||
}
|
||||
class Rut {
|
||||
static format(rut) {
|
||||
return Intl.NumberFormat('es-CL', {maximumFractionDigits: 0}).format(rut)
|
||||
}
|
||||
static digito(rut) {
|
||||
const cleanRut = rut.replace(/\D/g, ''); // Removes non-digit characters more efficiently
|
||||
let sum = 0;
|
||||
const factors = [2, 3, 4, 5, 6, 7, 2, 3, 4, 5];
|
||||
for (let i = 0; i < cleanRut.length; i++) {
|
||||
const digit = parseInt(cleanRut[cleanRut.length - 1 - i], 10);
|
||||
sum += digit * factors[i % factors.length];
|
||||
}
|
||||
const dv = 11 - (sum % 11);
|
||||
return dv === 10 ? 'K' : dv === 11 ? '0' : dv.toString();
|
||||
}
|
||||
}
|
||||
|
||||
const propietario = {
|
||||
props: {
|
||||
ids: {},
|
||||
@ -394,6 +413,8 @@ Editar Propietario
|
||||
$("[name='numero']").val(this.props.data.props.direccion.numero)
|
||||
$("[name='extra']").val(this.props.data.props.direccion.extra)
|
||||
$('#region').val(this.props.data.props.direccion.region)
|
||||
$("[name='email']").val(this.props.data.props.email)
|
||||
$("[name='telefono']").val(this.props.data.props.telefono)
|
||||
this.update().region()
|
||||
},
|
||||
region: () => {
|
||||
@ -435,6 +456,8 @@ Editar Propietario
|
||||
this.props.data.update().direccion().extra(data.propietario.direccion.extra)
|
||||
this.props.data.update().direccion().comuna(data.propietario.direccion.comuna.id)
|
||||
this.props.data.update().direccion().region(data.propietario.direccion.comuna.provincia.region.id)
|
||||
this.props.data.update().email(data.propietario.email)
|
||||
this.props.data.update().telefono(data.propietario.telefono)
|
||||
this.update().propietario()
|
||||
})
|
||||
})
|
||||
@ -489,6 +512,8 @@ Editar Propietario
|
||||
$("[name='calle']").val('')
|
||||
$("[name='numero']").val('')
|
||||
$("[name='extra']").val('')
|
||||
$("[name='email']").val('')
|
||||
$("[name='telefono']").val('')
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -511,7 +536,8 @@ Editar Propietario
|
||||
})
|
||||
this.update().region()
|
||||
|
||||
$(this.props.ids.forms.edit).submit(Form.submit)
|
||||
document.getElementById(this.props.ids.forms.edit.replace('#', '')).addEventListener('submit', Form.submit)
|
||||
document.getElementById(this.props.ids.buttons.guardar.replace('#', '')).addEventListener('click', Form.submit)
|
||||
Watcher.run()
|
||||
}
|
||||
}
|
||||
@ -534,7 +560,7 @@ Editar Propietario
|
||||
nombres: '{{$propietario->nombres}}',
|
||||
apellidos: {
|
||||
paterno: '{{$propietario->apellidos['paterno']}}',
|
||||
materno: '{{$propietario->apellidos['materno']}}'
|
||||
materno: '{{$propietario->apellidos['materno'] ?? ''}}'
|
||||
},
|
||||
direccion: {
|
||||
calle: '{{$propietario->datos->direccion->calle}}',
|
||||
@ -542,7 +568,9 @@ Editar Propietario
|
||||
extra: '{{$propietario->datos->direccion->extra}}',
|
||||
comuna: '{{$propietario->datos->direccion->comuna->id}}',
|
||||
region: '{{$propietario->datos->direccion->comuna->provincia->region->id}}',
|
||||
}
|
||||
},
|
||||
email: '{{$propietario->datos?->email}}',
|
||||
telefono: '{{$propietario->datos?->telefono}}'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -78,7 +78,7 @@
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Comentario {
|
||||
id
|
||||
fecha
|
||||
|
@ -33,7 +33,7 @@
|
||||
</div>
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
class Anchor
|
||||
{
|
||||
classes
|
||||
|
@ -1,42 +1,52 @@
|
||||
@if ($pie !== null)
|
||||
<tr>
|
||||
<td>
|
||||
Pie
|
||||
<sub>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
</sub>
|
||||
</td>
|
||||
<td>{{ $format->percent($pie->valor / $venta->valor, 2, true) }}</td>
|
||||
<td class="right aligned">{{$format->ufs($pie->valor)}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->valor * $pie->uf)}}</td>
|
||||
<td class="right aligned">Cuotas</td>
|
||||
<td>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas">
|
||||
<span data-tooltip="Pagadas">{{count($pie->cuotas(true, true))}}</span>/{{$pie->cuotas}}
|
||||
</a>
|
||||
@if (count($pie->cuotas(vigentes: true)) < $pie->cuotas)
|
||||
<a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add">
|
||||
@if ($pie !== null)
|
||||
<sub>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie">
|
||||
<i class="edit icon"></i>
|
||||
</a>
|
||||
</sub>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@if ($pie !== null)
|
||||
<td>{{ $format->percent($pie->valor / $venta->valor, 2, true) }}</td>
|
||||
<td class="right aligned">{{$format->ufs($pie->valor)}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->valor * $pie->uf)}}</td>
|
||||
<td class="right aligned">Cuotas</td>
|
||||
<td>
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas">
|
||||
<span data-tooltip="Pagadas">{{count($pie->cuotas(true, true))}}</span>/{{$pie->cuotas}}
|
||||
</a>
|
||||
@if (count($pie->cuotas(vigentes: true)) < $pie->cuotas)
|
||||
<a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
@endif
|
||||
</td>
|
||||
@else
|
||||
<td colspan="4"></td>
|
||||
@endif
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Pagado</td>
|
||||
<td>{{$format->percent($pie->pagado() / $venta->valor, 2, true)}}</td>
|
||||
<td class="right aligned">{{$format->ufs($pie->pagado())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->pagado('pesos'))}}</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
@if ($pie->reajuste)
|
||||
<tr>
|
||||
<td>Reajuste</td>
|
||||
<td></td>
|
||||
<td class="right aligned">{{$format->ufs($pie->reajuste->valor())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->reajuste->valor)}}</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
@endif
|
||||
@if ($pie !== null)
|
||||
<tr>
|
||||
<td>Pagado</td>
|
||||
<td>{{$format->percent($pie->pagado() / $venta->valor, 2, true)}}</td>
|
||||
<td class="right aligned">{{$format->ufs($pie->pagado())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->pagado('pesos'))}}</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
@if ($pie->reajuste)
|
||||
<tr>
|
||||
<td>Reajuste</td>
|
||||
<td></td>
|
||||
<td class="right aligned">{{$format->ufs($pie->reajuste->valor())}}</td>
|
||||
<td class="right aligned">{{$format->pesos($pie->reajuste->valor)}}</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
@endif
|
||||
@endif
|
||||
|
Reference in New Issue
Block a user