public function importExcel() { $fileInfo = $this->uploadFile(request()->file('file'), 'import'); $pathToFile = $fileInfo['path'] . '/' . $fileInfo['name']; Excel::selectSheets('Sheet1')->load($pathToFile, function ($reader) { $rows = $reader->get(); foreach ($rows as $key => $value) { // b1: find order with unit, order_name, order_phone $query = DB::table('orders')->join('units', 'orders.unit_id', '=', 'units.id')->join('phones', 'orders.id', '=', 'phones.order_id')->join('purposes', 'orders.purpose_id', '=', 'purposes.id')->where('phones.number', $value['so_dien_thoai'])->where('units.symbol', $value['don_vi_yc'])->where('orders.order_name', 'like', '%' . $value['ho_ten_doi_tuong'] . '%')->where('purposes.group', 'monitor')->select('phones.id'); $order = $query->first(); if (isset($order)) { // up date status phone $phone = Phone::find($order->id); if ($phone->status != 'success') { $phone->status = 'success'; $phone->save(); } $input = $this->excelForShip($value, $order->id); $newShip = new ShipRepository(new Ship()); $newShip->create($input); } } }); return redirect()->back(); }
public function importExcel() { $fileInfo = $this->uploadFile(request()->file('file'), 'import'); $pathToFile = $fileInfo['path'] . '/' . $fileInfo['name']; Excel::selectSheets('Sheet1')->load($pathToFile, function ($reader) { $rows = $reader->get(); foreach ($rows as $key => $value) { // b1: insert Order $order = $this->excelForOrder($value, 'xmctb'); $newOrder = new OrderRepository(new Order()); $t = $newOrder->create($order); // b2: insert ship from order foreach ($t->phones as $index => $phone) { $input = $this->excelForShip($value, $phone->id); $newShip = new ShipRepository(new Ship()); $newShip->create($input); } } }); return redirect()->back(); }