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

BTHAMM-15: Add custom delay before updating line item total #1016

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
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
24 changes: 15 additions & 9 deletions js/sales-order-contribution.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
(function ($, _) {
const waitForElement = function ($, elementPath, callBack) {
(new window.MutationObserver(function () {
callBack($, $(elementPath));
})).observe(document.querySelector(elementPath), {
attributes: true
});
window.setTimeout(function () {
if ($(elementPath).length) {
callBack($, $(elementPath));
} else {
window.waitForElement($, elementPath, callBack);
}
}, 500);
};

$(document).one('crmLoad', function () {
$(document).one('crmLoad', async function () {
const params = CRM.vars['uk.co.compucorp.civicase'];
const salesOrderId = params.sales_order;
const salesOrderStatusId = params.sales_order_status_id;
Expand All @@ -29,6 +31,9 @@
}];

if (Array.isArray(lineItems)) {
CRM.$.blockUI();
CRM.$('form#Contribution').css('visibility', 'hidden');
await new Promise(resolve => setTimeout(resolve, 2000));
CRM.api4(apiRequest).then(function (batch) {
const caseSalesOrder = batch.caseSalesOrders[0];

Expand All @@ -37,7 +42,6 @@
});

$('#total_amount').val(0);
$('#lineitem-add-block').show().removeClass('hiddenElement');
$('#contribution_status_id').val(batch.optionValues[0].value);
$('#source').val(`Quotation ${caseSalesOrder.id}`).trigger('change');
$('#contact_id').select2('val', caseSalesOrder.client_id).trigger('change');
Expand All @@ -52,6 +56,9 @@
$(`[name^=${caseCustomField}_]`).val(caseSalesOrder.case_id).trigger('change');
$(`[name^=${quotationCustomField}_]`).val(caseSalesOrder.id).trigger('change');
});
}).finally(() => {
CRM.$.unblockUI();
CRM.$('form#Contribution').css('visibility', 'visible');
});
}

Expand All @@ -73,10 +80,9 @@

const total = quantity * parseFloat(unitPrice);

$('input[id^="item_unit_price"]', row).val(unitPrice);
$('input[id^="item_line_total"]', row).val(CRM.formatMoney(total, true));

$('input[id^="item_tax_amount"]', row).val(taxAmount);
$('input[id^="item_unit_price"]', row).val(unitPrice).trigger('change');

count++;
}
Expand Down
Loading