Compare commits

...

10 commits

10 changed files with 106 additions and 124 deletions

View file

@ -52,6 +52,15 @@ class GrupoDeCompra extends Model
return $total; return $total;
} }
public function totalDevoluciones()
{
$total = 0;
foreach ($this->pedidosAprobados() as $subpedido) {
$total = $total + $subpedido->devoluciones_total;
}
return $total;
}
public function totalATransferir() public function totalATransferir()
{ {
return $this->totalCentralesQueNoPaganTransporte() return $this->totalCentralesQueNoPaganTransporte()

View file

@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Api;
use App\GrupoDeCompra;
use App\Http\Controllers\Controller;
use App\Http\Resources\GrupoDeCompraResource;
class GrupoDeCompraController extends Controller
{
public function index()
{
return GrupoDeCompraResource::collection(GrupoDeCompra::all());
}
public function show(GrupoDeCompra $grupoDeCompra)
{
return new GrupoDeCompraResource($grupoDeCompra);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class GrupoDeCompraResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'nombre' => $this->nombre,
'devoluciones_habilitadas' => $this->devoluciones_habilitadas,
'pedidos' => SubpedidoResource::collection($this->subpedidos),
'total_a_recaudar' => number_format($this->totalARecaudar(),2),
'total_barrial' => number_format($this->totalBarrial(),2),
'total_devoluciones' => number_format($this->totalDevoluciones(),2),
'total_a_transferir' => number_format($this->totalATransferir(),2),
'total_transporte' => number_format($this->totalTransporte(),0),
'cantidad_transporte' => number_format($this->cantidadTransporte(),0),
];
}
}

View file

@ -14,18 +14,17 @@ class SubpedidoResource extends JsonResource
*/ */
public function toArray($request) public function toArray($request)
{ {
$total = $this->total();
return [ return [
'id' => $this->id, 'id' => $this->id,
'nombre' => $this->nombre, 'nombre' => $this->nombre,
'grupo_de_compra' => $this->grupoDeCompra, 'grupo_de_compra' => $this->grupoDeCompra,
'productos' => $this->productos, 'productos' => $this->productos,
'aprobado' => (bool) $this->aprobado, 'aprobado' => (bool) $this->aprobado,
'total' => $total, 'total' => number_format($this->total(),2),
'total_transporte' => $this->totalTransporte(), 'total_transporte' => number_format($this->totalTransporte(),0),
'cantidad_transporte' => number_format($this->cantidadTransporte(),0), 'cantidad_transporte' => number_format($this->cantidadTransporte(),0),
'total_menos_devoluciones' => $total - $this->devoluciones_total, 'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
'devoluciones_total' => $this->devoluciones_total, 'devoluciones_total' => number_format($this->devoluciones_total,2),
'devoluciones_notas' => $this->devoluciones_notas 'devoluciones_notas' => $this->devoluciones_notas
]; ];
} }

View file

@ -3,27 +3,18 @@
<comunes-tabs-secciones :tabs="tabs" :tabInicial="tabActiva"></comunes-tabs-secciones> <comunes-tabs-secciones :tabs="tabs" :tabInicial="tabActiva"></comunes-tabs-secciones>
<div class="block" id="pedidos-seccion" <div class="block" id="pedidos-seccion"
:class="seccionActiva === 'pedidos-seccion' ? 'is-active' : 'is-hidden'"> :class="seccionActiva === 'pedidos-seccion' ? 'is-active' : 'is-hidden'">
<div class="block pb-6" id="pedidos-tabla-y-dropdown" v-show="hayPedidos"> <div class="block pb-6" id="pedidos-tabla-y-dropdown" v-if="hayPedidos">
<admin-dropdown-descargar <admin-dropdown-descargar
:gdc="gdc"> :gdc_id="gdc.id">
</admin-dropdown-descargar> </admin-dropdown-descargar>
<admin-tabla-pedidos <admin-tabla-pedidos
:pedidos="pedidos" :bonosDeTransporte="bonosDeTransporte" :totalBonosBarriales="totalBonosBarriales"> :gdc="this.gdc"
</admin-tabla-pedidos> ></admin-tabla-pedidos>
</div> </div>
<p class="has-text-centered" v-show="!hayPedidos"> <p class="has-text-centered" v-else>
Todavía no hay ningún pedido para administrar. Todavía no hay ningún pedido para administrar.
</p> </p>
</div> </div>
<div class="block pb-6" id="bonos-seccion"
:class="seccionActiva === 'bonos-seccion' ? 'is-active' : 'is-hidden'">
<admin-tabla-bonos v-show="hayAprobados"
:pedidos="pedidos">
</admin-tabla-bonos>
<p class="has-text-centered" v-show="!hayAprobados">
Todavía no hay pedidos aprobados.
</p>
</div>
<div class="block pb-6" id="caracteristicas-seccion" <div class="block pb-6" id="caracteristicas-seccion"
:class="seccionActiva === 'caracteristicas-seccion' ? 'is-active' : 'is-hidden'"> :class="seccionActiva === 'caracteristicas-seccion' ? 'is-active' : 'is-hidden'">
<admin-caracteristicas-opcionales> <admin-caracteristicas-opcionales>
@ -38,6 +29,7 @@ import TabsSecciones from "../comunes/TabsSecciones.vue";
import DropdownDescargar from "./DropdownDescargar.vue"; import DropdownDescargar from "./DropdownDescargar.vue";
import TablaPedidos from "./TablaPedidos.vue"; import TablaPedidos from "./TablaPedidos.vue";
import TablaBonos from "./TablaBonos.vue"; import TablaBonos from "./TablaBonos.vue";
import axios from "axios";
export default { export default {
components: { components: {
CaracteristicasOpcionales, CaracteristicasOpcionales,
@ -48,12 +40,8 @@ export default {
}, },
data() { data() {
return { return {
gdc: 0, gdc: undefined,
pedidos: [],
bonosDeTransporte: 0,
totalBonosBarriales: 0,
tabs: [{ id: "pedidos", nombre: "Pedidos" }, tabs: [{ id: "pedidos", nombre: "Pedidos" },
{ id: "bonos", nombre: "Bonos" },
{ id: "caracteristicas", nombre: "Caracteristicas opcionales" }], { id: "caracteristicas", nombre: "Caracteristicas opcionales" }],
tabActiva: "pedidos", tabActiva: "pedidos",
seccionActiva: "pedidos-seccion", seccionActiva: "pedidos-seccion",
@ -61,46 +49,32 @@ export default {
}, },
computed: { computed: {
hayPedidos: function() { hayPedidos: function() {
return this.pedidos.length !== 0 return this.gdc && this.gdc.pedidos.length !== 0
}, },
hayAprobados: function() { hayAprobados: function() {
return this.pedidos.filter(p => p.aprobado).length > 0 return this.gdc && this.gdc.pedidos.filter(p => p.aprobado).length > 0
} }
}, },
methods: { methods: {
fetchPedidos() {
axios.get("/api/grupos-de-compra/"+this.gdc+"/bonos-de-transporte", {})
.then(response => this.bonosDeTransporte = response.data.bdt);
axios.get("/api/subpedidos/resources", {
params: {
grupo_de_compra: this.gdc
}})
.then(response => {
this.pedidos = response.data.data
}).get;
axios.get("/api/grupos-de-compra/"+this.gdc+"/bonos-barriales", {})
.then(response => this.totalBonosBarriales = response.data.bonos_barriales)
},
setSeccionActiva(tabId) { setSeccionActiva(tabId) {
this.tabActiva = tabId; this.tabActiva = tabId;
this.seccionActiva = tabId + "-seccion"; this.seccionActiva = tabId + "-seccion";
}, },
getBonosBarriales() { actualizar() {
axios.get("/api/grupos-de-compra/"+this.gdc+"/bonos-barriales", {}) axios.get('/api/grupos-de-compra/' + this.$root.gdc)
.then(response => this.totalBonosBarriales = response.data.bonos_barriales) .then(response => {
this.gdc = response.data.data;
console.log(this.gdc);
})
} }
}, },
mounted() { async mounted() {
Event.$on('sync-aprobacion', (_) => { Event.$on('sync-aprobacion', (_) => {
this.fetchPedidos(); this.actualizar();
}); });
await new Promise(r => setTimeout(r, 1000));
axios.get("/admin/obtener_sesion").then(response => { this.actualizar();
this.gdc = response.data.gdc; },
this.fetchPedidos();
this.bonosBarriales = this.getBonosBarriales()
});
}
} }
</script> </script>

View file

@ -14,13 +14,13 @@
</div> </div>
<div class="dropdown-menu" id="dropdown-menu" role="menu"> <div class="dropdown-menu" id="dropdown-menu" role="menu">
<div class="dropdown-content"> <div class="dropdown-content">
<a :href="'/admin/exportar-pedido-a-csv/' + gdc" class="dropdown-item has-background-primary"> <a :href="'/admin/exportar-pedido-a-csv/' + gdc_id" class="dropdown-item has-background-primary">
Planilla para central (CSV) Planilla para central (CSV)
</a> </a>
<a :href="'/admin/exportar-planillas-a-pdf/' + gdc" class="dropdown-item"> <a :href="'/admin/exportar-planillas-a-pdf/' + gdc_id" class="dropdown-item">
Planillas para armado (PDF) Planillas para armado (PDF)
</a> </a>
<a :href="'/admin/exportar-pedido-con-nucleos-a-csv/' + gdc" class="dropdown-item"> <a :href="'/admin/exportar-pedido-con-nucleos-a-csv/' + gdc_id" class="dropdown-item">
Planilla completa de la canasta (CSV) Planilla completa de la canasta (CSV)
</a> </a>
</div> </div>
@ -32,7 +32,7 @@
<script> <script>
export default { export default {
props: { props: {
gdc: { gdc_id: {
type: Number, type: Number,
required: true required: true
}, },

View file

@ -41,7 +41,7 @@ export default {
mounted() { mounted() {
if (this.$root.gdc) { if (this.$root.gdc) {
this.gdc = this.$root.gdc; this.gdc = this.$root.gdc;
this.obtenerValor(this); this.obtenerValor();
} }
} }
} }

View file

@ -1,9 +1,9 @@
<template> <template>
<tr> <tr>
<td>{{ pedido.nombre }}</td> <td>{{ pedido.nombre }}</td>
<td v-if="$root.devoluciones" class="has-text-right" >{{ pedido.total }}</td> <td v-if="$root.devoluciones" class="has-text-right" >{{ pedido.total_sin_devoluciones }}</td>
<td v-if="$root.devoluciones" class="has-text-right" ><abbr :title="pedido.devoluciones_notas">-{{ pedido.devoluciones_total }}</abbr></td> <td v-if="$root.devoluciones" class="has-text-right" ><abbr :title="pedido.devoluciones_notas">-{{ pedido.devoluciones_total }}</abbr></td>
<td class="has-text-right" >{{ $root.devoluciones ? pedido.total_menos_devoluciones : pedido.total }}</td> <td class="has-text-right" >{{ $root.devoluciones ? pedido.total : pedido.total_sin_devoluciones }}</td>
<td> <td>
<admin-switch-aprobacion <admin-switch-aprobacion
:pedido="pedido"> :pedido="pedido">

View file

@ -12,7 +12,7 @@
</thead> </thead>
<tbody> <tbody>
<admin-fila-pedido <admin-fila-pedido
v-for="pedido in this.pedidos" v-for="pedido in gdc.pedidos"
:pedido="pedido" :key="pedido.id"> :pedido="pedido" :key="pedido.id">
</admin-fila-pedido> </admin-fila-pedido>
</tbody> </tbody>
@ -23,23 +23,27 @@
</tr> </tr>
<tr> <tr>
<th>Total a recaudar:</th> <th>Total a recaudar:</th>
<td class="has-text-right">$ {{ totalARecaudar }}</td> <td class="has-text-right">$ {{ gdc.total_a_recaudar }}</td>
</tr> </tr>
<tr> <tr>
<th>Total bonos barriales:</th> <th>Total bonos barriales:</th>
<td class="has-text-right">$ {{ $parent.totalBonosBarriales }}</td> <td class="has-text-right">$ {{ gdc.total_barrial }}</td>
</tr> </tr>
<tr v-if="$root.devoluciones"> <tr v-if="$root.devoluciones">
<th>Total devoluciones:</th> <th>Total devoluciones:</th>
<td class="has-text-right">- $ {{ totalDevoluciones() }}</td> <td class="has-text-right">- $ {{ gdc.total_devoluciones }}</td>
</tr>
<tr>
<th>Cantidad bonos de transporte:</th>
<td class="has-text-right">{{ gdc.cantidad_transporte }}</td>
</tr> </tr>
<tr> <tr>
<th>Total bonos de transporte:</th> <th>Total bonos de transporte:</th>
<td class="has-text-right">$ {{ bonosDeTransporte * 15 }}</td> <td class="has-text-right">$ {{ gdc.total_transporte }}</td>
</tr> </tr>
<tr> <tr>
<th>Total a depositar:</th> <th>Total a depositar:</th>
<td class="has-text-right">$ {{ totalAprobadosConTransporteRecalculado() - totalBonosBarriales }}</td> <td class="has-text-right">$ {{ gdc.total_a_transferir }}</td>
</tr> </tr>
</table> </table>
</div> </div>
@ -52,60 +56,11 @@ export default {
FilaPedido FilaPedido
}, },
props: { props: {
pedidos: { gdc: {
type: Array, type: Object,
required: true required: true
},
bonosDeTransporte: {
type: Number,
required: true
},
totalBonosBarriales: {
type: Number,
required: true
},
},
computed: {
totalARecaudar: function() {
return this.$root.devoluciones ? this.totalAprobadosMenosDevoluciones() : this.totalAprobados();
},
},
methods: {
totalDevoluciones() {
let suma = 0
let aprobados = this.pedidos.filter(p => p.aprobado);
for (let i = 0; i < aprobados.length; i++) {
suma += aprobados[i].devoluciones_total
}
return suma;
},
totalAprobados() {
let suma = 0
let aprobados = this.pedidos.filter(p => p.aprobado);
for (let i = 0; i < aprobados.length; i++) {
suma += this.$limpiarFloat(aprobados[i].total)
}
return suma;
},
totalAprobadosMenosDevoluciones() {
let suma = 0
let aprobados = this.pedidos.filter(p => p.aprobado);
for (let i = 0; i < aprobados.length; i++) {
suma += this.$limpiarFloat(aprobados[i].total_menos_devoluciones)
}
return suma;
},
totalAprobadosConTransporteRecalculado() {
let suma = 0
let aprobados = this.pedidos.filter(p => p.aprobado);
for (let i = 0; i < aprobados.length; i++) {
suma += this.$limpiarFloat(aprobados[i].total)
suma -= this.$limpiarFloat(aprobados[i].subtotal_bonos_de_transporte)
}
suma += parseInt(this.bonosDeTransporte)*15
return suma;
} }
}, }
} }
</script> </script>

View file

@ -28,18 +28,14 @@ Route::middleware('api')->group(function () {
$atributos_a_ocultar = ['telefono', 'cantidad_de_nucleos', 'correo', 'referente_finanzas', 'created_at', 'updated_at']; $atributos_a_ocultar = ['telefono', 'cantidad_de_nucleos', 'correo', 'referente_finanzas', 'created_at', 'updated_at'];
return GrupoDeCompra::all()->makeHidden($atributos_a_ocultar)->sortBy('nombre')->groupBy('region'); return GrupoDeCompra::all()->makeHidden($atributos_a_ocultar)->sortBy('nombre')->groupBy('region');
}); });
Route::get('/{gdc}/bonos-de-transporte', function($gdc) {
$grupo = GrupoDeCompra::where('id',$gdc)->first(); Route::get('/{grupoDeCompra}', 'Api\GrupoDeCompraController@show');
return ['bdt' => $grupo->calcularCantidadBDT()];
});
Route::get('/{gdc}/bonos-barriales', function($gdc) {
$grupo = GrupoDeCompra::where('id',$gdc)->first();
return ['bonos_barriales' => $grupo->totalBonosBarriales()];
});
Route::get('/{gdc}/devoluciones', function($gdc) { Route::get('/{gdc}/devoluciones', function($gdc) {
$habilitadas = GrupoDeCompra::find($gdc)->devoluciones_habilitadas; $habilitadas = GrupoDeCompra::find($gdc)->devoluciones_habilitadas;
return ['devoluciones' => $habilitadas]; return ['devoluciones' => $habilitadas];
}); });
Route::post('/{gdc}/devoluciones', function($gdc) { Route::post('/{gdc}/devoluciones', function($gdc) {
$habilitadas = GrupoDeCompra::find($gdc)->toggleDevoluciones(); $habilitadas = GrupoDeCompra::find($gdc)->toggleDevoluciones();
return ['devoluciones' => $habilitadas]; return ['devoluciones' => $habilitadas];