Movida logica de cargar planilla a comisiones.js, quitados casos en los que el barrio no está en la lista pues son imposibles
This commit is contained in:
parent
0fc370e9d1
commit
c514569acd
2 changed files with 41 additions and 49 deletions
|
@ -14,15 +14,20 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('ui',["toast"]),
|
...mapActions('ui',["toast"]),
|
||||||
...mapActions('comisiones', ['setSaldo']),
|
...mapActions('comisiones', ['setSaldo', 'cargarSaldos']),
|
||||||
async confirmar_saldo(gdc_id) {
|
async confirmar_saldo(gdc_id) {
|
||||||
var saldo = this.getSaldo(gdc_id);
|
|
||||||
await this.setSaldo({
|
await this.setSaldo({
|
||||||
gdc_id: gdc_id,
|
gdc_id: gdc_id,
|
||||||
saldo: saldo,
|
saldo: this.getSaldo(gdc_id),
|
||||||
});
|
});
|
||||||
this.saldo_modificado[gdc_id] = false;
|
this.saldo_modificado[gdc_id] = false;
|
||||||
await this.getGruposDeCompra();
|
},
|
||||||
|
async archivoSubido(event) {
|
||||||
|
event.component.cargando = true;
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('data',event.archivo);
|
||||||
|
await this.cargarSaldos(formData);
|
||||||
|
event.component.cargando = false;
|
||||||
},
|
},
|
||||||
saldoModificado(gdc_id) {
|
saldoModificado(gdc_id) {
|
||||||
this.saldo_modificado[gdc_id] = true;
|
this.saldo_modificado[gdc_id] = true;
|
||||||
|
@ -31,35 +36,8 @@ export default {
|
||||||
return gdc_id in this.saldo_modificado && this.saldo_modificado[gdc_id];
|
return gdc_id in this.saldo_modificado && this.saldo_modificado[gdc_id];
|
||||||
},
|
},
|
||||||
getSaldo(gdc_id) {
|
getSaldo(gdc_id) {
|
||||||
for (var i = 0; i < this.grupos_de_compra.length; i++) {
|
const barrio = this.grupos_de_compra.find(gdc => gdc.id === gdc_id);
|
||||||
if (this.grupos_de_compra[i].id == gdc_id) {
|
return barrio.saldo;
|
||||||
return this.grupos_de_compra[i].saldo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
async saldosSubido(event) {
|
|
||||||
var archivo = event.archivo;
|
|
||||||
if (archivo.type === "text/csv") {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("data", archivo);
|
|
||||||
try {
|
|
||||||
const response = await axios.post("/comisiones/saldos", formData, {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "multipart/form-data",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
this.getGruposDeCompra();
|
|
||||||
this.toast({ mensaje: (response.data.message || "Canasta cargada exitosamente") });
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
this.toast({ mensaje: (error.response?.data?.message || "Hubo errores.") });
|
|
||||||
}
|
|
||||||
event.component.cargando = false;
|
|
||||||
} else {
|
|
||||||
this.toast("El archivo debe ser .CSV");
|
|
||||||
event.component.cargando = false;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
toggleSaldosFileDialog() {
|
toggleSaldosFileDialog() {
|
||||||
this.show_saldos_file_dialog = !this.show_saldos_file_dialog;
|
this.show_saldos_file_dialog = !this.show_saldos_file_dialog;
|
||||||
|
@ -98,12 +76,12 @@ export default {
|
||||||
<article class="message is-danger mt-2">
|
<article class="message is-danger mt-2">
|
||||||
<div class="message-body">
|
<div class="message-body">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
Cargar un archivo de saldos sólo reemplazará los saldos de los barrios presentes en la tabla.
|
Al cargar un archivo, se reemplazaran los saldos de los barrios que éste contenga, el resto quedará sin cambiar.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<input-file-button text="Subir archivo" @archivo-subido="saldosSubido" />
|
<input-file-button text="Subir archivo" @archivo-subido="archivoSubido" />
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
|
42
resources/js/store/modules/comisiones.js
vendored
42
resources/js/store/modules/comisiones.js
vendored
|
@ -8,14 +8,10 @@ const mutations = {
|
||||||
setGruposDeCompra(state, { data }) {
|
setGruposDeCompra(state, { data }) {
|
||||||
state.grupos_de_compra = data;
|
state.grupos_de_compra = data;
|
||||||
},
|
},
|
||||||
setGrupoDeCompra(state, gdc) {
|
setSaldo(state, { gdc_id, saldo }) {
|
||||||
for (var i = 0; i < state.grupos_de_compra.length; i++) {
|
const barrio = state.grupos_de_compra.find(gdc => gdc.id === gdc_id);
|
||||||
if (state.grupos_de_compra[i].id == gdc.id) {
|
const i = state.grupos_de_compra.indexOf(barrio);
|
||||||
state.grupos_de_compra[i] = gdc;
|
state.grupos_de_compra[i].saldo = saldo;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state.grupos_de_compra.push(gdc);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,12 +20,30 @@ const actions = {
|
||||||
const response = await axios.get('/api/grupos-de-compra');
|
const response = await axios.get('/api/grupos-de-compra');
|
||||||
commit('setGruposDeCompra', response.data);
|
commit('setGruposDeCompra', response.data);
|
||||||
},
|
},
|
||||||
async setSaldo({ commit }, { gdc_id, saldo }) {
|
async setSaldo({ commit, dispatch }, { gdc_id, saldo }) {
|
||||||
const response = await axios.post(
|
try {
|
||||||
"api/grupos-de-compra/" + gdc_id + "/saldo",
|
await axios.post(
|
||||||
{ saldo: saldo }
|
"api/grupos-de-compra/" + gdc_id + "/saldo",
|
||||||
);
|
{ saldo: saldo }
|
||||||
commit('setGrupoDeCompra', response.data.data);
|
);
|
||||||
|
commit('setSaldo', { gdc_id: gdc_id, saldo: saldo });
|
||||||
|
dispatch("ui/toast", { mensaje: 'Saldo modificado con éxito' }, { root: true });
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async cargarSaldos({ commit, dispatch }, formData) {
|
||||||
|
try {
|
||||||
|
const response = await axios.post("/comisiones/saldos", formData, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "multipart/form-data",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
commit('setGruposDeCompra', response);
|
||||||
|
dispatch("ui/toast", { mensaje: 'Saldos cargados con éxito' }, { root: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
dispatch("ui/error", { error: error }, { root: true });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue