Example #1
0
 /**
  * 
  * @return int|bool
  */
 public function saveInformation()
 {
     $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
     $dbAdapter->beginTransaction();
     try {
         $dataForm = $this->_data;
         $dateBirth = new Zend_Date($this->_data['birth_date']);
         $age = App_General_Date::getAge($dateBirth);
         if ($age < 14) {
             $this->_message->addMessage('Erro: Kliente iha jovem liu ba heta rejistrasaum.', App_Message::ERROR);
             $this->addFieldError('birth_date');
             return false;
         }
         if ($age > 110) {
             $this->_message->addMessage('Erro: Kliente iha katuas liu ba heta rejistrasaum.', App_Message::ERROR);
             $this->addFieldError('birth_date');
             return false;
         }
         if (!$this->_validateName()) {
             $this->_message->addMessage('Erro: Kliente naran tiha ona.', App_Message::ERROR);
             $this->addFieldError('first_name')->addFieldError('last_name');
             return false;
         }
         if (empty($this->_data['id_perdata'])) {
             $dateRegistration = new Zend_Date($this->_data['date_registration']);
             $dateNow = new Zend_Date();
             if ($dateRegistration->isLater($dateNow)) {
                 $this->_message->addMessage('Erro: Data Rejistu depois ho data ohin', App_Message::ERROR);
                 $this->addFieldError('date_registration');
                 return false;
             }
             $districtMapper = new Register_Model_Mapper_AddDistrict();
             $district = $districtMapper->fetchRow($this->_data['fk_id_adddistrict']);
             $this->_data['num_year'] = date('y');
             $this->_data['num_district'] = $district->acronym;
             $this->_data['num_servicecode'] = 'BU';
             $this->_data['num_sequence'] = str_pad($this->_getNumSequence($this->_data), 4, '0', STR_PAD_LEFT);
             $this->_data['date_registration'] = $dateRegistration->toString('yyyy-MM-dd');
             $history = 'REJISTRU KLIENTE: %s HAKAT 1 - REJISTRU DADOS OBRIGATORIU HUSI KLIENTE';
             // Prepare the data to the history
             $dataHistory = array('action' => 'KLIENTE HALO REJISTRU CEOP', 'description' => 'REJISTRU DADOS OBRIGATORIU HUSI KLIENTE');
         } else {
             unset($this->_data['date_registration'], $this->_data['fk_id_adddistrict'], $this->_data['num_subdistrict']);
             $history = 'ATUALIZA KLIENTE: %s DADUS PRINCIPAL - ATUALIZA DADOS OBRIGATORIU HUSI KLIENTE';
             // Prepare the data to the history
             $dataHistory = array('action' => 'ATUALIZA KLIENTE DADUS PRINCIPAL', 'description' => 'ATUALIZA DADOS OBRIGATORIU HUSI KLIENTE');
         }
         $this->_data['birth_date'] = $dateBirth->toString('yyyy-MM-dd');
         // Save the Client
         $id = parent::_simpleSave();
         // If it is inserting the client and it has document
         if (empty($dataForm['id_perdata']) && !empty($dataForm['fk_id_pertypedocument'])) {
             $dataForm['fk_id_perdata'] = $id;
             $this->_saveDocument($dataForm);
         }
         // Set the missing data to the history
         $dataHistory['fk_id_perdata'] = $id;
         $dataHistory['fk_id_dec'] = $dataForm['fk_id_dec'];
         // Save the client history
         $this->_saveHistory($dataHistory);
         // Save the audit
         $history = sprintf($history, $id);
         $this->_sysAudit($history);
         $dbAdapter->commit();
         return $id;
     } catch (Exception $e) {
         $dbAdapter->rollBack();
         $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR);
         return false;
     }
 }
 /**
  * 
  */
 public function calculateMonthAction()
 {
     $dateIni = new Zend_Date($this->_getParam('data_ini'));
     $dateFin = new Zend_Date($this->_getParam('date_fim'));
     $diff = App_General_Date::getMonth($dateIni, $dateFin);
     $this->_helper->json(array('duration' => $diff));
 }
Example #3
0
 /**
  * 
  */
 public function calcAgeAction()
 {
     $birth = $this->_getParam('birth');
     $date = new Zend_Date($birth);
     $now = $this->_getParam('finish');
     if (!empty($now)) {
         $now = new Zend_Date($now);
     }
     $data = array('age' => App_General_Date::getAge($date, $now));
     $this->_helper->json($data);
 }
Example #4
0
 /**
  * 
  * @return int|bool
  */
 public function saveEditTrainee()
 {
     $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
     $dbAdapter->beginTransaction();
     try {
         $dbTrainee = App_Model_DbTable_Factory::get('JOBTraining_Trainee');
         $date = new Zend_Date();
         if (!empty($this->_data['date_start'])) {
             $this->_data['date_start'] = $date->set($this->_data['date_start'])->toString('yyyy-MM-dd');
         }
         if (!empty($this->_data['date_finish'])) {
             $this->_data['date_finish'] = $date->set($this->_data['date_finish'])->toString('yyyy-MM-dd');
         }
         $history = 'ATUALIZA JOB TRAINING - TRAINEE: %s - IHA JOB TRAINING - %s';
         if (!empty($this->_data['status'])) {
             $dateIni = new Zend_Date($this->_data['date_start']);
             $dateFinish = new Zend_Date($this->_data['date_finish']);
             $duration = App_General_Date::getMonth($dateIni, $dateFinish);
             $jobTraining = $this->fetchRow($this->_data['fk_id_jobtraining']);
             $this->_data['completed'] = $duration < $jobTraining->duration ? 0 : 1;
         }
         $id = parent::_simpleSave($dbTrainee);
         $history = sprintf($history, $id, $this->_data['fk_id_jobtraining']);
         $this->_sysAudit($history);
         $dbAdapter->commit();
         return $id;
     } catch (Exception $e) {
         $dbAdapter->rollBack();
         $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR);
         return false;
     }
 }