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;
}
public function totalDevoluciones()
{
$total = 0;
foreach ($this->pedidosAprobados() as $subpedido) {
$total = $total + $subpedido->devoluciones_total;
}
return $total;
}
public function totalATransferir()
{
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)
{
$total = $this->total();
return [
'id' => $this->id,
'nombre' => $this->nombre,
'grupo_de_compra' => $this->grupoDeCompra,
'productos' => $this->productos,
'aprobado' => (bool) $this->aprobado,
'total' => $total,
'total_transporte' => $this->totalTransporte(),
'total' => number_format($this->total(),2),
'total_transporte' => number_format($this->totalTransporte(),0),
'cantidad_transporte' => number_format($this->cantidadTransporte(),0),
'total_menos_devoluciones' => $total - $this->devoluciones_total,
'devoluciones_total' => $this->devoluciones_total,
'total_sin_devoluciones' => number_format($this->totalSinDevoluciones(),2),
'devoluciones_total' => number_format($this->devoluciones_total,2),
'devoluciones_notas' => $this->devoluciones_notas
];
}

View file

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

View file

@ -14,13 +14,13 @@
</div>
<div class="dropdown-menu" id="dropdown-menu" role="menu">
<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)
</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)
</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)
</a>
</div>
@ -32,7 +32,7 @@
<script>
export default {
props: {
gdc: {
gdc_id: {
type: Number,
required: true
},

View file

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

View file

@ -1,9 +1,9 @@
<template>
<tr>
<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 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>
<admin-switch-aprobacion
:pedido="pedido">

View file

@ -12,7 +12,7 @@
</thead>
<tbody>
<admin-fila-pedido
v-for="pedido in this.pedidos"
v-for="pedido in gdc.pedidos"
:pedido="pedido" :key="pedido.id">
</admin-fila-pedido>
</tbody>
@ -23,23 +23,27 @@
</tr>
<tr>
<th>Total a recaudar:</th>
<td class="has-text-right">$ {{ totalARecaudar }}</td>
<td class="has-text-right">$ {{ gdc.total_a_recaudar }}</td>
</tr>
<tr>
<th>Total bonos barriales:</th>
<td class="has-text-right">$ {{ $parent.totalBonosBarriales }}</td>
<td class="has-text-right">$ {{ gdc.total_barrial }}</td>
</tr>
<tr v-if="$root.devoluciones">
<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>
<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>
<th>Total a depositar:</th>
<td class="has-text-right">$ {{ totalAprobadosConTransporteRecalculado() - totalBonosBarriales }}</td>
<td class="has-text-right">$ {{ gdc.total_a_transferir }}</td>
</tr>
</table>
</div>
@ -52,60 +56,11 @@ export default {
FilaPedido
},
props: {
pedidos: {
type: Array,
gdc: {
type: Object,
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>

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'];
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();
return ['bdt' => $grupo->calcularCantidadBDT()];
});
Route::get('/{gdc}/bonos-barriales', function($gdc) {
$grupo = GrupoDeCompra::where('id',$gdc)->first();
return ['bonos_barriales' => $grupo->totalBonosBarriales()];
});
Route::get('/{grupoDeCompra}', 'Api\GrupoDeCompraController@show');
Route::get('/{gdc}/devoluciones', function($gdc) {
$habilitadas = GrupoDeCompra::find($gdc)->devoluciones_habilitadas;
return ['devoluciones' => $habilitadas];
});
Route::post('/{gdc}/devoluciones', function($gdc) {
$habilitadas = GrupoDeCompra::find($gdc)->toggleDevoluciones();
return ['devoluciones' => $habilitadas];