Compare commits
No commits in common. "cc6fe6878a26e3a3522d2cb3b1b3c820c479d8c8" and "148e54356c58572290d9eebc2efa83f04c1c6ccc" have entirely different histories.
cc6fe6878a
...
148e54356c
2 changed files with 7 additions and 31 deletions
|
@ -3,7 +3,6 @@
|
||||||
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;
|
||||||
|
@ -44,42 +43,18 @@ 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,
|
||||||
$contenido->concat([$ollas])
|
self::generarContenidoCSV(
|
||||||
|
$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
|
||||||
|
|
|
@ -18,6 +18,7 @@ class UsuarioOllasSeeder extends Seeder
|
||||||
$barrios = GrupoDeCompra::all();
|
$barrios = GrupoDeCompra::all();
|
||||||
$usersToInsert = [];
|
$usersToInsert = [];
|
||||||
$ollas_id = UserRole::where('nombre', 'ollas')->first()->id;
|
$ollas_id = UserRole::where('nombre', 'ollas')->first()->id;
|
||||||
|
$pedidos_id = UserRole::where('nombre', 'barrio')->first()->id;
|
||||||
|
|
||||||
foreach ($barrios as $barrio) {
|
foreach ($barrios as $barrio) {
|
||||||
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
||||||
|
|
Loading…
Add table
Reference in a new issue