diff --git a/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php b/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php index 0e2a9d1b5..dac5e0698 100644 --- a/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php +++ b/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php @@ -1,5 +1,6 @@ CRM_Core_BAO_CustomField::getCustomFieldID('Case_Opportunity', 'Opportunity_Details', TRUE), 'entity' => 'Case', 'placeholder' => '- Select Case/Opportunity -', ]; - $customFields[] = [ + $customFields['salesOrder'] = [ 'name' => CRM_Core_BAO_CustomField::getCustomFieldID('Quotation', 'Opportunity_Details', TRUE), 'entity' => 'CaseSalesOrder', 'placeholder' => '- Select Quotation -', @@ -36,9 +37,35 @@ public function run(CRM_Core_Form &$form, $formName) { 'scriptFile' => [E::LONG_NAME, 'js/contribution-entityref-field.js'], 'region' => 'page-header', ]); + + $this->populateDefaultFields($form, $customFields); \Civi::resources()->addVars('civicase', ['entityRefCustomFields' => $customFields]); } + /** + * Populates default fields. + * + * @param \CRM_Core_Form &$form + * Form Class object. + * @param array &$customFields + * Custom fields to set default value. + */ + private function populateDefaultFields(CRM_Core_Form &$form, array &$customFields) { + $caseId = CRM_Utils_Request::retrieve('caseId', 'Positive', $form); + if (!$caseId) { + return; + } + + $customFields['case']['value'] = $caseId; + $caseClient = CaseContact::get() + ->addSelect('contact_id') + ->addWhere('case_id', '=', $caseId) + ->execute() + ->first()['contact_id'] ?? NULL; + + $form->setDefaults(array_merge($form->_defaultValues, ['contact_id' => $caseClient])); + } + /** * Checks if the hook should run. * diff --git a/ang/civicase-features/invoices/directives/invoices-list.directive.html b/ang/civicase-features/invoices/directives/invoices-list.directive.html index c34641c6d..233d52c1c 100644 --- a/ang/civicase-features/invoices/directives/invoices-list.directive.html +++ b/ang/civicase-features/invoices/directives/invoices-list.directive.html @@ -1,5 +1,13 @@

{{ ts('Quotation Invoices') }}

+ + + add_circle + {{:: ts('Create Invoice') }} + +
diff --git a/ang/civicase-features/invoices/directives/invoices-list.directive.js b/ang/civicase-features/invoices/directives/invoices-list.directive.js index 41751d97a..4ce2265de 100644 --- a/ang/civicase-features/invoices/directives/invoices-list.directive.js +++ b/ang/civicase-features/invoices/directives/invoices-list.directive.js @@ -18,6 +18,14 @@ * @param {object} $window window object of the browser */ function invoicesListController ($scope, $location, $window) { + $scope.contributionURL = async () => { + let url = CRM.url('/contribute/add?reset=1&action=add&context=standalone'); + const caseId = $location.search().caseId; + if (caseId) { + url += `&caseId=${caseId}`; + } + $window.location.href = url; + }; } })(angular, CRM._); diff --git a/ang/civicase-features/quotations/directives/quotations-list.directive.js b/ang/civicase-features/quotations/directives/quotations-list.directive.js index d527176bc..1d414ff7a 100644 --- a/ang/civicase-features/quotations/directives/quotations-list.directive.js +++ b/ang/civicase-features/quotations/directives/quotations-list.directive.js @@ -31,7 +31,7 @@ * Redirects user to new quotation screen */ function redirectToQuotationCreationScreen () { - let url = '/civicrm/case-features/a#/quotations/new'; + let url = CRM.url('/case-features/a#/quotations/new'); const caseId = $location.search().caseId; if (caseId) { url += `?caseId=${caseId}`; diff --git a/js/contribution-entityref-field.js b/js/contribution-entityref-field.js index cd424a04a..8d0922353 100644 --- a/js/contribution-entityref-field.js +++ b/js/contribution-entityref-field.js @@ -8,7 +8,7 @@ }; $(document).one('crmLoad', function () { - const entityRefCustomFields = CRM.vars.civicase.entityRefCustomFields ?? []; + const entityRefCustomFields = Object.values(CRM.vars.civicase.entityRefCustomFields ?? {}); /* eslint-disable no-undef */ waitForElement($, '#customData', function ($, elem) { @@ -20,6 +20,10 @@ entity: field.entity, create: false }); + + if (field.value) { + $(`[name^=${field.name}_]`).val(field.value).trigger('change'); + } }); }); });