Editar Brokers y sus contratos

This commit is contained in:
Juan Pablo Vial
2025-03-11 17:41:11 -03:00
parent 510e05e5ca
commit 7c7c8315e2
13 changed files with 491 additions and 60 deletions

View File

@ -17,16 +17,20 @@
</thead>
@foreach($brokers as $broker)
<tr>
<td>{{$broker->rutFull()}}</td>
<td>
<span
@if ($broker->data()?->legalName !== '')
data-tooltip="{{ $broker->data()?->legalName }}" data-position="right center"
@if ($broker->data()?->legalName !== '')
data-tooltip="{{ $broker->data()?->legalName }}" data-position="right center"
@endif
>
{{$broker->name}}
{{$broker->rutFull()}}
</span>
</td>
<td>
<a href="{{ $urls->base }}/proyectos/broker/{{ $broker->rut }}">
{{$broker->name}}
</a>
</td>
<td>
<span
@if ($broker->data()?->representative?->email !== '' || $broker->data()?->representative?->phone !== '')
@ -40,7 +44,9 @@
<div class="ui list">
@foreach($broker->contracts() as $contract)
<div class="item">
<a href="{{$urls->base}}/proyecto/{{$contract->project->id}}">{{$contract->project->descripcion}} ({{$format->percent($contract->commission, 2, true)}})</a>
<a href="{{$urls->base}}/proyecto/{{$contract->project->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>
@ -57,10 +63,23 @@
@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: {
@ -77,16 +96,19 @@
edit: ''
}
},
modals: {
add: null,
edit: null
},
events() {
return {
add: clickEvent => {
console.debug(clickEvent)
clickEvent.preventDefault()
brokersHandler.actions().add()
},
edit: clickEvent => {
clickEvent.preventDefault()
const broker_rut = clickEvent.currentTarget.dataset.index
const broker_rut = parseInt(clickEvent.currentTarget.dataset.index)
brokersHandler.actions().edit(broker_rut)
},
delete: clickEvent => {
@ -108,9 +130,23 @@
actions() {
return {
add: () => {
$(`#${brokersHandler.ids.modals.add}`).modal('show')
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)
},
edit: broker_rut => {},
delete: broker_rut => {
brokersHandler.execute().delete(broker_rut)
}
@ -150,31 +186,19 @@
setup(ids) {
brokersHandler.ids = ids
brokersHandler.buttonWatch()
$(`#${brokersHandler.ids.modals.add}`).modal('hide')
new AddModal(brokersHandler)
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'
remove: 'remove_button',
},
modals: {
add: 'add_broker_modal',
edit: 'edit_broker_modal'
},
forms: {
add: {
base: 'add_broker_form',
digit: 'digit'
},
edit: {
base: 'edit_broker_form'
}
}
})
})
</script>