Agregada cantidad de ollas a planilla de ollas
This commit is contained in:
parent
7f59b9a2ff
commit
cc6fe6878a
1 changed files with 31 additions and 6 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use App\GrupoDeCompra;
|
use App\GrupoDeCompra;
|
||||||
|
use App\TipoPedido;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Database\Query\Expression;
|
use Illuminate\Database\Query\Expression;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
@ -43,18 +44,42 @@ class PedidosExportHelper
|
||||||
{
|
{
|
||||||
$filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv";
|
$filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv";
|
||||||
$barrios = GrupoDeCompra::barriosMenosPrueba()->get();
|
$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(
|
self::exportarCSV(
|
||||||
$filePath,
|
$filePath,
|
||||||
$barrios,
|
$barrios,
|
||||||
self::generarContenidoCSV(
|
$contenido->concat([$ollas])
|
||||||
$barrios,
|
|
||||||
fn ($grupoId) =>
|
|
||||||
"subpedidos.grupo_de_compra_id = $grupoId
|
|
||||||
AND subpedidos.tipo_pedido_id = 2"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 InvalidArgument
|
||||||
* @throws CannotInsertRecord
|
* @throws CannotInsertRecord
|
||||||
|
|
Loading…
Add table
Reference in a new issue