コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new LbCustomerAddress();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $customer_id = $_REQUEST['customer_id'];
     if (isset($_POST['LbCustomerAddress'])) {
         $model->attributes = $_POST['LbCustomerAddress'];
         $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, 'customer_id' => $customer_id));
 }
コード例 #2
0
 /**
  * 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));
     }
 }
コード例 #3
0
 /**
  * Quick create customer address from a modal form
  * over invoice main page
  *
  * @param string $id   invoice id
  * @return bool
  * @throws CHttpException if customer is not selected.
  */
 public function actionAjaxQuickCreateAddress($id)
 {
     $model = $this->loadModel($id);
     $customerModel = LbCustomer::model()->findByPk($model->lb_invoice_customer_id);
     $customerAddress = new LbCustomerAddress();
     // a customer must have been assigned first
     if ($customerModel === null) {
         throw new CHttpException(404, 'Please select a customer first.');
     }
     if (isset($_POST['LbCustomerAddress'])) {
         // save customer data
         $customerAddress->attributes = $_POST['LbCustomerAddress'];
         $customerAddress->lb_customer_id = $customerModel->lb_record_primary_key;
         if ($customerAddress->save()) {
             // assign this address to this invoice
             $model->lb_invoice_customer_address_id = $customerAddress->lb_record_primary_key;
             $model->save();
         }
         //return JSON record of customer address
         LBApplication::renderPlain($this, array('content' => CJSON::encode($customerAddress->formatAddressLines())));
         return true;
     }
     // show quick create form
     LBApplication::render($this, '_form_address', array('model' => $model, 'customerModel' => $customerModel, 'customerAddressModel' => $customerAddress));
 }
コード例 #4
0
 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));
 }