Skip to content
Snippets Groups Projects
Commit 7b3622bf authored by Pradeep Nayak's avatar Pradeep Nayak
Browse files

-- worked on CRM-12470 and fixed formatting

----------------------------------------
* CRM-12470: Creating new financial type without AR account leads to unbalanced transactions
  http://issues.civicrm.org/jira/browse/CRM-12470
parent ddaa8ef1
Branches
Tags
No related merge requests found
......@@ -128,11 +128,21 @@ class CRM_Admin_Page_AJAX {
$status = ts('Are you sure you want to disable this relationship type?') . '<br/><br/>' . ts('Users will no longer be able to select this value when adding or editing relationships between contacts.');
break;
case 'CRM_Contribute_BAO_FinancialType':
case 'CRM_Financial_BAO_FinancialType':
$status = ts('Are you sure you want to disable this financial type?');
break;
case 'CRM_Financial_BAO_FinancialAccount':
if (!CRM_Financial_BAO_FinancialAccount::getARAccounts($recordID)) {
$show = 'noButton';
$status = ts('The selected financial account cannot be disabled because least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).');
}
else {
$status = ts('Are you sure you want to disable this financial account?');
}
break;
case 'CRM_Financial_BAO_PaymentProcessor':
case 'CRM_Financial_BAO_PaymentProcessor':
$status = ts('Are you sure you want to disable this payment processor?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing transaction pages.');
break;
......
......@@ -48,7 +48,7 @@ class CRM_Financial_Page_AJAX {
empty($_GET['_value'])) {
CRM_Utils_System::civiExit();
}
$defaultId = NULL;
if ($_GET['_value'] == 'select') {
$result = CRM_Contribute_PseudoConstant::financialAccount();
}
......@@ -65,6 +65,7 @@ class CRM_Financial_Page_AJAX {
$financialAccountType = "{$financialAccountType[$_GET['_value']]}";
$result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
$defaultId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = $financialAccountType");
}
$elements = array(
array(
......@@ -75,10 +76,14 @@ class CRM_Financial_Page_AJAX {
if (!empty($result)){
foreach ($result as $id => $name) {
$selectedArray = array();
if ($id == $defaultId) {
$selectedArray['selected'] = 'Selected';
}
$elements[] = array(
'name' => $name,
'value' => $id,
);
) + $selectedArray;
}
}
echo json_encode($elements);
......
......@@ -26,142 +26,139 @@
{* this template is used for adding/editing/deleting financial type *}
<h3>{if $action eq 8}{ts}Delete Financial Type Account{/ts}{elseif $action eq 1}{ts}Add New Financial Type Account{/ts}{elseif $action eq 2}{ts}Edit Financial Type Account{/ts}{/if}</h3>
<div class="crm-block crm-form-block crm-financial_type-form-block">
{if $action eq 8}
<div class="messages status">
<div class="icon inform-icon"></div>
{ts}WARNING: You cannot delete a financial type if it is currently used by any Contributions, Contribution Pages or Membership Types. Consider disabling this option instead.{/ts} {ts}Deleting a financial type cannot be undone.{/ts} {ts}Do you want to continue?{/ts}
{if $action eq 8}
<div class="messages status">
<div class="icon inform-icon"></div>
{ts}WARNING: You cannot delete a financial type if it is currently used by any Contributions, Contribution Pages or Membership Types. Consider disabling this option instead.{/ts} {ts}Deleting a financial type cannot be undone.{/ts} {ts}Do you want to continue?{/ts}
</div>
{else}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
{else}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout">
<table class="form-layout">
<tr class="crm-contribution-form-block-account_relationship">
<td class="label">{$form.account_relationship.label}</td>
<td class="html-adjust">{$form.account_relationship.html}</td>
</tr>
<tr class="crm-contribution-form-block-account_relationship">
<td class="label">{$form.account_relationship.label}</td>
<td class="html-adjust">{$form.account_relationship.html}</td>
</tr>
<tr class="crm-contribution-form-block-financial_account_id">
<td class="label">{$form.financial_account_id.label}</td>
<td class="html-adjust">{$form.financial_account_id.html}</td>
</tr>
<td class="label">{$form.financial_account_id.label}</td>
<td class="html-adjust">{$form.financial_account_id.html}</td>
</tr>
</table>
</table>
{/if}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="botttom"}</div>
</div>
<script language="JavaScript" type="text/javascript">
{literal}
cj("#financial_account_id").change(function()
{
cj("#financial_account_id").change(function() {
{/literal}
relationID = "#account_relationship"
financialAccountID = "#financial_account_id"
callbackURL = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancialRelation'}"
relationID = "#account_relationship"
financialAccountID = "#financial_account_id"
callbackURL = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancialRelation'}"
{literal}
var financialId = cj("#financial_account_id").val();
var check = cj(relationID).val();
if( check == 'select' || financialId == 'select' ){
callbackURL = callbackURL+"&_value="+financialId;
cj.ajax({
url: callbackURL,
context: document.body,
success: function( data, textStatus ){
cj(relationID).html("");//clear old options
data = eval(data);//get json array
if ( data != null ) {
for (i = 0; i < data.length; i++) {
if( data[i].selected == 'Selected')
var idf = data[i].value;
cj(relationID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
if( idf != null)
cj(relationID).val(idf);
//cj("option:first", relationID).attr( "selected", "selected" );//select first option
}
});
if( financialId == 'select' ){
var financialId = cj("#financial_account_id").val();
var check = cj(relationID).val();
if (check == 'select' || financialId == 'select') {
callbackURL = callbackURL+"&_value=" + financialId;
cj.ajax({
url: callbackURL,
context: document.body,
success: function(data, textStatus) {
cj(relationID).html("");//clear old options
data = eval(data);//get json array
if (data != null) {
for (i = 0; i < data.length; i++) {
if (data[i].selected == 'Selected') {
var idf = data[i].value;
}
cj(relationID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
if (idf != null) {
cj(relationID).val(idf);
}
}
});
if (financialId == 'select') {
{/literal}
callbackURLs = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancial'}"
callbackURLs = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancial'}"
{literal}
callbackURLs = callbackURLs+"&_value=select";
cj.ajax({
url: callbackURLs,
context: document.body,
success: function( data, textStatus ){
cj(financialAccountID).html("");//clear old options
data = eval(data);//get json array
if ( data != null ) {
for (i = 0; i < data.length; i++) {
cj(financialAccountID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
}
});
}
callbackURLs = callbackURLs + "&_value=select";
cj.ajax({
url: callbackURLs,
context: document.body,
success: function(data, textStatus) {
cj(financialAccountID).html("");//clear old options
data = eval(data);//get json array
if (data != null) {
for (i = 0; i < data.length; i++) {
cj(financialAccountID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
}
});
}
}
});
{/literal}
{literal}
cj("#account_relationship").change(function()
{
{literal}
cj("#account_relationship").change(function() {
{/literal}
relationID = "#account_relationship"
financialAccountID = "#financial_account_id"
callbackURLs = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancial'}"
relationID = "#account_relationship"
financialAccountID = "#financial_account_id"
callbackURLs = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancial'}"
{literal}
var financialId = cj("#account_relationship").val();
var check = cj(financialAccountID).val();
if( check == 'select' || financialId == 'select' ){
callbackURLs = callbackURLs+"&_value="+financialId;
cj.ajax({
url: callbackURLs,
context: document.body,
success: function( data, textStatus ){
cj(financialAccountID).html("");//clear old options
data = eval(data);//get json array
if ( data != null ) {
for (i = 0; i < data.length; i++) {
cj(financialAccountID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
}
});
if( financialId == 'select' ){
var financialId = cj("#account_relationship").val();
var check = cj(financialAccountID).val();
if (check == 'select' || financialId == 'select') {
callbackURLs = callbackURLs+"&_value="+financialId;
cj.ajax({
url: callbackURLs,
context: document.body,
success: function(data, textStatus) {
cj(financialAccountID).html("");//clear old options
data = eval(data);//get json array
if (data != null) {
for (i = 0; i < data.length; i++) {
if (data[i].selected == 'Selected') {
var idf = data[i].value;
}
cj(financialAccountID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
if (idf != null) {
cj(financialAccountID).val(idf);
}
}
});
if (financialId == 'select') {
{/literal}
callbackURL = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancialRelation'}"
callbackURL = "{crmURL p='civicrm/ajax/rest' h=0 q='className=CRM_Financial_Page_AJAX&fnName=jqFinancialRelation'}"
{literal}
callbackURL = callbackURL+"&_value=select";
cj.ajax({
url: callbackURL,
context: document.body,
success: function( data, textStatus ){
cj(relationID).html("");//clear old options
data = eval(data);//get json array
if ( data != null ) {
for (i = 0; i < data.length; i++) {
if( data[i].selected == 'Selected')
var idf = data[i].value;
cj(relationID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
if( idf != null)
cj(relationID).val(idf);
//cj("option:first", relationID).attr( "selected", "selected" );//select first option
}
});
}
callbackURL = callbackURL+"&_value=select";
cj.ajax({
url: callbackURL,
context: document.body,
success: function(data, textStatus) {
cj(relationID).html("");//clear old options
data = eval(data);//get json array
if (data != null) {
for (i = 0; i < data.length; i++) {
if (data[i].selected == 'Selected') {
var idf = data[i].value;
}
cj(relationID).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null);
}
}
if (idf != null) {
cj(relationID).val(idf);
}
}
});
}
}
});
{/literal}
</script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment