public function getSearch(Request $request) { $q = $request->get('q'); $limit = $request->get('limit', 5); $customers = Customer::where('mobile_phone', 'like', $q . '%')->with('addresses')->paginate($limit); return $customers; }
public function test() { $customer = Customer::where('openid', 'oUS_vt3J8ClZx4q1wmx6VBJ1KfwQ')->firstOrFail(); $end = new \DateTime(Carbon::now()->format('Y-m')); $begin = new \DateTime($customer->created_at->format('Y-m')); $month = \Helper::getDatePeriod($begin, $end); dd($month); }
public function showDetail($id) { $customer = Customer::where('kode', $id)->firstOrFail(); $reservation = Reservation::where('customer_kode', $id)->orderBy('created_at', 'desc')->firstOrFail(); $transaksi = Reservation::where('customer_kode', $id)->orderBy('id', 'desc')->get(); $sisabayar = DB::table('reservation')->where('customer_kode', '=', $id)->sum('cash'); $tagihan = $reservation->total - $sisabayar; return view('reservation.detail', compact('customer', 'reservation', 'tagihan', 'transaksi')); }
public function beansLogForUnionId(Request $request) { $unionid = $request->input('unionid'); try { $customer = Customer::where('unionid', $unionid)->firstOrFail(); $beans_log = $customer->beans()->with('rate')->get(); return response()->json(['success' => true, 'data' => ['beans_log' => $beans_log->toArray()]]); } catch (ModelNotFoundException $e) { return response()->json(['success' => false, 'error' => 'No such customer.']); } }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $customer = Customer::where('name', $data['name'])->first(); if (!$customer) { $customer = Customer::create($data); } // We'll need to link the customer and user in this method $user = User::create(['email' => $data['email'], 'password' => bcrypt($data['password']), 'sex' => $data['sex'], 'birthdate' => $data['birthdate'], 'customer_id' => $customer->id]); event(new UserRegistered($user)); return $user; }
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 moveUser() { $wechat = new Wechat(); $arr = Customer::where('referrer_id', 25011)->skip(4000)->take(500)->get(); foreach ($arr as $k => $v) { $result = $wechat->moveUserToGroup($v->openid, 103); $a = json_decode($result); // print_r($v->nickname);echo '<br/>'; if ($a->errcode == 0) { echo $v->nickname . '--移动分组成功' . $a->errcode . '<br.>'; } else { echo $v->nickname . '--移动分组失败' . $a->errcode . '<br.>'; } } }
public function getReport(Request $request) { $customers = Customer::where('status', 1)->lists('name', 'id'); $employees = Employee::where('status', 1)->lists('name', 'id'); $suppliers = Supplier::where('status', 1)->lists('company_name', 'id'); $cashInHand = DB::table('workspace_ledgers')->where(['account_code' => 11000, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => CommonHelper::get_current_financial_year()])->sum('balance'); $sales = DB::table('general_journals')->select('general_journals.*', 'chart_of_accounts.name', 'sales_order.customer_id', 'sales_order.customer_type')->join('chart_of_accounts', 'chart_of_accounts.code', '=', 'general_journals.account_code')->join('sales_order', 'sales_order.id', '=', 'general_journals.reference_id')->where(['transaction_type' => Config::get('common.transaction_type.sales'), 'account_code' => 31000, 'year' => CommonHelper::get_current_financial_year(), 'general_journals.status' => 1])->where('general_journals.date', '=', strtotime(date('d-m-Y')))->get(); $salesReturns = DB::table('general_journals')->select('general_journals.*', 'chart_of_accounts.name', 'sales_order.customer_id', 'sales_order.customer_type')->join('chart_of_accounts', 'chart_of_accounts.code', '=', 'general_journals.account_code')->join('sales_order', 'sales_order.id', '=', 'general_journals.reference_id')->where(['transaction_type' => Config::get('common.transaction_type.sales_return'), 'account_code' => 32000, 'year' => CommonHelper::get_current_financial_year(), 'general_journals.status' => 1])->where('general_journals.date', '=', strtotime(date('d-m-Y')))->get(); $expenses = DB::table('general_journals')->select('general_journals.*', 'chart_of_accounts.name')->join('chart_of_accounts', 'chart_of_accounts.code', '=', 'general_journals.account_code')->where('general_journals.account_code', 'like', '2%')->where('general_journals.date', '=', strtotime(date('d-m-Y')))->get(); $sales = json_decode(json_encode($sales), true); $salesReturns = json_decode(json_encode($salesReturns), true); $expenses = json_decode(json_encode($expenses), true); $ajaxView = view('reports.cashFlow.view', compact('sales', 'salesReturns', 'expenses', 'customers', 'employees', 'suppliers', 'cashInHand'))->render(); return response()->json($ajaxView); }
/** * Function to add a new customer to the database * * Returns customer id for appointment creation * **/ public static function addCustomer() { // We get appointment information then set up our validator $info = Session::get('appointmentInfo'); $validator = Validator::make(array('first_name' => $info['fname'], 'last_name' => $info['lname'], 'email' => $info['email']), array('first_name' => 'exists:customers,first_name', 'last_name' => 'exists:customers,last_name', 'email' => 'exists:customers,email')); // If the validator fails, that means the user does not exist // If any of those three variables don't exist, we create a new user // This is so that families can use the same e-mail to book, but // We stil create a new user for them in the database. if ($validator->fails()) { // Registering the new user return Customer::create(array('first_name' => $info['fname'], 'last_name' => $info['lname'], 'contact_number' => $info['number'], 'email' => $info['email'], 'wants_updates' => Session::get('updates')))->id; } else { return Customer::where('email', $info['email'])->pluck('id'); } }
public function index(Request $request){ $search = $request->input('search'); if($search){ $customers = Customer::where('type', '=', 'customer') ->where('lastname', 'LIKE', '%'.$search.'%') ->orWhere('firstname','LIKE','%'.$search.'%') ->get(); }else{ $customers = Customer::where('type', '=', 'customer')->get(); } $data = [ 'customers' => $customers, 'subnav' => $this->default_sub_nav ]; return view('customers.index', $data); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { try { $user = \Helper::getSessionCachedUser(); $customer = Customer::where('openid', $user['openid'])->firstOrFail(); return $next($request); } catch (UserNotSubscribedException $e) { return redirect(AppConstant::ATTENTION_URL); } catch (UserNotCachedException $e) { return redirect(AppConstant::ATTENTION_URL); } catch (ModelNotFoundException $e) { /** @var array $user */ Customer::create(['openid' => $user['openid'], 'nickname' => $user['nickname'], 'unionid' => isset($user['unionid']) ? $user['unionid'] : null, 'head_image_url' => $user['headimgurl'], 'type_id' => 1]); return $next($request); } }
public function persist() { $filename = $this->moveToLocalStorage($this->file('doctor-information')); \Excel::load(storage_path('app/doctor-information/' . $filename), function (LaravelExcelReader $reader) { $result = $reader->get(); foreach ($result as $row) { $param = ['name' => $row['姓名'], 'type' => substr(trim($row['等级']), 0, 1), 'level' => 5, 'hospital' => $row['所属医院'], 'hospital_level' => $row['医院级别'], 'department' => $row['科室'], 'phone' => strval(intval($row['注册电话'])), 'referred_name' => $row['推荐代表'], 'referred_phone' => strval(intval($row['代表电话'])), 'region' => $row['区域9大区'], 'region_level' => $row['销售大区级别'], 'responsible' => $row['销售地区级别']]; if ($customer = Customer::where('phone', strval(intval($row['注册电话'])))->first()) { $param['customer_id'] = $customer->id; } if ($customer_info = CustomerInformation::where('phone', strval(intval($row['注册电话'])))->first()) { $customer_info->update($param); return; } CustomerInformation::create($param); } }); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { try { $user = \Helper::getSessionCachedUser(); $customer = Customer::where('openid', $user['openid'])->firstOrFail(); if (!$customer->is_registered) { \Session::put('register_next_url', $request->fullUrl()); return redirect('/register/create'); } /*if>*/ if ($this->userDatabaseExpired($customer)) { $this->refreshUserDatabase($user, $customer); } /*if>*/ return $next($request); } catch (UserNotSubscribedException $e) { return redirect(AppConstant::ATTENTION_URL); } catch (UserNotCachedException $e) { return redirect(AppConstant::ATTENTION_URL); } catch (ModelNotFoundException $e) { return redirect(AppConstant::ATTENTION_URL); } /*catch>*/ }
protected static function getDoctorCount() { return \Cache::remember('enterprise_doctor_count', 60, function () { return Customer::where('type_id', 4)->count(); }); }
public function store(Request $request) { $customerInformation = CustomerInformation::create(['name' => $request->input('name'), 'hospital' => $request->input('hospital'), 'province' => $request->input('province'), 'city' => $request->input('city'), 'district' => $request->input('district'), 'department' => $request->input('department'), 'remark' => $request->input('remark'), 'type' => $request->input('type'), 'referred_name' => $request->input('referred_name'), 'referred_phone' => $request->input('referred_phone'), 'region' => $request->input('region'), 'region_level' => $request->input('region_level'), 'responsible' => $request->input('responsible'), 'hospital_level' => $request->input('hospital_level'), 'phone' => $request->input('phone')]); $inputPhone = $request->input('phone'); if ($inputPhone) { $customer = Customer::where('phone', $inputPhone)->first(); if ($customer) { $customerInformation->update(['customer_id' => $customer->id]); } else { $customerInformation->update(['customer_id' => null]); } } if ($request->has('beans_total') && $customer) { $customer->update(['beans_total' => $request->input('beans_total')]); } if ($request->has('type_id') && $customer) { $customer->update(['type_id' => $request->input('type_id')]); } if ($customer) { return response()->json(['success' => true, 'data' => ['customer' => $customer->with('information')]]); } else { return response()->json(['success' => true, 'data' => ['customer' => null]]); } }
public function edit($id) { $salesOrder = SalesOrder::where('id', $id)->where('status', '!=', 4)->with(['salesOrderItems', 'salesOrderItems.product', 'salesOrderItems.salesDelivery'])->first(); if ($salesOrder->customer_type == 1) { $customers = Employee::where('status', 1)->lists('name', 'id'); } elseif ($salesOrder->customer_type == 2) { $customers = Supplier::where('status', 1)->lists('name', 'id'); } else { $customers = Customer::where('status', 1)->lists('name', 'id'); } if ($salesOrder->customer_id) { $personalAccount = PersonalAccount::where('person_id', '=', $salesOrder->customer_id)->where('person_type', '=', $salesOrder->customer_type)->first(); } return view('sales.salesOrder.edit')->with(compact('salesOrder', 'customers', 'personalAccount')); }
public function create() { $customers = Customer::where('status', 1)->lists('name', 'id'); return view('sales.salesReturn.create')->with('customers', $customers); }
/** * @return \Closure */ public function subscribeEventCallback() { return function ($event) { // \Log::info('yijian:0831::---' . $event); \Log::info('subscribe' . $event); $openId = $event['FromUserName']; $eventKey = $event['EventKey']; $customer = Customer::where('openid', $openId)->first(); if ($customer) { if ($eventKey == 'qrscene_25011') { \Log::info('test 1:::---' . $event); $this->moveUserToGroup($openId, 103); //移动用户分组 return Message::make('text')->content("嗨!欢迎关注小易,我们有全面及时的糖尿病教育资讯和便捷丰富的在线商城。首次注册即赠送价值10元的迈豆,持续学习迈豆享不停,快来尽情换购吧\n\n<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire2/\">点击此处,快来1元换购胰岛素针头!</a>"); } elseif ($eventKey == 'qrscene_25005') { return Message::make('text')->content("亲爱的用户:欢迎您关注易康伴侣,为普及糖尿病知识,提高大众对糖尿病认知水平,易康伴侣现发起全民“斗糖大赛”活动,邀您参与。每次5道题,答对3题及以上即可开启换购,支付1到3元不等即可换购对应商品,易折棉棒、低糖卫士、胰岛素针头等您领取。<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire3/\">点击此处</a>,立即斗起来!"); } else { \Log::info('test 2:::---' . $event); return Message::make('text')->content('欢迎您回来!'); } } $customer = new Customer(); $customer->openid = $openId; $typeId = CustomerType::where('type_en', AppConstant::CUSTOMER_COMMON)->first()->id; $customer->type_id = $typeId; if (is_array($eventKey) && 0 == count($eventKey)) { \Log::info('test 3:::---' . $event); $customer->referrer_id = 0; } else { \Log::info('test 4:::---' . $event); $referrer_str = substr($eventKey, 8); if (strlen($referrer_str) > 10) { //假如是32位随机数,则为瞬联的旧版用户 $referrer = Customer::where('old_id', $referrer_str)->first(); } else { $referrerId = (int) $referrer_str; $referrer = Customer::where('id', $referrerId)->first(); } if (!$referrer || !$referrer->is_registered) { $customer->referrer_id = 0; } else { $customer->referrer_id = $referrer->id; } /*else>*/ } $customer->save(); \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_FOCUS); if ($eventKey == 'qrscene_25011') { $this->moveUserToGroup($openId, 103); //移动用户分组 \Log::info('test 5:::---' . $event); return Message::make('text')->content("嗨!欢迎关注小易,我们有全面及时的糖尿病教育资讯和便捷丰富的在线商城。首次注册即赠送价值10元的迈豆,持续学习迈豆享不停,快来尽情换购吧\n\n<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire2/\">点击此处,快来1元换购胰岛素针头!</a>"); } elseif ($eventKey == 'qrscene_25005') { return Message::make('text')->content("亲爱的用户:欢迎您关注易康伴侣,为普及糖尿病知识,提高大众对糖尿病认知水平,易康伴侣现发起全民“斗糖大赛”活动,邀您参与。每次5道题,答对3题及以上即可开启换购,支付1到3元不等即可换购对应商品,易折棉棒、低糖卫士、胰岛素针头等您领取。<a target=\"_blank\" href=\"http://www.ohmate.cn/questionnaire3/\">点击此处</a>,立即斗起来!"); } $upper = $customer->getReferrer(); if ($upper && $upper->doctorType() == 'A') { return Message::make('news')->items(function () { return [Message::make('news_item')->title('问卷有礼')->description('问卷有礼')->url(url('/questionnaire'))->picUrl('http://7xrlyr.com1.z0.glb.clouddn.com/填调查问卷.jpg')]; }); } $content = '嗨!欢迎关注易康伴侣!' . '在此您能任性享用新鲜实用的糖尿病资讯。' . '您学习,我送礼;' . '您消费,我奖励。' . '一大波迈豆等您拿,注册立奖10元!'; return Message::make('text')->content($content); }; }
public static function boot() { parent::boot(); static::creating(function ($model) { $employee = Employee::find($model->salesmanemployeeid); $model->salesmanteamid = $employee->teamid; $model->provinceid = $employee->branch->provinceid; $model->branchid = $employee->branchid; $model->status = 0; if ($model->carobjectivetype == 0) { $model->financingfee = null; $model->transferfee = null; $model->transferoperationfee = null; } else { if ($model->carobjectivetype == 1) { $model->cashpledgeredlabel = null; $model->registerprovinceid = null; $model->registrationtype = null; $model->registrationfee = null; } } if ($model->contractdate == '') { $model->contractdate = null; } $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); Customer::where('id', $model->bookingcustomerid)->orWhere('id', $model->buyercustomerid)->update(['statusexpect' => 0]); $bookingcustomerid = $model->bookingcustomerid; $buyercustomerid = $model->buyercustomerid; CustomerExpectation::where('active', true)->where(function ($query) use($bookingcustomerid, $buyercustomerid) { $query->where('customerid', $bookingcustomerid)->orWhere('customerid', $buyercustomerid); })->update(['active' => false]); }); static::updating(function ($model) { if ($model->carobjectivetype == 0) { $model->financingfee = null; $model->transferfee = null; $model->transferoperationfee = null; } else { if ($model->carobjectivetype == 1) { $model->cashpledgeredlabel = null; $model->registerprovinceid = null; $model->registrationtype = null; $model->registrationfee = null; } } if ($model->contractdate == '') { $model->contractdate = null; } $model->carPreemptionGiveaways()->delete(); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
public function edit($id) { $transaction = Transaction::find($id); $customer = Customer::where('id', '=', $transaction->customer_id)->firstOrFail(); $status = Status::lists('name', 'id'); return view('transactions.edit', compact(['transaction', 'customer', 'status'])); }
/** * 增加约谈记录 */ public function interviewAdd() { // dd($this->request->all()); $interview = new Interview(); //获取约谈字段 $interview->investor_id = $this->user()->id; $interview->project_id = $this->request->get('project_id'); $interview->interview_date = $this->request->get('date'); $interview->interview_time = $this->request->get('time'); $interview->interview_address = $this->request->get('address'); // $interview->interview_amount = $this->request->get('amount'); $interview->interview_desc = $this->request->get('desc'); //查询项目创建人 $project = CompanyProject::find($interview->project_id); if (empty($project)) { return return_rest('0', '', '没有找到该项目'); } $customer = Customer::where('is_company_creator', 1)->where('company_id', $project->company_id)->first(); if (empty($customer)) { return return_rest('0', '', '该项目没有创始人'); } $interview->creator_id = $customer->id; if ($interview->save()) { return return_rest('1', '', '提交成功'); } return return_rest('0', '', '提交失败,约harry'); }
public function update(CustomerRequest $request, $id) { $inputs = $request->input(); $file = $request->file('picture'); $destinationPath = base_path() . '/public/image/customer/'; if ($request->hasFile('picture')) { $name = time() . $file->getClientOriginalName(); $file->move($destinationPath, $name); $inputs['picture'] = $name; } $inputs['updated_by'] = Auth::user()->id; $inputs['updated_at'] = time(); // $customer=Customer::findOrFail($id); unset($inputs['_method']); unset($inputs['_token']); Customer::where(['id' => $id])->update($inputs); Session::flash('flash_message', 'Customer updated successfully'); return redirect('customers'); }
public function getQuestionnaireCountAttribute() { $key = 'questionnaire_count_' . $this->id; if (!request()->has('force_search')) { return 0; } $result = \Cache::remember($key, 60, function () { return Customer::where('referrer_id', $this->id)->has('yikangQuestionnaire')->count(); }); return $result; }
public function registercc(Request $request) { $c = new Coa(); $c->id = $request->input('id'); $c->code = $request->input('code'); $name = explode("+", $request->input('name')); $c->name = $name[1]; $c->description = $request->input('description'); $c->increasetypeid = $request->input('increasetypeid'); $c->taxrateid = $request->input('taxrateid'); $c->coatypeid = $request->input('coatypeid'); $c->userid = $request->input('userid'); $c->save(); $pid = $request->input('code'); Customer::where('code', $pid)->update(['coastatus' => 1]); //$cn=$request->input('name'); //Customer::where('name',$cn)->update(['customerstatus' => 1]); return redirect('coa'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // $feed = Feed::where('id', $id)->get(); //$customers = Customer::where('id', $feed->first()->customer_id)->lists('name','id'); $customers = Customer::where('id', $feed->first()->customer_id)->get(); return view('feeds.edit', compact('customers', 'feed')); }
public function edit($id) { $customers = Customer::where('status', 1)->lists('name', 'id'); $suppliers = Supplier::where('status', 1)->lists('company_name', 'id'); $employees = Supplier::where('status', 1)->lists('name', 'id'); $providers = Supplier::where('status', 1)->lists('name', 'id'); $materials = Material::where('type', array_flip(Config::get('common.material_type'))['Discarded'])->lists('name', 'id'); $discardedSales = DiscardedSales::with(['DiscardedSalesDetail' => function ($q) { $q->where('status', 1); }])->findOrFail($id); return view('discardedSales.edit', compact('discardedSales', 'customers', 'materials', 'suppliers', 'employees', 'providers')); }
/** * @SWG\Api( * path="/customer/login", * @SWG\Operation( * nickname="Login", * method="POST", * summary="Login cusomer", * type="Customer", * authorizations={}, * @SWG\Parameter( * name="login", * description="Login", * required=true, * type="string", * paramType="form", * allowMultiple=false * ), * @SWG\Parameter( * name="password", * description="Password", * required=true, * type="string", * paramType="form", * allowMultiple=false * ), * @SWG\ResponseMessage(code=404, message="Customer not found"), * @SWG\ResponseMessage(code=500, message="Internal server error") * ) * ) */ public function login() { $statusCode = 200; $inputs = \Input::all(); try { $customerModel = Models\Customer::where(['login' => $inputs['login'], 'password' => $inputs['password']])->first(); if (!isset($customerModel)) { throw new ModelNotFoundException(); } $customerView = new ModelViews\Customer($customerModel); $response = $customerView->get(); } catch (ModelNotFoundException $e) { $response = ['error' => 'Customer doesn\'t exists']; $statusCode = 404; } finally { return \Response::json($response, $statusCode); } }
public function edit($id) { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } $model = CarPreemption::find($id); $carPayment = CarPayment::where('carpreemptionid', $id)->first(); if (!Auth::user()->isadmin && $carPayment != null && $carPayment->deliverycarbookno != null && $carPayment->deliverycarbookno != '') { return "ไม่สามารถแก้ไขข้อมูลการจองได้ เนื่องจากมีการส่งรถแล้ว!!"; } $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) { $model->buyertype = 1; $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)); } } else { $model->buyertype = 0; } $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; } if (Auth::user()->isadmin) { $customers = Customer::orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } else { $customers = Customer::where('provinceid', Auth::user()->provinceid)->orderBy('firstname', 'asc')->orderBy('lastname', 'asc')->get(['id', 'title', 'firstname', 'lastname']); } $customerselectlist = array(); $customerselectlist[null] = 'เลือกชื่อลูกค้า'; foreach ($customers as $item) { $customerselectlist[$item->id] = $item->title . ' ' . $item->firstname . ' ' . $item->lastname; } $provinces = Province::orderBy('name', 'asc')->get(['id', 'name']); $provinceselectlist = array(); $provinceselectlist[null] = 'เลือกจังหวัด'; foreach ($provinces as $item) { $provinceselectlist[$item->id] = $item->name; } $bookingcustomeramphurs = Amphur::where('provinceid', $model->bookingcustomerprovinceid)->orderBy('name', 'asc')->get(['id', 'name']); $bookingcustomeramphurselectlist = array(); $bookingcustomeramphurselectlist[null] = 'เลือกเขต/อำเภอ'; foreach ($bookingcustomeramphurs as $item) { $bookingcustomeramphurselectlist[$item->id] = $item->name; } $buyercustomeramphurselectlist = array(); if ($model->bookingcustomerid != $model->buyercustomerid) { $buyercustomeramphurs = Amphur::where('provinceid', $model->buyercustomerprovinceid)->orderBy('name', 'asc')->get(['id', 'name']); $buyercustomeramphurselectlist[null] = 'เลือกเขต/อำเภอ'; foreach ($buyercustomeramphurs as $item) { $buyercustomeramphurselectlist[$item->id] = $item->name; } } $bookingcustomerdistricts = District::where('amphurid', $model->bookingcustomeramphurid)->orderBy('name', 'asc')->get(['id', 'name']); $bookingcustomerdistrictselectlist = array(); $bookingcustomerdistrictselectlist[null] = 'เลือกแขวง/ตำบล'; foreach ($bookingcustomerdistricts as $item) { $bookingcustomerdistrictselectlist[$item->id] = $item->name; } $buyercustomerdistrictselectlist = array(); if ($model->bookingcustomerid != $model->buyercustomerid) { $buyercustomerdistricts = District::where('amphurid', $model->buyercustomeramphurid)->orderBy('name', 'asc')->get(['id', 'name']); $buyercustomerdistrictselectlist[null] = 'เลือกแขวง/ตำบล'; foreach ($buyercustomerdistricts as $item) { $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; } $carmodels = CarModel::whereHas("carbrand", function ($q) { $q->where('ismain', true); })->orderBy('name', 'asc')->get(['id', 'name']); $carmodelselectlist = array(); $carmodelselectlist[null] = 'เลือกแบบ'; foreach ($carmodels as $item) { $carmodelselectlist[$item->id] = $item->name; } $carsubmodels = CarSubModel::where('carmodelid', $model->carmodelid)->orderBy('name', 'asc')->get(['id', 'name']); $carsubmodelselectlist = array(); $carsubmodelselectlist[null] = 'เลือกรุ่น'; foreach ($carsubmodels as $item) { $carsubmodelselectlist[$item->id] = $item->name; } $colorprices = array(); $colors = Color::with(['carModelColors' => function ($query) use($model) { $query->where('carmodelid', $model->carmodelid); }])->whereHas('carModelColors', function ($q) use($model) { $q->where('carmodelid', $model->carmodelid); })->orderBy('code', 'asc')->get(['id', 'code', 'name']); $colorselectlist = array(); $colorselectlist[null] = 'เลือกสี'; foreach ($colors as $item) { $colorselectlist[$item->id] = $item->code . ' - ' . $item->name; $obj = (object) array("colorid" => $item->id, "price" => $item->carModelColors[0]->price); array_push($colorprices, $obj); } $provinceregistrationfee = array(); $provinces = Province::with(['carModelRegisters' => function ($query) use($model) { $query->where('carmodelid', $model->carmodelid); }])->whereHas('carModelRegisters', function ($q) use($model) { $q->where('carmodelid', $model->carmodelid); })->orderBy('name', 'asc')->get(['id', 'name']); $registerprovinceselectlist = array(); $registerprovinceselectlist[null] = 'เลือกจังหวัด'; foreach ($provinces as $item) { $registerprovinceselectlist[$item->id] = $item->name; $registrationfee = array(); array_push($registrationfee, (object) array("type" => 0, "price" => $item->carModelRegisters[0]->individualregistercost)); array_push($registrationfee, (object) array("type" => 1, "price" => $item->carModelRegisters[0]->companyregistercost)); array_push($registrationfee, (object) array("type" => 2, "price" => $item->carModelRegisters[0]->governmentregistercost)); $obj = (object) array("provinceid" => $item->id, "registrationfee" => $registrationfee); array_push($provinceregistrationfee, $obj); } $oldcarbrands = CarBrand::where('ismain', false)->orderBy('name', 'asc')->get(['id', 'name']); $oldcarbrandselectlist = array(); $oldcarbrandselectlist[null] = 'เลือกยี่ห้อรถ'; foreach ($oldcarbrands as $item) { $oldcarbrandselectlist[$item->id] = $item->name; } $oldcarmodels = CarModel::where('carbrandid', $model->oldcarbrandid)->orderBy('name', 'asc')->get(['id', 'name']); $oldcarmodelselectlist = array(); $oldcarmodelselectlist[null] = 'เลือกแบบ'; foreach ($oldcarmodels as $item) { $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 . ' บาท)'); } $giveawayFreeDatas = array(); $giveawayBuyDatas = array(); $giveawayFreeData = SupportRequest::old('giveawayFreeData'); $giveawayBuyData = SupportRequest::old('giveawayBuyData'); if ($giveawayFreeData != null && $giveawayFreeData != '') { $giveawayFreeData = json_decode($giveawayFreeData, true); foreach ($giveawayFreeData as $data) { $obj = (object) array("id" => $data["id"], "giveawayid" => $data["giveawayid"], "price" => $data["price"]); array_push($giveawayFreeDatas, $obj); } } else { $giveawayFrees = CarPreemptionGiveaway::where('free', true)->where('carpreemptionid', $id)->get(['id', 'giveawayid', 'price']); foreach ($giveawayFrees as $data) { $obj = (object) array("id" => $data->id, "giveawayid" => $data->giveawayid, "price" => $data->price); array_push($giveawayFreeDatas, $obj); } } if ($giveawayBuyData != null && $giveawayBuyData != '') { $giveawayBuyData = json_decode($giveawayBuyData, true); foreach ($giveawayBuyData as $data) { $obj = (object) array("id" => $data["id"], "giveawayid" => $data["giveawayid"]); array_push($giveawayBuyDatas, $obj); } } else { $giveawayBuys = CarPreemptionGiveaway::where('free', false)->where('carpreemptionid', $id)->get(['id', 'giveawayid']); foreach ($giveawayBuys as $data) { $obj = (object) array("id" => $data->id, "giveawayid" => $data->giveawayid); array_push($giveawayBuyDatas, $obj); } } $finacecompanies = FinaceCompany::orderBy('name', 'asc')->get(['id', 'name']); $finacecompanyselectlist = array(); $finacecompanyselectlist[null] = 'เลือกบริษัท'; foreach ($finacecompanies as $item) { $finacecompanyselectlist[$item->id] = $item->name; } $interestratetypes = InterestRateType::where('finacecompanyid', $model->finacecompanyid)->orderBy('name', 'asc')->get(['id', 'name']); $interestratetypeselectlist = array(); $interestratetypeselectlist[null] = 'เลือกประเภทอัตราดอกเบี้ย'; foreach ($interestratetypes as $item) { $interestratetypeselectlist[$item->id] = $item->name; } $carprices = array(); $priceselectlist = array(); $pricelists = Pricelist::where('carsubmodelid', $model->carsubmodelid)->where('effectivefrom', '<=', $model->date)->where('effectiveTo', '>=', $model->date)->orderBy('sellingpricewithaccessories', 'asc')->get(['id', 'sellingpricewithaccessories', 'promotion']); foreach ($pricelists as $item) { if ($item->promotion != null && $item->promotion != '') { $priceselectlist[$item->id] = $item->sellingpricewithaccessories . ' (' . $item->promotion . ')'; } else { $priceselectlist[$item->id] = $item->sellingpricewithaccessories; } $obj = (object) array("pricelistid" => $item->id, "price" => $item->sellingpricewithaccessories); array_push($carprices, $obj); } $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' => 'edit', 'pathPrefix' => '../../', 'carpreemption' => $model, 'carprices' => $carprices, 'colorprices' => $colorprices, 'provinceregistrationfee' => $provinceregistrationfee, '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 run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/seed_files/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); DB::table('invalid_mappings')->truncate(); DB::table('store_items')->truncate(); DB::table('channel_items')->truncate(); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'MKL Mapping') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($row[0] != '') { if ($cnt > 0) { // dd($row); if (!ctype_digit(trim($row[4])) || !ctype_digit(trim($row[5])) || !ctype_digit(trim($row[6]))) { InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'MKL Mapping', 'remarks' => 'Invalid mapping']); } else { $channel = ''; $customer = ''; $store = ''; if (trim($row[0]) != '') { $channel = Channel::where('channel_code', trim($row[0]))->get(); } if (trim($row[1]) != '') { $customer = Customer::where('customer_code', trim($row[1]))->get(); } if (trim($row[2]) != '') { $store = Store::where('store_code', trim($row[2]))->first(); } // dd($customer); $stores = Store::where(function ($query) use($channel) { if (!empty($channel)) { $channel_id = []; foreach ($channel as $value) { $channel_id[] = $value->id; } $query->whereIn('channel_id', $channel_id); } })->where(function ($query) use($customer) { if (!empty($customer)) { $customer_id = []; foreach ($customer as $value) { $customer_id[] = $value->id; } $query->whereIn('customer_id', $customer_id); } })->where(function ($query) use($store) { if (!empty($store)) { $query->where('store', $store->id); } })->get(); // dd($stores); $item = Item::where('sku_code', trim($row[3]))->first(); if (!empty($item)) { $item_type = ItemType::where('type', "MKL")->first(); foreach ($stores as $store) { $osa_tagging = 0; if (isset($row[7])) { $osa_tagging = trim($row[7]); } $npi_tagging = 0; if (isset($row[8])) { $npi_tagging = trim($row[8]); } StoreItem::firstOrCreate(['store_id' => $store->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]); ChannelItem::firstOrCreate(['channel_id' => $store->channel_id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]); } } } } $cnt++; } } } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function edit($id) { $defect = Defect::where('id', '=', $id)->with('defectItems.product')->first(); // dd($defect); if ($defect->customer_type == 1) { $customers = Employee::where('status', 1)->lists('name', 'id'); } elseif ($defect->customer_type == 2) { $customers = Supplier::where('status', 1)->lists('company_name', 'id'); } else { $customers = Customer::where('status', 1)->lists('name', 'id'); } $salesOrder = new SalesOrder(); if ($defect->is_replacement) { $salesOrder = SalesOrder::where('defect_id', '=', $defect->id)->with(['salesOrderItems', 'salesOrderItems.product', 'salesOrderItems.salesDelivery'])->first(); } $personalAccount = PersonalAccount::where('person_type', '=', $defect->customer_type)->where('person_id', '=', $defect->customer_id)->first(); return view('sales.receiveDefect.edit')->with(compact('defect', 'customers', 'personalAccount', 'salesOrder')); }