/** * */ public function informationAction() { // Form Information $formInformation = $this->_getForm($this->_helper->url('save')); $id = $this->_getParam('id'); if (!empty($id)) { $row = $this->_mapper->detail($id); $data = $row->toArray(); $data['start_date'] = $this->view->date($data['date_start']); $data['finish_date'] = $this->view->date($data['date_finish']); $data['scholarity'] = (empty($row->external_code) ? '' : $row->external_code . ' - ') . $row->scholarity; $budget = $this->_mapper->getBudgetCategory($id); $data['id_budget_category'] = $budget->fk_id_budget_category; $formInformation->populate($data); $formInformation->getElement('fk_id_adddistrict')->setAttrib('readonly', true); if (!$this->view->fefopContract($data['id_fefop_contract'])->isEditable()) { $formInformation->removeDisplayGroup('toolbar'); } $this->view->id_planning_course = $row->fk_id_planning_course; } else { $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $expenseModule = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PFPCI_FP); // Check if the module has Budget Category Defined if ($expenseModule->count() < 1) { foreach ($formInformation->getElements() as $element) { $element->setAttrib('disabled', true); } $this->view->fefopContract()->addMessage('Seidauk iha Rubrica ba Modulu FP.'); } else { $formInformation->getElement('id_budget_category')->setValue($expenseModule->current()->id_budget_category); } } $this->view->form = $formInformation; }
/** * */ public function informationAction() { // Form Information $formInformation = $this->_getForm($this->_helper->url('save')); $id = $this->_getParam('id'); if (!empty($id)) { $row = $this->_mapper->detail($id); $data = $row->toArray(); $data['date_start'] = $this->view->date($data['date_start']); $data['date_finish'] = $this->view->date($data['date_finish']); $data['date_formation'] = $this->view->date($data['date_formation']); $mapperSubDistrict = new Register_Model_Mapper_AddSubDistrict(); $rows = $mapperSubDistrict->listAll($data['fk_id_adddistrict']); $opts = array(array('' => '')); foreach ($rows as $row) { $opts[$row->id_addsubdistrict] = $row->sub_district; } $formInformation->getElement('fk_id_addsubdistrict')->addMultiOptions($opts); $formInformation->populate($data); $formInformation->getElement('fk_id_adddistrict')->setAttrib('readonly', true); // List the expenses related to the contract $this->view->expenses = $this->_mapper->listExpenses($id); if (!$this->view->fefopContract($data['id_fefop_contract'])->isEditable()) { $formInformation->removeDisplayGroup('toolbar'); } } else { // Fetch the Expenses related to the FE module $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $this->view->expenses = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PISE_FE); } $this->view->form = $formInformation; }
/** * */ public function printAction() { $this->_helper->layout()->setLayout('print'); $id = $this->_getParam('id'); $mapperExpense = new Fefop_Model_Mapper_Expense(); $itemsConfig = $mapperExpense->getItemsConfig(); $this->view->identifier = $itemsConfig[$id]; $this->view->rules = $this->_mapper->listRules($id); $this->view->rulesOptions = $this->_mapper->getOptionsRules(); $this->view->user = Zend_Auth::getInstance()->getIdentity(); }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $dateStart = new Zend_Date($this->_data['date_start']); $dateFinish = new Zend_Date($this->_data['date_finish']); $mapperExpense = new Fefop_Model_Mapper_Expense(); $item = $mapperExpense->getModuleToItem($this->_data['fk_id_fefop_modules']); $mapperRule = new Fefop_Model_Mapper_Rule(); $mapperRule->validate($this->_message, $this->_data, $item); // Check if the initial date is later than finish date if ($dateStart->isLater($dateFinish)) { $this->_message->addMessage('Data loron keta liu data remata.'); $this->addFieldError('date_start')->addFieldError('date_finish'); return false; } // If there is no contract yet if (empty($this->_data['fk_id_fefop_contract'])) { $dataContract = array('module' => $this->_data['fk_id_fefop_modules'], 'district' => $this->_data['fk_id_adddistrict']); $mapperFefopContract = new Fefop_Model_Mapper_Contract(); $this->_data['fk_id_fefop_contract'] = $mapperFefopContract->save($dataContract); } $this->_data['amount'] = App_General_String::toFloat($this->_data['amount']); $this->_data['date_start'] = $dateStart->toString('yyyy-MM-dd'); $this->_data['date_finish'] = $dateFinish->toString('yyyy-MM-dd'); $dataForm = $this->_data; // Save the contract $dataForm['id_per_contract'] = parent::_simpleSave(); $dataForm['fk_id_per_contract'] = $dataForm['id_per_contract']; // Save budget category $this->_saveExpenses($dataForm); if (empty($this->_data['id_per_contract'])) { $history = 'REJISTU KONTRAKTU PER: %s'; } else { $history = 'ATUALIZA KONTRAKTU PER: %s'; } $history = sprintf($history, $dataForm['id_per_contract']); $this->_sysAudit($history); $dbAdapter->commit(); return $dataForm['id_per_contract']; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
public function init() { $this->setAttrib('class', 'horizontal-form'); $elements = array(); $elements[] = $this->createElement('hidden', 'rule')->setIsArray(true); $elements[] = $this->createElement('hidden', 'value')->setIsArray(true); $elements[] = $this->createElement('hidden', 'message')->setIsArray(true); $elements[] = $this->createElement('hidden', 'required')->setIsArray(true); $elements[] = $this->createElement('hidden', 'time_unit')->setIsArray(true); $mapperExpense = new Fefop_Model_Mapper_Expense(); $itemsConfig = $mapperExpense->getItemsConfig(); $items = array('' => '') + $itemsConfig; $elements[] = $this->createElement('select', 'identifier')->setDecorators($this->getDefaultElementDecorators())->setAttrib('class', 'm-wrap span12 chosen')->setLabel('Hili Item ba Konfigurasaun')->addMultiOptions($items)->setRequired(true); $this->addElements($elements); App_Form_Toolbar::build($this, self::ID); $this->setDecorators($this->getDefaultFormDecorators()); }
/** * */ public function informationAction() { $id = $this->_getParam('id'); $row = $this->_mapper->fetchBusinessPlan($id); $mapperClient = new Client_Model_Mapper_Client(); $client = $mapperClient->detailClient($row->fk_id_perdata); $clientsBusinessPlan = $this->_mapper->listClientBusinessPlan($id); $this->view->clientsBusinessPlan = $clientsBusinessPlan; // Fetch description fields $fieldsBusinessPlan = $this->_mapper->groupFieldsBusinessPlan($id); // Fetch totals $totalsFields = $this->_mapper->groupTotals($id); $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $itemConfig = $mapperBudgetCategory->getModuleToItem($row->fk_id_fefop_modules); $this->view->expenses = $this->_mapper->listExpenses($id, $itemConfig); $this->view->initial_expense = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_INITIAL); $this->view->annual_expense = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL); $this->view->revenue_expense = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE); // List the items expense detailed $itensExpense = $this->_mapper->listItemExpenses($id); $dataItensExpense = array(); foreach ($itensExpense as $item) { if (!array_key_exists($item->fk_id_budget_category, $dataItensExpense)) { $dataItensExpense[$item->fk_id_budget_category] = array(); } $dataItensExpense[$item->fk_id_budget_category][] = $item; } $this->view->itemsExpense = $dataItensExpense; $this->view->id = $id; $this->view->contract = $row; $this->view->totals_fields = $totalsFields; $this->view->values_description_fields = $fieldsBusinessPlan; $this->view->description_fields = $this->_mapper->getDescriptionFields(); $this->view->client = $client; $this->view->no_edit = true; }
/** * * @param int $module * @return float */ public function getTotalModule($module) { $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $identifier = $mapperBudgetCategory->getModuleToItem($module); $mapperRule = new Fefop_Model_Mapper_Rule(); $ruleAmount = $mapperRule->getRuleIdentifier($identifier, Fefop_Model_Mapper_Rule::AMOUNT_MAX); if (empty($ruleAmount)) { return (double) $this->_limitAmounts[$module]; } else { return (double) $ruleAmount->value; } }
/** * */ public function addExpenseAction() { if ($this->getRequest()->isXmlHttpRequest()) { $this->_helper->layout()->disableLayout(); } $defaultValues = array('amount' => 0); $row = $this->_getParam('row'); if (!empty($row)) { $defaultValues = $row->toArray(); $this->view->expense = $row; } else { $mapperBusinessExpense = new Fefop_Model_Mapper_Expense(); $expense = $mapperBusinessExpense->fetchRow($this->_getParam('id')); $this->view->expense = $expense; } $this->view->defaultValues = $defaultValues; }
/** * */ public function informationAction() { // Form Information $formInformation = $this->_getForm($this->_helper->url('save')); $id = $this->_getParam('id'); if (!empty($id)) { $row = $this->_mapper->detail($id); $data = $row->toArray(); $data['date_start'] = $this->view->date($data['date_start']); $data['date_finish'] = $this->view->date($data['date_finish']); $mapperIsicTimor = new Register_Model_Mapper_IsicTimor(); $classTimor = $mapperIsicTimor->listClassByDisivion($data['fk_id_isicdivision']); $classes = array(); if (!empty($classTimor[$data['fk_id_isicdivision']]['classes'])) { $classes = $classTimor[$data['fk_id_isicdivision']]['classes']; } $opt = array('' => ''); foreach ($classes as $class) { $opt[$class->id_isicclasstimor] = $class->name_classtimor; } $formInformation->getElement('fk_id_isicclasstimor')->addMultiOptions($opt); $formInformation->populate($data); $formInformation->getElement('fk_id_adddistrict')->setAttrib('readonly', true); $formInformation->getElement('fk_id_fefop_modules')->setAttrib('readonly', true); // List the expenses related to the contract $this->view->expenses = $this->_mapper->listExpenses($id); // List the items expense detailed $itensExpense = $this->_mapper->listItemExpenses($id); $dataItensExpense = array(); foreach ($itensExpense as $item) { if (!array_key_exists($item->fk_id_budget_category, $dataItensExpense)) { $dataItensExpense[$item->fk_id_budget_category] = array(); } $dataItensExpense[$item->fk_id_budget_category][] = $item; } $this->view->itemsExpense = $dataItensExpense; if (!$this->view->fefopContract($data['id_fefop_contract'])->isEditable()) { $formInformation->removeDisplayGroup('toolbar'); } } else { $module = $this->_getParam('module'); if (!empty($module)) { $formInformation->getElement('fk_id_fefop_modules')->setValue($module); $constant = Fefop_Model_Mapper_Expense::CONFIG_PCE_CEC_FASE_I; if (Fefop_Model_Mapper_Module::CED == $module) { $constant = Fefop_Model_Mapper_Expense::CONFIG_PCE_CED_FASE_I; } // Fetch the Expenses related to the module $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $this->view->expenses = $mapperBudgetCategory->expensesInItem($constant); } else { foreach ($formInformation->getElements() as $element) { $element->setAttrib('disabled', true); } $formInformation->getElement('fk_id_fefop_modules')->setAttrib('disabled', null); } } $this->view->form = $formInformation; }
/** * */ public function listContractsAction() { $this->_helper->layout()->disableLayout(); $id = $this->_getParam('id'); // Fetch the Expenses related to the DRH module $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $this->view->expenses = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PFPCI_DRH); $mapperDRHTrainingPlan = new Fefop_Model_Mapper_DRHTrainingPlan(); $filters = array('no_contract' => true, 'training_plan' => $id); $this->view->beneficiaries = $mapperDRHTrainingPlan->listBeneficiariesByFilter($filters); $this->view->training_plan = $mapperDRHTrainingPlan->detail($id); }
/** * * @param int $component * @param int $contract * @return Zend_Db_Table_Rowset */ public function loadBudgetCategory($component, $contract) { if (Fefop_Model_Mapper_ExpenseType::ADDITIONALS == $component) { $mapperExpense = new Fefop_Model_Mapper_Expense(); $rows = $mapperExpense->listAll($component); } else { $mapperContract = new Fefop_Model_Mapper_Contract(); $rows = $mapperContract->listExpensesContract($contract, $component); } return $rows; }
/** * */ public function fetchFinancialAnalysisAction() { if ($this->getRequest()->isXmlHttpRequest()) { $this->_helper->layout()->disableLayout(); } $id = $this->_getParam('id'); $businessPlan = $this->_mapper->fetchBusinessPlan($id); $this->_setParam('year', $businessPlan->year_activity); $totals = $this->_mapper->groupTotals($id); foreach ($totals as $total => $amount) { $this->_setParam($total, $amount); } $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); if ($this->_mapper->hasBudgetCategory($id)) { $expenses = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL); $annualSales = $this->_mapper->listExpenses($id, Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE); } else { $expenses = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PCE_ANNUAL); $annualSales = $mapperBudgetCategory->expensesInItem(Fefop_Model_Mapper_Expense::CONFIG_PCE_REVENUE); } $totalAnnualSales = 0; if ($annualSales->count() > 0) { $totalAnnualSales = $annualSales->current()->amount; } $this->_setParam('expenses', $expenses); $this->_setParam('annual', $totalAnnualSales); $this->_setParam('submitted', $businessPlan->submitted); $this->_forward('financial-analysis'); }
/** * */ public function removeExpenseAction() { $json = $this->_mapper->removeExpense($this->_getAllParams()); $this->_helper->json($json); }
/** * * @param array $data * @return int */ protected function _saveTransaction($data) { $dbFEFOPTransaction = App_Model_DbTable_Factory::get('FEFOPTransaction'); $dbFEFOPContractFund = App_Model_DbTable_Factory::get('FEFOPContractFund'); $where = array('fk_id_fefop_contract = ?' => $data['fk_id_fefop_contract']); $contractFund = $dbFEFOPContractFund->fetchRow($where); if (empty($contractFund)) { $message = sprintf('Kontratu %s seidauk iha folin husi Fundu.', Fefop_Model_Mapper_Contract::buildNumById($data['fk_id_fefop_contract'])); $this->_message->addMessage($message, App_Message::ERROR); throw new Exception($message); } $mapperBudgetCategory = new Fefop_Model_Mapper_Expense(); $expense = $mapperBudgetCategory->fetchRow($data['fk_id_budget_category']); $data['fk_id_budget_category_type'] = $expense->fk_id_budget_category_type; // If the value is already a transaction if (!empty($data['id_fefop_transaction'])) { $idTransaction = $data['id_fefop_transaction']; $where = array('id_fefop_transaction = ?' => $idTransaction); $row = $dbFEFOPTransaction->fetchRow($where); } if (empty($row)) { $row = $dbFEFOPTransaction->createRow(); $data['fk_id_sysuser'] = Zend_Auth::getInstance()->getIdentity()->id_sysuser; } $idContract = $data['fk_id_fefop_contract']; $idExpense = $data['fk_id_budget_category']; switch ($data['fk_id_fefop_type_transaction']) { case self::TYPE_CONTRACT: $mapperContract = new Fefop_Model_Mapper_Contract(); $contract = $mapperContract->detail($idContract); $statusForbidden = array(Fefop_Model_Mapper_Status::CANCELLED, Fefop_Model_Mapper_Status::CEASED, Fefop_Model_Mapper_Status::REJECTED); if (in_array($contract->id_fefop_status, $statusForbidden)) { $message = sprintf('Kontratu %s ho status %s. Keta halo lansamentu', Fefop_Model_Mapper_Contract::buildNumById($idContract), $contract->status_description); $this->_message->addMessage($message, App_Message::ERROR); throw new Exception($message); } // Se custos acrescidos if (Fefop_Model_Mapper_ExpenseType::ADDITIONALS == $data['fk_id_budget_category_type']) { break; } $totalContract = $mapperContract->getTotalContract($idContract); // Get financial total without additional costs $totalFinancial = abs($this->getTotalContract($idContract, true)); // Sum up current transaction $totalFinancial += abs($data['amount']) - (double) $row->amount; // Check if the total financial is over the contract amount if ($totalFinancial > $totalContract) { $currency = new Zend_Currency(); $amount = $currency->setValue($totalContract)->toCurrency(); $message = sprintf('Total Lansamentu hotu-hotu keta liu Total Kontratu hotu-hotu. %s', $amount); $this->_message->addMessage($message, App_Message::ERROR); throw new Exception($message); } $totalExpenseContract = $mapperContract->getTotalExpenseContract($idContract, $idExpense); $totalExpenseFinancial = abs($this->getTotalExpenseContract($idContract, $idExpense)); // Sum up current transaction $totalExpenseFinancial += abs($data['amount']) - (double) $row->amount; if ($totalExpenseFinancial > $totalExpenseContract) { $currency = new Zend_Currency(); $amount = $currency->setValue($totalExpenseContract)->toCurrency(); $message = sprintf("Total Rubrika liu Total Rubrika iha Kontratu. %s", $amount); $this->_message->addMessage($message, App_Message::INFO); } break; case self::TYPE_REIMBURSEMENT: $totalPaymentsExpense = abs($this->getTotalExpenseContract($idContract, $idExpense, self::TYPE_CONTRACT)); $totalReibursementExpense = abs($this->getTotalExpenseContract($idContract, $idExpense, self::TYPE_REIMBURSEMENT)); // Sum up current transaction $totalReibursementExpense += abs($data['amount']) - (double) $row->amount; if ($totalPaymentsExpense <= 0) { $message = 'Keta halo lansamentu devolusan, seidauk iha lansamentu ba pagamentu ba Rúbrica nee'; $this->_message->addMessage($message, App_Message::ERROR); throw new Exception($message); } if ($totalReibursementExpense > $totalPaymentsExpense) { $currency = new Zend_Currency(); $amount = $currency->setValue($totalPaymentsExpense)->toCurrency(); $message = 'Keta halo lansamentu devolusan, folin hira nee liu pagamentu hotu ba Rúbrica nee: %s'; $this->_message->addMessage(sprintf($message, $amount), App_Message::ERROR); throw new Exception($message); } break; } $row->setFromArray($data); $row->save(); // Calculate Additional cost proportionality $this->calcAdditionalCost($data['fk_id_fefop_contract']); // Try to change contract status $this->_tryUpdateStatusContract($data['fk_id_fefop_contract']); return $row; }
/** * */ public function addExpenseAction() { $this->_helper->layout()->disableLayout(); $idContract = $this->_getParam('id_contract'); $row = $this->_getParam('row'); if (!empty($row)) { $this->view->row = $row; $idContract = $row->fk_id_fefop_contract; } $this->view->idContract = $idContract; $mapperContract = new Fefop_Model_Mapper_Contract(); $expenses = $mapperContract->listExpensesContract($idContract); $optExpenses = array('' => ''); $cont = 'A'; foreach ($expenses as $expense) { $optExpenses[$expense->id_budget_category] = $cont++ . ' - ' . $expense->description; } $mapperExpense = new Fefop_Model_Mapper_Expense(); $expensesAdditional = $mapperExpense->listAll(Fefop_Model_Mapper_ExpenseType::ADDITIONALS); foreach ($expensesAdditional as $expense) { $optExpenses[$expense->id_budget_category] = $expense->description; } $this->view->optionsBudgetCategory = $optExpenses; }