Compare commits

..

No commits in common. "45757f0ae1da319c21b2a60672f7d0a3c5d21d63" and "641eb6a4d33b11f69b65db1fcd3b1e3f591775bb" have entirely different histories.

10 changed files with 124 additions and 106 deletions

View file

@ -52,15 +52,6 @@ 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

@ -1,19 +0,0 @@
<?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

@ -1,30 +0,0 @@
<?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,17 +14,18 @@ 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' => number_format($this->total(),2), 'total' => $total,
'total_transporte' => number_format($this->totalTransporte(),0), 'total_transporte' => $this->totalTransporte(),
'cantidad_transporte' => number_format($this->cantidadTransporte(),0), 'cantidad_transporte' => number_format($this->cantidadTransporte(),0),
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2), 'total_menos_devoluciones' => $total - $this->devoluciones_total,
'devoluciones_total' => number_format($this->devoluciones_total,2), 'devoluciones_total' => $this->devoluciones_total,
'devoluciones_notas' => $this->devoluciones_notas 'devoluciones_notas' => $this->devoluciones_notas
]; ];
} }

View file

@ -3,18 +3,27 @@
<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-if="hayPedidos"> <div class="block pb-6" id="pedidos-tabla-y-dropdown" v-show="hayPedidos">
<admin-dropdown-descargar <admin-dropdown-descargar
:gdc_id="gdc.id"> :gdc="gdc">
</admin-dropdown-descargar> </admin-dropdown-descargar>
<admin-tabla-pedidos <admin-tabla-pedidos
:gdc="this.gdc" :pedidos="pedidos" :bonosDeTransporte="bonosDeTransporte" :totalBonosBarriales="totalBonosBarriales">
></admin-tabla-pedidos> </admin-tabla-pedidos>
</div> </div>
<p class="has-text-centered" v-else> <p class="has-text-centered" v-show="!hayPedidos">
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>
@ -29,7 +38,6 @@ 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,
@ -40,8 +48,12 @@ export default {
}, },
data() { data() {
return { return {
gdc: undefined, gdc: 0,
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",
@ -49,32 +61,46 @@ export default {
}, },
computed: { computed: {
hayPedidos: function() { hayPedidos: function() {
return this.gdc && this.gdc.pedidos.length !== 0 return this.pedidos.length !== 0
}, },
hayAprobados: function() { hayAprobados: function() {
return this.gdc && this.gdc.pedidos.filter(p => p.aprobado).length > 0 return this.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";
}, },
actualizar() { getBonosBarriales() {
axios.get('/api/grupos-de-compra/' + this.$root.gdc) axios.get("/api/grupos-de-compra/"+this.gdc+"/bonos-barriales", {})
.then(response => { .then(response => this.totalBonosBarriales = response.data.bonos_barriales)
this.gdc = response.data.data;
console.log(this.gdc);
})
} }
}, },
async mounted() { mounted() {
Event.$on('sync-aprobacion', (_) => { Event.$on('sync-aprobacion', (_) => {
this.actualizar(); this.fetchPedidos();
}); });
await new Promise(r => setTimeout(r, 1000));
this.actualizar(); axios.get("/admin/obtener_sesion").then(response => {
}, 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_id" class="dropdown-item has-background-primary"> <a :href="'/admin/exportar-pedido-a-csv/' + gdc" class="dropdown-item has-background-primary">
Planilla para central (CSV) Planilla para central (CSV)
</a> </a>
<a :href="'/admin/exportar-planillas-a-pdf/' + gdc_id" class="dropdown-item"> <a :href="'/admin/exportar-planillas-a-pdf/' + gdc" class="dropdown-item">
Planillas para armado (PDF) Planillas para armado (PDF)
</a> </a>
<a :href="'/admin/exportar-pedido-con-nucleos-a-csv/' + gdc_id" class="dropdown-item"> <a :href="'/admin/exportar-pedido-con-nucleos-a-csv/' + gdc" 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_id: { gdc: {
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.obtenerValor(this);
} }
} }
} }

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_sin_devoluciones }}</td> <td v-if="$root.devoluciones" class="has-text-right" >{{ pedido.total }}</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 : pedido.total_sin_devoluciones }}</td> <td class="has-text-right" >{{ $root.devoluciones ? pedido.total_menos_devoluciones : pedido.total }}</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 gdc.pedidos" v-for="pedido in this.pedidos"
:pedido="pedido" :key="pedido.id"> :pedido="pedido" :key="pedido.id">
</admin-fila-pedido> </admin-fila-pedido>
</tbody> </tbody>
@ -23,27 +23,23 @@
</tr> </tr>
<tr> <tr>
<th>Total a recaudar:</th> <th>Total a recaudar:</th>
<td class="has-text-right">$ {{ gdc.total_a_recaudar }}</td> <td class="has-text-right">$ {{ totalARecaudar }}</td>
</tr> </tr>
<tr> <tr>
<th>Total bonos barriales:</th> <th>Total bonos barriales:</th>
<td class="has-text-right">$ {{ gdc.total_barrial }}</td> <td class="has-text-right">$ {{ $parent.totalBonosBarriales }}</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">- $ {{ gdc.total_devoluciones }}</td> <td class="has-text-right">- $ {{ totalDevoluciones() }}</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">$ {{ gdc.total_transporte }}</td> <td class="has-text-right">$ {{ bonosDeTransporte * 15 }}</td>
</tr> </tr>
<tr> <tr>
<th>Total a depositar:</th> <th>Total a depositar:</th>
<td class="has-text-right">$ {{ gdc.total_a_transferir }}</td> <td class="has-text-right">$ {{ totalAprobadosConTransporteRecalculado() - totalBonosBarriales }}</td>
</tr> </tr>
</table> </table>
</div> </div>
@ -56,11 +52,60 @@ export default {
FilaPedido FilaPedido
}, },
props: { props: {
gdc: { pedidos: {
type: Object, type: Array,
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,14 +28,18 @@ 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) {
Route::get('/{grupoDeCompra}', 'Api\GrupoDeCompraController@show'); $grupo = GrupoDeCompra::where('id',$gdc)->first();
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];