' +
'
' +
'
' +
'
' +
'' +
'' +
'
' +
'
' +
'
' +
'
' +
'
' +
'';
if (row.accountId != 0) {
html += '' +
'' +
'';
}
else {
html += '' +
'' +
'';
}
html += '
' +
'
' +
'
' +
'' +
'' + row.availQty + '' +
'
' +
'
' +
'
';
$(".item-row:last").after(html);
var element = $(".item-addedrow:last");
$("#spn_InvoiceItem_" + this.rowIndex).click(function () {
ItemDetails.Instance().loadMrp(element);
});
ItemDetails.instance.itemsAutoComplete(element);
$('.inv_txtaddldiscount').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();
});
$('.prodQuantity').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();
});
$('.prodPrice').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();
});
ItemDetails.Instance().RemoveItem(element);
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");
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("#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 (!element.hasClass('SplitItem')) {
}
if (row.TotalRowAmount != 0) {
if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") {
element.find(".hfRowTotalwithAdjustment").val();
}
else {
element.find('.prodTotalPrice').text('');
}
}
if (row.TotalDiscount != 0 && row.TotalDiscount != undefined)
if (row.invoiceItemId != "0" && ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "SalesReturn" || $("#hfInv_Invoicetype").val() == "DebitNote")) {
var x = element.find('.hfRowTotalwithAdjustment');
element.find('.AdjustmentRow').click(function () {
});
}
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 == 7) {
element = $(".netdiscount-addedrow:last");
}
else {
}
}
}
loadMrp(element) {
var instance = this;
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/controls/itemdetails/item.mrp.js", function () {
instance.navigationHelper.popup(0, "", Unibase.Forms.Controls.MRPDetails.Instance(), null, Unibase.Platform.Helpers.Size.Large);
Controls.MRPDetails.element = element;
Unibase.Forms.Controls.MRPDetails.Instance().init(element, "", 2);
});
}
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";
var url = _appsettings.server_url() + '/apis/v4/unibase/platform/forms/getformsautocomplete';
AutoCompleteHelper.getHelper().Create("#txt_prodTax_" + this.rowIndex, hfProdTax, url, function (response) {
var data = response;
});
var url = _appsettings.server_url() + '/apis/v4/unibase/platform/forms/getformsautocomplete';
AutoCompleteHelper.getHelper().Create("#txt_Account_" + this.rowIndex, hfAccount, url, function (response) {
var data = response;
});
if (taxgrpid != 0) {
$("#hf_TaxGroupId").val(taxgrpid);
if ($("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected").length == 0) {
$("#ddl_TaxGroupId").append(new Option(taxgrptext, taxgrpid, true));
}
else {
$("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected");
}
}
if (accid != 0) {
$("#hf_AccountId").val(accid);
if ($("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected").length == 0) {
$("#ddl_AccountId").append(new Option(acctext, accid, true));
}
else {
$("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected");
}
}
}
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;
$('.expenserow-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));
itemdiscount_total += discountAmount;
var discountedAmount = Number(totalLineAmount) - Number(discountAmount);
totalDiscountAmount += Number(discountAmount);
element.find(".hfDiscountedAmount").val(discountAmount);
if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") {
element.find(".txtRowTotalwithAdjustment").val(totalLineAmount - discountAmount);
}
else
element.find(".prodTotalPrice").html((totalLineAmount - discountAmount).toString());
}
});
if (this.SplitedInvoiceItemList.length > 0) {
for (var i = 0; i < this.SplitedInvoiceItemList.length; i++) {
var totalline_Amount = Number(this.SplitedInvoiceItemList[i].quantity * this.SplitedInvoiceItemList[i].unitPrice);
var discountAmount = 0;
var nonexciseAmount = totalline_Amount - Number(this.SplitedInvoiceItemList[i].exciseAmount);
discountAmount = (Number(nonexciseAmount) * Number(this.SplitedInvoiceItemList[i].addlDiscountPercent) / 100)
+ (Number(this.SplitedInvoiceItemList[i].quantity) * Number(this.SplitedInvoiceItemList[i].addlDiscountValue));
discountAmount = Number(discountAmount);
totalLineAmount_total += Number(this.SplitedInvoiceItemList[i].quantity * this.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();
if (!isNaN(totalLineAmount))
totalNonDiscountedAmount += Number(totalLineAmount);
discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
var assesableAmount = totalLineAmount - discountAmount;
assesableAmount = Number(assesableAmount);
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 ($("#hfId_IsTaxInclusive").val() == "true") {
for (var i = 0; i < taxpercentarray.length; i++) {
var taxPercentModel1 = taxpercentarray[i];
var taxPercentM1 = Number(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 i = 0; i < taxpercentarray.length; i++) {
var taxPercentModel = taxpercentarray[i];
var taxPercentM = taxPercentModel.split(":");
var ledgerid = taxPercentM[0];
var taxPercent = Number(taxPercentM[1]);
var taxAmt = 0;
if ($("#hfId_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 += taxAmt;
}
});
if (!ledgerexists) {
taxAmounts.push({
LedgerId: ledgerid,
TaxAmount: taxAmt,
});
}
}
}
totalAmount += Number(totalLineAmount);
totalQty += Number(quantity);
}
});
if (this.SplitedInvoiceItemList.length > 0) {
for (var i = 0; i < this.SplitedInvoiceItemList.length; i++) {
var TotalLineAmount = Number(this.SplitedInvoiceItemList[i].quantity * this.SplitedInvoiceItemList[i].unitPrice);
var quantiy = Number(this.SplitedInvoiceItemList[i].quantity);
if (!isNaN(TotalLineAmount))
totalNonDiscountedAmount += Number(TotalLineAmount);
var discountAmount = Number(this.SplitedInvoiceItemList[i].addlDiscountValue) + (Number(TotalLineAmount) * Number(this.SplitedInvoiceItemList[i].addlDiscountPercent) / 100);
var assesableAmount = TotalLineAmount - discountAmount;
assesableAmount = Number(assesableAmount);
var taxPercents = '';
var instance = this;
if (this.SplitedInvoiceItemList[i].TaxPercent == undefined || this.SplitedInvoiceItemList[i].TaxPercent == 0) {
var element = "";
$(".SplitItem").each(function () {
if ($(this).find(".selectedItemId").val() == instance.SplitedInvoiceItemList[i].itemId) {
element = $(this);
taxPercents = element.find('.hfProdTaxPercent').val();
}
});
}
else
taxPercents = instance.SplitedInvoiceItemList[i].TaxPercent;
if (taxPercents != undefined && taxPercents != '')
var taxpercentarray = taxPercents.split(',');
var assesableAdjustment = instance.SplitedInvoiceItemList[i].assesableAdjustment;
var taxAdjustment = instance.SplitedInvoiceItemList[i].taxAdjustment;
if (!isNaN(taxAdjustment))
totalTaxAdjustment += Number(taxAdjustment);
if (!isNaN(assesableAdjustment))
totalAsseableAdjustment += Number(assesableAdjustment);
var cumlTax = 0;
var cumtaxtotal = 0;
if ($("#hfId_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++) {
var taxPercentModel = taxpercentarray[k];
var taxPercentM = taxPercentModel.split(":");
var ledgerid = taxPercentM[0];
var taxPercent = taxPercentM[1];
var taxAmt = 0;
if ($("#hfId_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 += 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)) {
taxAmount += Number(taxAmounts[i].TaxAmount);
}
}
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;
subtotal = subtotal;
var overalldiscount = 0;
var taxadjustment = 0;
if (!isNaN(Number($('#txt_TaxAdjustment').val()))) {
taxadjustment = Number($('#txt_TaxAdjustment').val());
}
totaltax = Number(totaltax) + Number(taxadjustment);
$('#totalTax').html(totaltax);
$('#grosstotal').html(grosstotal);
$('#totalItemDiscount').html(itemdiscount_total);
$('#totalDiscount').html(totalDiscountAmount);
$("#totalinvoiceqty").html(totalQty);
var expense = 0;
if (!isNaN(Number($('#txtOverallExpenseAmount').val()))) {
expense = Number($('#txtOverallExpenseAmount').val());
$("#totalexpense").text(expense);
}
var adjustment = 0;
if (!isNaN(Number($('#txt_Adjustment').val()))) {
adjustment = Number($('#txt_Adjustment').val());
$("#span_Adjustment").text(adjustment);
}
var nettotal = Number(subtotal) + Number(addexpenserow_total) - Number(overalldiscount) - Number(netadddiscountrow_total) + Number(adjustment);
if ($("#hfId_IsTaxInclusive").val() == "false")
nettotal += Number(totaltax);
if ($("#hfId_IsTaxInclusive").val() == "true") {
subtotal = Number(subtotal) - Number(totalTaxAmount);
}
$('#subtotal').html(subtotal);
$('.nettotal').html(nettotal);
ItemDetails.Instance().totalAdjustment();
}
totalAdjustment() {
if ($('#chk_AutoAdjustment').is(':checked')) {
var total = $('.nettotal').text();
var splitTotal = total.split('.');
var AdjustmentValue = 0;
var splitedAdjestment = 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();
}
else {
splitedAdjestment = Number(splitTotal[1]) / 100;
AdjustmentValue -= splitedAdjestment;
$('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
}
}
}
}
itemsAutoComplete(element) {
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/default/components/details/details.js", function () {
});
var txtAutoSearchCtrl = element.find(".prodName");
var hdnOrderItemId = element.find(".orderItemId");
var hdnDcItemId = element.find(".dcItemId");
var hdnSelectedItemId = element.find(".selectedItemId");
if (hdnSelectedItemId.val() != 0 && hdnSelectedItemId.val() != "") {
this.itemIds.push(hdnSelectedItemId.val());
element.find(".hfoldItemId").val(hdnSelectedItemId.val());
}
this.itemIds = [];
var hdnAutoId = hdnSelectedItemId;
var orderid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val();
var dcid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_DcId").val();
var invoiceid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_InvoiceId").val();
if (invoiceid == undefined || invoiceid == "null")
invoiceid = 0;
var url = "";
var OrdersettingId = 0;
var url = _appsettings.server_url() + '/apis/v4/unibase/transact/items/getitems/itemids/' + ',' + '/lobid/' + 100284890000001;
AutoCompleteHelper.getHelper().Create("#txt_item_" + this.rowIndex, "#hf_txtitem_" + this.rowIndex, url, function (response) {
var data = response;
ItemDetails.Instance().update_total();
});
element.find(".div_SplitInvoiceItem").removeClass("hidden");
ItemDetails.instance.loadTaxGroupAutoComplete(element);
}
RemoveItem(element) {
var rowIndex = element.find(".rowIndex").val();
element.find(".delete").on('click', function () {
var _this = element.find(".delete");
var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
_this.parents('.item-row').remove();
var count = 1;
$(".InvoiceItems").find(".item-addedrow").each(function () {
$(this).find(".rowIndex").val(count);
$(this).find(".selectedItemId").attr("id", "hf_txtitem_" + count);
$(this).find(".prodName").attr("id", "txt_item_" + count);
$(this).attr("id", "div_itemAddedRow_" + count);
count++;
});
});
}
deleteRow(rowid, itemid) {
var ids = this.deletedItems.push(itemid);
ItemDetails.instance.deleteInvoiceItem(ids);
}
deleteInvoiceItem(invItemIds) {
for (var i = 0; i < invItemIds.length; i++) {
}
}
static Instance() {
if (this.instance === undefined) {
this.instance = new ItemDetails();
}
return this.instance;
}
}
Controls.ItemDetails = ItemDetails;
})(Controls = Forms.Controls || (Forms.Controls = {}));
})(Forms = Unibase.Forms || (Unibase.Forms = {}));
})(Unibase || (Unibase = {}));