/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $dataForm = $this->_data; // If there is no business plan yet if (empty($dataForm['id_businessplan'])) { $mapperModule = new Fefop_Model_Mapper_Module(); $module = $mapperModule->fetchModule($dataForm['module']); // Get the District $mapperDistrict = new Register_Model_Mapper_AddDistrict(); $district = $mapperDistrict->fetchRow($dataForm['fk_id_adddistrict']); $dataForm += array('fk_id_fefop_modules' => $module->id_fefop_modules, 'num_district' => $district->acronym, 'num_module' => $module->num_module, 'num_year' => date('y')); $dataForm['num_sequence'] = str_pad($this->_getNumSequence($dataForm), 4, '0', STR_PAD_LEFT); $dataForm['bussines_plan_developer'] = $dataForm['fk_id_perdata']; //If it is not CEG, fetch the first contract if (Fefop_Model_Mapper_Module::CEG != $dataForm['module']) { $dbPceContract = App_Model_DbTable_Factory::get('PCEContract'); $whereContract = array('fk_id_fefop_modules = ?' => $dataForm['module'], 'fk_id_perdata = ?' => $dataForm['fk_id_perdata']); $pceContract = $dbPceContract->fetchRow($whereContract); $dataForm['fk_id_pce_contract'] = $pceContract->id_pce_contract; } } // If it is CED module, check to see if the client has any disability if (Fefop_Model_Mapper_Module::CED == $dataForm['module'] && !Client_Model_Mapper_Client::isHandicapped($dataForm['fk_id_perdata'])) { $this->_message->addMessage("Benefisiariu ne'e la iha defisiénsia ba halo modulu CED.", App_Message::ERROR); return false; } // Check to see if there are another participants $dataForm['partisipants'] = !empty($dataForm['clients']) ? 'G' : 'S'; if (!empty($dataForm['clients'])) { $dataForm['total_partisipants'] = count($dataForm['clients']) + 1; } else { $dataForm['total_partisipants'] = 1; } $this->_data = $dataForm; $id = parent::_simpleSave(); $dataForm['id_businessplan'] = $id; if (!empty($dataForm['clients']) && count($dataForm['clients']) > 5) { throw new Exception('More then five clients'); } // save participants in the Business Plan $this->_saveParticipants($dataForm); $history = "INSERE PLANU NEGOSIU: %s BA PROGRAMA PCE IHA MODULU: %s"; $history = sprintf($history, $id, $dataForm['id_businessplan']); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * * @return int|bool */ public function save($dataExternal) { try { // Get the Module $mapperModule = new Fefop_Model_Mapper_Module(); $module = $mapperModule->fetchModule($dataExternal['module']); // Get the District $mapperDistrict = new Register_Model_Mapper_AddDistrict(); $district = $mapperDistrict->fetchRow($dataExternal['district']); $data = array('fk_id_fefop_modules' => $module->id_fefop_modules, 'fk_id_fefop_programs' => $module->id_fefop_programs, 'fk_id_sysuser' => Zend_Auth::getInstance()->getIdentity()->id_sysuser, 'num_district' => $district->acronym, 'num_program' => $module->num_program, 'num_module' => $module->num_module, 'num_year' => date('y')); $data['num_sequence'] = str_pad($this->_getNumSequence($data), 4, '0', STR_PAD_LEFT); $this->_data = $data; $id = parent::_simpleSave($this->_dbTable, false); $dataStatus = array('contract' => $id, 'status' => !empty($dataExternal['status']) ? $dataExternal['status'] : Fefop_Model_Mapper_Status::ANALYSIS, 'description' => 'Kontraktu rejistu'); $mapperStatus = new Fefop_Model_Mapper_Status(); $mapperStatus->setData($dataStatus)->save(); return $id; } catch (Exception $ex) { throw $ex; } }