From 9166000fde5ba81ed24efdc339a0b9f234f495a7 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Tue, 10 Jul 2018 17:27:39 +0100 Subject: [PATCH] Don't reset financial type every time product is edited --- .../Form/ContributionPage/AddProduct.hlp | 1 + .../Form/ContributionPage/AddProduct.tpl | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/templates/CRM/Contribute/Form/ContributionPage/AddProduct.hlp b/templates/CRM/Contribute/Form/ContributionPage/AddProduct.hlp index c00ad8de84..001d16591d 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/AddProduct.hlp +++ b/templates/CRM/Contribute/Form/ContributionPage/AddProduct.hlp @@ -25,4 +25,5 @@ *} {htxt id="id-financial_type-product"} {ts}Select a Financial Type that has both a 'Cost of Sales Premiums Account' and a 'Premiums Inventory Account' if you want to generate accounting transactions to track the cost of premiums used.{/ts} +
{ts}The default Financial Type is configured when creating the "Premium" but it can be changed for each contribution page if required.{/ts} {/htxt} diff --git a/templates/CRM/Contribute/Form/ContributionPage/AddProduct.tpl b/templates/CRM/Contribute/Form/ContributionPage/AddProduct.tpl index a97f0f6b8b..ec8bfdb252 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/AddProduct.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/AddProduct.tpl @@ -53,7 +53,7 @@ {capture assign=ftUrl}{crmURL p='civicrm/admin/financial/financialType' q="reset=1"}{/capture} {ts 1=$ftUrl}There are no financial types configured with linked 'Cost of Sales Premiums' and 'Premiums Inventory Account' accounts. If you want to generate accounting transactions which track the cost of premiums used click here to configure financial types and accounts.{/ts} {else} - {$form.financial_type_id.html}{help id="id-financial_type-product"} + {$form.financial_type_id.html} {help id="id-financial_type-product"} {/if} @@ -78,7 +78,7 @@ CRM.$(function($) { - function getFinancialType() { + function getFinancialType(set) { var callbackURL = CRM.url('civicrm/ajax/rest', { className: 'CRM_Financial_Page_AJAX', fnName: 'jqFinancialType', @@ -88,17 +88,24 @@ url: callbackURL, success: function( data, textStatus ){ data = eval(data);//get json array - if ( data != null ) { + if ((data != null) && (set)) { $("#financial_type_id").val(data); } + if (data == $("#financial_type_id").val()) { + $("#resetfinancialtype").hide(); + } + else { + $("#resetfinancialtype").show(); + } } }); - } - getFinancialType(); - $("#product_id").change(getFinancialType); + getFinancialType(false); + $("#product_id").change(function() { getFinancialType(true); }); + $("#resetfinancialtype").click(function() { getFinancialType(true); }); + $("#financial_type_id").change(function() { getFinancialType(false); }); }); {/literal} -- 2.25.1