Rutas para faltantes y sobrantes

This commit is contained in:
Alejandro Tasistro 2024-12-23 19:04:02 -03:00
parent 27390e4659
commit 6ad00b2de1
3 changed files with 49 additions and 3 deletions

View file

@ -16,6 +16,16 @@ class GrupoDeCompra extends Model
protected $table = 'grupos_de_compra'; protected $table = 'grupos_de_compra';
protected $hidden = ['password']; protected $hidden = ['password'];
public function faltantes()
{
return 'Faltantes de ' . $this->nombre;
}
public function sobrantes()
{
return 'Sobrantes de ' . $this->nombre;
}
public function toggleDevoluciones() public function toggleDevoluciones()
{ {
$this->devoluciones_habilitadas = !$this->devoluciones_habilitadas; $this->devoluciones_habilitadas = !$this->devoluciones_habilitadas;

View file

@ -9,39 +9,67 @@
</tabs-secciones> </tabs-secciones>
<div class="block pb-6" id="faltantes-seccion" <div class="block pb-6" id="faltantes-seccion"
:class="seccionActiva === 'faltantes-seccion' ? 'is-active' : 'is-hidden'"> :class="seccionActiva === 'faltantes-seccion' ? 'is-active' : 'is-hidden'">
<p>Faltantes</p> <p>{{faltantes ?? 'nada aún'}}</p>
</div> </div>
<div class="block pb-6" id="sobrantes-seccion" <div class="block pb-6" id="sobrantes-seccion"
:class="seccionActiva === 'sobrantes-seccion' ? 'is-active' : 'is-hidden'"> :class="seccionActiva === 'sobrantes-seccion' ? 'is-active' : 'is-hidden'">
<p>Sobrantes</p> <p>{{sobrantes ?? 'nada aún'}}</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import axios from "axios";
import TabsSecciones from "../comunes/TabsSecciones.vue"; import TabsSecciones from "../comunes/TabsSecciones.vue";
import Chismosa from "../pedidos/Chismosa.vue";
export default { export default {
name: "FaltantesYSobrantes", name: "FaltantesYSobrantes",
components: { components: {
TabsSecciones, TabsSecciones,
Chismosa,
}, },
data() { data() {
return { return {
gdc: undefined,
tabs: [{ id: "faltantes", nombre: "Faltantes" }, tabs: [{ id: "faltantes", nombre: "Faltantes" },
{ id: "sobrantes", nombre: "Sobrantes" }], { id: "sobrantes", nombre: "Sobrantes" }],
tabActiva: "faltantes", tabActiva: "faltantes",
seccionActiva: "faltantes-seccion", seccionActiva: "faltantes-seccion",
faltantes: undefined,
sobrantes: undefined,
}; };
}, },
watch: {
'$root.gdc' : {
handler(newValue) {
if (newValue) {
this.gdc = newValue;
this.actualizarFaltantes();
this.actualizarSobrantes();
}
}
},
},
methods: { methods: {
setSeccionActiva(tabId) { setSeccionActiva(tabId) {
this.tabActiva = tabId; this.tabActiva = tabId;
this.seccionActiva = tabId + "-seccion"; this.seccionActiva = tabId + "-seccion";
}, },
actualizarFaltantes() {
axios.get(`/api/grupos-de-compra/${this.gdc}/faltantes`)
.then(response => {
this.faltantes = response.data['faltantes'];
})
},
actualizarSobrantes() {
axios.get(`/api/grupos-de-compra/${this.gdc}/sobrantes`)
.then(response => {
this.sobrantes = response.data['sobrantes'];
})
},
} }
} }
</script> </script>

View file

@ -44,6 +44,14 @@ Route::middleware('api')->group(function () {
$habilitadas = GrupoDeCompra::find($gdc)->toggleDevoluciones(); $habilitadas = GrupoDeCompra::find($gdc)->toggleDevoluciones();
return ['devoluciones' => $habilitadas]; return ['devoluciones' => $habilitadas];
}); });
Route::get('/{gdc}/faltantes', function($gdc) {
$faltantes = GrupoDeCompra::find($gdc)->faltantes();
return ['faltantes' => $faltantes];
});
Route::get('/{gdc}/sobrantes', function($gdc) {
$sobrantes = GrupoDeCompra::find($gdc)->sobrantes();
return ['sobrantes' => $sobrantes];
});
}); });
Route::prefix('subpedidos')->group(function () { Route::prefix('subpedidos')->group(function () {