Agregada cantidad de bonos de transporte a planilla de totales

This commit is contained in:
Alejandro Tasistro 2025-05-09 16:57:46 -03:00
parent b1b424897c
commit 9fcdc5a52a
2 changed files with 40 additions and 8 deletions

View file

@ -229,6 +229,28 @@ class GrupoDeCompra extends Model
return array($records, $i, $cantidad);
}
/**
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function barriosMenosPrueba(): \Illuminate\Database\Eloquent\Builder
{
return self::where('nombre', '<>', 'PRUEBA')
->orderBy('region')
->orderBy('nombre');
}
public static function transportePorBarrio()
{
$result = [];
$barrios = GrupoDeCompra::barriosMenosPrueba()->get();
foreach ($barrios as $barrio) {
$result[] = $barrio->cantidadTransporte();
}
return $result;
}
static public function totalesParaTransportePorBarrio() {
return DB::table('grupos_de_compra')
->leftJoin('subpedidos', 'grupos_de_compra.id', '=', 'subpedidos.grupo_de_compra_id')

View file

@ -3,9 +3,11 @@
namespace App;
use App\Filtros\FiltroDeProducto;
use App\Helpers\TransporteHelper;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use League\Csv\CannotInsertRecord;
use League\Csv\Writer;
@ -59,8 +61,7 @@ class Producto extends Model
static public function cantidadesPorBarrio()
{
$barrios = DB::table('grupos_de_compra')
->where('nombre', '<>', 'PRUEBA')
$barrios = GrupoDeCompra::barriosMenosPrueba()
->pluck('id', 'nombre');
$columnasBarrios = $barrios->map(function ($id, $nombre) {
@ -81,22 +82,28 @@ class Producto extends Model
->get();
}
static public function planillaTotales() {
static public function planillaTotales()
{
$headers = ['Producto'];
$barrios = DB::table('grupos_de_compra')
->where('nombre', '<>', 'PRUEBA')
$barrios = GrupoDeCompra::barriosMenosPrueba()
->pluck('nombre')->toArray();
$headers = array_merge($headers, $barrios);
$cantidadesPorBarrio = self::cantidadesPorBarrio();
$transportePorBarrio = GrupoDeCompra::transportePorBarrio();
$planilla = [];
$ultimaFila = 1;
$filaTransporte = TransporteHelper::filaTransporte();
foreach ($cantidadesPorBarrio as $productoCantidades) {
$fila = $productoCantidades->fila;
while ($fila - $ultimaFila > 1) {
$ultimaFila++;
$planilla[$ultimaFila] = ['---'];
if ($ultimaFila == $filaTransporte) {
$planilla[$ultimaFila] = ['Bono de transporte'];
} else {
$planilla[$ultimaFila] = ['---'];
}
}
$planilla[$fila] = [$productoCantidades->producto];
foreach ($barrios as $barrio) {
@ -105,6 +112,10 @@ class Producto extends Model
$ultimaFila = $fila;
}
foreach ($transportePorBarrio as $key => $cantidad) {
$planilla[$filaTransporte][] = $cantidad;
}
try {
$writer = Writer::createFromPath(resource_path('csv/exports/pedidos-por-barrio.csv'), 'w');
$writer->insertOne($headers);
@ -132,8 +143,7 @@ class Producto extends Model
static public function planillaNotas() {
$headers = ['Producto'];
$barrios = DB::table('grupos_de_compra')
->where('nombre', '<>', 'PRUEBA')
$barrios = GrupoDeCompra::barriosMenosPrueba()
->pluck('nombre')->toArray();
$headers = array_merge($headers, $barrios);