public function newcancelcarpreemption() { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } if (Auth::user()->isadmin) { $carpreemptions = CarPreemption::where('status', 0)->doesntHave('carPayment')->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no']); } else { $carpreemptions = CarPreemption::where('provinceid', Auth::user()->provinceid)->where('status', 0)->doesntHave('carPayment')->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no']); } $carpreemptionselectlist = array(); $carpreemptionselectlist[null] = 'เลือกการจอง'; foreach ($carpreemptions as $item) { $carpreemptionselectlist[$item->id] = $item->bookno . '/' . $item->no; } $carpreemptionid = SupportRequest::old('carpreemptionid'); if ($carpreemptionid != null && $carpreemptionid != '') { $carpreemption = CarPreemption::find($carpreemptionid); $model = Customer::find($carpreemption->buyercustomerid); $customer = $model->title . ' ' . $model->firstname . ' ' . $model->lastname; $model = CarModel::find($carpreemption->carmodelid); $model2 = CarSubModel::find($carpreemption->carsubmodelid); $carmodel = $model->name . '/' . $model2->name; $date = date('d-m-Y', strtotime($carpreemption->date)); $cashpledge = $carpreemption->cashpledge; $model = Employee::find($carpreemption->salesmanemployeeid); $salesmanemployee = $model->title . ' ' . $model->firstname . ' ' . $model->lastname; } else { $customer = null; $carmodel = null; $date = null; $cashpledge = null; $salesmanemployee = null; } if (Auth::user()->isadmin) { $toemployees = Employee::where('departmentid', 5)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } else { $toemployees = Employee::where('provinceid', Auth::user()->provinceid)->where('departmentid', 5)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } $toemployeeselectlist = array(); $toemployeeselectlist[null] = 'เลือกพนักงาน'; foreach ($toemployees as $item) { $toemployeeselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname; } if (Auth::user()->isadmin) { $accountandfinanceemployees = Employee::where('departmentid', 4)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } else { $accountandfinanceemployees = Employee::where('provinceid', Auth::user()->provinceid)->where('departmentid', 4)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } $accountandfinanceemployeeselectlist = array(); $accountandfinanceemployeeselectlist[null] = 'เลือกพนักงาน'; foreach ($accountandfinanceemployees as $item) { $accountandfinanceemployeeselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname; } $cancelcarpreemption = new CancelCarPreemption(); return view('cancelcarpreemptionform', ['oper' => 'new', 'pathPrefix' => '../', 'cancelcarpreemption' => $cancelcarpreemption, 'carpreemptionselectlist' => $carpreemptionselectlist, 'toemployeeselectlist' => $toemployeeselectlist, 'accountandfinanceemployeeselectlist' => $accountandfinanceemployeeselectlist, 'customer' => $customer, 'carmodel' => $carmodel, 'date' => $date, 'cashpledge' => $cashpledge, 'salesmanemployee' => $salesmanemployee]); }
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); } if (Auth::user()->isadmin) { $customers = Customer::has('redLabels')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } else { $customers = Customer::where('provinceid', Auth::user()->provinceid)->has('redLabels')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } $customerselectlist = array(); foreach ($customers as $item) { array_push($customerselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname); } if (Auth::user()->isadmin) { $cars = Car::has('redLabel')->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']); } else { $cars = Car::where('provinceid', Auth::user()->provinceid)->has('redLabel')->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']); } $carselectlist = array(); array_push($carselectlist, ':เลือกรถ'); foreach ($cars as $item) { array_push($carselectlist, $item->id . ':' . $item->chassisno . '/' . $item->engineno); } if (Auth::user()->isadmin) { $carpreemptions = CarPreemption::has('redlabelhistories')->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no', 'buyercustomerid', 'salesmanemployeeid']); } else { $carpreemptions = CarPreemption::where('provinceid', Auth::user()->provinceid)->has('redlabelhistories')->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no', 'buyercustomerid', 'salesmanemployeeid']); } $carpreemptionselectlist = array(); array_push($carpreemptionselectlist, ':เลือกการจอง'); foreach ($carpreemptions as $item) { $buyercustomer = Customer::find($item->buyercustomerid); $buyercustomername = $buyercustomer->title . ' ' . $buyercustomer->firstname . ' ' . $buyercustomer->lastname; $salesmanemployee = Employee::find($item->salesmanemployeeid); $salesmanemployeename = $salesmanemployee->title . ' ' . $salesmanemployee->firstname . ' ' . $salesmanemployee->lastname; array_push($carpreemptionselectlist, $item->id . ':' . str_pad($item->bookno . '/' . $item->no, strlen($item->bookno . '/' . $item->no) + 15, " ") . str_pad($buyercustomername, strlen($buyercustomername) + 15, " ") . $salesmanemployeename); } $defaultProvince = ''; if (Auth::user()->isadmin == false) { $defaultProvince = Auth::user()->provinceid; } return view('redlabel', ['provinceselectlist' => implode(";", $provinceselectlist), 'customerselectlist' => implode(";", $customerselectlist), 'carselectlist' => implode(";", $carselectlist), 'carpreemptionselectlist' => implode(";", $carpreemptionselectlist), 'defaultProvince' => $defaultProvince]); }
public function newcarpayment() { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } if (Auth::user()->isadmin) { $carpreemptions = CarPreemption::where('status', 0)->where(function ($query) { $query->where('carobjectivetype', 1)->orWhere(function ($query) { $query->where('cashpledgeredlabel', 0)->orWhereHas('redlabelhistories', function ($q) { $q->whereNull('returndate'); }); }); })->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no']); } else { $carpreemptions = CarPreemption::where('provinceid', Auth::user()->provinceid)->where('status', 0)->where(function ($query) { $query->where('carobjectivetype', 1)->orWhere(function ($query) { $query->where('cashpledgeredlabel', 0)->orWhereHas('redlabelhistories', function ($q) { $q->whereNull('returndate'); }); }); })->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no']); } $carpreemptionselectlist = array(); $carpreemptionselectlist[null] = 'เลือกการจอง'; foreach ($carpreemptions as $item) { $carpreemptionselectlist[$item->id] = $item->bookno . '/' . $item->no; } $carpreemptionid = SupportRequest::old('carpreemptionid'); $carselectlist = array(); $carselectlist[null] = 'เลือกรถ'; $purchasetype0 = false; $purchasetype1 = false; $carobjectivetype0 = false; $carobjectivetype1 = false; $registrationtype0 = false; $registrationtype1 = false; $registrationtype2 = false; if ($carpreemptionid != null && $carpreemptionid != '') { $carpreemption = CarPreemption::find($carpreemptionid); if ($carpreemption->purchasetype == 0) { $purchasetype0 = true; $purchasetype1 = false; } elseif ($carpreemption->purchasetype == 1) { $purchasetype0 = false; $purchasetype1 = true; } if ($carpreemption->carobjectivetype == 0) { $carobjectivetype0 = true; $carobjectivetype1 = false; } elseif ($carpreemption->carobjectivetype == 1) { $carobjectivetype0 = false; $carobjectivetype1 = true; } if ($carpreemption->registrationtype == 0) { $registrationtype0 = true; $registrationtype1 = false; $registrationtype2 = false; } elseif ($carpreemption->registrationtype == 1) { $registrationtype0 = false; $registrationtype1 = true; $registrationtype2 = false; } elseif ($carpreemption->registrationtype == 2) { $registrationtype0 = false; $registrationtype1 = false; $registrationtype2 = true; } if (Auth::user()->isadmin) { if ($carpreemption->carobjectivetype == 0) { $cars = Car::doesntHave('carPayment')->where('objective', 0)->where('carmodelid', $carpreemption->carmodelid)->where('carsubmodelid', $carpreemption->carsubmodelid)->where('colorid', $carpreemption->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']); } else { $cars = Car::doesntHave('carPayment')->where('objective', '!=', 0)->where('carmodelid', $carpreemption->carmodelid)->where('carsubmodelid', $carpreemption->carsubmodelid)->where('colorid', $carpreemption->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']); } } else { if ($carpreemption->carobjectivetype == 0) { $cars = Car::where('provinceid', Auth::user()->provinceid)->doesntHave('carPayment')->where('objective', 0)->where('carmodelid', $carpreemption->carmodelid)->where('carsubmodelid', $carpreemption->carsubmodelid)->where('colorid', $carpreemption->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']); } else { $cars = Car::where('provinceid', Auth::user()->provinceid)->doesntHave('carPayment')->where('objective', '!=', 0)->where('carmodelid', $carpreemption->carmodelid)->where('carsubmodelid', $carpreemption->carsubmodelid)->where('colorid', $carpreemption->colorid)->orderBy('chassisno', 'asc')->orderBy('engineno', 'asc')->get(['id', 'chassisno', 'engineno']); } } foreach ($cars as $item) { $carselectlist[$item->id] = $item->chassisno . '/' . $item->engineno; } } $insurancecompanies = InsuranceCompany::orderBy('name', 'asc')->get(['id', 'name']); $insurancecompanyselectlist = array(); $insurancecompanyselectlist[null] = 'เลือกบริษัท'; foreach ($insurancecompanies as $item) { $insurancecompanyselectlist[$item->id] = $item->name; } if (Auth::user()->isadmin) { $payeeemployees = Employee::where('departmentid', 4)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } else { $payeeemployees = Employee::where('provinceid', Auth::user()->provinceid)->where('departmentid', 4)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } $payeeemployeeselectlist = array(); $payeeemployeeselectlist[null] = 'เลือกพนักงาน'; foreach ($payeeemployees as $item) { $payeeemployeeselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname; } $carpayment = new CarPayment(); $carpayment->date = date('d-m-Y'); return view('carpaymentform', ['oper' => 'new', 'pathPrefix' => '../', 'carpayment' => $carpayment, 'carpreemptionselectlist' => $carpreemptionselectlist, 'carselectlist' => $carselectlist, 'insurancecompanyselectlist' => $insurancecompanyselectlist, 'payeeemployeeselectlist' => $payeeemployeeselectlist, 'purchasetype0' => $purchasetype0, 'purchasetype1' => $purchasetype1, 'carobjectivetype0' => $carobjectivetype0, 'carobjectivetype1' => $carobjectivetype1, 'registrationtype0' => $registrationtype0, 'registrationtype1' => $registrationtype1, 'registrationtype2' => $registrationtype2]); }
public function readCarPreemptionSelectlistForDisplayInGrid($redlabelid) { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } if (Auth::user()->isadmin) { $carpreemptions = CarPreemption::whereHas('redlabelhistories', function ($q) use($redlabelid) { $q->where('redlabelid', $redlabelid); })->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no', 'buyercustomerid', 'salesmanemployeeid']); } else { $carpreemptions = CarPreemption::where('provinceid', Auth::user()->provinceid)->whereHas('redlabelhistories', function ($q) use($redlabelid) { $q->where('redlabelid', $redlabelid); })->orderBy('bookno', 'asc')->orderBy('no', 'asc')->get(['id', 'bookno', 'no', 'buyercustomerid', 'salesmanemployeeid']); } $carpreemptionselectlist = array(); array_push($carpreemptionselectlist, ':เลือกการจอง'); foreach ($carpreemptions as $item) { $buyercustomer = Customer::find($item->buyercustomerid); $buyercustomername = $buyercustomer->title . ' ' . $buyercustomer->firstname . ' ' . $buyercustomer->lastname; $salesmanemployee = Employee::find($item->salesmanemployeeid); $salesmanemployeename = $salesmanemployee->title . ' ' . $salesmanemployee->firstname . ' ' . $salesmanemployee->lastname; array_push($carpreemptionselectlist, $item->id . ':' . str_pad($item->bookno . '/' . $item->no, strlen($item->bookno . '/' . $item->no) + 15, " ") . str_pad($buyercustomername, strlen($buyercustomername) + 15, " ") . $salesmanemployeename); } return ['carpreemptionselectlist' => implode(";", $carpreemptionselectlist)]; }