예제 #1
0
 public function dstaixe()
 {
     $taixe = TaiXe::select('taixe_id', 'tentaixe', 'banglaixe', 'ngaysinh', 'sothich')->get()->toArray();
     foreach ($taixe as $key => $value) {
         $myfunction = new MyFunction();
         $arrayxe = $myfunction->laixe($value['banglaixe']);
         array_push($taixe[$key], $arrayxe);
         $socho_xe = TaiXe::find($value['taixe_id'])->xe;
         //dd($socho_xe);
         if ($socho_xe != null) {
             array_push($taixe[$key], $socho_xe->socho_xe);
         }
     }
     //dd($taixe);
     return view('backend.taixe.list', compact('taixe'));
 }
예제 #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(EditXeRequest $request, $xe_id)
 {
     $car = Cars::findOrFail($xe_id);
     //$cars->xe_id = $id;
     $car->hang_id = $request->hang_name;
     $car->ten_xe = $request->ten_xe;
     $car->giamuaxe = $request->giamuaxe;
     $car->sodangky_xe = $request->sodangky_xe;
     $car->color = $request->color;
     $car->socho_xe = $request->socho_xe;
     $car->tai_xe_id = $request->taixe_xe;
     $function = new MyFunction();
     if ($request->hasFile('url_hinhxe')) {
         $file = $request->file('url_hinhxe');
         $destinationPath = base_path() . "/public/user/images/";
         $url_hinhxe = $function->stripUnicode(basename($file->getClientOriginalName()));
         $car->url_hinhxe = $url_hinhxe;
         $fileName = $destinationPath . $url_hinhxe;
         //dd($file); die();
         if ($file->isValid()) {
             $file->move($destinationPath, $fileName);
         }
     }
     if ($request->ngaydangkiem != null) {
         $car->ngaydangkiem = $function->changedatetimeformat($request->ngaydangkiem);
         //dd($cars->ngaydangkiem);
     }
     if ($request->ngaysanxuat != null) {
         $car->ngaysanxuat = $function->changedatetimeformat($request->ngaysanxuat);
     }
     $car->gianoithanh = $request->gianoithanh;
     $car->giaduongdai = $request->giaduongdai;
     $car->giasanbay = $request->giasanbay;
     $car->giathuethang = $request->giathuethang;
     $car->giangoaigio = $request->giangoaigio;
     $car->save();
     return redirect('danhsachxe')->with('flash_message', 'Xe ' . $xe_id . ' đã được sửa.');
 }
예제 #3
0
 public function postDatXe(DatXeRequest $request)
 {
     $MyFunction = new MyFunction();
     $ngaydi = $MyFunction->changedatetimeformat($request->ngaydi);
     $ngayve = $MyFunction->changedatetimeformat($request->ngayve);
     $array_cars = [];
     foreach (Session::get('datxe') as $key => $value) {
         array_push($array_cars, $value['id']);
     }
     $cars_not_in = DB::table('tbl_dondat')->join('tbl_dondatchitiet', 'tbl_dondat.dondat_id', '=', 'tbl_dondatchitiet.don_dat_id')->select('tbl_dondatchitiet.xe_id')->where('tbl_dondat.active', '=', 1)->where(function ($query) use($ngaydi, $ngayve) {
         $query->where('tbl_dondat.ngaydi', '<=', $ngaydi)->where('tbl_dondat.ngayve', '>=', $ngayve);
     })->orWhere(function ($query) use($ngaydi, $ngayve) {
         $query->where('tbl_dondat.ngaydi', '>=', $ngaydi)->where('tbl_dondat.ngaydi', '<=', $ngayve)->where('tbl_dondat.ngayve', '>=', $ngayve);
     })->orWhere(function ($query) use($ngaydi, $ngayve) {
         $query->where('tbl_dondat.ngaydi', '<=', $ngaydi)->where('tbl_dondat.ngayve', '<=', $ngayve)->where('tbl_dondat.ngayve', '>=', $ngaydi);
     })->orWhere(function ($query) use($ngaydi, $ngayve) {
         $query->where('tbl_dondat.ngaydi', '>=', $ngaydi)->where('tbl_dondat.ngayve', '<=', $ngayve);
     })->distinct()->get();
     //dd($cars_not_in); die();
     $array_car_in = [];
     foreach ($array_cars as $car) {
         foreach ($cars_not_in as $xe => $value) {
             if ($value->xe_id == $car) {
                 array_push($array_car_in, $value->xe_id);
             }
         }
     }
     $dondat_car_in = [];
     foreach ($array_car_in as $car) {
         $now = Carbon::now();
         $unixtimenow = strtotime($now);
         $dondat = DB::table('tbl_dondat')->join('tbl_dondatchitiet', 'tbl_dondat.dondat_id', '=', 'tbl_dondatchitiet.don_dat_id')->where('tbl_dondatchitiet.xe_id', '=', $car)->where('tbl_dondat.ngayve', '>', $now)->where('tbl_dondat.ngaydi', '<', $ngayve)->get();
         array_push($dondat_car_in, $dondat);
         //dd($dondat); die();
     }
     //dd($dondat_car_in); die();
     if (count($array_car_in) > 0) {
         $user = User::where('nguoidung_id', Auth::user()->nguoidung_id)->get()->first();
         return view('backend.booking.datxe', compact('user', 'dondat_car_in'));
     } else {
         //dd($array_car_in); die();
         //dd($array_cars); die();
         $user = User::findOrFail(Auth::user()->nguoidung_id);
         $user->tendaydu = $request->tendaydu;
         $user->email = $request->email;
         switch ($request->gioitinh) {
             case 1:
                 $user->gioitinh = 'Nam';
                 break;
             case 0:
                 $user->gioitinh = 'Nữ';
                 break;
             default:
                 $user->gioitinh = 'Không xác định';
         }
         $user->sodienthoai = $request->sodienthoai;
         $user->tencongty = $request->tencongty;
         $user->masothue = $request->masothue;
         $user->save();
         $datxe = new DonDat(['diemdon' => $request->diemdon, 'diemden' => $request->diemden, 'yeucau' => $request->yeucau, 'ngaydi' => $ngaydi, 'ngayve' => $ngayve]);
         $user->dondat()->save($datxe);
         foreach (Session::get('datxe') as $key => $value) {
             $dondatchitiet = new DonDatCT(['xe_id' => $value['id']]);
             $datxe->dondatchitiet()->save($dondatchitiet);
         }
         Session::forget('datxe');
         return redirect('quanlydondat');
     }
 }