Exemplo n.º 1
0
 public function POS()
 {
     Excel::load(public_path('uploads/distributors') . '/POS.xls', function ($reader) {
         $results = $reader->get();
         $areas = ['ميامي', 'القباري', 'مينا البصل', 'الفلكى', 'النزهة', 'كفر الزيات', 'دمنهور', 'طنطا', 'المحلة', 'المنصورة', 'دكرنس', 'دمياط', 'شبين الكوم', 'الناصرية', 'دمنهور 2', 'الزقازيق', 'بنها 2', 'المطرية', 'مصر الجديدة', 'مدينة نصر', 'عين شمس', 'روض الفرج', 'الجيزة', 'خاتم المرسلين', 'حلوان', 'امبابة 1', 'مسطرد', 'امبابة 2', 'الفيوم', 'بني سويف', 'المنيا', 'اسيوط', 'سوهاج', 'قنا', 'المنيا 2'];
         foreach ($results as $key => $row) {
             $i = 0;
             if (!is_null($results[$key][0])) {
                 if ($results[$key][0] == 'Total Units' || $results[$key][0] == 'Total Values') {
                     unset($results[$key][0]);
                     continue;
                 }
                 $itemName = $results[$key][0];
                 $itemCode = $results[$key]['product_code'];
                 unset($results[$key][0]);
                 unset($results[$key]['product_code']);
                 foreach ($row as $area => $qty) {
                     if ($area == 'total' || $area == 'total_bonus') {
                         unset($area);
                         continue;
                     }
                     if ($i < count($areas)) {
                         //                            echo date('M-Y') . '->' . $itemName . '->' . $itemCode . '->' . $areas[$i] . '->' . $qty . '<br>';
                         $pos = new POS();
                         $pos->month = config('app.current_month');
                         $pos->code = $itemCode;
                         $pos->product_name = $itemName;
                         $pos->area = $areas[$i];
                         $pos->quantity = $qty;
                         $pos->save();
                         $i++;
                     } else {
                         $i = 0;
                     }
                 }
             }
         }
     }, 'UTF-8');
 }