Compare commits

..

No commits in common. "ca4dd862d0a004a958667fe16ff12498633a318d" and "71a6e496e925b0b63676b5faa229392f074c9e82" have entirely different histories.

15 changed files with 120 additions and 195 deletions

View file

@ -127,33 +127,21 @@ class SubpedidoController extends Controller
*/
public function syncFaltantesYSobrantes(Subpedido $subpedido): SubpedidoResource
{
$valid = request()->validate([
'cantidad' => ['integer', 'required'],
'producto_id' => [
'required',
Rule::in(Producto::all()->pluck('id')),
]
]);
$producto = Producto::find($valid['producto_id']);
if ($producto->bono)
abort(400, "No te puede haber faltado un bono");
$cantidad = $valid['cantidad'];
if ($cantidad < 0) { // caso faltantes
$barrio = GrupoDeCompra::find($subpedido->grupo_de_compra_id);
$productosPedidos = $barrio->productosPedidos(true);
$productoPedido = $productosPedidos->where('producto_id', $producto->id)->first();
if (!$productoPedido)
abort(400, "No te puede faltar algo que no pediste.");
$cantidadPedida = intval($productoPedido->cantidad_pedida);
if ($cantidadPedida + $cantidad < 0)
abort(400, 'No te puede faltar más de lo que pediste');
$producto_id = request()->producto_id;
$producto = Producto::find($producto_id);
if (!$producto) {
throw new HttpException(400, "No se encontro el producto.");
}
$subpedido->syncProducto($producto, $cantidad);
$cantidad = -1*($subpedido->productos()->find($producto_id)?->cantidad ?? 0);
$valid = request()->validate([
'cantidad' => ['integer', 'required', 'min:' . $cantidad],
'producto_id' => ['required']
]);
$cantidad = $valid['cantidad'];
$subpedido->syncProducto($producto, $cantidad, null);
return new SubpedidoResource($subpedido);
}
}

View file

@ -4,10 +4,17 @@ namespace App\Http\Controllers;
use App\GrupoDeCompra;
use App\Http\Resources\PedidoFaltantesYSobrantesResource;
use App\Http\Resources\PedidoOllasResource;
use App\TipoPedido;
use Illuminate\Http\Request;
class FaltantesYSobrantesController extends Controller
{
public function show()
{
return view('auth/login');
}
public function pedido(GrupoDeCompra $gdc)
{
$tipoFaltantesYSobrantes = TipoPedido::firstOrCreate(['nombre' => 'faltantes_y_sobrantes']);

View file

@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class GrupoDeCompraFaltantesYSobrantesResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$productos_cantidades = [];
$productosPedidos = $this->productosPedidos();
foreach ($productosPedidos as $productoPedido) {
$productos_cantidades[$productoPedido->producto_id] = $productoPedido->cantidad_pedida;
}
return [
'id' => $this->id,
'nombre' => $this->nombre,
'productos_cantidades' => $productos_cantidades,
];
}
}

View file

@ -109,7 +109,7 @@ class Subpedido extends Model
}
// Actualiza el pedido, agregando o quitando del subpedido según sea necesario. Debe ser llamado desde el controlador de subpedidos, luego de validar que los parámetros $producto y $cantidad son correctos. También calcula el subtotal por producto.
public function syncProducto(Producto $producto, int $cantidad, string $notas = "")
public function syncProducto(Producto $producto, int $cantidad, string $notas)
{
if ($cantidad) {
//si la cantidad es 1 o más se agrega el producto o actualiza la cantidad

View file

@ -1,30 +1,19 @@
<template>
<div>
<pedidos-main v-if="show_faltantes_y_sobrantes"/>
<div class="block ml-3 mr-3 is-max-widescreen is-max-desktop" v-else>
<tabs-secciones :tabs="tabs" :tabInicial="tabActiva"/>
<div class="block" id="pedidos-seccion"
:class="seccionActiva === 'pedidos-seccion' ? 'is-active' : 'is-hidden'">
<div class="block pb-6" id="pedidos-tabla-y-dropdown" v-if="hayPedidos">
<div class="is-flex is-justify-content-space-between mb-3">
<button class="button is-danger" @click="abrirFaltantesYSobrantes">
<span class="icon">
<i class="fa fa-refresh"></i>
</span>
<span>Faltantes y Sobrantes</span>
</button>
<dropdown-descargar/>
</div>
<tabla-pedidos/>
</div>
<p class="has-text-centered" v-else>
Todavía no hay ningún pedido para administrar.
</p>
</div>
<div class="block pb-6" id="caracteristicas-seccion"
:class="seccionActiva === 'caracteristicas-seccion' ? 'is-active' : 'is-hidden'">
<caracteristicas-opcionales/>
<div class="block ml-3 mr-3 is-max-widescreen is-max-desktop">
<tabs-secciones :tabs="tabs" :tabInicial="tabActiva"/>
<div class="block" id="pedidos-seccion"
:class="seccionActiva === 'pedidos-seccion' ? 'is-active' : 'is-hidden'">
<div class="block pb-6" id="pedidos-tabla-y-dropdown" v-if="hayPedidos">
<dropdown-descargar/>
<tabla-pedidos/>
</div>
<p class="has-text-centered" v-else>
Todavía no hay ningún pedido para administrar.
</p>
</div>
<div class="block pb-6" id="caracteristicas-seccion"
:class="seccionActiva === 'caracteristicas-seccion' ? 'is-active' : 'is-hidden'">
<caracteristicas-opcionales/>
</div>
</div>
</template>
@ -34,14 +23,10 @@ import CaracteristicasOpcionales from "./CaracteristicasOpcionales.vue";
import TabsSecciones from "../comunes/TabsSecciones.vue";
import DropdownDescargar from "./DropdownDescargar.vue";
import TablaPedidos from "./TablaPedidos.vue";
import { mapActions, mapGetters, mapMutations, mapState } from "vuex";
import Canasta from "../pedidos/Canasta.vue";
import PedidosMain from "../pedidos/PedidosMain.vue";
import { mapActions, mapGetters } from "vuex";
export default {
name: "AdminBody",
components: {
PedidosMain,
Canasta,
CaracteristicasOpcionales,
TabsSecciones,
DropdownDescargar,
@ -57,12 +42,9 @@ export default {
},
computed: {
...mapGetters('admin', ['hayPedidos']),
...mapState('ui', ['show_faltantes_y_sobrantes'])
},
methods: {
...mapActions('admin', ['getGrupoDeCompra', 'abrirFaltantesYSobrantes']),
...mapActions('ui', ['toast']),
...mapMutations('ui', ['toggleFaltantesYSobrantes']),
...mapActions('admin', ['getGrupoDeCompra']),
setSeccionActiva(tabId) {
this.tabActiva = tabId;
this.seccionActiva = tabId + "-seccion";

View file

@ -2,11 +2,7 @@
<div class="buttons is-right">
<div class="dropdown" :class="{'is-active': dropdownActivo}" @mouseleave="dropdownActivo = false">
<div class="dropdown-trigger">
<button class="button"
aria-haspopup="true"
aria-controls="dropdown-menu"
:disabled="!hayAprobados"
@click="dropdownActivo = !dropdownActivo">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu" :disabled="!hayAprobados" @click="dropdownActivo = !dropdownActivo">
<span class="icon is-small">
<i class="fas fa-download"></i>
</span>

View file

@ -18,25 +18,71 @@
/>
</tbody>
</table>
<tabla-totales/>
<table class="table is-striped is-bordered">
<tr>
<th colspan="2" class="has-background-black has-text-white has-text-centered">TOTALES</th>
</tr>
<tr>
<th>Total a recaudar:</th>
<td class="has-text-right">$ {{ devoluciones_habilitadas ? total_a_recaudar : total_sin_devoluciones }}</td>
</tr>
<tr>
<th>Total bonos barriales:</th>
<td class="has-text-right">$ {{ total_barrial }}</td>
</tr>
<tr v-if="devoluciones_habilitadas">
<th>Total devoluciones:</th>
<td class="has-text-right">- $ {{ total_devoluciones }}</td>
</tr>
<tr>
<th>Cantidad bonos de transporte:</th>
<td class="has-text-right">{{ cantidad_transporte }}</td>
</tr>
<tr>
<th>Total bonos de transporte:</th>
<td class="has-text-right">$ {{ total_transporte }}</td>
</tr>
<tr>
<th>Total de pedido:</th>
<td class="has-text-right">$ {{ total_de_pedido }}</td>
</tr>
<tr>
<th>{{ texto_saldo }}</th>
<td class="has-text-right"> $ {{ saldo }}</td>
</tr>
<tr>
<th>Total a transferir:</th>
<td class="has-text-right">$ {{ total_a_transferir }}</td>
</tr>
</table>
</div>
</template>
<script>
import FilaPedido from "./FilaPedido.vue";
import { mapGetters, mapState } from "vuex";
import TablaTotales from "./TablaTotales.vue";
export default {
components: {
TablaTotales,
FilaPedido
},
computed: {
...mapState('admin', [
"devoluciones_habilitadas",
"pedidos",
"total_a_recaudar",
"total_sin_devoluciones",
"total_barrial",
"total_devoluciones",
"cantidad_transporte",
"total_transporte",
"total_de_pedido",
"total_a_transferir",
"saldo",
]),
...mapGetters('admin', ['pedidosAprobados']),
texto_saldo() {
return this.saldo < 0 ? "Deuda:" : "Saldo a favor:";
}
},
}
</script>

View file

@ -1,69 +0,0 @@
<script>
import { mapGetters, mapState } from "vuex";
export default {
name: 'TablaTotales',
computed: {
...mapState('admin', [
"devoluciones_habilitadas",
"total_a_recaudar",
"total_sin_devoluciones",
"total_barrial",
"total_devoluciones",
"cantidad_transporte",
"total_transporte",
"total_de_pedido",
"total_a_transferir",
"saldo",
]),
...mapGetters('admin', ['pedidosAprobados']),
texto_saldo() {
return this.saldo < 0 ? "Deuda:" : "Saldo a favor:";
}
}
}
</script>
<template>
<table class="table is-striped is-bordered">
<tr>
<th colspan="2" class="has-background-black has-text-white has-text-centered">TOTALES</th>
</tr>
<tr>
<th>Total a recaudar:</th>
<td class="has-text-right">$ {{ devoluciones_habilitadas ? total_a_recaudar : total_sin_devoluciones }}</td>
</tr>
<tr>
<th>Total bonos barriales:</th>
<td class="has-text-right">$ {{ total_barrial }}</td>
</tr>
<tr v-if="devoluciones_habilitadas">
<th>Total devoluciones:</th>
<td class="has-text-right">- $ {{ total_devoluciones }}</td>
</tr>
<tr>
<th>Cantidad bonos de transporte:</th>
<td class="has-text-right">{{ cantidad_transporte }}</td>
</tr>
<tr>
<th>Total bonos de transporte:</th>
<td class="has-text-right">$ {{ total_transporte }}</td>
</tr>
<tr>
<th>Total de pedido:</th>
<td class="has-text-right">$ {{ total_de_pedido }}</td>
</tr>
<tr>
<th>{{ texto_saldo }}</th>
<td class="has-text-right"> $ {{ saldo }}</td>
</tr>
<tr>
<th>Total a transferir:</th>
<td class="has-text-right">$ {{ total_a_transferir }}</td>
</tr>
</table>
</template>
<style>
</style>

View file

@ -14,7 +14,7 @@
<th class="has-text-right">{{ cantidad_transporte }}</th>
<th class="has-text-right">{{ total_transporte }}</th>
</tr>
<tr v-if="mostrarDevoluciones">
<tr v-if="grupo_de_compra.devoluciones_habilitadas && !aprobado">
<th><p>Devoluciones</p></th>
<td>
<abbr :title="devoluciones_notas">{{ notas_abreviadas }}</abbr>
@ -49,7 +49,6 @@ import { mapMutations, mapState } from "vuex";
export default {
components: { ProductoRow },
computed: {
...mapState('login', ["rol"]),
...mapState('pedido',[
"grupo_de_compra",
"productos",
@ -66,9 +65,6 @@ export default {
mostrar_tabla() {
return this.productos?.length !== 0;
},
mostrarDevoluciones() {
return this.rol === "barrio" && this.grupo_de_compra.devoluciones_habilitadas && !this.aprobado;
}
},
methods: {
...mapMutations('ui',["toggleDevoluciones"]),

View file

@ -2,7 +2,7 @@
<div class="is-justify-content-center">
<div class="field has-addons is-justify-content-center contador">
<div class="control">
<button class="button is-small" :disabled="!puedeDecrementar" v-if="!aprobado" @click.capture="decrementar();">
<button class="button is-small" :disabled="cantidadControl < 1" v-if="!aprobado" @click.capture="decrementar();">
<i class="fa fa-solid fa-minus"></i>
</button>
</div>
@ -19,7 +19,7 @@
<i class="fa fa-solid fa-plus"></i>
</button>
</div>
<button :disabled="!puedeConfirmar" v-if="!aprobado" class="button is-small is-success ml-1" @click="confirmar()">
<button :disabled="!hayCambios || cantidadControl < 0" v-if="!aprobado" class="button is-small is-success ml-1" @click="confirmar()">
<span class="icon">
<i class="fas fa-check"></i>
</span>
@ -82,13 +82,8 @@ export default {
this.actualizar();
},
computed: {
...mapState('login', ["rol"]),
...mapState('pedido', ["aprobado"]),
...mapGetters('pedido', ["enChismosa", "cantidad", "notas"]),
...mapGetters('admin', ["cantidadBarrial"]),
cantidadTotal() {
return this.cantidadBarrial(this.producto_id);
},
cantidadEnChismosa() {
return this.cantidad(this.producto_id);
},
@ -104,14 +99,6 @@ export default {
faltaNotas() {
return this.requiere_notas && this.cantidadControl > 0 && !this.notasControl;
},
puedeDecrementar() {
const min = this.rol === "admin_barrio" ? -1*this.cantidadTotal : 0;
return this.cantidadControl > min;
},
puedeConfirmar() {
const min = this.rol === "admin_barrio" ? -1*this.cantidadTotal : 0;
return this.hayCambios && this.cantidadControl >= min;
}
},
methods: {
...mapActions('pedido', ["modificarChismosa"]),

View file

@ -17,7 +17,6 @@ const state: AdminState = {
total_transporte: undefined,
cantidad_transporte: undefined,
saldo: undefined,
productos_cantidades: [],
};
const mutations = {
@ -41,8 +40,6 @@ const mutations = {
state.total_transporte = grupo_de_compra.total_transporte;
state.cantidad_transporte = grupo_de_compra.cantidad_transporte;
state.saldo = grupo_de_compra.saldo;
state.productos_cantidades = grupo_de_compra.productos_cantidades
.map(pc => ({...pc, cantidad: parseInt(pc.cantidad)}));
},
toggleCaracteristica(state, { caracteristica_id }) {
state[`${caracteristica_id}_habilitadas`] = !state[`${caracteristica_id}_habilitadas`];
@ -65,14 +62,6 @@ const actions = {
await axios.post(`/api/grupos-de-compra/${state.grupo_de_compra_id}/${caracteristica_id}`);
commit('toggleCaracteristica', { caracteristica_id: caracteristica_id })
},
async abrirFaltantesYSobrantes({ commit, dispatch }) {
const { data } = await axios.get(`/admin/${state.grupo_de_compra_id}/faltantes-y-sobrantes`)
const pedido = { pedido_id: data.id };
dispatch("productos/init", null, { root: true });
dispatch("pedido/elegirPedido", pedido, { root: true });
dispatch("ui/migasFaltantesYSobrantes", null, { root: true });
dispatch("ui/toggleFaltantesYSobrantes", null, { root: true });
}
};
const getters = {
@ -96,10 +85,6 @@ const getters = {
},
getCaracteristica() {
return (caracteristica) => state[`${caracteristica}_habilitadas`];
},
cantidadBarrial() {
return (producto_id) =>
state.productos_cantidades.find(pc => pc.id === producto_id)?.cantidad ?? 0;
}
};

View file

@ -17,7 +17,6 @@ export interface Barrio {
total_transporte?: number,
cantidad_transporte?: number,
saldo?: number,
productos_cantidades: ProductoCantidad[],
}
export interface Pedido {
@ -32,8 +31,3 @@ export interface Pedido {
devoluciones_total: number,
devoluciones_notas: string
}
export interface ProductoCantidad {
id: number,
cantidad: number,
}

View file

@ -4,7 +4,6 @@ const state: UiState = {
show_chismosa: false,
show_devoluciones: false,
show_tags: true,
show_faltantes_y_sobrantes: false,
burger_activa: false,
tags_interactuada: false,
migas: [{ nombre: 'Pedidos', action: 'pedido/resetear' }],
@ -25,9 +24,6 @@ const mutations = {
state.tags_interactuada = manual;
state.show_tags = !state.show_tags;
},
toggleFaltantesYSobrantes(state) {
state.show_faltantes_y_sobrantes = !state.show_faltantes_y_sobrantes;
},
toggleBurger(state) {
state.burger_activa = !state.burger_activa;
},
@ -45,10 +41,6 @@ const mutations = {
migasOllas(state) {
state.migas.reverse().pop();
},
migasFaltantesYSobrantes(state) {
const migaAdmin = { nombre: 'Administración', action: 'ui/toggleFaltantesYSobrantes' }
state.migas[0] = migaAdmin;
}
};
const actions = {
@ -88,12 +80,6 @@ const actions = {
migasOllas({ commit }) {
commit("migasOllas");
},
toggleFaltantesYSobrantes({ commit }) {
commit("toggleFaltantesYSobrantes");
},
migasFaltantesYSobrantes({ commit }) {
commit("migasFaltantesYSobrantes");
}
};
export default {

View file

@ -3,8 +3,6 @@ export interface UiState {
show_chismosa: boolean,
show_devoluciones: boolean,
show_tags: boolean,
show_faltantes_y_sobrantes: boolean,
burger_activa: boolean,
tags_interactuada: boolean,
migas: Miga[],
canasta_actual?: DatosCanasta,

View file

@ -29,7 +29,7 @@ Route::middleware(['auth'])->group(function () {
Route::get('/user/grupo_de_compra', 'UserController@grupoDeCompra');
});
Route::middleware(['auth'])->group(function() {
Route::middleware(['auth', 'role:barrio'])->group(function() {
Route::get('/pedido', 'RouteController@main')->name('pedido');
Route::get('/pedido/sesion', 'SessionController@fetch');
Route::post('/pedido/sesion', 'SessionController@store');