示例#1
0
 public static function getProgressiveCode($group_id)
 {
     $max = Customers::maximum(array('column' => 'codice_fatturatario', 'conditions' => "customers_groups_id = {$group_id}"));
     $customer_code = str_pad((int) substr($max, -4) + 1, 4, 0, STR_PAD_LEFT);
     $group_code = CustomersGroups::findFirstById($group_id)->codice_gruppo;
     return $group_code . $customer_code;
 }
示例#2
0
 public function updateCustomerDetailsAction()
 {
     if ($this->request->isPost()) {
         if ($this->request->isAjax()) {
             $field = $this->request->getPost('name');
             $value = $this->request->getPost('value');
             $id = $this->request->getPost('pk');
             $customer = Customers::findFirstById($id);
             if ($customer) {
                 if (!$customer->dettagli) {
                     $customer->dettagli = new CustomersDetails();
                 }
                 if (!$customer->indirizzo) {
                     $customer->indirizzo = new CustomersAddress();
                 }
                 $customer->dettagli->{$field} = $value;
                 $customer->indirizzo->{$field} = $value;
                 if ($customer->save() !== false) {
                     $response = array('error' => 0, 'message' => _('Customer Details updated'));
                 } else {
                     $response = array('error' => 1);
                     foreach ($customer->getMessages() as $message) {
                         $response['message'] .= $message . '<br>';
                     }
                 }
             } else {
                 $response = array('error' => 2, 'message' => _('No Customer Found'));
             }
             return $this->sendAjax($response);
         }
     }
 }