Editor de saldos en compras
This commit is contained in:
parent
02aba80fc9
commit
6787dde711
7 changed files with 90 additions and 10 deletions
|
@ -286,4 +286,9 @@ class GrupoDeCompra extends Model
|
|||
->get()
|
||||
->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();
|
||||
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,
|
||||
'pedidos' => SubpedidoResource::collection($this->subpedidos),
|
||||
'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_barrial' => number_format($this->totalBarrial(),2),
|
||||
'total_devoluciones' => number_format($this->totalDevoluciones(),2),
|
||||
'total_de_pedido' => number_format($this->totalDePedido(),2),
|
||||
'total_a_transferir' => number_format($this->totalATransferir(),2),
|
||||
'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>
|
||||
<th>Saldo a favor:</th>
|
||||
<td class="has-text-right">$ {{ saldo }}</td>
|
||||
<td class="has-text-right">- $ {{ saldo }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Total a transferir:</th>
|
||||
|
|
|
@ -47,11 +47,31 @@
|
|||
:class="seccionActiva === 'saldos-compras-seccion' ? 'is-active' : 'is-hidden'"
|
||||
>
|
||||
<div class="block" id="saldos-compras-seccion">
|
||||
<table>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Barrio</th>
|
||||
<th>Saldo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="gdc in grupos_de_compra">
|
||||
<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>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -71,6 +91,7 @@ export default {
|
|||
TabsSecciones,
|
||||
DropdownDescargar,
|
||||
CanastaInput,
|
||||
InputFileButton,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -82,6 +103,7 @@ export default {
|
|||
tabActiva: "pedidos-compras",
|
||||
seccionActiva: "pedidos-compras-seccion",
|
||||
archivo: undefined,
|
||||
saldo_modificado: {},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -89,7 +111,30 @@ export default {
|
|||
this.tabActiva = tabId;
|
||||
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: {
|
||||
...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";
|
||||
|
||||
const state = {
|
||||
grupos_de_compra: null,
|
||||
grupos_de_compra: [],
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
setGruposDeCompra(state, { grupos_de_compra }) {
|
||||
state.grupos_de_compra = grupos_de_compra;
|
||||
setGruposDeCompra(state, { data }) {
|
||||
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');
|
||||
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 {
|
||||
namespaced: true,
|
||||
|
|
|
@ -21,6 +21,7 @@ Route::middleware('api')->group(function() {
|
|||
Route::get('/', 'Api\GrupoDeCompraController@index');
|
||||
Route::get('/{grupoDeCompra}', 'Api\GrupoDeCompraController@show');
|
||||
Route::post('/{gdc}/devoluciones', 'Api\GrupoDeCompraController@toggleDevoluciones');
|
||||
Route::post('/{gdc}/saldo', 'Api\GrupoDeCompraController@setSaldo');
|
||||
});
|
||||
|
||||
Route::prefix('subpedidos')->group(function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue