<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
$this->_isARFlag = TRUE;
if ($this->_action & CRM_Core_Action::DELETE) {
$msg = ts("The selected financial account cannot be deleted because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).");
- if (CRM_Utils_Array::value('snippet', $_REQUEST) == 'json') {
- CRM_Core_Page_AJAX::returnJsonResponse($msg);
- }
- CRM_Core_Session::setStatus($msg, '', 'error');
- CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount',
- "reset=1&action=browse"));
+ CRM_Core_Error::statusBounce($msg);
}
}
}
*/
public function buildQuickForm( ) {
parent::buildQuickForm( );
+ $this->setPageTitle(ts('Financial Account'));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
if (!empty($financialAccountType)) {
$element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'),
- array('' => '- select -') + $financialAccountType, TRUE);
+ array('' => '- select -') + $financialAccountType, TRUE, array('class' => 'crm-select2 huge'));
if ($this->_isARFlag) {
$element->freeze();
$elementAccounting->freeze();
/**
* global validation rules for the form
*
- * @param array $fields posted values of the form
+ * @param $values
+ * @param $files
+ * @param $self
+ *
+ * @internal param array $fields posted values of the form
*
* @return array list of errors to be posted back to the form
* @static
*/
static function formRule( $values, $files, $self ) {
$errorMsg = array( );
- if (!empty( $values['tax_rate'])) {
- if ($values['tax_rate'] <= 0 || $values['tax_rate'] > 100) {
+ $financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' "));
+ if (isset($values['is_tax'])) {
+ if ($values['financial_account_type_id'] != $financialAccountTypeId) {
+ $errorMsg['financial_account_type_id'] = ts('Taxable accounts should have Financial Account Type set to Liability.');
+ }
+ if (CRM_Utils_Array::value('tax_rate', $values) == NULL) {
+ $errorMsg['tax_rate'] = ts('Please enter value for tax rate');
+ }
+ }
+ if ((CRM_Utils_Array::value('tax_rate', $values) != NULL)) {
+ if ($values['tax_rate'] < 0 || $values['tax_rate'] >= 100) {
$errorMsg['tax_rate'] = ts('Tax Rate Should be between 0 - 100');
}
}
+ if ($self->_action & CRM_Core_Action::UPDATE) {
+ if (!(isset($values['is_tax']))) {
+ $relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
+ $params = array(
+ 'financial_account_id' => $self->_id,
+ 'account_relationship'=> $relationshipId
+ );
+ $result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults);
+ if ($result) {
+ $errorMsg['is_tax'] = ts('Is Tax? must be set for this financial account');
+ }
+ }
+ }
return CRM_Utils_Array::crmIsEmptyArray( $errorMsg ) ? true : $errorMsg;
}
CRM_Core_Session::setStatus(ts('The Financial Account \'%1\' has been saved.', array(1 => $contributionType->name)));
}
}
+
}