Esempio n. 1
0
 /**
  * Display a listing of the user.
  *
  * @return Response
  */
 public function index()
 {
     if (Auth::user()->isadmin) {
         $provincebranchs = Province::whereHas('branchs', function ($q) {
             $q->where('isheadquarter', true);
         })->orderBy('name', 'asc')->get(['id', 'name']);
     } else {
         $provincebranchs = Province::where('id', Auth::user()->provinceid)->whereHas('branchs', function ($q) {
             $q->where('isheadquarter', true);
         })->orderBy('name', 'asc')->get(['id', 'name']);
     }
     $provincebranchselectlist = array();
     foreach ($provincebranchs as $item) {
         $provincebranchselectlist[$item->id] = $item->name;
     }
     return view('report', ['provincebranchselectlist' => $provincebranchselectlist]);
 }
Esempio n. 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');
 }