/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new LbCustomerContact(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $customer_id = ""; if (isset($_GET['customer_id'])) { $customer_id = $_GET['customer_id']; } if (isset($_POST['LbCustomerContact'])) { $model->attributes = $_POST['LbCustomerContact']; $model->lb_customer_id = $customer_id; if ($model->save()) { Yii::app()->request->redirect(Yii::app()->createUrl('lbCustomer/default/view', array('id' => $customer_id))); } } LBApplication::render($this, 'create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($own = false) { $model = new LbCustomer(); $addressModel = new LbCustomerAddress(); $contactModel = new LbCustomerContact(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['LbCustomer'])) { $model->attributes = $_POST['LbCustomer']; if ($model->save()) { // save address if any if (isset($_POST['LbCustomerAddress'])) { $addressModel->attributes = $_POST['LbCustomerAddress']; $addressModel->lb_customer_id = $model->lb_record_primary_key; $addressModel->save(); } // save contact if any if (isset($_POST['LbCustomerContact'])) { $contactModel->attributes = $_POST['LbCustomerContact']; $contactModel->lb_customer_id = $model->lb_record_primary_key; if ($contactModel->save()) { // automatically assign this contact to submitted address $contactAddressModel = new LbCustomerAddressContact(); $contactAddressModel->lb_customer_address_id = $addressModel->lb_record_primary_key; $contactAddressModel->lb_customer_contact_id = $contactModel->lb_record_primary_key; $contactAddressModel->save(); } } //$this->redirect(array('view','id'=>$model->lb_record_primary_key)); $this->redirect($model->getViewURL($model->lb_customer_name)); } } if ($own) { $this->renderPartial('create', array('model' => $model, 'addressModel' => $addressModel, 'contactModel' => $contactModel, 'own' => $own)); } else { LBApplication::render($this, 'create', array('model' => $model, 'addressModel' => $addressModel, 'contactModel' => $contactModel, 'own' => $own)); } }
/** * Quick create contact from a modal form * over invoice main page * * @param $id invoice id * @return bool * @throws ChttpException if customer is not selected */ public function actionAjaxQuickCreateContact($id) { $model = $this->loadModel($id); $customerModel = LbCustomer::model()->findByPk($model->lb_invoice_customer_id); $customerContact = new LbCustomerContact(); // a customer must have been assigned first if ($customerModel === null) { throw new CHttpException(404, 'Please select a customer first.'); } if (isset($_POST['LbCustomerContact'])) { // save customer data $customerContact->attributes = $_POST['LbCustomerContact']; $customerContact->lb_customer_id = $customerModel->lb_record_primary_key; if ($customerContact->save()) { // assign this contact to this invoice $model->lb_invoice_attention_contact_id = $customerContact->lb_record_primary_key; $model->save(); } //return JSON record of customer address LBApplication::renderPlain($this, array('content' => CJSON::encode($customerContact))); return true; } // show quick create form LBApplication::render($this, '_form_contact', array('model' => $model, 'customerModel' => $customerModel, 'customerContactModel' => $customerContact)); }
public function actionExpensesNewCustomer() { // $model = $this->loadModel($id); $expenses_id = isset($_REQUEST['expenses_id']) ? $_REQUEST['expenses_id'] : 0; // $submission_type = isset($_GET['form_type']) ? $_GET['form_type'] : 'default'; $expensesModel = LbExpenses::model()->findByPk($expenses_id); $customerModel = new LbCustomer(); $addressModel = new LbCustomerAddress(); $contactModel = new LbCustomerContact(); $own = false; if (isset($_POST['LbCustomer'])) { $customerModel->attributes = $_POST['LbCustomer']; // $customerModel->lb_customer_is_own_company = 0; if ($customerModel->save()) { // if($submission_type == 'ajax'){ if (isset($expenses_id) && $expenses_id > 0) { $expenses_customer = new LbExpensesCustomer(); $expenses_customer->lb_expenses_id = $expenses_id; $expenses_customer->lb_customer_id = $customerModel->lb_record_primary_key; $expenses_customer->save(); LBApplication::renderPlain($this, array('content' => CJSON::encode($expenses_customer))); } if (isset($_POST['LbCustomerAddress'])) { $addressModel->attributes = $_POST['LbCustomerAddress']; $addressModel->lb_customer_id = $customerModel->lb_record_primary_key; $addressModel->save(); } // save contact if any if (isset($_POST['LbCustomerContact'])) { $contactModel->attributes = $_POST['LbCustomerContact']; $contactModel->lb_customer_id = $customerModel->lb_record_primary_key; if ($contactModel->save()) { // automatically assign this contact to submitted address $contactAddressModel = new LbCustomerAddressContact(); $contactAddressModel->lb_customer_address_id = $addressModel->lb_record_primary_key; $contactAddressModel->lb_customer_contact_id = $contactModel->lb_record_primary_key; $contactAddressModel->save(); } } } } LBApplication::render($this, 'addCustomer', array('expensesModel' => $expensesModel, 'own' => $own, 'customerModel' => $customerModel, 'addressModel' => $addressModel, 'contactModel' => $contactModel)); }