/** * Creates a new Device model. * * @return mixed */ public static function actionCreate($param_data = null) { $model = new Device(); if ($param_data) { $current_exp = DeviceController::getCurrentExpiration($param_data); // calculate current and future device count $current_device_count = Device::find()->where(['user_id' => $param_data['user_id']])->count(); $current_device_count = $current_device_count > 0 ? $current_device_count : 0; $new_device_count = DeviceCountOptions::find('value')->where(['id' => $param_data->getAttribute('device_count_id')])->one()->getAttribute('value'); $final_device_count = $current_device_count + $new_device_count; // misc req. info $username = User::find()->where(['id' => $param_data->getAttribute('user_id')])->one()->getAttribute('username'); $user_id = $param_data->getAttribute('user_id'); // loop for the # of devices purchased while ($current_device_count < $final_device_count) { $device_mdl = new Device(); $device_mdl->setAttribute('created_at', time()); $device_mdl->setAttribute('device_name', $username . ' ' . ++$current_device_count); $device_mdl->setAttribute('expiration', $current_exp); $device_mdl->setAttribute('pass_phrase', DeviceController::generateRandomString()); $device_mdl->setAttribute('user_id', $user_id); // save entery and insert into RadCheck if ($device_mdl->validate() && $device_mdl->save()) { RadCheckController::actionCreate($device_mdl); } else { Yii::$app->getSession()->setFlash('error', 'Error saving new devices to your account.'); return false; } } Yii::$app->getSession()->setFlash('success', $new_device_count . ' device(s) successfully added to your account.'); return $device_mdl; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Lists all DeviceCountOptions models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => DeviceCountOptions::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
<?php echo $this->render('_purchasemenu'); ?> <?php $form = ActiveForm::begin(['layout' => 'horizontal', 'enableClientScript' => true, 'enableAjaxValidation' => false, 'enableClientValidation' => true, 'validateOnChange' => true]); ?> <hr> <h1>Service Options:</h1> <div class="form-group field-purchase-type required"> <div class="col-sm-6 col-sm-offset-3"> <?php echo Html::activeDropDownList($purchase_mdl, 'device_count_id', ArrayHelper::map(DeviceCountOptions::find()->all(), 'id', 'key', 'cost'), ['prompt' => '--Select Number of Devices--', 'class' => 'form-control']); ?> </div> </div> <div class="form-group field-purchase-type required"> <div class="col-sm-6 col-sm-offset-3"> <?php echo Html::activeDropDownList($purchase_mdl, 'time_amount_id', ArrayHelper::map(TimeAmountOptions::find()->all(), 'id', 'key', 'cost'), ['prompt' => '--Select Length of Time--', 'class' => 'form-control']); ?> </div> </div> <?php echo $this->render('_billing', ['form' => $form, 'purchase_mdl' => $purchase_mdl]); ?>
/** * [prepPayPalData description] * * Maps data from the two forms into the way the paypal component expects it. * * @version 0.5.1 * @since 0.5.1 * @param Purchase $param_data * @param CCFormat $cc_data * @return array */ private function prepPayPalData(Purchase $param_data, CCFormat $cc_data) { // todo This iteration is Paypal only. - DJE : 2015-04-11 // Process the CC transaction $return_data['Address'] = ['City' => $param_data->getAttribute('city'), 'CountryCode' => Country::find('value')->where(['id' => $param_data->getAttribute('country_id')])->one()->getAttribute('key'), 'Line1' => $param_data->getAttribute('street_1'), 'Line2' => $param_data->getAttribute('street_2'), 'PostalCode' => $param_data->getAttribute('postal'), 'State' => $param_data->getAttribute('prov')]; // Process the CC transaction $return_data['CreditCard'] = ['Cvv2' => $cc_data['cvv2'], 'FirstName' => $param_data->getAttribute('f_name'), 'LastName' => $param_data->getAttribute('l_name'), 'Month' => $cc_data['exp_month'], 'Number' => $cc_data['number'], 'Type' => $cc_data['type'], 'Year' => $cc_data['exp_year']]; $subtotal = []; $subtotal[0] = isset(\Yii::$app->request->post()['Purchase']['time_amount_id']) ? TimeAmountOptions::find('value')->where(['id' => \Yii::$app->request->post()['Purchase']['time_amount_id']])->one()->getAttribute('cost') : 0; $subtotal[1] = isset(\Yii::$app->request->post()['Purchase']['device_count_id']) ? DeviceCountOptions::find('value')->where(['id' => \Yii::$app->request->post()['Purchase']['device_count_id']])->one()->getAttribute('cost') : 0; $return_data['Details']['SubTotal'] = array_sum($subtotal); return $return_data; }
?> <div class="purchase-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php /* <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> <?= Html::a('Delete', ['delete', 'id' => $model->id], [ 'class' => 'btn btn-danger', 'data' => [ 'confirm' => 'Are you sure you want to delete this item?', 'method' => 'post', ], ]) ?> */ ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => [['label' => 'Length of Time', 'value' => TimeAmountOptions::find()->where(['id' => $model->getAttribute('time_amount_id')])->one()->getAttribute('key')], ['label' => '# of Devices', 'value' => DeviceCountOptions::find()->where(['id' => $model->getAttribute('device_count_id')])->one()->getAttribute('key')], 'f_name', 'l_name', 'street_1', 'street_2', 'city', ['label' => 'State / Prov.', 'value' => $model->getAttribute('prov')], 'postal', 'last_4', 'price', 'created_at:datetime']]); ?> </div>