Esempio n. 1
0
 public function postImportPo(Request $request)
 {
     $getSheetName = Excel::load(Request::file('file'))->getSheetNames();
     foreach ($getSheetName as $sheetName) {
         //if ($sheetName === 'Product-General-Table')  {
         //selectSheetsByIndex(0)
         //DB::statement('SET FOREIGN_KEY_CHECKS=0;');
         //DB::table('pos')->truncate();
         //Excel::selectSheets($sheetName)->load($request->file('file'), function ($reader)
         //Excel::selectSheets($sheetName)->load(Input::file('file'), function ($reader)
         //Excel::filter('chunk')->selectSheetsByIndex(0)->load(Request::file('file'))->chunk(50, function ($reader)
         Excel::filter('chunk')->selectSheets($sheetName)->load(Request::file('file'))->chunk(50, function ($reader) {
             foreach ($reader->toArray() as $sheet) {
                 //MainModel::create($sheet);
                 //$sheet->dump();
             }
             $readerarray = $reader->toArray();
             //var_dump($readerarray);
             foreach ($readerarray as $row) {
                 //var_dump($row['po_key']);
                 //var_dump($row['po']);
                 //$order_code = $row->order_code;
                 //$order_code = $row['order_code'];
                 //$po = substr($order_code, 4,10);
                 //$rest = substr("abcdef", -3, 1); // returns "d" 16IC5800050657::00102::M
                 //var_dump($po);
                 $season = $row['season'];
                 $order_code = $row['order_code'];
                 // 16IC5800050657::00102::M
                 $product = $row['product'];
                 // 1MC07A   4619L
                 $product_des = $row['product_description'];
                 $qty = $row['total_qty'];
                 $flash = $row['flash'];
                 $po = substr($order_code, 9, 5);
                 //
                 $size = substr($order_code, 23, 3);
                 $style = substr($product, 0, 8);
                 $color = substr($product, 9, 4);
                 $po_key = $po . "-" . $size;
                 $brand = substr($order_code, 2, 1);
                 if ($brand == "T") {
                     $brand = "TEZENIS";
                 } elseif ($brand == "I") {
                     $brand = "INTIMISSIMI";
                 } elseif ($brand == "C") {
                     $brand = "CALZEDONIA";
                 } else {
                     $brand = "";
                 }
                 if ($flash == 'N') {
                     $flash = '';
                 } else {
                     $flash = $flash;
                 }
                 $closed = 'Open';
                 $style = str_replace(' ', '', $style);
                 $size = str_replace(' ', '', $size);
                 $color = str_replace(' ', '', $color);
                 $porder = new Po();
                 $porder->po_key = $po_key;
                 $porder->order_code = $order_code;
                 $porder->po = $po;
                 $porder->size = $size;
                 $porder->style = $style;
                 $porder->color = $color;
                 $porder->color_desc = $product_des;
                 $porder->season = $season;
                 $porder->total_order_qty = $qty;
                 $porder->flash = $flash;
                 $porder->closed_po = $closed;
                 $porder->brand = $brand;
                 $porder->status;
                 $porder->type;
                 $porder->comment;
                 $porder->save();
                 $barcode = new BarcodeStock();
                 $barcode->po_id = $porder->id;
                 // ???
                 $barcode->user_id = 3;
                 $barcode->ponum = $po;
                 $barcode->size = $size;
                 $barcode->qty = 0;
                 $barcode->module;
                 $barcode->status;
                 $barcode->type = "insert";
                 $barcode->comment;
                 $barcode->save();
                 $carelabel = new CarelabelStock();
                 $carelabel->po_id = $porder->id;
                 // ???
                 $carelabel->user_id = 3;
                 $carelabel->ponum = $po;
                 $carelabel->size = $size;
                 $carelabel->qty = 0;
                 $carelabel->module;
                 $carelabel->status;
                 $carelabel->type = "insert";
                 $carelabel->comment;
                 $carelabel->save();
             }
         });
     }
     //Session::flash('file_uploaded_successfully', 'File has been uploaded successfully and has also updated the database.');
     return redirect('/');
     //return view('import.importresult', compact('reader'));
 }
 public function storeundo(Request $request)
 {
     //
     //validation
     $this->validate($request, ['po' => 'required|min:5|max:5', 'size' => 'required', 'qty' => 'required']);
     $forminput = $request->all();
     $ponum = $forminput['po'];
     $size = $forminput['size'];
     $qty = $forminput['qty'];
     $comment = $forminput['comment'];
     $key = $ponum . '-' . $size;
     //dd($key);
     $type = "undo";
     $qty = $qty * -1;
     // virfy userId
     if (Auth::check()) {
         $userId = Auth::user()->id;
     } else {
         $msg = 'User is not autenticated';
         return view('CarelabelStock.error', compact('msg'));
     }
     // verify po_id
     try {
         $poid = Po::where('po_key', $key)->firstOrFail()->id;
         $po_closed = Po::where('po_key', $key)->firstOrFail()->closed_po;
     } catch (ModelNotFoundException $e) {
         $msg = 'Po and size not exist in Po table';
         return view('CarelabelStock.error', compact('msg'));
     }
     // verify po is closed
     if ($po_closed == 'Closed') {
         $msg = 'Po is Closed';
         return view('CarelabelStock.error', compact('msg'));
     }
     try {
         $carelabel = new CarelabelStock();
         $carelabel->po_id = $poid;
         $carelabel->user_id = $userId;
         $carelabel->ponum = $ponum;
         $carelabel->size = $size;
         $carelabel->qty = $qty;
         //$carelabel->module = $module;
         //$carelabel->status = $status;
         $carelabel->type = $type;
         $carelabel->comment = $comment;
         $carelabel->save();
     } catch (\Illuminate\Database\QueryException $e) {
         $msg = "Problem to save in database";
         return view('CarelabelStock.error', compact('msg'));
     }
     return view('CarelabelStock.success');
 }