public function index() { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } $bookingcustomers = Customer::has('bookingCarPreemptions')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); $bookingcustomerselectlist = array(); foreach ($bookingcustomers as $item) { array_push($bookingcustomerselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname); } $carmodels = CarModel::has('carPreemptions')->orderBy('name', 'asc')->get(['id', 'name']); $carmodelselectlist = array(); foreach ($carmodels as $item) { array_push($carmodelselectlist, $item->id . ':' . $item->name); } $carsubmodels = CarSubModel::has('carPreemptions')->orderBy('name', 'asc')->get(['id', 'name']); $carsubmodelselectlist = array(); foreach ($carsubmodels as $item) { array_push($carsubmodelselectlist, $item->id . ':' . $item->name); } $colors = Color::has('carPreemptions')->orderBy('code', 'asc')->get(['id', 'code', 'name']); $colorselectlist = array(); foreach ($colors as $item) { array_push($colorselectlist, $item->id . ':' . $item->code . ' - ' . $item->name); } $buyercustomers = Customer::has('buyerCarPreemptions')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); $buyercustomerselectlist = array(); foreach ($buyercustomers as $item) { array_push($buyercustomerselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname); } $salesmanemployees = Employee::has('salesmanCarPreemptions')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); $salesmanemployeeselectlist = array(); foreach ($salesmanemployees as $item) { array_push($salesmanemployeeselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname); } $salesmanageremployees = Employee::has('salesmanagerCarPreemptions')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); $salesmanageremployeeselectlist = array(); foreach ($salesmanageremployees as $item) { array_push($salesmanageremployeeselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname); } $approversemployees = Employee::has('approversCarPreemptions')->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); $approversemployeeselectlist = array(); foreach ($approversemployees as $item) { array_push($approversemployeeselectlist, $item->id . ':' . $item->title . ' ' . $item->firstname . ' ' . $item->lastname); } $pricelists = Pricelist::has('carPreemptions')->orderBy('sellingpricewithaccessories', 'asc')->get(['id', 'sellingpricewithaccessories', 'promotion']); $priceselectlist = array(); foreach ($pricelists as $item) { //if($item->promotion != null && $item->promotion != '') //array_push($priceselectlist,$item->id.':'.$item->sellingpricewithaccessories.' ('.$item->promotion.')'); //else array_push($priceselectlist, $item->id . ':' . $item->sellingpricewithaccessories); } return view('carpreemption', ['bookingcustomerselectlist' => implode(";", $bookingcustomerselectlist), 'carmodelselectlist' => implode(";", $carmodelselectlist), 'carsubmodelselectlist' => implode(";", $carsubmodelselectlist), 'colorselectlist' => implode(";", $colorselectlist), 'buyercustomerselectlist' => implode(";", $buyercustomerselectlist), 'salesmanemployeeselectlist' => implode(";", $salesmanemployeeselectlist), 'salesmanageremployeeselectlist' => implode(";", $salesmanageremployeeselectlist), 'approversemployeeselectlist' => implode(";", $approversemployeeselectlist), 'priceselectlist' => implode(";", $priceselectlist)]); }
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]); }