<?php
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
/**
* This class generates form components for Financial Account
- *
+ *
*/
class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form {
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
-
+
$this->applyFilter('__ALL__', 'trim');
$attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_FinancialAccount');
$this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
$this->addRule('name', ts('A financial type with this name already exists. Please select another name.'),
'objectExists', array('CRM_Financial_DAO_FinancialAccount', $this->_id));
-
+
$this->add('text', 'description', ts('Description'), $attributes['description']);
$this->add('text', 'accounting_code', ts('Accounting Code'), $attributes['accounting_code']);
$elementAccounting = $this->add('text', 'account_type_code', ts('Account Type Code'), $attributes['account_type_code']);
$this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'));
$elementActive = $this->add('checkbox', 'is_active', ts('Enabled?'));
$this->add('checkbox', 'is_tax', ts('Is Tax?'));
+
$element = $this->add('checkbox', 'is_default', ts('Default?'));
// CRM-12470 freeze is default if is_default is set
if ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_default')) {
$element->freeze();
}
+
$financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type');
if (!empty($financialAccountType)) {
$element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'),
$elementActive->freeze();
}
}
-
+
if ($this->_action == CRM_Core_Action::UPDATE &&
CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $this->_id, 'is_reserved')) {
$this->freeze(array('name', 'description', 'is_active'));
}
$this->addFormRule(array('CRM_Financial_Form_FinancialAccount', 'formRule'), $this);
}
-
+
/**
* global validation rules for the form
*
}
return CRM_Utils_Array::crmIsEmptyArray( $errorMsg ) ? true : $errorMsg;
}
-
+
/**
* This function sets the default values for the form.
* the default values are retrieved from the database
}
return $defaults;
}
-
+
/**
* Function to process the form
*
$ids = array( );
// store the submitted values in an array
$params = $this->exportValues();
-
+
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['contributionType'] = $this->_id;
}
-
+
$contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
CRM_Core_Session::setStatus(ts('The Financial Account \'%1\' has been saved.', array(1 => $contributionType->name)));
}