コード例 #1
0
 /**
  * edit method
  *
  * @param string $id
  * @return void
  */
 public function edit($id = null, $section = null)
 {
     if ($section == 'basic') {
         $section = 'builder-basic';
     }
     $this->Customer->id = $id;
     if (!$this->Customer->exists()) {
         throw new NotFoundException(__('Invalid customer'));
     }
     if ($this->request->is('post') || $this->request->is('put')) {
         $exit_email = $this->Customer->find('first', array('fields' => array('email'), 'conditions' => array('email' => $this->request->data['Customer']['email'])));
         $this->request->data['Customer']['last_name'] = $this->request->data['BuilderAccount']['builder_legal_name'];
         //      debug($this->request->data);exit;
         App::import('Model', 'CustomerManager.BuilderAccount');
         $this->BuilderAccount = new BuilderAccount();
         $builder_account_info = $this->BuilderAccount->find('all', array('conditions' => array('BuilderAccount.customer_id' => $id)));
         $BuilderAccount_old_id = $builder_account_info[0]['BuilderAccount']['id'];
         if ($this->Customer->save($this->request->data)) {
             $msg = "";
             if ($exit_email) {
                 $msg = '"' . $this->request->data['Customer']['email'] . '" This email address already exist.';
             }
             $this->Session->setFlash(__('The customer has been saved. ' . $msg));
             if ($section != 'builder-basic') {
                 $this->redirect(array('action' => 'detail_section', $this->Customer->id, $section));
             } else {
                 $sales_representatives = serialize($this->request->data['Customer']['sales_representative']);
                 $customer_id_sales = $this->Customer->id;
                 App::uses("CustomerSalesRepresentetives", "CustomerManager.Model");
                 $csr = new CustomerSalesRepresentetives();
                 $csr->deleteAll(array('CustomerSalesRepresentetives.customer_id' => $this->Customer->id));
                 foreach ($this->request->data['Customer']['sales_representative'] as $value) {
                     $sales_list = array('user_id' => $value, 'customer_id' => $this->Customer->id);
                     $user = new CustomerSalesRepresentetives();
                     $user->save($sales_list);
                 }
                 App::uses("BuilderSupplyTypesList", "CustomerManager.Model");
                 $bst = new BuilderSupplyTypesList();
                 $bst->deleteAll(array('BuilderSupplyTypesList.builder_account_id' => $BuilderAccount_old_id));
                 $builder_supply_types_list = array();
                 if (is_array($this->request->data['BuilderAccount']['builder_supply_type_id']) && !empty($this->request->data['BuilderAccount']['builder_supply_type_id'])) {
                     foreach ($this->request->data['BuilderAccount']['builder_supply_type_id'] as $value) {
                         $builder_supply_types_list[] = array('inventory_lookup_id' => $value, 'builder_account_id' => $this->Customer->BuilderAccount->id);
                     }
                     $bst = new BuilderSupplyTypesList();
                     $bst->saveAll($builder_supply_types_list);
                 }
                 $this->redirect(array('action' => DETAIL, $this->Customer->id));
             }
         } else {
             $this->Session->setFlash(__('The customer could not be saved. Please, try again.'));
         }
     } else {
         $this->request->data = $this->Customer->find('first', array('conditions' => array('Customer.customer_type_id' => array('2', '3'), 'Customer.id' => $id)));
         $sales_data = $this->request->data['Customer']['sales_representatives'];
         App::uses("BuilderSupplyTypesList", "CustomerManager.Model");
         $builder_supply_types_list = new BuilderSupplyTypesList();
         $builder_supply_types = $builder_supply_types_list->find("all", array("conditions" => array("BuilderSupplyTypesList.builder_account_id" => $this->request->data['BuilderAccount']['id'])));
     }
     $customerTypes = $this->Customer->CustomerType->find('list');
     $this->set(compact('customerTypes', 'id', 'section', 'sales_data', 'builder_supply_types'));
 }
コード例 #2
0
 /**
  * edit method
  *
  * @param string $id
  * @return void
  */
 public function edit($id = null, $section = null)
 {
     $this->Customer->id = $id;
     if (!$this->Customer->exists()) {
         throw new NotFoundException(__('Invalid customer'));
     }
     if ($this->request->is('post') || $this->request->is('put')) {
         $exit_email = $this->Customer->find('first', array('fields' => array('email'), 'conditions' => array('email' => $this->request->data['Customer']['email'])));
         if ($this->Customer->save($this->request->data)) {
             $msg = "";
             if ($exit_email) {
                 $msg = '"' . $this->request->data['Customer']['email'] . '" This email address already exist.';
             }
             $this->Session->setFlash(__('The retail customer has been saved. ' . $msg));
             if ($section != 'basic') {
                 $this->redirect(array('action' => 'detail_section', $this->Customer->id, $section));
             } else {
                 $sales_representatives = serialize($this->request->data['Customer']['sales_representative']);
                 $customer_id_sales = $this->Customer->id;
                 App::uses("CustomerSalesRepresentetives", "CustomerManager.Model");
                 $csr = new CustomerSalesRepresentetives();
                 $csr->deleteAll(array('CustomerSalesRepresentetives.customer_id' => $this->Customer->id));
                 foreach ($this->request->data['Customer']['sales_representative'] as $key => $value) {
                     $sales_list = array('user_id' => $value, 'customer_id' => $this->Customer->id);
                     $user = new CustomerSalesRepresentetives();
                     $user->save($sales_list);
                 }
                 $this->request->data['Customer']['sales_representatives'] = $sales_representatives;
                 $this->request->data['id'] = $customer_id_sales;
                 $this->Customer->save($this->request->data);
                 $this->redirect(array('action' => DETAIL, $this->Customer->id));
             }
         } else {
             $this->Session->setFlash(__('The retail customer could not be saved. Please, try again.'));
         }
     } else {
         $this->request->data = $this->Customer->read(null, $id);
         $sales_data = $this->request->data['Customer']['sales_representatives'];
     }
     $customerTypes = $this->Customer->CustomerType->find('list');
     $this->set(compact('customerTypes', 'id', 'section', 'sales_data'));
 }