Compare commits
	
		
			2 commits
		
	
	
		
			95a9a404d2
			...
			cc734866c5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| cc734866c5 | |||
| c31b808f05 | 
					 3 changed files with 68 additions and 4 deletions
				
			
		
							
								
								
									
										11
									
								
								app/CanastaLog.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/CanastaLog.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace App; | ||||||
|  | 
 | ||||||
|  | use Illuminate\Database\Eloquent\Model; | ||||||
|  | 
 | ||||||
|  | class CanastaLog extends Model | ||||||
|  | { | ||||||
|  |     protected $fillable = ["nombre", "descripcion"]; | ||||||
|  |     protected $table = "carga_de_canastas"; | ||||||
|  | } | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| namespace App\Helpers; | namespace App\Helpers; | ||||||
| 
 | 
 | ||||||
| use App\Proveedor; | use App\Proveedor; | ||||||
|  | use App\CanastaLog; | ||||||
| use DatabaseSeeder; | use DatabaseSeeder; | ||||||
| use Illuminate\Support\Arr; | use Illuminate\Support\Arr; | ||||||
| use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||||
|  | @ -13,12 +14,16 @@ class CanastaHelper | ||||||
| { | { | ||||||
|     const FILA_HEADER = "Tipo"; |     const FILA_HEADER = "Tipo"; | ||||||
|     const ULTIMA_FILA = "TOTAL"; |     const ULTIMA_FILA = "TOTAL"; | ||||||
|  |     const ARCHIVO_SUBIDO = 'Archivo subido'; | ||||||
|  |     const CANASTA_CARGADA = 'Canasta cargada'; | ||||||
| 
 | 
 | ||||||
|     public static function guardarCanasta($data, $path): string |     public static function guardarCanasta($data, $path): string { | ||||||
|     { |  | ||||||
|         $nombre = $data->getClientOriginalName(); |         $nombre = $data->getClientOriginalName(); | ||||||
| 
 | 
 | ||||||
|         $data->move(resource_path($path), $nombre); |         $data->move(resource_path($path), $nombre); | ||||||
|  | 
 | ||||||
|  |         self::log($path . $nombre, self::ARCHIVO_SUBIDO); | ||||||
|  | 
 | ||||||
|         return $nombre; |         return $nombre; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -73,10 +78,11 @@ class CanastaHelper | ||||||
|             ]; |             ]; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) |         foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) { | ||||||
|         { |  | ||||||
|             DB::table('productos')->insert($chunk); |             DB::table('productos')->insert($chunk); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         self::log($archivo, self::CANASTA_CARGADA); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static function obtenerIndiceDeHeader($csv){ |     private static function obtenerIndiceDeHeader($csv){ | ||||||
|  | @ -102,4 +108,18 @@ class CanastaHelper | ||||||
|         } |         } | ||||||
|         return $result; |         return $result; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @param $nombre | ||||||
|  |      * @param $descripcion | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     private static function log($nombre, $descripcion): void | ||||||
|  |     { | ||||||
|  |         $log = new CanastaLog([ | ||||||
|  |             'nombre' => $nombre, | ||||||
|  |             'descripcion' => $descripcion, | ||||||
|  |         ]); | ||||||
|  |         $log->save(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | use Illuminate\Database\Migrations\Migration; | ||||||
|  | use Illuminate\Database\Schema\Blueprint; | ||||||
|  | use Illuminate\Support\Facades\Schema; | ||||||
|  | 
 | ||||||
|  | class CrearCargaDeCanastas extends Migration | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * Run the migrations. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function up() | ||||||
|  |     { | ||||||
|  |         Schema::create('carga_de_canastas', function (Blueprint $table) { | ||||||
|  |             $table->id(); | ||||||
|  |             $table->string('nombre'); | ||||||
|  |             $table->string('descripcion'); | ||||||
|  |             $table->timestamps(); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Reverse the migrations. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public function down() | ||||||
|  |     { | ||||||
|  |         Schema::dropIfExists('carga_de_canastas'); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue