Planilla de notas + ignorar barrio PRUEBA
This commit is contained in:
		
							parent
							
								
									acc21091f9
								
							
						
					
					
						commit
						f778a4f24e
					
				
					 1 changed files with 18 additions and 13 deletions
				
			
		|  | @ -83,17 +83,19 @@ class Producto extends Model | |||
| 
 | ||||
|     static public function planillaTotales() { | ||||
|         $headers = ['Producto']; | ||||
|         $barrios = DB::table('grupos_de_compra')->pluck('nombre')->toArray(); | ||||
|         $barrios = DB::table('grupos_de_compra') | ||||
|             ->where('nombre', '<>', 'PRUEBA') | ||||
|             ->pluck('nombre')->toArray(); | ||||
|         $headers = array_merge($headers, $barrios); | ||||
| 
 | ||||
|         $cantidadesPorBarrio = Producto::cantidadesPorBarrio(); | ||||
|         $cantidadesPorBarrio = self::cantidadesPorBarrio(); | ||||
|         $planilla = []; | ||||
|         $ultimaFila = 1; | ||||
| 
 | ||||
|         foreach ($cantidadesPorBarrio as $productoCantidades) { | ||||
|             $fila = $productoCantidades->fila; | ||||
|             while ($fila - $ultimaFila > 1) { | ||||
|                 $producto = Producto::where('fila', $ultimaFila)->first(); | ||||
|                 $producto = self::where('fila', $ultimaFila)->first(); | ||||
|                 $planilla[$ultimaFila] = [$producto ? $producto->nombre : '']; | ||||
|                 $ultimaFila++; | ||||
|             } | ||||
|  | @ -104,7 +106,6 @@ class Producto extends Model | |||
|             $ultimaFila = $fila; | ||||
|         } | ||||
| 
 | ||||
|         // Guardar en un archivo .csv
 | ||||
|         try { | ||||
|             $writer = Writer::createFromPath(resource_path('csv/exports/total-pedidos.csv'), 'w'); | ||||
|             $writer->insertOne($headers); | ||||
|  | @ -114,12 +115,9 @@ class Producto extends Model | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     static public function planillaNotas() { | ||||
|         $headers = ['Producto']; | ||||
|         $barrios = DB::table('grupos_de_compra')->pluck('nombre')->toArray(); | ||||
|         $headers = array_merge($headers, $barrios); | ||||
| 
 | ||||
|         $notasPorBarrio = DB::table('productos') | ||||
|     public static function notasPorBarrio(): \Illuminate\Support\Collection | ||||
|     { | ||||
|         return DB::table('productos') | ||||
|             ->join('producto_subpedido', 'productos.id', '=', 'producto_subpedido.producto_id') | ||||
|             ->join('subpedidos', 'producto_subpedido.subpedido_id', '=', 'subpedidos.id') | ||||
|             ->join('grupos_de_compra', 'subpedidos.grupo_de_compra_id', '=', 'grupos_de_compra.id') | ||||
|  | @ -130,18 +128,25 @@ class Producto extends Model | |||
|                 'producto_subpedido.notas' | ||||
|             ) | ||||
|             ->get() | ||||
|             ->groupBy('producto'); // Group notes by product
 | ||||
|             ->groupBy('producto'); | ||||
|     } | ||||
| 
 | ||||
|     static public function planillaNotas() { | ||||
|         $headers = ['Producto']; | ||||
|         $barrios = DB::table('grupos_de_compra') | ||||
|             ->where('nombre', '<>', 'PRUEBA') | ||||
|             ->pluck('nombre')->toArray(); | ||||
|         $headers = array_merge($headers, $barrios); | ||||
| 
 | ||||
|         $notasPorBarrio = self::notasPorBarrio(); | ||||
|         $planilla = []; | ||||
| 
 | ||||
|         foreach ($notasPorBarrio as $producto => $notasGrupo) { | ||||
|             $fila = [$producto]; | ||||
| 
 | ||||
|             foreach ($barrios as $barrio) { | ||||
|                 $notas = $notasGrupo->where('barrio', $barrio)->pluck('notas')->implode('; '); | ||||
|                 $fila[] = $notas ?: ''; | ||||
|             } | ||||
| 
 | ||||
|             $planilla[] = $fila; | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue