/** * Finds user by [[username]] * * @return User|null */ protected function getUser() { if ($this->_user === null) { $this->_user = Customer::findByUsername($this->username); } return $this->_user; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new Customer(); $user->created_at = strtotime('now'); $user->status = Customer::STATUS_ACTIVE; $user->firstname = $this->firstname; $user->lastname = $this->lastname; $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }
/** * Creates a form model given a token. * * @param string $token * @param array $config name-value pairs that will be used to initialize the object properties * @throws InvalidParamException if token is empty or not valid */ public function __construct($token, $config = []) { if (empty($token) || !is_string($token)) { throw new InvalidParamException('Password reset token cannot be blank.'); } $this->_user = Customer::findByPasswordResetToken($token); if (!$this->_user) { throw new InvalidParamException(\common\models\I18n::t('Wrong password reset token')); } parent::__construct($config); }
/** * function ::create ($data) */ public static function create($data) { $now = strtotime('now'); // $username = Yii::$app->user->identity->username; $model = new Customer(); if ($model->load($data)) { $model->created_at = $now; $model->dob = strtotime($model->dob); // do { // $path = FileUtils::generatePath($now); // } while (file_exists(Yii::$app->params['images_folder'] . $path)); // $model->image_path = $path; // $targetFolder = Yii::$app->params['images_folder'] . $model->image_path; // $targetUrl = Yii::$app->params['images_url'] . $model->image_path; // // if (!empty($data['customer-image'])) { // $copyResult = FileUtils::copyImage([ // 'imageName' => $model->image, // 'fromFolder' => Yii::$app->params['uploads_folder'], // 'toFolder' => $targetFolder, // 'resize' => [[120, 120], [200, 200]], // 'removeInputImage' => true, // ]); // if ($copyResult['success']) { // $model->image = $copyResult['imageName']; // } // } // User class $model->status = parent::STATUS_ACTIVE; $model->generateAuthKey(); $model->setPassword($model->password); if ($model->save()) { return $model; } $model->getErrors(); return $model; } return false; }
public function actionIndex() { $mregional = new Regional(); $mcustomer = new Customer(); $session = new Session(); $company = $session->get('company'); $facebook = Facebook::find()->asArray()->count(); $twitter = Twitter::find()->asArray()->count(); $blog = Blog::find()->asArray()->count(); $instagram = Instagram::find()->asArray()->count(); $customer = Customer::find()->asArray()->count(); $customer_countall = $mcustomer->find()->limit(7)->count(); $regional = $mregional->find()->limit(7)->all(); $speedo = ""; foreach ($regional as $key => $rows) { $customer_count = $mcustomer->find()->where(['FIELD7' => $rows->FIELD1])->andWhere(['FIELD9' => $company])->limit(7)->count(); $no = $key + 1; $percentage = $customer_count / $customer_countall * 100; $agree = number_format($percentage, 0, '.', '.'); $speedo .= "<div class='wrapp-spedo'>\n <div id='speedo" . $no . "'>\n " . $agree . "\n </div>\n <h4 align='center'>REGIONAL " . $no . "</h4>\n </div>"; } return $this->render('index', ['speedo' => $speedo, 'facebook' => $facebook, 'twitter' => $twitter, 'blog' => $blog, 'instagram' => $instagram, 'customer' => $customer]); }
/** * 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, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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(['id' => $this->id, 'phone_number' => $this->phone_number, 'dob' => $this->dob, 'gender' => $this->gender, 'language_id' => $this->language_id, 'is_active' => $this->is_active, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'total_purchase_orders' => $this->total_purchase_orders, 'total_purchase_products' => $this->total_purchase_products, 'total_purchase_value' => $this->total_purchase_value]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'zip_postal_code', $this->zip_postal_code]); return $dataProvider; }
/** * Creates a new PurchaseOrder model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $username = Yii::$app->user->identity ? Yii::$app->user->identity->username : null; $model = new PurchaseOrder(); if (Yii::$app->request->isPost) { if (is_object($cart = Yii::$app->session->get('cart'))) { if ($cart->totalQuantity() > 0) { if ($model = PurchaseOrder::create(Yii::$app->request->post())) { // if ($model->customer_id !== null) { $customer = Customer::findOne(['id' => $model->customer_id, 'status' => Customer::STATUS_ACTIVE]); // } foreach ($cart->data as $item) { $p = $item['product']; $qty = $item['quantity']; if (PurchaseOrderDetail::create(['PurchaseOrderDetail' => ['purchase_order_id' => $model->id, 'product_id' => $p->id, 'product_name' => $p->t('name'), 'product_code' => $p->code, 'quantity' => $qty, 'unit_price' => $p->price, 'discount_percent' => round(100 * ($p->original_price - $p->price) / $p->original_price, 4), 'is_offer' => $p->original_price > $p->price ? 1 : 0]]) !== false) { if ($customer) { $customer->total_purchase_products += $qty; $customer->total_purchase_value += $qty * $p->price; } $p->available_quantity -= $qty; $p->order_quantity += $qty; // $p->total_revenue += $qty * $p->price; $p->save(); } } if ($customer) { $customer->total_purchase_orders++; $customer->save(false); } try { Yii::$app->orderMailer->compose(['html' => 'purchaseOrderReview-html', 'text' => 'purchaseOrderReview-text'], ['purchase_order' => $model])->setFrom([Yii::$app->params['order_email'] => Yii::$app->name])->setTo($model->customer_email)->setSubject(I18n::t('Purchase order review'))->send(); } catch (Exception $e) { } Yii::$app->session->set('cart', new Cart()); $model = new PurchaseOrder(); Yii::$app->session->setFlash('success', I18n::t('Your purchase order submitted successfully') . '. ' . I18n::t('Thank you')); // $this->goHome(); } else { Yii::$app->session->setFlash('error', I18n::t('Some errors occurred') . '. ' . I18n::t('Please try again') . '.'); } } else { Yii::$app->session->setFlash('error', I18n::t('Your cart is empty') . '. ' . I18n::t('Please try again') . '.'); } } else { Yii::$app->session->setFlash('error', I18n::t('Some errors occurred') . '. ' . I18n::t('Please try again') . '.'); } } return $this->render('create', ['username' => $username, 'model' => $model]); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = Customer::findOne(['status' => Customer::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!Customer::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save(false)) { return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([Yii::$app->params['noreply_email'] => Yii::$app->name])->setTo($this->email)->setSubject(I18n::t('Password reset for your account'))->send(); } } // var_dump($user->getErrors()); // return false; }
public function actionGet() { $modelList = Customer::find()->where(['level' => Variable::$customer_type_w])->all(); $jsonList = []; foreach ($modelList as $k => $v) { if ($v->level != Variable::$customer_type_w) { continue; } if (empty($v->parentId)) { continue; } if (!isset($v->parent) || empty($v->parent)) { continue; } $id = '1_' . $v->parent->id; $item = []; $tmp = []; $pic = []; if ($v->img1) { array_push($pic, FVariable::$domainUrl . $v->img1); } if ($v->img2) { array_push($pic, FVariable::$domainUrl . $v->img2); } if ($v->img3) { array_push($pic, FVariable::$domainUrl . $v->img3); } if ($v->img4) { array_push($pic, FVariable::$domainUrl . $v->img4); } if ($v->img5) { array_push($pic, FVariable::$domainUrl . $v->img5); } $tmp = ['name' => $v->name, 'pic' => $pic]; $jsonList[$id]['item'][] = $tmp; } echo json_encode($jsonList); }
/** * @return \yii\db\ActiveQuery */ public function getCustomer() { return $this->hasOne(Customer::className(), ['customer_user_name' => 'user_name']); }
/** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Customer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionCustomer() { $model = new Customer(); for ($i = 1; $i <= 2000; $i++) { $tunggakan = 1; $idperusahaan = 1; $id_regional = 1; $id_area = 1; if ($i % 8 == 0) { $tunggakan = 54897987; $idperusahaan = 8; $id_regional = 8; $id_area = 8; } else { if ($i % 7 == 0) { $tunggakan = 1231579; $idperusahaan = 7; $id_regional = 7; $id_area = 7; } else { if ($i % 6 == 0) { $tunggakan = 26579889; $idperusahaan = 6; $id_regional = 6; $id_area = 6; } else { if ($i % 5 == 0) { $tunggakan = 897878; $idperusahaan = 5; $id_regional = 5; $id_area = 5; } else { if ($i % 4 == 0) { $tunggakan = 4589745; $idperusahaan = 4; $id_regional = 4; $id_area = 4; } else { if ($i % 3 == 0) { $tunggakan = 26579889; $idperusahaan = 3; $id_regional = 3; $id_area = 3; } else { if ($i % 2 == 0) { $tunggakan = 1564989; $idperusahaan = 2; $id_regional = 2; $id_area = 2; } } } } } } } $model->FIELD1 = $i; $model->FIELD2 = $i; $model->FIELD3 = "08798498489"; $model->FIELD4 = $tunggakan; $model->FIELD5 = ""; $model->FIELD6 = "*****@*****.**"; $model->FIELD7 = $id_regional; $model->FIELD8 = $id_area; if ($model->insert()) { echo "sukses" . $i; } else { print_r($model->getErrors()); } } }
public function getParent() { return $this->hasOne(Customer::className(), ['id' => 'parentId']); }
public function actionCreatejsonkota() { $mcustomer = new Customer(); $mkota = new Kota(); $kota = $mkota->find()->all(); $total = $mcustomer->find()->count(); $labels = $mcustomer->attributeLabels(); $array = array(); $file = "uploads/json/customer/attributekota.json"; fopen($file, "w"); foreach ($kota as $row) { $namekota = $row->FIELD2; foreach ($labels as $key => $rows) { $label = strtoupper($rows); $filled = $mcustomer->find()->where($key . ' IS NOT NULL')->count(); $notfilled = $mcustomer->find()->where($key . ' IS NULL')->count(); array_push($array, array('kota' => $namekota, 'attribute' => array('labels' => $label, 'count' => $total, 'filled' => $filled, 'notfilled' => $notfilled))); } } $data = json_encode($array, JSON_PRETTY_PRINT); file_put_contents($file, $data); }