Reemplazo de logica de proovedor por es_solidario
This commit is contained in:
parent
de1bae8620
commit
2e78d39f12
1 changed files with 8 additions and 30 deletions
|
@ -3,14 +3,12 @@
|
|||
namespace App\Helpers;
|
||||
|
||||
use App\Producto;
|
||||
use App\Proveedor;
|
||||
use App\CanastaLog;
|
||||
use DatabaseSeeder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
||||
class CanastaHelper
|
||||
{
|
||||
const TIPO = "Tipo";
|
||||
|
@ -39,23 +37,16 @@ class CanastaHelper
|
|||
$categoria = '';
|
||||
|
||||
foreach($registros as $i => $registro) {
|
||||
// saltear filas que no tienen tipo
|
||||
if (self::noTieneTipo($registro)) {
|
||||
var_dump("no hay tipo en la fila " . $i);
|
||||
// saltear bono de transporte y filas que no tienen tipo
|
||||
if (self::noTieneTipo($registro) || $registro[self::TIPO] == "T")
|
||||
continue;
|
||||
}
|
||||
|
||||
// saltear bono de transporte
|
||||
if ($registro[self::TIPO] == "T"){
|
||||
continue;
|
||||
}
|
||||
|
||||
// obtener categoria si no hay producto
|
||||
if ($registro[self::PRODUCTO] == '') {
|
||||
// no es la pregunta de la copa?
|
||||
if (!Str::contains($registro[self::TIPO],"¿"))
|
||||
$categoria = $registro[self::TIPO];
|
||||
continue;
|
||||
continue; // saltear si es la pregunta de la copa
|
||||
}
|
||||
|
||||
// completar producto
|
||||
|
@ -64,33 +55,20 @@ class CanastaHelper
|
|||
'categoria' => $categoria,
|
||||
'nombre' => trim(str_replace('*', '',$registro[self::PRODUCTO])),
|
||||
'precio' => $registro[self::PRECIO],
|
||||
'proveedor_id' => self::obtenerProveedor($registro[self::PRODUCTO]),
|
||||
'es_solidario' => Str::contains($registro[self::PRODUCTO],"*"),
|
||||
'bono' => preg_match(self::REGEX_BONO, $registro[self::TIPO]),
|
||||
'requiere_notas'=> $registro[self::TIPO] == self::PRODUCTO_TALLE_COLOR,
|
||||
];
|
||||
}
|
||||
|
||||
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) {
|
||||
DB::table('productos')->insert($chunk);
|
||||
}
|
||||
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
Producto::insert($chunk);
|
||||
|
||||
self::agregarBonoBarrial();
|
||||
|
||||
self::log($archivo, self::CANASTA_CARGADA);
|
||||
}
|
||||
|
||||
private static function obtenerProveedor($nombre) {
|
||||
$result = null;
|
||||
if (Str::contains($nombre,"*")){
|
||||
$result = Proveedor::firstOrCreate([
|
||||
'nombre' => 'Proveedor de economía solidaria',
|
||||
'economia_solidaria' => 1,
|
||||
'nacional' => 1
|
||||
])->id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $descripcion
|
||||
|
@ -122,13 +100,13 @@ class CanastaHelper
|
|||
return Str::contains($c, 'BONO');
|
||||
});
|
||||
|
||||
DB::table('productos')->insert([
|
||||
Producto::create([
|
||||
'fila' => 420,
|
||||
'nombre' => "Bono barrial",
|
||||
'precio' => 20,
|
||||
'categoria' => $categoria,
|
||||
'bono' => 1,
|
||||
'proveedor_id' => null,
|
||||
'es_solidario' => 0,
|
||||
'requiere_notas'=> false,
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue