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 @@