forked from nathalie/pedi2
Editor de saldos en compras
This commit is contained in:
parent
eb1b5bbc2e
commit
eee23082db
7 changed files with 90 additions and 10 deletions
|
@ -290,4 +290,9 @@ class GrupoDeCompra extends Model
|
||||||
->get()
|
->get()
|
||||||
->keyBy('producto_id');
|
->keyBy('producto_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSaldo(float $saldo) {
|
||||||
|
$this->saldo = $saldo;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,4 +32,13 @@ class GrupoDeCompraController extends Controller
|
||||||
GrupoDeCompra::find($gdc)->toggleDevoluciones();
|
GrupoDeCompra::find($gdc)->toggleDevoluciones();
|
||||||
return response()->noContent();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSaldo(int $gdc) {
|
||||||
|
$valid = request()->validate([
|
||||||
|
'saldo' => ['required', 'min:0'],
|
||||||
|
]);
|
||||||
|
$grupoDeCompra = GrupoDeCompra::find($gdc);
|
||||||
|
$grupoDeCompra->setSaldo($valid['saldo']);
|
||||||
|
return new GrupoDeCompraResource($grupoDeCompra);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,14 @@ class GrupoDeCompraResource extends JsonResource
|
||||||
'devoluciones_habilitadas' => $this->devoluciones_habilitadas,
|
'devoluciones_habilitadas' => $this->devoluciones_habilitadas,
|
||||||
'pedidos' => SubpedidoResource::collection($this->subpedidos),
|
'pedidos' => SubpedidoResource::collection($this->subpedidos),
|
||||||
'total_a_recaudar' => number_format($this->totalARecaudar(),2),
|
'total_a_recaudar' => number_format($this->totalARecaudar(),2),
|
||||||
'saldo' => number_format($this->saldo,2),
|
'saldo' => number_format($this->saldo, 2, ".", ""),
|
||||||
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
|
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
|
||||||
'total_barrial' => number_format($this->totalBarrial(),2),
|
'total_barrial' => number_format($this->totalBarrial(),2),
|
||||||
'total_devoluciones' => number_format($this->totalDevoluciones(),2),
|
'total_devoluciones' => number_format($this->totalDevoluciones(),2),
|
||||||
'total_de_pedido' => number_format($this->totalDePedido(),2),
|
'total_de_pedido' => number_format($this->totalDePedido(),2),
|
||||||
'total_a_transferir' => number_format($this->totalATransferir(),2),
|
'total_a_transferir' => number_format($this->totalATransferir(),2),
|
||||||
'total_transporte' => number_format($this->totalTransporte()),
|
'total_transporte' => number_format($this->totalTransporte()),
|
||||||
'cantidad_transporte' => number_format($this->cantidadTransporte()),
|
'cantidad_transnumber_formatporte' => number_format($this->cantidadTransporte()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Saldo a favor:</th>
|
<th>Saldo a favor:</th>
|
||||||
<td class="has-text-right">$ {{ saldo }}</td>
|
<td class="has-text-right">- $ {{ saldo }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Total a transferir:</th>
|
<th>Total a transferir:</th>
|
||||||
|
|
|
@ -46,11 +46,31 @@
|
||||||
:class="seccionActiva === 'saldos-comisiones-seccion' ? 'is-active' : 'is-hidden'"
|
:class="seccionActiva === 'saldos-comisiones-seccion' ? 'is-active' : 'is-hidden'"
|
||||||
>
|
>
|
||||||
<div class="block" id="saldos-comisiones-seccion">
|
<div class="block" id="saldos-comisiones-seccion">
|
||||||
<table>
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Barrio</th>
|
||||||
|
<th>Saldo</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="gdc in grupos_de_compra">
|
<tr v-for="gdc in grupos_de_compra">
|
||||||
<th>{{ gdc.nombre }}</th>
|
<th>{{ gdc.nombre }}</th>
|
||||||
<td>{{ gdc.saldo }}</td>
|
<td>
|
||||||
|
<input id="cantidad"
|
||||||
|
v-model="gdc.saldo"
|
||||||
|
class="input is-small"
|
||||||
|
type="number"
|
||||||
|
style="text-align: center"
|
||||||
|
@input="saldoModificado(gdc.id)">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button :disabled="!isSaldoModificado(gdc.id)" class="button is-small is-success ml-1" @click="confirmar_saldo(gdc.id)">
|
||||||
|
<span class="icon">
|
||||||
|
<i class="fas fa-check"></i>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -71,6 +91,7 @@ export default {
|
||||||
TabsSecciones,
|
TabsSecciones,
|
||||||
DropdownDescargar,
|
DropdownDescargar,
|
||||||
CanastaInput,
|
CanastaInput,
|
||||||
|
InputFileButton,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -82,6 +103,7 @@ export default {
|
||||||
tabActiva: "pedidos-comisiones",
|
tabActiva: "pedidos-comisiones",
|
||||||
seccionActiva: "pedidos-comisiones-seccion",
|
seccionActiva: "pedidos-comisiones-seccion",
|
||||||
archivo: undefined,
|
archivo: undefined,
|
||||||
|
saldo_modificado: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -89,7 +111,30 @@ export default {
|
||||||
this.tabActiva = tabId;
|
this.tabActiva = tabId;
|
||||||
this.seccionActiva = tabId + "-seccion";
|
this.seccionActiva = tabId + "-seccion";
|
||||||
},
|
},
|
||||||
...mapActions('comisiones', ['getGruposDeCompra']),
|
...mapActions('comisiones', ['getGruposDeCompra', 'setSaldo']),
|
||||||
|
async confirmar_saldo(gdc_id) {
|
||||||
|
var saldo = this.getSaldo(gdc_id);
|
||||||
|
await this.setSaldo({
|
||||||
|
gdc_id: gdc_id,
|
||||||
|
saldo: saldo,
|
||||||
|
});
|
||||||
|
this.saldo_modificado[gdc_id] = false;
|
||||||
|
await this.getGruposDeCompra();
|
||||||
|
},
|
||||||
|
saldoModificado(gdc_id) {
|
||||||
|
this.saldo_modificado[gdc_id] = true;
|
||||||
|
},
|
||||||
|
isSaldoModificado(gdc_id) {
|
||||||
|
return gdc_id in this.saldo_modificado && this.saldo_modificado[gdc_id];
|
||||||
|
},
|
||||||
|
getSaldo(gdc_id) {
|
||||||
|
for (var i = 0; i < this.grupos_de_compra.length; i++) {
|
||||||
|
if (this.grupos_de_compra[i].id == gdc_id) {
|
||||||
|
return this.grupos_de_compra[i].saldo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState('comisiones', [
|
...mapState('comisiones', [
|
||||||
|
|
28
resources/js/store/modules/comisiones.js
vendored
28
resources/js/store/modules/comisiones.js
vendored
|
@ -1,12 +1,21 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
grupos_de_compra: null,
|
grupos_de_compra: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
setGruposDeCompra(state, { grupos_de_compra }) {
|
setGruposDeCompra(state, { data }) {
|
||||||
state.grupos_de_compra = grupos_de_compra;
|
state.grupos_de_compra = data;
|
||||||
|
},
|
||||||
|
setGrupoDeCompra(state, gdc) {
|
||||||
|
for (var i = 0; i < state.grupos_de_compra.length; i++) {
|
||||||
|
if (state.grupos_de_compra[i].id == gdc.id) {
|
||||||
|
state.grupos_de_compra[i] = gdc;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.grupos_de_compra.push(gdc);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,9 +24,20 @@ 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 }) {
|
||||||
|
const response = await axios.post(
|
||||||
|
"api/grupos-de-compra/" + gdc_id + "/saldo",
|
||||||
|
{ saldo: saldo }
|
||||||
|
);
|
||||||
|
commit('setGrupoDeCompra', response.data.data);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const getters = {};
|
const getters = {
|
||||||
|
getSaldo() {
|
||||||
|
return (gdc_id) => state.grupos_de_compra.find(gdc => gdc.id === gdc_id)?.saldo ?? 0;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
|
|
|
@ -23,6 +23,7 @@ Route::middleware('api')->group(function() {
|
||||||
Route::get('/', 'Api\GrupoDeCompraController@index');
|
Route::get('/', 'Api\GrupoDeCompraController@index');
|
||||||
Route::get('/{grupoDeCompra}', 'Api\GrupoDeCompraController@show');
|
Route::get('/{grupoDeCompra}', 'Api\GrupoDeCompraController@show');
|
||||||
Route::post('/{gdc}/devoluciones', 'Api\GrupoDeCompraController@toggleDevoluciones');
|
Route::post('/{gdc}/devoluciones', 'Api\GrupoDeCompraController@toggleDevoluciones');
|
||||||
|
Route::post('/{gdc}/saldo', 'Api\GrupoDeCompraController@setSaldo');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('subpedidos')->group(function () {
|
Route::prefix('subpedidos')->group(function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue