Compare commits

..

No commits in common. "5b9908e0b5eb5cba9286eff0056e0ba135102141" and "5a0cf73218a0718af1f4fe1e8cdb681949f09e58" have entirely different histories.

33 changed files with 485 additions and 528 deletions

View file

@ -35,7 +35,7 @@ class SubpedidoController extends Controller
$s->nombre = $validado["nombre"];
$s->grupo_de_compra_id = $validado["grupo_de_compra_id"];
$s->save();
return $this->show($s);
return $s;
}
protected function validateSubpedido(): array
@ -57,7 +57,7 @@ class SubpedidoController extends Controller
// recibe request, saca producto y cantidad, valida, y pasa a syncProducto en Subpedido
public function syncProductos(Subpedido $subpedido) {
if ($subpedido->aprobado)
abort(400, "No se puede modificar un pedido aprobado.");
return new SubpedidoResource($subpedido);
$valid = request()->validate([
'cantidad' => ['integer','required','min:0'],
@ -84,8 +84,7 @@ class SubpedidoController extends Controller
}
public function syncDevoluciones(Subpedido $subpedido) {
if ($subpedido->aprobado)
abort(400, "No se puede modificar un pedido aprobado.");
if ($subpedido->aprobado) return new SubpedidoResource($subpedido);
$valid = request()->validate([
'total' => 'required|min:0',

View file

@ -18,7 +18,7 @@ class RouteController extends Controller
switch ($request->user()->role_id) {
case $barrio->id:
return redirect('/pedido');
return redirect('/productos');
case $admin->id:
return redirect('/admin');
case $comision->id:
@ -27,8 +27,4 @@ class RouteController extends Controller
abort(400, 'Rol de usuario invalido');
}
}
function main(Request $request) {
return view('main');
}
}

View file

@ -11,16 +11,12 @@ use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function rol(Request $request) {
return ["rol" => UserRole::find($request->user()->role_id)->nombre];
}
public function grupoDeCompra(Request $request)
{
$user = Auth::user();
$result = [ 'grupo_de_compra' => null, ];
$grupo_de_compra = GrupoDeCompra::find($user->grupo_de_compra_id);
switch (UserRole::findOrFail($user->role_id)->nombre) {
switch (UserRole::find($user->role_id)->nombre ?? 'error') {
case 'barrio':
$result['grupo_de_compra'] = new GrupoDeCompraReducido($grupo_de_compra);
break;

87
resources/js/app.js vendored
View file

@ -5,7 +5,6 @@
*/
import axios from 'axios';
import Vue from 'vue';
window.Vue = require('vue');
window.Event = new Vue();
window.axios = axios;
@ -20,11 +19,13 @@ window.bulmaToast = require('bulma-toast');
*/
import './components';
import store from "./store";
/**
* Global methods
*/
Vue.prototype.$toast = function (mensaje, duration = 2000) {
Vue.prototype.$settearProducto = function(cantidad, id) {
Event.$emit("sync-subpedido", this.cant, this.producto.id)
}
Vue.prototype.$toast = function(mensaje, duration = 2000) {
return window.bulmaToast.toast({
message: mensaje,
duration: duration,
@ -38,8 +39,86 @@ Vue.prototype.$toast = function (mensaje, duration = 2000) {
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
new Vue({
const app = new Vue({
el: '#root',
store,
data() {
return {
gdc: null,
pedido: null,
devoluciones: null,
}
},
computed: {
productos: function() {
return this.pedido.productos
}
},
methods: {
cantidad(producto) {
let pedido = this.productos.some(p => p.id == producto.id)
return pedido ? this.productos.find(p => p.id == producto.id).pivot.cantidad : 0
},
notas(producto) {
let pedido = this.productos.some(p => p.id == producto.id);
return pedido ? this.productos.find(p => p.id == producto.id).pivot.notas : "";
},
settearDevoluciones() {
axios.get(`/api/grupos-de-compra/${this.gdc}/devoluciones`)
.then(response => {
this.devoluciones = response.data.devoluciones;
});
}
},
mounted() {
Event.$on('obtener-sesion', () => {
if (!window.location.pathname.startsWith('/admin')) {
axios.get('/subpedidos/obtener_sesion')
.then(response => {
this.gdc = response.data.gdc;
// this.settearDevoluciones();
this.pedido = response.data.subpedido.id;
axios.get('/api/subpedidos/' + this.pedido)
.then(response => {
this.pedido = response.data.data;
Event.$emit("pedido-actualizado");
});
})
}
})
Event.$on('sync-subpedido', (cantidad, id, notas) => {
if (this.pedido.aprobado) {
this.$toast('No se puede modificar un pedido ya aprobado', 2000);
return;
}
axios.post("/api/subpedidos/" + this.pedido.id + "/sync", {
cantidad: cantidad,
producto_id: id,
notas: notas,
}).then((response) => {
this.pedido = response.data.data
this.$toast('Pedido actualizado exitosamente')
Event.$emit("pedido-actualizado");
});
});
// Actualizar monto y notas de devoluciones
Event.$on('sync-devoluciones', (total, notas) => {
if (this.pedido.aprobado) {
this.$toast('No se puede modificar un pedido ya aprobado', 2000);
return;
}
axios.post("api/subpedidos/" + this.pedido.id + "/sync_devoluciones", {
total: total,
notas: notas,
}).then((response) => {
this.pedido = response.data.data;
this.$toast('Pedido actualizado');
Event.$emit("pedido-actualizado");
});
});
if (window.location.pathname.startsWith('/productos'))
Event.$emit('obtener-sesion')
},
});

View file

@ -1,30 +0,0 @@
<script>
import NavBar from "./comunes/NavBar.vue";
import { mapActions, mapState } from "vuex";
export default {
name: 'Main',
components: { NavBar },
computed: {
...mapState('login',["rol"]),
},
methods: {
...mapActions('login',["getRol"]),
},
async mounted() {
await this.getRol();
},
}
</script>
<template>
<div id="app-main">
<nav-bar></nav-bar>
<pedidos-body v-if="rol === 'barrio'"></pedidos-body>
<admin-body v-if="rol === 'admin_barrio'"></admin-body>
<compras-body v-if="rol === 'comision'"></compras-body>
</div>
</template>
<style scoped>
</style>

View file

@ -1,7 +1,7 @@
<template>
<div v-if="region_elegida !== null" class="block">
<div class="field">
<label class="label" :class="adminUrl ? 'has-text-white' : ''">
<label class="label" :class="admin ? 'has-text-white' : ''">
Seleccioná tu barrio o grupo de compra
</label>
<div class="control">
@ -35,7 +35,7 @@ export default {
},
computed: {
...mapState('login',["region_elegida","grupos_de_compra","grupo_de_compra_elegido"]),
...mapGetters('login',["adminUrl"]),
...mapGetters('login',["admin"]),
},
data() {
return {

View file

@ -2,7 +2,7 @@
<div v-if="grupo_de_compra_elegido !== null" class="block">
<div class="field">
<label class="label"
:class="adminUrl ? 'has-text-white' : ''">{{ mensajes.mensaje }}</label>
:class="admin ? 'has-text-white' : ''">{{ mensajes.mensaje }}</label>
<div class="field has-addons">
<div class="control">
<input required class="input" :type="this.passwordType" name="password" :placeholder="mensajes.mensaje">
@ -14,7 +14,7 @@
</div>
</div>
<p class="help"
:class="adminUrl ? 'has-text-white' : ''">{{ mensajes.ayuda }}</p>
:class="admin ? 'has-text-white' : ''">{{ mensajes.ayuda }}</p>
</div>
<div class="field">
<div class="control">
@ -37,7 +37,7 @@ export default {
},
computed: {
...mapState('login',["grupo_de_compra_elegido"]),
...mapGetters('login',["adminUrl","mensajes"]),
...mapGetters('login',["admin","mensajes"]),
},
methods: {
togglePassword() {

View file

@ -20,10 +20,10 @@ export default {
await this.getRegiones();
},
computed: {
...mapGetters('login',["adminUrl"]),
...mapGetters('login',["admin"]),
...mapState('login',["grupo_de_compra_elegido"]),
nombre() {
return `${this.grupo_de_compra_elegido}${this.adminUrl ? '_admin' : ''}`;
return `${this.grupo_de_compra_elegido}${this.admin ? '_admin' : ''}`;
}
},
methods: {

View file

@ -4,15 +4,14 @@
<a class="navbar-item" href="https://mps.org.uy">
<img src="/assets/logoMPS.png" height="28">
</a>
<div class="navbar-item" id="datos-pedido" v-if="pedidoDefinido">
<p class="hide-below-1024">
{{ `Núcleo: ${nombre} - Barrio: ${grupo_de_compra}` }}
<p class="navbar-item hide-below-1024">
</p>
<p class="navbar-item">
</p>
</div>
<chismosa-dropdown
v-if="pedidoDefinido"
class="hide-above-1023"
ariaControls="mobile">
id="mobile">
</chismosa-dropdown>
<a role="button" class="navbar-burger" :class="{'is-active':burgerActiva}" aria-label="menu"
aria-expanded="false" data-target="nav-bar" @click="toggleBurger">
@ -35,7 +34,7 @@
<chismosa-dropdown
v-if="pedidoDefinido"
class="hide-below-1024"
ariaControls="wide">
id="wide">
</chismosa-dropdown>
<div class="block navbar-item">
<a onclick="event.preventDefault(); document.getElementById('logout-form').submit();"
@ -51,7 +50,7 @@
<script>
import ChismosaDropdown from '../pedidos/ChismosaDropdown.vue';
import { mapActions, mapGetters, mapMutations, mapState } from "vuex";
import { mapActions, mapGetters } from "vuex";
export default {
components: { ChismosaDropdown },
@ -62,13 +61,10 @@ export default {
}
},
computed: {
...mapGetters('pedido', ["pedidoDefinido"]),
...mapState('pedido',["nombre"]),
...mapState('barrio',["grupo_de_compra"]),
...mapGetters('pedido',["pedidoDefinido"]),
},
methods: {
...mapActions('productos', ["filtrarProductos"]),
...mapMutations('ui',["addMiga"]),
toggleBurger() {
this.burgerActiva = !this.burgerActiva
},
@ -76,7 +72,7 @@ export default {
if (this.burgerActiva)
this.toggleBurger();
this.filtrarProductos({ filtro: "nombre", valor: this.searchString });
this.addMiga({ nombre: this.searchString });
Event.$emit('migas-agregar', { nombre: this.searchString });
}
},
};

View file

@ -1,7 +1,7 @@
<template>
<div class="block">
<div class="field">
<label class="label" :class="adminUrl ? 'has-text-white' : ''">
<label class="label" :class="admin ? 'has-text-white' : ''">
Seleccioná tu región
</label>
<div class="control">
@ -38,7 +38,7 @@ export default {
},
computed: {
...mapState('login',["regiones","region_elegida"]),
...mapGetters('login',["adminUrl"]),
...mapGetters('login',["admin"]),
}
}
</script>

View file

@ -1,21 +1,32 @@
<template>
<div id="pedidos-body">
<cartel-pedido-aprobado></cartel-pedido-aprobado>
<pedido-select-section v-if="!pedidoDefinido"></pedido-select-section>
<pedido v-else></pedido>
<div class="columns ml-3 mr-3">
<categorias-container :class="chismosaActiva ? 'hide-below-1024' : ''"></categorias-container>
<productos-container :class="chismosaActiva ? 'hide-below-1024' : ''"></productos-container>
<chismosa v-show="chismosaActiva"></chismosa>
</div>
</template>
<script>
import { mapGetters } from "vuex";
import PedidoSelectSection from "./PedidoSelectSection.vue";
import Pedido from "./Pedido.vue";
import CartelPedidoAprobado from "./CartelPedidoAprobado.vue";
import { mapActions } from "vuex";
import Chismosa from "./Chismosa.vue";
import ProductosContainer from "./ProductosContainer.vue";
import CategoriasContainer from "./CategoriasContainer.vue";
export default {
components: { CartelPedidoAprobado, Pedido, Productos: Pedido, PedidoSelectSection },
computed: {
...mapGetters('pedido',["pedidoDefinido"]),
components: { CategoriasContainer, ProductosContainer, Chismosa },
data() {
return {
chismosaActiva: false,
}
},
methods: {
...mapActions('productos',["init"]),
},
async mounted() {
await this.init();
Event.$on('toggle-chismosa', (activa) => {
this.chismosaActiva = activa;
});
},
}
</script>

View file

@ -1,18 +1,31 @@
<template>
<div v-if="aprobado" class="notification is-warning has-text-centered">
<div v-show="aprobado" class="notification is-warning has-text-centered">
Tu pedido fue <strong>aprobado</strong>, por lo que no puede ser modificado
</div>
</template>
<script>
import { mapState } from "vuex";
export default {
name: 'CartelPedidoAprobado',
computed: {
...mapState('pedido',["aprobado"]),
export default {
data() {
return {
aprobado: false,
}
},
mounted() {
Event.$on('pedido-actualizado', this.actualizarEstado);
if (this.$root.pedido != null) {
this.actualizarEstado();
}
},
methods: {
pedidoAprobado: function() {
return this.$root.pedido.aprobado;
},
actualizarEstado: function() {
this.aprobado = this.pedidoAprobado();
},
},
}
}
</script>
<style>

View file

@ -18,7 +18,7 @@
</template>
<script>
import { mapActions, mapMutations, mapState } from "vuex";
import { mapActions, mapState } from "vuex";
export default {
name: 'CategoriasContainer',
computed: {
@ -28,11 +28,10 @@ export default {
}
},
methods: {
...mapActions('productos',["seleccionarCategoria"]),
...mapMutations('ui',["addMiga"]),
...mapActions('productos', ["seleccionarCategoria"]),
seleccionar(categoria) {
this.seleccionarCategoria({ categoria: categoria });
this.addMiga({ nombre: categoria });
Event.$emit('migas-agregar', { nombre: categoria });
}
}
}

View file

@ -12,20 +12,20 @@
<tfoot>
<tr>
<th><abbr title="Bonos de Transporte">B. Transporte</abbr></th>
<th class="has-text-right">{{ cantidad_transporte }}</th>
<th class="has-text-right">{{ total_transporte }}</th>
<th class="has-text-right">{{ cantidad_bonos_transporte }}</th>
<th class="has-text-right">{{ total_bonos_transporte }}</th>
</tr>
<tr v-if="devoluciones_habilitadas">
<tr v-if="this.$root.devoluciones">
<th><p>Devoluciones</p></th>
<td>
<abbr :title="devoluciones_notas">{{ notas_abreviadas }}</abbr>
<button @click.capture="toggleDevoluciones()" class="button is-warning is-small">
<abbr :title="notas_devoluciones">{{ notas_devoluciones_abbr }}</abbr>
<button @click.capture="modificarDevoluciones()" class="button is-warning is-small">
<span class="icon">
<i class="fas fa-edit"></i>
</span>
</button>
</td>
<th class="has-text-right">-{{ devoluciones_total }}</th>
<th class="has-text-right">-{{ devoluciones }}</th>
</tr>
<tr>
<th>Total total</th>
@ -45,43 +45,61 @@
</template>
<script>
import ProductoRow from "./ProductoRow.vue";
import { mapMutations, mapState } from "vuex";
import ProductoRow from "./ProductoRow.vue";
export default {
components: { ProductoRow },
computed: {
...mapState('barrio',["devoluciones_habilitadas"]),
...mapState('pedido',[
"productos",
"total",
"total_transporte",
"cantidad_transporte",
"devoluciones_total",
"devoluciones_notas",
]),
notas_abreviadas() {
return this.devoluciones_notas.substring(0, 15) + (this.devoluciones_notas.length > 15 ? "..." : "");
},
mostrar_tabla() {
return this.productos?.length !== 0;
export default {
components: {ProductoRow},
data() {
return {
mostrar_tabla: false,
cantidad_bonos_transporte: 0,
total_bonos_transporte: 0,
devoluciones: 0,
notas_devoluciones: "",
notas_devoluciones_abbr: "",
total: 0,
productos: [],
}
},
mounted() {
Event.$on('pedido-actualizado', this.pedidoActualizado);
Event.$on('toggle-chismosa', this.pedidoActualizado);
},
methods: {
...mapMutations('ui',["toggleDevoluciones"]),
pedidoActualizado: function() {
this.mostrar_tabla = this.$root.productos.length > 0;
this.cantidad_bonos_transporte = this.cantidadBonosDeTransporte();
this.total_bonos_transporte = this.totalBonosDeTransporte();
this.devoluciones = this.$root.pedido.devoluciones_total;
this.notas_devoluciones = this.$root.pedido.devoluciones_notas;
this.notas_devoluciones_abbr = this.notas_devoluciones.substring(0, 15);
if (this.notas_devoluciones.length > 15) {
this.notas_devoluciones_abbr += "...";
}
this.total = this.$root.pedido.total;
this.productos = this.$root.productos;
},
}
modificarDevoluciones: function() {
Event.$emit("modificar-devoluciones");
},
cantidadBonosDeTransporte: function() {
return this.$root.pedido.cantidad_transporte;
},
totalBonosDeTransporte: function() {
return this.$root.pedido.total_transporte
},
},
}
</script>
<style>
.tabla-chismosa {
.tabla-chismosa {
width: 100%;
}
.fixed-right {
}
.fixed-right {
position: fixed;
overflow-y: auto;
max-height: 81vh;
margin-right: 20px;
}
}
</style>

View file

@ -1,7 +1,7 @@
<template>
<div class="dropdown is-right navbar-item" :class="{'is-active': show_chismosa}">
<div class="dropdown is-right navbar-item" :class="{'is-active':activa}">
<div class="dropdown-trigger">
<a class="text-a" aria-haspopup="true" :aria-controls="ariaControls" @click.capture="toggleChismosa">
<a class="text-a" aria-haspopup="true" :aria-controls="id" @click.capture="toggle">
<span class="icon is-small mr-1">
<img src="/assets/chismosa.png">
</span>
@ -13,23 +13,33 @@
<script>
import Chismosa from './Chismosa.vue'
import { mapMutations, mapState } from "vuex";
export default {
components: {
Chismosa
},
props: {
ariaControls: {
id: {
type: String,
required: true
}
},
computed: {
...mapState('pedido',["total"]),
...mapState('ui',["show_chismosa"]),
data() {
return {
activa: false,
total: 0,
}
},
mounted() {
Event.$on('pedido-actualizado', this.actualizar);
},
methods: {
...mapMutations('ui',["toggleChismosa"]),
toggle() {
this.activa = !this.activa;
Event.$emit("toggle-chismosa", this.activa);
},
actualizar() {
this.total = this.$root.pedido.total;
},
},
}
</script>

View file

@ -1,71 +1,67 @@
<template>
<div :class="show_devoluciones ? 'is-active modal' : 'modal'">
<div v-bind:class="visible ? 'is-active modal' : 'modal'">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Devoluciones</p>
<button class="delete" aria-label="close" @click.capture="toggleDevoluciones()"></button>
<button class="delete" aria-label="close" @click.capture="cerrar"></button>
</header>
<section class="modal-card-body">
<div class="field has-addons is-centered is-thin-centered">
<p class="control">
Total:
<input id="totalControl" class="input" type="number" v-model="totalControl"
style="text-align: center">
<input id="total" class="input" type="number" v-model="total" style="text-align: center">
</p>
</div>
<div class="field has-addons is-centered is-thin-centered">
<p class="control">
Notas:
<input id="notasControl" class="input" type="text" v-model.text="notasControl">
<input id="notas" class="input" type="text" v-model.text="notas">
</p>
</div>
</section>
<footer class="modal-card-foot">
<button class="button is-success" @click="modificar">Aceptar</button>
<button class="button" @click.capture="toggleDevoluciones()">Cancelar</button>
<button class="button" @click.capture="cerrar">Cancelar</button>
</footer>
</div>
</div>
</template>
<script>
import { mapActions, mapMutations, mapState } from "vuex";
export default {
name: 'DevolucionesModal',
export default {
data() {
return {
totalControl: 0,
notasControl: "",
}
},
mounted() {
this.actualizar();
},
watch: {
cantidadEnChismosa() {
this.actualizar();
},
notasEnChismosa() {
this.actualizar();
visible: false,
total: 0,
notas: "",
}
},
computed: {
...mapState('ui', ["show_devoluciones"]),
...mapState('pedido', ["devoluciones_total", "devoluciones_notas"])
miga: function() {
return {
nombre: "Devoluciones",
href: "#devoluciones",
}
},
},
methods: {
...mapMutations('ui', ["toggleDevoluciones"]),
...mapActions('pedido', ["modificarDevoluciones"]),
cerrar() {
this.visible = false;
Event.$emit("migas-pop");
},
modificar() {
this.modificarDevoluciones({ monto: this.totalControl, notas: this.notasControl });
this.toggleDevoluciones();
Event.$emit('sync-devoluciones', this.total, this.notas);
this.cerrar();
}
},
actualizar() {
this.totalControl = this.devoluciones_total;
this.notasControl = this.devoluciones_notas;
mounted() {
Event.$on('modificar-devoluciones', () => {
this.visible = true;
this.total = this.$root.pedido.devoluciones_total;
this.notas = this.$root.pedido.devoluciones_notas;
Event.$emit("migas-agregar", this.miga);
});
},
},
}
}
</script>

View file

@ -3,7 +3,7 @@
aria-label="breadcrumbs" v-show="visible">
<ul class="mt-4">
<li v-for="(miga, i) in migas" :key="i" :class="{'is-active': i === migaActiva}">
<a @click="clickMiga({ miga: miga })" v-text="miga.nombre"
<a :href="miga.href" v-text="miga.nombre"
:class="{'has-text-danger': i !== migaActiva}"></a>
</li>
</ul>
@ -11,23 +11,39 @@
</template>
<script>
import { mapActions, mapGetters, mapState } from "vuex";
import { mapGetters } from "vuex";
export default {
methods: {
...mapActions('productos',["getProductos"]),
...mapActions('ui',["clickMiga"]),
data() {
return {
initial: [{ nombre: 'Categorías', href: '/productos' }],
migas: [{ nombre: 'Categorías', href: '/productos' }],
}
},
computed: {
...mapState('ui',["migas"]),
...mapGetters('pedido',["pedidoDefinido"]),
visible() {
...mapGetters('pedido', ["pedidoDefinido"]),
visible: function () {
return this.migas.length > 0
},
migaActiva() {
migaActiva: function () {
return this.migas.length - 1
}
},
mounted() {
Event.$on('migas-setear-como-inicio', (miga) => {
this.migas = [];
this.migas.push(miga);
});
Event.$on('migas-agregar', (miga) => {
this.migas.push(miga);
});
Event.$on('migas-reset', () => {
this.migas = this.initial;
});
Event.$on('migas-pop', () => {
this.migas.pop();
});
}
}
</script>

View file

@ -1,36 +0,0 @@
<script >
import { defineComponent } from "vue";
import { mapActions, mapState } from "vuex";
import SubpedidoSelect from "./SubpedidoSelect.vue";
import CategoriasContainer from "./CategoriasContainer.vue";
import ProductosContainer from "./ProductosContainer.vue";
import Chismosa from "./Chismosa.vue";
import DevolucionesModal from "./DevolucionesModal.vue";
import CartelPedidoAprobado from "./CartelPedidoAprobado.vue";
export default defineComponent({
components: { CartelPedidoAprobado, DevolucionesModal, SubpedidoSelect, CategoriasContainer, ProductosContainer, Chismosa },
computed: {
...mapState('ui',["show_chismosa","show_devoluciones"])
},
methods: {
...mapActions('productos',["init"]),
},
async mounted() {
await this.init();
},
})
</script>
<template>
<div class="columns ml-3 mr-3" v-else>
<categorias-container :class="show_chismosa ? 'hide-below-1024' : ''"></categorias-container>
<productos-container :class="show_chismosa ? 'hide-below-1024' : ''"></productos-container>
<chismosa v-show="show_chismosa"></chismosa>
<devoluciones-modal v-show="show_devoluciones"></devoluciones-modal>
</div>
</template>
<style scoped>
</style>

View file

@ -1,26 +0,0 @@
<script>
import { defineComponent } from "vue";
import SubpedidoSelect from "./SubpedidoSelect.vue";
import { mapGetters } from "vuex";
export default defineComponent({
components: { SubpedidoSelect },
})
</script>
<template>
<section class="section">
<div id="root" class="container">
<h1 class="title">
Pedidos MPS
</h1>
<p class="subtitle">
Bienvenidx a la aplicación de pedidos del <strong>Mercado Popular de Subsistencia</strong>
</p>
<subpedido-select></subpedido-select>
</div>
</section>
</template>
<style scoped>
</style>

View file

@ -7,31 +7,29 @@
</button>
</div>
<div class="control">
<input id="cantidad" v-model="cantidadControl" class="input is-small" type="number"
style="text-align: center">
<input id="cantidad" v-model="cantidad" class="input is-small" type="number" style="text-align: center">
</div>
<div class="control" @click="incrementar();">
<button class="button is-small">
<i class="fa fa-solid fa-plus"></i>
</button>
</div>
<button :disabled="!hayCambios" class="button is-small is-success ml-1" @click="confirmar()">
<button :disabled="disableConfirm()" class="button is-small is-success ml-1" @click="confirmar()">
<span class="icon">
<i class="fas fa-check"></i>
</span>
</button>
<button :disabled="!puedeBorrar" class="button is-small is-danger ml-1" @click="borrar()">
<button :disabled="!puedeBorrar()" class="button is-small is-danger ml-1" @click="borrar()">
<span class="icon">
<i class="fas fa-trash-alt"></i>
</span>
</button>
</div>
<div v-if="requiere_notas" :class="{'has-icons-right': notas_warning_visible}"
class="control is-full-width has-icons-left">
<div v-if="producto.requiere_notas" v-bind:class="{'has-icons-right': notas_warning_visible}" class="control is-full-width has-icons-left">
<span class="icon is-small is-left">
<i class="fas fa-sticky-note"></i>
</span>
<input v-model="notasControl" v-bind:class="{'is-danger': notas_warning_visible}" id="notas" class="input" type="text" placeholder="Talle o color"/>
<input v-model="notas" v-bind:class="{'is-danger': notas_warning_visible}" id="notas" class="input" type="text" placeholder="Talle o color" />
<span v-if="notas_warning_visible" class="icon is-small is-right">
<i class="fas fa-exclamation-triangle"></i>
</span>
@ -45,110 +43,98 @@
</template>
<script>
import { mapActions, mapGetters } from "vuex";
export default {
export default {
props: {
producto_id: {
type: Number,
required: true,
},
requiere_notas: {
type: Number,
required: true,
}
producto: Object
},
data() {
return {
cantidadControl: 0,
notasControl: '',
cantidad: this.cantidadEnChismosa(),
notas: this.notasEnChismosa(),
notas_warning_visible: false,
}
},
watch: {
cantidadEnChismosa() {
this.actualizar();
},
notasEnChismosa() {
this.actualizar();
}
},
mounted() {
this.actualizar();
},
computed: {
...mapGetters('pedido', ["enChismosa", "cantidad", "notas"]),
cantidadEnChismosa() {
return this.cantidad(this.producto_id);
},
notasEnChismosa() {
return this.notas(this.producto_id);
},
hayCambios() {
return this.cantidadControl !== this.cantidadEnChismosa || this.notasControl !== this.notasEnChismosa;
},
puedeBorrar() {
return this.enChismosa(this.producto_id);
},
faltaNotas() {
return this.requiere_notas && this.cantidadControl > 0 && !this.notasControl;
},
Event.$on('sync-subpedido', (cantidad, productoId, notas) => {
if (this.producto.id === productoId)
this.sincronizar(cantidad, notas);
});
},
methods: {
...mapActions('pedido', ["modificarChismosa"]),
notasEnChismosa() {
return this.producto.pivot !== undefined ? this.producto.pivot.notas : "";
},
cantidadEnChismosa() {
return this.producto.pivot !== undefined ? this.producto.pivot.cantidad : 0;
},
decrementar() {
this.cantidadControl -= 1;
this.cantidad -= 1;
},
incrementar() {
this.cantidadControl += 1;
this.cantidad += 1;
},
borrar() {
this.cantidadControl = 0;
this.confirmar();
},
async confirmar() {
if (this.faltaNotas) {
confirmar() {
if (this.warningNotas()) {
this.notas_warning_visible = true;
return;
}
await this.modificarChismosa({
producto_id: this.producto_id,
cantidad: this.cantidadControl,
notas: this.notasControl
});
console.log("Emit sync " + this.cantidad + " " + this.notas);
Event.$emit('sync-subpedido', this.cantidad, this.producto.id, this.notas);
},
actualizar() {
this.cantidadControl = this.cantidadEnChismosa;
this.notasControl = this.notasEnChismosa;
borrar() {
this.cantidad = 0;
this.confirmar();
},
sincronizar(cantidad, notas) {
this.notas_warning_visible = false;
this.notas = notas;
this.cantidad = cantidad;
if (this.producto.pivot !== undefined) {
this.producto.pivot.cantidad = cantidad;
this.producto.pivot.notas = notas;
}
},
hayCambios() {
if (this.cantidad != this.cantidadEnChismosa()) return true;
return this.cantidad > 0 && this.notas != this.notasEnChismosa();
},
puedeBorrar() {
return this.cantidadEnChismosa() > 0;
},
warningNotas() {
return this.producto.requiere_notas && this.cantidad > 0 && !this.notas;
},
disableConfirm() {
return !this.hayCambios();
},
}
}
}
</script>
<style>
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
}
/* Firefox */
input[type=number] {
/* Firefox */
input[type=number] {
appearance: textfield;
-moz-appearance: textfield;
}
}
.contador {
.contador {
min-width: 178px;
}
}
.is-danger {
.is-danger {
background-color: #fca697;
}
.is-danger::placeholder {
}
.is-danger::placeholder {
color: #fff;
opacity: 1; /* Firefox */
}
}
</style>

View file

@ -1,25 +1,53 @@
<script>
import ProductoCantidad from "./ProductoCantidad.vue";
import { mapGetters } from "vuex";
export default {
name: "ProductoCard",
components: { ProductoCantidad },
props: {
producto: {
type: Object,
required: true
producto: Object
},
data() {
return {
cantidad: this.producto.cantidad,
enChismosa: this.producto.cantidad,
notas: this.producto.notas,
}
},
computed: {
...mapGetters('pedido',["enChismosa", "cantidad"]),
fuePedido() {
return this.enChismosa(this.producto.id);
mounted() {
Event.$on('sync-subpedido', (cantidad, productoId, notas) => {
if (this.producto.id === productoId)
this.sincronizar(cantidad, notas);
});
},
methods: {
decrementar() {
this.cantidad -= 1;
},
incrementar() {
this.cantidad += 1;
},
confirmar() {
Event.$emit('sync-subpedido', this.cantidad, this.producto.id, this.notas);
},
borrar() {
this.cantidad = 0;
this.confirmar();
},
sincronizar(cantidad, notas) {
this.cantidad = cantidad;
this.producto.cantidad = cantidad;
this.enChismosa = cantidad;
this.notas = notas;
this.producto.notas = notas;
},
hayCambios() {
return this.cantidad !== this.enChismosa || this.notas !== this.producto.notas;
},
puedeBorrar() {
return this.enChismosa > 0;
},
cantidadEnChismosa() {
return this.cantidad(this.producto.id);
}
},
}
</script>
@ -31,7 +59,7 @@ export default {
<p class="title is-6">
{{ producto.nombre }}
</p>
<span class="subtitle is-7 hidden-from-tablet" v-if="fuePedido">{{ cantidadEnChismosa }}</span>
<span class="subtitle is-7 hidden-from-tablet" v-if="enChismosa">{{ enChismosa }} en chismosa</span>
</div>
<div class="column is-one-quarter has-text-right">
<p class="has-text-weight-bold has-text-primary">
@ -45,16 +73,13 @@ export default {
</div>
<footer class="columns">
<div class="column is-three-quarters">
<producto-cantidad
:producto_id="producto.id"
:requiere_notas="producto.requiere_notas">
</producto-cantidad>
<producto-cantidad :producto="producto"></producto-cantidad>
</div>
<div class="column">
<p class="subtitle is-7 is-hidden-mobile" v-if="fuePedido">{{ cantidadEnChismosa }} en chismosa</p>
<p class="subtitle is-7 is-hidden-mobile" v-if="enChismosa > 0">{{ enChismosa }} en chismosa</p>
</div>
</footer>
</div>
</div><!-- END BOX -->
</div>
</template>

View file

@ -2,25 +2,18 @@
<tr>
<td>{{ this.producto.nombre }}</td>
<td class="has-text-right">
<producto-cantidad
:producto_id="producto.id"
:requiere_notas="producto.requiere_notas">
</producto-cantidad>
<producto-cantidad :producto="producto"></producto-cantidad>
</td>
<td class="has-text-right">{{ cantidad(producto.id) }}</td>
<td class="has-text-right">{{ this.producto.pivot.total }}</td>
</tr>
</template>
<script>
import ProductoCantidad from "./ProductoCantidad.vue";
import { mapGetters } from "vuex";
export default {
components: { ProductoCantidad },
props: {
producto: Object
},
computed: {
...mapGetters('pedido',["cantidad"]),
},
}
</script>

View file

@ -1,13 +1,10 @@
<template>
<div v-show="visible" class="column">
<div class="columns is-multiline is-mobile">
<producto-card
v-for="(producto,i) in this.productos"
:key="i"
:producto="producto">
</producto-card>
</div>
</div>
<producto-card v-for="(producto,i) in this.productos" :key="i" :producto="producto">
</producto-card><!-- END BLOCK COLUMN -->
</div><!-- END COLUMNS -->
</div><!-- END CONTAINER -->
</template>
<script>
@ -23,8 +20,8 @@ export default {
},
miga: function () {
return {
nombre: this.filtro.valor,
href: "#" + this.filtro.valor
nombre: this.valor,
href: "#" + this.valor
}
}
},

View file

@ -25,7 +25,7 @@
v-text="subpedidoExistente.nombre"></p>
</div>
<div class="buttons column is-half-mobile is-one-third-desktop is-one-third-tablet">
<button class="button is-danger" @click="elegirPedido({ pedido: subpedidoExistente })">Continuar pedido
<button class="button is-danger" @click="elegirSubpedido(subpedidoExistente)">Continuar pedido
</button>
</div>
</div>
@ -37,7 +37,6 @@
import { mapActions, mapMutations, mapState } from "vuex";
export default {
name: 'SubpedidoSelect',
async mounted() {
await this.getGrupoDeCompra();
},
@ -56,18 +55,33 @@ export default {
},
methods: {
...mapActions('barrio',["getGrupoDeCompra","getPedidos"]),
...mapActions('pedido',["crearPedido","elegirPedido"]),
...mapActions('pedido',["crearPedido"]),
...mapMutations('barrio',["setPedidos"]),
onType() {
if (!this.searchString) {
this.setPedidos([]);
return;
}
this.getPedidos(this.searchString);
},
async submit() {
await this.crearPedido({ nombre: this.searchString, grupo_de_compra_id: this.grupo_de_compra_id });
this.guardarSubpedidoEnSesion({ id: this.pedido_id, nombre: this.nombre });
},
elegirSubpedido(subpedido) {
//lo guardamos en sesion
this.guardarSubpedidoEnSesion(subpedido);
},
guardarSubpedidoEnSesion(subpedido) {
axios.post("/subpedidos/guardar_sesion", {
subpedido: subpedido,
grupo_de_compra_id: this.grupo_de_compra_id
}).then(_ => {
Event.$emit('obtener-sesion')
window.location.href = 'productos';
});
}
}
}
</script>

View file

@ -5,7 +5,6 @@ import login from "./modules/login";
import pedido from "./modules/pedido";
import barrio from "./modules/barrio";
import productos from "./modules/productos";
import ui from "./modules/ui";
Vue.use(Vuex);
@ -16,6 +15,5 @@ export default new Vuex.Store({
pedido,
barrio,
productos,
ui,
},
});

View file

@ -38,12 +38,9 @@ const actions = {
const response = await axios.get('/user/grupo_de_compra');
commit('setState', response.data);
},
async setAprobacionPedido({ commit, dispatch }, { pedido_id, aprobacion }){
async setAprobacionPedido({ commit }, { pedido_id, aprobacion }){
await axios.post("/api/admin/subpedidos/" + pedido_id + "/aprobacion", { aprobacion: aprobacion });
await actions.getGrupoDeCompra({ commit });
dispatch("ui/toast",
{ mensaje: `Pedido ${aprobacion ? '' : 'des' }aprobado con éxito.` },
{ root: true });
},
async toggleCaracteristica({ commit }, { caracteristica_id }) {
await axios.post(`/api/grupos-de-compra/${state.grupo_de_compra_id}/${caracteristica_id}`);

View file

@ -5,7 +5,6 @@ const state = {
grupos_de_compra: null,
region_elegida: null,
grupo_de_compra_elegido: null,
rol: null,
};
const mutations = {
@ -19,9 +18,6 @@ const mutations = {
selectGrupoDeCompra(state, { grupo_de_compra }) {
state.grupo_de_compra_elegido = grupo_de_compra;
},
setRol(state, { rol }) {
state.rol = rol;
},
};
const actions = {
@ -32,21 +28,17 @@ const actions = {
async selectRegion({ commit }, { region }) {
const response = await axios.get("/api/grupos-de-compra");
commit('setRegionYBarrios', { region: region, grupos_de_compra: response.data[region] });
},
async getRol({ commit }) {
const response = await axios.get("/user/rol");
commit('setRol', { rol: response.data.rol });
}
};
const getters = {
adminUrl() {
admin() {
return window.location.pathname.startsWith('/admin');
},
mensajes() {
return {
mensaje: `Contraseña de ${getters.adminUrl() ? 'administración ' : ''}del barrio`,
ayuda: `Si no la sabés, consultá a ${getters.adminUrl() ? 'la comisión informática ' : 'tus compañerxs'}.`
mensaje: `Contraseña de ${getters.admin() ? 'administración ' : ''}del barrio`,
ayuda: `Si no la sabés, consultá a ${getters.admin() ? 'la comisión informática ' : 'tus compañerxs'}.`
};
},
};

View file

@ -1,5 +1,3 @@
import axios from "axios";
const state = {
lastFetch: null,
pedido_id: null,
@ -36,52 +34,20 @@ const actions = {
nombre: nombre,
grupo_de_compra_id: grupo_de_compra_id
});
commit('setState', response.data);
},
async getPedido({ commit }, pedido_id) {
const response = await axios.get(`/api/subpedidos/${pedido_id}`);
commit('setState', response.data.data);
},
async elegirPedido({ commit }, { pedido }) {
const response = await axios.get(`/api/subpedidos/${pedido.id}`);
commit('setState', response.data.data);
},
async modificarChismosa({ commit, dispatch }, { producto_id, cantidad, notas }) {
try {
const response = await axios.post("/api/subpedidos/" + state.pedido_id + "/sync", {
cantidad: cantidad,
producto_id: producto_id,
notas: notas,
});
commit('setState', response.data.data);
dispatch("ui/toast", { mensaje: 'Pedido modificado con éxito' }, { root: true });
} catch (error) {
dispatch("ui/error", { error: error }, { root: true });
}
},
async modificarDevoluciones({ commit, dispatch }, { monto, notas }) {
try {
const response = await axios.post("api/subpedidos/" + state.pedido_id + "/sync_devoluciones", {
total: monto,
notas: notas,
});
commit('setState', response.data.data);
dispatch("ui/toast", { mensaje: 'Devoluciones modificadas con éxito' }, { root: true });
} catch (error) {
dispatch("ui/error", { error: error }, { root: true });
}
},
async modificarChismosa({ commit }, producto_id, cantidad, notas) {},
async modificarDevoluciones({ commit }, monto, notas) {}
};
const getters = {
pedidoDefinido() {
return state.lastFetch !== null;
},
enChismosa() {
return ((producto_id) => state.productos.some(p => p.id === producto_id));
},
cantidad() {
return ((producto_id) => state.productos.find(p => p.id === producto_id)?.pivot.cantidad ?? 0);
},
notas() {
return ((producto_id) => state.productos.find(p => p.id === producto_id)?.pivot.notas ?? "");
}
}
export default {

View file

@ -1,48 +0,0 @@
import { dropWhile } from "lodash/array";
const state = {
show_chismosa: false,
show_devoluciones: false,
miga_inicial: { nombre: 'Categorias', action: 'productos/getProductos' },
migas: [{ nombre: 'Categorias', action: 'productos/getProductos' }],
};
const mutations = {
toggleChismosa(state) {
state.show_chismosa = !state.show_chismosa;
},
toggleDevoluciones(state) {
state.show_devoluciones = !state.show_devoluciones;
},
addMiga(state, miga) {
state.migas.push(miga);
},
};
const actions = {
clickMiga({ dispatch }, { miga }) {
dispatch(miga.action, null, { root: true });
state.migas = dropWhile(state.migas.reverse(),(m => m.nombre !== miga.nombre)).reverse();
},
toast(_, { mensaje }) {
return window.bulmaToast.toast({
message: mensaje,
duration: 2000,
type: 'is-danger',
position: 'bottom-center',
});
},
error({ dispatch }, { error }) {
const errorMsg = error.response && error.response.data && error.response.data.message
? error.response.data.message
: error.message;
dispatch("toast", { mensaje: errorMsg });
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};

View file

@ -7,7 +7,7 @@
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Pedidos del MPS') }}</title>
<title>{{ session("subpedido_nombre") ? "Pedido de " . session("subpedido_nombre") . " - " . config('app.name', 'Pedidos del MPS') : config('app.name', 'Pedidos del MPS')}}</title>
<link rel="icon" type="image/x-icon" href="/assets/favicon.png">
<!-- Fonts -->
@ -26,6 +26,7 @@
</comunes-nav-bar>
<pedidos-nav-migas></pedidos-nav-migas>
<main id="main" class="py-4 has-top-padding">
<pedidos-cartel-pedido-aprobado></pedidos-cartel-pedido-aprobado>
@yield('content')
</main>
</div>

View file

@ -1,8 +0,0 @@
@extends('layouts.app')
@section('content')
<app-main></app-main>
@endsection
@section('scripts')
@endsection

View file

@ -1,7 +1,17 @@
@extends('layouts.app')
@section('content')
<app-main></app-main>
<section class="section">
<div id="root" class="container">
<h1 class="title">
Pedidos MPS
</h1>
<p class="subtitle">
Bienvenidx a la aplicación de pedidos del <strong>Mercado Popular de Subsistencia</strong>
</p>
<pedidos-subpedido-select></pedidos-subpedido-select>
</div>
</section>
@endsection
@section('scripts')

View file

@ -25,16 +25,13 @@ Auth::routes(['register' => false]);
Route::get('/', 'RouteController@home')->name('home');
Route::middleware(['auth'])->group(function () {
Route::get('/user/rol', 'UserController@rol')->name('user.rol');
Route::get('/user/grupo_de_compra', 'UserController@grupoDeCompra');
});
Route::middleware(['auth', 'role:barrio'])->group(function() {
Route::get('/pedido', 'RouteController@main')->name('pedido');
Route::middleware(['auth', 'role:barrio'])->group( function() {
Route::get('/productos', 'ProductoController@index')->name('productos.index');
Route::name('subpedidos.')->prefix("subpedidos")->group(function() {
Route::name('subpedidos.')->prefix("subpedidos")->group( function() {
Route::get('/', function() {
return view('subpedidos_create');
})->name('create');
@ -71,8 +68,8 @@ Route::middleware(['auth', 'role:barrio'])->group(function() {
Route::get('/admin/login', 'AdminController@show')->name('admin.login');
Route::middleware(['auth', 'role:admin_barrio'])->group(function () {
Route::get('/admin', 'RouteController@main')->name('admin');
Route::middleware(['auth', 'role:admin_barrio'])->group( function () {
Route::get('/admin', 'AdminController@index')->name('admin.pedidos');
Route::get('/admin/exportar-planillas-a-pdf/{gdc}', 'AdminController@exportarPedidosAPdf');
@ -84,7 +81,7 @@ Route::middleware(['auth', 'role:admin_barrio'])->group(function () {
Route::get('/compras/login', 'ComprasController@show')->name('compras.login');
Route::middleware(['auth', 'role:comision'])->group( function() {
Route::get('/compras', 'RouteController@main')->name('compras');
Route::get('/compras', 'ComprasController@indexPedidos')->name('compras.pedidos');
Route::get('/compras/pedidos/descargar', 'ComprasController@descargarPedidos')->name('compras.pedidos.descargar');
Route::get('/compras/pedidos/notas', 'ComprasController@descargarNotas')->name('compras.pedidos.descargar');
Route::get('/compras/pedidos/pdf', 'ComprasController@pdf')->name('compras.pedidos.pdf');