Agregada cantidad de ollas a planilla de ollas

This commit is contained in:
Alejandro Tasistro 2025-07-08 22:46:09 -03:00
parent 7f59b9a2ff
commit cc6fe6878a

View file

@ -3,6 +3,7 @@
namespace App\Helpers;
use App\GrupoDeCompra;
use App\TipoPedido;
use Closure;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Collection;
@ -43,18 +44,42 @@ class PedidosExportHelper
{
$filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv";
$barrios = GrupoDeCompra::barriosMenosPrueba()->get();
$contenido = self::generarContenidoCSV($barrios,
fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId
AND subpedidos.tipo_pedido_id = 2");
$ollas = self::cantidadDeOllasParaCSV($barrios, $contenido);
self::exportarCSV(
$filePath,
$barrios,
self::generarContenidoCSV(
$barrios,
fn ($grupoId) =>
"subpedidos.grupo_de_compra_id = $grupoId
AND subpedidos.tipo_pedido_id = 2"
)
$contenido->concat([$ollas])
);
}
/**
* @throws Exception
*/
public static function cantidadDeOllasParaCSV(Collection $barrios, Collection $contenido)
{
$tipo_olla = TipoPedido::where('nombre', 'olla')->first()->id;
$parametros = collect(CsvHelper::getRecords(resource_path("csv/parametros.csv"), "No se pudo leer el archivo."));
$fila = [
"producto" => "Cantidad de ollas",
"precio" => $parametros->where('id','monto-olla')->pluck('valor')->first(),
"paga_transporte" => false,
"fila" => $contenido->last()->fila + 1,
];
foreach ($barrios as $barrio) {
$pedido = $barrio->subpedidos()->where('tipo_pedido_id', $tipo_olla)->first();
$fila[$barrio->nombre] = $pedido->cantidad_ollas;
}
return (object) $fila;
}
/**
* @throws InvalidArgument
* @throws CannotInsertRecord