var Bizgaze;
(function (Bizgaze) {
let Apps;
(function (Apps) {
let Transact;
(function (Transact) {
let Controls;
(function (Controls) {
class InvoiceAmount extends Unibase.Platform.Core.BaseComponent {
init(formpropertyid, prop, callback) {
var instance = InvoiceAmount.Instance();
instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
}
loadControl(containerid, prop) {
var html = "
0.00
";
$("#" + containerid).html(html);
$('#txt_Adjustment').prop("disabled", false);
$('#txt_Adjustment').keypress(function (event) {
if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8) || (event.which == 45)) {
}
else {
event.preventDefault();
}
}).on('paste', function (event) {
event.preventDefault();
});
$('#txt_Adjustment').blur(function () {
if ($('#chk_AutoAdjustment').prop("checked") == false) {
$('.hdn_adjustment').val($('#txt_Adjustment').val());
if (Number($('#txt_Adjustment').val()) != 0) {
$('.span_AdjustmentAccountName').removeClass('hidden');
}
else {
$('.span_AdjustmentAccountName').addClass('hidden');
}
Controls.InvoiceItem.Instance().update_total();
Controls.InvoiceItem.Instance().TotalAdjustment();
}
});
var instance = this;
instance.loadAccounts();
$('#chk_AutoAdjustment').prop("checked", true);
$(".hdn_autoadjustment").val("true");
$('#txt_Adjustment').prop("disabled", true);
$('#chk_AutoAdjustment').change(function () {
if ($('#chk_AutoAdjustment').is(':checked')) {
$('.span_AdjustmentAccountName').removeClass('hidden');
$('#txt_Adjustment').prop("disabled", true);
Controls.InvoiceItem.Instance().update_total();
Controls.InvoiceItem.Instance().TotalAdjustment();
$(".hdn_autoadjustment").val("true");
}
else {
$("#txt_Adjustment").val(0);
$("#txt_Adjustment").blur();
$(".hdn_adjustment").val(0);
$('.span_AdjustmentAccountName').addClass('hidden');
$('#txt_Adjustment').prop("disabled", false);
$(".hdn_autoadjustment").val("false");
}
});
$("#addNetDiscount").off().click(function () {
let lobid = $(".hfAutoCompleteId_lobid").val();
if (lobid == undefined || lobid == "" || lobid == "0") {
MessageHelper.Instance().showError("Please Select LoB", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
return false;
}
else {
Controls.InvoiceItem.Instance().addNetDiscountRow();
$(".netdiscount-row:last").find(".netdiscount-name").find("input:text").focus();
}
});
$("#addExpense").off().click(function () {
;
let lobid = $(".hfAutoCompleteId_lobid").val();
if (lobid == undefined || lobid == "" || lobid == "0") {
MessageHelper.Instance().showError("Please Select LoB", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
return false;
}
else {
Controls.InvoiceItem.Instance().addExpenseRow(null, "", "", true);
$(".expense-row:last").find(".expense-name").find("input:text").focus();
}
});
if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") {
$("#addNetDiscount").addClass("hidden");
}
}
loadControlSettings(controlsettingjson, formpropertyid) {
return null;
}
loadPropertySettings(propertysettings, formpropertyid) {
if (propertysettings != null) {
for (var i = 0; i < propertysettings.length; i++) {
var data = propertysettings[i];
if (data.ControlPropertyName == "MaxLength") {
$("#txt_" + formpropertyid).attr("MaxLength", data.ControlPropertyValue);
}
}
}
}
bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
throw new Error("Method not implemented.");
}
loadAccounts() {
var instance = this;
var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete';
AutoCompleteHelper.getHelper().Create("#txt_AdjustmentAccountName", "#hf_AdjustmentAccountId", url, null);
$("#txt_AdjustmentAccountName").on('select2:select', function (e) {
instance.LedgerAccountChange();
});
}
LedgerAccountChange() {
var instance = this;
var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete';
AutoCompleteHelper.getHelper().Create("#txt_AdjustmentAccountName", "#hf_AdjustmentAccountId", url, function (response) {
debugger;
var accountId = 0;
var accountName = "";
var controlId = "";
var hiddenFieldControlId = "";
accountId = Number(response.id);
accountName = response.text;
controlId = "#txt_AdjustmentAccountName";
hiddenFieldControlId = "#hf_AdjustmentAccountId";
if (accountId == 0)
accountName = "Select Account";
if (accountId == 1 || accountId == -1)
accountName = "Create New";
if (accountName == "Create New") {
$("#txt_AdjustmentAccountName").val(null).trigger("change");
var FormUniqueId = "Bizgaze_Extension_Transact_Ledgers_App_Ledgers_CreateForm";
var AppConfigurationUnique = "Bizgaze_Extension_Transact_Ledgers_AppConfiguration_CreateLedgers";
Unibase.Platform.Forms.Managers.FormManager.Instance().getFormbyUniqueId(FormUniqueId).then(function (response) {
var obj = {
controlid: controlId,
hiddenid: hiddenFieldControlId
};
var successobj = {
CallBack: function (id, obj) {
Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLedgerById(id).then(function (response) {
var createdLedger = new Option(response.result.LedgerName, response.result.LedgerId, true);
$(obj.controlid + " option").remove();
$(obj.controlid).append(createdLedger).trigger('change');
$(obj.hiddenid).val(response.result.LedgerId);
});
},
Parameters: obj,
};
var formviewerObj = {
FormId: response.result.FormId,
AppConfigurationId: 0,
Pk_Value: 0,
PortletWidgetId: 0,
OnSuccess: successobj,
OnFail: null,
OnLoad: null,
};
instance.fileCacheHelper.loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", function () {
instance.fileCacheHelper.loadJsFile("platform/forms/components/formviewer/formviewer.js", function () {
Unibase.Platform.Forms.Components.FormViewer.instance.init(formviewerObj);
setTimeout(function () {
$("#btn_CloseForm_" + response.result.FormId).click(function () {
$("#txt_AdjustmentAccountName").val(null).trigger("change");
});
}, 1000);
});
});
});
}
});
}
static Instance() {
if (this.instance === undefined) {
this.instance = new InvoiceAmount();
}
return this.instance;
}
}
Controls.InvoiceAmount = InvoiceAmount;
})(Controls = Transact.Controls || (Transact.Controls = {}));
})(Transact = Apps.Transact || (Apps.Transact = {}));
})(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
})(Bizgaze || (Bizgaze = {}));