Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pos.component.js 177KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. var Bizgaze;
  11. (function (Bizgaze) {
  12. let Apps;
  13. (function (Apps) {
  14. let Transact;
  15. (function (Transact) {
  16. let Controls;
  17. (function (Controls) {
  18. class Pos extends Unibase.Platform.Core.BaseComponent {
  19. constructor() {
  20. super(...arguments);
  21. this.userCart = [];
  22. this.userCartDiscount = [];
  23. this.userCartTax = [];
  24. this.selectedItemsArray = [];
  25. this.offerItemsArray = [];
  26. this.itemImage = [];
  27. this.isBootBoxRendered = false;
  28. this.allEventsExecuted = false;
  29. this.IswalkinCustomer = false;
  30. this.EnableTenantTcs = false;
  31. this.TurnOver = 0;
  32. this.TaxRate = 0;
  33. this.ContactTcsEnable = false;
  34. this.PanAvailable = false;
  35. this.totalDiscountValue = 0;
  36. this.totalTaxAmount = 0;
  37. this.selectedPlanArray = [];
  38. this.cartInst = Bizgaze.Apps.Transact.Controls.CartItem.Instance();
  39. this.isKeyboard = false;
  40. this.offerPriceList = [];
  41. this.offerItemPriceAdded = false;
  42. this.isCheckoutMode = false;
  43. }
  44. init(formpropertyid, prop, callback) {
  45. var instance = this;
  46. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFiles(['platform/core/helpers/numberhelper/numberhelper.js', 'apps/transact/managers/invoicemanager.js', 'apps/transact/managers/paymentterms/paymenttermmanager.js', 'apps/transact/managers/offers/offermanager.js', 'tenants/themes/compact/components/details/details.js', 'platform/forms/components/formviewer/formviewer.js', 'libs/parsley/parsley.min.js', 'apps/transact/components/invoices/itemofferselection.js', 'apps/transact/controls/orders/orderitems.component.js', 'apps/transact/controls/orders/order.component.js', 'apps/transact/controls/payments/wallet.component.js', 'apps/transact/controls/invoices/cartitem.component.js', 'libs/kioskboard/kioskboard.min.js'], function () {
  47. instance.isdraft = false;
  48. instance.invoiceid = $(".hdn_invoiceid").val();
  49. if (instance.invoiceid != "0") {
  50. instance.bindEditInvoiceDetails(instance.invoiceid);
  51. }
  52. });
  53. }
  54. loadControl(containerid, prop) {
  55. this.fileCacheHelper.loadJsFile("apps/transact/managers/invoicemanager.js", () => {
  56. this.containerId = containerid;
  57. });
  58. this.fileCacheHelper.loadCssFiles(["apps/transact/controls/invoices/pos-styles.css", "libs/kioskboard/kioskboard.min.css"], () => { });
  59. }
  60. setProductDetails(html, containerid) {
  61. var accountId = 0;
  62. var branchId = Unibase.Platform.Membership.Infos.Identity.currentUser.settings.find(x => x.settingName == 'branchid').settingValue;
  63. $(".hdn_branchid").val(branchId);
  64. this.contactId = $(".hdn_organizationid").val();
  65. const formParentEl = $('.simple-scroll-bar.formviewer_id');
  66. const modalHeaderHeight = formParentEl.siblings('.modal-header').outerHeight(true);
  67. const modalFooterHeight = formParentEl.siblings('.modal-footer').outerHeight(true);
  68. formParentEl.addClass('pos-modal-body').css('height', `calc(100% - ${modalHeaderHeight + modalFooterHeight}px)`);
  69. this.lobId = $(".txtAutoComplete_lobid").val();
  70. if (this.lobId != undefined && this.lobId != 0) {
  71. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getproductsbyLobid(this.lobId).then((responce) => {
  72. var taxInclusive = true;
  73. if (responce.result.length > 0) {
  74. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemsUnitPriceByProductId(responce.result[0].ProductId, this.contactId, null).then((res) => {
  75. if (res.result.length > 0) {
  76. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", () => {
  77. Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLobLedgerSetting(this.lobId, branchId).then((response) => {
  78. accountId = response.result.SettingValue1;
  79. this.updateDataArray(res.result, accountId);
  80. this.dataBeforeSearch = res.result;
  81. this.resBeforeSearch = res;
  82. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getpricebyProductId("a", this.lobId, responce.result[0].ProductId).then((data) => {
  83. html = `<div class='card section-products-items border-0 mb-0 shadow-none'><div class='card-body row m-0 pa-0'>${this.createProductsGroup(responce.result)}`;
  84. $("#" + containerid).html(html);
  85. this.allEventsExecuted = false;
  86. this.itemInfoElement = null;
  87. this.productContainerElement = null;
  88. this.productInfoElement = null;
  89. this.cartInfoElement = null;
  90. $(".products-container .products-container-body").append(this.createItemsList(res.result, false, false));
  91. !this.allEventsExecuted && this.eventListeners();
  92. this.initializeCarousel();
  93. this.initializeKeyBoard();
  94. this.applyCartBodyHeight();
  95. });
  96. });
  97. });
  98. }
  99. else {
  100. html = `<div class='card section-products-items'><div class='card-body row m-0 pa-0'>${this.createProductsGroup(responce.result)}</div></div>`;
  101. $("#" + containerid).html(html);
  102. this.allEventsExecuted = false;
  103. this.itemInfoElement = null;
  104. this.productContainerElement = null;
  105. this.productInfoElement = null;
  106. this.cartInfoElement = null;
  107. $(".products-container .products-container-body").append(this.createItemsList(res.result, false, true));
  108. $('#poscart_details').find('.Section').first().find(".card-body").first().append(Bizgaze.Apps.Transact.Controls.CartItem.Instance().getCartHtml());
  109. !this.allEventsExecuted && this.eventListeners();
  110. this.initializeCarousel();
  111. this.initializeKeyBoard();
  112. this.applyCartBodyHeight();
  113. $(".btn_Save_Form").hide();
  114. $(".btnSection_CardPayment").removeClass("btn-primary");
  115. $(".btnSection_CardPayment").addClass("btn-dark");
  116. }
  117. });
  118. }
  119. else {
  120. html = `<div class='card section-products-items'><div class='card-body row m-0 pa-0'>${this.createProductsGroup(responce.result)}</div></div>`;
  121. $("#" + containerid).html(html);
  122. this.allEventsExecuted = false;
  123. this.itemInfoElement = null;
  124. this.productContainerElement = null;
  125. this.productInfoElement = null;
  126. this.cartInfoElement = null;
  127. $(".products-container .products-container-body").append(this.createItemsList(responce.result, false, true));
  128. $('#poscart_details').find('.Section').first().find(".card-body").first().append(Bizgaze.Apps.Transact.Controls.CartItem.Instance().getCartHtml());
  129. this.initializeKeyBoard();
  130. this.applyCartBodyHeight();
  131. !this.allEventsExecuted && this.eventListeners();
  132. }
  133. });
  134. }
  135. else {
  136. this.renderSampleTemplate();
  137. }
  138. }
  139. initializeCarousel() {
  140. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadFile({
  141. FileName: 'libs/owl.carousel/owl.carousel.min.js',
  142. FileType: Unibase.Platform.Helpers.FileType.Js
  143. }, function () {
  144. $('.products-container-data').owlCarousel({
  145. items: 5,
  146. margin: 10,
  147. autoplay: false,
  148. nav: true,
  149. });
  150. });
  151. }
  152. initializeKeyBoard() {
  153. let kioskboard = `KioskBoard.Init({
  154. keysArrayOfObjects: null,
  155. keysJsonUrl: 'libs/kioskboard/kioskboard-keys-english.json',
  156. specialCharactersObject: null,
  157. language: 'en',
  158. theme: 'Material',
  159. capsLockActive: true,
  160. allowRealKeyboard: false,
  161. allowMobileKeyboard: false,
  162. cssAnimations: false,
  163. cssAnimationsStyle: 'slide',
  164. keysAllowSpacebar: true,
  165. keysSpacebarText: 'Space',
  166. keysFontFamily: 'sans-serif',
  167. keysFontSize: '22px',
  168. keysFontWeight: 'normal',
  169. keysIconSize: '25px',
  170. autoScroll: true,
  171. });
  172. KioskBoard.Run('.virtual-keyboard');
  173. `;
  174. eval(kioskboard);
  175. }
  176. runVirtualKeyboard() {
  177. let kioskboardRun = `KioskBoard.Run('.virtual-keyboard');`;
  178. eval(kioskboardRun);
  179. }
  180. applyCartBodyHeight() {
  181. let cartParentEl = $('#poscart_details .cart-container');
  182. let cartHeaderHeight = cartParentEl.find('.card-header').outerHeight(true);
  183. let cartFooterHeight = cartParentEl.find('.cart-footer').outerHeight(true);
  184. let deductHeight = cartHeaderHeight + cartFooterHeight;
  185. cartParentEl.find('.cart-body').css('height', `calc(100% - ${deductHeight}px)`);
  186. }
  187. renderSampleTemplate() {
  188. let html = `<div class="section_ItemDetails card products-container section-products-items">
  189. <div class="card-header"> Item Details </div>
  190. <div class="card-body products-container-body pl-0 py-0">
  191. <div class="row products-container-data">
  192. <p class=""> Please select the LOB to show info...</p>
  193. </div>
  194. </div>
  195. </div>`;
  196. $("#" + this.containerId).html(html);
  197. !this.allEventsExecuted && this.eventListeners();
  198. }
  199. totalDiscount() {
  200. this.totalDiscount;
  201. for (var i = 0; i < this.userCart.length; i++) {
  202. let itemId = this.userCart[i].itemId;
  203. let itemPrice = this.userCart[i].itemPrice;
  204. let itemDiscount = this.userCart[i].discountValue * this.userCart[i].quantity;
  205. if (itemPrice > 0) {
  206. this.totalDiscountValue = this.totalDiscountValue + itemDiscount;
  207. }
  208. }
  209. }
  210. getOfferDetails(itemDetails, focItemId) {
  211. var price = (itemDetails.quantity * itemDetails.itemPrice).toFixed(2);
  212. var orderItems = [];
  213. var instance = this;
  214. var result;
  215. orderItems.push({
  216. ItemId: Number(itemDetails.itemId),
  217. Quantity: Number(parseFloat(itemDetails.quantity).toFixed(2)),
  218. RowTotal: Number(price),
  219. });
  220. var data = {
  221. OrderItems: orderItems,
  222. ContactId: Number(instance.contactId),
  223. ApplyType: 1,
  224. };
  225. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getOffersByItemIdWithPrice(data).then((response) => {
  226. if (response.result != null && response.result != "") {
  227. for (var i = 0; i < response.result.length; i++) {
  228. var result = response.result[i];
  229. var offer = response.result[i].Offer;
  230. var index = this.userCart.findIndex(x => x.itemId == itemDetails.itemId);
  231. var discount = "";
  232. if (offer.DiscountType == 1) {
  233. if (index != -1) {
  234. discount = offer.PayoutValue;
  235. this.userCart[index].discountValue = offer.PayoutValue;
  236. this.userCart[index].discountRate = parseFloat(((offer.PayoutValue / (itemDetails.itemPrice * itemDetails.quantity)) * 100).toString()).toFixed(0);
  237. }
  238. }
  239. else if (offer.DiscountType == 2) {
  240. var discountPercentage = offer.PayoutPercent;
  241. discount = parseFloat(((itemDetails.itemPrice) * (discountPercentage / 100)).toString()).toFixed(2);
  242. if (index != -1) {
  243. this.userCart[index].discountValue = discount;
  244. this.userCart[index].discountRate = offer.PayoutPercent;
  245. }
  246. }
  247. else if (offer.DiscountType == 3) {
  248. if (index != -1) {
  249. this.userCart[index].discountValue = offer.OPayoutValue;
  250. discount = offer.OPayoutValue;
  251. }
  252. }
  253. let cartContainerItemElement = document.querySelector(".cart-container [data-itemId='" + itemDetails.itemId + "'][data-productId='" + itemDetails.productId + "']");
  254. if (cartContainerItemElement) {
  255. $(cartContainerItemElement).find('.item-discount').removeClass("d-none");
  256. $(cartContainerItemElement).find('.item-discount').text(" - (" + this.userCart[index].discountRate + "%)");
  257. $(cartContainerItemElement).find(".total-accessible-price").text((((itemDetails.quantity * itemDetails.itemPrice) - Number(discount)).toFixed(2)).toString());
  258. }
  259. this.userCart[index].accessibleAmount = parseFloat((itemDetails.itemPrice - Number(discount)).toString()).toFixed(2);
  260. if (offer.ItemVolumePayouts.length > 0) {
  261. for (var j = 0; j < offer.ItemVolumePayouts.length; j++) {
  262. var offerItem = offer.ItemVolumePayouts[j];
  263. if (itemDetails.quantity >= offerItem.Recur) {
  264. var imageurl = offerItem.ImageUrl;
  265. if (imageurl != null && imageurl != undefined && imageurl != "") {
  266. var image = imageurl.split("~");
  267. var imageIndex = this.itemImage.findIndex(x => x.itemId == offerItem.ItemId);
  268. if (imageIndex == -1) {
  269. this.itemImage.push({ "itemId": offerItem.ItemId, "image": image[1] });
  270. }
  271. }
  272. var _itemDetails = result.ItemDetails;
  273. var unitprice = _itemDetails.find(x => x.ItemId == offerItem.ItemId);
  274. var price = unitprice.UnitPrice;
  275. var tax = unitprice.TaxRate;
  276. var focValue = ((offerItem.Discount / 100) * price).toString();
  277. var discountItemPrice = Number(parseFloat(focValue).toFixed(2));
  278. var effectivePrice = price - discountItemPrice;
  279. var index = this.userCart.findIndex(x => x.offerrefid == itemDetails.itemId && x.itemId == offerItem.ItemId && x.productId == 0);
  280. if (index == -1) {
  281. if (focItemId != null && focItemId != undefined && focItemId != 0) {
  282. if (offerItem.ItemId == focItemId) {
  283. this.userCart.push({ lobId: this.lobId, productId: 0, itemId: offerItem.ItemId, quantity: offerItem.Quantity, itemPrice: price, itemName: offerItem.ItemName, totalPrice: 0, offerrefid: itemDetails.itemId, isFOC: true, taxAmmount: 0, discountValue: discountItemPrice, discountRate: offerItem.Discount, accessibleAmount: effectivePrice, incentiveName: offer.IncentiveName });
  284. }
  285. }
  286. else {
  287. var offerItems = this.userCart.filter(x => x.offerrefid == itemDetails.itemId);
  288. if (offerItems.length > 0) {
  289. for (var k = 0; k < offerItems.length; k++) {
  290. if (offerItems[k].itemId == offerItem.ItemId) {
  291. this.userCart.push({ lobId: this.lobId, productId: 0, itemId: offerItem.ItemId, quantity: offerItem.Quantity, itemPrice: price, itemName: offerItem.ItemName, totalPrice: 0, offerrefid: itemDetails.itemId, isFOC: true, taxAmmount: 0, discountValue: discountItemPrice, discountRate: offerItem.Discount, accessibleAmount: effectivePrice, incentiveName: offer.IncentiveName });
  292. }
  293. }
  294. }
  295. else {
  296. if (!offerItem.IsFoC) {
  297. this.userCart.push({ lobId: this.lobId, productId: 0, itemId: offerItem.ItemId, quantity: offerItem.Quantity, itemPrice: price, itemName: offerItem.ItemName, totalPrice: 0, offerrefid: itemDetails.itemId, isFOC: true, taxAmmount: 0, discountValue: discountItemPrice, discountRate: offerItem.Discount, accessibleAmount: effectivePrice, incentiveName: offer.IncentiveName });
  298. }
  299. }
  300. }
  301. }
  302. else {
  303. this.userCart[index].quantity = parseInt(offerItem.Quantity);
  304. }
  305. this.cartInst.updateCartContainerHtml(offerItem.ItemId, 0);
  306. }
  307. }
  308. }
  309. else {
  310. var offerItemIndex = this.userCart.findIndex(x => x.offerrefid == itemDetails.itemId && x.incentiveName != offer.IncentiveName);
  311. if (offerItemIndex != -1) {
  312. this.removeItemFromItemCartAndUsercart(this.userCart[offerItemIndex].productId, this.userCart[offerItemIndex].itemId);
  313. }
  314. }
  315. }
  316. }
  317. });
  318. return result;
  319. }
  320. totalPrice(cartArrayList) {
  321. var total;
  322. var grandTotal = 0;
  323. for (var i = 0; i < cartArrayList.length; i++) {
  324. if (cartArrayList[i].isFOC) {
  325. total = cartArrayList[i].accessibleAmount * cartArrayList[i].quantity;
  326. }
  327. else {
  328. total = cartArrayList[i].itemPrice * cartArrayList[i].quantity;
  329. }
  330. grandTotal = grandTotal + total;
  331. }
  332. return grandTotal;
  333. }
  334. updateDataArray(itemsArray, accountId) {
  335. return __awaiter(this, void 0, void 0, function* () {
  336. var instance = this;
  337. for (var i = 0; i < itemsArray.length; i++) {
  338. var index = instance.selectedItemsArray.find(x => x.itemId == itemsArray[i].ItemId);
  339. if (index == undefined) {
  340. itemsArray[i].AccountId = 0;
  341. itemsArray[i].TaxGroupId = 0;
  342. instance.selectedItemsArray.push({ "UnitPrice": itemsArray[i].UnitPrice, "UnitName": itemsArray[i].UnitName, "UnitId": itemsArray[i].UnitId, "TaxAmount": itemsArray[i].TaxRate, "StatusId": itemsArray[i].StatusId, "SKU": itemsArray[i].SKU, "ProductName": itemsArray[i].ProductName, "productId": itemsArray[i].ProductId, "LobId": itemsArray[i].LobId, "itemId": itemsArray[i].ItemId, "actualPrice": itemsArray[i].UnitPrice - itemsArray[i].TaxRate, "taxGroupId": itemsArray[i].TaxGroupId, "accountId": itemsArray[i].AccountId, "accountName": itemsArray[i].AccountName, "isOfferAvailable": itemsArray[i].IsOfferAvailable, "isFocAvailable": itemsArray[i].IsFocAvailable, "itemName": itemsArray[i].ItemName });
  343. }
  344. }
  345. });
  346. }
  347. getLobAccountId(branchId) {
  348. return __awaiter(this, void 0, void 0, function* () {
  349. var accountId = 0;
  350. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", () => {
  351. Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLobLedgerSetting(this.lobId, branchId).then((response) => {
  352. accountId = response.result.SettingValue1;
  353. });
  354. });
  355. return accountId;
  356. });
  357. }
  358. eventListeners() {
  359. if (!this.productContainerElement) {
  360. var timer;
  361. $("#txtSearchItem").unbind().on('change', () => {
  362. var delay = 1500;
  363. window.clearTimeout(timer);
  364. timer = window.setTimeout(() => {
  365. var searchtext = $("#txtSearchItem").val();
  366. if (searchtext != "") {
  367. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemsUnitPriceByProductId(0, this.contactId, searchtext).then((response) => {
  368. this.refreshItems(response, "");
  369. this.allEventsExecuted = false;
  370. this.eventListeners();
  371. });
  372. }
  373. else {
  374. this.refreshItems(this.resBeforeSearch, this.dataBeforeSearch);
  375. this.allEventsExecuted = false;
  376. this.eventListeners();
  377. }
  378. }, delay);
  379. });
  380. $(".txtAutoComplete_lobid").change(() => {
  381. });
  382. $("[id^=btn_CloseForm_]").click(() => {
  383. $(".section-products-items").remove();
  384. $("body").off("mousedown", "body", this.eventListeners);
  385. this.userCart = [];
  386. this.productContainerElement = null;
  387. this.itemInfoElement = null;
  388. this.productInfoElement = null;
  389. this.allEventsExecuted = false;
  390. this.isCheckoutMode = false;
  391. });
  392. $("#btnDynamicSave").prop('disabled', true);
  393. $(".txt_cashamount").change(() => {
  394. var totalstring = $("#grand_total_checkout").text();
  395. var total = parseFloat(totalstring);
  396. var ammountstring = $(".txt_cashamount").val();
  397. var ammount = parseFloat(ammountstring);
  398. if (ammount > total) {
  399. $("#btnDynamicSave").prop('disabled', false);
  400. }
  401. });
  402. $(".txt_cashamount").on('click', () => {
  403. this.isKeyboard = true;
  404. });
  405. var cash = $(".txt_cashamount").val();
  406. if (cash == "") {
  407. $("#btnDynamicSave").prop('disabled', true);
  408. }
  409. else {
  410. $("#btnDynamicSave").prop('disabled', false);
  411. }
  412. $(".btnSection_AddItems").click(() => {
  413. this.isCheckoutMode = false;
  414. $(".section_ContactInformation").hide();
  415. $(".section_PaymentInformation").hide();
  416. $(".section_CompanyDetails ").hide();
  417. $(".section_Items").show();
  418. $("#btn_SaveAsDraft").hide();
  419. $(".btn_Save_Form").hide();
  420. $('#billDetailsWrap').addClass('d-none');
  421. $('.cart-checkout-btn').removeClass('d-none');
  422. var lengnth = Bizgaze.Apps.Transact.Controls.Pos.Instance().userCart.length;
  423. if (lengnth == 0) {
  424. $('.cart-checkout-btn').addClass('d-none');
  425. }
  426. else {
  427. $('.cart-checkout-btn').removeClass('d-none');
  428. }
  429. this.applyCartBodyHeight();
  430. $(".txt_cashamount").val("");
  431. $(".txt_change").val("");
  432. });
  433. $(".btn_Save_Form").hide();
  434. $(".btn_SaveAsDraft").hide();
  435. var ammountstring = $(".txt_cashamount").val();
  436. var ammount = parseInt(ammountstring.toString());
  437. if (ammount > 0) {
  438. $(".div_cashamount").show();
  439. $(".div_change").show();
  440. }
  441. else {
  442. $(".div_cashamount").hide();
  443. $(".div_change").hide();
  444. }
  445. $(".divCustomProperties_upitypeid").removeClass('col-sm-12').hide();
  446. $(".divCustomProperties_voucherno").hide();
  447. $(".btnSection_CashPayment").click(() => {
  448. $(".div_cashamount").toggle();
  449. $(".div_change").toggle();
  450. $(".divCustomProperties_upitypeid").hide();
  451. $(".hdn_iscash").val("true");
  452. $(".hdn_iscard").val("false");
  453. $(".hdn_isupi").val("false");
  454. $("#btnDynamicSave").prop('disabled', true);
  455. });
  456. $(".btnSection_CardPayment").click(() => {
  457. $(".div_cashamount").hide();
  458. $(".div_change").hide();
  459. $(".txt_cashamount").val("0");
  460. $(".txt_change").val("0");
  461. $(".divCustomProperties_upitypeid").hide();
  462. $(".hdn_iscash").val("false");
  463. $(".hdn_iscard").val("true");
  464. $(".hdn_isupi").val("false");
  465. $("#btnDynamicSave").prop('disabled', false);
  466. });
  467. $(".btnSection_UpiPayment").click(() => {
  468. $(".div_cashamount").hide();
  469. $(".div_change").hide();
  470. $(".txt_cashamount").val("0");
  471. $(".txt_change").val("0");
  472. $(".divCustomProperties_upitypeid").toggle();
  473. $(".hdn_iscash").val("false");
  474. $(".hdn_iscard").val("false");
  475. $(".hdn_isupi").val("true");
  476. });
  477. $(".chk_isvoucher").click(() => {
  478. $(".divCustomProperties_voucherno").toggle();
  479. });
  480. if ($('.products-container-body').is(':visible')) {
  481. $(".section_ContactInformation").hide();
  482. $(".section_PaymentInformation").addClass('mb-0').hide();
  483. }
  484. this.productContainerElement = document.querySelector(".products-container .products-container-data");
  485. $('.products-container').on('click', '.group-name,.item-name', function () {
  486. let element = this;
  487. if (element.offsetWidth < element.scrollWidth) {
  488. $(this).popover('toggle');
  489. }
  490. });
  491. $('#pos_details').on('click', 'input:visible', function () {
  492. setTimeout(function () {
  493. if ($('#KioskBoard-VirtualKeyboard').is(':visible')) {
  494. let keyboardHeight = $('#KioskBoard-VirtualKeyboard').outerHeight(true);
  495. let posHeight = $('#pos_details').outerHeight(true);
  496. $('#pos_details').css('height', `${posHeight - (keyboardHeight - 70)}px`);
  497. }
  498. }, 100);
  499. });
  500. let parentEl = $('.pos_container');
  501. parentEl.find('#txtPhn_phonenumber,.txt_cashamount,.txt_change').addClass('virtual-keyboard').attr('data-kioskboard-type', 'numpad');
  502. parentEl.find('.txt_contactname').addClass('virtual-keyboard').attr({ 'data-kioskboard-type': 'keyboard', 'data-kioskboard-specialcharacters': 'false' });
  503. parentEl.find('.txt_contactemail').addClass('virtual-keyboard').attr({ 'data-kioskboard-type': 'all', 'data-kioskboard-specialcharacters': 'true' });
  504. const paymentSectionEl = $('.section_PaymentInformation');
  505. const paymentCardBodyRow = paymentSectionEl.find('.card-body .row').first();
  506. paymentCardBodyRow.addClass('mx-0').prepend('<div id="posPaymentModes" class="pos-payment-modes col-xl-3 col-lg-4 col-md-6"></div><div id="posPaymentDetails" class="pos-payment-details col-xl-9 col-lg-8 col-md-6"></div>');
  507. paymentSectionEl.find('#divSectionProperties_CashPayment,#divSectionProperties_CardPayment,#divSectionProperties_UpiPayment').removeClass('col-sm-4').detach().appendTo('#posPaymentModes');
  508. paymentCardBodyRow.find('.divCustomProperties').removeClass('col-sm-6').detach().appendTo('#posPaymentDetails');
  509. $('#posPaymentModes').find('.divSectionProperties').removeClass('mt-10').addClass('my-1').find('.btn').removeClass('btn-primary mt-20 text-white').addClass('w-100');
  510. $('#posPaymentModes').find('.btn.type-control').click(function () {
  511. $('#posPaymentModes').find('.btn.type-control').removeClass('active');
  512. $(this).addClass('active');
  513. });
  514. $('.btnSection_CashPayment').trigger('click');
  515. $(".btnSection_AddItems").removeClass('mt-20');
  516. }
  517. if (!this.productInfoElement) {
  518. this.productInfoElement = document.querySelector(".products-container .product-info");
  519. if (true) {
  520. $(".pos_container").mousedown((e) => {
  521. let virtualkeybord = e.target.closest(".kioskboard-row-numpad");
  522. let currentProductCard = e.target.closest(".product-info");
  523. let itemCard_clst = e.target.closest(".item-data");
  524. let btn_decrement_clst = e.target.closest(".item-decrement-btn");
  525. let btn_increment_clst = e.target.closest(".item-increment-btn");
  526. let btn_decrement = e.target.classList.contains(".item-decrement-btn");
  527. let btn_increment = e.target.classList.contains(".item-increment-btn");
  528. let cartInfo_clst = e.target.closest(".cart-item-info");
  529. let offerInfo = e.target.classList.contains(".item-offer-msg");
  530. if ($('#KioskBoard-VirtualKeyboard').is(':visible')) {
  531. $('#pos_details').css('height', `auto`);
  532. }
  533. if (currentProductCard) {
  534. let taxInclusive = true;
  535. var branchId = Unibase.Platform.Membership.Infos.Identity.currentUser.settings.find(x => x.settingName == 'branchid').settingValue;
  536. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemsUnitPriceByProductId(currentProductCard.id, this.contactId, null).then((res) => {
  537. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", () => {
  538. Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLobLedgerSetting(this.lobId, branchId).then((response) => {
  539. var accountId = response.result.SettingValue1;
  540. this.updateDataArray(res.result, accountId);
  541. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getpricebyProductId("a", this.lobId, currentProductCard.id).then((data) => {
  542. this.refreshItems(res, data.result);
  543. this.dataBeforeSearch = data.result;
  544. $(".products-container").find(".border-primary")[0].classList.remove("border-primary");
  545. currentProductCard.classList.add("border-2");
  546. currentProductCard.classList.add("border-primary");
  547. });
  548. });
  549. });
  550. });
  551. }
  552. else if ((itemCard_clst && (btn_decrement_clst || btn_increment_clst)) || (btn_decrement || btn_increment)) {
  553. this.setCart_ItemsContainers(itemCard_clst, e);
  554. }
  555. else if ((cartInfo_clst && (btn_decrement_clst || btn_increment_clst)) || (btn_decrement || btn_increment)) {
  556. let productId = parseInt(cartInfo_clst.dataset.productid);
  557. let itemId = parseInt(cartInfo_clst.dataset.itemid);
  558. let itemContainerCardElement = document.querySelector(".items-container [id='" + itemId + "']");
  559. let cartItem = document.querySelector(".cart-container [data-itemId='" + itemId + "'][data-productId='" + productId + "']");
  560. this.updateItemContainerSpinnerOnMDown(cartInfo_clst, e, false);
  561. (itemContainerCardElement) && this.updateItemContainerSpinnerOnMDown(itemContainerCardElement, e, true);
  562. !this.isBootBoxRendered && this.updateUserCart(cartItem, true);
  563. !this.isBootBoxRendered && this.cartInst.updateCartContainerHtml(itemId, productId);
  564. }
  565. else if (cartInfo_clst) {
  566. if (e.target.classList.contains("item-remove-btn") || e.target.closest(".item-remove-btn")) {
  567. let itemId = cartInfo_clst.dataset.itemid;
  568. let productId = cartInfo_clst.dataset.productid;
  569. this.renderDeleteItemDialog(productId, itemId);
  570. }
  571. }
  572. if (virtualkeybord == null && this.isKeyboard == true) {
  573. this.isKeyboard = false;
  574. var totalstring = $("#grand_total_checkout").text();
  575. var total = parseFloat(totalstring);
  576. var ammountstring = $(".txt_cashamount").val();
  577. var ammount = 0;
  578. if (ammountstring != "") {
  579. var ammount = parseFloat(ammountstring);
  580. }
  581. if (ammount < total) {
  582. $("#btnDynamicSave").prop('disabled', true);
  583. var diffAmt = Math.abs(ammount - total);
  584. setTimeout(() => {
  585. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Rs " + parseFloat(diffAmt).toFixed(2) + " is Shortfall for Completion of the Payment");
  586. }, 200);
  587. $("#Bizgaze-messageInfo").fadeOut('fast');
  588. $(".txt_change").val("");
  589. }
  590. else if (ammount >= total) {
  591. $("#btnDynamicSave").prop('disabled', false);
  592. var changeAmt = ammount - total;
  593. $(".txt_change").val(parseFloat(changeAmt).toFixed(2));
  594. }
  595. }
  596. !this.allEventsExecuted && this.eventListeners();
  597. });
  598. }
  599. }
  600. if (!this.itemInfoElement) {
  601. this.itemInfoElement = document.querySelector(".products-container .item-info");
  602. if (this.itemInfoElement) {
  603. $(".item-quantity").change((e) => {
  604. let cartInfo_clst = e.target.closest(".item-info");
  605. this.setCart_ItemsContainers(cartInfo_clst, e);
  606. });
  607. }
  608. }
  609. if (!this.cartInfoElement) {
  610. this.cartInfoElement = document.querySelector(".cart-container .cart-item-info");
  611. if (this.cartInfoElement) {
  612. $(".cart-checkout-btn").click(() => {
  613. this.isCheckoutMode = true;
  614. var totalstring = $("#grand_total_checkout").text();
  615. ;
  616. var total = parseInt(totalstring);
  617. if (total > 0) {
  618. $(".section_ContactInformation").show();
  619. $(".section_PaymentInformation").show();
  620. $(".section_CompanyDetails ").hide();
  621. $(".section_Items").hide();
  622. $(".btn_Save_Form").show();
  623. $("#btn_SaveAsDraft").show();
  624. $('#billDetailsWrap').removeClass('d-none');
  625. $('.cart-checkout-btn').addClass('d-none');
  626. this.applyCartBodyHeight();
  627. }
  628. });
  629. }
  630. }
  631. $("#btnDynamicSave").click(() => {
  632. var instance = this;
  633. Bizgaze.Apps.Transact.Controls.Pos.Instance().userCart = [];
  634. Bizgaze.Apps.Transact.Controls.Pos.Instance().productContainerElement = null;
  635. Bizgaze.Apps.Transact.Controls.Pos.Instance().itemInfoElement = null;
  636. Bizgaze.Apps.Transact.Controls.Pos.Instance().productInfoElement = null;
  637. Bizgaze.Apps.Transact.Controls.Pos.Instance().allEventsExecuted = false;
  638. this.isCheckoutMode = false;
  639. });
  640. if (this.productContainerElement && this.productInfoElement && this.itemInfoElement && this.cartInfoElement)
  641. this.allEventsExecuted = true;
  642. }
  643. saveASDraft() {
  644. Bizgaze.Apps.Transact.Controls.Pos.Instance().isdraft = true;
  645. let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  646. $(".hdn_isdraft").val("true");
  647. var isDraft = $(".hdn_isdraft").val();
  648. if (isDraft == "true") {
  649. Bizgaze.Apps.Transact.Controls.Pos.Instance().isdraft = true;
  650. }
  651. else {
  652. Bizgaze.Apps.Transact.Controls.Pos.Instance().isdraft = false;
  653. }
  654. var cash = $(".txt_cashamount").val();
  655. if (cash == "") {
  656. $(".txt_cashamount").val("0");
  657. $(".txt_change").val("0");
  658. }
  659. $(detailContainer).find("#btnDynamicSave").click();
  660. }
  661. ;
  662. setCart_ItemsContainers(itemCard_clst, e) {
  663. let itemPriceElement = itemCard_clst.querySelector(".prodPrice");
  664. let itemPriceValue = parseInt(itemPriceElement.innerText);
  665. if (itemPriceValue > 0) {
  666. let productElement = document.querySelector(".products-container .border-primary").closest(".product-info");
  667. this.updateItemContainerSpinnerOnMDown(itemCard_clst, e, true);
  668. this.updateUserCart(itemCard_clst, false);
  669. let offeritem = this.userCart.filter(x => x.itemId == parseInt(itemCard_clst.id));
  670. offeritem.find(x => x.offerId != 0);
  671. this.cartInst.updateCartContainerHtml(parseInt(itemCard_clst.id), parseInt(productElement.id));
  672. }
  673. }
  674. updateCheckoutPrice() {
  675. if (this.invoiceid == 0) {
  676. this.totalTaxAmount = 0;
  677. }
  678. this.totalDiscountAmount = 0;
  679. this.totalAdjustmentAmmount = 0;
  680. for (var i = 0; i < this.userCart.length; i++) {
  681. let tax = parseFloat(this.userCart[i].taxAmmount);
  682. let actualAmount = (parseFloat(this.userCart[i].itemPrice)) * this.userCart[i].quantity;
  683. this.totalTaxAmount += (actualAmount) * (tax / 100);
  684. this.totalDiscountAmount += parseFloat(this.userCart[i].discountValue) * this.userCart[i].quantity;
  685. }
  686. $("#total_taxprice").text(parseFloat(this.totalTaxAmount).toFixed(2));
  687. $("#total_discountprice").text(parseFloat(this.totalDiscountAmount).toFixed(2));
  688. let totalVal = 0;
  689. var totalSum = this.totalPrice(this.userCart);
  690. let adjustmentprice = (Number(totalSum) - (Number(this.totalTaxAmount))).toFixed(2);
  691. $("#total_adjustmentprice").text(parseFloat(adjustmentprice).toFixed(2));
  692. $('.cart-checkout-btn .total-price').text(parseFloat(totalSum.toString()).toFixed(2));
  693. if (totalSum == 0) {
  694. $('.cart-checkout-btn').addClass('d-none');
  695. }
  696. else {
  697. if (!this.isCheckoutMode) {
  698. $('.cart-checkout-btn').removeClass('d-none');
  699. }
  700. }
  701. }
  702. updateItemContainerSpinnerOnMDown(itemCard_clst, e, isItemContainer, quantity) {
  703. let itemQantityElement;
  704. if (!isItemContainer) {
  705. itemQantityElement = $(itemCard_clst).find(".item-quantity");
  706. }
  707. else {
  708. itemQantityElement = $(itemCard_clst).find(".item-quantity");
  709. }
  710. let itemQantityValue = parseInt(itemQantityElement.val() || itemQantityElement.text());
  711. if (e != null) {
  712. if (e.target.closest(".item-decrement-btn")) {
  713. if (itemQantityValue == 1 && !isItemContainer) {
  714. this.renderDeleteItemDialog(parseInt(itemCard_clst.dataset.productid), parseInt(itemCard_clst.dataset.itemid));
  715. this.isBootBoxRendered = true;
  716. }
  717. else if (itemQantityValue == 1) {
  718. !this.isBootBoxRendered && this.renderDeleteItemDialog(parseInt(document.querySelector(".products-container .border-primary").id), parseInt(itemCard_clst.id));
  719. this.totalPrice(this.userCart);
  720. }
  721. else {
  722. if (itemQantityValue) {
  723. itemQantityElement.val((itemQantityValue - 1).toString());
  724. itemQantityElement.text((itemQantityValue - 1).toString());
  725. }
  726. else
  727. itemQantityElement.val("0");
  728. this.totalPrice(this.userCart);
  729. }
  730. }
  731. else if (e.target.closest(".item-increment-btn")) {
  732. if (itemQantityValue) {
  733. itemQantityElement.val((itemQantityValue + 1).toString());
  734. itemQantityElement.text((itemQantityValue + 1).toString());
  735. }
  736. else
  737. itemQantityElement.val("1");
  738. this.totalPrice(this.userCart);
  739. }
  740. }
  741. else if (quantity > 0) {
  742. itemQantityElement.val((quantity).toString());
  743. }
  744. }
  745. renderDeleteItemDialog(productId, itemId) {
  746. bootbox.confirm("Are you sure you want delete this Item ?", (result) => {
  747. let cartItem = document.querySelector(".cart-container [data-itemId='" + itemId + "'][data-productId='" + productId + "']");
  748. if (result) {
  749. this.removeItemFromItemCartAndUsercart(productId, itemId);
  750. var offeritems = this.userCart.filter(x => x.offerrefid == itemId);
  751. if (offeritems != null) {
  752. for (var i = 0; i < offeritems.length; i++) {
  753. this.removeItemFromItemCartAndUsercart(offeritems[i].productId, offeritems[i].itemId);
  754. }
  755. }
  756. }
  757. this.isBootBoxRendered = false;
  758. });
  759. }
  760. removeItemFromItemCartAndUsercart(productId, itemId) {
  761. this.removeCartItemFromCartContainer(productId, itemId);
  762. this.removeItemFromCart(parseInt(productId), parseInt(itemId));
  763. let itemhtml = document.getElementById(itemId);
  764. (itemhtml) && (itemhtml.querySelector(".item-quantity").value = "0");
  765. }
  766. removeItemFromCart(productId, itemId) {
  767. var ins = Bizgaze.Apps.Transact.Controls.Pos.Instance();
  768. let index = ins.userCart.findIndex(x => x.productId == productId && x.itemId == itemId);
  769. if (index != -1) {
  770. ins.userCart.splice(index, 1);
  771. this.updateCartItemsOnDelete();
  772. this.updateCheckoutPrice();
  773. }
  774. if (index == 0) {
  775. $(".total-pay-price-wrap").remove();
  776. $(".bill-details").remove();
  777. }
  778. }
  779. updateUserCart(itemCard, isCartItem) {
  780. let itemId;
  781. let productId;
  782. let productElement = document.querySelector(".products-container .border-primary").closest(".product-info");
  783. let itemPrice = parseFloat(itemCard.querySelector(".item-price").textContent).toFixed(2);
  784. let itemName = itemCard.querySelector(".item-name").textContent;
  785. let itemQantityElement = itemCard.querySelector(".item-quantity");
  786. var totalPrice = this.totalPrice(this.userCart);
  787. let discount = parseFloat(itemCard.querySelector(".discount_amount").value);
  788. let taxAmount = parseFloat(itemCard.querySelector(".item-tax-amount").value);
  789. (isCartItem) ? productId = parseInt(itemCard.dataset.productid) : productId = parseInt(productElement.id);
  790. (isCartItem) ? itemId = parseInt(itemCard.dataset.itemid) : itemId = parseInt(itemCard.id);
  791. ;
  792. let index = this.userCart.findIndex(x => x.itemId == itemId && x.productId == productId);
  793. if (index == -1) {
  794. var item = this.selectedItemsArray.find(x => x.itemId == itemId);
  795. var taxIndex = this.selectedItemsArray.findIndex(x => x.itemId == itemId && x.productId == productId);
  796. var taxAmmount = 0;
  797. if (taxIndex != -1) {
  798. taxAmmount = this.selectedItemsArray[taxIndex].TaxAmount;
  799. }
  800. if (item != null && item.isOfferAvailable) {
  801. this.userCart.push({ lobId: this.lobId, productId: productId, itemId: itemId, quantity: parseInt(itemQantityElement.value), itemPrice: itemPrice, itemName: itemName, totalPrice: totalPrice, offerrefid: 0, isFOC: false, discountValue: 0, taxAmmount: taxAmmount, accessibleAmount: itemPrice });
  802. var itemDetails = this.userCart.find(x => x.itemId == itemId);
  803. var offer = this.getOfferDetails(itemDetails);
  804. }
  805. else {
  806. this.userCart.push({ lobId: this.lobId, productId: productId, itemId: itemId, quantity: parseInt(itemQantityElement.value), itemPrice: itemPrice, itemName: itemName, totalPrice: totalPrice, offerrefid: 0, isFOC: false, discountValue: 0, taxAmmount: taxAmmount, accessibleAmount: itemPrice });
  807. }
  808. }
  809. else {
  810. this.userCart[index].quantity = parseInt(itemQantityElement.value);
  811. var itemDetails = this.userCart.find(x => x.itemId == itemId);
  812. var offer = this.getOfferDetails(itemDetails);
  813. }
  814. }
  815. updateCheckoutPageList() {
  816. if (this.invoiceid == 0) {
  817. this.totalTaxAmount = 0;
  818. }
  819. this.totalDiscountAmount = 0;
  820. this.totalAdjustmentAmmount = 0;
  821. for (var i = 0; i < this.userCart.length; i++) {
  822. let tax = this.userCart[i].taxAmmount;
  823. let actualAmount = (this.userCart[i].itemPrice - this.userCart[i].discountValue) * this.userCart[i].quantity;
  824. this.totalTaxAmount += (actualAmount) * (tax / 100);
  825. let taxammount = (actualAmount) * (tax / 100);
  826. this.totalDiscountAmount += this.userCart[i].discountValue * this.userCart[i].quantity;
  827. this.totalAdjustmentAmmount += ((actualAmount) - (taxammount));
  828. }
  829. }
  830. removeCartItemFromCartContainer(productId, itemId) {
  831. let cartItem = document.querySelector(".cart-container [data-itemId='" + itemId + "'][data-productId='" + productId + "']");
  832. (cartItem) && cartItem.remove();
  833. }
  834. updateCartItemsOnDelete() {
  835. let cartItemsEle = document.querySelector(".cart-container #cart-quantity");
  836. let firstEle = cartItemsEle.firstElementChild.outerHTML;
  837. firstEle += this.userCart.length + " Items";
  838. cartItemsEle.innerHTML = firstEle;
  839. }
  840. createProductsGroup(list) {
  841. let html = "";
  842. for (var i = 0; i < list.length; i++) {
  843. html += this.getProductsHtml(list[i]);
  844. if (i == 0)
  845. html = this.initialSelectedEffect(list[i], html);
  846. }
  847. return `<div class="col-12 px-0 products-container">
  848. <div class="card-body products-container-body">
  849. <div class="item-search-wrap"><input type="text" maxlength="50" class="form-control virtual-keyboard" id="txtSearchItem" value="" data-kioskboard-type="all" data-kioskboard-specialcharacters="false" data-isdynamic="false" placeholder="Search" data-placeholder="Search" data-label="Search"><i class="fa fa-search item-search-icon biz-highlight-bg-color"></i></div>
  850. <div class="products-container-data owl-carousel owl-theme mx-0" id="productsCarousel">
  851. ${html}
  852. </div>
  853. </div>
  854. </div>
  855. <div class="panel panel-default" style="padding-bottom: 10px;" id="invoiceitem">
  856. <input type="hidden" id="hdn_customcontrol" class="value-control" value="Bizgaze.Apps.Transact.Controls.Pos.Instance().loaddata();" />
  857. <input type="hidden" id="hdninvoiceitem" class="" value="" data-isdynamic="true" data-propdoctypename="" /></div>
  858. </div>`;
  859. }
  860. getProductsHtml(productGroupDetails) {
  861. var imageurl = productGroupDetails.UploadImage;
  862. var image = "";
  863. if (imageurl != null && imageurl != undefined && imageurl != "") {
  864. image = imageurl.split("~");
  865. this.productImage = image[1];
  866. }
  867. return `<div class="card product-info" id="${productGroupDetails.ProductId}"><div class="product-img-wrapper"><img src="${this.productImage}" class="product-img"></div><span class="group-name" tabindex="0" data-trigger="focus" data-placement="top" data-content="${productGroupDetails.ProductName}">${productGroupDetails.ProductName}</span></div>`;
  868. }
  869. loaddata() {
  870. var instance = this;
  871. var itemarray = [];
  872. var itemsarray = [];
  873. var totalAmount = 0;
  874. var branchId = Unibase.Platform.Membership.Infos.Identity.currentUser.settings.find(x => x.settingName == 'branchid').settingValue;
  875. for (var i = 0; i < instance.userCart.length; i++) {
  876. var data = instance.selectedItemsArray.find(x => x.productId == instance.userCart[i].productId && x.itemId == instance.userCart[i].itemId);
  877. if (data != undefined) {
  878. totalAmount = totalAmount + Number(instance.userCart[i].itemPrice);
  879. itemsarray.push({ "ItemId": instance.userCart[i].itemId, "UnitPrice": Number(instance.userCart[i].itemPrice), "istaxinclusive": true, "AccountId": data.accountId, "TotalAmount": Number(instance.userCart[i].itemPrice), "Quantity": instance.userCart[i].quantity, "DiscountAmount": instance.userCart[i].discountValue, "DiscountType": 1 });
  880. }
  881. else {
  882. totalAmount = totalAmount + Number(instance.userCart[i].itemPrice);
  883. itemsarray.push({ "ItemId": instance.userCart[i].itemId, "UnitPrice": Number(instance.userCart[i].itemPrice), "istaxinclusive": true, "AccountId": 0, "TotalAmount": Number(instance.userCart[i].itemPrice), "Quantity": instance.userCart[i].quantity, "DiscountAmount": instance.userCart[i].discountValue, "DiscountType": 1 });
  884. }
  885. }
  886. var InvoiceObject = {
  887. TotalAmount: Number(totalAmount),
  888. InvoiceItems: itemsarray,
  889. InvoiceCharges: [],
  890. AutoAdjustment: false,
  891. AutoDc: false,
  892. InvItemTaxAdjustments: [],
  893. JournalAlloc: [],
  894. AdjustmentAccountId: 0,
  895. InvoiceId: Number($(".hdn_invoiceid").val()),
  896. RefInvoiceId: 0,
  897. OrgContactId: branchId,
  898. DeletedInvoiceId: [],
  899. };
  900. return InvoiceObject;
  901. }
  902. createItemsList(itemsList, getRows, getHeader) {
  903. let html = "";
  904. for (var i = 0; i < itemsList.length; i++)
  905. html += this.createItemHtml(itemsList[i]);
  906. if (getRows)
  907. return html;
  908. else if (getHeader) {
  909. return `<div data-simplebar class="simple-scroll-bar items-container" id="itemsContainer">
  910. <div class="items-data">
  911. No items to display...
  912. </div>
  913. </div>`;
  914. }
  915. return `<div data-simplebar class="simple-scroll-bar items-container" id="itemsContainer">
  916. <div class="items-data">
  917. ${html}
  918. </div>
  919. </div>`;
  920. }
  921. createItemHtml(itemsDetails) {
  922. let index = this.userCart.findIndex(x => x.itemId == itemsDetails.ItemId);
  923. let items = this.userCart.filter(x => x.itemId == itemsDetails.ItemId);
  924. if (index != -1) {
  925. var quantity = this.userCart.find(x => x.itemId == itemsDetails.ItemId);
  926. if (items.length) {
  927. let chargableItem = items.find(x => x.isFOC == false);
  928. if (!chargableItem)
  929. itemsDetails["quantity"] = 0;
  930. else
  931. itemsDetails["quantity"] = quantity.quantity;
  932. }
  933. else
  934. itemsDetails["quantity"] = quantity.quantity;
  935. }
  936. else {
  937. itemsDetails["quantity"] = 0;
  938. }
  939. var imageurl = itemsDetails.ImageUrl;
  940. var image = "";
  941. if (imageurl != null && imageurl != undefined && imageurl != "") {
  942. image = imageurl.split("~");
  943. var imageIndex = this.itemImage.findIndex(x => x.itemId == itemsDetails.ItemId);
  944. if (imageIndex == -1) {
  945. this.itemImage.push({ "itemId": itemsDetails.ItemId, "image": image[1] });
  946. }
  947. image = image[1];
  948. }
  949. var offerString = "";
  950. if (itemsDetails.IsOfferAvailable || itemsDetails.IsFocAvailable) {
  951. offerString = '<div class="item-offer-msg"><span class="badge badge-primary"><i class="las la-tag mr-1 font-12"></i>Offer</span></div>';
  952. }
  953. return `<div class="item-data item-info" id="${itemsDetails.ItemId}" data-offerrefid="${itemsDetails.OfferRefId}">
  954. ` + offerString + `
  955. <div class="item-img-wrapper">
  956. <img src="${image}" class="item-img">
  957. </div>
  958. <div class="item-details-wrapper">
  959. <input class="item-tax-amount hidden" style="" value ="${itemsDetails.TaxAmount}">
  960. <input class="discount_amount d-none hidden" value="${itemsDetails.DiscountAmount}">
  961. <p class="item-name" tabindex="0" data-trigger="focus" data-placement="top" data-content="${itemsDetails.ItemName}">${itemsDetails.ItemName}</p>
  962. <div class="item-meta">
  963. <div class="item-price-wrapper">
  964. <span class="item-price prodPrice">${parseFloat(itemsDetails.UnitPrice).toFixed(2)}</span>
  965. </div>
  966. <div class="cart-counter">
  967. <a class="item-decrement-btn control-btn" href="javascript:;"><i class="las la-minus"></i></a>
  968. <input type="number" min="0" value="${itemsDetails.quantity}" class="prodQuantity item-quantity virtual-keyboard" data-kioskboard-type="numpad">
  969. <a class="item-increment-btn control-btn" href="javascript:;"><i class="las la-plus"></i></a>
  970. </div>
  971. </div>
  972. </div>
  973. </div>`;
  974. }
  975. refreshItems(res, data) {
  976. let html;
  977. if (res.result.length > 0)
  978. html = this.createItemsList(res.result, true);
  979. else if (res.result.length == 0)
  980. html = "No items to display...";
  981. $(".items-container .items-data").empty().append(html);
  982. $(".item-offer-msg").click(() => {
  983. var instance = this;
  984. var itemId;
  985. var itemDetails;
  986. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(0, "", Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance(), function () {
  987. itemId = document.getElementsByClassName("item-offer-msg")[0].parentElement.id;
  988. itemDetails = instance.selectedItemsArray.find(x => x.itemId == itemId);
  989. Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance().LoadOfferItems(Number(instance.contactId), Number(itemId), itemDetails.itemName, 1, null, "Pos");
  990. }, Unibase.Platform.Helpers.Size.Large);
  991. });
  992. }
  993. initialSelectedEffect(product, htmlstr) {
  994. let index = htmlstr.indexOf("card");
  995. return htmlstr.substring(0, index + 4) + " border-2 border-primary " + htmlstr.substring(index + 4, htmlstr.length);
  996. }
  997. bindContactName() {
  998. var instance = this;
  999. Unibase.Platform.Forms.Managers.TagManager.Instance().GetTagItemsByUserId(Unibase.Platform.Membership.Infos.Identity.getCurrentUser().userId).then(function (response) {
  1000. if (response.result.length == 1) {
  1001. instance.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
  1002. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByTagGroupId(response.result[0].TagGroupId).then(function (res) {
  1003. let LobId = res.result.LobId;
  1004. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByLobId(LobId).then(function (result) {
  1005. if (result.result != null) {
  1006. if (result.result.DefaultContactId != 0) {
  1007. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  1008. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getOrgContact(result.result.DefaultContactId).then(function (response) {
  1009. if (response.result != null) {
  1010. let items = Bizgaze.Apps.Transact.Controls.Pos.Instance();
  1011. var _Name = new Option(response.result.OrgContactName, response.result.OrgContactId.toString(), false, false);
  1012. $(".txtAutoComplete_orgcontactid").append(_Name).trigger("change");
  1013. $(".hfAutoCompleteId_orgcontactid").val(response.result.OrgContactId);
  1014. instance.LoadContactDetails();
  1015. }
  1016. });
  1017. });
  1018. }
  1019. }
  1020. });
  1021. });
  1022. });
  1023. }
  1024. });
  1025. $("#btnDynamicSave").after('<a href="javascript:;" id="btn_SaveAsDraft" class="btn btn-yellow btn_POSSaveAsDraft btn-sm" onclick="Bizgaze.Apps.Transact.Controls.Pos.Instance().saveASDraft();;" style="display:none" >Save as Draft</a>');
  1026. $(".hdn_isdraft").val("false");
  1027. }
  1028. LoadContactDetails() {
  1029. var instance = this;
  1030. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorganization($(".hfAutoCompleteId_orgcontactid").val()).then(function (response) {
  1031. if (response.result != null && response.result != "") {
  1032. if (response.result.OrganizationTypeId == 1)
  1033. instance.IswalkinCustomer = false;
  1034. else
  1035. instance.IswalkinCustomer = true;
  1036. instance.LoadSpocDetails($(".hfAutoCompleteId_orgcontactid").val());
  1037. }
  1038. else {
  1039. instance.IswalkinCustomer = false;
  1040. instance.LoadSpocDetails($(".hfAutoCompleteId_orgcontactid").val());
  1041. }
  1042. });
  1043. }
  1044. LoadSpocDetails(contactid) {
  1045. var instance = this;
  1046. if ($('.hdn_invoicetypeid').val() == "1" || $('.hdn_invoicetypeid').val() == "6" || $('.hdn_invoicetypeid').val() == "4") {
  1047. $('.txtAutoComplete_billtoaddressid').empty();
  1048. $('.txtAutoComplete_shiptoaddressid').empty();
  1049. }
  1050. else {
  1051. $('.txtAutoComplete_billfromaddressid').empty();
  1052. $('.txtAutoComplete_shipfromaddressid').empty();
  1053. }
  1054. if ($(".hdn_invoiceid").val() == "0") {
  1055. $(".txtAutoComplete_LobId").empty();
  1056. $(".hfAutoCompleteId_LobId").empty();
  1057. }
  1058. $(".txtAutoComplete_salespersonid").empty();
  1059. $(".hfAutoCompleteId_salespersoid").empty();
  1060. if (instance.IswalkinCustomer == true) {
  1061. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorganization(contactid).then(function (response) {
  1062. if (response.result != null) {
  1063. $(".hdn_organizationid").val(response.result.OrganizationId);
  1064. $("#hfInv_OrganizationName").val(response.result.OrganizationName);
  1065. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined) {
  1066. instance.GetCustomerTurnOver();
  1067. }
  1068. $.when(instance.loadAddressAutoCompletes(response.result.OrganizationId)).then(function () {
  1069. instance.BindAddressDetails(response.result.OrganizationId);
  1070. instance.GetAvailableWallets(0);
  1071. });
  1072. }
  1073. });
  1074. }
  1075. else {
  1076. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorgcontact(contactid).then(function (response) {
  1077. var data = response.result;
  1078. if (response.result != null && data.OrganizationId != 0) {
  1079. $(".hdn_organizationid").val(response.result.OrganizationId);
  1080. $("#hfInv_OrganizationName").val(data.OrganizationName);
  1081. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined) {
  1082. instance.GetCustomerTurnOver();
  1083. }
  1084. $.when(instance.loadAddressAutoCompletes(response.result.OrganizationId)).then(function () {
  1085. instance.BindAddressDetails(response.result.OrganizationId);
  1086. instance.GetAvailableWallets(0);
  1087. });
  1088. }
  1089. });
  1090. }
  1091. }
  1092. GetCustomerTurnOver() {
  1093. var instance = this;
  1094. $(".txt_tcsadjustment").val("0");
  1095. $("#chk_tcsapplied").unbind();
  1096. $(".number_tcsamount").prop("disabled", true);
  1097. $(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
  1098. $("#chk_tcsapplied").change(function () {
  1099. if ($(this).prop('checked') == true && instance.EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  1100. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  1101. $("#hdnchk_tcsapplied").val("false");
  1102. $('#chk_tcsapplied').prop('checked', false);
  1103. }
  1104. else {
  1105. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  1106. $("#txt_Adjustment").val(0);
  1107. $(".hdn_adjustment").val(0);
  1108. }
  1109. if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
  1110. bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
  1111. if (result) {
  1112. $("#div_tcstaxrate").removeClass("hidden");
  1113. $(".div_tcsadjustment").removeClass("hidden");
  1114. $("#div_tcsamount").removeClass("hidden");
  1115. instance.update_total();
  1116. instance.TotalAdjustment();
  1117. }
  1118. else {
  1119. $("#div_tcstaxrate").addClass("hidden");
  1120. $(".div_tcsadjustment").addClass("hidden");
  1121. $("#div_tcsamount").addClass("hidden");
  1122. $('#chk_tcsapplied').prop('checked', false);
  1123. $("#hdnchk_tcsapplied").val("false");
  1124. instance.update_total();
  1125. instance.TotalAdjustment();
  1126. }
  1127. });
  1128. }
  1129. else if ($(this).prop('checked') == true) {
  1130. $("#div_tcstaxrate").removeClass("hidden");
  1131. $(".div_tcsadjustment").removeClass("hidden");
  1132. $("#div_tcsamount").removeClass("hidden");
  1133. instance.update_total();
  1134. instance.TotalAdjustment();
  1135. }
  1136. else {
  1137. $("#div_tcstaxrate").addClass("hidden");
  1138. $(".div_tcsadjustment").addClass("hidden");
  1139. $("#div_tcsamount").addClass("hidden");
  1140. instance.update_total();
  1141. instance.TotalAdjustment();
  1142. }
  1143. }
  1144. });
  1145. $(".txt_tcsadjustment").unbind();
  1146. $(".txt_tcsadjustment").blur(function () {
  1147. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  1148. $("#txt_Adjustment").val(0);
  1149. $(".hdn_adjustment").val(0);
  1150. }
  1151. instance.update_total();
  1152. instance.TotalAdjustment();
  1153. });
  1154. $("#div_tcstaxrate").addClass("hidden");
  1155. $(".div_tcsadjustment").addClass("hidden");
  1156. $("#div_tcsamount").addClass("hidden");
  1157. $("#chk_tcsapplied").prop("checked", false);
  1158. $("#chk_tcsapplied").prop("disabled", false);
  1159. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCustomerTurnOver($(".hdn_organizationid").val(), $(".hdn_invoiceid").val(), Pos.Instance().formatDate($(".date_journaldate").val()), $(".hdn_invoicetypeid").val()).then(function (response) {
  1160. if (response.result != null) {
  1161. $(".number_tcstaxrate").val(response.result.TaxRate);
  1162. if (response.result.TCSTaxCodeId != 0) {
  1163. $(".hdn_tcstaxcodeid").val(response.result.TCSTaxCodeId);
  1164. $(".hdn_tcstaxcodeaccountid").val(response.result.TCSTaxCodeAccountId);
  1165. $(".number_tcstaxrate").prop("disabled", true);
  1166. }
  1167. instance.TurnOver = response.result.TurnOver;
  1168. instance.ContactTcsEnable = response.result.Enable;
  1169. instance.EnableTenantTcs = response.result.EnableTenantTcs;
  1170. instance.PanAvailable = response.result.PanAvailable;
  1171. instance.TaxRate = response.result.TaxRate;
  1172. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  1173. if (instance.ContactTcsEnable == true && instance.EnableTenantTcs == true) {
  1174. $("#chk_tcsapplied").prop("checked", true);
  1175. if ($(".hdn_invoicetypeid").val() == "1")
  1176. $("#chk_tcsapplied").prop("disabled", "disabled");
  1177. $("#hdnchk_tcsapplied").val("true");
  1178. $("#div_tcstaxrate").removeClass("hidden");
  1179. $(".div_tcsadjustment").removeClass("hidden");
  1180. $("#div_tcsamount").removeClass("hidden");
  1181. $(".number_tcsamount").prop("disabled", true);
  1182. }
  1183. else if (instance.TurnOver > 5000000 && $(".hdn_invoicetypeid").val() == "1") {
  1184. $("#chk_tcsapplied").prop("checked", true);
  1185. $("#chk_tcsapplied").prop("disabled", "disabled");
  1186. $("#hdnchk_tcsapplied").val("true");
  1187. $("#div_tcstaxrate").removeClass("hidden");
  1188. $(".div_tcsadjustment").removeClass("hidden");
  1189. $("#div_tcsamount").removeClass("hidden");
  1190. $(".number_tcsamount").prop("disabled", true);
  1191. }
  1192. }
  1193. else if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") {
  1194. $("#chk_tcsapplied").prop("checked", false);
  1195. $("#hdnchk_tcsapplied").val("false");
  1196. $("#div_tcstaxrate").addClass("hidden");
  1197. $(".div_tcsadjustment").addClass("hidden");
  1198. $("#div_tcsamount").addClass("hidden");
  1199. }
  1200. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_RefInvoiceId').val() == 0 && $("#hf_AppSettingName").val() == "Create Return") {
  1201. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(($(".hdn_invoicetypeid").val())).then(function (res) {
  1202. if (res.result != null && res.result != "") {
  1203. instance.TaxRate = res.result.TcsTaxRate;
  1204. $(".number_tcstaxrate").val(res.result.TcsTaxRate);
  1205. $(".hdn_tcstaxcodeid").val(response.result.TcsTaxCodeId);
  1206. if (res.result.TcsTaxCodeId != 0) {
  1207. $(".number_tcstaxrate").prop("disabled", true);
  1208. }
  1209. $(".number_tcsamount").prop("disabled", true);
  1210. }
  1211. });
  1212. }
  1213. }
  1214. });
  1215. }
  1216. loadAddressAutoCompletes(organizationid) {
  1217. var instance = this;
  1218. var ToAddressParameters = [{ "ColumnName": "contactid", "Value": organizationid, }];
  1219. let invoicetypeid = $(".hdn_invoicetypeid").val();
  1220. if (invoicetypeid == "1" || invoicetypeid == "4" || invoicetypeid == "6") {
  1221. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billtoaddressid"), ToAddressParameters);
  1222. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shiptoaddressid"), ToAddressParameters);
  1223. $(".txtAutoComplete_billtoaddressid").change(function () {
  1224. $.when(instance.loadLobAndSp()).then(function () {
  1225. instance.BindLoB();
  1226. });
  1227. });
  1228. }
  1229. else {
  1230. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billfromaddressid"), ToAddressParameters);
  1231. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shipfromaddressid"), ToAddressParameters);
  1232. $(".txtAutoComplete_billfromaddressid").change(function () {
  1233. $.when(instance.loadLobAndSp()).then(function () {
  1234. instance.BindLoB();
  1235. });
  1236. });
  1237. }
  1238. var FromAddressParameters = [{ "ColumnName": "companyid", "Value": Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid")) }];
  1239. if (invoicetypeid == "1" || invoicetypeid == "4" || invoicetypeid == "6") {
  1240. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billfromaddressid"), FromAddressParameters);
  1241. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shipfromaddressid"), FromAddressParameters);
  1242. }
  1243. else {
  1244. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billtoaddressid"), FromAddressParameters);
  1245. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shiptoaddressid"), FromAddressParameters);
  1246. }
  1247. }
  1248. BindAddressDetails(orgid) {
  1249. var instance = this;
  1250. let branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  1251. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getbranche(branchid).then(function (responce) {
  1252. if (responce.result != null) {
  1253. if (responce.result.DefaultWarehouseId != 0)
  1254. var ShipTo = new Option(responce.result.DefaultWarehouseName, responce.result.DefaultWarehouseId, true);
  1255. else
  1256. var ShipTo = new Option(responce.result.BranchName, responce.result.BranchId, true);
  1257. var BillTo = new Option(responce.result.BranchName, responce.result.BranchId, true);
  1258. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  1259. $(".txtAutoComplete_shiptoaddressid").append(ShipTo);
  1260. $(".txtAutoComplete_billtoaddressid").append(BillTo);
  1261. $(".txtAutoComplete_billtoaddressid").change(function () {
  1262. instance.bindSeries($(".txtAutoComplete_lobid").val(), $(".txtAutoComplete_billtoaddressid"));
  1263. instance.bindAdjustmentAccount($(".txtAutoComplete_lobid").val(), responce.result.BranchId);
  1264. });
  1265. }
  1266. else {
  1267. $(".txtAutoComplete_shipfromaddressid").append(ShipTo);
  1268. $(".txtAutoComplete_billfromaddressid").append(BillTo);
  1269. $(".txtAutoComplete_billfromaddressid").change(function () {
  1270. instance.bindSeries($(".txtAutoComplete_lobid").val(), $(".txtAutoComplete_billfromaddressid"));
  1271. instance.bindAdjustmentAccount($(".txtAutoComplete_lobid").val(), responce.result.BranchId);
  1272. });
  1273. }
  1274. }
  1275. });
  1276. this.fileCacheHelper.loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  1277. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressByContactId(orgid).then(function (response) {
  1278. if (response.result != null && response.result != "") {
  1279. var ShipTo = new Option(response.result.AddressName, response.result.ContactAddressId, true);
  1280. var BillTo = new Option(response.result.AddressName, response.result.ContactAddressId, true);
  1281. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4") {
  1282. $(".txtAutoComplete_shiptoaddressid").append(ShipTo);
  1283. $(".txtAutoComplete_billtoaddressid").append(BillTo);
  1284. $(".txtAutoComplete_billtoaddressid").change(function () {
  1285. $.when(instance.loadLobAndSp()).then(function () {
  1286. instance.BindLoB();
  1287. });
  1288. });
  1289. instance.getGSTNo();
  1290. }
  1291. else {
  1292. $(".txtAutoComplete_shipfromaddressid").append(ShipTo);
  1293. $(".txtAutoComplete_billfromaddressid").append(BillTo);
  1294. $(".txtAutoComplete_billfromaddressid").change(function () {
  1295. $.when(instance.loadLobAndSp()).then(function () {
  1296. instance.BindLoB();
  1297. });
  1298. });
  1299. instance.getGSTNo();
  1300. }
  1301. if (response.result.GSTNO != "" && response.result.GSTNO != null)
  1302. $(".txt_gstno").val(response.result.GSTNO);
  1303. $.when(instance.loadLobAndSp()).then(function () {
  1304. instance.BindLoB();
  1305. });
  1306. }
  1307. else {
  1308. MessageHelper.Instance().showError("Please assign billing address and shipping address", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  1309. }
  1310. });
  1311. });
  1312. }
  1313. GetAvailableWallets(invoiceid) {
  1314. var instance = this;
  1315. var ContactId = $(".hdn_organizationid").val();
  1316. var invoiceId = 0;
  1317. if (invoiceid != 0 && $('#hfInv_IsRetun').val() != "1") {
  1318. invoiceId = Number($(".hdn_invoiceid").val());
  1319. }
  1320. if (invoiceId != 0)
  1321. instance.GetJournalAlloc(invoiceId);
  1322. var invoicedate = $('.date_journaldate').val();
  1323. var invdate = instance.formatDate(invoicedate);
  1324. var lobid = $(".txtAutoComplete_lobid").val();
  1325. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getJournalWallets(invdate, invoiceId, ContactId, Number($(".hdn_invoicetypeid").val()), lobid).then(function (response) {
  1326. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/payments/wallet.component.js", function () {
  1327. if (response.result != null) {
  1328. Bizgaze.Apps.Transact.Controls.Wallet.Instance().loadInvoiceWallets(response.result);
  1329. }
  1330. });
  1331. });
  1332. }
  1333. update_total() {
  1334. var instance = this;
  1335. var totalAmount = 0;
  1336. var totalDiscountAmount = 0;
  1337. var totalNonDiscountedAmount = 0;
  1338. var totalTaxAmount = 0;
  1339. var totalTaxAdjustment = 0;
  1340. var totalAsseableAdjustment = 0;
  1341. var totalQty = 0;
  1342. var totalDiscountPercent = 0;
  1343. var totalDiscountValue = 0;
  1344. var totalAddlDiscountPercent = 0;
  1345. var totalAddlDiscountValue = 0;
  1346. var totalExpensePercent = 0;
  1347. var totalExpenseValue = 0;
  1348. var addexpenserow_total = 0;
  1349. $('.expense-row-total').each(function (i) {
  1350. var expense_row_total = Number($(this).html());
  1351. addexpenserow_total += expense_row_total;
  1352. });
  1353. var ConsumedWalletValue = 0;
  1354. var totalTaxPercent = 0;
  1355. var totalTaxValue = 0;
  1356. var totalCreditNote = 0;
  1357. var adddiscountrow_total = 0;
  1358. var netadddiscountrow_total = ConsumedWalletValue;
  1359. $('.discount-row-total').each(function (i) {
  1360. var discount_row_total = Number($(this).html());
  1361. adddiscountrow_total += discount_row_total;
  1362. });
  1363. $('.netdiscount-row-total').each(function (i) {
  1364. var discount_row_total = Number($(this).html());
  1365. netadddiscountrow_total += discount_row_total;
  1366. });
  1367. var itemdiscount_total = 0;
  1368. var totalLineAmount_total = 0;
  1369. $('.hfRowTotal').each(function (i) {
  1370. var element = $(this).parents(".item-row");
  1371. if (!element.hasClass('SplitItem')) {
  1372. var totalLineAmount = Number($(this).val());
  1373. if (!isNaN(totalLineAmount))
  1374. totalLineAmount_total += Number(totalLineAmount);
  1375. var discountPercent = 0;
  1376. var discountValue = 0;
  1377. var quantity = Number(element.find(".prodQuantity").val());
  1378. var unitPrice = Number(element.find(".prodPrice").val());
  1379. var exciseAmount = Number(element.find(".exciseAmount").val());
  1380. if (isNaN(exciseAmount))
  1381. exciseAmount = 0;
  1382. var nonexciseAmount = totalLineAmount - exciseAmount;
  1383. if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
  1384. discountValue = Number(element.find('.inv_txtaddldiscount').val());
  1385. }
  1386. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
  1387. discountPercent = Number(element.find('.inv_txtaddldiscount').val());
  1388. }
  1389. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Mul') {
  1390. if (element.find('#hfProdDiscountList').val() != '' || element.find('#hfProdDiscountApplyTypes').val() != '') {
  1391. var discountsArray = element.find('#hfProdDiscountList').val().toString().split(',');
  1392. var applyTypes = element.find('#hfProdDiscountApplyTypes').val().toString().split(',');
  1393. var price = Number(unitPrice) * Number(quantity);
  1394. var currentAmount = Number(unitPrice) * Number(quantity);
  1395. $.each(discountsArray, function (j) {
  1396. var percent = discountsArray[j];
  1397. var applyType = applyTypes[j];
  1398. var discount = 0;
  1399. if (applyType == 'NET' || applyType == '1') {
  1400. discount = Number(price) * Number(percent) / 100;
  1401. currentAmount -= Number(discount);
  1402. }
  1403. else {
  1404. discount = Number(currentAmount) * Number(percent) / 100;
  1405. currentAmount -= Number(discount);
  1406. }
  1407. discountValue += Number(discount);
  1408. });
  1409. element.find('.inv_txtaddldiscount').val(discountValue);
  1410. }
  1411. else {
  1412. discountValue = Number(element.find('.inv_txtaddldiscount').val());
  1413. }
  1414. }
  1415. if (!isNaN(discountPercent))
  1416. totalDiscountPercent += Number(discountPercent);
  1417. if (!isNaN(discountValue))
  1418. totalAddlDiscountValue += Number(discountValue);
  1419. var discountAmount = 0;
  1420. discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
  1421. + (Number(quantity) * Number(discountValue));
  1422. discountAmount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discountAmount, 2));
  1423. itemdiscount_total += discountAmount;
  1424. var discountedAmount = Number(totalLineAmount) - Number(discountAmount);
  1425. totalDiscountAmount += Number(discountAmount);
  1426. element.find(".hfDiscountedAmount").val(discountAmount);
  1427. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  1428. element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2));
  1429. }
  1430. else
  1431. element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
  1432. }
  1433. });
  1434. }
  1435. TotalAdjustment() {
  1436. if ($('#chk_AutoAdjustment').is(':checked')) {
  1437. var total = $('.nettotal').text();
  1438. var splitTotal = total.split('.');
  1439. var AdjustmentValue = 0;
  1440. var splitedAdjestment = 0;
  1441. $("#txt_Adjustment").val(0);
  1442. $(".hdn_adjustment").val(0);
  1443. if (!isNaN(Number($('#txt_Adjustment').val()))) {
  1444. AdjustmentValue = Number($('#txt_Adjustment').val());
  1445. }
  1446. if (Number(splitTotal[1]) > 0) {
  1447. if (Number(splitTotal[1]) >= 50) {
  1448. splitedAdjestment = (100 - Number(splitTotal[1])) / 100;
  1449. AdjustmentValue += splitedAdjestment;
  1450. $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
  1451. $(".hdn_adjustment").val($('#txt_Adjustment').val());
  1452. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
  1453. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
  1454. }
  1455. else {
  1456. splitedAdjestment = Number(splitTotal[1]) / 100;
  1457. AdjustmentValue -= splitedAdjestment;
  1458. $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2));
  1459. $(".hdn_adjustment").val($('#txt_Adjustment').val());
  1460. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
  1461. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
  1462. }
  1463. }
  1464. }
  1465. else {
  1466. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($('#txt_Adjustment').val()), 2));
  1467. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number($('.nettotal').text()) + Number($('#txt_Adjustment').val())), 2));
  1468. }
  1469. }
  1470. loadLobAndSp() {
  1471. var AddressId = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1472. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4")
  1473. AddressId = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1474. var lobParameters = [{ "ColumnName": "contactaddressid", "Value": AddressId, }];
  1475. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_lobid"), lobParameters);
  1476. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
  1477. var SpParameters = [{ "ColumnName": "contactaddressid", "Value": AddressId, }];
  1478. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_salespersonid"), null);
  1479. });
  1480. }
  1481. BindLoB() {
  1482. var instance = this;
  1483. $(".txtAutoComplete_lobid").empty();
  1484. $('#hf_AdjustmentAccountId').val("0");
  1485. $('#txt_AdjustmentAccountName').empty();
  1486. if ($(".hdn_invoiceid").val() == "0") {
  1487. $(".InvoiceItems").find(".item-addedrow").remove();
  1488. instance.SplitedInvoiceItemList = new Array();
  1489. instance.itemIds = [0];
  1490. instance.itemIds = [0];
  1491. $("#txt_Adjustment").val("0");
  1492. $("#span_Adjustment").text("0");
  1493. instance.update_total();
  1494. instance.TotalAdjustment();
  1495. }
  1496. var AddressId = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1497. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  1498. AddressId = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1499. this.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
  1500. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobsByAddressId(Number(AddressId)).then(function (response) {
  1501. let items = Bizgaze.Apps.Transact.Controls.Pos.Instance();
  1502. if (response.result != "" && response.result != null) {
  1503. if (response.result.length == 1) {
  1504. var LoB = new Option(response.result[0].LobName, response.result[0].LobId, true);
  1505. $(".txtAutoComplete_lobid").append(LoB);
  1506. $(".txtAutoComplete_lobid").val(response.result[0].LobId);
  1507. !items.productContainerElement && items.setProductDetails("", items.containerId);
  1508. instance.BindSalesPerson(AddressId);
  1509. instance.bindDefaultPaymentTerm($(".hdn_organizationid").val(), response.result[0].LobId);
  1510. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1511. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  1512. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1513. instance.bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  1514. instance.bindAdjustmentAccount(response.result[0].LobId, Addr);
  1515. }
  1516. }
  1517. else {
  1518. $(".section_CartItems").remove();
  1519. items.renderSampleTemplate();
  1520. items.productContainerElement = null;
  1521. items.productInfoElement = null;
  1522. items.allEventsExecuted = false;
  1523. }
  1524. });
  1525. });
  1526. $(".txtAutoComplete_lobid").change(function () {
  1527. instance.bindDefaultPaymentTerm($(".hdn_organizationid").val(), $(".txtAutoComplete_lobid option:selected").val());
  1528. var Address = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1529. var Billto = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1530. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6") {
  1531. Address = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1532. Billto = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1533. }
  1534. instance.BindSalesPerson(Billto);
  1535. instance.bindSeries($(".txtAutoComplete_lobid option:selected").val(), Address);
  1536. instance.bindAdjustmentAccount($(".txtAutoComplete_lobid option:selected").val(), Address);
  1537. $(".InvoiceItems").find(".item-addedrow").remove();
  1538. instance.SplitedInvoiceItemList = new Array();
  1539. instance.itemIds = [0];
  1540. instance.dcItemIds = [0];
  1541. $("#txt_Adjustment").val("0");
  1542. instance.update_total();
  1543. instance.TotalAdjustment();
  1544. });
  1545. }
  1546. bindSeries(lobid, branchid) {
  1547. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getSeries($("#hf_FormInstalledAppId").val(), lobid, branchid).then(function (response) {
  1548. if (response.result != null) {
  1549. if (response.result.length > 0) {
  1550. $(".txtSeriesAutoComplete_seriesid").empty();
  1551. $(".txtSeriesAutoComplete_seriesid").append(new Option(response.result[0].SeriesName, response.result[0].SeriesId.toString(), true));
  1552. $(".txtSeriesAutoComplete_seriesid").val(response.result[0].SeriesId);
  1553. }
  1554. else {
  1555. Unibase.Platform.Series.Managers.SeriesManager.Instance().getActiveSeries(0, Number($("#hf_FormInstalledAppId").val())).then(function (response) {
  1556. var data = response.result;
  1557. if (data != null) {
  1558. if (data.length != 0) {
  1559. $(".txtSeriesAutoComplete_seriesid").empty();
  1560. for (var s = 0; s < data.length; s++) {
  1561. var Series = new Option(data[s].SeriesName, data[s].SeriesId.toString(), true);
  1562. $(".txtSeriesAutoComplete_seriesid").append(Series);
  1563. $(".txtSeriesAutoComplete_seriesid").val(data[s].SeriesId);
  1564. }
  1565. $(".txtSeriesAutoComplete_seriesid").val(data[0].SeriesId);
  1566. }
  1567. }
  1568. });
  1569. }
  1570. }
  1571. else {
  1572. Unibase.Platform.Series.Managers.SeriesManager.Instance().getActiveSeries(0, Number($("#hf_FormInstalledAppId").val())).then(function (response) {
  1573. var data = response.result;
  1574. if (data != null) {
  1575. if (data.length != 0) {
  1576. $(".txtSeriesAutoComplete_seriesid").empty();
  1577. for (var s = 0; s < data.length; s++) {
  1578. var Series = new Option(data[s].SeriesName, data[s].SeriesId.toString(), true);
  1579. $(".txtSeriesAutoComplete_seriesid").append(Series);
  1580. $(".txtSeriesAutoComplete_seriesid").val(data[s].SeriesId);
  1581. }
  1582. $(".txtSeriesAutoComplete_seriesid").val(data[0].SeriesId);
  1583. }
  1584. }
  1585. });
  1586. }
  1587. });
  1588. }
  1589. bindAdjustmentAccount(lobid, branchid) {
  1590. $('#hf_AdjustmentAccountId').val("0");
  1591. $('#txt_AdjustmentAccountName').empty();
  1592. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", function () {
  1593. Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLobLedgerSetting(lobid, branchid).then(function (response) {
  1594. if (response.result != null && response.result != "") {
  1595. $("#txt_AdjustmentAccountName").append(new Option(response.result.LedgerName, response.result.SettingValue1, true));
  1596. $("#hf_AdjustmentAccountId").val(response.result.SettingValue1);
  1597. $("#txt_AdjustmentAccountName").val(response.result.SettingValue1);
  1598. }
  1599. });
  1600. });
  1601. }
  1602. getGSTNo() {
  1603. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  1604. var gstno = "";
  1605. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0 && Number($(".hdn_invoiceid").val()) != 0) {
  1606. gstno = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_gstno").Value;
  1607. }
  1608. if (gstno != null && gstno != "") {
  1609. $(".txt_gstno").val(gstno);
  1610. }
  1611. else
  1612. $(".txt_gstno").val("GSTIN not Assigned");
  1613. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4") {
  1614. $(".txtAutoComplete_billtoaddressid").change(function () {
  1615. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(Number($(".txtAutoComplete_billtoaddressid").val())).then(function (ress) {
  1616. if (ress.result != null) {
  1617. if (ress.result.GSTNO != "" && ress.result.GSTNO != null)
  1618. $(".txt_gstno").val(ress.result.GSTNO);
  1619. }
  1620. });
  1621. });
  1622. }
  1623. else {
  1624. $(".txtAutoComplete_billfromaddressid").change(function () {
  1625. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(Number($(".txtAutoComplete_billfromaddressid").val())).then(function (ress) {
  1626. if (ress.result != null) {
  1627. if (ress.result.GSTNO != "" && ress.result.GSTNO != null)
  1628. $(".txt_gstno").val(ress.result.GSTNO);
  1629. }
  1630. });
  1631. });
  1632. }
  1633. }
  1634. GetJournalAlloc(invoiceId) {
  1635. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getJournalAllocs(invoiceId).then(function (response) {
  1636. if (response.result.length > 0)
  1637. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1638. });
  1639. }
  1640. formatDate(date) {
  1641. var datearray = date.split("/");
  1642. var newdate = datearray[1] + '/' + datearray[0] + '/' + datearray[2];
  1643. var d = new Date(newdate), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
  1644. if (month.length < 2)
  1645. month = '0' + month;
  1646. if (month.length < 2)
  1647. month = '0' + month;
  1648. if (day.length < 2)
  1649. day = '0' + day;
  1650. return [year, month, day].join('-');
  1651. }
  1652. BindSalesPerson(AddressId) {
  1653. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  1654. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getManagerDetails(Number($(".txtAutoComplete_lobid option:selected").val()), AddressId).then(function (response) {
  1655. if (response.result != null) {
  1656. var SalesPerson = new Option(response.result.ManagerName, response.result.EmployeeId, true);
  1657. $(".txtAutoComplete_salespersonid").empty();
  1658. $(".txtAutoComplete_salespersonid").append(SalesPerson);
  1659. $(".txtAutoComplete_salespersonid").val(response.result.EmployeeId);
  1660. }
  1661. });
  1662. });
  1663. }
  1664. bindDefaultPaymentTerm(organizationid, lobid) {
  1665. $('.hfAutoCompleteId_paymenttermid').val(0);
  1666. $('.txtAutoComplete_paymenttermid').empty();
  1667. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/paymentterms/paymenttermmanager.js", function () {
  1668. Bizgaze.Apps.Transact.Managers.PaymentTermManager.Instance().getPaymentTermByOrg(organizationid, lobid).then(function (response) {
  1669. var paymentterm = response.result;
  1670. if (paymentterm != null && paymentterm != "") {
  1671. $('.hfAutoCompleteId_paymenttermid').val(paymentterm.PaymentTermId);
  1672. $('.txtAutoComplete_paymenttermid').append(new Option(paymentterm.PaymentTermName, paymentterm.PaymentTermId, true));
  1673. if (paymentterm.DueDays != null && paymentterm.DueDays > 0) {
  1674. var from = $('.date_journaldate').val().toString().split("/");
  1675. var f = new Date(Number(from[2]), Number(from[1]) - 1, Number(from[0]));
  1676. var currentdate = f.setDate(f.getDate() + paymentterm.DueDays);
  1677. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(currentdate, ""));
  1678. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), "");
  1679. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  1680. $('.hfdate_duedate').val(tdate);
  1681. }
  1682. }
  1683. });
  1684. });
  1685. }
  1686. loadControlSettings(controlsettingjson, formpropertyid) {
  1687. }
  1688. loadPropertySettings(propertysettings, formpropertyid) {
  1689. }
  1690. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  1691. this.bindEditInvoiceDetails(propval);
  1692. }
  1693. bindEditInvoiceDetails(invoiceid) {
  1694. var instance = this;
  1695. $(".btn_Save_Form").removeClass("hidden");
  1696. if ($('.hdn_invoicetypeid').val() == "1" && $("#hf_AppSettingName").val() == "Create Return") {
  1697. $('#hfInv_IsRetun').val(1);
  1698. $('.hdn_invoicetypeid').val("3");
  1699. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  1700. $("#div_FormName").text("Create Sales Return");
  1701. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1702. $(".hdn_journalno").val(0);
  1703. }
  1704. else if ($('.hdn_invoicetypeid').val() == "2" && $("#hf_AppSettingName").val() == "Create Return") {
  1705. $('#hfInv_IsRetun').val(1);
  1706. $('.hdn_invoicetypeid').val("4");
  1707. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  1708. $("#div_FormName").text("Create Purchase Return");
  1709. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1710. $(".hdn_journalno").val(0);
  1711. }
  1712. let invoicetypeid = $('.hdn_invoicetypeid').val();
  1713. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  1714. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(invoiceid).then(function (result) {
  1715. var data = result.result;
  1716. var companyId = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid"));
  1717. var Parameters = [{ "ColumnName": "companyid", "Value": companyId }];
  1718. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_orgcontactid"), Parameters);
  1719. if (data.OrgContactId == 0) {
  1720. instance.IswalkinCustomer = true;
  1721. $(".hfAutoCompleteId_orgcontactid").val(data.OrganizationId);
  1722. var selectedCompany = new Option(data.OrganizationName, data.OrganizationId, true);
  1723. }
  1724. else {
  1725. instance.IswalkinCustomer = false;
  1726. $(".hfAutoCompleteId_orgcontactid").val(data.OrgContactId);
  1727. var selectedCompany = new Option(data.OrganizationName + " - " + data.OrgContactName, data.OrgContactId, true);
  1728. }
  1729. $(".txtAutoComplete_orgcontactid").empty();
  1730. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  1731. if ($(".section_Details").hasClass('hidden')) {
  1732. $(".section_Details").removeClass('hidden');
  1733. }
  1734. if ($(".section_ItemDetails").hasClass('hidden')) {
  1735. $(".section_ItemDetails").removeClass('hidden');
  1736. }
  1737. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  1738. $(".section_InvoiceAmount").removeClass('hidden');
  1739. }
  1740. if ($(".section_Description").hasClass('hidden')) {
  1741. $(".section_Description").removeClass('hidden');
  1742. }
  1743. if ($(".section_BillingAndShippingDetails").hasClass('hidden')) {
  1744. $(".section_BillingAndShippingDetails").removeClass('hidden');
  1745. }
  1746. if ($(".section_Wallets").hasClass('hidden')) {
  1747. $(".section_Wallets").removeClass("hidden");
  1748. }
  1749. if ($(".section_TCS").hasClass('hidden')) {
  1750. $(".section_TCS").removeClass("hidden");
  1751. }
  1752. $("#btn_Save").removeClass('hidden');
  1753. $(".txtAutoComplete_lobid").prop("disabled", true);
  1754. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1755. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.InvoiceDate, ""));
  1756. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.InvoiceDate), "");
  1757. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  1758. $('.hfdate_journaldate').val(tdate);
  1759. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.DueDate, ""));
  1760. var date1 = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.DueDate), "");
  1761. tdate = moment(date1, "DD/MM/YYYY").format("YYYY/MM/DD");
  1762. $('.hfdate_duedate').val(tdate);
  1763. $('.date_refdate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.RefDate, ""));
  1764. date1 = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.RefDate), "");
  1765. tdate = moment(date1, "DD/MM/YYYY").format("YYYY/MM/DD");
  1766. $('.hfdate_refdate').val(tdate);
  1767. $.when(instance.loadAddressAutoCompletes(data.OrganizationId)).then(function (response) {
  1768. $(".txtAutoComplete_billfromaddressid").empty();
  1769. $(".txtAutoComplete_billtoaddressid").empty();
  1770. $(".txtAutoComplete_shiptoaddressid").empty();
  1771. $(".txtAutoComplete_shipfromaddressid").empty();
  1772. if ($('.hdn_invoicetypeid').val() == "1" || $('.hdn_invoicetypeid').val() == "4" || $('.hdn_invoicetypeid').val() == "6") {
  1773. $(".hfAutoCompleteId_billfromaddressid").val(data.BillFromAddressId);
  1774. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  1775. $(".hfAutoCompleteId_billtoaddressid").val(data.BillToAddressId);
  1776. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  1777. $(".hfAutoCompleteId_shiptoaddressid").val(data.ShipToAddressId);
  1778. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  1779. $(".hfAutoCompleteId_shipfromaddressid").val(data.ShipFromAddressId);
  1780. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  1781. }
  1782. else {
  1783. $(".hfAutoCompleteId_billfromaddressid").val(data.BillToAddressId);
  1784. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  1785. $(".hfAutoCompleteId_billtoaddressid").val(data.BillFromAddressId);
  1786. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  1787. $(".hfAutoCompleteId_shiptoaddressid").val(data.ShipFromAddressId);
  1788. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  1789. $(".hfAutoCompleteId_shipfromaddressid").val(data.ShipToAddressId);
  1790. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipToAddressName, data.ShipFromAddressId, true));
  1791. }
  1792. instance.loadLobAndSp();
  1793. instance.getGSTNo();
  1794. $('.txtAutoComplete_lobid').empty();
  1795. $(".txtAutoComplete_lobid").append(new Option(data.LobName, data.LobId, true));
  1796. $(".hfAutoCompleteId_lobid").val(data.LobId);
  1797. $('.txtAutoComplete_salespersonid').empty();
  1798. $('.txtAutoComplete_salespersonid').append(new Option(data.SalesPersonName, data.SalesPersonId, true));
  1799. $('.hfAutoCompleteId_salespersonid').val(data.SalesPersonId);
  1800. $('hdn_OrganizationId').val(data.OrganizationId);
  1801. $("#hfInv_OrganizationName").val(data.OrganizationName);
  1802. $('.txtAutoComplete_paymenttermid').empty();
  1803. $('.hfAutoCompleteId_paymenttermid').val(data.PaymentTermId);
  1804. $('.txtAutoComplete_paymenttermid').append(new Option(data.PaymentTermName, data.PaymentTermId, true));
  1805. if (data.SeriesId != 0 && $('#hfInv_IsRetun').val() != "1") {
  1806. $(".txtSeriesAutoComplete_seriesid").empty();
  1807. $(".hfSeriesAutoCompleteId_seriesid").val(0);
  1808. $(".txtSeriesAutoComplete_seriesid").append(new Option(data.SeriesName, data.SeriesId, true));
  1809. $(".hfSeriesAutoCompleteId_seriesid").val(data.SeriesId);
  1810. }
  1811. else {
  1812. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  1813. if (data.SeriesId == 0 && data.InvoiceNo != null && data.InvoiceNo != "") {
  1814. $(".isManualSeries_seriesid").prop("checked", true);
  1815. $(".TextManualSeries").val(data.InvoiceNo);
  1816. }
  1817. else {
  1818. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1819. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  1820. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1821. instance.bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  1822. }
  1823. }
  1824. if (($('#hfInv_IsRetun').val() != "1") && ($('.hdn_invoicetypeid').val() == "4" || $('.hdn_invoicetypeid').val() == "7" || $('.hdn_invoicetypeid').val() == "6" || $('.hdn_invoicetypeid').val() == "3")) {
  1825. $(".txtSeriesAutoComplete_seriesid").prop("disabled", true);
  1826. }
  1827. if (data.RefNo != "" && data.RefNo != null)
  1828. $(".txt_refno").val(data.RefNo);
  1829. if (data.AdjustmentAccountId != 0) {
  1830. $("#txt_AdjustmentAccountName").append(new Option(data.AdjustmentAccountName, data.AdjustmentAccountId, true));
  1831. $("#txt_AdjustmentAccountName").val(data.AdjustmentAccountId);
  1832. $("#hf_AdjustmentAccountId").val(data.AdjustmentAccountId);
  1833. }
  1834. if (data.AutoAdjustment == true) {
  1835. $('#chk_AutoAdjustment').prop('checked', true);
  1836. $('#txt_Adjustment').prop("disabled", true);
  1837. $(".span_AdjustmentAccountName").removeClass('hidden');
  1838. $("#txt_AdjustmentAccountName").addClass('required');
  1839. }
  1840. else {
  1841. $('#chk_AutoAdjustment').prop('checked', false);
  1842. $('#txt_Adjustment').prop("disabled", false);
  1843. $("#txt_AdjustmentAccountName").removeClass('required');
  1844. $(".span_AdjustmentAccountName").addClass('hidden');
  1845. }
  1846. $('#txt_Adjustment').val(data.Adjustment);
  1847. if (data.Adjustment != 0) {
  1848. $('.span_AdjustmentAccountName').removeClass('hidden');
  1849. $("#txt_AdjustmentAccountName").addClass('required');
  1850. }
  1851. else {
  1852. $('.span_AdjustmentAccountName').addClass('hidden');
  1853. $("#txt_AdjustmentAccountName").removeClass('required');
  1854. }
  1855. if (data.InvoiceStatusId == 6) {
  1856. $('#btnInvoiceItem').hide();
  1857. }
  1858. var Iswalkincustomer = false;
  1859. var contactid = data.OrgContactId;
  1860. if (data.OrgContactId == 0) {
  1861. Iswalkincustomer = true;
  1862. contactid = data.OrganizationId;
  1863. }
  1864. $(".chk_excludefromcampaign").prop("checked", data.ExcludeFromCampaign);
  1865. $("#hfId_istaxinclusive").val(data.IsTaxInclusive);
  1866. $(".dropdown_istaxinclusive").val(data.IsTaxInclusive.toString());
  1867. $(".dropdown_paymentmethodid").val(data.PaymentMethodId);
  1868. instance.GetAvailableWallets(data.InvoiceId);
  1869. instance.loadOrderPendingItems();
  1870. });
  1871. $(".txtAutoComplete_orgcontactid").change(function () {
  1872. instance.LoadContactDetails();
  1873. });
  1874. if (data.GSTNO != "" && data.GSTNO != null)
  1875. $(".txt_gstno").val(data.GSTNO);
  1876. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCustomerTurnOver($(".hdn_organizationid").val(), $(".hdn_invoiceid").val(), instance.formatDate($(".date_journaldate").val()), $(".hdn_invoicetypeid").val()).then(function (res) {
  1877. if (res.result != null) {
  1878. instance.TurnOver = res.result.TurnOver;
  1879. instance.ContactTcsEnable = res.result.Enable;
  1880. instance.EnableTenantTcs = res.result.EnableTenantTcs;
  1881. instance.PanAvailable = res.result.PanAvailable;
  1882. instance.TaxRate = data.TcsTaxRate;
  1883. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  1884. if (instance.ContactTcsEnable == true && instance.EnableTenantTcs == true) {
  1885. $("#chk_tcsapplied").prop("checked", true);
  1886. if ($(".hdn_invoicetypeid").val() == "1")
  1887. $("#chk_tcsapplied").prop("disabled", "disabled");
  1888. $("#hdnchk_tcsapplied").val("true");
  1889. $("#div_tcstaxrate").removeClass("hidden");
  1890. $(".div_tcsadjustment").removeClass("hidden");
  1891. $("#div_tcsamount").removeClass("hidden");
  1892. $(".number_tcsamount").prop("disabled", true);
  1893. }
  1894. }
  1895. }
  1896. });
  1897. $("chk_tcsapplies").prop("checked", data.TcsApplied);
  1898. $(".hdn_tcstaxcodeid").val(data.TcsTaxCodeId);
  1899. $(".hdn_tcstaxcodeaccountid").val(data.TcsTaxCodeAccountId);
  1900. $(".number_tcstaxrate").val(data.TcsTaxRate);
  1901. $(".number_tcstaxrate").prop("disabled", true);
  1902. $(".txt_tcsadjustment").val(data.TcsAdjustment);
  1903. $(".number_tcsamount").val(data.TcsAmount);
  1904. $(".number_tcsamount").prop("disabled", true);
  1905. instance.ContactTcsEnable = data.TcsApplied;
  1906. instance.TaxRate = data.TcsTaxRate;
  1907. if (data.TcsApplied == true) {
  1908. $("#div_tcstaxrate").removeClass("hidden");
  1909. $(".div_tcsadjustment").removeClass("hidden");
  1910. $("#div_tcsamount").removeClass("hidden");
  1911. }
  1912. else {
  1913. $("#div_tcstaxrate").addClass("hidden");
  1914. $(".div_tcsadjustment").addClass("hidden");
  1915. $("#div_tcsamount").addClass("hidden");
  1916. }
  1917. $("#chk_tcsapplied").unbind();
  1918. $("#chk_tcsapplied").change(function () {
  1919. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  1920. $("#txt_Adjustment").val(0);
  1921. $(".hdn_adjustment").val(0);
  1922. }
  1923. $(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
  1924. if ($(this).prop('checked') == true && instance.EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  1925. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  1926. $("#hdnchk_tcsapplied").val("false");
  1927. $('#chk_tcsapplied').prop('checked', false);
  1928. }
  1929. else {
  1930. if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
  1931. bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
  1932. if (result) {
  1933. $("#div_tcstaxrate").removeClass("hidden");
  1934. $(".div_tcsadjustment").removeClass("hidden");
  1935. $("#div_tcsamount").removeClass("hidden");
  1936. instance.update_total();
  1937. instance.TotalAdjustment();
  1938. }
  1939. else {
  1940. $("#div_tcstaxrate").addClass("hidden");
  1941. $(".div_tcsadjustment").addClass("hidden");
  1942. $("#div_tcsamount").addClass("hidden");
  1943. $('#chk_tcsapplied').prop('checked', false);
  1944. instance.update_total();
  1945. instance.TotalAdjustment();
  1946. }
  1947. });
  1948. }
  1949. else if ($(this).prop('checked') == true) {
  1950. $("#div_tcstaxrate").removeClass("hidden");
  1951. $(".div_tcsadjustment").removeClass("hidden");
  1952. $("#div_tcsamount").removeClass("hidden");
  1953. instance.update_total();
  1954. instance.TotalAdjustment();
  1955. }
  1956. else if ($(this).prop('checked') == false) {
  1957. $("#div_tcstaxrate").addClass("hidden");
  1958. $(".div_tcsadjustment").addClass("hidden");
  1959. $("#div_tcsamount").addClass("hidden");
  1960. $(".number_tcstaxrate").val(data.TcsTaxRate);
  1961. $(".number_tcstaxrate").prop("disabled", true);
  1962. $(".txt_tcsadjustment").val(data.TcsAdjustment);
  1963. $(".number_tcsamount").val(data.TcsAmount);
  1964. $(".number_tcsamount").prop("disabled", true);
  1965. instance.update_total();
  1966. instance.TotalAdjustment();
  1967. }
  1968. }
  1969. });
  1970. $(".txt_tcsadjustment").unbind();
  1971. $(".txt_tcsadjustment").blur(function () {
  1972. instance.update_total();
  1973. instance.TotalAdjustment();
  1974. });
  1975. });
  1976. });
  1977. }
  1978. SaveAsDraft() {
  1979. let InstalledAppId = Unibase.Platform.Forms.Components.FormViewer.instance.InstalledAppId;
  1980. let RefStatusId = Bizgaze.Apps.Transact.Enums.InvoiceStatus.Draft;
  1981. Unibase.Platform.Apps.Managers.StageManager.Instance().getStagesByInstalledAppandRefStatus(InstalledAppId, RefStatusId).then(function (response) {
  1982. $(".hdn_stageid").val(response.result.StageId);
  1983. $("#btnDynamicSave").click();
  1984. });
  1985. }
  1986. loadOrderPendingItems() {
  1987. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  1988. var instance = this;
  1989. let invoiceid = $(".hdn_invoiceid").val();
  1990. var orderid = $(".hdn_orderid").val();
  1991. var Dcid = $(".hdn_dcid").val();
  1992. var fromOrder = false;
  1993. var items = [];
  1994. var Invoiceitem = [];
  1995. $(".item-addedrow").remove();
  1996. var url = "";
  1997. if (Dcid != 0 && Dcid != undefined && orderid == 0) {
  1998. fromOrder = false;
  1999. url = "apis/v4/bizgaze/transact/Dc/getpendingdcitemsforinvoice/dcid/" + Dcid;
  2000. }
  2001. if (Dcid == 0 || Dcid == undefined || instance.OrderSettingId == 2) {
  2002. if (orderid != "0" && orderid != undefined) {
  2003. fromOrder = true;
  2004. url = "apis/v4/bizgaze/transact/Orders/getpendingitemsforinvoice/orderid/" + orderid + "/ismergeorder/false";
  2005. }
  2006. }
  2007. else if (Dcid != 0 && Dcid != undefined) {
  2008. fromOrder = false;
  2009. url = "apis/v4/bizgaze/transact/Dc/getpendingdcitemsforinvoice/dcid/" + Dcid;
  2010. }
  2011. if (invoiceid != 0 && invoiceid != undefined && invoiceid != "null") {
  2012. fromOrder = false;
  2013. if ($('#hfInv_IsRetun').val() == "1") {
  2014. if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")
  2015. url = "apis/v4/bizgaze/transact/invoices/getinvoiceitemsbyinvoiceid/invoiceid/" + invoiceid + "/isreturn/true/itemid/0";
  2016. }
  2017. else
  2018. url = "apis/v4/bizgaze/transact/invoices/getinvoiceitemsbyinvoiceid/invoiceid/" + invoiceid + "/isreturn/false/itemid/0";
  2019. }
  2020. if (url != "") {
  2021. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceItems(url).then(function (response) {
  2022. var oldTaxId = 0;
  2023. var totalQty = 0;
  2024. for (var i = 0; i < response.result.length; i++) {
  2025. var item = response.result[i];
  2026. var invoiceItemId = 0;
  2027. totalQty += item.Quantity;
  2028. if (invoiceid != "0" && invoiceid != undefined && invoiceid != "null")
  2029. invoiceItemId = item.InvoiceItemId;
  2030. var refInvoiceItemId = 0;
  2031. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $("#hf_AppSettingName").val() == "Create Return")
  2032. refInvoiceItemId = item.InvoiceItemId;
  2033. if (i == 0)
  2034. oldTaxId = item.TaxGroupId;
  2035. if (oldTaxId != item.TaxGroupId && i != 0)
  2036. $('#addDiscount').addClass('hidden');
  2037. var maxQty = 0;
  2038. if (item.OrderItemPendingQty > 0)
  2039. maxQty = item.OrderItemPendingQty;
  2040. var pendingQuantity = item.OrderItemPendingQty > 0 ? item.OrderItemPendingQty : 0;
  2041. if (invoiceItemId != 0)
  2042. maxQty = item.Quantity + pendingQuantity;
  2043. if (item.DcItemId == undefined)
  2044. item.DcItemId = 0;
  2045. if (item.TaxAdjustment == undefined)
  2046. item.TaxAdjustment = 0;
  2047. if (item.AssesableAdjustment == undefined)
  2048. item.AssesableAdjustment = 0;
  2049. if (item.IsFoc == undefined)
  2050. item.IsFoc = false;
  2051. if (item.OfferItemId == undefined)
  2052. item.OfferItemId = 0;
  2053. if (item.DiscountPercent == undefined)
  2054. item.DiscountPercent = 0;
  2055. if (item.DiscountValue == undefined)
  2056. item.DiscountValue = 0;
  2057. var itemRow = {
  2058. orderItemId: item.OrderItemId,
  2059. invoiceItemId: invoiceItemId,
  2060. itemName: item.ItemName,
  2061. itemId: item.ItemId,
  2062. itemSKU: item.ItemSKU,
  2063. unitName: item.UnitName,
  2064. packSize: item.PackSize,
  2065. packCount: item.PackCount,
  2066. packs: item.Packs,
  2067. quantity: item.Quantity,
  2068. availPacks: item.AvailablePacks,
  2069. availQty: item.AvailableQty,
  2070. listPrice: 0,
  2071. description: item.Description,
  2072. taxGroupName: item.TaxGroupName,
  2073. taxGroupId: item.TaxGroupId,
  2074. isTaxInclusive: $("#hfId_istaxinclusive").val(),
  2075. addlDiscountPercent: item.DiscountPercent,
  2076. addlDiscountValue: item.DiscountAmount,
  2077. creditNote: 0,
  2078. priceListId: 0,
  2079. batchId: 0,
  2080. unitPrice: item.UnitPrice,
  2081. invoiceallocations: null,
  2082. exciseInvoiceItem: null,
  2083. accountId: item.LedgerId,
  2084. accountName: item.LedgerName,
  2085. walletId: 0,
  2086. Adjustment: 0,
  2087. IsFoc: item.IsFoc,
  2088. TariffNo: "",
  2089. exciseAmount: item.ExciseAmount,
  2090. discountName: "",
  2091. discountId: 0,
  2092. refNo: item.RefNo,
  2093. DiscountGroupId: item.DiscountGroupId,
  2094. DiscountGroupName: item.DiscountGroupName,
  2095. ExchangeItem: item.ExchangeDC,
  2096. maxQty: maxQty,
  2097. RefInvoiceItemId: refInvoiceItemId,
  2098. MrpId: item.MrpId,
  2099. taxAdjustment: item.TaxAdjustment,
  2100. assesableAdjustment: item.AssesableAdjustment,
  2101. inventoryTypeId: item.InventoryTypeId,
  2102. IsBoMItem: item.IsBoMItem,
  2103. dcItemId: item.DcItemId,
  2104. TotalRowAmount: 0,
  2105. TotalDiscount: 0,
  2106. BatchId: item.BatchId,
  2107. OfferItemId: item.OfferItemId,
  2108. AlternateUnitId: item.AlternateUnitId,
  2109. DefaultSize: item.DefaultSize,
  2110. ParentBOMItemId: item.ParentBOMItemId,
  2111. TaxAmount: item.TaxAmount,
  2112. DiscountAmount: item.DiscountAmount,
  2113. };
  2114. var EnableMrp = item.EnableMRP;
  2115. var EnableBatch = item.EnableBatch;
  2116. if (item.IsFoc == true)
  2117. Invoiceitem.push(itemRow);
  2118. else if (item.DcItemId != 0 && EnableMrp != true && EnableBatch != true)
  2119. Invoiceitem.push(itemRow);
  2120. else if (item.InvoiceItemId == 0) {
  2121. if (instance.orderid != 0 && Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_ordertypeid").Value) == 2 && EnableMrp != true && EnableBatch != true)
  2122. Invoiceitem.push(itemRow);
  2123. }
  2124. else if (item.InvoiceItemId == 0) {
  2125. if (instance.orderid != 0 && Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_ordertypeid").Value) == 1 && ((EnableMrp != true && EnableBatch != true) || Number(item.AvailableQty) <= 0))
  2126. Invoiceitem.push(itemRow);
  2127. }
  2128. else if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && ((EnableMrp != true && EnableBatch != true) || (Number(item.AvailableQty) <= 0)))
  2129. Invoiceitem.push(itemRow);
  2130. else if (($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3") && EnableMrp != true && EnableBatch != true)
  2131. Invoiceitem.push(itemRow);
  2132. else if ($(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7")
  2133. Invoiceitem.push(itemRow);
  2134. else {
  2135. if (item.InventoryTypeId != 5 && item.InventoryTypeId != 6 && item.InventoryTypeId != 7) {
  2136. var total = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  2137. var nonexcise = total - itemRow.exciseAmount;
  2138. var disc = ((nonexcise * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  2139. var Rowtotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(total - disc, 3);
  2140. instance.SplitedInvoiceItemList.push({
  2141. orderItemId: item.OrderItemId,
  2142. invoiceItemId: invoiceItemId,
  2143. itemName: item.ItemName,
  2144. itemId: item.ItemId,
  2145. itemSKU: item.ItemSKU,
  2146. unitName: item.UnitName,
  2147. packSize: item.PackSize,
  2148. packCount: item.PackCount,
  2149. packs: item.Packs,
  2150. quantity: item.Quantity,
  2151. availPacks: item.AvailablePacks,
  2152. availQty: item.AvailableQty,
  2153. listPrice: 0,
  2154. description: item.Description,
  2155. taxGroupName: item.TaxGroupName,
  2156. taxGroupId: item.TaxGroupId,
  2157. isTaxInclusive: $("#hfId_istaxinclusive").val(),
  2158. addlDiscountPercent: item.DiscountPercent,
  2159. addlDiscountValue: item.DiscountAmount,
  2160. creditNote: 0,
  2161. priceListId: 0,
  2162. batchId: 0,
  2163. unitPrice: item.UnitPrice,
  2164. invoiceallocations: null,
  2165. exciseInvoiceItem: null,
  2166. accountId: item.LedgerId,
  2167. accountName: item.LedgerName,
  2168. walletId: 0,
  2169. Adjustment: 0,
  2170. IsFoc: 0,
  2171. TariffNo: "",
  2172. exciseAmount: item.ExciseAmount,
  2173. discountName: "",
  2174. discountId: 0,
  2175. refNo: item.RefNo,
  2176. DiscountGroupId: item.DiscountGroupId,
  2177. DiscountGroupName: item.DiscountGroupName,
  2178. ExchangeItem: item.ExchangeDC,
  2179. maxQty: maxQty,
  2180. RefInvoiceItemId: refInvoiceItemId,
  2181. MrpId: item.MrpId,
  2182. taxAdjustment: item.TaxAdjustment,
  2183. assesableAdjustment: item.AssesableAdjustment,
  2184. inventoryTypeId: item.InventoryTypeId,
  2185. IsBoMItem: item.IsBoMItem,
  2186. dcItemId: item.DcItemId,
  2187. TotalRowAmount: Rowtotal,
  2188. TotalDiscount: disc,
  2189. BatchId: item.BatchId,
  2190. TotalAmount: Rowtotal,
  2191. ParentBOMItemId: item.ParentBOMItemId
  2192. });
  2193. if (items.length != 0 && items.find(x => x.itemId == item.ItemId) != undefined) {
  2194. var multipleExist = items.find(x => x.itemId == item.ItemId);
  2195. multipleExist.quantity += itemRow.quantity;
  2196. var RowTotal = 0;
  2197. var rowtotal = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  2198. var nonexiceamount = rowtotal - itemRow.exciseAmount;
  2199. var discount = ((nonexiceamount * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  2200. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  2201. RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  2202. multipleExist.TotalRowAmount = Number(multipleExist.TotalRowAmount) + Number(RowTotal);
  2203. multipleExist.TotalDiscount = Number(multipleExist.TotalDiscount) + Number(discount);
  2204. if (instance.OrderSettingId == 1) {
  2205. var Qty = Number(maxQty);
  2206. multipleExist.maxQty = Qty + Number(multipleExist.maxQty);
  2207. }
  2208. else {
  2209. var Qty = Number(item.Quantity);
  2210. multipleExist.maxQty = Qty + Number(multipleExist.maxQty);
  2211. }
  2212. }
  2213. else {
  2214. var RowTotal = 0;
  2215. var rowtotal = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  2216. var nonexiceamount = rowtotal - itemRow.exciseAmount;
  2217. var discount = ((nonexiceamount * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  2218. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  2219. RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  2220. itemRow.TotalRowAmount = Number(itemRow.TotalRowAmount) + Number(RowTotal);
  2221. itemRow.TotalDiscount = Number(discount);
  2222. items.push(itemRow);
  2223. }
  2224. }
  2225. else {
  2226. Invoiceitem.push(itemRow);
  2227. }
  2228. }
  2229. var isFOC = false;
  2230. if (itemRow.unitPrice == 0) {
  2231. isFOC = true;
  2232. }
  2233. var taxamount = itemRow.TaxAmount / itemRow.quantity;
  2234. instance.userCart.push({ lobId: 0, productId: 0, itemId: itemRow.itemId, quantity: itemRow.quantity, itemPrice: itemRow.unitPrice, itemName: itemRow.itemName, isFOC: isFOC, taxAmmount: taxamount, discountValue: itemRow.DiscountAmount });
  2235. instance.updateCheckoutPageList();
  2236. instance.cartInst.updateCartContainerHtml(itemRow.itemId, 0);
  2237. }
  2238. for (const j of items) {
  2239. var emptyRow = {
  2240. orderItemId: j.orderItemId,
  2241. invoiceItemId: 0,
  2242. itemName: j.itemName,
  2243. itemId: j.itemId,
  2244. itemSKU: j.itemSKU,
  2245. unitName: "",
  2246. packSize: 0,
  2247. packCount: 0,
  2248. packs: 0,
  2249. quantity: j.quantity,
  2250. availPacks: 0,
  2251. availQty: j.availQty,
  2252. listPrice: 0,
  2253. description: "",
  2254. taxGroupName: j.taxGroupName,
  2255. taxGroupId: j.taxGroupId,
  2256. isTaxInclusive: $("#hf_istaxinclusive").val(),
  2257. addlDiscountPercent: 0,
  2258. addlDiscountValue: j.addlDiscountValue,
  2259. creditNote: 0,
  2260. priceListId: 0,
  2261. batchId: 0,
  2262. unitPrice: j.unitPrice,
  2263. invoiceallocations: null,
  2264. exciseInvoiceItem: null,
  2265. accountId: j.accountId,
  2266. accountName: j.accountName,
  2267. walletId: 0,
  2268. Adjustment: 0,
  2269. IsFoc: j.IsFoc,
  2270. TariffNo: "",
  2271. exciseAmount: 0,
  2272. discountName: "",
  2273. discountId: 0,
  2274. refNo: "",
  2275. DiscountGroupId: 0,
  2276. DiscountGroupName: '',
  2277. RefInvoiceItemId: 0,
  2278. MrpId: j.MrpId,
  2279. taxAdjustment: 0,
  2280. assesableAdjustment: 0,
  2281. inventoryTypeId: 0,
  2282. dcItemId: 0,
  2283. TotalRowAmount: j.TotalRowAmount,
  2284. BatchId: j.BatchId,
  2285. maxQty: j.maxQty,
  2286. TotalDiscount: j.TotalDiscount,
  2287. ParentBOMItemId: j.ParentBOMItemId
  2288. };
  2289. }
  2290. $("#totalinvoiceqty").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalQty, 2));
  2291. });
  2292. }
  2293. }
  2294. Print(id) {
  2295. var templateid = "0";
  2296. if (Bizgaze.Apps.Transact.Controls.Pos.Instance().isdraft == false) {
  2297. Pos.Instance().fileCacheHelper.loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  2298. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(id).then(function (response) {
  2299. if (response.result != null) {
  2300. var invoiceresponse = response.result;
  2301. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().updateinvoiceseries(id, invoiceresponse.SeriesId, 0, invoiceresponse.TemplateId).then(function (data) {
  2302. if (data.status == 2) {
  2303. MessageHelper.Instance().showError(data.message, 'bizgaze_CreateErrorMessages');
  2304. return false;
  2305. }
  2306. else {
  2307. var detailobj = Unibase.Themes.Providers.DetailHelper.DetailInstance();
  2308. detailobj._recordId = Unibase.Themes.Providers.DetailHelper.recordId;
  2309. detailobj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  2310. detailobj._containerId = detailobj._containerId;
  2311. detailobj.loadPortlets(detailobj);
  2312. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getprintinvoice(id, true, true).then(function (data) {
  2313. var resp = data.result;
  2314. Pos.Instance().printPopup(resp);
  2315. var printhtml = '<div id="divPrint hidden"><span class="printDataN">' + resp.Html + '</span></div >';
  2316. }, function (response) {
  2317. MessageHelper.Instance().showError(response.responseText, "");
  2318. });
  2319. }
  2320. });
  2321. }
  2322. });
  2323. });
  2324. }
  2325. }
  2326. applyOffer(selectedItemArray) {
  2327. var totalPrice = this.totalPrice(this.userCart);
  2328. if (selectedItemArray != null) {
  2329. for (var i = 0; i < selectedItemArray.length; i++) {
  2330. var item = this.selectedItemsArray.find(x => x.itemId == selectedItemArray[i].ItemId);
  2331. var focItemId = selectedItemArray.map(x => x.focItemId);
  2332. var index = this.userCart.findIndex(x => x.itemId == item.itemId && x.productId == item.productId);
  2333. if (index == -1) {
  2334. this.userCart.push({ lobId: this.lobId, productId: item.productId, itemId: item.itemId, quantity: selectedItemArray[i].Volume, itemPrice: item.UnitPrice, itemName: item.itemName, totalPrice: totalPrice, offerrefid: 0, isFOC: false, discountValue: 0, taxAmmount: item.TaxAmount });
  2335. item = this.userCart.find(x => x.itemId == item.itemId && x.productId == item.productId);
  2336. }
  2337. else {
  2338. var offerIndex = this.userCart.findIndex(x => x.offerrefid == item.itemId && x.itemId == selectedItemArray[i].focItemId);
  2339. if (offerIndex == -1) {
  2340. this.removeItemFromItemCartAndUsercart(item.productId, item.itemId);
  2341. var offeritems = this.userCart.filter(x => x.offerrefid == item.itemId);
  2342. if (offeritems != null) {
  2343. for (var j = 0; j < offeritems.length; j++) {
  2344. this.removeItemFromItemCartAndUsercart(offeritems[j].productId, offeritems[j].itemId);
  2345. }
  2346. }
  2347. this.userCart.push({ lobId: this.lobId, productId: item.productId, itemId: item.itemId, quantity: selectedItemArray[i].Volume, itemPrice: item.UnitPrice, itemName: item.itemName, totalPrice: totalPrice, offerrefid: 0, isFOC: false, discountValue: 0, taxAmmount: item.taxAmmount });
  2348. item = this.userCart.find(x => x.itemId == item.itemId && x.productId == item.productId);
  2349. }
  2350. }
  2351. var element = document.getElementById(item.itemId);
  2352. this.updateItemContainerSpinnerOnMDown(element, null, true, item.quantity);
  2353. this.getOfferDetails(item, focItemId);
  2354. this.cartInst.updateCartContainerHtml(item.itemid, item.productId);
  2355. }
  2356. }
  2357. else if (this.offerItemsArray.length > 0) {
  2358. }
  2359. }
  2360. printPopup(data) {
  2361. var mywindow = window.open('', 'my Print', 'height=400,width=850');
  2362. var content = '<html><head><title>Print</title><link rel="stylesheet" href="lib/bizgaze/print.css" /><link rel="stylesheet" href="lib/bootstrap/bootstrap-theme.min.css" /></head><body>';
  2363. content += data.Html;
  2364. content += "<script>print();</script>";
  2365. content += '</body></html>';
  2366. mywindow.document.write(content);
  2367. return true;
  2368. }
  2369. static Instance() {
  2370. if (this._instance === undefined) {
  2371. this._instance = new Pos();
  2372. }
  2373. return this._instance;
  2374. }
  2375. }
  2376. Controls.Pos = Pos;
  2377. })(Controls = Transact.Controls || (Transact.Controls = {}));
  2378. })(Transact = Apps.Transact || (Apps.Transact = {}));
  2379. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  2380. })(Bizgaze || (Bizgaze = {}));