Don't reset financial type every time product is edited
authorMatthew Wire <devel@mrwire.co.uk>
Tue, 10 Jul 2018 16:27:39 +0000 (17:27 +0100)
committerMatthew Wire <devel@mrwire.co.uk>
Wed, 11 Jul 2018 11:27:14 +0000 (12:27 +0100)
templates/CRM/Contribute/Form/ContributionPage/AddProduct.hlp
templates/CRM/Contribute/Form/ContributionPage/AddProduct.tpl

index c00ad8de84340a7671de80dd969fef5a6f618539..001d16591d2a621a22bd00c20a8bcb944d8337ec 100644 (file)
@@ -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}
+<br />{ts}The default Financial Type is configured when creating the "Premium" but it can be changed for each contribution page if required.{/ts}
 {/htxt}
index a97f0f6b8b40e490eb3ab0c0a0da069c030cbb66..ec8bfdb252fb04b51643242b5aa3325f5c0b53b0 100644 (file)
@@ -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 <a href='%1'>click here</a> 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"} <a name='resetfinancialtype' id="resetfinancialtype" style="display: none;">{ts}Reset to default for selected product{/ts}</a>
       {/if}
       </td>
     </tr>
@@ -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',
         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}
 </script>