function InvokePaymentRequestHandler() { $(document).ready(function () { var $invoiceNumberField = $("#t3_invoicenumber"); var $amountField = $("#t3_amount"); var $submitButton = $(".submit-btn"); //ValidateInvoiceNumber(); // 2023-05-30: Since the GMS portal upgrade the invoice number validation is not implemented ValidateTotalAmount(); //ProcessTotals(); //function ProcessTotals() { // // 2023-05-30: As of CR1020 the invoice form has no line item grid. This function is deprecated. // // adds event listener to the invoice detail table // // to recalculate the total amount // $(".entity-grid.subgrid").on("loaded", function () { // var total = 0; // $("[data-attribute='t3_amount']").each(function (index, value) { // var amt = $(value).text().replace("$", "").replace(/,/g, ""); // total += parseFloat(amt); // }); // $amountField.val(TransformIntoCurrencyFormat(total)); // $amountField.siblings(".text-muted").hide(); // fixes a display styling issue // // disables next button if total if below 1 // if (total < 1) { // $submitButton.attr("disabled", 1); // } // else { // ValidateInvoiceAmount(total); // } // }); //} function ValidateInvoiceNumber() { // save original invoice number value on form load var originalInvoiceNumber = $invoiceNumberField.val(); // adds event listener to invoice number field change // validates for duplicate invoice numbers $invoiceNumberField.keyup(function () { var invoiceNumberEntered = $(this).val(); if (invoiceNumberEntered == originalInvoiceNumber) { return; } var data = { "Id": GetRequestId(), "InvoiceNumber": $(this).val() }; $.post("/_services/GMS/PaymentRequest/InvoiceNumber", data).done(function (response) { console.debug("dup invoice number? " + response); if (response === true) { if ($("#dupInvoiceWarning").length < 1) { // message doesn't already exist var errMessage = "

This invoice number has already been submitted by your organization. Please enter a different invoice number.

"; $invoiceNumberField.closest("td").append(); } $(".btn").prop("disabled", true); } else { $("#dupInvoiceWarning").remove(); $(".btn").prop("disabled", false); } }); }); } //function ValidateInvoiceAmount(amt) { // var paymentRequestId = $("#EntityFormView_EntityID").val(); // if (paymentRequestId == null || paymentRequestId.length < 1) { // paymentRequestId = $("#EntityFormControl_EntityFormView_EntityID").val(); // } // $.getJSON("/API/ConsultantRequestBalance/?id=" + GetRequestId()).done(function (response) { // if (response.Balance === 'undefined' || response.Balance < 0 || amt > parseFloat(response.Balance)) { // if ($("#invalidAmountWarning").length < 1) { // // invalid amount message doesn't already exist, add it // var errMessage = "

The amount is invalid. This may be due to an amount exceeding your available amount. Please review and try again.

"; // $amountField.closest("td").append(errMessage); // } // $submitButton.prop("disabled", true); // } // else { // $("#invalidAmountWarning").remove(); // $submitButton.prop("disabled", false); // } // }); //} function ValidateTotalAmount() { // on first load Validate(); // on subsequent field changes $amountField.on("keyup", Validate); function Validate() { var amount = parseFloat($amountField.val().replace("$", "").replace(/,/g, "")); if (isNaN(amount) || amount < 1) { $submitButton.attr("disabled", 1); } else { $.getJSON("/API/ConsultantRequestBalance/?id=" + GetRequestId()).done(function (response) { if (response.Balance === 'undefined' || response.Balance < 0 || amount > parseFloat(response.Balance)) { if ($("#invalidAmountWarning").length < 1) { // invalid amount message doesn't already exist, add it var errMessage = "

The amount is invalid. This may be due to an amount exceeding your available amount. Please review and try again.

"; $amountField.closest("td").append(errMessage); } $submitButton.prop("disabled", true); } else { $("#invalidAmountWarning").remove(); $submitButton.prop("disabled", false); } }); } } } function GetRequestId() { var urlParams = new URLSearchParams(window.location.search); var projectId = urlParams.get('refid'); return projectId; } }); }