public function import()
 {
     try {
         $file = Input::file('pricelist');
         //$path = Input::file('pricelist')->getRealPath();
         $temp = null;
         Excel::load($file, function ($reader) use($temp) {
             //$reader->dump();
             $reader->skip(1);
             // Loop through all rows
             $reader->each(function ($row) {
                 $carBrand = CarBrand::where('name', 'NISSAN')->first();
                 $carModel = CarModel::firstOrCreate(['name' => trim($row->d) . ' ' . trim($row->e), 'cartypeid' => $row->c, 'carbrandid' => $carBrand->id]);
                 $carSubModel = CarSubModel::firstOrCreate(['code' => trim($row->g), 'name' => trim($row->f), 'carmodelid' => $carModel->id]);
                 $pricelist = Pricelist::firstOrNew(['carmodelid' => $carModel->id, 'carsubmodelid' => $carSubModel->id, 'effectivefrom' => date('Y-m-d', strtotime(trim($row->a))), 'effectiveto' => date('Y-m-d', strtotime(trim($row->b))), 'sellingprice' => $row->i, 'accessoriesprice' => $row->j, 'sellingpricewithaccessories' => $row->h, 'margin' => $row->k, 'ws50' => $row->l, 'dms' => $row->m, 'wholesale' => $row->n, 'execusiveinternal' => $row->o, 'execusivecampaing' => $row->p, 'execusivetotalmargincampaing' => $row->q, 'internal' => $row->r, 'campaing' => $row->s, 'totalmargincampaing' => $row->t]);
                 $pricelist->effectivefrom = trim($row->a);
                 $pricelist->effectiveto = trim($row->b);
                 $pricelist->save();
             });
         });
     } catch (Exception $e) {
         return 'Message: ' . $e->getMessage();
     }
     return redirect()->action('Settings\\PricelistController@index');
 }
示例#2
0
 public function import()
 {
     try {
         $file = Input::file('file');
         //$path = Input::file('pricelist')->getRealPath();
         $temp = null;
         Excel::load($file, function ($reader) use($temp) {
             //$reader->dump();
             $reader->skip(1);
             // Loop through all rows
             $reader->each(function ($row) {
                 $carBrand = CarBrand::where('name', 'NISSAN')->first();
                 $color = Color::where('code', trim($row->p))->first();
                 $carModel = CarModel::firstOrCreate(['name' => trim($row->c) . ' ' . trim($row->d), 'cartypeid' => $row->b, 'carbrandid' => $carBrand->id]);
                 $carSubModel = CarSubModel::firstOrCreate(['code' => trim($row->f), 'name' => trim($row->e), 'carmodelid' => $carModel->id]);
                 $car = Car::firstOrNew(['engineno' => trim($row->m), 'chassisno' => trim($row->n)]);
                 $car->datatype = 0;
                 $car->provinceid = trim($row->a);
                 $car->carmodelid = $carModel->id;
                 $car->carsubmodelid = $carSubModel->id;
                 $car->receivetype = trim($row->g);
                 $car->dealername = trim($row->h);
                 $car->no = trim($row->i);
                 $car->dodate = trim($row->j);
                 $car->dono = trim($row->k);
                 if ($row->l != null && $row->l != '') {
                     $car->receiveddate = trim($row->l);
                 }
                 if ($row->o != null && $row->o != '') {
                     $car->keyno = trim($row->o);
                 }
                 $car->colorid = $color->id;
                 $car->objective = trim($row->q);
                 if ($row->r != null && $row->r != '') {
                     $car->parklocation = trim($row->r);
                 }
                 if ($row->s != null && $row->s != '') {
                     $car->notifysolddate = trim($row->s);
                 }
                 if ($row->u != null && $row->u != '' && $row->v != null && $row->v != '') {
                     $customer = Customer::firstOrNew(['provinceid' => trim($row->a), 'title' => trim($row->u), 'firstname' => trim($row->v), 'lastname' => trim($row->w)]);
                     $customer->isreal = true;
                     if ($row->x != null && $row->x != '') {
                         $customer->phone1 = trim($row->x);
                     }
                     if ($row->y != null && $row->y != '') {
                         $customer->occupationid = trim($row->y);
                     }
                     if ($row->z != null && $row->z != '') {
                         $customer->birthdate = trim($row->z);
                     }
                     if ($row->aa != null && $row->aa != '') {
                         $customer->address = trim($row->aa);
                     }
                     $district = District::where('name', trim($row->ab))->first();
                     $amphur = Amphur::where('name', trim($row->ac))->first();
                     $province = Province::where('name', trim($row->ad))->first();
                     if ($district != null) {
                         $customer->districtid = $district->id;
                     }
                     if ($amphur != null) {
                         $customer->amphurid = $amphur->id;
                     }
                     if ($province != null) {
                         $customer->addprovinceid = $province->id;
                     }
                     if ($row->ad != null && $row->ad != '') {
                         $customer->zipcode = trim($row->ae);
                     }
                     $customer->save();
                     $car->issold = true;
                     $car->buyercustomerid = $customer->id;
                     if ($row->t != null && $row->t != '') {
                         $car->isdelivered = true;
                     }
                 }
                 $car->save();
             });
         });
     } catch (Exception $e) {
         return 'Message: ' . $e->getMessage();
     }
     return redirect()->action('CarController@index');
 }