From 3a9012f11d12bcaa07e77f0683d7ac436e90b76f Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Mon, 25 Sep 2023 15:11:58 +0100 Subject: [PATCH 1/4] BTHAB-206: Fix failing upgrader --- CRM/Civicase/Upgrader/Steps/Step0019.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CRM/Civicase/Upgrader/Steps/Step0019.php b/CRM/Civicase/Upgrader/Steps/Step0019.php index c89186996..14cfd30cf 100644 --- a/CRM/Civicase/Upgrader/Steps/Step0019.php +++ b/CRM/Civicase/Upgrader/Steps/Step0019.php @@ -18,8 +18,7 @@ class CRM_Civicase_Upgrader_Steps_Step0019 { */ public function apply() { try { - $upgrader = CRM_Civicase_Upgrader_Base::instance(); - $upgrader->executeSqlFile('sql/auto_install.sql'); + CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, CRM_Civicase_ExtensionUtil::path('sql/auto_install.sql')); (new QuotationTemplateManager())->create(); (new CaseTypeCategoryManager())->create(); From 2224d56e56fef16945aff47c394fb247f95aec7f Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Mon, 25 Sep 2023 15:13:16 +0100 Subject: [PATCH 2/4] BTHAB-206: Set payment and invoice status for new sales order --- CRM/Civicase/Service/CaseSalesOrderInvoice.php | 2 +- .../Action/CaseSalesOrder/SalesOrderSaveAction.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CRM/Civicase/Service/CaseSalesOrderInvoice.php b/CRM/Civicase/Service/CaseSalesOrderInvoice.php index 57dfa46a2..426b2352a 100644 --- a/CRM/Civicase/Service/CaseSalesOrderInvoice.php +++ b/CRM/Civicase/Service/CaseSalesOrderInvoice.php @@ -13,7 +13,7 @@ class CRM_Civicase_Service_CaseSalesOrderInvoice { /** - * CreditNoteInvoiceService constructor. + * CaseSalesOrderInvoice constructor. * * @param \CRM_Civicase_WorkflowMessage_SalesOrderInvoice $template * Workflow template. diff --git a/Civi/Api4/Action/CaseSalesOrder/SalesOrderSaveAction.php b/Civi/Api4/Action/CaseSalesOrder/SalesOrderSaveAction.php index c5918c126..9529b80e8 100644 --- a/Civi/Api4/Action/CaseSalesOrder/SalesOrderSaveAction.php +++ b/Civi/Api4/Action/CaseSalesOrder/SalesOrderSaveAction.php @@ -26,6 +26,7 @@ public function _run(Result $result) { // phpcs:ignore $this->matchExisting($record); if (empty($record['id'])) { $this->fillDefaults($record); + $this->fillMandatoryFields($record); } } $this->validateValues(); @@ -129,4 +130,17 @@ private function updateOpportunityDetails($salesOrderId): void { $caseSaleOrderContributionService->updateOpportunityFinancialDetails(); } + /** + * Fill mandatory fields. + * + * @param array $params + * Single Sales Order Record. + */ + protected function fillMandatoryFields(&$params) { + $saleOrderId = $params['id'] ?? NULL; + $caseSaleOrderContributionService = new \CRM_Civicase_Service_CaseSalesOrderContributionCalculator($saleOrderId); + $params['payment_status_id'] = $caseSaleOrderContributionService->calculateInvoicingStatus(); + $params['invoicing_status_id'] = $caseSaleOrderContributionService->calculatePaymentStatus(); + } + } From b780a5897fe97114f787de6d94d5d36d583e5f85 Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Mon, 25 Sep 2023 15:22:35 +0100 Subject: [PATCH 3/4] BTHAB-206: Add searchtask to send bulk invoice with quotation --- .../AttachQuotationToInvoiceMail.php | 12 +++++---- .../Hook/alterMailParams/AttachQuotation.php | 6 ++++- civicase.php | 25 +++++++++++++++++++ .../Form/Contribute/AttachQuotation.tpl | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php b/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php index 9c36c431b..ab64014c2 100644 --- a/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php +++ b/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php @@ -17,7 +17,7 @@ class CRM_Civicase_Hook_BuildForm_AttachQuotationToInvoiceMail { * Form Name. */ public function run(CRM_Core_Form &$form, $formName) { - if (!$this->shouldRun($formName)) { + if (!$this->shouldRun($form, $formName)) { return; } @@ -31,18 +31,20 @@ public function run(CRM_Core_Form &$form, $formName) { /** * Determines if the hook will run. * + * @param CRM_Core_Form $form + * Form Class object. * @param string $formName * Form Name. * * @return bool * TRUE if the hook should run, FALSE otherwise. */ - private function shouldRun($formName) { + private function shouldRun($form, $formName) { if ($formName != 'CRM_Contribute_Form_Task_Invoice') { return FALSE; } - $contributionId = CRM_Utils_Request::retrieve('id', 'Positive'); + $contributionId = CRM_Utils_Request::retrieve('id', 'Positive', $form, FALSE); if (!$contributionId) { return FALSE; } @@ -50,12 +52,12 @@ private function shouldRun($formName) { $salesOrder = Contribution::get() ->addSelect('Opportunity_Details.Quotation') ->addWhere('Opportunity_Details.Quotation', 'IS NOT EMPTY') - ->addWhere('id', '=', $contributionId) + ->addWhere('id', 'IN', explode(',', $contributionId)) ->addChain('salesOrder', CaseSalesOrder::get() ->addWhere('id', '=', '$Opportunity_Details.Quotation') ) ->execute() - ->first()['salesOrder']; + ->getArrayCopy(); return !empty($salesOrder); } diff --git a/CRM/Civicase/Hook/alterMailParams/AttachQuotation.php b/CRM/Civicase/Hook/alterMailParams/AttachQuotation.php index dcf2d8ecf..e368a33ef 100644 --- a/CRM/Civicase/Hook/alterMailParams/AttachQuotation.php +++ b/CRM/Civicase/Hook/alterMailParams/AttachQuotation.php @@ -25,7 +25,11 @@ public function run(array &$params, $context) { $rendered = $this->getContributionQuotationInvoice($params['tokenContext']['contributionId']); - $params['attachments'][] = CRM_Utils_Mail::appendPDF('quotation_invoice.pdf', $rendered['html'], $rendered['format']); + $attachment = CRM_Utils_Mail::appendPDF('quotation_invoice.pdf', $rendered['html'], $rendered['format']); + + if ($attachment) { + $params['attachments'][] = $attachment; + } } /** diff --git a/civicase.php b/civicase.php index a2eaae277..02e85ced2 100644 --- a/civicase.php +++ b/civicase.php @@ -224,6 +224,11 @@ function civicase_civicrm_buildForm($formName, &$form) { if (!empty($_REQUEST['civicase_reload'])) { $form->civicase_reload = json_decode($_REQUEST['civicase_reload'], TRUE); } + + $isSearchKit = CRM_Utils_Request::retrieve('sk', 'Positive'); + if ($formName == 'CRM_Contribute_Form_Task_Invoice' && $isSearchKit) { + $form->add('hidden', 'mail_task_from_sk', $isSearchKit); + } } /** @@ -296,6 +301,10 @@ function civicase_civicrm_postProcess($formName, &$form) { $api = civicrm_api3('Case', 'getdetails', ['check_permissions' => 1] + $form->civicase_reload); $form->ajaxResponse['civicase_reload'] = $api['values']; } + + if ($formName == 'CRM_Contribute_Form_Task_Invoice' && !empty($form->getVar('_submitValues')['mail_task_from_sk'])) { + CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']); + } } /** @@ -572,4 +581,20 @@ function civicase_civicrm_searchKitTasks(array &$tasks, bool $checkPermissions, ]; $tasks['CaseSalesOrder'] = $actions; + +} + +/** + * Implements hook_civicrm_searchTasks(). + */ +function civicase_civicrm_searchTasks(string $objectName, array &$tasks) { + if ($objectName === 'contribution') { + $tasks['bulk_invoice'] = [ + 'title' => ts('Send Invoice by email'), + 'class' => 'CRM_Contribute_Form_Task_Invoice', + 'icon' => 'fa-paper-plane-o', + 'url' => 'civicrm/contribute/task?reset=1&task_item=invoice&sk=1', + 'key' => 'invoice', + ]; + } } diff --git a/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl b/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl index 82a949091..76c82d7b8 100644 --- a/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl +++ b/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl @@ -8,7 +8,7 @@ {literal} {/literal} From e4b5740accb080e9ceaaa9f7ce7162c237a756cf Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Tue, 26 Sep 2023 07:30:14 +0100 Subject: [PATCH 4/4] BTHAB-206: Hide PDF selector and suport invoicehelper customization --- .../Hook/BuildForm/AttachQuotationToInvoiceMail.php | 5 ++++- civicase.php | 7 +++++++ js/invoice-bulk-mail.js | 5 +++++ managed/SavedSearch_Civicase_Quotations.mgd.php | 2 +- templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl | 6 ++++++ 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 js/invoice-bulk-mail.js diff --git a/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php b/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php index ab64014c2..ea9dd080a 100644 --- a/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php +++ b/CRM/Civicase/Hook/BuildForm/AttachQuotationToInvoiceMail.php @@ -40,7 +40,10 @@ public function run(CRM_Core_Form &$form, $formName) { * TRUE if the hook should run, FALSE otherwise. */ private function shouldRun($form, $formName) { - if ($formName != 'CRM_Contribute_Form_Task_Invoice') { + if (!in_array($formName, [ + 'CRM_Contribute_Form_Task_Invoice', + 'CRM_Invoicehelper_Contribute_Form_Task_Invoice', + ])) { return FALSE; } diff --git a/civicase.php b/civicase.php index 02e85ced2..7d15c0fd1 100644 --- a/civicase.php +++ b/civicase.php @@ -228,6 +228,13 @@ function civicase_civicrm_buildForm($formName, &$form) { $isSearchKit = CRM_Utils_Request::retrieve('sk', 'Positive'); if ($formName == 'CRM_Contribute_Form_Task_Invoice' && $isSearchKit) { $form->add('hidden', 'mail_task_from_sk', $isSearchKit); + CRM_Core_Resources::singleton()->addScriptFile( + CRM_Civicase_ExtensionUtil::LONG_NAME, + 'js/invoice-bulk-mail.js', + ); + $form->setTitle(ts('Email Contribution Invoice')); + $ids = CRM_Utils_Request::retrieve('id', 'Positive', $form, FALSE); + $form->assign('totalSelectedContributions', count(explode(',', $ids))); } } diff --git a/js/invoice-bulk-mail.js b/js/invoice-bulk-mail.js new file mode 100644 index 000000000..d63bb1bac --- /dev/null +++ b/js/invoice-bulk-mail.js @@ -0,0 +1,5 @@ +(function ($, _) { + $('input[value=email_invoice]').prop('checked', true).click(); + $('div.help').hide(); + $('input[name=output]').parent().parent().hide(); +})(CRM.$, CRM._); diff --git a/managed/SavedSearch_Civicase_Quotations.mgd.php b/managed/SavedSearch_Civicase_Quotations.mgd.php index df80a6b6c..1000f31fc 100644 --- a/managed/SavedSearch_Civicase_Quotations.mgd.php +++ b/managed/SavedSearch_Civicase_Quotations.mgd.php @@ -584,7 +584,7 @@ 'icon' => 'fa-paper-plane-o', 'text' => 'Send By Email', 'style' => 'default', - 'path' => 'civicrm/contribute/invoice/email/?reset=1&id=[id]&select=email', + 'path' => 'civicrm/contribute/invoice/email/?reset=1&id=[id]&select=email&cid=[contact_id]', 'condition' => [], ], ], diff --git a/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl b/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl index 76c82d7b8..b84493606 100644 --- a/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl +++ b/templates/CRM/Civicase/Form/Contribute/AttachQuotation.tpl @@ -4,10 +4,16 @@ {$form.attach_quote.html} Yes +
{literal}