public function actionCreateMultipleModels() { $models = []; if (isset($_POST['Customer'])) { $validateOK = true; foreach ($_POST['Customer'] as $postObj) { $model = new Customer(); $model->attributes = $postObj; $models[] = $model; $validateOK = $validateOK && $model->validate(); } // All models are validated and will be saved if ($validateOK) { foreach ($models as $model) { $model->save(); } // Redirect to grid after save return $this->redirect(['grid']); } } else { for ($k = 0; $k < 3; $k++) { $models[] = new Customer(); } } return $this->render('createMultipleModels', ['models' => $models]); }
function save(array $params) { $response = new ResponseEntity(); DB::transaction(function () use(&$response, $params) { $user = User::find(Auth::user()->id); $product = Product::find($params['product_id']); $cust = new Customer(); $cust->first_name = $params['customer']['first_name']; $cust->last_name = $params['customer']['last_name']; $cust->phone_number = $params['customer']['phone_number']; $custCreated = $cust->save(); if ($custCreated && $product && $user) { $sale = new Sale(); $sale->user_id = $user->id; $sale->sale_status_id = Config::get('constants.sale_status.sale'); $sale->product_id = $product->id; $sale->customer_id = $cust->id; $sale->date_sold = Carbon::createFromFormat('m/d/Y', $params['date_sold'])->toDateString(); $sale->remarks = isset($params['remarks']) ? $params['remarks'] : ''; $sale->order_number = $params['order_number']; $sale->ninety_days = isset($params['ninety_days']) ?: 0; $ok = $sale->save(); if ($ok) { $ok = $this->setIncentive($sale->user_id, $sale->date_sold); $response->setMessages($ok ? ['Sale successfully created!'] : ['Failed to create sale!']); $response->setSuccess($ok); } else { $response->setMessages(['Failed to create sale!']); } } else { $response->setMessages(['Entities not found']); } }); return $response; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { try { $admin = \Auth::User(); if (!$admin) { return $this->failResponse('admin not logged in'); } $customerObj = new Customer(); $data = $this->getRequestBody(); $customerObj->first_name = $data['first_name']; $customerObj->last_name = $data['last_name']; $customerObj->business_name = $data['business_name']; $customerObj->mobile = $data['mobile']; $customerObj->email = $data['email']; $customerObj->address = $data['address']; $customerObj->save(); if (!$customerObj->save()) { Log::error("error in saving"); $errors = $customerObj->getErrors(); return $this->failResponse('Validation failed. Cannot save data.' . $errors); } else { return $this->successResponse('updated sucessfully'); } } catch (\Exception $e) { Log::error($customerObj->getErrors()); return $this->failResponse($e->getMessage()); } }
/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Customer(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function postEdit($id) { $this->validateForm(); $customer = new Customer($id); $customer->first_name = Request::get('first_name'); $customer->last_name = Request::get('last_name'); $customer->email = Request::get('email'); $customer->phone = Request::get('phone'); $customer->gender = Request::get('gender'); $customer->save(); return redirect('customer/' . $id); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $validator = Validator::make($request->all(), ['name' => 'required|max:255']); if ($validator->fails()) { return redirect('/')->withInput()->withErrors($validator); } $customer = new Customer(); $customer->name = $request->name; $customer->eng_name = $request->eng_name; $customer->save(); Activity::log(Auth::user()->name . ' Add customer:' . $request->name); return redirect('admin/customers'); }
/** * @param \App\Models\Customer $customer * @param string $action * @param int $beans_changed */ protected function update(Customer $customer, $action, $beans_changed) { if ($action == AppConstant::BEAN_ACTION_CONSUME or $action == AppConstant::BEAN_ACTION_TRANSFER_CASH) { if ($beans_changed >= $customer->beans_total) { \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, -$customer->beans_total); $customer->beans_total = 0; } else { \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, -$beans_changed); $customer->beans_total -= $beans_changed; } } else { \EnterpriseAnalyzer::updateBasic(AnalyzerConstant::ENTERPRISE_BEAN, $beans_changed); $customer->beans_total += $beans_changed; } $customer->save(); }
public function register(Request $request) { $c = new Customer(); $c->id = $request->input('id'); $c->code = $request->input('code'); $c->openbalance = $request->input('openbalance'); $c->creditlimit = $request->input('creditlimit'); $c->name = $request->input('name'); $c->preaddress = $request->input('preaddress'); $c->peraddress = $request->input('peraddress'); $c->phone = $request->input('phone'); $c->email = $request->input('email'); $c->fax = $request->input('fax'); $c->url = $request->input('url'); $c->userid = $request->input('userid'); $c->save(); return redirect('customers'); }
/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Customer(); if ($model->load(Yii::$app->request->post())) { $tax_number = $model->tax_number; $check = $model->find()->where(['tax_number' => $tax_number])->one(); if ($check['tax_number'] != '') { $config = new \app\models\Config_system(); $cusId = $config->autoId("customer", "cus_id", 7); return $this->render('create', ['error' => "ลูกค้าบริษัทนี้นี้มีอยู่ในระบบแล้ว ...!", 'model' => $model, 'cus_id' => $cusId]); } else { $model->create_date = date("Y-m-d H:i:s"); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } } else { $config = new \app\models\Config_system(); $cusId = $config->autoId("customer", "cus_id", 7); return $this->render('create', ['error' => '', 'model' => $model, 'cus_id' => $cusId]); } }
public function actionSignup() { $model = new Customer(); if ($model->load(Yii::$app->request->post())) { $request = Yii::$app->request->post('Customer'); $username = $request['username']; $password = $request['password']; $verify = $request['verify']; if ($password != $verify) { return $this->redirect(['signup', 'error' => 'Mật khẩu không trùng khớp']); } else { if ($model->checkUserName($username) == FALSE) { return $this->redirect(['signup', 'error' => 'Tên đăng nhập đã tồn tại']); } else { $model->password = md5($password); $model->save(); return $this->redirect(['signup', 'success' => 'OK']); } } } return $this->render('signup', ['model' => $model]); }
public function actionCreateCustomerAndReservation() { $customer = new \app\models\Customer(); $reservation = new \app\models\Reservation(); // It is useful to set fake customer_id to reservation model to avoid validationerror (because customer_id is mandatory) $reservation->customer_id = 0; if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) { $dbTrans = Yii::$app->db->beginTransaction(); $customerSaved = $customer->save(); if ($customerSaved) { $reservation->customer_id = $customer->id; $reservationSaved = $reservation->save(); if ($reservationSaved) { $dbTrans->commit(); } else { $dbTrans->rollback(); } } else { $dbTrans->rollback(); } } return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]); }
public function actionCreateCustomerAndReservation() { $customer = new Customer(); $reservation = new Reservation(); $reservation->customer_id = 1; if ($customer->load(Yii::$app->request->post()) && $customer->validate() && $reservation->load(Yii::$app->request->post()) && $reservation->validate()) { $dbTrans = Yii::$app->db->beginTransaction(); $customerSaved = $customer->save(); if ($customerSaved) { $reservation->customer_id = $customer->id; $reservationSaved = $reservation->save(); if ($reservationSaved) { $dbTrans->commit(); $this->redirect(['grid']); } else { $dbTrans->rollBack(); } } else { $dbTrans->rollBack(); } } return $this->render('createCustomerAndReservation', compact('customer', 'reservation')); }
function save(array $params) { $response = new ResponseEntity(); try { DB::transaction(function () use(&$response, $params) { $user = User::find(1); $product = Product::find($params['product_id']); $cust = new Customer(); $cust->first_name = $params['customer']['first_name']; $cust->last_name = $params['customer']['last_name']; $cust->phone_number = $params['customer']['phone_number']; $custCreated = $cust->save(); if ($custCreated && $product && $user) { $sale = new Sale(); $sale->user_id = $user->id; $sale->product_id = $product->id; $sale->customer_id = $cust->id; $sale->date_sold = Carbon::createFromFormat('m/d/Y', $params['date_sold']); $sale->remarks = isset($params['remarks']) ? $params['remarks'] : ''; $sale->order_number = $params['order_number']; $sale->ninety_days = isset($params['ninety_days']) ?: 0; $ok = $sale->save(); if ($ok) { $response->setSuccess(true); $response->setMessages(['Sale successfully created!']); } else { $response->setMessages(['Failed to create sale!']); } } else { $response->setMessages(['Entities not found']); } }); } catch (\Exception $ex) { $response->setMessages(['Exception: ' . $ex->getMessage()]); } return $response; }
public function customer_register(Request $request) { if ($request->ajax() && $request->method() == 'POST') { $customer_code = $request->input('customer_code'); $customer_name = $request->input('customer_name'); $opening_balance = $request->input('opening_balance'); $preaddress = $request->input('preaddress'); $customer = new Customer(); $customer->code = $customer_code; $customer->name = $customer_name; $customer->openbalance = $opening_balance; $customer->preaddress = $preaddress; $customer->save(); Session::flash('new_customer_id', $customer->id); return response()->json(1); } }
protected function sync_ekp_customer_init() { //更新没有code客户 //update customers a inner join customer b on a.`name` = b.`name` set a.ekp_code = b.`code` where a.ekp_code is null //北京区域过滤规则 $csts = DB::select('select * from customer where area_id = \'6b676aeb-a0ab-4e4e-b301-7a614cdff49d\' and LEFT(name,2) = \'北京\' and `name` not in (\'北京一组_费用权责发生制\',\'北京二组erp303sp4专属\',\'北京307sp4\')and LEFT(`name`,4) not in (select LEFT(`name`,4) from customers )'); foreach ($csts as $cst) { if (!empty($cst)) { $customer = new Customer(); $customer->name = $cst->name; $customer->uuid = Uuid::generate(); $customer->ekp_code = $cst->code; $customer->area = '北京'; $customer->source = 1; $customer->save(); echo $this->print_log("客户 {$customer->name} 同步成功,客户code: {$cst->code} "); } } //成渝区域 $csts = DB::select('select * from customer where area_id = \'d157cafa-85b5-4353-b583-4c584b424180\' and `name` not in (\'TEST\') and LEFT(`name`,4) not in (select LEFT(`name`,4) from customers )'); foreach ($csts as $cst) { if (!empty($cst)) { $customer = new Customer(); $customer->name = $cst->name; $customer->uuid = Uuid::generate(); $customer->ekp_code = $cst->code; $customer->area = '成渝'; $customer->source = 1; $customer->save(); echo $this->print_log("客户 {$customer->name} 同步成功,客户code: {$cst->code} "); } } //广州福建长沙中山区域 $csts = DB::select('select * from customer where area_id = \'570680b7-d751-4986-a83a-8aa4c6f01aec\' and `name` not in (\'TEST\') and LEFT(`name`,4) not in (select LEFT(`name`,4) from customers )'); foreach ($csts as $cst) { if (!empty($cst)) { $customer = new Customer(); $customer->name = $cst->name; $customer->uuid = Uuid::generate(); $customer->ekp_code = $cst->code; // $customer->area = '成渝'; $customer->source = 1; $customer->save(); echo $this->print_log("客户 {$customer->name} 同步成功,客户code: {$cst->code} "); } } //联营区域 $csts = DB::select('select * from customer where area_id = \'ee0a764b-27d2-4bf5-af7b-6d196aa31c77\' and `name` not in (\'TEST\') and LEFT(`name`,4) not in (select LEFT(`name`,4) from customers ) and LEFT(`name`,4) not in (\'标准产品\',\'产品验证\')'); foreach ($csts as $cst) { if (!empty($cst)) { $customer = new Customer(); $customer->name = $cst->name; $customer->uuid = Uuid::generate(); $customer->ekp_code = $cst->code; $customer->area = '联营'; $customer->source = 1; $customer->save(); echo $this->print_log("客户 {$customer->name} 同步成功,客户code: {$cst->code} "); } } //上海区域 $csts = DB::select('select * from customer where area_id = \'54fa8f61-55ff-4169-9fc2-8f63fdeb8ceb\' and `name` not in (\'TEST\') and LEFT(`name`,4) not in (select LEFT(`name`,4) from customers ) and LEFT(`name`,4) not in (\'商城项目\')'); foreach ($csts as $cst) { if (!empty($cst)) { $customer = new Customer(); $customer->name = $cst->name; $customer->uuid = Uuid::generate(); $customer->ekp_code = $cst->code; $customer->area = '上海'; $customer->source = 1; $customer->save(); echo $this->print_log("客户 {$customer->name} 同步成功,客户code: {$cst->code} "); } } //总部区域 $csts = DB::select('select * from customer where area_id = \'b303ed9d-64ef-4f90-b6c6-c62819fbf387\' and `name` not in (\'TEST\') and LEFT(`name`,4) not in (select LEFT(`name`,4) from customers ) and LEFT(`name`,4) not in (\'金威啤酒-粤海置地\',\'源动力\',\'星河\',\'万科\',\'招商\',\'明源公司\')'); foreach ($csts as $cst) { if (!empty($cst)) { $customer = new Customer(); $customer->name = $cst->name; $customer->uuid = Uuid::generate(); $customer->ekp_code = $cst->code; $customer->area = '总部深圳'; $customer->source = 1; $customer->save(); echo $this->print_log("客户 {$customer->name} 同步成功,客户code: {$cst->code} "); } } }
/** * Creates a new Bill model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Bill(); if (Yii::$app->session['carPartTotal'] <= 0.0) { return; } if (isset($_POST['mode'], $_POST['discount'])) { $result = []; if ($_POST['mode'] == 0 || $_POST['mode'] == 1) { $transaction = $model->getDb()->beginTransaction(); try { $discount = (double) $_POST['discount']; if ($discount > Yii::$app->session['carPartTotal']) { $discount = 0.0; } $modelPrice = new Price(); $modelPrice->price = (double) Yii::$app->session['carPartTotal'] - (double) $discount; $modelPrice->calculate(); if (!$modelPrice->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelPrice->tableName())), 'msj' => print_r($modelPrice->getErrors(), true)]), 500); } $model->price_id = $modelPrice->id; $model->discount = $discount; if (isset($_POST['draft']) && !empty($_POST['draft'])) { $model->draft = 1; } if (isset($_POST['Vehicle'])) { $vehicle = new Vehicle(); $vehicle->attributes = $_POST['Vehicle']; if (!empty($vehicle->brand) || !empty($vehicle->model) || !empty($vehicle->color) || !empty($vehicle->plaque)) { if (!$vehicle->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($vehicle->tableName())), 'msj' => print_r($vehicle->getErrors(), true)]), 500); } $model->vehicle_id = $vehicle->id; } } if (isset($_POST['Customer'])) { $customer = new Customer(); $customer->attributes = $_POST['Customer']; if (!empty($customer->name) || !empty($customer->serial)) { if (!$customer->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($customer->tableName())), 'msj' => print_r($customer->getErrors(), true)]), 500); } $model->customer_id = $customer->id; } } if ($model->save()) { $result['message'] = Yii::t('app', '{modelClass} saved', ['modelClass' => Yii::t('app', ucfirst($model->tableName()))]); } else { $result['message'] = Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->errors, true)]); } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $result['message'] = Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => $e]); } } echo json_encode($result); } else { if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } }
/** * POST接收一个JSON数组 * 保存单据数据 */ public function actionSave() { if (isset($_POST['jsonData'])) { $jsonData = $_POST['jsonData']; } if ($jsonData != null) { $json = array(); $idArray = array(); $dataArray = json_decode($jsonData); //解析JSON数据 $sellnum = $dataArray[0]->sellnum; //第一个数组0 代表销售单据 //查询单据号的所有的单据,用来比较是否更改数据 $sell = Sell::find()->where(['uid' => Yii::$app->user->id, 'sellnum' => $sellnum])->all(); $jsonCount = count($dataArray); //获取JSON数组总和 $json['return_code'] = 1; for ($i = 1; $i < $jsonCount; $i++) { //数组0是单据号,所以 i 从1 开始循环 $id = $dataArray[$i]->id; if ($id == 0) { //表单JSON数据会提交一个 id,代表单据在数据的id,如果为0,是新数据 $model = new Sell(); //直接把数据保存在Model 在 model->save(); $model->sellnum = $sellnum; $model->addnum = $dataArray[$i]->addnum; $product = $dataArray[$i]->product; $brand = explode('-', $product); if (count($brand) == 1) { $model->brand = $product; } else { $model->brand = $brand[0]; $model->model = $brand[1]; } $model->count = $dataArray[$i]->count; $model->price = $dataArray[$i]->price; $model->addprice = $dataArray[$i]->addprice; $model->oldprice = $dataArray[$i]->oldprice; $model->color = $dataArray[$i]->color; $model->barcode = $dataArray[$i]->barcode; $model->supplier = $dataArray[$i]->supplier; $model->warehouse = $dataArray[$i]->warehouse; $model->remark = $dataArray[$i]->remark; $model->employee = Yii::$app->user->identity->username; $model->status = 0; $model->pid = $dataArray[$i]->pid; $model->uid = Yii::$app->user->id; //检测是否填写客户信息,有的话保存在客户表tbl_customer,在把返回的客户ID 保存在出库单据cid上 if ($dataArray[$i]->custom != "" || $dataArray[$i]->tell != "") { $customModel = new Customer(); if ($dataArray[$i]->custom == "") { $customModel->name = "无"; } else { $customModel->name = $dataArray[$i]->custom; } if ($dataArray[$i]->tell == "") { $customModel->tell = "无"; } else { $customModel->tell = $dataArray[$i]->tell; } $customModel->uid = Yii::$app->user->id; $customModel->save(); //保存客户数据 $cid = $customModel->getAttribute('id'); //获取客户数据的ID $model->cid = $cid; } $model->save(); $idArray[] = $model->getAttribute('id'); //更新条码为 出库状态 status=1 if ($dataArray[$i]->barcode != "") { //如果产品有条码,更新条码数据库tab_barcode的状态为1,代表出库了 Barcode::updateAll(['status' => 1], 'barcode=:barcode', [':barcode' => $dataArray[$i]->barcode]); } } else { if ($id > 0) { //大于0 代表数据已经在库,直接更新数据库 //先查询这个单据号的所以数据,用来循环比较表格数据 $timeNow = date('Y-m-d H:i:s', time()); //表格JSON数据 与 数据库查询数据循环比较,查找对应ID的数据 foreach ($sell as $item) { //ID一样说明数据找到 if ($item->getAttribute('id') == $id) { //获取客户ID $cid = $item->getAttribute('cid'); //查询客户信息,对比表格输入数据是否有更改,然后update tbl_customer if ($cid != null && $cid > 0) { $customModel = Customer::find()->where(['uid' => Yii::$app->user->id, 'id' => $cid])->one(); if ($customModel->getAttribute('name') != $dataArray[$i]->custom) { Customer::updateAll(['name' => $dataArray[$i]->custom], 'id=:id', [':id' => $cid]); } if ($customModel->getAttribute('tell') != $dataArray[$i]->tell) { Customer::updateAll(['tell' => $dataArray[$i]->tell], 'id=:id', [':id' => $cid]); } } //数据库对比表格输入信息是否有更改,然后update tbl_sell if ($item->getAttribute('count') != $dataArray[$i]->count || $item->getAttribute('price') != $dataArray[$i]->price || $item->getAttribute('remark') != $dataArray[$i]->remark) { Sell::updateAll(['count' => $dataArray[$i]->count, 'price' => $dataArray[$i]->price, 'remark' => $dataArray[$i]->remark], 'id=:id', [':id' => $id]); } } } } } } $json['idArray'] = $idArray; echo json_encode($json); } }
public function save(Request $request) { if (!$this->hasPermission($this->menuPermissionName)) { return view($this->viewPermissiondeniedName); } $this->validate($request, ['bookno' => 'required', 'no' => 'required', 'date' => 'required', 'bookingcustomerid' => 'required_if:customer-type,0', 'bookingcustomerfirstname' => 'required_if:customer-type,1', 'bookingcustomerphone1' => 'required', 'carobjectivetype' => 'required', 'carmodelid' => 'required', 'carsubmodelid' => 'required', 'colorid' => 'required', 'pricelistid' => 'required', 'discount' => 'required', 'subdown' => 'required', 'accessories' => 'required', 'cashpledge' => 'required', 'cashpledgepaymenttype' => 'required', 'cashpledgechargepercent' => 'required_if:cashpledgepaymenttype,1', 'purchasetype' => 'required', 'finacecompanyid' => 'required_if:purchasetype,1', 'interestratetypeid' => 'required_if:purchasetype,1', 'interestratemode' => 'required_if:purchasetype,1', 'interest' => 'required_if:purchasetype,1', 'down' => 'required_if:purchasetype,1', 'subsidise' => 'required_if:purchasetype,1', 'installments' => 'required_if:purchasetype,1', 'cashpledgeredlabel' => 'required_if:carobjectivetype,0', 'registrationtype' => 'required_if:carobjectivetype,0', 'registrationfee' => 'required_if:carobjectivetype,0', 'insurancefee' => 'required', 'compulsorymotorinsurancefee' => 'required', 'accessoriesfee' => 'required', 'giveawaywithholdingtax' => 'required', 'otherfee' => 'required', 'otherfee2' => 'required', 'otherfee3' => 'required', 'implementfee' => 'required', 'datewantgetcar' => 'required', 'giveawayadditionalcharges' => 'required', 'buyercustomerid' => 'required_if:buyertype,1', 'buyercustomerfirstname' => 'required_if:buyertype,2', 'buyercustomerphone1' => 'required_if:buyertype,1,2', 'salesmanemployeeid' => 'required', 'salesmanageremployeeid' => 'required', 'approversemployeeid' => 'required', 'approvaldate' => 'required', 'customertype' => 'required'], ['bookno.required' => 'ข้อมูล เล่มที่ จำเป็นต้องกรอก', 'no.required' => 'ข้อมูล เลขที่ จำเป็นต้องกรอก', 'date.required' => 'ข้อมูล วันที่ จำเป็นต้องกรอก', 'bookingcustomerid.required_if' => 'ผู้สั่งจอง กรุณาเลือกชื่อลูกค้า', 'bookingcustomerfirstname.required_if' => 'ผู้สั่งจอง ชื่อ จำเป็นต้องกรอก', 'bookingcustomerphone1.required' => 'ผู้สั่งจอง เบอร์โทร 1 จำเป็นต้องกรอก', 'carobjectivetype.required' => 'รายละเอียดรถยนตร์ใหม่ รถใหม่/รถบริษัท จำเป็นต้องเลือก', 'carmodelid.required' => 'รายละเอียดรถยนตร์ใหม่ กรุณาเลือกแบบ', 'carsubmodelid.required' => 'รายละเอียดรถยนตร์ใหม่ กรุณาเลือกรุ่น', 'colorid.required' => 'รายละเอียดรถยนตร์ใหม่ กรุณาเลือกสี', 'pricelistid.required' => 'รายละเอียดรถยนตร์ใหม่ กรุณาเลือกราคา', 'discount.required' => 'รายละเอียดรถยนตร์ใหม่ ส่วนลด จำเป็นต้องกรอก', 'subdown.required' => 'รายละเอียดรถยนตร์ใหม่ Sub Down จำเป็นต้องกรอก', 'accessories.required' => 'รายละเอียดรถยนตร์ใหม่ บวกอุปกรณ์ จำเป็นต้องกรอก', 'cashpledge.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน เงินมัดจำ จำเป็นต้องกรอก', 'cashpledgepaymenttype.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ประเภทการจ่ายเงินมัดจำ จำเป็นต้องเลือก', 'cashpledgechargepercent.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน % ค่าธรรมเนียม จำเป็นต้องเลือก', 'purchasetype.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ประเภทซื้อรถยนต์ จำเป็นต้องเลือก', 'finacecompanyid.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ชื่อบริษัทเช่าซื้อ จำเป็นต้องเลือก', 'interestratetypeid.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ประเภทอัตราดอกเบี้ย จำเป็นต้องเลือก', 'interestratemode.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน Mode อัตราดอกเบี้ย จำเป็นต้องเลือก', 'interest.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ดอกเบี้ย จำเป็นต้องกรอก', 'down.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ดาวน์ จำเป็นต้องกรอก', 'installments.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน จำนวนงวด จำเป็นต้องกรอก', 'cashpledgeredlabel.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่ามัดจำป้ายแดง จำเป็นต้องกรอก', 'registrationtype.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ประเภทจดทะเบียน จำเป็นต้องเลือก', 'registrationfee.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าจดทะเบียน จำเป็นต้องกรอก', 'insurancefee.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าประกันภัย จำเป็นต้องกรอก', 'compulsorymotorinsurancefee.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่า พ.ร.บ. จำเป็นต้องกรอก', 'accessoriesfee.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าอุปกรณ์ จำเป็นต้องกรอก', 'giveawaywithholdingtax.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ภาษีหัก ณ ที่จ่าย (กรณีลูกค้าได้รับของแถม เช่น ทอง) จำเป็นต้องกรอก', 'otherfee.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าอื่นๆ (1) จำเป็นต้องกรอก', 'otherfee2.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าอื่นๆ (2) จำเป็นต้องกรอก', 'otherfee3.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าอื่นๆ (3) จำเป็นต้องกรอก', 'subsidise.required_if' => 'รายละเอียด/เงื่อนไขการชำระเงิน SUBSIDISE จำเป็นต้องกรอก', 'implementfee.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน ค่าดำเนินการ จำเป็นต้องกรอก', 'datewantgetcar.required' => 'รายละเอียด/เงื่อนไขการชำระเงิน วันที่ต้องการรับรถ จำเป็นต้องกรอก', 'giveawayadditionalcharges.required' => 'รายละเอียดอื่นๆ ลูกค้าจ่ายเพิ่มเติ่มค่าของแถม จำเป็นต้องกรอก', 'buyercustomerid.required_if' => 'ผู้ซื้อ กรุณาเลือกชื่อลูกค้า', 'buyercustomerfirstname.required_if' => 'ผู้ซื้อ ชื่อ จำเป็นต้องกรอก', 'buyercustomerphone1.required_if' => 'ผู้ซื้อ เบอร์โทร 1 จำเป็นต้องกรอก', 'salesmanemployeeid.required' => 'พนักงานขาย กรุณาเลือกชื่อพนักงาน', 'salesmanageremployeeid.required' => 'ผู้จัดการฝ่ายขาย กรุณาเลือกชื่อพนักงาน', 'approversemployeeid.required' => 'ผู้อนุมัติ กรุณาเลือกชื่อพนักงาน', 'approvaldate.required' => 'วันที่อนุมัติ จำเป็นต้องกรอก', 'customertype.required' => 'ประเภทลูกค้า จำเป็นต้องเลือก']); $input = $request->all(); if ($request->has('id')) { $model = CarPreemption::find($input['id']); if ($model == null) { return "ขออภัย!! ไม่พบข้อมูลที่จะทำการแก้ไขในระบบ เนื่องจากอาจถูกลบไปแล้ว"; } } else { $model = new CarPreemption(); } $model->bookno = $input['bookno']; $model->no = $input['no']; $model->date = date('Y-m-d', strtotime($input['date'])); if ($input['customer-type'] == 0) { $customer = Customer::find($input['bookingcustomerid']); } else { $customer = new Customer(); if (Auth::user()->isadmin) { $customer->provinceid = $input['provincebranchid']; } else { $customer->provinceid = Auth::user()->provinceid; } $customer->title = $input['bookingcustomertitle']; $customer->firstname = $input['bookingcustomerfirstname']; $customer->lastname = $input['bookingcustomerlastname']; } $customer->address = $input['bookingcustomeraddress']; $customer->addprovinceid = $input['bookingcustomerprovinceid']; $customer->amphurid = $input['bookingcustomeramphurid']; $customer->districtid = $input['bookingcustomerdistrictid']; $customer->zipcode = $input['bookingcustomerzipcode']; $customer->phone1 = $input['bookingcustomerphone1']; $customer->phone2 = $input['bookingcustomerphone2']; $customer->occupationid = $input['bookingcustomeroccupationid']; if ($input['bookingcustomerbirthdate'] != null && $input['bookingcustomerbirthdate'] != '') { $customer->birthdate = date('Y-m-d', strtotime($input['bookingcustomerbirthdate'])); } if ($customer->save()) { $model->bookingcustomerid = $customer->id; } else { //hack returning error $this->validate($request, ['bookno' => 'alpha'], ['bookno.alpha' => 'ไม่สามารถทำการบันทึกข้อมูลผู้จองได้ กรุณาติดต่อผู้ดูแลระบบ!!']); } $model->carobjectivetype = $input['carobjectivetype']; $model->carmodelid = $input['carmodelid']; $model->carsubmodelid = $input['carsubmodelid']; $model->colorid = $input['colorid']; $model->pricelistid = $input['pricelistid']; $model->colorprice = $input['colorprice']; $model->totalcarprice = $input['totalcarprice']; $model->discount = $input['discount']; $model->subdown = $input['subdown']; $model->accessories = $input['accessories']; $model->oldcarbrandid = $input['oldcarbrandid']; $model->oldcarmodelid = $input['oldcarmodelid']; $model->oldcargear = $input['oldcargear']; $model->oldcarcolor = $input['oldcarcolor']; $model->oldcarenginesize = $input['oldcarenginesize']; $model->oldcarlicenseplate = $input['oldcarlicenseplate']; $model->oldcaryear = $input['oldcaryear']; $model->oldcarprice = $input['oldcarprice']; $model->oldcarbuyername = $input['oldcarbuyername']; $model->oldcarother = $input['oldcarother']; $model->cashpledge = $input['cashpledge']; $model->cashpledgepaymenttype = $input['cashpledgepaymenttype']; $model->cashpledgechargepercent = $input['cashpledgechargepercent']; $model->cashpledgechargeamount = $input['cashpledgechargeamount']; if ($request->has('cashpledgechargefree')) { $model->cashpledgechargefree = $input['cashpledgechargefree']; } else { $model->cashpledgechargefree = 0; } $model->purchasetype = $input['purchasetype']; $model->finacecompanyid = $input['finacecompanyid']; $model->interestratetypeid = $input['interestratetypeid']; $model->interestratemode = $input['interestratemode']; $model->interest = $input['interest']; $model->down = $input['down']; $model->installments = $input['installments']; $model->financingfee = $input['financingfee']; $model->transferfee = $input['transferfee']; $model->transferoperationfee = $input['transferoperationfee']; $model->cashpledgeredlabel = $input['cashpledgeredlabel']; $model->registerprovinceid = $input['registerprovinceid']; $model->registrationtype = $input['registrationtype']; $model->registrationfee = $input['registrationfee']; if ($request->has('registrationfeefree')) { $model->registrationfeefree = $input['registrationfeefree']; } else { $model->registrationfeefree = 0; } $model->insurancefee = $input['insurancefee']; if ($request->has('insurancefeefree')) { $model->insurancefeefree = $input['insurancefeefree']; } else { $model->insurancefeefree = 0; } $model->compulsorymotorinsurancefee = $input['compulsorymotorinsurancefee']; if ($request->has('compulsorymotorinsurancefeefree')) { $model->compulsorymotorinsurancefeefree = $input['compulsorymotorinsurancefeefree']; } else { $model->compulsorymotorinsurancefeefree = 0; } $model->accessoriesfee = $input['accessoriesfee']; $model->giveawaywithholdingtax = $input['giveawaywithholdingtax']; $model->otherfee = $input['otherfee']; $model->otherfeedetail = $input['otherfeedetail']; $model->otherfee2 = $input['otherfee2']; $model->otherfeedetail2 = $input['otherfeedetail2']; $model->otherfee3 = $input['otherfee3']; $model->otherfeedetail3 = $input['otherfeedetail3']; $model->subsidise = $input['subsidise']; if ($request->has('subsidisefree')) { $model->subsidisefree = $input['subsidisefree']; } else { $model->subsidisefree = 0; } $model->implementfee = $input['implementfee']; if ($request->has('implementfeefree')) { $model->implementfeefree = $input['implementfeefree']; } else { $model->implementfeefree = 0; } $model->datewantgetcar = date('Y-m-d', strtotime($input['datewantgetcar'])); $model->giveawayadditionalcharges = $input['giveawayadditionalcharges']; $model->totalfree = $input['totalfree']; if ($input['buyertype'] == 0) { $model->buyercustomerid = $model->bookingcustomerid; } else { if ($input['buyertype'] == 1) { $customer = Customer::find($input['buyercustomerid']); } else { $customer = new Customer(); if (Auth::user()->isadmin) { $customer->provinceid = $input['provincebranchid']; } else { $customer->provinceid = Auth::user()->provinceid; } $customer->title = $input['buyercustomertitle']; $customer->firstname = $input['buyercustomerfirstname']; $customer->lastname = $input['buyercustomerlastname']; } $customer->address = $input['buyercustomeraddress']; $customer->addprovinceid = $input['buyercustomerprovinceid']; $customer->amphurid = $input['buyercustomeramphurid']; $customer->districtid = $input['buyercustomerdistrictid']; $customer->zipcode = $input['buyercustomerzipcode']; $customer->phone1 = $input['buyercustomerphone1']; $customer->phone2 = $input['buyercustomerphone2']; $customer->occupationid = $input['buyercustomeroccupationid']; if ($input['buyercustomerbirthdate'] != null && $input['buyercustomerbirthdate'] != '') { $customer->birthdate = date('Y-m-d', strtotime($input['buyercustomerbirthdate'])); } if ($customer->save()) { $model->buyercustomerid = $customer->id; } else { //hack returning error $this->validate($request, ['bookno' => 'alpha'], ['bookno.alpha' => 'ไม่สามารถทำการบันทึกข้อมูลผู้ซื้อได้ กรุณาติดต่อผู้ดูแลระบบ!!']); } } $model->salesmanemployeeid = $input['salesmanemployeeid']; $model->salesmanageremployeeid = $input['salesmanageremployeeid']; $model->approversemployeeid = $input['approversemployeeid']; $model->approvaldate = date('Y-m-d', strtotime($input['approvaldate'])); if ($request->has('place')) { $model->place = $input['place']; } else { $model->place = 0; } if ($request->has('showroom')) { $model->showroom = $input['showroom']; } else { $model->showroom = 0; } if ($request->has('booth')) { $model->booth = $input['booth']; } else { $model->booth = 0; } if ($request->has('leaflet')) { $model->leaflet = $input['leaflet']; } else { $model->leaflet = 0; } if ($request->has('businesscard')) { $model->businesscard = $input['businesscard']; } else { $model->businesscard = 0; } if ($request->has('invitationcard')) { $model->invitationcard = $input['invitationcard']; } else { $model->invitationcard = 0; } if ($request->has('phone')) { $model->phone = $input['phone']; } else { $model->phone = 0; } if ($request->has('signshowroom')) { $model->signshowroom = $input['signshowroom']; } else { $model->signshowroom = 0; } if ($request->has('spotradiowalkin')) { $model->spotradiowalkin = $input['spotradiowalkin']; } else { $model->spotradiowalkin = 0; } if ($request->has('recommendedby')) { $model->recommendedby = $input['recommendedby']; } else { $model->recommendedby = 0; } $model->recommendedbyname = $input['recommendedbyname']; if ($request->has('recommendedbytype')) { $model->recommendedbytype = $input['recommendedbytype']; } if ($request->has('customertype')) { $model->customertype = $input['customertype']; } $model->documentstatus = $input['documentstatus']; $model->remark = $input['remark']; if ($model->oldcarbrandid == '') { $model->oldcarbrandid = null; } if ($model->oldcarmodelid == '') { $model->oldcarmodelid = null; } if ($model->oldcargear == '') { $model->oldcargear = null; } if ($model->oldcarcolor == '') { $model->oldcarcolor = null; } if ($model->oldcarenginesize == '') { $model->oldcarenginesize = null; } if ($model->oldcarlicenseplate == '') { $model->oldcarlicenseplate = null; } if ($model->oldcaryear == '') { $model->oldcaryear = null; } if ($model->oldcarprice == '') { $model->oldcarprice = null; } if ($model->oldcarbuyername == '') { $model->oldcarbuyername = null; } if ($model->oldcarother == '') { $model->oldcarother = null; } if ($model->cashpledgepaymenttype == 0) { $model->cashpledgechargepercent = null; $model->cashpledgechargeamount = null; } if ($model->purchasetype == 0) { $model->finacecompanyid = null; $model->interestratetypeid = null; $model->interest = null; $model->down = null; $model->installments = null; $model->subsidise = null; $model->interestratemode = null; } if ($model->recommendedby == false) { $model->recommendedbyname = null; $model->recommendedbytype = null; } if ($input['contractdate'] != null && $input['contractdate'] != '') { $model->contractdate = date('Y-m-d', strtotime($input['contractdate'])); } else { $model->contractdate = $input['contractdate']; } if ($model->save()) { $giveawayFreeData = $request->giveawayFreeData; $giveawayBuyData = $request->giveawayBuyData; $giveawayFreeData = json_decode($giveawayFreeData, true); $giveawayBuyData = json_decode($giveawayBuyData, true); foreach ($giveawayFreeData as $data) { $obj = new CarPreemptionGiveaway(); $obj->carpreemptionid = $model->id; $obj->giveawayid = $data["giveawayid"]; $obj->free = true; $obj->price = $data["price"]; $obj->save(); } foreach ($giveawayBuyData as $data) { $obj = new CarPreemptionGiveaway(); $obj->carpreemptionid = $model->id; $obj->giveawayid = $data["giveawayid"]; $obj->free = false; $obj->save(); } return redirect()->action('CarPreemptionController@edit', ['id' => $model->id]); } else { //hack returning error $this->validate($request, ['bookno' => 'alpha'], ['bookno.alpha' => 'ไม่สามารถทำการบันทึกข้อมูลการจองได้ กรุณาติดต่อผู้ดูแลระบบ!!']); } }
/** * @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); }; }
/** * 昵称 type */ public function signup() { $token = $this->request->get('smsToken'); $validator = \Validator::make($this->request->all(), ['user_name' => 'required|between:4,12|unique:customers|Regex:/^[a-z0-9]{4,12}$/', 'mobile' => "required|confirm_mobile_not_change:{$token}", 'password' => 'required', 'verifyCode' => "required|verify_code:{$token}|confirm_mobile_rule:mobile_required,{$token}"], ['verifyCode.required' => '请输入短信验证码', 'verify_code' => '验证码错误', 'confirm_mobile_not_change' => '当前手机号码与发送号码不符', 'confirm_mobile_rule' => '验证码验证错误', 'user_name.unique' => '用户名已注册', 'user_name.regex' => '用户名必须为小写字母或数字', 'user_name.between' => '用户名必须为4-12位']); $messages = $validator->messages(); if ($messages->has('mobile')) { $mobiles_rule = $messages->get('mobile'); foreach ($mobiles_rule as $mobile_rule) { if ($mobile_rule == '当前手机号码与发送号码不符') { return return_rest('0', '', '当前手机号码与发送号码不符'); } } } if ($messages->has('verifyCode')) { $verifyCodes = $messages->get('verifyCode'); foreach ($verifyCodes as $verifyCode) { if ($verifyCode == '请输入短信验证码') { return return_rest('0', '', '请输入短信验证码'); } if ($verifyCode == '验证码错误') { return return_rest('0', '', '验证码错误'); } if ($verifyCode == '验证码验证错误') { return return_rest('0', '', '验证码验证错误'); } } } if ($messages->has('password')) { return return_rest('0', '', '请输入密码'); } if ($messages->has('user_name')) { if ($mobile_rule == '用户名已注册') { return return_rest('0', '', '用户名已注册'); } if ($mobile_rule == '用户名必须为小写字母或数字') { return return_rest('0', '', '用户名必须为小写字母或数字'); } if ($mobile_rule == '用户名必须为4-12位') { return return_rest('0', '', '用户名必须为4-12位'); } } //增加环信注册 失败返回false $easemob = Easemob::user_register($this->request->get('user_name'), $this->request->get('password')); //TODO if (isset($easemob['mobile'])) { return return_rest('0', '', '该用户已注册环信'); } //设置用户相关信息 $mobile = $this->request->get('mobile'); $password = $this->request->get('password'); //TODO 用户类型 设置默认为3游客 1为创业者2为投资人 $type = $this->request->has('type') ? $this->request->get('type') : 3; //TODO 其他信息 $customer = new Customer(); $customer->user_name = $this->request->get('user_name'); $customer->mobile = $mobile; $customer->password = bcrypt($password); $customer->type = $type; $customer->avatar = 'http://image.haihespace.com/default/avatar/avatar.jpg'; if ($customer->save()) { // 用户注册事件 $token = \JWTAuth::fromUser($customer); //为用户生成头像 // $img = Image::make('uploads/avatars/avatar.jpg'); // $img->save('uploads/avatars/'.$mobile.'.jpg'); return return_rest('1', compact('token', 'customer')); } $this->errorBadRequest(return_rest('0', '', '操作失败')); }
public function store(CustomerRequest $request) { try { DB::transaction(function () use($request) { $inputs = $request->input(); $time = time(); $date = strtotime(date('d-m-Y')); $user = Auth::user(); $year = CommonHelper::get_current_financial_year(); $file = $request->file('picture'); $customer = new Customer(); $destinationPath = base_path() . '/public/image/customer/'; if ($request->hasFile('picture')) { $name = time() . $file->getClientOriginalName(); $file->move($destinationPath, $name); $inputs['picture'] = $name; $customer->picture = $inputs['picture']; } $customer->name = $inputs['name']; $customer->mobile = $inputs['mobile']; $customer->address = $inputs['address']; $customer->type = $inputs['type']; $customer->business_name = $inputs['business_name']; $customer->business_address = $inputs['business_address']; $customer->created_by = $user->id; $customer->created_at = $time; $customer->save(); //Personal Account Creation $personal = new PersonalAccount(); $personal->person_type = Config::get('common.person_type_customer'); if (!empty($inputs['balance'])) { $personal->balance = $inputs['balance']; } if (!empty($inputs['due'])) { $personal->due = $inputs['due']; } $personal->person_id = $customer->id; $personal->created_by = Auth::user()->id; $personal->created_at = $time; $personal->save(); if (!empty($inputs['balance'])) { //Update Workspace Ledger $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 41000, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => $year])->first(); $workspaceLedger->balance += $inputs['balance']; $workspaceLedger->updated_by = $user->id; $workspaceLedger->updated_by = $time; $workspaceLedger->save(); } if (!empty($inputs['due'])) { //Update Workspace Ledger $workspaceLedger = WorkspaceLedger::where(['workspace_id' => $user->workspace_id, 'account_code' => 12000, 'balance_type' => Config::get('common.balance_type_intermediate'), 'year' => $year])->first(); $workspaceLedger->balance += $inputs['due']; $workspaceLedger->updated_by = $user->id; $workspaceLedger->updated_by = $time; $workspaceLedger->save(); } }); } catch (\Exception $e) { Session::flash('error_message', 'Failed to create customer. Please Try again.'); return Redirect::back(); } Session::flash('flash_message', 'Customer created successfully!'); return redirect('customers'); }