diff --git a/CRM/Civicase/Hook/Post/CreateSalesOrderContribution.php b/CRM/Civicase/Hook/Post/CreateSalesOrderContribution.php index 29944571a..27907a008 100644 --- a/CRM/Civicase/Hook/Post/CreateSalesOrderContribution.php +++ b/CRM/Civicase/Hook/Post/CreateSalesOrderContribution.php @@ -42,11 +42,17 @@ public function run($op, $objectName, $objectId, &$objectRef) { $salesOrderStatusId = CRM_Utils_Request::retrieve('sales_order_status_id', 'Integer'); if (empty($salesOrderStatusId)) { - $salesOrder = $salesOrder['status_id']; + $salesOrderStatusId = $salesOrder['status_id']; } $transaction = CRM_Core_Transaction::create(); try { + \Civi\Api4\Contribution::update(FALSE) + ->addWhere('id', '=', $objectId) + ->addValue('Opportunity_Details.Case_Opportunity', $salesOrder['case_id'] ?? NULL) + ->addValue('Opportunity_Details.Quotation', $salesOrderId) + ->execute(); + $caseSaleOrderContributionService = new CRM_Civicase_Service_CaseSalesOrderContributionCalculator($salesOrderId); $paymentStatusID = $caseSaleOrderContributionService->calculatePaymentStatus(); $invoicingStatusID = $caseSaleOrderContributionService->calculateInvoicingStatus(); diff --git a/js/sales-order-contribution.js b/js/sales-order-contribution.js index 02c2245de..c54458166 100644 --- a/js/sales-order-contribution.js +++ b/js/sales-order-contribution.js @@ -43,11 +43,11 @@ $(``).insertBefore('#source'); $(' #totalAmountORaddLineitem, #totalAmountORPriceSet, #price_set_id, #choose-manual').hide(); - if ($('#customData')) { + if ($('#customData_Contribution')) { CRM.$(`[name^=${caseCustomField}_]`).val(caseSalesOrder.case_id).trigger('change'); CRM.$(`[name^=${quotationCustomField}_]`).val(caseSalesOrder.id).trigger('change'); } - waitForElement($, '#customData', function ($, elem) { + waitForElement($, '#customData_Contribution', function ($, elem) { CRM.$(`[name^=${caseCustomField}_]`).val(caseSalesOrder.case_id).trigger('change'); CRM.$(`[name^=${quotationCustomField}_]`).val(caseSalesOrder.id).trigger('change'); });