diff --git a/CRM/Civicase/Service/CaseSalesOrderOpportunityCalculator.php b/CRM/Civicase/Service/CaseSalesOrderOpportunityCalculator.php
index 47c157b16..18859fc4a 100644
--- a/CRM/Civicase/Service/CaseSalesOrderOpportunityCalculator.php
+++ b/CRM/Civicase/Service/CaseSalesOrderOpportunityCalculator.php
@@ -172,7 +172,10 @@ private function calculateOpportunityFinancialAmount($contributions) {
private function getContributions($caseId) {
$contributions = Contribution::get(FALSE)
->addSelect('*', 'Opportunity_Details.Quotation')
- ->addWhere('Opportunity_Details.Case_Opportunity', '=', $caseId);
+ ->addWhere('Opportunity_Details.Case_Opportunity', '=', $caseId)
+ ->addJoin('CaseSalesOrder AS case_sales_order', 'INNER',
+ ['Opportunity_Details.Quotation', '=', 'case_sales_order.id']
+ );
if ($this->deletingContributionId !== NULL) {
$contributions->addWhere('id', '!=', $this->deletingContributionId);
diff --git a/js/contribution-entityref-field.js b/js/contribution-entityref-field.js
index 11731408e..7164866e8 100644
--- a/js/contribution-entityref-field.js
+++ b/js/contribution-entityref-field.js
@@ -24,6 +24,18 @@
if (field.value) {
$(`[name^=${field.name}_]`).val(field.value).trigger('change');
}
+
+ $(`[name^=${field.name}_]`).on('change', field, function (event) {
+ const f = event.data;
+
+ $(`[name^=${f.name}_]`)
+ .attr('placeholder', f.placeholder)
+ .attr('disabled', false)
+ .crmEntityRef({
+ entity: f.entity,
+ create: false
+ });
+ });
});
});
});
diff --git a/js/sales-order-contribution.js b/js/sales-order-contribution.js
index c423d2def..02c2245de 100644
--- a/js/sales-order-contribution.js
+++ b/js/sales-order-contribution.js
@@ -43,9 +43,13 @@
$(``).insertBefore('#source');
$(' #totalAmountORaddLineitem, #totalAmountORPriceSet, #price_set_id, #choose-manual').hide();
+ if ($('#customData')) {
+ CRM.$(`[name^=${caseCustomField}_]`).val(caseSalesOrder.case_id).trigger('change');
+ CRM.$(`[name^=${quotationCustomField}_]`).val(caseSalesOrder.id).trigger('change');
+ }
waitForElement($, '#customData', function ($, elem) {
- $(`[name^=${caseCustomField}_]`).val(caseSalesOrder.case_id).trigger('change');
- $(`[name^=${quotationCustomField}_]`).val(caseSalesOrder.id).trigger('change');
+ CRM.$(`[name^=${caseCustomField}_]`).val(caseSalesOrder.case_id).trigger('change');
+ CRM.$(`[name^=${quotationCustomField}_]`).val(caseSalesOrder.id).trigger('change');
});
}).finally(() => {
CRM.$.unblockUI();
diff --git a/templates/CRM/Civicase/Form/CaseSalesOrderContributionCreate.tpl b/templates/CRM/Civicase/Form/CaseSalesOrderContributionCreate.tpl
index d575b8bae..5bd651fa7 100644
--- a/templates/CRM/Civicase/Form/CaseSalesOrderContributionCreate.tpl
+++ b/templates/CRM/Civicase/Form/CaseSalesOrderContributionCreate.tpl
@@ -61,3 +61,12 @@
});
{/literal}
+
+{literal}
+
+
+{/literal}
\ No newline at end of file