Beispiel #1
0
 public function index()
 {
     /*$branchs = Branch::orderBy('name', 'asc')->get(['id', 'name']);
       $branchselectlist = array();
       array_push($branchselectlist,':เลือกสาขา');
       foreach($branchs as $item){
           array_push($branchselectlist,$item->id.':'.$item->name);
       }*/
     $provinces = Province::orderBy('name', 'asc')->get(['id', 'name']);
     $provinceselectlist = array();
     array_push($provinceselectlist, ':เลือกจังหวัด');
     foreach ($provinces as $item) {
         array_push($provinceselectlist, $item->id . ':' . $item->name);
     }
     $occupations = Occupation::orderBy('name', 'asc')->get(['id', 'name']);
     $occupationselectlist = array();
     array_push($occupationselectlist, ':เลือกอาชีพ');
     foreach ($occupations as $item) {
         array_push($occupationselectlist, $item->id . ':' . $item->name);
     }
     $amphurids = Customer::distinct()->lists('amphurid');
     $amphurs = Amphur::whereIn('id', $amphurids)->orderBy('name', 'asc')->get(['id', 'name']);
     $amphurselectlist = array();
     array_push($amphurselectlist, ':เลือกเขต/อำเภอ');
     foreach ($amphurs as $item) {
         array_push($amphurselectlist, $item->id . ':' . $item->name);
     }
     $districtids = Customer::distinct()->lists('districtid');
     $districts = District::whereIn('id', $districtids)->orderBy('name', 'asc')->get(['id', 'name']);
     $districtselectlist = array();
     array_push($districtselectlist, ':เลือกตำบล/แขวง');
     foreach ($districts as $item) {
         array_push($districtselectlist, $item->id . ':' . $item->name);
     }
     $employees = Employee::all(['id', 'firstname', 'lastname']);
     $employeeselectlist = array();
     array_push($employeeselectlist, ':เลือกพนักงาน');
     foreach ($employees as $emp) {
         array_push($employeeselectlist, $emp->id . ':' . $emp->firstname . ' ' . $emp->lastname);
     }
     $carmodels = CarModel::all(['id', 'name']);
     $carmodelselectlist = array();
     array_push($carmodelselectlist, ':เลือกแบบ');
     foreach ($carmodels as $cm) {
         array_push($carmodelselectlist, $cm->id . ':' . $cm->name);
     }
     $defaultProvince = '';
     if (Auth::user()->isadmin == false) {
         $defaultProvince = Auth::user()->branchid == null ? '' : Auth::user()->branch->provinceid;
     }
     return view('customer', ['provinceselectlist' => implode(";", $provinceselectlist), 'amphurselectlist' => implode(";", $amphurselectlist), 'districtselectlist' => implode(";", $districtselectlist), 'carmodelselectlist' => implode(";", $carmodelselectlist), 'employeeselectlist' => implode(";", $employeeselectlist), 'occupationselectlist' => implode(";", $occupationselectlist), 'defaultProvince' => $defaultProvince]);
 }
 public function view($id)
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     $model = CarPreemption::find($id);
     $bookingcustomer = Customer::find($model->bookingcustomerid);
     $model->bookingcustomername = $bookingcustomer->title . ' ' . $bookingcustomer->firstname . ' ' . $bookingcustomer->lastname;
     $model->provincebranchid = $bookingcustomer->provinceid;
     $model->bookingcustomeraddress = $bookingcustomer->address;
     $model->bookingcustomerprovinceid = $bookingcustomer->addprovinceid;
     $model->bookingcustomeramphurid = $bookingcustomer->amphurid;
     $model->bookingcustomerdistrictid = $bookingcustomer->districtid;
     $model->bookingcustomerzipcode = $bookingcustomer->zipcode;
     $model->bookingcustomerphone1 = $bookingcustomer->phone1;
     $model->bookingcustomerphone2 = $bookingcustomer->phone2;
     $model->bookingcustomeroccupationid = $bookingcustomer->occupationid;
     if ($bookingcustomer->birthdate != null && $bookingcustomer->birthdate != '') {
         $model->bookingcustomerbirthdate = date('d-m-Y', strtotime($bookingcustomer->birthdate));
     }
     if ($model->bookingcustomerid != $model->buyercustomerid) {
         $buyercustomer = Customer::find($model->buyercustomerid);
         $model->buyercustomeraddress = $buyercustomer->address;
         $model->buyercustomerprovinceid = $buyercustomer->addprovinceid;
         $model->buyercustomeramphurid = $buyercustomer->amphurid;
         $model->buyercustomerdistrictid = $buyercustomer->districtid;
         $model->buyercustomerzipcode = $buyercustomer->zipcode;
         $model->buyercustomerphone1 = $buyercustomer->phone1;
         $model->buyercustomerphone2 = $buyercustomer->phone2;
         $model->buyercustomeroccupationid = $buyercustomer->occupationid;
         if ($buyercustomer->birthdate != null && $buyercustomer->birthdate != '') {
             $model->buyercustomerbirthdate = date('d-m-Y', strtotime($buyercustomer->birthdate));
         }
     }
     $provincebranchs = Province::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;
     }
     $customerselectlist = array();
     $customerselectlist[$bookingcustomer->id] = $bookingcustomer->title . ' ' . $bookingcustomer->firstname . ' ' . $bookingcustomer->lastname;
     if ($model->bookingcustomerid != $model->buyercustomerid) {
         $customerselectlist[$buyercustomer->id] = $buyercustomer->title . ' ' . $buyercustomer->firstname . ' ' . $buyercustomer->lastname;
     }
     $provinces = Province::orderBy('name', 'asc')->get(['id', 'name']);
     $provinceselectlist = array();
     $provinceselectlist[null] = 'เลือกจังหวัด';
     foreach ($provinces as $item) {
         $provinceselectlist[$item->id] = $item->name;
     }
     $bookingcustomeramphurselectlist = array();
     $bookingcustomeramphurselectlist[null] = 'เลือกเขต/อำเภอ';
     if ($model->bookingcustomeramphurid != null && $model->bookingcustomeramphurid != '') {
         $item = Amphur::find($model->bookingcustomeramphurid);
         $bookingcustomeramphurselectlist[$item->id] = $item->name;
     }
     $buyercustomeramphurselectlist = array();
     $buyercustomeramphurselectlist[null] = 'เลือกเขต/อำเภอ';
     if ($model->bookingcustomerid != $model->buyercustomerid && $model->buyercustomeramphurid != null && $model->buyercustomeramphurid != '') {
         $item = Amphur::find($model->buyercustomeramphurid);
         $buyercustomeramphurselectlist[$item->id] = $item->name;
     }
     $bookingcustomerdistrictselectlist = array();
     $bookingcustomerdistrictselectlist[null] = 'เลือกแขวง/ตำบล';
     if ($model->bookingcustomerdistrictid != null && $model->bookingcustomerdistrictid != '') {
         $item = District::find($model->bookingcustomerdistrictid);
         $bookingcustomerdistrictselectlist[$item->id] = $item->name;
     }
     $buyercustomerdistrictselectlist = array();
     $buyercustomerdistrictselectlist[null] = 'เลือกแขวง/ตำบล';
     if ($model->bookingcustomerid != $model->buyercustomerid && $model->buyercustomerdistrictid != null && $model->buyercustomerdistrictid != '') {
         $item = District::find($model->buyercustomerdistrictid);
         $buyercustomerdistrictselectlist[$item->id] = $item->name;
     }
     $occupations = Occupation::orderBy('name', 'asc')->get(['id', 'name']);
     $occupationselectlist = array();
     $occupationselectlist[null] = 'เลือกอาชีพ';
     foreach ($occupations as $item) {
         $occupationselectlist[$item->id] = $item->name;
     }
     $carmodelselectlist = array();
     $item = CarModel::find($model->carmodelid);
     $carmodelselectlist[$item->id] = $item->name;
     $carsubmodelselectlist = array();
     $item = CarSubModel::find($model->carsubmodelid);
     $carsubmodelselectlist[$item->id] = $item->name;
     $colorselectlist = array();
     $item = Color::find($model->colorid);
     $colorselectlist[$item->id] = $item->code . ' - ' . $item->name;
     $registerprovinceselectlist = array();
     if ($model->registerprovinceid != null && $model->registerprovinceid != '') {
         $item = Province::find($model->registerprovinceid);
         $registerprovinceselectlist[$item->id] = $item->name;
     }
     $oldcarbrandselectlist = array();
     $oldcarbrandselectlist[null] = 'เลือกยี่ห้อรถ';
     if ($model->oldcarbrandid != null) {
         $item = CarBrand::find($model->oldcarbrandid);
         $oldcarbrandselectlist[$item->id] = $item->name;
     }
     $oldcarmodelselectlist = array();
     $oldcarmodelselectlist[null] = 'เลือกแบบ';
     if ($model->oldcarmodelid != null) {
         $item = CarModel::find($model->oldcarmodelid);
         $oldcarmodelselectlist[$item->id] = $item->name;
     }
     if (Auth::user()->isadmin) {
         $saleemployees = Employee::where('departmentid', 6)->where('teamid', '<>', 1)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     } else {
         $saleemployees = Employee::where('provinceid', Auth::user()->provinceid)->where('departmentid', 6)->where('teamid', '<>', 1)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     }
     $saleemployeeselectlist = array();
     $saleemployeeselectlist[null] = 'เลือกพนักงาน';
     foreach ($saleemployees as $item) {
         $saleemployeeselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname;
     }
     if (Auth::user()->isadmin) {
         $salemanageremployees = Employee::where('departmentid', 6)->where('teamid', 1)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     } else {
         $salemanageremployees = Employee::where('provinceid', Auth::user()->provinceid)->where('departmentid', 6)->where('teamid', 1)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     }
     $salemanageremployeeselectlist = array();
     $salemanageremployeeselectlist[null] = 'เลือกพนักงาน';
     foreach ($salemanageremployees as $item) {
         $salemanageremployeeselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname;
     }
     if (Auth::user()->isadmin) {
         $approveremployees = Employee::where('departmentid', 5)->orWhere(function ($query) {
             $query->where('departmentid', 6)->where('teamid', 1);
         })->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     } else {
         $approveremployees = Employee::where('provinceid', Auth::user()->provinceid)->where(function ($query) {
             $query->where('departmentid', 5)->orWhere(function ($query) {
                 $query->where('departmentid', 6)->where('teamid', 1);
             });
         })->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']);
     }
     $approveremployeeselectlist = array();
     $approveremployeeselectlist[null] = 'เลือกพนักงาน';
     foreach ($approveremployees as $item) {
         $approveremployeeselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname;
     }
     $giveaways = Giveaway::orderBy('name', 'asc')->orderBy('saleprice', 'asc')->get(['id', 'name', 'saleprice']);
     $giveawayselectlist = array();
     array_push($giveawayselectlist, ':เลือกของแถม');
     foreach ($giveaways as $ct) {
         array_push($giveawayselectlist, $ct->id . ':' . $ct->name . ' (' . $ct->saleprice . ' บาท)');
     }
     $giveawayFrees = CarPreemptionGiveaway::where('free', true)->where('carpreemptionid', $id)->get(['id', 'giveawayid', 'price']);
     $giveawayFreeDatas = array();
     foreach ($giveawayFrees as $data) {
         $obj = (object) array("id" => $data->id, "giveawayid" => $data->giveawayid, "price" => $data->price);
         array_push($giveawayFreeDatas, $obj);
     }
     $giveawayBuys = CarPreemptionGiveaway::where('free', false)->where('carpreemptionid', $id)->get(['id', 'giveawayid']);
     $giveawayBuyDatas = array();
     foreach ($giveawayBuys as $data) {
         $obj = (object) array("id" => $data->id, "giveawayid" => $data->giveawayid);
         array_push($giveawayBuyDatas, $obj);
     }
     $finacecompanyselectlist = array();
     array_push($finacecompanyselectlist, ':เลือกบริษัท');
     if ($model->purchasetype == 1) {
         $item = FinaceCompany::find($model->finacecompanyid);
         $finacecompanyselectlist[$item->id] = $item->name;
     }
     $interestratetypeselectlist = array();
     array_push($interestratetypeselectlist, ':เลือกประเภทอัตราดอกเบี้ย');
     if ($model->purchasetype == 1) {
         $item = InterestRateType::find($model->interestratetypeid);
         $interestratetypeselectlist[$item->id] = $item->name;
     }
     $priceselectlist = array();
     $item = Pricelist::find($model->pricelistid);
     if ($item->promotion != null && $item->promotion != '') {
         $priceselectlist[$item->id] = $item->sellingpricewithaccessories . ' (' . $item->promotion . ')';
     } else {
         $priceselectlist[$item->id] = $item->sellingpricewithaccessories;
     }
     $model->date = date('d-m-Y', strtotime($model->date));
     $model->datewantgetcar = date('d-m-Y', strtotime($model->datewantgetcar));
     $model->approvaldate = date('d-m-Y', strtotime($model->approvaldate));
     if ($model->contractdate != null && $model->contractdate != '') {
         $model->contractdate = date('d-m-Y', strtotime($model->contractdate));
     }
     return view('carpreemptionform', ['oper' => 'view', 'pathPrefix' => '../../', 'carpreemption' => $model, 'carprices' => array(), 'colorprices' => array(), 'provinceregistrationfee' => array(), 'giveawayFreeDatas' => $giveawayFreeDatas, 'giveawayBuyDatas' => $giveawayBuyDatas, 'provincebranchselectlist' => $provincebranchselectlist, 'customerselectlist' => $customerselectlist, 'provinceselectlist' => $provinceselectlist, 'bookingcustomeramphurselectlist' => $bookingcustomeramphurselectlist, 'buyercustomeramphurselectlist' => $buyercustomeramphurselectlist, 'bookingcustomerdistrictselectlist' => $bookingcustomerdistrictselectlist, 'buyercustomerdistrictselectlist' => $buyercustomerdistrictselectlist, 'occupationselectlist' => $occupationselectlist, 'carmodelselectlist' => $carmodelselectlist, 'carsubmodelselectlist' => $carsubmodelselectlist, 'colorselectlist' => $colorselectlist, 'oldcarbrandselectlist' => $oldcarbrandselectlist, 'oldcarmodelselectlist' => $oldcarmodelselectlist, 'giveawayselectlist' => implode(";", $giveawayselectlist), 'saleemployeeselectlist' => $saleemployeeselectlist, 'salemanageremployeeselectlist' => $salemanageremployeeselectlist, 'approveremployeeselectlist' => $approveremployeeselectlist, 'finacecompanyselectlist' => $finacecompanyselectlist, 'interestratetypeselectlist' => $interestratetypeselectlist, 'priceselectlist' => $priceselectlist, 'registerprovinceselectlist' => $registerprovinceselectlist]);
 }
 public function index()
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     $provinces = Province::whereHas('branchs', function ($q) {
         $q->where('isheadquarter', true);
     })->orderBy('name', 'asc')->get(['id', 'name']);
     $provinceselectlist = array();
     array_push($provinceselectlist, ':เลือกจังหวัด');
     foreach ($provinces as $item) {
         array_push($provinceselectlist, $item->id . ':' . $item->name);
     }
     $occupations = Occupation::orderBy('name', 'asc')->get(['id', 'name']);
     $occupationselectlist = array();
     array_push($occupationselectlist, ':เลือกอาชีพ');
     foreach ($occupations as $item) {
         array_push($occupationselectlist, $item->id . ':' . $item->name);
     }
     $addprovinces = Province::orderBy('name', 'asc')->get(['id', 'name']);
     $addprovinceselectlist = array();
     array_push($addprovinceselectlist, ':เลือกจังหวัด');
     foreach ($addprovinces as $item) {
         array_push($addprovinceselectlist, $item->id . ':' . $item->name);
     }
     $amphurs = Amphur::has('customers')->orderBy('name', 'asc')->get(['id', 'name']);
     $amphurselectlist = array();
     array_push($amphurselectlist, ':เลือกเขต/อำเภอ');
     foreach ($amphurs as $item) {
         array_push($amphurselectlist, $item->id . ':' . $item->name);
     }
     $districts = District::has('customers')->orderBy('name', 'asc')->get(['id', 'name']);
     $districtselectlist = array();
     array_push($districtselectlist, ':เลือกตำบล/แขวง');
     foreach ($districts as $item) {
         array_push($districtselectlist, $item->id . ':' . $item->name);
     }
     if (Auth::user()->isadmin) {
         $employees = Employee::orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'firstname', 'lastname']);
     } else {
         $provinceid = Auth::user()->provinceid;
         $employees = Employee::whereHas('branch', function ($q) use($provinceid) {
             $q->where('provinceid', $provinceid);
         })->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'firstname', 'lastname']);
     }
     $employeeselectlist = array();
     array_push($employeeselectlist, ':เลือกพนักงาน');
     foreach ($employees as $emp) {
         array_push($employeeselectlist, $emp->id . ':' . $emp->firstname . ' ' . $emp->lastname);
     }
     $carmodels = CarModel::whereHas("carbrand", function ($q) {
         $q->where('ismain', true);
     })->orderBy('name', 'asc')->get(['id', 'name']);
     $carmodelselectlist = array();
     array_push($carmodelselectlist, ':เลือกแบบ');
     foreach ($carmodels as $cm) {
         array_push($carmodelselectlist, $cm->id . ':' . $cm->name);
     }
     $colors = Color::all(['id', 'code', 'name']);
     $colorselectlist = array();
     array_push($colorselectlist, ':เลือกสี');
     foreach ($colors as $item) {
         array_push($colorselectlist, $item->id . ':' . $item->code . ' - ' . $item->name);
     }
     $defaultProvince = '';
     if (Auth::user()->isadmin == false) {
         $defaultProvince = Auth::user()->provinceid;
     }
     return view($this->viewname, ['colorselectlist' => implode(";", $colorselectlist), 'provinceselectlist' => implode(";", $provinceselectlist), 'addprovinceselectlist' => implode(";", $addprovinceselectlist), 'amphurselectlist' => implode(";", $amphurselectlist), 'districtselectlist' => implode(";", $districtselectlist), 'carmodelselectlist' => implode(";", $carmodelselectlist), 'employeeselectlist' => implode(";", $employeeselectlist), 'occupationselectlist' => implode(";", $occupationselectlist), 'defaultProvince' => $defaultProvince]);
 }