123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- var Bizgaze;
- (function (Bizgaze) {
- let Apps;
- (function (Apps) {
- let Transact;
- (function (Transact) {
- let Controls;
- (function (Controls) {
- class Eb extends Unibase.Platform.Core.BaseComponent {
- constructor() {
- super(...arguments);
- this.ebcontainer = "";
- this.deleted_EBs = new Array();
- this.itemIds = new Array();
- }
- init(formpropertyid, prop, callback) {
- let instance = this;
- let jsFiles = ["apps/transact/controls/invoices/invoiceitem.component.js", "apps/crm/contacts/managers/contactmanager.js", "apps/transact/managers/invoicemanager.js", "platform/core/helpers/numberhelper/numberhelper.js", "libs/jquery/pagination/jquery.pagination.js"];
- instance.fileCacheHelper.loadJsFiles(jsFiles, function () {
- instance._invoiceItems = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance();
- instance.deleted_EBs = [];
- instance.itemIds = [];
- instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
- instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
- });
- }
- loadControl(containerid, prop) {
- var instance = this;
- let html = `<div class="form-group EBContainer m-t" id="divEBs">
- <div class="m-l m-r">
- <div class="EB_header row bg-white border-2 border-bottom border-grey mx-0 py-10">
- <div class="col-sm-7 text-left font-weight-600">EB Name</div>
- <div class="col-sm-3 text-center font-weight-600">Fill Type</div>
- <div class="col-sm-2 text-right font-weight-600">Volume</div></div></div></div>
- <div class="EB-row hidden"></div>
-
- <div class="col-xs-6 m-l m-r">
- <input type = "hidden" id = "hdn_customcontrol" class="value-control" value = "Bizgaze.Apps.Transact.Controls.Eb.Instance().getEbItems();">
- <a id="addEBrow" href="javascript: Bizgaze.Apps.Transact.Controls.Eb.Instance().addEBDatarow();" class="btn btn-outline-primary" title="Add EB">Add EB</a>
- </div></div></div>`;
- $("#" + containerid).html(html);
- instance.ebcontainer = containerid;
- }
- loadControlSettings(controlsettingjson, formpropertyid) {
- var instance = this;
- instance.loadEBs();
- }
- loadPropertySettings(propertysettings, formpropertyid) {
- return null;
- }
- bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
- return null;
- }
- getEbItems() {
- var instance = this;
- var EBs = instance.getEBs();
- return EBs;
- }
- addEBDatarow() {
- var instance = this;
- $('.divDescriptionDetails').addClass('hidden');
- instance.addEBRow(0, 0, 0, "", 0.0, 0, 1, "", null);
- }
- addEBRow(orderId, EBId, EBContactId, EBName, volume, InvoiceId, FillType, Notes, EBItemList) {
- var instance = this;
- var padding = "";
- if (EBId) {
- padding = "m-t";
- }
- var html = '<div class="form-group EB-row addedEB-row">' +
- '<div class="row mx-0 EBdata"><div class="EB-Name col-sm-7 d-flex align-items-center ' + padding + '">' +
- '<a class="input-group-addon no-border EBdelete" href="javascript:;" title="Remove row"><i class="fa fa-trash-o fa-lg mr-2 text-danger delete" aria-hidden="true"></i></a>' +
- '<div><input type="hidden" class="hfOrderEBId" value="0" />' +
- '<div class="input-group">';
- if (EBId != 0) {
- html += '<a class="default EBName-link" href="javascript:;">' + EBName + '</a>';
- }
- else {
- html += `<select class="txt_EBName ui-autocomplete form-control col-sm-6" data-placeholder="Select"
- placeholder="EB Name" value="' + EBName + '">`;
- }
- html +=
- '<input type="hidden" class="hf_EBId" value="' + EBContactId + '" />' +
- '</div>' +
- '</div></div>' +
- '<div class="col-sm-3 m-t text-center">' +
- '<select id="cmbFillType" class="form-control"><option value="1">Initial Fill</option><option value="2">Service Fill</option></select></div>' +
- '<div class="col-sm-2">' +
- '<div class="EB_Volume floating-label-form-group text-right"><b class="text-dark">' + volume + '</b></div></div></div>' +
- '<div class="divDescriptionDetails bg-secondary-light-5 pa-10 mt-10 hidden">' +
- '<div class="clear m-b-sm"> <div class="EB-Itemrow hidden"></div>';
- html += '<div class="col-xs-6 m-l m-r m-t"><a id="addEBItemrow" class="btn btn-outline-primary" title="Add EB Item">Add EB Item</a></div>';
- html += '<div class="col-sm-12 mt-10">' +
- '<div class="floating-label-form-group item-desc min-padding floating-label-form-group-with-value">' +
- '<input type="text" class="EBDesc form-control" value="' + Notes + '" placeholder="Notes" />' +
- '</div>' +
- '</div></div></div>' +
- '</div>';
- $(".EB-row:last").after(html);
- var element = $(".EB-row:last");
- element.find('.EB_Volume').on('click', function () {
- $(".divDescriptionDetails").addClass("hidden");
- $(this).parents('.addedEB-row').find(".divDescriptionDetails").removeClass('hidden');
- });
- if (EBItemList != null || EBItemList != undefined) {
- for (var i = 0; i < EBItemList.length; i++) {
- instance.addEBItemrow(EBItemList[i], element);
- }
- }
- else {
- instance.addEBItemrow(null, element);
- }
- element.find(".EBDesc").val(Notes);
- element.find("#cmbFillType").val(FillType);
- var TotalVolume = 0;
- element.find(".EB-Itemrow").each(function () {
- if ($(this).find(".EBItem_Volume").val() != 0 && $(this).find(".EBItem_Volume").val() != undefined) {
- TotalVolume += Number($(this).find(".EBItem_Volume").val());
- }
- });
- element.find(".EB_Volume").text(TotalVolume);
- element.find(".txt_EBName,.EBName-link").focusin(function () {
- if (element.find(".hf_EBId").val() != -1) {
- $(".divDescriptionDetails").addClass("hidden");
- element.find(".divDescriptionDetails").toggleClass("hidden");
- }
- });
- var txtEBName = element.find(".txt_EBName");
- var hfSelectedEBId = element.find(".hf_EBId");
- if (hfSelectedEBId.val() == -1) {
- $("#addEBrow").addClass('hidden');
- }
- var url = _appsettings.server_url() + '/apis/v4/bizgaze/crm/contacts/getcontactebs';
- AutoCompleteHelper.getHelper().Create(txtEBName, hfSelectedEBId, url, function (response) {
- if (hfSelectedEBId.val() != 0) {
- element.find(".EB_volume").removeClass('hidden');
- $(".divDescriptionDetails").addClass('hidden');
- element.find(".divDescriptionDetails").removeClass('hidden');
- }
- if (hfSelectedEBId.val() == -1) {
- $(".divDescriptionDetails").addClass('hidden');
- $("#addEBrow").addClass('hidden');
- }
- else {
- var hfSelectedEBItemId = element.find(".hf_EBItemId");
- instance.loadItemAutoComplete(element, "0", hfSelectedEBItemId);
- }
- $('.txt_EBName + .select2-container').width(421.987);
- });
- element.find(".EBdelete").on('click', function () {
- bootbox.confirm("You are about to delete the EB. Are you sure?", function (result) {
- if (result) {
- element.find(".EB-Itemrow").each(function () {
- var Ebid = $(this).find(".hf_InvEBId").val();
- element.remove();
- if (Ebid != "0" && Ebid != undefined) {
- instance.deleted_EBs.push(Number(Ebid));
- }
- });
- if (hfSelectedEBId.val() == -1) {
- $("#addEBrow").removeClass('hidden');
- }
- }
- });
- });
- element.find("#addEBItemrow").on('click', function () {
- instance.addEBItemrow(null, element);
- });
- }
- addEBItemrow(EBItemList, EBelement) {
- var instance = this;
- var ItemName = "";
- var ItemId = 0;
- var Volume = 0;
- var EBId = 0;
- var SKU = "";
- if (EBItemList != null || EBItemList != undefined) {
- EBId = EBItemList.EBId;
- ItemName = EBItemList.ItemName;
- ItemId = EBItemList.ItemId;
- Volume = EBItemList.Volume;
- SKU = EBItemList.SKU;
- }
- var floting = "";
- if (ItemId == 0) { }
- floting = "floating-label-form-group";
- var html = '<div class="EB-Itemrow row mx-0 mb-15">' +
- '<div class="EB_Item-Name col-sm-7 d-flex align-items-center"><input type="hidden" class="hf_InvEBId" value="' + EBId + '" />' +
- '<a class="input-group-addon no-border EBItemdelete" href = "javascript:;" title = "Remove row"><i class="fa fa-trash-o fa-lg mr-2 text-danger"> </i></a> <input type = "hidden" class="hf_EBItemId" value = "' + ItemId + '" /> ';
- if (ItemId != 0) {
- html += '<a class="default EBItemName-link" href="javascript:;">' + SKU + "-" + ItemName + '</a>';
- }
- else {
- html += '<select class="txt_EBItemName ui-autocomplete form-control" data-placeholder="Select" placeholder="EB Item Name" value="' + ItemName + '"></select>';
- }
- html += '</div><div class="col-sm-3"></div>' +
- '<div class="col-sm-2 pr-0">' +
- '<input type="text" class="EBItem_Volume form-control text-right" placeholder="volume" onkeypress="return isNumberKey(event)" value="' + Volume + '" /></div></div>';
- EBelement.find(".EB-Itemrow:last").after(html);
- var element = EBelement.find(".EB-Itemrow:last");
- var lobid = $(".hfAutoCompleteId_lobid").val();
- var Dcid = Controls.InvoiceItem.Instance().dcid;
- if (lobid == 0)
- lobid = $("#cmbInv_Lob").val();
- var txtEBItemName = element.find(".txt_EBItemName");
- var hfSelectedEBItemId = element.find(".hf_EBItemId");
- var selectitemids = "";
- EBelement.find(".EB-Itemrow").each(function () {
- if ($(this).find(".hf_EBItemId").val() != 0 && $(this).find(".hf_EBItemId").val() != undefined) {
- selectitemids += $(this).find(".hf_EBItemId").val() + ",";
- }
- });
- var url = "";
- var invoiceid = $(".hdn_invoiceid").val();
- if (selectitemids == '')
- selectitemids = '0';
- if ($(".hdn_invoiceid").val() != 0 && $(".hdn_invoiceid").val() != undefined) {
- url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/invoices/autopendingebitemsforinvoicebyinvoiceid/invoiceid/' + $(".hdn_invoiceid").val() + '/itemids/' + selectitemids;
- AutoCompleteHelper.getHelper().Create(txtEBItemName, hfSelectedEBItemId, url, function (response) {
- var data = response;
- });
- }
- else {
- instance.loadItemAutoComplete(element, selectitemids, hfSelectedEBItemId);
- }
- element.find(".EBItemdelete").on('click', function () {
- bootbox.confirm("You are about to delete the EB. Are you sure?", function (result) {
- if (result) {
- var Ebid = element.find(".hf_InvEBId").val();
- element.remove();
- if (Ebid != "0") {
- $(this).parent().find(".EB_Volume").val();
- instance.deleted_EBs.push(Number(Ebid));
- var TotalVolume = Number(EBelement.find(".EB_Volume").html());
- TotalVolume -= Number(element.find(".EBItem_Volume").val());
- EBelement.find(".EB_Volume").text(TotalVolume);
- }
- }
- });
- });
- element.find(".EBItem_Volume").blur(function () {
- var TotalVolume = 0;
- if (element.find(".hf_EBItemId").val() == 0) {
- MessageHelper.Instance().showError("please select EB Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
- return false;
- }
- var checkingInvoiceItemQty = true;
- $(".InvoiceItems").find(".item-row").each(function () {
- if ($(this).children().length > 0) {
- if ($(this).find(".selectedItemId").val() == element.find(".hf_EBItemId").val()) {
- if ($(this).find(".selectedItemId").val() != "" && $(this).find(".selectedItemId").val() != "0" && $(this).find(".prodQuantity").val() > 0) {
- var invoiceQty = Number($(this).find(".prodQuantity").val());
- if (checkingInvoiceItemQty)
- checkingInvoiceItemQty = instance.checkingInvoiceItemQuantitywithEBItemQuantity(invoiceQty, $(this).find(".selectedItemId").val());
- }
- }
- }
- });
- if (!checkingInvoiceItemQty) {
- if ($(".hdn_invoiceid").val() != 0)
- MessageHelper.Instance().showError("EB Volume must be less than or equal to invoiced Quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
- else
- MessageHelper.Instance().showError("Please Adjust the EB Volumes", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
- element.find(".EBItem_Volume").val(0);
- return false;
- }
- EBelement.find(".EB-Itemrow").each(function () {
- if ($(this).find(".EBItem_Volume").val() != 0 && $(this).find(".EBItem_Volume").val() != undefined) {
- TotalVolume += Number($(this).find(".EBItem_Volume").val());
- }
- });
- EBelement.find(".EB_Volume").text(TotalVolume);
- });
- }
- checkingInvoiceItemQuantitywithEBItemQuantity(invoiceItemQty, ItemId) {
- var EBItemQuantity = 0;
- $(".EB-row").each(function () {
- if ($(this).find(".hf_EBId").val() != undefined || $(this).find(".hf_EBId").val() != -1) {
- $(this).find(".EB-Itemrow").each(function () {
- if ($(this).find(".hf_EBItemId").val() != undefined && $(this).find(".hf_EBItemId").val() == ItemId) {
- EBItemQuantity += Number($(this).find(".EBItem_Volume").val());
- }
- });
- }
- });
- if (EBItemQuantity > invoiceItemQty) {
- return false;
- }
- else
- return true;
- }
- loadEBs() {
- var instance = this;
- $('.addedEB-row').remove();
- var url = "";
- if ($(".hdn_invoiceid").val() != 0)
- url = '/apis/v4/bizgaze/transact/invoices/GetOpportunityEBsByInvoiceId/InvoiceId/' + $(".hdn_invoiceid").val();
- else
- url = '/apis/v4/bizgaze/transact/invoices/GetEBsDetailsByOrderId/OrderId/' + Number($(".hdn_orderid").val());
- Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().loadEbs(url).then(function (response) {
- var data = response;
- if (data.result.length > 0) {
- var EbsList = instance.EBsgroupByEbContactId(data.result, 'EBContactId');
- Object.keys(EbsList).forEach(function (k) {
- var Ebdata = EbsList[k];
- var EBItemList = new Array();
- for (var i = 0; i < Ebdata.length; i++) {
- EBItemList.push({
- EBId: Number(Ebdata[i].EBId),
- ItemId: Number(Ebdata[i].ItemId),
- Volume: Number(Ebdata[i].Volume),
- ItemName: Ebdata[i].ItemName,
- SKU: Ebdata[i].SKU
- });
- }
- instance.addEBRow(Ebdata[0].OrderId, Ebdata[0].EBId, Ebdata[0].EBContactId, Ebdata[0].EBName, Ebdata[0].Volume, Ebdata[0].InvoiceId, Ebdata[0].FillType, Ebdata[0].Notes, EBItemList);
- });
- }
- else {
- instance.addEBRow(0, 0, 0, "", 0.0, 0, 1, "", null);
- }
- }, function (response) {
- Unibase.Platform.Forms.Components.FormViewer.Instance().showError(response.responseText);
- });
- }
- EBsgroupByEbContactId(objectArray, property) {
- return objectArray.reduce((acc, obj) => {
- const key = obj[property] + '-' + obj["FillType"];
- if (!acc[key]) {
- acc[key] = [];
- }
- acc[key].push(obj);
- return acc;
- }, {});
- }
- getEBs() {
- var instance = this;
- var checkingInvoiceItemQty = true;
- $(".InvoiceItems").find(".item-row").each(function () {
- if ($(this).find(".selectedInvoiceItemId").val() != undefined) {
- if ($(this).find(".selectedItemId").val() != "" && $(this).find(".selectedItemId").val() != "0" && $(this).find(".prodQuantity").val() > 0) {
- var invoiceQty = Number($(this).find(".prodQuantity").val());
- if (checkingInvoiceItemQty)
- checkingInvoiceItemQty = instance.checkingInvoiceItemQuantitywithEBItemQuantity(invoiceQty, $(this).find(".selectedItemId").val());
- }
- }
- });
- if (!checkingInvoiceItemQty) {
- if ($(".hdn_invoiceid").val() != 0)
- MessageHelper.Instance().showError("EB Volume must be less than or equal to invoiced Quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
- else
- MessageHelper.Instance().showError("EB volume (EB Info section) cannot be more than Total volume", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
- return;
- }
- var EBList = new Array();
- $(".EB-row").each(function () {
- if ($(this).find(".hf_EBId").val() != undefined) {
- if ($(this).find(".hf_EBId").val() != "" && $(this).find(".hf_EBId").val() != "0") {
- var OrderId = Number($(this).find("hfOrderEBId").val());
- var EBContactId = Number($(this).find(".hf_EBId").val());
- var FillType = Number($(this).find('#cmbFillType').val());
- var Notes = $(this).find('.EBDesc').val();
- if (OrderId == null)
- OrderId = 0;
- if ($(this).find(".hf_EBId").val() != -1) {
- $(this).find(".EB-Itemrow").each(function () {
- if ($(this).find(".hf_EBItemId").val() != undefined && $(this).find(".hf_EBItemId").val() != 0) {
- EBList.push({
- OrderId: isNaN(OrderId) ? 0 : OrderId,
- EBId: Number($(this).find(".hf_InvEBId").val()),
- EBContactId: Number(EBContactId),
- Volume: Number($(this).find(".EBItem_Volume").val()),
- InvoiceId: 0,
- ItemId: Number($(this).find(".hf_EBItemId").val()),
- FillType: FillType,
- Notes: Notes,
- DeletedEbs: []
- });
- }
- });
- }
- else {
- EBList.push({
- OrderId: isNaN(OrderId) ? 0 : OrderId,
- EBId: isNaN(Number($(this).find(".hf_InvEBId").val())) ? 0 : Number($(this).find(".hf_InvEBId").val()),
- EBContactId: EBContactId,
- Volume: 0,
- InvoiceId: 0,
- ItemId: 0,
- FillType: FillType,
- Notes: Notes,
- DeletedEbs: []
- });
- }
- }
- }
- });
- if ($('.section_Ebs').is(":visible") && EBList.length == 0) {
- MessageHelper.Instance().showError("EB information is mandatory.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
- return false;
- }
- else if (instance.deleted_EBs.length > 0) {
- EBList[0].DeletedEbs = instance.deleted_EBs;
- }
- return EBList;
- }
- loadItemAutoComplete(element, selectitemids, hfSelectedEBItemId) {
- let userinfo = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
- let sessionid = userinfo.sessionId;
- let postData = null;
- var selecteditems = selectitemids.split(',');
- var ids = [];
- for (var i = 0; i <= Controls.InvoiceItem.instance.itemIds.length; i++) {
- let index = Controls.InvoiceItem.instance.itemIds.findIndex(x => x == selecteditems[i]);
- if (index == -1 && Controls.InvoiceItem.instance.itemIds[i] != null) {
- ids.push(Controls.InvoiceItem.instance.itemIds[i]);
- }
- }
- element.find(".txt_EBItemName").select2({
- placeholder: "Select",
- tags: false,
- allowClear: true,
- theme: "default select2ErrorClass w-100",
- data: [],
- ajax: {
- url: function (request) {
- let reqUrl = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/getebitemsforinvoice';
- return reqUrl;
- },
- type: "POST",
- contentType: 'application/json',
- dataType: 'json',
- data: function (params) {
- let Term = params.term;
- sessionid = sessionid.replace('#', '');
- if (selectitemids == '') {
- ids = Controls.InvoiceItem.instance.itemIds;
- }
- postData = {
- LobId: Number($(".hfAutoCompleteId_lobid").val()),
- ItemIds: ids,
- 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
- };
- })
- };
- },
- },
- }).on('select2:select', function (e) {
- var result = e.params.data;
- $(hfSelectedEBItemId).val(result.id);
- });
- }
- static Instance() {
- if (this.instance === undefined) {
- this.instance = new Eb();
- }
- return this.instance;
- }
- }
- Controls.Eb = Eb;
- })(Controls = Transact.Controls || (Transact.Controls = {}));
- })(Transact = Apps.Transact || (Apps.Transact = {}));
- })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
- })(Bizgaze || (Bizgaze = {}));
|