' +
'
' +
'
' +
'
' +
'' +
'' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'';
if (row.accountId != 0) {
html += '' +
'' +
'';
}
else {
html += '' +
'' +
'';
}
html += '
' +
'
' +
'
' +
'' +
'' + row.availQty + '' +
'
' +
'
' +
'
' +
'
';
$(".item-row:last").after(html);
var element = $(".item-addedrow:last");
if (IsSplitItem == true) {
element.addClass('SplitItem');
}
InvoiceItem.Instance().loadTaxGroupAutoComplete(element);
if (row.IsMultipleUOMs && $(".hdn_invoicetypeid").val() == "1") {
let MultipleUOMs = row.MultipleUoms;
let html = '
';
for (var i = 0; i < MultipleUOMs.length; i++) {
html += '
';
}
element.find(".ddl_MultipleUOMs").html(html);
element.find("#div_MultipleUOMs").removeClass("hidden");
InvoiceItem.Instance().UOMs.push({
ItemId: row.itemId,
MultipleUOMs: MultipleUOMs
});
let SelectedUOM = Number(element.find(".hf_AlternateUnitId").val());
let DefaultSize = Number(element.find(".hf_DefaultSize").val());
if (SelectedUOM != 0) {
element.find(".ddl_MultipleUOMs").val(SelectedUOM);
let Qty = Number(element.find(".prodQuantity").val());
let NewQty = Qty / DefaultSize;
element.find(".prodQuantity").val(NewQty);
}
}
var txtTaxGroup = element.find(".prodTax");
var hfProdTax = element.find(".hfProdTax");
var hfAccount = element.find(".hf_Account");
var txtAccount = element.find(".txt_Account");
hfAccount.val(row.accountId);
hfProdTax.val(row.taxGroupId);
txtTaxGroup.append(new Option(row.taxGroupName, row.taxGroupId, true));
txtAccount.append(new Option(row.accountName, row.accountId, true));
InvoiceItem.instance.itemsAutoComplete(element);
InvoiceItem.instance.itemChange(element, element.find(".prodName").val(), element.find(".selectedItemId"));
$('.inv_txtaddldiscount').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
if (element.find(".selectedItemId").val() == "0") {
Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Please Select Item");
element.find('.inv_txtaddldiscount').val(0);
}
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
let val = event.originalEvent["clipboardData"].getData('text');
if (!numberRegex.test(val)) {
event.preventDefault();
return false;
}
});
$('.prodQuantity').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
if (element.find(".selectedItemId").val() == "0") {
Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Please Select Item");
element.find(".prodQuantity").val(0);
}
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
let val = event.originalEvent["clipboardData"].getData('text');
if (!numberRegex.test(val)) {
event.preventDefault();
return false;
}
});
$('.prodPrice').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
if (element.find(".selectedItemId").val() == "0") {
Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Please Select Item");
element.find('.prodPrice').val(0);
}
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
let val = event.originalEvent["clipboardData"].getData('text');
if (!numberRegex.test(val)) {
event.preventDefault();
return false;
}
});
element.find(".btnInvoice_DiscType option[value='" + activeDiscText + "']").prop("selected", true);
element.find(".prodPrice,.prodQuantity,.inv_txtaddldiscount").focusin(function () {
if (element.find($(".prodName")).val() != null || element.find($(".ItemName")).val() != null) {
$(".div_MoreDetails").addClass("hidden");
if (!element.parents(".item-row").hasClass('SplitItem'))
element.find(".div_MoreDetails").removeClass("hidden");
}
});
element.find(".prodName").focusin(function () {
$(".divMoreDetails").addClass("hidden");
});
if (row.description != null && row.description != '' && row.description != 'null') {
element.find('#txt_Description').val(row.description);
element.find('#txt_Description').parent(".Desc").addClass("floating-label-form-group-with-value");
}
InvoiceItem.Instance().bind(element, row.inventoryTypeId);
element.find("#inv_txtdiscount").change(function () {
if (!element.hasClass('SplitItem')) {
if (element.find(".btnInvoice_DiscType").val() == "%") {
if (Number(element.find("#inv_txtdiscount").val()) > 100) {
element.find("#inv_txtdiscount").val("100");
}
}
}
});
if (row.TotalRowAmount != 0) {
if ($(".hdn_invoicetypeid").val() == "2") {
element.find(".hfRowTotalwithAdjustment").val();
element.find(".hfRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(row.TotalRowAmount), 2));
if (element.hasClass('SplitItem'))
element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalRowAmount, 2));
}
else {
element.find('.prodTotalPrice').text('');
element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalRowAmount, 2));
}
}
if (row.TotalDiscount != 0 && row.TotalDiscount != undefined)
element.find('#inv_txtdiscount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalDiscount, 2));
if (row.invoiceItemId != "0" && ($(".hdn_invoicetypeid").val() == "2")) {
var x = element.find('.hfRowTotalwithAdjustment');
element.find('.AdjustmentRow').click(function () {
InvoiceItem.Instance().editInvItemTaxAllocs(row.invoiceItemId, row.taxGroupId, row.itemId, row.orderItemId, element);
});
}
if (row.IsFoc == true) {
element.find('.delete').addClass('hidden');
element.find('.prodQuantity').prop('readonly', 'readonly');
element.find('.prodPrice').prop('readonly', 'readonly');
element.find("#inv_txtdiscount").prop('readonly', 'readonly');
element.find(".btnInvoice_DiscType").prop('disabled', true);
element.find('.prodQuantity').css('cursor', 'not-allowed');
element.find('.prodPrice').css('cursor', 'not-allowed');
element.find("#inv_txtdiscount").css('cursor', 'not-allowed');
}
}
else {
var element = $(".discount-addedrow:last");
if (row.inventoryTypeId == 5) {
element = $(".netdiscount-addedrow:last");
InvoiceItem.Instance().adddiscountrow(row, row.itemName, row.itemId, true);
}
if (row.inventoryTypeId == 6) {
InvoiceItem.Instance().adddiscountrow(row, row.itemName, row.itemId, false);
}
if (row.inventoryTypeId == 7) {
InvoiceItem.Instance().addExpenseRow(row, row.itemName, row.itemId, true);
}
}
}
loadTaxGroupAutoComplete(element) {
var txtTaxGroup = element.find(".prodTax");
var hfProdTax = element.find(".hfProdTax");
var hfAccount = element.find(".hf_Account");
var txtAccount = element.find(".txt_Account");
var accid = element.find(".hf_Account").val();
var taxgrpid = element.find(".hfProdTax").val();
var taxgrptext = element.find(".txtProdTax").val();
var acctext = element.find(".txt_AccountName").val();
var applytype = "Sales";
AutoCompleteHelper.getHelper().Create("#txt_prodTax_" + this.rowIndex, hfProdTax, _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
if (hfProdTax.val() != '')
InvoiceItem.Instance().update_tax(element, hfProdTax.val());
});
var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete';
const selectId = `#txt_Account_${this.rowIndex}`;
AutoCompleteHelper.getHelper().Create(selectId, hfAccount, url, function (response) {
$(selectId).off('select2:open').on('select2:open', (e) => {
const dropdownEl = $($(e.currentTarget).data('select2').$dropdown);
dropdownEl.addClass('select2-account-container');
});
});
}
update_total() {
var totalAmount = 0;
var totalDiscountAmount = 0;
var totalNonDiscountedAmount = 0;
var totalTaxAmount = 0;
var totalTaxAdjustment = 0;
var totalAsseableAdjustment = 0;
var totalQty = 0;
var totalDiscountPercent = 0;
var totalDiscountValue = 0;
var totalAddlDiscountPercent = 0;
var totalAddlDiscountValue = 0;
var totalExpensePercent = 0;
var totalExpenseValue = 0;
var addexpenserow_total = 0;
$('.expense-row-total').each(function (i) {
var expense_row_total = Number($(this).html());
addexpenserow_total += expense_row_total;
});
var ConsumedWalletValue = 0;
var totalTaxPercent = 0;
var totalTaxValue = 0;
var totalCreditNote = 0;
var adddiscountrow_total = 0;
var netadddiscountrow_total = ConsumedWalletValue;
$('.discount-row-total').each(function (i) {
var discount_row_total = Number($(this).html());
adddiscountrow_total += discount_row_total;
});
$('.netdiscount-row-total').each(function (i) {
var discount_row_total = Number($(this).html());
netadddiscountrow_total += discount_row_total;
});
var itemdiscount_total = 0;
var totalLineAmount_total = 0;
$('.hfRowTotal').each(function (i) {
var element = $(this).parents(".item-row");
if (!element.hasClass('SplitItem')) {
var totalLineAmount = Number($(this).val());
if (!isNaN(totalLineAmount))
totalLineAmount_total += Number(totalLineAmount);
var discountPercent = 0;
var discountValue = 0;
var quantity = Number(element.find(".prodQuantity").val());
var unitPrice = Number(element.find(".prodPrice").val());
var exciseAmount = Number(element.find(".exciseAmount").val());
if (isNaN(exciseAmount))
exciseAmount = 0;
var nonexciseAmount = totalLineAmount - exciseAmount;
if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
discountValue = Number(element.find('.inv_txtaddldiscount').val());
}
else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
discountPercent = Number(element.find('.inv_txtaddldiscount').val());
}
else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Mul') {
if (element.find('#hfProdDiscountList').val() != '' || element.find('#hfProdDiscountApplyTypes').val() != '') {
var discountsArray = element.find('#hfProdDiscountList').val().toString().split(',');
var applyTypes = element.find('#hfProdDiscountApplyTypes').val().toString().split(',');
var price = Number(unitPrice) * Number(quantity);
var currentAmount = Number(unitPrice) * Number(quantity);
$.each(discountsArray, function (j) {
var percent = discountsArray[j];
var applyType = applyTypes[j];
var discount = 0;
if (applyType == 'NET' || applyType == '1') {
discount = Number(price) * Number(percent) / 100;
currentAmount -= Number(discount);
}
else {
discount = Number(currentAmount) * Number(percent) / 100;
currentAmount -= Number(discount);
}
discountValue += Number(discount);
});
element.find('.inv_txtaddldiscount').val(discountValue);
}
else {
discountValue = Number(element.find('.inv_txtaddldiscount').val());
}
}
if (!isNaN(discountPercent))
totalDiscountPercent += Number(discountPercent);
if (!isNaN(discountValue))
totalAddlDiscountValue += Number(discountValue);
var discountAmount = 0;
discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
+ (Number(quantity) * Number(discountValue));
if ($(".hdn_invoicetypeid").val() == "1" && (element.find(".hf_IsManualUOM").val() == "true" || element.find(".hf_IsMultipleUOM").val() == "true")) {
let ConversionQuantity = Number(element.find(".hf_ConversionQuantity").val());
if (ConversionQuantity > 0)
discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
+ (Number(ConversionQuantity) * Number(discountValue));
}
discountAmount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discountAmount, 2));
itemdiscount_total += discountAmount;
var discountedAmount = Number(totalLineAmount) - Number(discountAmount);
totalDiscountAmount += Number(discountAmount);
element.find(".hfDiscountedAmount").val(discountAmount);
let invoiceid = $(".hdn_invoiceid").val();
if (invoiceid == undefined || invoiceid == "null")
invoiceid = 0;
if (($(".hdn_invoicetypeid").val() == "2") && invoiceid != 0) {
element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2));
element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
}
else
element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
}
});
if (InvoiceItem.Instance().SplitedInvoiceItemList.length > 0) {
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
var totalline_Amount = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
var discountAmount = 0;
var nonexciseAmount = totalline_Amount - Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount);
discountAmount = (Number(nonexciseAmount) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent) / 100)
+ (Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue));
discountAmount = Number(discountAmount);
totalLineAmount_total += Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
itemdiscount_total += discountAmount;
totalDiscountAmount += discountAmount;
}
}
var overalldiscountpercent = 0;
if (adddiscountrow_total != 0) {
overalldiscountpercent = (100 * Number(adddiscountrow_total)) / Number(totalLineAmount_total);
overalldiscountpercent = Number(overalldiscountpercent);
$("#hfOverallDiscountPercent").val(overalldiscountpercent);
}
var taxAmounts = [];
$('.hfRowTotal').each(function (i) {
var element = $(this).parents(".item-row");
if (!element.hasClass('SplitItem')) {
var totalLineAmount = Number($(this).val());
var quantity = element.find(".prodQuantity").val();
var UnitPrice = element.find(".prodPrice").val();
var Discount = element.find("#inv_txtdiscount").val();
var DiscountType = element.find(".btn_inv_DiscType").val();
discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
var assesableAmount = totalLineAmount - discountAmount;
assesableAmount = Number(assesableAmount);
if (element.find(".hf_IsMultipleUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
let ItemId = Number(element.find(".selectedItemId").val());
let SelectedUnitId = Number(element.find(".hf_AlternateUnitId").val());
if (SelectedUnitId == 0 || SelectedUnitId == 1) {
SelectedUnitId = Number(element.find(".ddl_MultipleUOMs").val());
}
if (SelectedUnitId != 0 && SelectedUnitId != 1) {
let Uom = InvoiceItem.Instance().UOMs.find(x => x.ItemId == ItemId);
let SelectedUOM = Uom.MultipleUOMs.find(x => x.SchemaDetailId == SelectedUnitId);
let DefaultSize = SelectedUOM.DefaultSize;
let AlternateSize = SelectedUOM.AlternateSize;
quantity = Number(element.find(".prodQuantity").val()) * (AlternateSize / DefaultSize);
totalLineAmount = Number(assesableAmount) * (AlternateSize / DefaultSize);
element.find(".prodTotalPrice").text(totalLineAmount);
element.find(".hfRowTotalwithAdjustment").val(totalLineAmount);
let Conversion = SelectedUOM.DefaultSize + " " + SelectedUOM.DefaultUnitName + " = " + SelectedUOM.AlternateSize + " " + SelectedUOM.AlternateUnitName;
element.find(".ItemConversion").text(Conversion);
element.find(".SelectedUOMName").text('(' + SelectedUOM.DefaultUnitName + ')');
let UOMCalc = UnitPrice + ' X ' + quantity + ' ( ' + SelectedUOM.AlternateUnitName + ' )';
if (Discount > 0) {
if (DiscountType == 'Val') {
UOMCalc = '(' + UnitPrice + ' - ' + Discount + ')' + ' X ' + quantity + ' ( ' + SelectedUOM.DefaultUnitName + ' )';
}
else if (DiscountType == '%') {
UOMCalc = '(' + UnitPrice + ' - ' + Discount + '%)' + ' X ' + quantity + ' ( ' + SelectedUOM.DefaultUnitName + ' )';
}
}
element.find(".UOMCalc").text(UOMCalc);
}
else {
element.find(".ItemConversion").text("");
element.find(".UOMCalc").text("");
element.find(".SelectedUOMName").text("");
}
}
if (element.find(".hf_IsManualUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
let ItemId = Number(element.find(".selectedItemId").val());
let SelectedUnitId = Number(element.find(".hf_AlternateUnitId").val());
let ConversionQuantity = Number(element.find(".hf_ConversionQuantity").val());
let AlternateUnitName = element.find(".hf_AlternateUnitName").val();
let ItemUnitName = element.find(".hf_UnitName").val();
totalLineAmount = Number(ConversionQuantity) * Number(UnitPrice);
discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
var assesableAmount = totalLineAmount - discountAmount;
assesableAmount = Number(assesableAmount);
totalLineAmount = assesableAmount;
if (SelectedUnitId != 0 && SelectedUnitId != 1) {
element.find(".prodTotalPrice").text(totalLineAmount);
element.find(".hfRowTotalwithAdjustment").val(totalLineAmount);
element.find(".SelectedUOMName").text('(' + ItemUnitName + ')');
let UOMCalc = UnitPrice + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
if (Discount > 0) {
if (DiscountType == 'Val') {
UOMCalc = '(' + UnitPrice + ' - ' + Discount + ')' + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
}
else if (DiscountType == '%') {
UOMCalc = '(' + UnitPrice + ' - ' + Discount + '%)' + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
}
}
element.find(".UOMCalc").text(UOMCalc);
}
else {
element.find(".ItemConversion").text("");
element.find(".UOMCalc").text("");
element.find(".SelectedUOMName").text("");
}
}
if (!isNaN(totalLineAmount))
totalNonDiscountedAmount += Number(totalLineAmount);
discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
var assesableAmount = totalLineAmount - discountAmount;
var taxPercents = element.find(".hfProdTaxPercent").val();
if (taxPercents != undefined)
var taxpercentarray = taxPercents.toString().split(',');
var taxValue = 0;
var assesableAdjustment = Number(element.find('.hfItemAssesableAdjustmentVal').val());
var taxAdjustment = Number(element.find('.hfItemTaxAdjsutmentVal').val());
if (!isNaN(taxAdjustment))
totalTaxAdjustment += Number(taxAdjustment);
if (!isNaN(assesableAdjustment))
totalAsseableAdjustment += Number(assesableAdjustment);
var cumlTax = 0;
var cumtaxtotal = 0;
if ($(".dropdown_istaxinclusive").val() == "true") {
for (var i = 0; i < taxpercentarray.length; i++) {
var taxPercentModel1 = taxpercentarray[i];
var taxPercentM1 = taxPercentModel1.split(":");
if (!isNaN(Number(taxPercentM1[1])))
cumlTax += Number(taxPercentM1[1]);
}
var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
}
if (taxpercentarray != undefined) {
for (var i = 0; i < taxpercentarray.length; i++) {
var taxPercentModel = taxpercentarray[i];
var taxPercentM = taxPercentModel.split(":");
var ledgerid = taxPercentM[0];
var taxPercent = Number(taxPercentM[1]);
let taxAmt = 0;
if ($(".dropdown_istaxinclusive").val() == "true") {
taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
}
else {
var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
taxAmt = Number(tax);
}
var ledgerexists = false;
$.map(taxAmounts, function (e, i) {
if (e.LedgerId == ledgerid) {
ledgerexists = true;
taxAmounts[i].TaxAmount = Number(taxAmounts[i].TaxAmount) + Number(taxAmt);
}
});
if (!ledgerexists) {
taxAmounts.push({
LedgerId: ledgerid,
TaxAmount: taxAmt,
});
}
}
}
totalAmount += Number(totalLineAmount);
totalQty += Number(quantity);
}
});
if (InvoiceItem.Instance().SplitedInvoiceItemList.length > 0) {
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
var TotalLineAmount = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
var quantiy = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity);
if (!isNaN(TotalLineAmount))
totalNonDiscountedAmount += Number(TotalLineAmount);
var discountAmount = (quantiy * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue)) + ((Number(TotalLineAmount) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent)) / 100) + (Number(TotalLineAmount) * Number(overalldiscountpercent) / 100);
;
var assesableAmount = TotalLineAmount - discountAmount;
assesableAmount = Number(assesableAmount);
var taxPercents = '';
var instance = this;
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent == undefined || InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent == 0) {
var element = "";
$(".SplitItem").each(function () {
if ($(this).find(".selectedItemId").val() == InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId) {
element = $(this);
taxPercents = element.find('.hfProdTaxPercent').val();
}
});
}
else
taxPercents = InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent;
if (taxPercents != undefined && taxPercents != '')
var taxpercentarray = taxPercents.split(',');
var assesableAdjustment = InvoiceItem.Instance().SplitedInvoiceItemList[i].assesableAdjustment;
var taxAdjustment = InvoiceItem.Instance().SplitedInvoiceItemList[i].taxAdjustment;
if (!isNaN(taxAdjustment))
totalTaxAdjustment += Number(taxAdjustment);
if (!isNaN(assesableAdjustment))
totalAsseableAdjustment += Number(assesableAdjustment);
var cumlTax = 0;
var cumtaxtotal = 0;
if ($(".dropdown_istaxinclusive").val() == "true") {
for (var j = 0; j < taxpercentarray.length; j++) {
var taxPercentModel1 = taxpercentarray[j];
var taxPercentM1 = taxPercentModel1.split(":");
if (!isNaN(taxPercentM1[1]))
cumlTax += Number(taxPercentM1[1]);
}
var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
}
if (taxpercentarray != undefined) {
for (var k = 0; k < taxpercentarray.length; k++) {
if (taxpercentarray[k] != '' && taxpercentarray[k] != null) {
var taxPercentModel = taxpercentarray[k];
var taxPercentM = taxPercentModel.split(":");
var ledgerid = taxPercentM[0];
var taxPercent = taxPercentM[1];
var taxAmt = 0;
if ($(".dropdown_istaxinclusive").val() == "true") {
taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
}
else {
var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
taxAmt = Number(tax);
}
var ledgerexists = false;
$.map(taxAmounts, function (e, m) {
if (e.LedgerId == ledgerid) {
ledgerexists = true;
taxAmounts[m].TaxAmount = Number(taxAmounts[m].TaxAmount) + Number(taxAmt);
}
});
if (!ledgerexists) {
taxAmounts.push({
LedgerId: ledgerid,
TaxAmount: taxAmt,
});
}
}
}
}
totalAmount += Number(TotalLineAmount);
totalQty += Number(quantiy);
}
}
var taxAmount = 0;
var taxAdjustment = 0;
for (var i = 0; i < taxAmounts.length; i++) {
if (!isNaN(taxAmounts[i].TaxAmount)) {
var taxamt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(taxAmounts[i].TaxAmount, 2);
taxAmount += Number(taxamt);
}
}
if (!isNaN(totalTaxAdjustment))
totalTaxAdjustment = totalTaxAdjustment;
if (!isNaN(totalAsseableAdjustment)) {
totalAsseableAdjustment = totalAsseableAdjustment;
}
else {
totalAsseableAdjustment = 0;
}
if (!isNaN(totalAsseableAdjustment))
totalAmount += Number(totalAsseableAdjustment);
totalTaxAmount = Number(taxAmount) + Number(totalTaxAdjustment);
totalDiscountAmount += adddiscountrow_total;
var totaltax = totalTaxAmount;
var grosstotal = totalAmount;
var creditnotes = 0;
var assessableadjustment = 0;
if (!isNaN(Number($("#txt_assessableadjustment").val())))
assessableadjustment = Number($("#txt_assessableadjustment").val());
var subtotal = grosstotal - totalDiscountAmount + assessableadjustment;
let itemCount = $("#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find(".InvoiceItems .item-addedrow .selectedItemId[value!='0']").length;
$("#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find("#Item_Count").text(itemCount);
var overalldiscount = 0;
var taxadjustment = 0;
if (!isNaN(Number($('#txt_taxadjustment').val()))) {
taxadjustment = Number($('#txt_taxadjustment').val());
}
totaltax = Number(totaltax) + Number(taxadjustment);
totaltax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaltax, 2);
$('#totalTax').html(totaltax);
$('.hdn_taxamount').val(totaltax);
$('#grosstotal').html(grosstotal);
$('#totalItemDiscount').html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(itemdiscount_total, 2));
$('#totalDiscount').html(totalDiscountAmount);
$("#totalinvoiceqty").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalQty, 2));
var expense = 0;
if (!isNaN(Number($('#txtOverallExpenseAmount').val()))) {
expense = Number($('#txtOverallExpenseAmount').val());
$("#totalexpense").text(expense);
}
var adjustment = 0;
var nettotal = Number(subtotal) + Number(addexpenserow_total) - Number(overalldiscount) - Number(netadddiscountrow_total) + Number(adjustment);
if ($(".dropdown_istaxinclusive").val() == "false")
nettotal += Number(totaltax);
if ($(".dropdown_istaxinclusive").val() == "true") {
subtotal = Number(subtotal) - Number(totalTaxAmount);
}
subtotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(subtotal, 2);
$('#subtotal').html(subtotal);
$('.hdn_assessableamount').val(subtotal);
$('.hdn_assessableamount').val($('#subtotal').text());
if ($("#hf_AdjustmentAccountId").val() != undefined) {
$(".hdn_adjustmentaccountId").val($("#hf_AdjustmentAccountId").val());
}
if ($("#chk_tcsapplied").val() != undefined) {
if ($("#chk_tcsapplied").prop("checked")) {
let tcstax = 0;
let tcsrate = 0;
tcsrate = InvoiceItem.Instance().TaxRate;
if (tcsrate != 0) {
tcstax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(subtotal) + Number(totalTaxAmount)) * (tcsrate / 100), 2);
$('.number_tcsamount').val(tcstax);
nettotal += Number(tcstax);
$('#lbltcsrate').text("TCS " + tcsrate + " %");
var tcsadjustment = 0;
if (!isNaN(Number($('.txt_tcsadjustment').val()))) {
tcsadjustment = Number($('.txt_tcsadjustment').val());
}
$(".number_tcstaxrate").val(tcsrate);
$('.number_tcsamount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(tcstax) + tcsadjustment), 2));
nettotal += tcsadjustment;
}
}
else {
$('.txt_tcsadjustment').val(0);
$('.number_tcsamount').val(0);
}
}
if ($("#chk_tdsapplied").val() != undefined) {
if ($("#chk_tdsapplied").prop("checked")) {
let taxcodeid = $(".txtAutoComplete_tdstaxcodeid").val();
let tdsrate = $(".number_tdstaxrate").val();
let tdstax = 0;
if (tdsrate != 0) {
tdstax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(subtotal) * (Number(tdsrate) / 100), 2);
$('.number_tdsamount').val(tdstax);
}
nettotal -= Number(tdstax);
}
else {
$('.txt_tdsadjustment').val(0);
$('.number_tdsamount').val(0);
}
}
$('.nettotal').html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(nettotal, 2));
}
loadItemAutoComplete(element) {
let userinfo = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
let sessionid = userinfo.sessionId;
let postData = null;
element.find(".prodName").select2({
placeholder: "Select",
tags: false,
allowClear: true,
theme: "default select2ErrorClass",
data: [],
ajax: {
url: function (request) {
let reqUrl = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/getitemsdcitemsandinvoiceitems';
return reqUrl;
},
type: "POST",
contentType: 'application/json',
dataType: 'json',
data: function (params) {
let Term = params.term;
sessionid = sessionid.replace('#', '');
postData = {
LobId: Number($(".hfAutoCompleteId_lobid").val()),
ItemIds: InvoiceItem.instance.itemIds,
term: Term,
};
return JSON.stringify(postData);
},
beforeSend: function (xhr) {
if (userinfo !== undefined && userinfo !== null) {
xhr.setRequestHeader("Authorization", "Basic " + userinfo.sessionId);
xhr.setRequestHeader('geoposition', userinfo.latd + ':' + userinfo.lgId);
}
},
processResults: function (data) {
return {
results: jQuery.map(JSON.parse(data.result), function (item) {
return {
id: item.Value,
text: item.SelectText,
addlInfo: item.addlData
};
})
};
},
},
});
}
itemChange(element, id, hdnAutoId) {
id = element.find(".prodName option:selected").val();
element.find(".prodName").change(function () {
if (id == null || id == 0) {
id = element.find(".prodName option:selected").val();
}
id = element.find(".prodName option:selected").val();
if (id != 0) {
var hdnItemId = id;
element.find(".selectedItemId").val(id);
if (id.search(':') == -1)
hdnItemId = id;
else
hdnItemId = id.split(':')[1];
if (element.find(".hfoldItemId").val() != hdnItemId) {
if (element.find(".orderItemId").val() == "0" && hdnItemId != "") {
if (element.find(".hfoldItemId").val() != "0" && element.find(".hfoldItemId").val() != undefined && element.find(".hfoldItemId").val() != "") {
let index = InvoiceItem.Instance().itemIds.indexOf(Number(element.find(".hfoldItemId").val()), 0);
if (index > -1) {
InvoiceItem.Instance().itemIds.splice(index, 1);
}
}
InvoiceItem.Instance().itemIds.push(Number(hdnItemId));
}
var x = [];
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == element.find(".hfoldItemId").val()) {
x.push(i);
}
}
for (var i = x.length - 1; i >= 0; i--) {
InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
}
$('.item-row').each(function () {
if ($(this).find('.hfOfferedItemId').val() == element.find(".hfoldItemId").val())
$(this).remove();
});
element.find(".hfoldItemId").val(hdnItemId);
element.find(".div_UnitPrice").removeClass('hidden');
element.find(".div_SplitInvoiceItem").addClass("hidden");
element.find(".prodQuantity").val(0);
element.find(".prodPrice").val(0);
element.find(".prodQuantity").prop('disabled', false);
element.find('.prodQuantity').css('cursor', 'default');
element.find('.prodPrice').css('cursor', 'default');
element.find("#inv_txtdiscount").css('cursor', 'default');
element.find('#inv_txtdiscount').prop('disabled', false);
element.find('#inv_txtdiscount').val(0);
element.find('.btn_inv_DiscType').removeClass('hidden');
element.find(".btn_inv_DiscType").prop('disabled', false);
element.find(".prodTax").empty();
element.find(".txt_Account").empty();
if (element.hasClass('SplitItem')) {
element.find(".spn_InvoiceItem").unbind("click", null);
}
element.find(".hfRowTotalwithAdjustment").val("0");
element.find('.prodTotalPrice').text('0');
$("#txt_Adjustment").val("0");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
element.removeClass('SplitItem');
element.find(".hfMrpId").val(0);
}
if ($(hdnAutoId).val().toString().search(':') == -1)
element.find(".hfoldItemId").val($(hdnAutoId).val());
else
element.find(".hfoldItemId").val($(hdnAutoId).val().toString().split(':')[1]);
var hdnSelectedItemIdVal = 0;
hdnSelectedItemIdVal = id;
if (id != 0) {
id = id;
var hdnOrderItemIdVal = 0;
var hdnDcItemIdVal = 0;
var ids = $(hdnAutoId).val();
if (ids.toString().search(':') == -1) {
hdnSelectedItemIdVal = Number($(hdnAutoId).val());
}
else {
var selectedVal = hdnAutoId;
if (!InvoiceItem.Instance().AutoDc) {
hdnOrderItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().OrderSettingId == 2)
hdnOrderItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
else {
hdnDcItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
element.find(".dcItemId").val(hdnDcItemIdVal);
let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(hdnDcItemIdVal, 0);
if (dcindex == -1)
InvoiceItem.Instance().dcItemIds.push(hdnDcItemIdVal);
}
}
hdnSelectedItemIdVal = Number($(selectedVal).val().toString().split(':')[1]);
}
var item = element.find(".prodName").text();
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemById(hdnSelectedItemIdVal).then(function (response) {
var inventarytype = response.result.InventoryTypeId;
if (inventarytype == 5 || inventarytype == 6) {
InvoiceItem.Instance().addDiscountRow(element, item, id);
var elementfordisc = $(".discount-row:last");
InvoiceItem.Instance().loadItemRowDetails(elementfordisc, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
}
else if (inventarytype == 7) {
InvoiceItem.Instance().addExpenseRow(element, item, id, true);
var elementforexp = $(".expense-row:last");
InvoiceItem.Instance().loadItemRowDetails(elementforexp, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
}
else {
var itemid = 0;
if (hdnSelectedItemIdVal == undefined) {
InvoiceItem.Instance().loadItemRowDetails(element, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
}
else {
InvoiceItem.Instance().loadItemRowDetails(element, hdnOrderItemIdVal, hdnDcItemIdVal, hdnSelectedItemIdVal);
}
}
});
}
}
});
}
itemsAutoComplete(element) {
var txtAutoSearchCtrl = element.find(".prodName");
var hdnOrderItemId = element.find(".orderItemId");
var hdnDcItemId = element.find(".dcItemId");
var hdnSelectedItemId = element.find(".selectedItemId");
let lobid = $(".hfAutoCompleteId_lobid").val();
if ((hdnSelectedItemId).val() != 0 && (hdnSelectedItemId).val() != "") {
this.itemIds.push(Number((hdnSelectedItemId).val()));
element.find(".hfoldItemId").val((hdnSelectedItemId).val());
}
let hdnAutoId = hdnSelectedItemId;
let orderid = InvoiceItem.Instance().orderid;
let dcid = InvoiceItem.Instance().dcid;
let invoiceid = $(".hdn_invoiceid").val();
if (invoiceid == undefined || invoiceid == "null")
invoiceid = 0;
var url = "";
var id = 0;
if ((orderid == 0) && (InvoiceItem.Instance().AutoDc) && InvoiceItem.Instance().OrderSettingId == 0 && ($('#hfInv_IsRetun').val() != "1" && ($(".hdn_refinvoiceid").val() == undefined || $(".hdn_refinvoiceid").val() == 0))) {
InvoiceItem.instance.loadItemAutoComplete(element);
}
else {
if ((orderid == 0) && (dcid != 0 && InvoiceItem.Instance().AutoDc == false))
url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autodcitemforinvoicewithoutorder/dcid/" + dcid + "/itemids/" + InvoiceItem.Instance().itemIds;
else if (InvoiceItem.Instance().OrderSettingId == 1)
url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autodcitemforinvoice/dcid/" + dcid + "/itemids/" + InvoiceItem.Instance().dcItemIds;
else
url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autopendingorderitemforinvoice/orderid/" + orderid + "/itemids/" + InvoiceItem.Instance().itemIds;
if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && ($('#hfInv_IsRetun').val() == "1" || ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0))) {
var refinvoiceid = 0;
if ($('#hfInv_IsRetun').val() == "1") {
refinvoiceid = Number(invoiceid);
$(".hdn_refinvoiceid").val(refinvoiceid);
}
if ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0)
refinvoiceid = Number($(".hdn_refinvoiceid").val());
url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autopendingreturnitemforinvoice/invoiceid/" + refinvoiceid + "/itemids/" + InvoiceItem.Instance().itemIds;
}
AutoCompleteHelper.getHelper().Create(txtAutoSearchCtrl, hdnAutoId, url, function (result) {
InvoiceItem.instance.itemChange(element, result.id, hdnAutoId);
});
}
InvoiceItem.Instance().loadItemRowDetails(element, hdnOrderItemId.val(), hdnDcItemId.val(), $(hdnSelectedItemId).val());
}
addDiscountRow(element, txtAutoSearchCtrl, hdnAutoId) {
InvoiceItem.Instance().RemoveItem(element);
InvoiceItem.Instance().adddiscountrow(null, txtAutoSearchCtrl, hdnAutoId, false);
}
adddiscountrow(row, txtAutoSearchCtrl, hdnAutoId, applyOnNet) {
let isemptyrow = false;
$(".addednetdiscount-row").each(function () {
if ($(this).find(".txtDiscountName").val() == undefined || $(this).find(".txtDiscountName").val() == null) {
isemptyrow = true;
}
});
if (isemptyrow) {
MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
return false;
}
var discountid = 0;
var discountname = '';
var description = '';
var ledgerId = 0;
var rowname = "discount-row";
var percent = 0.0;
var value = 0.0;
var invoicechargeid = 0;
var appliedWhole = false;
var inventorytypeid = 6;
var readonly = "";
if (applyOnNet) {
rowname = "netdiscount-row";
appliedWhole = true;
inventorytypeid = 5;
}
if ($("#hfDirectInvoice").val() == "0")
invoicechargeid = 0;
var html = '
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
';
$("." + rowname + ":last").after(html);
var element = $("." + rowname + ":last");
InvoiceItem.Instance().bind(element, inventorytypeid);
if (inventorytypeid == 5)
InvoiceItem.Instance().GetOnInvoiceDiscountItem(element);
var txtChargeCode = element.find(".txtDiscountName");
var hfSelectedChargeId = element.find(".hfSelectedChargeId");
$(hfSelectedChargeId).val(hdnAutoId);
if (hdnAutoId != 0) {
var selecteditem = new Option(txtAutoSearchCtrl, hdnAutoId, true);
txtChargeCode.append(selecteditem);
}
if (rowname == "netdiscount-row" || rowname == "discount-row") {
var id = 0;
if (row != null) {
var selecteditem = new Option(row.itemName, row.itemId, true);
txtChargeCode.append(selecteditem);
}
let typeid = "7";
if (rowname == "discount-row") {
typeid = "5,6";
}
var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/itemautocompletebyinventorytype/inventorytypeid/' + Number(inventorytypeid) + '/lobid/' + $(".hfAutoCompleteId_lobid").val() + '/invoicetypeid/' + $('.hdn_invoicetypeid').val();
AutoCompleteHelper.getHelper().Create(txtChargeCode, hfSelectedChargeId, url, function (result) {
if (id != result.id) {
id = result.id;
var elementfordisc = $(".netdiscount-row:last");
var hdnOrderItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[0];
var hdnSelectedItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[1];
if (result.addlData != undefined && result.addlData != null) {
var defaultpercent = Number(result.addlData.split(':')[0]);
var defaultvalue = Number(result.addlData.split(':')[1]);
element.find('.percentage').val(defaultpercent);
element.find('.fixedvalue').val(defaultvalue);
}
InvoiceItem.Instance().loadItemRowDetails(element, 0, 0, hdnOrderItemIdVal);
}
});
}
$('.percentage').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
event.preventDefault();
});
$('.fixedvalue').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
event.preventDefault();
});
}
addExpenseRow(row, txtAutoSearchCtrl, hdnAutoId, applyOnNet) {
let isemptyrow = false;
$(".addedexpense-row").each(function () {
if ($(this).find(".txtExpenseName").val() == undefined || $(this).find(".txtExpenseName").val() == null) {
isemptyrow = true;
}
});
if (isemptyrow) {
MessageHelper.Instance().showError("Please Select Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
return false;
}
var discountid = 0;
var discountname = '';
var description = '';
var ledgerId = 0;
var rowname = "expense-row";
var percent = 0.0;
var value = 0.0;
var invoicechargeid = 0;
var appliedWhole = true;
var inventorytypeid = 7;
if ($("#hfDirectInvoice").val() == "0")
invoicechargeid = 0;
var html = '
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
';
$("." + rowname + ":last").after(html);
var element = $("." + rowname + ":last");
InvoiceItem.Instance().bind(element, inventorytypeid);
var txtChargeCode = element.find(".txtExpenseName");
var hfSelectedChargeId = element.find(".hfSelectedChargeId");
$(hfSelectedChargeId).val(hdnAutoId);
if (hdnAutoId != 0) {
var selecteditem = new Option(txtAutoSearchCtrl, hdnAutoId, true);
txtChargeCode.append(selecteditem);
}
if (rowname == "expense-row") {
var id = 0;
if (row != null) {
var selecteditem = new Option(row.itemName, row.itemId, true);
txtChargeCode.append(selecteditem);
}
let typeid = "7";
var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/itemautocompletebyinventorytype/inventorytypeid/' + Number(inventorytypeid) + '/lobid/' + $(".hfAutoCompleteId_lobid").val() + '/invoicetypeid/' + $('.hdn_invoicetypeid').val();
AutoCompleteHelper.getHelper().Create(txtChargeCode, hfSelectedChargeId, url, function (result) {
if (id != result.id) {
id = result.id;
var elementfordisc = $(".expense-row:last");
var hdnOrderItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[0];
var hdnSelectedItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[1];
InvoiceItem.Instance().loadItemRowDetails(element, 0, 0, hdnOrderItemIdVal);
}
});
}
$('.exppercentage').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
event.preventDefault();
});
$('.expfixedvalue').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
event.preventDefault();
});
}
loadItemRowDetails(element, orderItemId, dcItemId, itemId) {
var instance = this;
if (orderItemId == '' || ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4"))
orderItemId = 0;
if (dcItemId == '' || ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
dcItemId = 0;
}
if ((orderItemId != 0 && orderItemId != undefined) || (itemId != 0 && itemId != undefined) || (dcItemId != 0 && dcItemId != undefined)) {
let lobId = $(".hfAutoCompleteId_lobid").val();
let billingAddressId = $('.txtAutoComplete_billtoaddressid').val();
if (billingAddressId == "0" || billingAddressId == "" || billingAddressId == null) {
MessageHelper.Instance().showError("Please select bill to address", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
return false;
}
var portalId = 0;
var ShipfromAddressId = 0;
let invoiceid = $(".hdn_invoiceid").val();
if (invoiceid == undefined)
invoiceid = 0;
ShipfromAddressId = Number($(".txtAutoComplete_shipfromaddressid").val());
var ShiptoAddressId = Number($(".txtAutoComplete_shiptoaddressid").val());
portalId = Number($(".txtAutoComplete_billfromaddressid").val());
var MrpId = element.find(".hfMrpId").val();
if (MrpId == undefined)
MrpId = 0;
var isconfirm = false;
var invoicemode = "1";
var invoiceType = $('.hdn_invoicetypeid').val();
if (itemId == undefined)
itemId = 0;
var contactId = $(".hdn_organizationid").val();
if (contactId == 0)
contactId = $(".hfAutoCompleteId_orgcontactid").val();
var invoiceapplytype = 1;
if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
invoiceapplytype = 2;
}
let ApplyDate = moment($('.date_journaldate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
var refinvoiceid = 0;
if ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0)
refinvoiceid = Number($(".hdn_refinvoiceid").val());
var post = {
OrderItemId: Number(orderItemId),
DcItemId: Number(dcItemId),
ItemId: Number(itemId),
BillingAddressId: Number(billingAddressId),
BillFromAddressId: portalId,
DefaultPriceListId: 0,
InvoiceType: Number(invoiceType),
MrpId: Number(MrpId),
InvoiceMode: Number(invoicemode),
isCform: Boolean(isconfirm),
LobId: Number(lobId),
contactId: Number(contactId),
InvoiceApplyType: invoiceapplytype,
ShipFromAddressId: ShipfromAddressId,
ShipToAddressId: ShiptoAddressId,
AutoDC: InvoiceItem.instance.AutoDc,
InvoiceDate: ApplyDate,
RefInvoiceId: refinvoiceid
};
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemDetails(post).then(function (response) {
var itemdata = response.result;
element.find(".selectedItemId").val(itemdata.ItemId);
if (itemdata.orderItemId == 0)
element.find(".orderItemId").val(orderItemId);
else
element.find(".orderItemId").val(itemdata.OrderItemId);
itemId = itemdata.ItemId;
element.find(".spnProdName").text(itemdata.ItemName);
element.find(".selectedItemName").text(itemdata.ItemName + ' - ' + itemdata.ItemSKU);
element.find("#inventorytypeid").val(itemdata.InventoryTypeId);
var prodPrice = element.find(".prodPrice");
var prodQty = element.find(".prodQuantity");
var priceListId = element.find(".hfPriceList");
var isSplitItem = false;
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
isSplitItem = true;
}
}
if (itemdata.AccountId != 0 && (element.find(".selectedInvoiceItemId").val() == "0" || (itemdata.InventoryTypeId == 5)) && !isSplitItem) {
var selectedAccount = new Option(itemdata.AccountName, itemdata.AccountId, true);
element.find(".txt_Account").empty();
element.find(".txt_Account").append(selectedAccount);
element.find(".hf_Account").val(itemdata.AccountId);
element.find(".txt_AccountName").val(itemdata.AccountName);
}
if (itemdata.TaxGroupId != 0 && (element.find(".selectedInvoiceItemId").val() == "0" || (itemdata.InventoryTypeId == 5)) && !isSplitItem) {
var txtTaxGroup = element.find(".prodTax");
var hfTaxGroupId = element.find(".hfProdTax");
txtTaxGroup.empty();
var selectedTaxgrp = new Option(itemdata.TaxGroupName, itemdata.TaxGroupId, true);
txtTaxGroup.append(selectedTaxgrp);
element.find(".txtProdTax").val(itemdata.TaxGroupName);
hfTaxGroupId.val(itemdata.TaxGroupId);
InvoiceItem.Instance().update_tax(element, itemdata.TaxGroupId);
}
if (element.find(".selectedInvoiceItemId").val() == "0" && !isSplitItem) {
prodPrice.val(itemdata.UnitPrice);
element.find(".hf_UnitPrice").val(itemdata.UnitPrice);
priceListId.val(itemdata.PriceListId);
if (itemdata.AddlDisountValue > 0) {
element.find(".btnInvoice_DiscType option[value='Val']").prop("selected", true);
element.find('.inv_txtaddldiscount').val(itemdata.AddlDisountValue);
}
else if (itemdata.AddlDiscountPercent > 0) {
element.find(".btnInvoice_DiscType option[value='%']").prop("selected", true);
element.find('.inv_txtaddldiscount').val(itemdata.AddlDiscountPercent);
}
}
if ($(".hdn_invoiceid").val() != "0") {
element.find(".prodAvail").text(itemdata.AvailableQty);
element.find(".hfAvail").val(itemdata.AvailableQty);
}
else {
element.find(".prodAvail").text(itemdata.AvailableQty);
element.find(".hfAvail").val(itemdata.AvailableQty);
}
var dcid = InvoiceItem.Instance().dcid;
if (dcid == undefined)
dcid = 0;
if ((itemdata.EnableMrp == true || itemdata.EnableBatchNo == true || itemdata.EnableSerialNo == true) && ((Number(element.find('.prodAvail').text()) > 0) || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || dcid != 0) && $(".hdn_invoicetypeid").val() != "6" && $(".hdn_invoicetypeid").val() != "7" && element.find('.hf_IsFoc').val() == "false") {
element.find(".div_UnitPrice").addClass('hidden');
element.find(".div_SplitInvoiceItem").removeClass("hidden");
element.find(".prodQuantity").prop('disabled', true);
element.find(".prodQuantity").css('cursor', "not-allowed");
element.find("#inv_txtdiscount").prop('disabled', true);
element.find("#inv_txtdiscount").css('cursor', "not-allowed");
element.find('.btn_inv_DiscType').addClass('hidden');
element.find(".btn_inv_DiscType").prop('disabled', true);
element.find(".prodTax").removeClass("required");
element.find(".txt_Account").removeClass("required");
element.addClass('SplitItem');
var ItemExist = false;
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
ItemExist = true;
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId == 0)
InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice = itemdata.UnitPrice;
}
}
var type = '';
if (itemdata.EnableBatchNo == true) {
if (ItemExist == true)
element.find(".spn_InvoiceItem").text("View BatchNo");
else
element.find(".spn_InvoiceItem").text("Select BatchNo");
type = "BatchNo";
}
else if (itemdata.EnableMrp == true) {
if (ItemExist == true)
element.find(".spn_InvoiceItem").text("View MRP");
else
element.find(".spn_InvoiceItem").text("Select MRP");
type = "MRP";
}
else {
if (ItemExist == true)
element.find(".spn_InvoiceItem").text("View SerialNo");
else
element.find(".spn_InvoiceItem").text("Select SerialNo");
type = 'SerialNo';
}
let d = InvoiceItem.instance.AutoDc;
if (d == false && dcItemId != 0 && element.find(".selectedInvoiceItemId").val() == "0") {
var Isitemadded = false;
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId == dcItemId) {
Isitemadded = true;
}
}
if (Isitemadded == false) {
var IsSpitItem = false;
var RowTotal = 0;
var Discount = 0;
var Qty = 0;
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
IsSpitItem = true;
}
}
InvoiceItem.Instance().SplitedInvoiceItemList.push({
orderItemId: itemdata.OrderItemId,
invoiceItemId: 0,
itemName: itemdata.ItemName,
itemId: itemdata.ItemId,
itemSKU: itemdata.ItemSKU,
unitName: itemdata.UnitName,
packSize: itemdata.PackSize,
packCount: itemdata.PackCount,
packs: itemdata.Packs,
quantity: itemdata.Quantity,
availPacks: itemdata.AvailablePacks,
availQty: itemdata.AvailableQty,
listPrice: 0,
description: itemdata.Description,
taxGroupName: itemdata.TaxGroupName,
taxGroupId: itemdata.TaxGroupId,
isTaxInclusive: $(".dropdown_istaxinclusive").val(),
addlDiscountPercent: itemdata.AddlDiscountPercent == undefined ? 0 : itemdata.AddlDiscountPercent,
addlDiscountValue: itemdata.AddlDisountValue,
creditNote: 0,
priceListId: 0,
batchId: 0,
unitPrice: itemdata.UnitPrice,
invoiceallocations: null,
exciseInvoiceItem: null,
accountId: itemdata.AccountId,
accountName: itemdata.AccountName,
walletId: 0,
Adjustment: 0,
IsFoc: false,
TariffNo: "",
exciseAmount: 0,
discountName: "",
discountId: 0,
refNo: itemdata.RefNo,
DiscountGroupId: 0,
DiscountGroupName: "",
ExchangeItem: false,
maxQty: itemdata.Quantity,
RefInvoiceItemId: 0,
MrpId: itemdata.MrpId,
taxAdjustment: 0,
assesableAdjustment: 0,
inventoryTypeId: itemdata.InventoryTypeId,
IsBoMItem: false,
dcItemId: dcItemId,
TotalRowAmount: 0,
TotalDiscount: 0,
TotalAmount: 0,
BatchId: itemdata.BatchId,
});
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
Qty += InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity;
var rowtotal = Number((InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice) + InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount + itemdata.Adjustment);
var nonexiceamount = rowtotal - InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount;
var discount = ((nonexiceamount * itemdata.AddlDiscountPercent) / 100) + (itemdata.Quantity * itemdata.AddlDisountValue);
InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalAmount = rowtotal,
InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalDiscount = discount,
Discount += discount;
RowTotal += rowtotal;
}
}
$('.item-row').each(function () {
if ($(this).find('.selectedItemId').val() == itemdata.ItemId) {
if ($(".hdn_invoicetypeid").val() == "2") {
$(this).find(".txtRowTotalwithAdjustment").val();
$(this).find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(RowTotal), 3));
}
else {
element.find('.prodTotalPrice').text('');
element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
}
$(this).find('.prodQuantity').val();
$(this).find('.prodQuantity').val(Qty);
$(this).find('#inv_txtdiscount').val();
$(this).find('#inv_txtdiscount').val(Discount);
}
});
}
}
if (orderItemId != 0 && invoiceid == 0) {
element.find('.prodQuantity').val(itemdata.Quantity);
}
element.find(".spn_InvoiceItem").unbind().click(function () {
InvoiceItem.Instance().createSplitItem(element, itemdata.ItemName + ' - ' + itemdata.ItemSKU, type);
});
}
else if (element.find(".selectedInvoiceItemId").val() == "0" && $('.hdn_invoicetypeid').val() != '3' && $('.hdn_invoicetypeid').val() != '4' && (dcItemId != 0 || (orderItemId != 0 && InvoiceItem.Instance().OrderSettingId == 2))) {
prodPrice.val(itemdata.UnitPrice);
prodQty.val(itemdata.Quantity);
priceListId.val(itemdata.PriceListId);
element.find('.maxQty').val(itemdata.Quantity);
}
if (element.find(".selectedInvoiceItemId").val() == "0" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
if (!element.hasClass('SplitItem'))
prodQty.val(itemdata.Quantity);
}
if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
if ((itemdata.IsOfferAvailable == true || itemdata.IsFocAvailable == true) && element.find('.hf_IsFoc').val() != "true") {
element.find('.btn_offer').removeClass('hidden');
element.find('.btn_offer').click(function () {
InvoiceItem.Instance().loadItemOffers(itemdata.ItemId, itemdata.ItemName, invoiceapplytype, contactId, element);
});
}
else
element.find('.btn_offer').addClass('hidden');
if (itemdata.IsSpecialPrice == true)
element.find('.btn_specialPrice').removeClass('hidden');
}
if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $("#hf_AppSettingName").val() == "Create Return") {
element.find(".prodTax").empty();
element.find(".txt_Account").empty();
if (itemdata.TaxGroupId != 0) {
element.find(".txtProdTax").val(itemdata.TaxGroupName);
element.find(".hfProdTax").val(itemdata.TaxGroupId);
}
if (itemdata.AccountId != 0) {
element.find(".hf_Account").val(itemdata.AccountId);
element.find(".txt_AccountName").val(itemdata.AccountName);
}
}
if (!element.hasClass('SplitItem')) {
if ($(".hdn_invoiceid").val() != "0" && $(".hdn_invoiceid").val() != undefined) {
var taxgrpid = element.find(".hfProdTax").val();
InvoiceItem.Instance().update_tax(element, taxgrpid);
}
}
if (!element.hasClass('SplitItem') && (element.find(".selectedInvoiceItemId").val() == "0" || element.find(".selectedInvoiceItemId").val() == "undefined")) {
var txtTaxGroup = element.find(".prodTax");
var hfTaxGroupId = element.find(".hfProdTax");
if (itemdata.TaxGroupId != 0) {
txtTaxGroup.empty();
var selectedTaxgrp = new Option(itemdata.TaxGroupName, itemdata.TaxGroupId, true);
txtTaxGroup.append(selectedTaxgrp);
element.find(".txtProdTax").val(itemdata.TaxGroupName);
hfTaxGroupId.val(itemdata.TaxGroupId);
InvoiceItem.Instance().update_tax(element, itemdata.TaxGroupId);
}
if (itemdata.AccountId != 0) {
var selectedAccount = new Option(itemdata.AccountName, itemdata.AccountId, true);
element.find(".txt_Account").empty();
element.find(".txt_Account").append(selectedAccount);
element.find(".hf_Account").val(itemdata.AccountId);
element.find(".txt_AccountName").val(itemdata.AccountName);
}
}
var unit = element.find(".unit");
unit.text(itemdata.UnitName);
var sku = element.find(".prodSKU");
sku.text(itemdata.ItemSKU);
var packSize = element.find(".packSize");
if (itemdata.PackSize == "0")
packSize.val("1");
else
packSize.val(itemdata.PackSize);
if (itemdata.PackCount == "0")
element.find(".packCount").val("1");
else
element.find(".packCount").val(itemdata.PackCount);
var rowTotal = 0;
var rowTotalwithAdjustment = 0;
if (element.find('.prodPrice').val() != undefined && element.find('.prodQuantity').val() != undefined) {
rowTotal = element.find('.prodPrice').val().replace("$", "") * element.find('.prodQuantity').val();
rowTotalwithAdjustment = element.find('.prodPrice').val().replace("$", "") * element.find('.prodQuantity').val();
}
if (itemdata.InventoryTypeId == 2) {
element.find('.prodQuantity').removeAttr('readonly');
}
var asbAdjAmt = element.find('.hfItemAssesableAdjustmentVal').val();
if (!isNaN(asbAdjAmt))
rowTotalwithAdjustment += Number(asbAdjAmt);
rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
if (isNaN(rowTotal)) {
if (!element.hasClass('SplitItem')) {
element.find('.prodTotalPrice').html("N/A");
element.find('.hfRowTotal').val("0");
element.find('.hfRowTotalwithAdjustment').val("0");
}
}
else {
if (!element.hasClass('SplitItem')) {
element.find('.hfRowTotal').val(rowTotal);
element.find('.hfRowTotalwithAdjustment').val(rowTotalwithAdjustment);
element.find('.prodTotalPrice').html(rowTotal);
}
}
if (itemdata.AvailableQty <= 0)
element.find(".prodAvail").addClass('text-danger');
else
element.find(".prodAvail").removeClass('text-danger');
if (!element.hasClass('SplitItem')) {
InvoiceItem.Instance().update_row_total(element, false);
}
InvoiceItem.Instance().loadPriceLists(element, itemId, itemdata.EnableMrp);
if (itemdata.EnableMrp != true && itemdata.EnableBatchNo != true && itemdata.EnableSerialNo != true) {
element.find('.hfRowTotalwithAdjustment').css("text-decoration", "underline");
element.find('.hfRowTotalwithAdjustment').attr("disabled", false);
element.find('.Adjustmentrow').click(function () {
if ($(".hdn_invoicetypeid").val() == "2" && element.find('.selectedInvoiceItemId').val() != "0") {
InvoiceItem.Instance().editInvItemTaxAllocs(element.find('.selectedInvoiceItemId').val(), element.find('.hfProdTax').val(), element.find('.selectedItemId').val(), element.find('.orderItemId').val(), element);
}
});
}
else {
element.find('.hfRowTotalwithAdjustment').css("text-decoration", "");
element.find('.hfRowTotalwithAdjustment').attr("disabled", true);
}
if (IsSpitItem == true) {
element.remove();
}
if (itemdata.IsMultilpeUOMs && $(".hdn_invoicetypeid").val() == "1") {
element.find(".hf_IsMultipleUOM").val(itemdata.IsMultilpeUOMs);
let MultipleUOMs = itemdata.MultipleUoms;
let html = '
';
for (var i = 0; i < MultipleUOMs.length; i++) {
html += '
';
}
element.find(".ddl_MultipleUOMs").html(html);
element.find("#div_MultipleUOMs").removeClass("hidden");
instance.UOMs.push({
ItemId: itemId,
MultipleUOMs: MultipleUOMs
});
let SelectedUOM = Number(element.find(".hf_AlternateUnitId").val());
let DefaultSize = Number(element.find(".hf_DefaultSize").val());
if (SelectedUOM != 0) {
element.find(".ddl_MultipleUOMs").val(SelectedUOM);
let Qty = element.find(".prodQuantity").val();
let NewQty = Qty / DefaultSize;
element.find(".prodQuantity").val(NewQty);
}
}
else {
element.find("#div_MultipleUOMs").addClass("hidden");
}
if (itemdata.InventoryTypeId == 1)
InvoiceItem.Instance().GetDiscounts();
}, function (response) {
MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
});
}
}
loadItemOffers(ItemId, ItemName, InvoiceApplyType, OrganizationId, element) {
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/components/invoices/itemofferselection.js", function () {
Unibase.Platform.Helpers.NavigationHelper.Instance().popup(0, "", Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance(), function () {
Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance().LoadOfferItems(OrganizationId, ItemId, ItemName, InvoiceApplyType, element, "Invoice");
}, Unibase.Platform.Helpers.Size.Large);
});
}
update_tax(element, taxGroupId) {
var hfTaxValue = element.find(".hfProdTaxValue");
var hfTaxPercent = element.find(".hfProdTaxPercent");
var hfProdTax = element.find(".hfProdTax");
var percentage = 0;
if (taxGroupId == "0" || taxGroupId == "" || taxGroupId == undefined)
return percentage;
let branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().gettaxpercentages(taxGroupId, branchid).then(function (response) {
var percentstring = "";
if (response.result.length > 0) {
var percentages = response.result;
for (var i = 0; i < percentages.length; i++) {
percentstring += percentages[i].LedgerId + ":" + percentages[i].Percentage + ",";
}
hfTaxPercent.val(percentstring);
}
hfTaxValue.val("0");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}, function (response) {
MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
});
}
createSplitItem(element, ItemName, type) {
let obj = [];
obj.push({
type: type,
element: element,
});
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/invoices/splititem.js", function () {
Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance(), null, Unibase.Platform.Helpers.Size.Large);
});
}
loadPriceLists(element, itemId, IsEnableMrp) {
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getLatestMrpByItemId(itemId).then(function (response) {
if (response.result != null) {
element.find(".hf_PriceList").val(response.result.PriceListId);
if (response.result.MrpId != 0 && IsEnableMrp) {
element.find(".txt_MRP").val(response.result.Mrp);
element.find(".hfMrpId").val(response.result.MrpId);
}
}
}, function (response) {
MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
});
}
RemoveItem(element) {
var _this = element.find(".delete");
var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
if (invoiceitemid == "0") {
$(element).find(".prodTax").removeClass("required");
$(element).find(".txt_Account").removeClass("required");
$(element).addClass("hidden remove_item");
$(element).find(".selectedItemId").val(0);
}
else {
_this.parents('.item-row').remove();
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
bind(element, inventoryTypeId) {
if (inventoryTypeId != 5 && inventoryTypeId != 6 && inventoryTypeId != 7) {
element.find(".delete").on('click', function () {
var _this = $(this);
var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
if (_this.parents('.item-row').hasClass('SplitItem')) {
bootbox.confirm("You are about to delete the invoice items. Are you sure?", function (result) {
if (result == true) {
var orderid = _this.parents('.item-row').find('.orderItemId').val();
if ((orderid == 0 || orderid == "0" || orderid == undefined) && _this.parents('.item-row').find('.selectedItemId').val() != 0) {
let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
if (index == -1)
index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
if (index > -1) {
InvoiceItem.Instance().itemIds.splice(index, 1);
}
}
else if (orderid != 0) {
let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
if (index == -1)
index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
if (index > -1) {
InvoiceItem.Instance().itemIds.splice(index, 1);
}
var itemlength = InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number(_this.parents('.item-row').find('.selectedItemId').val()));
if (itemlength == undefined) {
if (_this.parents('.item-row').find('.selectedInvoiceItemId').val() != 0) {
InvoiceItem.Instance().deleted_invoiceItems.push(Number(_this.parents('.item-row').find('.selectedInvoiceItemId').val()));
}
}
}
var x = [];
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == _this.parents('.item-row').find('.selectedItemId').val()) {
x.push(i);
var index = InvoiceItem.Instance().dcItemIds.indexOf(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId);
if (index == -1)
index = InvoiceItem.Instance().dcItemIds.indexOf(Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId));
if (index > -1) {
InvoiceItem.Instance().dcItemIds.splice(index, 1);
}
if (InvoiceItem.Instance().dcItemIds.length == 0)
InvoiceItem.Instance().dcItemIds = [0];
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId != 0 && $('#hfInv_IsRetun').val() != "1") {
InvoiceItem.Instance().deleted_invoiceItems.push(Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId));
}
}
}
$('.item-row').each(function () {
if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true") {
if ($(this).find('.selectedInvoiceItemId').val() != 0)
InvoiceItem.Instance().deleted_invoiceItems.push(Number($(this).find('.selectedInvoiceItemId').val()));
$(this).remove();
}
});
for (var i = x.length - 1; i >= 0; i--) {
InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
}
_this.parents('.item-row').remove();
$("#txt_Adjustment").val("0");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
}
});
}
else if (invoiceitemid != 0) {
bootbox.confirm("You are about to delete the invoice items. Are you sure?", function (result) {
if (result) {
var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
var orderitemid = _this.parents('.item-row').find('.orderItemId').val();
var dcitemid = _this.parents('.item-row').find('.dcItemId').val();
if (_this.parents('.item-row').find('.selectedItemId').val() != 0) {
let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
if (index == -1)
index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
if (index > -1) {
InvoiceItem.Instance().itemIds.splice(index, 1);
}
if (orderitemid != 0 && dcitemid != 0) {
let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(_this.parents('.item-row').find('.dcItemId').val(), 0);
if (dcindex == -1)
dcindex = InvoiceItem.Instance().dcItemIds.indexOf(Number(_this.parents('.item-row').find('.dcItemId').val()), 0);
InvoiceItem.Instance().dcItemIds.splice(dcindex, 1);
if (InvoiceItem.Instance().dcItemIds.length == 0)
InvoiceItem.Instance().dcItemIds.push(0);
}
}
$('.item-row').each(function () {
if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true")
$(this).remove();
});
_this.parents('.item-row').remove();
$("#txt_Adjustment").val("0");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
}
});
}
else {
bootbox.confirm("You are about to delete the invoice item. Are you sure?", function (result) {
if (result) {
var dcitemid = _this.parents('.item-row').find('.dcItemId').val();
if (_this.parents('.item-row').find('.selectedItemId').val() != 0) {
let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
if (index == -1)
index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
if (index > -1) {
InvoiceItem.Instance().itemIds.splice(index, 1);
if (dcitemid != 0) {
let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(Number(_this.parents('.item-row').find('.dcItemId').val()), 0);
InvoiceItem.Instance().dcItemIds.splice(dcindex, 1);
if (InvoiceItem.Instance().dcItemIds.length == 0)
InvoiceItem.Instance().dcItemIds.push(0);
}
}
}
var x = [];
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == _this.parents('.item-row').find('.selectedItemId').val()) {
x.push(i);
}
}
for (var i = x.length - 1; i >= 0; i--) {
InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
}
$('.item-row').each(function () {
if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true")
$(this).remove();
});
_this.parents('.item-row').remove();
$("#txt_Adjustment").val("0");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
}
});
}
});
element.find(".prodPrice,.prodQuantity,.exciseAmount").blur(function () {
InvoiceItem.Instance().update_price(element);
});
element.find(".prodQuantity").change(function () {
InvoiceItem.Instance().CheckOfferForItem($(this));
});
element.find(".prodTax").blur(function () {
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
element.find(".prodPrice").blur(function () {
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
});
element.find(".prodQuantity").blur(function () {
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
});
element.find('.ddl_MultipleUOMs').change(function () {
InvoiceItem.Instance().update_row_total(element, true);
});
element.find(".inv_txtaddldiscount").blur(function () {
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
});
element.find(".inv_txtaddldiscount").blur(InvoiceItem.Instance().update_discount_total);
element.find(".btnOrder_DiscType").text('Val');
element.find(".btnInvoice_DiscType").change(function () {
if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val') {
element.find('#hfProdDiscountGroupId').val(0);
element.find('#hfProdDiscountGroupName').val('');
element.find('.inv_txtaddldiscount').prop('disabled', false);
}
else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%') {
element.find('#hfProdDiscountGroupId').val(0);
element.find('#hfProdDiscountGroupName').val('');
element.find('.inv_txtaddldiscount').prop('disabled', false);
if (Number(element.find("#inv_txtdiscount").val()) > 100) {
element.find("#inv_txtdiscount").val("100");
}
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().GetDiscounts();
});
}
else {
if (inventoryTypeId == 6) {
element.find(".delete").on('click', function () {
var dis = $(".fixedvalue").val();
var _this = $(this);
var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
if (selectedinvoiceitemid != 0) {
bootbox.confirm("You are about to delete the discount item. Are you sure?", function (result) {
if (result) {
var rowIndex = element.find(".rowIndex").val();
var invoiceitemid = _this.parents('.discount-row').find(".selectedInvoiceItemId").val();
_this.parents('.discount-row').remove();
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
}
else {
_this.parents('.discount-row').remove();
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
}
else if (inventoryTypeId == 5) {
element.find(".delete").on('click', function () {
var dis = $(".fixedvalue").val();
var _this = $(this);
var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
if (selectedinvoiceitemid != 0) {
bootbox.confirm("You are about to delete the coupon item. Are you sure?", function (result) {
if (result) {
var rowIndex = element.find(".rowIndex").val();
var invoiceitemid = _this.parents('.netdiscount-row').find(".selectedInvoiceItemId").val();
_this.parents('.netdiscount-row').remove();
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
}
else {
if (_this.parents('.OnInvoiceOfferItem').length != 0) {
InvoiceItem.Instance().isOfferChargeApplied = false;
$(".hdn_isofferchargeapplied").val('false');
}
_this.parents('.netdiscount-row').remove();
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
}
else if (inventoryTypeId == 7) {
element.find(".delete").on('click', function () {
var dis = $(".expfixedvalue").val();
var _this = $(this);
var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
if (selectedinvoiceitemid != 0) {
bootbox.confirm("You are about to delete the coupon item. Are you sure?", function (result) {
if (result) {
var rowIndex = element.find(".rowIndex").val();
var invoiceitemid = _this.parents('.expense-row').find(".selectedInvoiceItemId").val();
_this.parents('.expense-row').remove();
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
}
else {
_this.parents('.expense-row').remove();
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
}
$(".percentage").on('blur', function () {
InvoiceItem.Instance().update_discount_total();
});
$(".fixedvalue").on('blur', function () {
InvoiceItem.Instance().update_discount_total();
});
$(".expfixedvalue").on('blur', function () {
InvoiceItem.Instance().update_expense_total();
});
$(".exppercentage").on('blur', function () {
InvoiceItem.Instance().update_expense_total();
});
InvoiceItem.Instance().update_discount_total();
InvoiceItem.Instance().update_expense_total();
}
}
update_price(element) {
InvoiceItem.Instance().update_row_total(element, true);
}
update_row_total(element, checkavailability) {
var row = element;
var item = Number(row.find('.selectedItemId').val());
var inventorytypeid = 0;
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
inventorytypeid = response.result.InventoryTypeId;
if (item == 0) {
row.find(".prodQuantity").val(0);
row.find(".prodPrice").val(0);
MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
return false;
}
if (checkavailability == true) {
let BranchId = 0;
var SettingName = "";
if ($(".hdn_invoicetypeid").val() == "1") {
SettingName = "Bizgaze_Extension_Transact_Orders_Setting_Sales_CheckAvailability";
BranchId = Number($(".txtAutoComplete_billfromaddressid option:selected").val());
}
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
let LobId = Number($(".txtAutoComplete_lobid option:selected").val());
Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getOrderSettingsByLob(SettingName, LobId, BranchId).then(function (res) {
let IsCheckAvailability_Lob = res.result.SettingValue;
if (IsCheckAvailability_Lob == "Yes" || res.result == "") {
if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().OrderSettingId == 2 || InvoiceItem.Instance().AutoDc == true)) {
if ($(".hdn_invoiceid").val() == "0") {
if (Number(row.find('.prodQuantity').val()) > Number(row.find('.prodAvail').text()) && inventorytypeid != 2) {
MessageHelper.Instance().showError("Check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
if (Number(row.find('.prodAvail').text()) > 0)
row.find('.prodQuantity').val(row.find('.prodAvail').text());
else {
row.find('.prodQuantity').val("0");
}
}
}
else {
let Qty = Number(row.find('.prodQuantity').val());
let AvQty = Number(row.find('.prodAvail').text()) + Number(row.find('.Qty').val());
if (Qty > AvQty && inventorytypeid != 2) {
MessageHelper.Instance().showError("Check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
row.find('.prodQuantity').val(row.find('.Qty').val());
}
}
}
if (row.find('.orderItemId').val() != 0 && !row.hasClass('.SplitItem')) {
if (Number(row.find('.prodQuantity').val()) > Number(row.find('.maxQty').val())) {
row.find('.prodQuantity').val(Number(row.find('.maxQty').val()));
InvoiceItem.Instance().update_row_total(element, checkavailability);
InvoiceItem.Instance().GetDiscounts();
}
}
}
});
});
}
var rowTotal = 0;
var rowTotalwithAdjustment = 0;
if (row.find('.prodPrice').val() != undefined && row.find('.prodQuantity').val() != undefined) {
rowTotal = row.find('.prodPrice').val().replace("$", "") * (Number(row.find('.prodQuantity').val()));
rowTotalwithAdjustment = row.find('.prodPrice').val().replace("$", "") * (Number(row.find('.prodQuantity').val()));
}
rowTotal += Number(row.find('.hfRowTotalAdjustment').val());
rowTotalwithAdjustment += Number(row.find('.hfRowTotalAdjustment').val());
var exciseAmount = element.find(".exciseAmount").val();
if (exciseAmount != undefined) {
rowTotal += Number(exciseAmount);
rowTotalwithAdjustment += Number(exciseAmount);
}
var asbAdjAmt = 0;
asbAdjAmt = row.find('.hfItemAssesableAdjustmentVal').val();
if (!isNaN(asbAdjAmt))
rowTotalwithAdjustment += Number(asbAdjAmt);
rowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotal, 2);
rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
if (isNaN(rowTotal)) {
element.find('.prodTotalPrice').html("N/A");
element.find('.hfRowTotal').val("0");
element.find('.hfRowTotalwithAdjustment').val("0");
}
else {
element.find('.hfRowTotal').val(rowTotal);
element.find('.hfRowTotalwithAdjustment').val(rowTotalwithAdjustment);
element.find('.prodTotalPrice').html(rowTotal);
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
InvoiceItem.Instance().update_discount_total();
InvoiceItem.Instance().update_expense_total();
});
});
}
CheckOfferForItem(control) {
var element = control.parents('.item-row');
if (element.find('.orderItemId').val() == 0) {
if ($(".hdn_invoicetypeid").val() == "1") {
if (Number(element.find('.prodQuantity').val()) <= Number(element.find('.prodAvail').text())) {
InvoiceItem.Instance().GetPlanItems(element.find('.selectedItemId').val(), element.find('.prodQuantity').val(), element);
}
}
else if ($(".hdn_invoicetypeid").val() == "2") {
InvoiceItem.Instance().GetPlanItems(element.find('.selectedItemId').val(), element.find('.prodQuantity').val(), element);
}
}
}
GetPlanItems(ItemId, Quantity, element) {
var contactId = $(".hdn_organizationid").val();
if (contactId == 0)
contactId = $(".hfAutoCompleteId_orgcontactid").val();
var invoiceapplytype = 1;
var RowTotal = Number(element.find('.prodTotalPrice').text());
if ($(".hdn_invoicetypeid").val() == "2") {
invoiceapplytype = 2;
RowTotal = Number(element.find(".txtRowTotalwithAdjustment").val());
}
$('.item-row').each(function () {
if ($(this).find('.hfOfferedItemId').val() == ItemId) {
if ($(this).find('.selectedInvoiceItemId').val() != "0")
InvoiceItem.Instance().deleted_invoiceItems.push(Number($(this).find('.selectedInvoiceItemId').val()));
$(this).remove();
}
});
let ApplyDate = moment($('.hfdate_journaldate').val().toString(), "YYYY/MM/DD").format("YYYY-MM-DD");
Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getoffers(ItemId, Number(contactId), Quantity, invoiceapplytype, RowTotal, ApplyDate).then(function (result) {
var response = result.result;
if (response.length > 0) {
for (var j = 0; j < response.length; j++) {
if (element.hasClass('SplitItem')) {
var RowTotal = 0;
var rowDiscount = 0;
for (var k = 0; k < InvoiceItem.Instance().SplitedInvoiceItemList.length; k++) {
if (InvoiceItem.Instance().SplitedInvoiceItemList[k].itemId == ItemId) {
var discValue = 0;
var discPercent = 0;
var Itemrow = InvoiceItem.Instance().SplitedInvoiceItemList[k];
if (response[j].PayoutValue > 0) {
discValue = response[j].PayoutValue;
Itemrow.addlDiscountValue = discValue;
Itemrow.addlDiscountPercent = 0;
}
else if (response[j].PayoutPercent > 0) {
discPercent = response[j].PayoutPercent;
Itemrow.addlDiscountPercent = discPercent;
Itemrow.addlDiscountValue = 0;
}
var TotalLineAmount = (Number(Itemrow.quantity) * Number(Itemrow.unitPrice)) + Number(Itemrow.exciseAmount) + Number(Itemrow.Adjustment) + Number(Itemrow.assesableAdjustment);
var NonExciseAmount = TotalLineAmount - Number(Itemrow.exciseAmount);
var DiscountAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(NonExciseAmount * (Number(Itemrow.addlDiscountPercent) / 100) + (Number(Itemrow.quantity) * Number(Itemrow.addlDiscountValue)), 2);
Itemrow.DiscountedAmount = DiscountAmount;
Itemrow.TotalAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((TotalLineAmount - Number(DiscountAmount)), 3);
RowTotal += Number(Itemrow.TotalAmount);
rowDiscount += Number(DiscountAmount);
}
}
if ($(".hdn_invoicetypeid").val() == "2") {
element.find(".txtRowTotalwithAdjustment").val();
element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
element.find('#inv_txtdiscount').val();
element.find('#inv_txtdiscount').val(rowDiscount);
}
else {
element.find('.prodTotalPrice').text('');
element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
element.find('#inv_txtdiscount').val();
element.find('#inv_txtdiscount').val(rowDiscount);
}
}
else {
var discValue = 0;
var discPercent = 0;
if (response[j].PayoutValue > 0) {
discValue = response[j].PayoutValue;
element.find(".btnInvoice_DiscType option[value='Val']").prop("selected", true);
element.find('.inv_txtaddldiscount').val(discValue);
}
else if (response[j].PayoutPercent > 0) {
discPercent = response[j].PayoutPercent;
element.find(".btnInvoice_DiscType option[value='%']").prop("selected", true);
element.find('.inv_txtaddldiscount').val(discPercent);
}
}
if (response[j].ItemVolumePayouts.length > 0) {
var OfferItems = response[j].ItemVolumePayouts;
for (var i = 0; i < OfferItems.length; i++) {
var emptyRow = {
orderItemId: 0,
invoiceItemId: 0,
itemName: OfferItems[i].ItemName,
itemId: OfferItems[i].ItemId,
itemSKU: "",
unitName: "",
packSize: 0,
packCount: 0,
packs: 0,
quantity: OfferItems[i].Quantity,
availPacks: 0,
availQty: 0,
listPrice: 0,
description: OfferItems[i].Description,
taxGroupName: "",
taxGroupId: 0,
isTaxInclusive: $("#hfIsTaxInclusive").val(),
addlDiscountPercent: OfferItems[i].Discount,
addlDiscountValue: 0,
creditNote: 0,
priceListId: 0,
batchId: 0,
unitPrice: 0,
invoiceallocations: null,
exciseInvoiceItem: null,
accountId: 0,
accountName: "",
walletId: 0,
Adjustment: 0,
TariffNo: "",
exciseAmount: 0,
discountName: "",
discountId: 0,
refNo: "",
DiscountGroupId: 0,
DiscountGroupName: '',
RefInvoiceItemId: 0,
MrpId: 0,
taxAdjustment: 0,
assesableAdjustment: 0,
inventoryTypeId: 0,
dcItemId: 0,
TotalRowAmount: 0,
maxQty: 0,
OfferItemId: ItemId,
IsFoc: true,
};
InvoiceItem.Instance().addDataRow(emptyRow, false);
}
}
}
}
});
}
TotalAdjustment() {
if ($('#chk_AutoAdjustment').is(':checked')) {
var total = $('.nettotal').text();
var splitTotal = total.split('.');
var AdjustmentValue = 0;
var splitedAdjestment = 0;
$("#txt_Adjustment").val(0);
$(".hdn_adjustment").val(0);
if (!isNaN(Number($('#txt_Adjustment').val()))) {
AdjustmentValue = Number($('#txt_Adjustment').val());
}
if (Number(splitTotal[1]) > 0) {
if (Number(splitTotal[1]) >= 50) {
splitedAdjestment = (100 - Number(splitTotal[1])) / 100;
AdjustmentValue += splitedAdjestment;
$('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
$(".hdn_adjustment").val($('#txt_Adjustment').val());
$("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
$('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
}
else {
splitedAdjestment = Number(splitTotal[1]) / 100;
AdjustmentValue -= splitedAdjestment;
$('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2));
$(".hdn_adjustment").val($('#txt_Adjustment').val());
$("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
$('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
}
}
}
else {
$("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($('#txt_Adjustment').val()), 2));
$('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number($('.nettotal').text()) + Number($('#txt_Adjustment').val())), 2));
}
}
update_discount_total() {
var item_total = Number($("#grosstotal").html()) - Number($("#totalItemDiscount").html());
var nettotal = Number($("#totalTax").text()) + Number(item_total);
var sub_dis_total = 0;
var prev_dis_total = 0;
$(".discount-row,.netdiscount-row").each(function () {
if ($(this).find(".percentage").val() != undefined) {
var ele = $(this);
var tt = prev_dis_total;
if (!isNaN(tt))
sub_dis_total += Number(tt);
var percent = ele.find(".percentage").val();
var value = ele.find(".fixedvalue").val();
var adjustment = 0;
if (percent == "")
percent = 0;
if (value == "")
value = 0;
var totaldiscount = 0;
var totalElement = $(this).find(".netdiscount-row-total");
if (totalElement.length != 0) {
totaldiscount = (Number(percent) * Number(nettotal - sub_dis_total) / 100) + Number(value) + Number(adjustment);
}
else
totaldiscount = (Number(percent) * Number(item_total - sub_dis_total) / 100) + Number(value) + Number(adjustment);
ele.find(".discount-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaldiscount, 2));
ele.find(".netdiscount-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaldiscount, 2));
prev_dis_total = totaldiscount;
}
});
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
update_expense_total() {
var item_total = Number($("#grosstotal").html()) - Number($("#totalItemDiscount").html());
var nettotal = Number($("#totalTax").text()) + Number(item_total);
var sub_dis_total = 0;
var prev_dis_total = 0;
$(".expense-row").each(function () {
if ($(this).find(".exppercentage").val() != undefined) {
var ele = $(this);
var tt = prev_dis_total;
if (!isNaN(tt))
sub_dis_total += Number(tt);
var percent = ele.find(".exppercentage").val();
var value = ele.find(".expfixedvalue").val();
var adjustment = 0;
if (percent == "")
percent = 0;
if (value == "")
value = 0;
var totalexpense = (Number(percent) * Number(nettotal - sub_dis_total) / 100) + Number(value) + Number(adjustment);
ele.find(".expense-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalexpense, 2));
prev_dis_total = totalexpense;
}
});
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
RefreshItemRowDetaisl(element) {
if (element.filter('.SplInvoiceItemRow').length > 0) {
Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance().update_Discount(element);
var row = InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.invoiceItemId == element.find(".hf_selectedInvoiceItemId").val());
if (row != undefined) {
row.assesableAdjustment = element.find('.hf_ItemAssesableAdjustmentVal').val();
row.TotalAmount = element.find(".hf_RowTotal").val();
}
Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance().updateQuantity();
InvoiceItem.Instance().update_total();
}
else {
InvoiceItem.Instance().update_total();
}
}
editInvItemTaxAllocs(invoiceItemId, taxGroupId, itemId, orderItemId, element) {
var prvs = InvoiceItem.Instance().invItemTaxAdjustmentList;
var obj = {
invoiceItemId: invoiceItemId,
taxGroupId: taxGroupId,
itemId: itemId,
orderItemId: orderItemId,
element: element,
};
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/components/invoices/invoiceitemtaxalloc.js", function () {
Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", Bizgaze.Apps.Transact.Components.Invoices.InvoiceItemTaxAloc.Instance(), null, Unibase.Platform.Helpers.Size.Large);
});
InvoiceItem.Instance().invItemTaxAdjustmentList = prvs;
}
GetCustomerTurnOver() {
$(".txt_tcsadjustment").val("0");
$("#chk_tcsapplied").unbind();
$(".number_tcsamount").prop("disabled", true);
$(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
$("#chk_tcsapplied").change(function () {
if ($(this).prop('checked') == true && InvoiceItem.Instance().EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
$("#hdnchk_tcsapplied").val("false");
$('#chk_tcsapplied').prop('checked', false);
}
else {
if ($('#chk_AutoAdjustment').prop("checked") == true) {
$("#txt_Adjustment").val(0);
$(".hdn_adjustment").val(0);
}
if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
if (result) {
$("#div_tcstaxrate").removeClass("hidden");
$(".div_tcsadjustment").removeClass("hidden");
$("#div_tcsamount").removeClass("hidden");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
else {
$("#div_tcstaxrate").addClass("hidden");
$(".div_tcsadjustment").addClass("hidden");
$("#div_tcsamount").addClass("hidden");
$('#chk_tcsapplied').prop('checked', false);
$("#hdnchk_tcsapplied").val("false");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
});
}
else if ($(this).prop('checked') == true) {
$("#div_tcstaxrate").removeClass("hidden");
$(".div_tcsadjustment").removeClass("hidden");
$("#div_tcsamount").removeClass("hidden");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
else {
$("#div_tcstaxrate").addClass("hidden");
$(".div_tcsadjustment").addClass("hidden");
$("#div_tcsamount").addClass("hidden");
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
}
});
$(".txt_tcsadjustment").unbind();
$(".txt_tcsadjustment").blur(function () {
if ($('#chk_AutoAdjustment').prop("checked") == true) {
$("#txt_Adjustment").val(0);
$(".hdn_adjustment").val(0);
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
});
$("#div_tcstaxrate").addClass("hidden");
$(".div_tcsadjustment").addClass("hidden");
$("#div_tcsamount").addClass("hidden");
$("#chk_tcsapplied").prop("checked", false);
$("#chk_tcsapplied").prop("disabled", false);
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCustomerTurnOver($(".hdn_organizationid").val(), $(".hdn_invoiceid").val(), InvoiceItem.Instance().formatDate($(".date_journaldate").val()), $(".hdn_invoicetypeid").val()).then(function (response) {
if (response.result != null) {
$(".number_tcstaxrate").val(response.result.TaxRate);
if (response.result.TCSTaxCodeId != 0) {
$(".hdn_tcstaxcodeid").val(response.result.TCSTaxCodeId);
$(".hdn_tcstaxcodeaccountid").val(response.result.TCSTaxCodeAccountId);
$(".number_tcstaxrate").prop("disabled", true);
}
InvoiceItem.Instance().TurnOver = response.result.TurnOver;
InvoiceItem.Instance().ContactTcsEnable = response.result.Enable;
InvoiceItem.Instance().EnableTenantTcs = response.result.EnableTenantTcs;
InvoiceItem.Instance().PanAvailable = response.result.PanAvailable;
InvoiceItem.Instance().TaxRate = response.result.TaxRate;
if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
if (InvoiceItem.Instance().ContactTcsEnable == true && InvoiceItem.Instance().EnableTenantTcs == true) {
$("#chk_tcsapplied").prop("checked", true);
$("#hdnchk_tcsapplied").val("true");
$("#div_tcstaxrate").removeClass("hidden");
$(".div_tcsadjustment").removeClass("hidden");
$("#div_tcsamount").removeClass("hidden");
$(".number_tcsamount").prop("disabled", true);
}
else if (InvoiceItem.Instance().TurnOver > 5000000 && $(".hdn_invoicetypeid").val() == "1") {
$("#chk_tcsapplied").prop("checked", true);
$("#chk_tcsapplied").prop("disabled", "disabled");
$("#hdnchk_tcsapplied").val("true");
$("#div_tcstaxrate").removeClass("hidden");
$(".div_tcsadjustment").removeClass("hidden");
$("#div_tcsamount").removeClass("hidden");
$(".number_tcsamount").prop("disabled", true);
}
}
else if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") {
$("#chk_tcsapplied").prop("checked", false);
$("#hdnchk_tcsapplied").val("false");
$("#div_tcstaxrate").addClass("hidden");
$(".div_tcsadjustment").addClass("hidden");
$("#div_tcsamount").addClass("hidden");
}
if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_RefInvoiceId').val() == 0 && $("#hf_AppSettingName").val() == "Create Return") {
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(($(".hdn_invoicetypeid").val())).then(function (res) {
if (res.result != null && res.result != "") {
InvoiceItem.Instance().TaxRate = res.result.TcsTaxRate;
$(".number_tcstaxrate").val(res.result.TcsTaxRate);
$(".hdn_tcstaxcodeid").val(response.result.TcsTaxCodeId);
if (res.result.TcsTaxCodeId != 0) {
$(".number_tcstaxrate").prop("disabled", true);
}
$(".number_tcsamount").prop("disabled", true);
}
});
}
}
});
}
bindContactName() {
Unibase.Platform.Forms.Managers.TagManager.Instance().GetTagItemsByUserId(Unibase.Platform.Membership.Infos.Identity.getCurrentUser().userId).then(function (response) {
if (response.result.length == 1) {
InvoiceItem.instance.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByTagGroupId(response.result[0].TagGroupId).then(function (res) {
let LobId = res.result.LobId;
Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByLobId(LobId).then(function (result) {
if (result.result != null) {
if (result.result.DefaultContactId != 0) {
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getOrgContact(result.result.DefaultContactId).then(function (response) {
if (response.result != null) {
if (response.result.OrgContactName == null)
response.result.OrgContactName = "";
var _Name = new Option(response.result.OrgContactName, response.result.OrgContactId.toString(), false, false);
$(".txtAutoComplete_orgcontactid").append(_Name).trigger("change");
$(".hfAutoCompleteId_orgcontactid").val(response.result.OrgContactId);
InvoiceItem.Instance().LoadContactDetails();
}
});
});
}
}
});
});
});
}
});
}
GetDiscounts() {
if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3")) {
let contactid = Number($(".hdn_organizationid").val());
let invoicedate = moment($('.date_journaldate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
if ($(".hdn_invoicetypeid").val() == "3")
invoicedate = moment($('.date_refdate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
var ItemList = [];
$(".InvoiceItems").find(".item-row").each(function () {
if (!$(this).hasClass('SplitItem')) {
if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
var Quantity = Number($(this).find(".prodQuantity").val());
let ItemId = Number($(this).find(".selectedItemId").val());
ItemList.push({
ItemId: ItemId,
Quantity: Number(Quantity),
ContactId: contactid,
InvoiceDate: invoicedate
});
}
}
});
for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
ItemList.push({
ItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId),
Quantity: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity),
ContactId: contactid,
InvoiceDate: invoicedate
});
}
Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getdiscounts(ItemList).then(function (response) {
var data = response.result;
var InvItemId = 0;
var discription = "";
if ($(".netdiscount-row[style='pointer-events:none']").length == 0 && $(".hdn_invoicetypeid").val() == "3") {
InvoiceItem.Instance().isOfferChargeApplied = false;
if (data != null)
data.PayoutValue == 0;
}
$('.netdiscount-row').each(function () {
var invoiceitemid = $(this).find(".selectedInvoiceItemId").val();
if ((data != null && (data.PayoutValue > 0 || InvoiceItem.Instance().isOfferChargeApplied) && $(this).find('.selectedItemId').val() != undefined && Number($(this).find('.selectedItemId').val()) != 0 && data.ItemId == Number($(this).find('.selectedItemId').val())) || (InvoiceItem.Instance().isOfferChargeApplied && invoiceitemid != undefined && invoiceitemid != 0 && data.ItemId == Number($(this).find('.selectedItemId').val()))) {
$(this).remove();
if (invoiceitemid != undefined || invoiceitemid != 0) {
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
InvItemId = Number(invoiceitemid);
discription = $(this).find('.discountDesc').val().toString();
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
});
if (data != null && data.PayoutValue == 0) {
if ($(".netdiscount-row[style='pointer-events:none']").length > 0) {
var invoiceitemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedInvoiceItemId").val();
$(".netdiscount-row[style='pointer-events:none']").remove();
if (invoiceitemid != undefined || invoiceitemid != 0) {
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
InvItemId = Number(invoiceitemid);
$(".hdn_isofferchargeapplied").val('false');
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
}
if ((data != null && data.PayoutValue > 0)) {
if ($(".netdiscount-row[style='pointer-events:none']").length > 0) {
var itemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedItemId").val();
if (data.ItemId != itemid) {
var invoiceitemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedInvoiceItemId").val();
$(".netdiscount-row[style='pointer-events:none']").remove();
if (invoiceitemid != undefined || invoiceitemid != 0) {
InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
InvItemId = Number(invoiceitemid);
}
InvoiceItem.Instance().update_total();
InvoiceItem.Instance().TotalAdjustment();
}
}
let Index = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.findIndex(x => x == InvItemId);
if (Index != -1) {
Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.splice(Index, 1);
}
var itemRow = {
orderItemId: 0,
invoiceItemId: InvItemId,
itemName: data.ItemName,
itemId: data.ItemId,
itemSKU: '',
unitName: "",
packSize: 0,
packCount: 0,
packs: 0,
quantity: 0,
availPacks: 0,
availQty: 0,
listPrice: 0,
description: discription,
taxGroupName: "",
taxGroupId: 0,
isTaxInclusive: $("#hf_istaxinclusive").val(),
addlDiscountPercent: 0,
addlDiscountValue: data.PayoutValue,
creditNote: 0,
priceListId: 0,
batchId: 0,
unitPrice: 0,
invoiceallocations: null,
exciseInvoiceItem: null,
accountId: 0,
accountName: "",
walletId: 0,
Adjustment: 0,
IsFoc: false,
TariffNo: "",
exciseAmount: 0,
discountName: "",
discountId: 0,
refNo: "",
DiscountGroupId: 0,
DiscountGroupName: '',
RefInvoiceItemId: 0,
MrpId: 0,
taxAdjustment: 0,
assesableAdjustment: 0,
inventoryTypeId: 5,
dcItemId: 0,
TotalRowAmount: 0,
maxQty: 0,
OfferItemId: 0
};
InvoiceItem.instance.addDataRow(itemRow, false);
}
});
}
}
GetOnInvoiceDiscountItem(element) {
if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3") {
var itemid = element.find('.selectedItemId').val();
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemById(Number(itemid)).then(function (response) {
var data = response.result;
let invoiceid = $(".hdn_invoiceid").val();
if (invoiceid == undefined || invoiceid == "null")
invoiceid = 0;
if (data != null && !data.Sellable && !data.Purchasable)
element.attr("style", "pointer-events:none");
if (invoiceid == "0")
element.addClass("OnInvoiceOfferItem");
});
}
}
IsCustomerIndustrial(LobId, OrganizationId) {
var url1 = "apis/v4/bizgaze/transact/invoice/checkisenablesalespipeline/invoicetype/" + $(".hdn_invoicetypeid").val() + "/lobid/" + LobId + "/organizationid/" + OrganizationId;
Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getIsEnableSalesPipeline(url1).then(function (response) {
if (response.result == false) {
$(".section_Ebs").addClass("hidden");
}
else {
$(".section_Ebs").removeClass("hidden");
}
});
}
loadChangeTaxGroupAutoComplete() {
var hfTaxgroup = $("#hdn_changetaxgroup");
AutoCompleteHelper.getHelper().Create("#change_taxgroup", hfTaxgroup, _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
});
}
ShowOrHideEInvoiceButton() {
let instance = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance();
var installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
var invoiceid = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + installedAppId + "_invoiceid").Value);
instance.fileCacheHelper.loadJsFiles(["apps/transact/managers/einvoice/einvoicemanager.js"], function () {
Bizgaze.Apps.Transact.Managers.EInvoiceManager.Instance().geteinvoicebyinvoiceid(invoiceid).then(function (res) {
if (res.result != null) {
if (res.result.EInvoiceStatusId == 2 || res.result.AckNo == null)
$(".DetailSetting_" + installedAppId + "_e-Invoice").removeClass("hidden");
else
$(".DetailSetting_" + installedAppId + "_e-Invoice").addClass("hidden");
}
});
});
}
static Instance() {
if (this.instance === undefined) {
this.instance = new InvoiceItem();
}
return this.instance;
}
}
Controls.InvoiceItem = InvoiceItem;
})(Controls = Transact.Controls || (Transact.Controls = {}));
})(Transact = Apps.Transact || (Apps.Transact = {}));
})(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
})(Bizgaze || (Bizgaze = {}));