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]);
 }
Example #2
0
 private function checkSaleCredential(Customer $customer, $sale)
 {
     if ($sale = '1元专区') {
         return !$customer->hasPurchesedOneSale();
     }
     return true;
 }
Example #3
0
 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;
 }
Example #4
0
 public function actionPayment()
 {
     if (\Yii::$app->session->has('customer')) {
         $modelCustomer = new Customer();
         $infoCustomer = $modelCustomer->getInformation($_SESSION['customer']);
         $modelOrder = new Order();
         $modelOrderDetail = new OrderDetail();
         $modelProduct = new Product();
         $ids = array();
         foreach ($_SESSION['cart_items'] as $id => $quantity) {
             array_push($ids, $id);
         }
         $products = $modelProduct->getWithIDs($ids);
         if (\Yii::$app->request->post()) {
             $modelOrder->load(\Yii::$app->request->post());
             $modelOrder->save();
             $orderId = $modelOrder->id;
             foreach ($_SESSION['cart_items'] as $id => $quantity) {
                 $unitPrice = $modelProduct->getPrice($id) * $quantity;
                 \Yii::$app->db->createCommand()->insert('order_detail', ['orderId' => $orderId, 'productId' => $id, 'unitPrice' => $unitPrice, 'quantity' => $quantity])->execute();
             }
             \Yii::$app->session->remove('cart_items');
             return $this->redirect(['cart/index', 'success' => 'Thanh toán thành công! Chúng tôi sẽ liên hệ bạn trong thời gian sớm nhất! Xin cảm ơn!']);
         } else {
             return $this->render('payment', ['infoCustomer' => $infoCustomer, 'modelOrder' => $modelOrder, 'products' => $products]);
         }
     } else {
         $this->redirect(['customer/login', 'error' => 'Vui lòng đăng nhập trước khi thanh toán']);
     }
 }
Example #5
0
 public function actionCreateMultipleModels()
 {
     $models = [];
     $OK = true;
     if (isset($_POST['Customer'])) {
         foreach ($_POST['Customer'] as $postObj) {
             $customer = new Customer();
             $customer->attributes = $postObj;
             $isValid = $customer->validate();
             $OK = $OK && $isValid;
             $models[] = $customer;
         }
         if ($OK) {
             foreach ($models as $model) {
                 $model->save();
             }
             $this->redirect('customers/grid');
         }
     } else {
         for ($i = 0; $i < 3; $i++) {
             $models[] = new Customer();
         }
     }
     return $this->render('createMultipleModels', compact('models'));
 }
 /**
  * O método precisa informar uma lista de produtos
  * @return {view}
  */
 public function create()
 {
     $stocks = Stock::all();
     $customers = Customer::all();
     $employees = Employee::all();
     return view('pages.new_sale', ['stocks' => $stocks, 'customers' => $customers, 'employees' => $employees]);
 }
Example #7
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = Role::where('name', 'admin')->first();
     $customer = Customer::create(['name' => 'test']);
     $customer->user()->save(new User(['email' => '*****@*****.**', 'password' => bcrypt('testing')]));
     $customer->user->assignRole($role);
 }
	public function index(){
		$data = [
			'auth'=>false,
			'recentAdded'=>Customer::orderBy('created_at', 'desc')->take(5)->get()
		];
		return view('home', $data);
	}
 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 approveApplication(Request $request)
 {
     $shop_card_application_id = $request->input('require_id');
     $application = ShopCardApplication::find($shop_card_application_id);
     $customer = Customer::find($application->customer_id);
     $card_type = $application->cardType;
     try {
         \DB::transaction(function () use($application, $customer, $card_type) {
             $customer_rows = \DB::table('customers')->where('id', $customer->id);
             $customer_rows->lockForUpdate();
             $customer_row = $customer_rows->first();
             if ($customer_row->beans_total < $card_type->beans_value * $application->amount) {
                 throw new NotEnoughBeansException();
             }
             $cards = \DB::table('shop_cards')->where('card_type_id', '=', $card_type->id)->whereNull('customer_id')->limit($application->amount);
             $cards->lockForUpdate();
             if ($cards->count() < $application->amount) {
                 throw new CardNotEnoughException();
             }
             $customer->minusBeansByHand($application->amount * $card_type->beans_value);
             $cards->update(['customer_id' => $customer->id, 'bought_at' => Carbon::now()]);
             $application->update(['authorized' => true]);
             return true;
         });
     } catch (CardNotEnoughException $e) {
         return '相应卡片不足,无法继续。';
     } catch (NotEnoughBeansException $e) {
         return '用户迈豆不足!';
     }
     return "操作成功!";
 }
 public function index()
 {
     $c = Customer::get();
     $bankaccount = Bankaccount::joining();
     $voucher = Voucher::orderBy('id', 'desc')->where('type', 5)->take(10)->get();
     return view('contravouchar', compact('bankaccount', 'c', 'voucher'));
 }
Example #12
0
 /**
  * Display a customer
  *
  * @return Response
  */
 public function detail($id = null)
 {
     $result = \App\Models\Customer::id($id)->with(['sales', 'myreferrals', 'myreferrals.user'])->first();
     if ($result) {
         return new JSend('success', (array) $result->toArray());
     }
     return new JSend('error', (array) Input::all(), 'ID Tidak Valid.');
 }
 public function report()
 {
     $s = Supplier::get();
     $c = Customer::get();
     $bankaccount = Bankaccount::joining();
     $voucher = Voucher::orderBy('id', 'desc')->take(10)->get();
     return view('ledger', compact('bankaccount', 'c', 's', 'voucher'));
 }
 public function actionLogin()
 {
     $model = new Customer();
     if ($model->load(Yii::$app->request->post())) {
         $request = Yii::$app->request->post('Customer');
         $username = $request['username'];
         $password = $request['password'];
         if ($model->checkLogin($username, $password)) {
             $customerName = $model->getName($username);
             Yii::$app->session->set('customer', $customerName);
             $this->redirect(['site/index']);
         } else {
             $this->redirect(['login', 'error' => 'Tên đăng nhập hoặc mật khẩu không đúng!']);
         }
     }
     return $this->render('login', ['model' => $model]);
 }
Example #15
0
 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);
 }
Example #16
0
 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'));
 }
Example #17
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validation_rules($request);
     $customerUpdate = $request->input();
     $customer = Customer::find($id);
     $customer->update($customerUpdate);
     Session::flash('flash_message', 'Data pelanggan berhasil diupdate!');
     return redirect('admin/customer');
 }
Example #18
0
 public function getDelete($id)
 {
     $table = null;
     if (!empty($id)) {
         $table = Customer::whereId($id);
         $table->delete();
     }
     return response()->json(array('msg' => 'ok', 'state' => 1, 'data' => null));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $customer = Customer::find($id);
     if (!$customer) {
         return response()->json('Le client n\'existe pas.', 404);
     }
     $customer->delete();
     return 'Le client a bien été supprimé.';
 }
Example #20
0
 public function testInvite()
 {
     $c = Customer::find(3);
     $counter = new CustomerInvitationCounter(Customer::find(1));
     $before = $counter->getMonthlyCount();
     //        $this->assertEquals(0, $before);
     event(new Register($c));
     $after = $counter->getMonthlyCount();
     $this->assertEquals($before + 1, $after);
 }
Example #21
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $customer = null;
     if (!empty($id)) {
         $customer = Customer::find($id);
         $customer_details = DB::table('customer_details')->where('customer_uuid', $customer->uuid)->get();
     }
     //        print_r($customer);
     return view('customer.edit', ['theme' => 'default', 'customer' => $customer, 'customer_details' => $customer_details]);
 }
 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.']);
     }
 }
Example #23
0
 /**
  * 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 actionCategory($url = null)
 {
     $query = Project::find();
     $addition = Project::find()->select('id')->orderBy('id ASC')->limit(3)->asArray()->all();
     if (!is_null($url)) {
         $query->innerJoinWith('category', 'category_id = category_id')->where(['url' => $url]);
     }
     $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 9]]);
     $projectModel = Project::find()->joinWith('category', 'category.category_id = project.category_id')->orderBy('id ASC')->limit(3)->all();
     return $this->render('category', ['dataProvider' => $dataProvider, 'categoryModel' => Category::find()->all(), 'customerModel' => Customer::find()->all(), 'projectModel' => $projectModel]);
 }
Example #25
0
 public function getIndex()
 {
     if (Auth::customer()->check()) {
         $id = Auth::customer()->user()->id;
         $table = new Customer();
         if (!empty($id)) {
             $table = Customer::find($id);
         }
         return viewc('client.' . self::NAMEC . '.index', compact('table'));
     }
     return redirect('login')->with('messageError', 'Inicie sesion');
 }
 public function update(Request $request, $id)
 {
     $this->validate($request, $this->rules);
     $data = $request->all();
     /* @var Receivable $receivable */
     $receivable = Receivable::find($id);
     $receivable->update($data);
     $customer = Customer::find($data['customer']['id']);
     $receivable->customer()->associate($customer);
     $receivable->save();
     return (new ApiParcel())->addMessage('general', 'Conta a pagar alterado com sucesso!');
 }
Example #27
0
 public function getAppointments()
 {
     $appointments = Appointment::all();
     $calendarAppointments = array();
     foreach ($appointments as $a) {
         $customer = Customer::find($a['customer_id']);
         $customer = $customer->first_name . ' ' . $customer->last_name;
         $event = array('title' => 'Appointment with ' . $customer, 'start' => $a['appointment_datetime']);
         array_push($calendarAppointments, $event);
     }
     return response()->json($calendarAppointments);
 }
 public function actionIndex()
 {
     $categoryModel = Category::find()->All();
     $projectModel = Project::find()->where(['show_in_index' => '1'])->limit(6)->all();
     $customerModel = Customer::find()->All();
     $applicationConfig = ApplicationConfig::find()->one();
     $newsModel = News::find()->where(['show_in_index' => '1'])->limit(2)->all();
     $galleryModel = Gallery::find()->orderBy(new Expression('rand()'))->limit(6)->all();
     $visitor = ApplicationConfig::findOne(1);
     $visitor->visitors_count = $visitor->visitors_count + 1;
     $visitor->save();
     return $this->render('index', ['categoryModel' => $categoryModel, 'projectModel' => $projectModel, 'customerModel' => $customerModel, 'applicationConfig' => $applicationConfig, 'newsModel' => $newsModel, 'galleryModel' => $galleryModel]);
 }
Example #29
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Customer::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'gender', $this->gender])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'address', $this->address]);
     return $dataProvider;
 }
 public function actionCreateCustomerAndReservation()
 {
     $customer = new Customer();
     $reservation = new Reservation();
     $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]);
 }