';
$("#" + containerid).html(html);
if (prop.PropertySettings != null) {
for (var i = 0; i < prop.PropertySettings.length; i++) {
var data = prop.PropertySettings[i];
if (data.ControlPropertyName == "ControlType" && data.ControlPropertyValue != "") {
this.controlType = data.ControlPropertyValue;
}
}
}
if (this.controlType == "1") {
instance.journalTypeId = 2;
}
else if (this.controlType == "2") {
instance.journalTypeId = 1;
}
else if (this.controlType == "3") {
instance.journalTypeId = 3;
}
}
loadInvoiceWallets(response) {
var instance = this;
var trnId = instance.transactionId;
var result = response;
var element = $('.transactonList_item_TRN' + trnId + '');
var divWallets = element.find('.divWallet_List');
$(divWallets).empty();
$(divWallets).html('
');
var walletsTotalBal = 0;
var adjustdTotalAmount = 0;
if (result.length != 0) {
for (var i = 0; i < result.length; i++) {
var item = result[i];
walletsTotalBal += Number(item.TotalAmount - item.CurrentAmount);
adjustdTotalAmount += Number(item.CurrentAmount);
function datediff(date2, today) {
today = new Date(today.split('/')[2], today.split('/')[1] - 1, today.split('/')[0]);
date2 = new Date(date2.split('/')[2], date2.split('/')[1] - 1, date2.split('/')[0]);
var timeDiff = Math.abs(today.getTime() - date2.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
return diffDays;
}
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
today = dd + '/' + mm + '/' + yyyy;
var wBalance = Number(item.TotalAmount);
var NumOfDays = datediff(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(item.JournalDate, null), today);
instance.bindWalletsHtml(item, wBalance, NumOfDays, item.CurrentAmount, trnId);
}
}
if (walletsTotalBal > 0)
element.find('.txtWalletsTotalAmt').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(walletsTotalBal, 2));
else
element.find('.txtWalletsTotalAmt').text("0.00");
if (adjustdTotalAmount > 0)
element.find('.txtTotalWalletAdjusted').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(adjustdTotalAmount, 2));
else
element.find('.txtTotalWalletAdjusted').val("0.00");
}
loadPaymentWallets(contactId) {
var instance = this;
if (contactId != null && contactId != 0 && contactId != undefined) {
var instance = this;
var trnId = instance.transactionId;
var paymentid = 0;
if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length != 0) {
var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
var hiddenFieldPaymentId = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_paymentid");
if (hiddenFieldPaymentId != null || hiddenFieldPaymentId != undefined) {
paymentid = Number(hiddenFieldPaymentId.Value);
}
}
var lobid = Number($(".txtAutoComplete_lobid").val());
if (isNaN(lobid)) {
lobid = 0;
}
var date = "";
var userDate = $(".date_journaldate").val();
if (userDate != undefined && userDate != null && userDate != "") {
var formattedUserDate = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatServerDate(userDate);
date = moment(formattedUserDate).format("YYYY-MM-DD");
}
else {
var curDate = Unibase.Platform.Helpers.DateTimeHelper.Instance().currentDate();
date = moment(curDate).format("YYYY-MM-DD");
}
var adjustedTotal = 0;
instance.isWalletLoading = true;
instance.navigationHelper.showLoading();
var element = $('.transactonList_item_TRN' + trnId + '');
Bizgaze.Apps.Transact.Managers.PaymentManager.Instance().getPendings(Number(contactId), paymentid, null, instance.journalTypeId, lobid, date, "Wallets").then(function (response) {
var result = response.result;
var divWallets = element.find('.divWallet_List');
$(divWallets).empty();
$(divWallets).html('
');
var walletsTotalBal = 0;
if (result.length != 0) {
for (var i = 0; i < result.length; i++) {
var item = result[i];
adjustedTotal += item.Amount;
walletsTotalBal += Number(item.JournalAlloc.TotalAmount - item.JournalAlloc.AdjustedAmount);
function datediff(date2, today) {
today = new Date(today.split('/')[2], today.split('/')[1] - 1, today.split('/')[0]);
date2 = new Date(date2.split('/')[2], date2.split('/')[1] - 1, date2.split('/')[0]);
var timeDiff = Math.abs(today.getTime() - date2.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
return diffDays;
}
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
today = dd + '/' + mm + '/' + yyyy;
var wBalance = Number(item.JournalAlloc.TotalAmount - item.JournalAlloc.AdjustedAmount);
var NumOfDays = datediff(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(item.JournalAlloc.JournalDate, null), today);
instance.bindWalletsHtml(item.JournalAlloc, wBalance, NumOfDays, item.Amount, trnId);
}
}
if (walletsTotalBal > 0)
element.find('.txtWalletsTotalAmt').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(walletsTotalBal, 2));
else
element.find('.txtWalletsTotalAmt').text("0.00");
}).then(function () {
$(".txtTotalWalletAdjusted").val(adjustedTotal);
element.find('.secWallets_' + trnId + '').addClass('hidden');
Bizgaze.Apps.Transact.Controls.PaymentSummary.Instance().updatePaymentSummaryTotal();
instance.isWalletLoading = false;
var isDueLoading = Bizgaze.Apps.Transact.Controls.Dues.Instance().isDueLoading;
if (instance.isWalletLoading == false && isDueLoading == false) {
instance.navigationHelper.hideLoading();
}
});
}
}
toggleWallets(trnId) {
var instance = this;
var element = $('.transactonList_item_' + trnId + '');
element.find('.secWallets_' + trnId + '').toggleClass('hidden');
}
isDecimal(evt, id) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode == 46) {
var val = document.getElementById(id);
var txt = val.value;
if (!(txt.indexOf(".") > -1)) {
return true;
}
}
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
isDecimalplusNoLongPress(evt, id) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
return false;
else {
var val = document.getElementById(id);
var len = val.value.length;
var index = val.value.indexOf('.');
if (index > 0 && charCode == 46) {
return false;
}
if (index > 0) {
var CharAfterdot = (len + 1) - index;
if (CharAfterdot > 3) {
return false;
}
}
}
return true;
}
initFlag() {
var instance = this;
instance.flag = 0;
}
bindWalletsHtml(journalAlloc, wBalance, NumOfDays, Amount, formPropId) {
var instance = this;
var html = '
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
';
var element = $('.transactonList_item_TRN' + formPropId + '');
element.find('.divWallet_List_item').before(html);
}
bindWalletEvents() {
}
totalWalletAdjustment(evt, curElement) {
var instance = this;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode == 190 || charCode == 110 || charCode == 46) {
return true;
}
var errormsg = $(".bizgaze_FormErrorMessages:visible").attr("id");
instance.initFlag();
if (instance.controlType != "3") {
Bizgaze.Apps.Transact.Controls.PaymentSummary.Instance().loadPaymentSummary();
}
var trnId = curElement.dataset.trnid;
var element = $('.transactonList_item_' + trnId + '');
var curAdjAmt = Number(element.find('.txtTotalWalletAdjusted').val());
var totWalletAmt = Number(element.find('.txtWalletsTotalAmt').text());
if (curAdjAmt > totWalletAmt) {
var totWalletAmt = Number(element.find('.txtWalletsTotalAmt').text());
element.find('.txtTotalWalletAdjusted_' + trnId).val(totWalletAmt);
MessageHelper.Instance().showError("Cannot adjust more than your wallets", errormsg);
}
instance.updatePayment(trnId);
}
walletsTotal(trnId) {
var instance = this;
var element = $('.transactonList_item_' + trnId + '');
var amount = 0;
var wTotals = element.find('.txtTotalWalletAdjusted').val();
wTotals = Number(wTotals);
if (wTotals > 0)
amount += wTotals;
return amount;
}
updatePayment(trnId) {
var instance = this;
var element = $('.transactonList_item_' + trnId + '');
var walletsTotal = instance.walletsTotal(trnId);
if (Number(walletsTotal) != 0) {
element.find('.txtTotalWalletAdjusted').val(walletsTotal);
$(element).find('.divWallet_Item').each(function (index) {
var wAmount = Number($(this).find('.hfWalletAmount').val());
var wCurrentAmt = 0;
if (walletsTotal >= wAmount) {
if (wAmount != 0) {
walletsTotal -= wAmount;
wCurrentAmt = wAmount;
wAmount = 0;
}
}
else {
wAmount -= walletsTotal;
wCurrentAmt = walletsTotal;
walletsTotal = 0;
}
$(this).find('.txtWalletCurrentAmount').val(wCurrentAmt);
$(this).find('.lblWalletRemaing').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(wAmount, 2));
});
}
else if (Number(walletsTotal) == 0) {
element.find('.txtTotalWalletAdjusted').val(walletsTotal);
element.find('.txtWalletCurrentAmount').val(walletsTotal);
$('.divWallet_Item').each(function () {
$(this).find(".lblWalletRemaing").val($(this).find(".hfWalletAmount").val());
});
}
}
AdjustWalletAmount(jId, trnId, evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode == 190 || charCode == 110 || charCode == 46) {
return true;
}
var instance = this;
instance.flag = 0;
var formId = $(".transactonList_div_" + trnId).parents("form").attr("id").split('_')[1];
var x = document.getElementById("divWallet_List_item_" + jId).parentElement.parentElement.getAttribute("class");
var elementforPayment = $('.transactonList_item_' + trnId + '');
var totAdjustment = $(elementforPayment).find('.txtTotalWalletAdjusted_' + trnId + '').val();
var totWallet = 0;
var totWalletAmt = Number(elementforPayment.find('.txtWalletsTotalAmt').text());
$(elementforPayment).find('.divWallet_Item').each(function () {
var xyz = Number($(this).find('.txtWalletCurrentAmount').val());
if (!isNaN(xyz))
totWallet += xyz;
});
var element = elementforPayment.find('#divWallet_List_item_' + jId + '');
var Amt = $("#hf_TotalCreditAmount").val();
if (instance.controlType == "3")
Amt = totWallet;
if (totWallet <= totWalletAmt) {
var OrgwalletAmount = Number($(element).find('.hfWalletAmount').val());
var txtWalletCurrentAmount = 0;
txtWalletCurrentAmount = Number($(element).find('.txtWalletCurrentAmount').val());
if (txtWalletCurrentAmount == 0 || txtWalletCurrentAmount == undefined) {
$(element).find('.txtWalletCurrentAmount').val(0.00);
$(element).find('.lblWalletRemaing').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(OrgwalletAmount, 2));
var ttWallet = 0;
$(elementforPayment).find('.divWallet_Item').each(function () {
var pqr = Number($(this).find('.txtWalletCurrentAmount').val());
if (!isNaN(pqr))
ttWallet += pqr;
});
$(elementforPayment).find('.txtTotalWalletAdjusted_' + trnId + '').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(ttWallet, 2));
return false;
}
if (txtWalletCurrentAmount > OrgwalletAmount) {
$(element).find('.txtWalletCurrentAmount').val(OrgwalletAmount);
$(element).find('.lblWalletRemaing').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(0, 2));
}
else {
var walletAmount = OrgwalletAmount - txtWalletCurrentAmount;
$(element).find('.txtWalletCurrentAmount').val(txtWalletCurrentAmount);
$(element).find('.lblWalletRemaing').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(walletAmount, 2));
}
var ttWallet = 0;
$(elementforPayment).find('.divWallet_Item').each(function () {
var pqr = Number($(this).find('.txtWalletCurrentAmount').val());
if (!isNaN(pqr))
ttWallet += pqr;
});
$(elementforPayment).find('.txtTotalWalletAdjusted_' + trnId + '').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(ttWallet, 2));
}
else {
MessageHelper.Instance().showError("You don't have enough amount in that wallets", 'div_ErrorMessage_' + formId);
$(element).find('.txtWalletCurrentAmount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(element).find('.hfWalletAmount').val()), 2));
$(element).find('.lblWalletRemaing').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(0, 2));
var ttWallet = 0;
$(elementforPayment).find('.divWallet_Item').each(function () {
var pqr = Number($(this).find('.txtWalletCurrentAmount').val());
if (!isNaN(pqr))
ttWallet += pqr;
});
$(elementforPayment).find('.txtTotalWalletAdjusted_' + trnId + '').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(ttWallet, 2));
}
if (instance.controlType != "3") {
Bizgaze.Apps.Transact.Controls.PaymentSummary.Instance().updatePaymentSummaryTotal();
Bizgaze.Apps.Transact.Controls.Dues.Instance().clearDues();
}
}
walletControlObj(trnId) {
var instance = this;
var element = $('.transactonList_item_' + trnId + '');
var data = new Array();
element.find('.divWallet_Item').each(function (index) {
if ($(this).find('.txtWalletCurrentAmount').val() != 0 && $(this).find('.txtWalletCurrentAmount').val() != '' && $(this).find('.txtWalletCurrentAmount').val() != undefined) {
var jAId = Number($(this).find('.hf_JournalAllocId').val());
if (instance.journalTypeId == 1) {
data.push({
JournalAllocId: isNaN(jAId) ? 0 : jAId,
Debit: Number($(this).find('.txtWalletCurrentAmount').val()),
RefAllocId: Number($(this).find('.hf_RefAllocId').val()),
AllocType: 2,
AllocTypeId: 2
});
}
else if (instance.journalTypeId == 2) {
data.push({
JournalAllocId: isNaN(jAId) ? 0 : jAId,
Credit: Number($(this).find('.txtWalletCurrentAmount').val()),
RefAllocId: Number($(this).find('.hf_RefAllocId').val()),
AllocType: 2,
AllocTypeId: 2
});
}
else if (instance.controlType == "3") {
let Notes = "";
let Debit = 0;
let Credit = 0;
if ($(".hdn_invoicetypeid").val() == "1") {
Notes = "Adjustment SalesReturn against " + $(".hdn_tempjournalno").val();
Debit = Number($(this).find('.txtWalletCurrentAmount').val());
}
else {
Notes = " Adjustment PurchaseReturn against " + $(".hdn_tempjournalno").val();
Credit = Number($(this).find('.txtWalletCurrentAmount').val());
}
data.push({
JournalAllocId: isNaN(jAId) ? 0 : jAId,
RefAllocId: Number($(this).find('.hf_RefAllocId').val()),
JournalId: Number($(this).find(".hf_JournalId").val()),
AdjustedAmount: Number($(this).find('.hf_AdjustedAmount').val()),
TotalAmount: Number($(this).find(".txtWalletsTotalAmt").text()),
IsWallet: true,
CurrentAmount: Number($(this).find('.txtWalletCurrentAmount').val()),
AllocType: 2,
Discount: 0,
RefNo: "",
Credit: Credit,
Debit: Debit
});
}
}
});
if (Number($(".totAdvance").first().text()) > 0) {
var jAId = Number($(this).find('.hf_AdvanceJournalAllocId').val());
if (instance.journalTypeId == 1) {
data.push({
JournalAllocId: isNaN(jAId) ? 0 : jAId,
LedgerId: Number($(".txtAutoComplete_contactid option:selected").val()),
Credit: Number($(".totAdvance").first().text()),
RefAllocId: 0,
AllocType: 3,
AllocTypeId: 3,
});
}
else if (instance.journalTypeId == 2) {
data.push({
JournalAllocId: isNaN(jAId) ? 0 : jAId,
LedgerId: Number($(".txtAutoComplete_contactid option:selected").val()),
Debit: Number($(".totAdvance").first().text()),
RefAllocId: 0,
AllocType: 3,
AllocTypeId: 3,
});
}
}
return data;
}
loadControlSettings(controlsettingjson, formpropertyid) {
return ``;
}
loadPropertySettings(propertysettings, formpropertyid, DocPropertyName) {
return ``;
}
bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
return ``;
}
static Instance() {
if (this.instance === undefined) {
this.instance = new Wallet();
}
return this.instance;
}
}
Controls.Wallet = Wallet;
})(Controls = Transact.Controls || (Transact.Controls = {}));
})(Transact = Apps.Transact || (Apps.Transact = {}));
})(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
})(Bizgaze || (Bizgaze = {}));