Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMCL-589: Merge Dev Branch #190

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Financeextras/Hook/PageRun/ContributionPageTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function handle($page) {
* @return bool
*/
public static function shouldHandle($page) {
return $page instanceof CRM_Contribute_Page_Tab && $page->_action == CRM_Core_Action::BROWSE;
return $page instanceof CRM_Contribute_Page_Tab && $page->getVar('_action') == CRM_Core_Action::BROWSE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Financeextras/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function disable() {
}

public function upgrade_1000() {
$this->executeSqlFile('sql/auto_install.sql');
$this->executeSqlFile('sql/upgrade_1000.sql');
$this->executeCustomDataFile('xml/customFields_install.xml');

$manageSteps = [
Expand Down
11 changes: 10 additions & 1 deletion Civi/Financeextras/Hook/Container/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ public function register() {
\Civi\Financeextras\Service\CreditNoteInvoiceService::class,
[]
)
)->setAutowired(TRUE);
)->setAutowired(TRUE)->setPublic(TRUE);

$this->container->setDefinition('workflow.message.credit_note_invoice',
new Definition(
\Civi\Financeextras\WorkflowMessage\CreditNoteInvoice::class,
[]
)
)->setAutowired(TRUE)->setPublic(TRUE);

$this->container->setAlias('Civi\Financeextras\WorkflowMessage\CreditNoteInvoice', 'workflow.message.credit_note_invoice');
}

}
3 changes: 3 additions & 0 deletions js/modifyContributionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const totalChanged = new CustomEvent("totalChanged", {});
const recordPaymentAmount = document.querySelector("input[name=fe_record_payment_amount]");
$('#total_amount').on("change", function() {
recordPaymentAmount.value = Number($('#total_amount').val()).toFixed(2);
if ($('#total_amount').val() == 0 && $('#line-total').data('raw-total') > 0) {
return
}
recordPaymentAmount.dispatchEvent(totalChanged)
});

Expand Down
151 changes: 151 additions & 0 deletions sql/upgrade_1000.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
-- /*******************************************************
-- *
-- * Clean up the existing tables - this section generated from drop.tpl
-- *
-- *******************************************************/

SET FOREIGN_KEY_CHECKS=0;

DROP TABLE IF EXISTS `financeextras_credit_note_line`;
DROP TABLE IF EXISTS `financeextras_credit_note_allocation`;
DROP TABLE IF EXISTS `financeextras_credit_note`;
DROP TABLE IF EXISTS `financeextras_company`;
DROP TABLE IF EXISTS `financeextras_batch_owner_org`;
DROP TABLE IF EXISTS `financeextras_exchange_rate`;

SET FOREIGN_KEY_CHECKS=1;
-- /*******************************************************
-- *
-- * Create new tables
-- *
-- *******************************************************/

-- /*******************************************************
-- *
-- * financeextras_credit_note
-- *
-- * Stores credit note for contribution refund or allocations
-- *
-- *******************************************************/
CREATE TABLE `financeextras_credit_note` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique CreditNote ID',
`contact_id` int unsigned COMMENT 'FK to Contact',
`owner_organization` int unsigned NOT NULL COMMENT 'FK to Contact',
`cn_number` varchar(11),
`date` date COMMENT 'Credit Note date',
`status_id` int unsigned NOT NULL COMMENT 'One of the values of the financeextras_credit_note_status option group',
`reference` varchar(11),
`currency` varchar(3) DEFAULT NULL COMMENT '3 character string, value from config setting or input via user.',
`description` text NULL COMMENT 'Credit note description',
`comment` text NULL COMMENT 'Credit note comment',
`subtotal` decimal(20,2) NULL COMMENT 'Total of all the total price fields',
`sales_tax` decimal(20,2) NULL COMMENT 'Credit note sales tax total',
`total_credit` decimal(20,2) NULL COMMENT 'Total value of the credit note',
PRIMARY KEY (`id`),
CONSTRAINT FK_financeextras_credit_note_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_financeextras_credit_note_owner_organization FOREIGN KEY (`owner_organization`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * financeextras_credit_note_allocation
-- *
-- * Stores amounts of credit that have been allocated or “used” from a credit note.
-- *
-- *******************************************************/
CREATE TABLE `financeextras_credit_note_allocation` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique CreditNoteAllocation ID',
`credit_note_id` int unsigned COMMENT 'FK to CreditNote',
`contribution_id` int unsigned COMMENT 'FK to Contribution',
`type_id` int unsigned NULL DEFAULT NULL COMMENT 'One of the values of the financeextras_credit_note_allocation_type option group',
`currency` varchar(3) DEFAULT NULL COMMENT '3 character string, value from config setting or input via user.',
`reference` text,
`amount` decimal(20,2) NULL COMMENT 'Ammount allocated',
`date` date COMMENT 'Allocation date',
`is_reversed` tinyint NOT NULL DEFAULT 0 COMMENT 'Allocation has been deleted by user',
PRIMARY KEY (`id`),
CONSTRAINT FK_financeextras_credit_note_allocation_credit_note_id FOREIGN KEY (`credit_note_id`) REFERENCES `financeextras_credit_note`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_financeextras_credit_note_allocation_contribution_id FOREIGN KEY (`contribution_id`) REFERENCES `civicrm_contribution`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * financeextras_credit_note_line
-- *
-- * Credit note line items
-- *
-- *******************************************************/
CREATE TABLE `financeextras_credit_note_line` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique CreditNoteLine ID',
`credit_note_id` int unsigned COMMENT 'FK to CreditNote',
`financial_type_id` int unsigned COMMENT 'FK to CiviCRM Financial Type',
`description` text NULL COMMENT 'line item description',
`quantity` decimal(20, 4) COMMENT 'Quantity',
`unit_price` decimal(20,2) COMMENT 'Unit Price',
`tax_amount` decimal(20,2) COMMENT 'Tax amount for the line item',
`line_total` decimal(20,2) COMMENT 'Line Total',
PRIMARY KEY (`id`),
CONSTRAINT FK_financeextras_credit_note_line_credit_note_id FOREIGN KEY (`credit_note_id`) REFERENCES `financeextras_credit_note`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_financeextras_credit_note_line_financial_type_id FOREIGN KEY (`financial_type_id`) REFERENCES `civicrm_financial_type`(`id`) ON DELETE SET NULL
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * financeextras_company
-- *
-- * Holds the company (legal entity) information
-- *
-- *******************************************************/
CREATE TABLE `financeextras_company` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Company ID',
`contact_id` int unsigned COMMENT 'FK to Contact',
`invoice_template_id` int unsigned COMMENT 'FK to the message template.',
`invoice_prefix` varchar(11),
`next_invoice_number` varchar(11),
`creditnote_template_id` int unsigned COMMENT 'FK to the message template.',
`creditnote_prefix` varchar(11),
`next_creditnote_number` varchar(11),
PRIMARY KEY (`id`),
CONSTRAINT FK_financeextras_company_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_financeextras_company_invoice_template_id FOREIGN KEY (`invoice_template_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE SET NULL,
CONSTRAINT FK_financeextras_company_creditnote_template_id FOREIGN KEY (`creditnote_template_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE SET NULL
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * financeextras_batch_owner_org
-- *
-- * The financial batch owner organisations
-- *
-- *******************************************************/
CREATE TABLE `financeextras_batch_owner_org` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique BatchOwnerOrganisation ID',
`batch_id` int unsigned COMMENT 'FK to Batch.',
`owner_org_id` int unsigned COMMENT 'FK to Contact',
PRIMARY KEY (`id`),
CONSTRAINT FK_financeextras_batch_owner_org_batch_id FOREIGN KEY (`batch_id`) REFERENCES `civicrm_batch`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_financeextras_batch_owner_org_owner_org_id FOREIGN KEY (`owner_org_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;

-- /*******************************************************
-- *
-- * financeextras_exchange_rate
-- *
-- * Exchange Rate Entity
-- *
-- *******************************************************/
CREATE TABLE `financeextras_exchange_rate` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique ExchangeRate ID',
`exchange_date` date COMMENT 'Exchange rate date',
`base_currency` varchar(3) DEFAULT NULL COMMENT '3 character string, value from config setting or input via user.',
`conversion_currency` varchar(3) DEFAULT NULL COMMENT '3 character string, value from config setting or input via user.',
`base_to_conversion_rate` decimal(20,2) NULL COMMENT 'The number of the converted currency to the base currency.',
`conversion_to_base_rate` decimal(20,2) NULL COMMENT 'The number of the Base currency to the converted currency.',
PRIMARY KEY (`id`)
)
ENGINE=InnoDB;
12 changes: 9 additions & 3 deletions templates/CRM/Financeextras/Form/Contribute/CustomLineItem.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
CRM.$(function($) {
const submittedRows = $.parseJSON('{/literal}{$lineItemSubmitted}{literal}');
const action = '{/literal}{$action}{literal}';
const nonEmtyFinancialTypes = $('table#info select[id^="item_financial_type_id_"]').filter(function() {
return this.value;
});
isNotQuickConfig = '{/literal}{$pricesetFieldsCount}{literal}'
const isEmptyPriceSet = !$('#price_set_id').length || $('#price_set_id').val() === ''

Expand Down Expand Up @@ -42,8 +45,11 @@
$('#selectPriceSet').prepend( `<div id="lineItemSwitch" class="crm-hover-button">OR <a href="#">Switch back to using line items</a></div>`)
$('#lineItemSwitch').css('display', 'block').on('click', () => $('#price_set_id').val('').change())

if ((isEmptyPriceSet) && submittedRows.length <= 0) {
$('#add-items').click()
const hasValues = nonEmtyFinancialTypes.each(function() {
$(this).val(this.value).trigger('change');
}).length > 0;
if (!hasValues && isEmptyPriceSet && submittedRows.length <= 0) {
$('#add-items').click();
}
toggleLineItemOrPricesetFields(isEmptyPriceSet);

Expand All @@ -58,7 +64,7 @@
$('#totalAmountORPriceSet, #price_set_id').show();
}
});
}, 100);
}, 500);

const toggleLineItemOrPricesetFields = (show) => {
if (!show) {
Expand Down
Loading