Built files from Bizgaze WebServer
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

splititem.js 81KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let Transact;
  6. (function (Transact) {
  7. let Controls;
  8. (function (Controls) {
  9. let Invoices;
  10. (function (Invoices) {
  11. class SplitItem extends Unibase.Platform.Core.BaseComponent {
  12. constructor() {
  13. super(...arguments);
  14. this.Type = "";
  15. this.PendingQty = 0;
  16. this.SplitedInvoiceItemList = new Array();
  17. this.rowIndex = 0;
  18. this.container = "";
  19. this.DcItemIds = new Array();
  20. this.Delete_InvoiceItems = new Array();
  21. }
  22. jsFiles() {
  23. return ["apps/transact/controls/pricelist/mrp.js", "/platform/forms/managers/interfaces/iformmanager.js", "/platform/forms/managers/formmanager.js", "platform/forms/components/formviewer/formviewer.js", 'libs/parsley/parsley.min.js', 'apps/transact/controls/pricelist/managers/pricelistmanager.js', "apps/transact/controls/inventory/batch.js"];
  24. }
  25. cssFiles() {
  26. return [];
  27. }
  28. load(item) {
  29. var instance = this;
  30. SplitItem.Instance().DcItemIds = [0];
  31. $("#btn_InvoiceItem_Close").click(function () {
  32. instance.navigationHelper.closePopUp();
  33. });
  34. let element = item[0].element;
  35. let type = item[0].type;
  36. this.Type = item[0].type;
  37. $(".InvoiceItemName").text(element.find(".selectedItemName").text());
  38. $(".EnabledType").text(type);
  39. $("#hf_ItemId").val(element.find(".selectedItemId").val());
  40. $(".hf_AvailQty").text(element.find(".prodAvail").text());
  41. let orderid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid;
  42. if (orderid != undefined && orderid != null && orderid != 0) {
  43. $(".hf_pendingQty").text(element.find(".maxQty").val());
  44. this.PendingQty = element.find(".maxQty").val();
  45. }
  46. this.Type = type;
  47. $("#btnInvoice_Batch").click(function () {
  48. Invoices.SplitItem.Instance().addMrpRow(element);
  49. });
  50. $(".btn_InvoiceItem_Save").click(function () {
  51. Invoices.SplitItem.Instance().SaveItem(element);
  52. });
  53. $(document).click(function (e) {
  54. var container = $(".div_Item_MoreDetails");
  55. if ($(e.target).closest("[class^='div_Item_MoreDetails']").length <= 0 && $(e.target).closest("[class^='Quantity']").length <= 0 && $(e.target).closest("[class^='Price']").length <= 0) {
  56. $("[class^='div_Item_MoreDetails']").addClass('hidden');
  57. }
  58. });
  59. let dcid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid;
  60. let InvoiceId = $(".hdn_invoiceid").val();
  61. let ItemExist = false;
  62. for (var i = 0; i < Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  63. if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == $("#hf_ItemId").val()) {
  64. if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false && (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 || (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid == 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid != 0)) && (InvoiceId == "0")) {
  65. if (SplitItem.Instance().Type == "MRP") {
  66. SplitItem.Instance().DcItemIds.push(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].MrpId);
  67. }
  68. else if (SplitItem.Instance().Type == "BatchNo") {
  69. SplitItem.Instance().DcItemIds.push(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].BatchId);
  70. }
  71. }
  72. ItemExist = true;
  73. Invoices.SplitItem.Instance().addMrpRowWithData(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i]);
  74. var accid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountId;
  75. var taxgrpid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId;
  76. var taxgrptext = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupName;
  77. var acctext = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountName;
  78. element.find(".hf_Account").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountId);
  79. element.find(".hfProdTax").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId);
  80. element.find(".txtProdTax").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupName);
  81. element.find(".txt_AccountName").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountName);
  82. if (accid != 0) {
  83. $("#hf_AccountId").val(accid);
  84. $("#ddl_AccountId").append(new Option(acctext, accid, true));
  85. }
  86. if (taxgrpid != 0) {
  87. $("#hf_TaxGroupId").val(taxgrpid);
  88. $("#ddl_TaxGroupId").append(new Option(taxgrptext, taxgrpid, true));
  89. Invoices.SplitItem.Instance().update_TaxPercentage(taxgrpid);
  90. }
  91. }
  92. }
  93. Invoices.SplitItem.Instance().loadTaxGroupAutoComplete(element);
  94. if (ItemExist == false)
  95. this.addMrpRow(element);
  96. }
  97. loadTaxGroupAutoComplete(element) {
  98. var hfProdTax = element.find(".hfProdTax");
  99. var accid = element.find(".hf_Account").val();
  100. var taxgrpid = element.find(".hfProdTax").val();
  101. var taxgrptext = element.find(".txtProdTax").val();
  102. var acctext = element.find(".txt_AccountName").val();
  103. AutoCompleteHelper.getHelper().Create("#ddl_TaxGroupId", "#hf_TaxGroupId", _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
  104. Invoices.SplitItem.Instance().update_TaxPercentage($("#hf_TaxGroupId").val());
  105. });
  106. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete';
  107. AutoCompleteHelper.getHelper().Create("#ddl_AccountId", "#hf_AccountId", url, function (response) {
  108. });
  109. if (taxgrpid != 0) {
  110. $("#hf_TaxGroupId").val(taxgrpid);
  111. if ($("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected").length == 0) {
  112. $("#ddl_TaxGroupId").append(new Option(taxgrptext, taxgrpid, true));
  113. }
  114. else {
  115. $("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected");
  116. }
  117. Invoices.SplitItem.Instance().update_TaxPercentage($("#hf_TaxGroupId").val());
  118. }
  119. if (accid != 0) {
  120. $("#hf_AccountId").val(accid);
  121. if ($("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected").length == 0) {
  122. $("#ddl_AccountId").append(new Option(acctext, accid, true));
  123. }
  124. else {
  125. $("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected");
  126. }
  127. }
  128. }
  129. update_TaxPercentage(taxGroupId) {
  130. var hfTaxPercent = $(".hf_ProdTaxPercent");
  131. var percentage = 0;
  132. if (taxGroupId == "0" || taxGroupId == "" || taxGroupId == undefined)
  133. return percentage;
  134. var isExcise = false;
  135. if ($('#hfInv_InvoiceMode').val() == 'Excise')
  136. isExcise = true;
  137. let branchid = Unibase.Platform.Membership.Infos.Identity.getSetting("branchid");
  138. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().gettaxpercentages(taxGroupId, branchid).then(function (response) {
  139. var percentstring = "";
  140. if (response.result.length > 0) {
  141. var percentages = response.result;
  142. for (var i = 0; i < percentages.length; i++) {
  143. percentstring += percentages[i].LedgerId + ":" + percentages[i].Percentage + ",";
  144. }
  145. hfTaxPercent.val(percentstring);
  146. }
  147. });
  148. }
  149. html() {
  150. var html = '<form id="frm_Bizgazetransact_Invoice_createInvoiceItem" data-validate="parsley"><div class="b-b bg-white modal-header bg-white b-b modal-header pa-10"><strong class="titlename InvoiceItemName col-8"></strong><div class="col-4 pull-right"><span class="pull-right mr-10">Amount: <strong class="hf_nettotal">0.00</strong></span></div></div><div style="height: 840px; overflow:hidden auto;" class="simple-scroll-bar modal-body bg-cyan-light-5"><div class="bg-white mb-10"><span class="ml-10"> Pending: <span class="hf_pendingQty ml-5" > 0 </span><span>/Total Avail: </span><span class="hf_AvailQty ml-5">0</span > </span></div ><div id="bizgaze_CreateBatchErrorMessages" class="clear"></div><div class="card" > <div class="card-body"><div class="col-sm-12 d-none d-md-block"><div class="row " style="overflow-x:hidden;border-bottom: 2px solid grey;"><input type="hidden" id="hf_ItemId" ><div class="col-sm-4 min-padding"><strong class="EnabledType ml-20">MRP</strong> </div><div class="col-sm-2 text-center min-padding"><strong class="ml-15">Qty</strong></div><div class="col-sm-2 text-center min-padding"><strong>Unit Price</strong></div><div class="col-sm-2 text-center min-padding"><strong>Disc.</strong></div><div class="col-sm-2 text-right min-padding"><strong class="mr-15">Total</strong></div></div></div><div><div class="Mrp-row added-row hidden"></div><div class="Batch-row added-row hidden"></div><div class="Serial-row added-row hidden"></div></div><div class="row"><a href="javascript:;" class="default pull-left" title="Add" data-original-title="Add"><span class="pull-right btn" id="btnInvoice_Batch" style="text-decoration:underline;color:deepskyblue">Add</span></a></div><div class="row div_TaxDetails mt-5"><div class="col-sm-4"><div class="floating-label-form-group-with-value"> <label id="lbl_TaxGroupId" for= "lbl_TaxGroupId" >Tax Group Name<span class="text-red ml-1" >*</span></label><select id="ddl_TaxGroupId" class="form-control required ui-autocomplete" style = "width:100%;" data - placeholder="TaxGroup Name" data-label="TaxGroup Name" placeholder = "TaxGroup Name" ></select><input type ="hidden" class="hf_ProdTaxPercent" value="0" /><input type="hidden" id = "hf_TaxGroupId"></div></div><div class="col-sm-4"><div class="floating-label-form-group-with-value"> <label id="lbl_AccountId" for= "lbl_AccountId"> Account Name <span class= "text-red ml-1" >* </span></label ><select id= "ddl_AccountId" class="form-control required ui-autocomplete" style = "width:100%;" data - placeholder="Account Name" data-label="Account Name" placeholder ="Account Name"></select> <input type = "hidden" id = "hf_AccountId" ></div></div></div></div></div></div><div class="b-t bg-white modal-footer pa-10"><a id="btn_InvoiceItem_Close" class="btn btn-light btn-sm mr-auto"> Close</a><a href="javascript:;" id="btn_InvoiceItem_Save_mobile" class="btn btn-primary btn-sm btn_InvoiceItem_Save">Save</a></div></form>';
  151. return html;
  152. }
  153. addMrpRow(element) {
  154. let item = false;
  155. $(".Mrp-addedrow").each(function () {
  156. if ($(this).find('.select_' + Invoices.SplitItem.Instance().Type + '').val() == undefined || $(this).find('.select_' + Invoices.SplitItem.Instance().Type + '').val() == null) {
  157. item = true;
  158. }
  159. });
  160. if (item) {
  161. MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, "bizgaze_CreateBatchErrorMessages");
  162. return false;
  163. }
  164. var array = {
  165. orderItemId: element.find('.orderItemId').val(),
  166. invoiceItemId: 0,
  167. itemId: element.find('.selectedItemId').val(),
  168. packSize: 0,
  169. packCount: 0,
  170. packs: 0,
  171. quantity: 0,
  172. availPacks: 0,
  173. availQty: 0,
  174. Description: "",
  175. isTaxInclusive: $("#hfIsTaxInclusive").val(),
  176. addlDiscountPercent: 0,
  177. addlDiscountValue: 0,
  178. creditNote: 0,
  179. priceListId: element.find('.hf_PriceList').val(),
  180. invoiceallocations: null,
  181. exciseInvoiceItem: null,
  182. walletId: 0,
  183. Adjustment: 0,
  184. IsFoc: 0,
  185. TariffNo: "",
  186. exciseAmount: 0,
  187. discountName: "",
  188. discountId: 0,
  189. description: "",
  190. RefNo: "",
  191. DiscountGroupId: 0,
  192. DiscountGroupName: '',
  193. RefInvoiceItemId: 0,
  194. taxAdjustment: element.find('.hfItemTaxAdjsutmentVal').val(),
  195. assesableAdjustment: element.find('.hfItemAssesableAdjustmentVal').val(),
  196. inventoryTypeId: 0,
  197. dcItemId: 0,
  198. ExchangeItem: element.find('.IsExchangeItem').val(),
  199. unitPrice: element.find('.prodPrice').val(),
  200. taxGroupId: $("#hf_TaxGroupId").val(),
  201. BatchId: 0,
  202. MrpId: 0,
  203. SerialId: 0,
  204. Name: '',
  205. maxQty: 0,
  206. AccountId: element.find('.txt_Account').val(),
  207. AccountName: element.find('.txt_Account').text()
  208. };
  209. Invoices.SplitItem.Instance().addMrpRowWithData(array);
  210. }
  211. addMrpRowWithData(row) {
  212. this.rowIndex += 1;
  213. var activeDiscVal = "";
  214. var activeDiscPercent = "";
  215. var activeDiscMul = "";
  216. var activeDiscText = "";
  217. var discValue = 0;
  218. if (row.addlDiscountPercent > 0) {
  219. discValue = row.addlDiscountPercent;
  220. activeDiscPercent = "active";
  221. activeDiscText = "%";
  222. }
  223. else if (row.addlDiscountValue > 0 && row.DiscountGroupId > 0) {
  224. discValue = row.addlDiscountValue;
  225. activeDiscMul = "active";
  226. activeDiscText = "Mul";
  227. }
  228. else {
  229. discValue = row.addlDiscountValue;
  230. activeDiscVal = "active";
  231. activeDiscText = "Val";
  232. }
  233. var Class = "";
  234. if (SplitItem.Instance().Type == "MRP") {
  235. Class = "Mrp-row Mrp-addedrow";
  236. }
  237. else if (SplitItem.Instance().Type == "BatchNo") {
  238. Class = "Batch-row Batch-addedrow";
  239. }
  240. else if (SplitItem.Instance().Type == "SerialNo") {
  241. Class = "Serial-row Serial-addedrow";
  242. }
  243. var readonlyPrice = "";
  244. var readonlyDisc = "";
  245. var readonlyTax = "";
  246. var readonlyQty = "";
  247. var ManageInvoice = 2;
  248. var ManageInvoiceTax = 1;
  249. if (ManageInvoice == 1 && AutoDc == false) {
  250. readonlyQty = "readonly";
  251. readonlyPrice = "readonly";
  252. readonlyDisc = "readonly";
  253. readonlyTax = "readonly";
  254. }
  255. if ($('.hdn_invoicetypeid').val() == "1" && ManageInvoiceTax == 1 && AutoDc == false) {
  256. readonlyTax = "readonly";
  257. }
  258. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_IsRetun').val() == "1") {
  259. row.invoiceallocations = null;
  260. row.invoiceItemId = 0;
  261. }
  262. var html = '<div class="row ' + Class + ' form-group mt-20 SplInvoiceItemRow "' + this.rowIndex + '"" >' +
  263. '<div class="row col-sm-12 ml-5">' +
  264. '<input type="hidden" class="txt_rowIndex" value="' + this.rowIndex + '"/>' +
  265. '<input type="hidden" class="hf_orderItemId" value="' + row.orderItemId + '"/>' +
  266. '<input type="hidden" class="hf_dcItemId" value="' + row.dcItemId + '"/>' +
  267. '<input type="hidden" class="hf_selectedInvoiceItemId" value="' + row.invoiceItemId + '"/>' +
  268. '<input type="hidden" class="hf_refInvoiceItemId" value="' + row.RefInvoiceItemId + '"/>' +
  269. '<input type="hidden" class="hf_selectedItemId" value="' + row.itemId + '"/>' +
  270. '<input type="hidden" class="hf_offerapplied" value="0"/>' +
  271. '<input type="hidden" class="hf_refNo" value="' + row.RefNo + '"/>' +
  272. '<input type="hidden" class="hf_description" value="' + row.description + '"/>' +
  273. '<input type="hidden" class="hf_IsExchangeItem" value="' + row.ExchangeItem + '"/>' +
  274. '<input type="hidden" class="hf_ItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '"/>' +
  275. '<input type="hidden" class="hf_ItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '"/>' +
  276. '<input type="hidden" class="hf_maxQty" value="' + row.maxQty + '" />' +
  277. '<input type="hidden" class="exciseAmount" value="0"/>' +
  278. '<input type="hidden" class="hf_UnitPrice" value="' + row.unitPrice + '"/>' +
  279. '<input type="hidden" class="hf_' + SplitItem.Instance().Type + '_Name" value=""/>' +
  280. '<div class="col-sm-4">' +
  281. '<div class=" min-padding">' +
  282. '<a class="no-border bg-white delete-row" href = "javascript:;" title = "Remove row" style = ""> <i class="fa fa-trash-o fa-lg mt-15 mr-2" style="margin-left:-25px;color:red"></i></a>' +
  283. '<select class=" required select_' + SplitItem.Instance().Type + '" id="select_itemMrp_' + this.rowIndex + '" placeholder=" Select ' + SplitItem.Instance().Type + '" style="width:100%;" ></select>' +
  284. '<input type="hidden" id="hf_itemMrp_' + this.rowIndex + '" class="hf_' + SplitItem.Instance().Type + '_Id"/>' +
  285. '</div></div>' +
  286. '<div class="col-sm-2">' +
  287. '<div class="floating-label-form-group min-padding">' +
  288. '<input type="text" class="Quantity text-center form-control" placeholder="0.00" value="' + row.quantity + '" ' + readonlyQty + '>' +
  289. '</div></div>' +
  290. '<div class="col-sm-2">' +
  291. '<div class="floating-label-form-group min-padding">' +
  292. '<input type="text" class="Price text-center form-control" placeholder="0.00" value="' + row.unitPrice + '" ' + readonlyPrice + '/>' +
  293. '</div></div>' +
  294. '<div class="col-sm-2">' +
  295. '<div class="floating-label-form-group">' +
  296. '<input type="hidden" id="hf_ItemDiscountGroupId" value="' + row.DiscountGroupId + '" />' +
  297. '<input type="hidden" id="hf_ItemDiscountGroupName" value="' + row.DiscountGroupName + '" />' +
  298. '<input type="hidden" id="hf_ItemDiscountList" value=""/>' +
  299. '<input type="hidden" id="hf_ItemDiscountApplyTypes" value=""/>' +
  300. '<div class="input-group">' +
  301. '<input type="text" id="txt_discount" placeholder="0.00" class="form-control txt_addldiscount text-center d-none d-md-block" value="' + discValue + '" readonlyDisc>' +
  302. '<input type="text" id="txt_discount" placeholder="0.00" class="form-control txt_addldiscount text-center ml-40 d-md-none" value="' + discValue + '" readonlyDisc>' +
  303. '<div class="input-group-btn">' +
  304. '<div class="input-group-btn">' +
  305. '<select class="btn_item_DiscType mt-10 border-blue"><option value="Val">Val</option><option value="%">%</option></select>' +
  306. '</div>' +
  307. '</div></div></div></div>' +
  308. '<div class="col-sm-2">' +
  309. '<input type="hidden" class="hf_DiscountedAmount" value="0" />' +
  310. '<input type="hidden" class="hf_RowTotalAdjustment" value="' + row.Adjustment + '" />' +
  311. '<input type="hidden" class="hf_AssesableAdjustment" value="" />' +
  312. '<input type="hidden" class="hf_TaxAdjustment" value="" />';
  313. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  314. html += '<a href="javascript:;" class="AjustmentRow"><input type="text" style="color:#5ba8fb;text-decoration:underline;cursor:pointer" class="hf_RowTotalwithAdjustment form-control txt_RowTotalwithAdjustment text-right" value="0" /></a>';
  315. html += '<a href="javascript:;" class="hidden" onclick="javascript:_bizgazetransact_invoice_edit.editInvItemTaxAllocs(' + row.invoiceItemId + ',' + row.TaxGroupId + ',' + row.itemId + ',' + row.orderItemId + ')"><input type="text" style="color:#5ba8fb;text-decoration:underline;cursor:pointer" class="hf_RowTotal form-control txt_RowTotal text-right" value="0" /></a>';
  316. }
  317. else {
  318. html += '<p class="pull-right mt-10 mr-10"><strong><input type="hidden" class="hf_RowTotal" value="0" /><span class="TotalPrice">0.00</span></strong></p>';
  319. }
  320. html += '</div></div >';
  321. html += '<div class="row col-sm-12 div_Item_MoreDetails clear hidden">' +
  322. '<div class="row col-sm-12 bg-light ml-10 mt-5">' +
  323. '<div class="col-sm-6">' +
  324. '<div class="floating-label-form-group desc">' +
  325. '<label for="lbl_Description" id="lbl_Description">Description</label>' +
  326. '<input type="text" id="txt_Item_Description" data-isdynamic="false" class="type-control form-control type-control value-control floating-label-control" data-placeholder="Enter Description" placeholder="Description" data-label="Description"/>' +
  327. '</div></div>';
  328. if (SplitItem.Instance().Type != "MRP") {
  329. html += '<div class="col-sm-2 mt-30">' +
  330. '<label for="lbl_Mrp" id="lbl_Mrp"><b>Mrp: &ensp;<span></span></b></label>' +
  331. '<span class="spn_Mrp">0</span>' +
  332. '<input type="hidden" class="hf_MrpId"/>' +
  333. '</div>';
  334. }
  335. html += '<div class="col-sm-3 mt-30">' +
  336. '<label for="lbl_Avalilability" id="lbl_Avalilability"><b>Availability: &ensp;<span></span></b></label>' +
  337. '<span class="spn_Avail">0</span>' +
  338. '<input type="hidden" class="hf_PriceList" value="' + row.priceListId + '"/>' +
  339. '</div>' +
  340. '</div></div></div>';
  341. var element = "";
  342. if (SplitItem.Instance().Type == "MRP") {
  343. $(".Mrp-row:last").after(html);
  344. element = $(".Mrp-addedrow:last");
  345. }
  346. else if (SplitItem.Instance().Type == "BatchNo") {
  347. $(".Batch-row:last").after(html);
  348. element = $(".Batch-addedrow:last");
  349. }
  350. else if (SplitItem.Instance().Type == "SerialNo") {
  351. $(".Serial-row:last").after(html);
  352. element = $(".Serial-addedrow:last");
  353. }
  354. element.find(".btn_item_DiscType option[value='" + activeDiscText + "']").prop("selected", true);
  355. if (row.description != null && row.description != '' && row.description != 'null') {
  356. element.find('#txt_Item_Description').val(row.description);
  357. element.find('#txt_Item_Description').parent(".desc").addClass("floating-label-form-group-with-value");
  358. }
  359. if ((row.orderItemId != 0 && row.dcItemId != 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1) || (row.orderItemId == 0 && row.dcItemId != 0 && AutoDc == false)) {
  360. element.find('.select_' + SplitItem.Instance().Type + '').prop('disabled', true);
  361. }
  362. $('.txt_addldiscount').keypress(function (event) {
  363. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  364. }
  365. else {
  366. event.preventDefault();
  367. }
  368. }).on('paste', function (event) {
  369. event.preventDefault();
  370. });
  371. $('.Quantity').keypress(function (event) {
  372. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  373. }
  374. else {
  375. event.preventDefault();
  376. }
  377. }).on('paste', function (event) {
  378. event.preventDefault();
  379. });
  380. $('.Price').keypress(function (event) {
  381. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  382. }
  383. else {
  384. event.preventDefault();
  385. }
  386. }).on('paste', function (event) {
  387. event.preventDefault();
  388. });
  389. var AutoDc = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc;
  390. if (row.dcItemId != 0 || row.MrpId != 0 || row.BatchId != 0) {
  391. if (SplitItem.Instance().Type == "MRP") {
  392. if ((row.MrpId != 0 && row.MrpId != undefined) || row.dcItemId != 0) {
  393. element.find('.hf_' + SplitItem.Instance().Type + '_Id').val(row.MrpId);
  394. Invoices.SplitItem.Instance().GetMrpandBatchQty(row.MrpId, element, "", 0, row);
  395. }
  396. else {
  397. Invoices.SplitItem.Instance().Load(element);
  398. }
  399. }
  400. else if (SplitItem.Instance().Type == "BatchNo") {
  401. if ((row.BatchId != 0 && row.BatchId != undefined)) {
  402. element.find('.hf_' + SplitItem.Instance().Type + '_Id').val(row.BatchId);
  403. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/pricelist/managers/pricelistmanager.js", function () {
  404. Bizgaze.Apps.Transact.Managers.PriceListManager.Instance().getbatch(row.BatchId).then(function (result) {
  405. Invoices.SplitItem.Instance().GetMrpandBatchQty(result.result.MrpId, element, result.result.BatchNo, row.BatchId, row);
  406. });
  407. });
  408. }
  409. else {
  410. Invoices.SplitItem.Instance().Load(element);
  411. }
  412. }
  413. else if (SplitItem.Instance().Type == "SerialNo") {
  414. if (row.SerialId != 0 || row.dcItemId != 0) {
  415. Invoices.SplitItem.Instance().GetMrpandBatchQty(row.SerialNoId, element, "", 0, null);
  416. row.Name = element.find('.hf_' + SplitItem.Instance().Type + '_Name').val();
  417. element.find('.hf_' + SplitItem.Instance().Type + '_Id').val(row.SerialId);
  418. }
  419. }
  420. }
  421. else {
  422. Invoices.SplitItem.Instance().Load(element);
  423. }
  424. element.find(".Price,.Quantity,.txt_addldiscount ").focusin(function () {
  425. $(".div_Item_MoreDetails").addClass("hidden");
  426. element.find(".div_Item_MoreDetails").removeClass("hidden");
  427. });
  428. element.find(".prodName").focusin(function () {
  429. $(".div_Item_MoreDetails").addClass("hidden");
  430. });
  431. element.find(".txt_addldiscount").change(function () {
  432. if (element.find(".btn_item_DiscType").val() == "%") {
  433. if (Number(element.find(".txt_addldiscount").val()) > 100)
  434. element.find(".txt_addldiscount").val("100");
  435. }
  436. });
  437. element.find(".select_" + SplitItem.Instance().Type).change(function () {
  438. let obj = [];
  439. obj.push({
  440. ItemId: $("#hf_ItemId").val(),
  441. element: element,
  442. });
  443. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3") {
  444. if (element.find(".select_" + SplitItem.Instance().Type + " option:selected").text() == "Create MRP") {
  445. var itemobj = Bizgaze.Apps.Transact.Controls.MRP.Instance();
  446. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", itemobj, null, Unibase.Platform.Helpers.Size.DockLeft);
  447. }
  448. else if (element.find(".select_" + SplitItem.Instance().Type + " option:selected").text() == "Create Batch") {
  449. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/inventory/batch.js", function () {
  450. var item = Bizgaze.Apps.Transact.Controls.Batch.Instance();
  451. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(Number($("#hf_ItemId").val()), "", item, null, Unibase.Platform.Helpers.Size.DockLeft);
  452. });
  453. }
  454. }
  455. });
  456. Invoices.SplitItem.Instance().update_row_total(element);
  457. if ($(".hdn_invoicetypeid").val() == "2") {
  458. element.find('.AjustmentRow').click(function () {
  459. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().editInvItemTaxAllocs(row.invoiceItemId, row.taxGroupId, row.itemId, row.orderItemId, element);
  460. });
  461. }
  462. Invoices.SplitItem.Instance().RemoveRow(element);
  463. element.find('.btn_item_DiscType').change(function () {
  464. if (element.find(".btn_item_DiscType").val() == "%") {
  465. if (Number(element.find(".txt_addldiscount").val()) > 100)
  466. element.find(".txt_addldiscount").val("100");
  467. }
  468. if (element.find(".btn_item_DiscType option:selected").text().trim() == 'Val') {
  469. element.find('#hf_ItemDiscountGroupId').val(0);
  470. element.find('#hf_ItemDiscountGroupName').val('');
  471. element.find('.txt_addldiscount').prop('disabled', false);
  472. }
  473. else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%') {
  474. element.find('#hf_ItemDiscountGroupId').val(0);
  475. element.find('#hf_ItemDiscountGroupName').val('');
  476. element.find('.txt_addldiscount').prop('disabled', false);
  477. }
  478. });
  479. }
  480. GetMrpandBatchQty(id, element, BatchNo, batchid, row) {
  481. var mrpid;
  482. var name = "";
  483. var url = '';
  484. let Mrpid = id;
  485. if (Mrpid == -1)
  486. Mrpid = 0;
  487. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  488. url = 'apis/v4/bizgaze/transact/items/getitemmrpavailability/itemid/' + $("#hf_ItemId").val() + '/branchid/' + $(".txtAutoComplete_shiptoaddressid").val() + '/mrpid/' + Mrpid;
  489. }
  490. else {
  491. url = 'apis/v4/bizgaze/transact/items/getitemmrpavailability/itemid/' + $("#hf_ItemId").val() + '/branchid/' + $(".txtAutoComplete_shipfromaddressid").val() + '/mrpid/' + Mrpid;
  492. }
  493. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().GetMrpandBatchQty(url).then(function (response) {
  494. let AvailItemQuntity = 0;
  495. if (response.result != null && response.result != '') {
  496. AvailItemQuntity = response.result.Quantity;
  497. element.find(".spn_Avail").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(AvailItemQuntity), 2));
  498. if (Invoices.SplitItem.Instance().Type == "MRP") {
  499. element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Name').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(response.result.Mrp), 2) + ' (' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(AvailItemQuntity), 2) + ')');
  500. name = element.find('.hf_' + SplitItem.Instance().Type + '_Name').val();
  501. element.find(".select_" + SplitItem.Instance().Type + "").empty();
  502. element.find(".select_" + SplitItem.Instance().Type + "").append(new Option(name, id));
  503. element.find(".select_" + SplitItem.Instance().Type + "").val(id).trigger("change");
  504. element.find(".select_" + SplitItem.Instance().Type + "").val(id);
  505. element.find(".spn_Mrp").text(response.result.Mrp);
  506. element.find(".hf_MrpId").val(id);
  507. Invoices.SplitItem.Instance().Load(element);
  508. if (row != null) {
  509. if (row.addlDiscountPercent > 0)
  510. element.find("#txt_discount").val(row.addlDiscountPercent);
  511. else
  512. element.find("#txt_discount").val(row.addlDiscountValue);
  513. element.find(".Quantity").val(row.quantity);
  514. Invoices.SplitItem.Instance().update_row_total(element);
  515. }
  516. }
  517. else if (Invoices.SplitItem.Instance().Type == "BatchNo") {
  518. element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Name').val('Batch No: ' + BatchNo + ' (' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(AvailItemQuntity), 3) + ')');
  519. element.find(".hf_MrpId").val(id);
  520. element.find(".spn_Mrp").text(response.result.Mrp);
  521. name = element.find('.hf_' + SplitItem.Instance().Type + '_Name').val();
  522. element.find(".select_" + SplitItem.Instance().Type + "").empty();
  523. element.find(".select_" + SplitItem.Instance().Type + "").append(new Option(name, batchid, true));
  524. Invoices.SplitItem.Instance().Load(element);
  525. if (row != null) {
  526. ``;
  527. if (row.addlDiscountPercent > 0)
  528. element.find("#txt_discount").val(row.addlDiscountPercent);
  529. else
  530. element.find("#txt_discount").val(row.addlDiscountValue);
  531. element.find(".Quantity").val(row.quantity);
  532. Invoices.SplitItem.Instance().update_row_total(element);
  533. }
  534. }
  535. }
  536. });
  537. }
  538. RemoveRow(element) {
  539. element.find(".delete-row").on('click', function () {
  540. var _this = $(this);
  541. _this.parents('.SplInvoiceItemRow');
  542. var invoiceitemid = _this.parents('.SplInvoiceItemRow').find(".hf_selectedInvoiceItemId").val();
  543. if (invoiceitemid != 0) {
  544. if (confirm("You are about to Delete the invoice item. Are you sure?")) {
  545. var x = [];
  546. for (var i = 0; i < Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  547. if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId == _this.parents('.SplInvoiceItemRow').find('.hf_selectedInvoiceItemId').val()) {
  548. x.push(i);
  549. SplitItem.Instance().Delete_InvoiceItems.push(invoiceitemid);
  550. }
  551. }
  552. for (var i = x.length - 1; i >= 0; i--) {
  553. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  554. }
  555. SplitItem.Instance().updateQuantity();
  556. }
  557. }
  558. else if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false && (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 || (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid == 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid != 0)) && ($(".hdn_invoiceid").val() == "0") && element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val() != "0") {
  559. var x = [];
  560. for (var i = 0; i < SplitItem.Instance().DcItemIds.length; i++) {
  561. if (Number(SplitItem.Instance().DcItemIds[i]) == Number(element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val())) {
  562. x.push(i);
  563. }
  564. }
  565. for (var i = x.length - 1; i >= 0; i--) {
  566. SplitItem.Instance().DcItemIds.splice(x[i], 1);
  567. }
  568. _this.parents('.SplInvoiceItemRow').remove();
  569. SplitItem.Instance().updateQuantity();
  570. }
  571. else {
  572. _this.parents('.SplInvoiceItemRow').remove();
  573. SplitItem.Instance().updateQuantity();
  574. }
  575. });
  576. element.find('.btn_item_DiscType').change(function () {
  577. if (element.find(".btn_item_DiscType").val() == "%") {
  578. if (Number(element.find(".txt_addldiscount").val()) > 100)
  579. element.find(".txt_addldiscount").val("100");
  580. }
  581. if (element.find(".btn_item_DiscType option:selected").text().trim() == 'Val') {
  582. element.find('#hf_ItemDiscountGroupId').val(0);
  583. element.find('#hf_ItemDiscountGroupName').val('');
  584. element.find('.txt_addldiscount').prop('disabled', false);
  585. }
  586. else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%') {
  587. element.find('#hf_ItemDiscountGroupId').val(0);
  588. element.find('#hf_ItemDiscountGroupName').val('');
  589. element.find('.txt_addldiscount').prop('disabled', false);
  590. }
  591. });
  592. element.find(".Price,.exciseAmount,.txt_addldiscount").blur(function () {
  593. Invoices.SplitItem.Instance().update_price(element);
  594. });
  595. element.find(".btn_item_DiscType").change(function () {
  596. Invoices.SplitItem.Instance().update_price(element);
  597. });
  598. element.find(".Quantity").blur(function () {
  599. Invoices.SplitItem.Instance().CheckAvailableQuantity(element);
  600. });
  601. }
  602. CheckAvailableQuantity(elements) {
  603. var quantity = elements.find('.Quantity').val();
  604. var element = elements;
  605. if (element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val() == "0") {
  606. MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, 'bizgaze_CreateBatchErrorMessages');
  607. }
  608. if (($('.hdn_invoicetypeid').val() == '1' || $('.hdn_invoicetypeid').val() == '4' || $('.hdn_invoicetypeid').val() == '6') && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId != 1) {
  609. if (element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val() != '0') {
  610. if (Number(quantity) > Number(element.find('.spn_Avail').text())) {
  611. MessageHelper.Instance().showError("Check available quantity", 'bizgaze_CreateBatchErrorMessages');
  612. if (Number(element.find('.spn_Avail').text()) > 0)
  613. elements.find('.Quantity').val(element.find('.spn_Avail').text());
  614. else {
  615. elements.find('.Quantity').val();
  616. }
  617. }
  618. }
  619. }
  620. if ((Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 && element.find('.hf_dcItemId').val() != "0") || (element.find('.hf_orderItemId').val() == "0" && element.find('.hf_dcItemId').val() != "0" && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false)) {
  621. if (Number(quantity) > Number(element.find('.hf_maxQty').val())) {
  622. elements.find('.Quantity').val(Number(element.find('.hf_maxQty').val()));
  623. }
  624. }
  625. if (element.find('.hf_orderItemId').val() != 0) {
  626. var totalqty = 0;
  627. $('.SplInvoiceItemRow').each(function () {
  628. totalqty += Number($(this).find('.Quantity').val());
  629. });
  630. if (Number(Invoices.SplitItem.Instance().PendingQty) < totalqty) {
  631. var d = totalqty - Number(Invoices.SplitItem.Instance().PendingQty);
  632. elements.find('.Quantity').val(Number(quantity) - d);
  633. }
  634. }
  635. Invoices.SplitItem.Instance().update_row_total(element);
  636. }
  637. update_price(element) {
  638. Invoices.SplitItem.Instance().update_row_total(element);
  639. }
  640. update_row_total(element) {
  641. var row = element;
  642. var rowTotal = row.find('.Price').val() * (Number(row.find('.Quantity').val()));
  643. var rowTotalwithAdjustment = row.find('.Price').val() * (Number(row.find('.Quantity').val()));
  644. rowTotal += Number(row.find('.hf_RowTotalAdjustment').val());
  645. Number($(this).find('.txt_RowTotalwithAdjustment').val());
  646. rowTotalwithAdjustment += Number(row.find('.hf_RowTotalAdjustment').val());
  647. var exciseAmount = element.find(".exciseAmount").val();
  648. if (exciseAmount != undefined) {
  649. rowTotal += Number(exciseAmount);
  650. rowTotalwithAdjustment += Number(exciseAmount);
  651. }
  652. var asbAdjAmt = 0;
  653. asbAdjAmt = row.find('.hf_ItemAssesableAdjustmentVal').val();
  654. if (!isNaN(asbAdjAmt))
  655. rowTotalwithAdjustment += Number(asbAdjAmt);
  656. rowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotal, 2);
  657. let assesableAdjustment = Number(element.find('.hf_ItemAssesableAdjustmentVal').val());
  658. if (!isNaN(assesableAdjustment)) {
  659. assesableAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(assesableAdjustment, 2);
  660. }
  661. else {
  662. assesableAdjustment = 0;
  663. }
  664. rowTotalwithAdjustment += Number(assesableAdjustment);
  665. rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
  666. if (isNaN(rowTotal)) {
  667. element.find('.TotalPrice').html("N/A");
  668. element.find('.hf_RowTotal').val("0");
  669. element.find('.hf_RowTotalwithAdjustment').val("0");
  670. }
  671. else {
  672. element.find('.hf_RowTotal').val(rowTotal);
  673. element.find('.hf_RowTotalwithAdjustment').val(rowTotalwithAdjustment);
  674. element.find('.TotalPrice').html(rowTotal);
  675. }
  676. Invoices.SplitItem.Instance().update_Discount(element);
  677. Invoices.SplitItem.Instance().updateQuantity();
  678. }
  679. updateQuantity() {
  680. var TotalAmt = 0;
  681. var totalqty = 0;
  682. $(".SplInvoiceItemRow").each(function () {
  683. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7")
  684. TotalAmt += Number($(this).find('.txt_RowTotalwithAdjustment').val());
  685. else
  686. TotalAmt += Number($(this).find('.TotalPrice').text());
  687. if ($("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val() != "0" && $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val() != undefined) {
  688. totalqty += Number($(this).find('.Quantity').val());
  689. }
  690. });
  691. $('.hf_nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmt, 2));
  692. $(".hf_pendingQty").text(Number(Invoices.SplitItem.Instance().PendingQty) - totalqty);
  693. Controls.InvoiceItem.Instance().GetDiscounts();
  694. }
  695. update_Discount(element) {
  696. let totalLineAmount = element.find('.hf_RowTotal').val();
  697. if (!isNaN(totalLineAmount))
  698. var discountPercent = 0;
  699. var discountValue = 0;
  700. var quantity = Number(element.find(".Quantity").val());
  701. var unitPrice = Number(element.find(".Price").val());
  702. totalLineAmount = element.find('.Price').val().replace("$", "") * quantity;
  703. var exciseAmount = Number(element.find(".exciseAmount").val());
  704. if (isNaN(exciseAmount))
  705. exciseAmount = 0;
  706. var nonexciseAmount = totalLineAmount - exciseAmount;
  707. if (element.find(".btn_item_DiscType option:selected").text().trim() == 'Val' && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) {
  708. discountValue = Number(element.find('.txt_addldiscount').val());
  709. }
  710. else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%' && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) {
  711. discountPercent = Number(element.find('.txt_addldiscount').val());
  712. }
  713. var discountAmount = 0;
  714. discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
  715. + (Number(quantity) * Number(discountValue));
  716. discountAmount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discountAmount, 2));
  717. let discountedAmount = Number(totalLineAmount) - Number(discountAmount);
  718. element.find(".hf_DiscountedAmount").val(discountAmount);
  719. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  720. var assesableAdjustment = Number(element.find('.hf_ItemAssesableAdjustmentVal').val());
  721. element.find(".txt_RowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount + assesableAdjustment, 2));
  722. }
  723. else {
  724. element.find(".TotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2));
  725. element.find(".hf_RowTotal").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2));
  726. }
  727. }
  728. Load(element) {
  729. var Ids = [];
  730. var AutoText = element.find(".select_" + SplitItem.Instance().Type + "");
  731. var hdnAutoId = element.find(".hf_" + SplitItem.Instance().Type + "_Id");
  732. Ids = [0];
  733. $(".hf_" + SplitItem.Instance().Type + "_Id").each(function (index) {
  734. if ($(this).val() == element.find(".hf_" + SplitItem.Instance().Type + "_Id").val()) { }
  735. else
  736. Ids.push($(this).val());
  737. });
  738. var InvoiceType = 'Purchase';
  739. var dctypeid = 1;
  740. var BranchId = $(".txtAutoComplete_shiptoaddressid").val();
  741. if ($('.hdn_invoicetypeid').val() == '1' || $('.hdn_invoicetypeid').val() == '4' || $('.hdn_invoicetypeid').val() == '6') {
  742. InvoiceType = 'Sales';
  743. BranchId = $(".txtAutoComplete_shipfromaddressid").val();
  744. dctypeid = 2;
  745. }
  746. let url;
  747. if (SplitItem.Instance().Type == "MRP") {
  748. url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/pricelists/MrpsAutoComplete/itemid/' + $("#hf_ItemId").val() + '/mrpids/' + Ids.toString() + '/invoicetype/' + InvoiceType + '/dctype/' + dctypeid + '/branchid/' + BranchId + '/isinvoice/true';
  749. }
  750. else if (SplitItem.Instance().Type == "BatchNo") {
  751. url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/pricelists/BatchAutoComplete/itemid/' + $("#hf_ItemId").val() + '/ids/' + Ids.toString() + '/invoicetype/' + InvoiceType + '/dctype/' + dctypeid + '/branchid/' + BranchId + '/isinvoice/true';
  752. }
  753. else if (SplitItem.Instance().Type == "SerialNo") {
  754. url = _appsettings.server_url() + "/api/v3/MRPs/Item/" + $("#hf_ItemId").val() + "/SerialNos/" + Ids.toString() + "/InvoiceType/" + InvoiceType + "/DCtype/0/";
  755. }
  756. var AutoText = element.find(".select_" + SplitItem.Instance().Type);
  757. var hdnAutoId = element.find(".hf_" + SplitItem.Instance().Type + "_Id");
  758. AutoCompleteHelper.getHelper().Create(AutoText, hdnAutoId, url, function (result) {
  759. var ids = $(hdnAutoId).val();
  760. if (ids != '0' && result.id != 0 && result.addlData != undefined) {
  761. element.find(".Quantity").val("0");
  762. element.find("Price").val(element.find('.hf_UnitPrice').val());
  763. element.find("#txt_discount").val("0");
  764. Invoices.SplitItem.Instance().update_row_total(element);
  765. if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false && (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 || (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid == 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid != 0) && result.addlData != undefined) && ($(".hdn_invoiceid").val() == "0")) {
  766. SplitItem.Instance().DcItemIds.push(result.id);
  767. element.find(".hf_dcItemId").val(result.addlData.split(':')[1]);
  768. element.find(".hf_orderItemId").val(result.addlData.split(':')[2]);
  769. element.find(".Quantity").val(result.addlData.split(':')[3]);
  770. element.find(".spn_Avail").text(result.addlData.split(':')[0]);
  771. }
  772. else {
  773. element.find(".spn_Avail").text(result.addlData);
  774. }
  775. if (SplitItem.Instance().Type == "MRP") {
  776. if (result.id.search(":") != -1)
  777. element.find(".hf_MrpId").val(result.id);
  778. else
  779. element.find(".hf_MrpId").val(result.id);
  780. }
  781. else if (SplitItem.Instance().Type == 'BatchNo') {
  782. Bizgaze.Apps.Transact.Managers.PriceListManager.Instance().getbatch(result.id).then(function (result) {
  783. element.find(".hf_MrpId").val(result.result.MrpId);
  784. element.find(".spn_Mrp").text(result.result.Mrp);
  785. });
  786. }
  787. Ids = [0];
  788. $(".hf_" + SplitItem.Instance().Type + "_Id").each(function () {
  789. Ids.push($(this).val());
  790. });
  791. }
  792. });
  793. }
  794. SaveItem(elements) {
  795. this.fileCacheHelper.loadJsFile("libs/parsley/parsley.min.js", null);
  796. var qty = false;
  797. var avlqty = false;
  798. var UnitPrice = false;
  799. let appcontrolid = "frm_Bizgazetransact_Invoice_createInvoiceItem";
  800. let itemcount = 0;
  801. var MRPandBatch = false;
  802. $(".SplInvoiceItemRow").each(function () {
  803. itemcount += 1;
  804. if ($(this).find(".Quantity").val() == 0) {
  805. qty = true;
  806. }
  807. if ($(this).find(".Price ").val() == 0) {
  808. UnitPrice = true;
  809. }
  810. if (($(this).find(".select_" + Invoices.SplitItem.Instance().Type).text()) == "") {
  811. MRPandBatch = true;
  812. }
  813. });
  814. if (itemcount == 0) {
  815. MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, "bizgaze_CreateBatchErrorMessages");
  816. return false;
  817. }
  818. if (MRPandBatch) {
  819. MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, "bizgaze_CreateBatchErrorMessages");
  820. return false;
  821. }
  822. let result = Unibase.Platform.Forms.Components.FormViewer.Instance().requiredFieldValidation(appcontrolid);
  823. if (result == false) {
  824. MessageHelper.Instance().showError("Mandatory fields are missing", "bizgaze_CreateBatchErrorMessages");
  825. return false;
  826. }
  827. if ($('#hf_InventoryTypeId').val() == '1' || $('#hf_InventoryTypeId').val() == '4' || $('#hf_InventoryTypeId').val() == '5') {
  828. $(".SplInvoiceItemRow").each(function () {
  829. if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId != 1) {
  830. if (Number($(this).find(".Quantity").val()) > Number($(this).find('.spn_Avail').text())) {
  831. avlqty = true;
  832. }
  833. }
  834. });
  835. }
  836. if (qty) {
  837. MessageHelper.Instance().showError("Item quantity should not be zero.", "bizgaze_CreateBatchErrorMessages");
  838. return false;
  839. }
  840. if (UnitPrice) {
  841. MessageHelper.Instance().showError("Unit Price should not be zero.", "bizgaze_CreateBatchErrorMessages");
  842. return false;
  843. }
  844. if (avlqty) {
  845. MessageHelper.Instance().showError("Check available quantity", 'bizgaze_CreateBatchErrorMessages');
  846. return false;
  847. }
  848. var x = [];
  849. for (var i = 0; i < Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  850. if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == $("#hf_ItemId").val()) {
  851. x.push(i);
  852. }
  853. }
  854. for (var i = 0; i < SplitItem.Instance().Delete_InvoiceItems.length; i++) {
  855. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.push(i);
  856. }
  857. for (var i = x.length - 1; i >= 0; i--) {
  858. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  859. }
  860. var TotalQuantity = 0;
  861. var TotalAmount = 0;
  862. var TotalDisc = 0;
  863. var RowExist = false;
  864. $(".SplInvoiceItemRow").each(function () {
  865. var element = $(this);
  866. var BatchId = 0;
  867. var SerialNoId = 0;
  868. var MrpId = 0;
  869. var Name = '';
  870. if (Invoices.SplitItem.Instance().Type == "MRP") {
  871. MrpId = Number(element.find('.hf_MRP_Id').val());
  872. Name = element.find('.select_' + Invoices.SplitItem.Instance().Type + ' option[value=' + MrpId + ']').text();
  873. }
  874. else if (Invoices.SplitItem.Instance().Type == "BatchNo") {
  875. BatchId = Number(element.find('.select_' + Invoices.SplitItem.Instance().Type + '').val());
  876. MrpId = Number(element.find(".hf_MrpId").val());
  877. Name = element.find('.select_' + Invoices.SplitItem.Instance().Type + ' option[value =' + BatchId + ']').text();
  878. }
  879. else if (Invoices.SplitItem.Instance().Type == "SerialNo") {
  880. SerialNoId = Number(element.find('.select_' + Invoices.SplitItem.Instance().Type + '').val());
  881. MrpId = Number(element.find(".hf_MrpId").val());
  882. Name = element.find('.select_' + Invoices.SplitItem.Instance().Type + ' option[value=' + SerialNoId + ']').text();
  883. }
  884. if (element.find("#hf_" + Invoices.SplitItem.Instance().Type + "_Id").val() != '' && element.find("#hf_" + Invoices.SplitItem.Instance().Type + "_Id").val() != 0) {
  885. RowExist = true;
  886. var discountAmount = 0;
  887. var discountPercent = 0;
  888. if ((element.find(".btn_item_DiscType option:selected").text().trim() == 'Val' || element.find(".btnOrder_DiscType option:selected").text().trim() == 'Mul') && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) {
  889. discountAmount = Number(element.find('.txt_addldiscount').val());
  890. }
  891. else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%' && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) {
  892. discountPercent = Number(element.find('.txt_addldiscount').val());
  893. }
  894. var DiscType = element.find(".btn_item_DiscType option:selected").text().trim();
  895. var AccountId = elements.find(".hf_Account").val();
  896. var TaxGroupId = elements.find(".hfProdTax").val();
  897. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.push({
  898. invoiceItemId: element.find(".hf_selectedInvoiceItemId").val(),
  899. orderItemId: element.find(".hf_orderItemId").val(),
  900. itemId: element.find(".hf_selectedItemId").val(),
  901. taxGroupId: $("#ddl_TaxGroupId").val(),
  902. taxGroupName: $("#ddl_TaxGroupId option:selected").text(),
  903. description: element.find("#txt_Item_Description").val(),
  904. priceListId: element.find(".hf_PriceList").val(),
  905. unitPrice: element.find(".Price").val(),
  906. addlDiscountValue: discountAmount,
  907. addlDiscountPercent: discountPercent,
  908. IsTaxInclusive: $('#hfId_IsTaxInclusive').val(),
  909. accountId: $("#ddl_AccountId").val(),
  910. accountName: $("#ddl_AccountId option:selected").text(),
  911. Adjustment: element.find(".hf_RowTotalAdjustment").val(),
  912. TotalAmount: element.find(".hf_RowTotal").val(),
  913. quantity: element.find(".Quantity").val(),
  914. exciseAmount: element.find(".exciseAmount").val(),
  915. refNo: element.find(".hf_refNo").val(),
  916. DiscountGroupId: element.find("#hf_ItemDiscountGroupId").val(),
  917. RefInvoiceItemId: element.find(".hf_refInvoiceItemId").val(),
  918. MrpId: MrpId,
  919. dcItemId: element.find(".hf_dcItemId").val(),
  920. BatchId: BatchId,
  921. SerialId: SerialNoId,
  922. ExchangeItem: element.find('.hf_IsExchangeItem').val(),
  923. taxAdjustment: element.find('.hf_ItemTaxAdjsutmentVal').val(),
  924. assesableAdjustment: element.find('.hf_ItemAssesableAdjustmentVal').val(),
  925. DiscountGroupName: element.find('.hf_ItemDiscountGroupName').val(),
  926. DiscountedAmount: element.find(".hf_DiscountedAmount").val(),
  927. TaxPercent: $(".hf_ProdTaxPercent").val(),
  928. Name: Name,
  929. DiscType: DiscType,
  930. maxQty: element.find('.hf_maxQty').val()
  931. });
  932. TotalQuantity += Number(element.find(".Quantity").val());
  933. var discount = 0;
  934. var qyt = Number(element.find(".Quantity").val());
  935. var price = Number(element.find(".Price").val());
  936. var excamt = Number(element.find(".exciseAmount").val());
  937. var assesableAdjustment = Number(element.find('.hf_ItemAssesableAdjustmentVal').val());
  938. var ItemAdjustment = Number(element.find(".hf_RowTotalAdjustment").val());
  939. discount = (((qyt * price) + assesableAdjustment + ItemAdjustment - excamt) * Number(discountPercent) / 100) + (Number(qyt) * Number(discountAmount));
  940. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  941. TotalDisc += discount;
  942. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  943. TotalAmount += Number(element.find(".txt_RowTotalwithAdjustment").val());
  944. }
  945. else {
  946. TotalAmount += Number(element.find(".TotalPrice").text());
  947. }
  948. }
  949. });
  950. if (RowExist = true)
  951. elements.find('.spn_InvoiceItem').text("View " + Invoices.SplitItem.Instance().Type);
  952. else
  953. elements.find('.spn_InvoiceItem').text("Select " + Invoices.SplitItem.Instance().Type);
  954. elements.find('.prodQuantity').val();
  955. elements.find('.prodQuantity').val(TotalQuantity);
  956. elements.find('#inv_txtdiscount').val();
  957. elements.find('#inv_txtdiscount').val(TotalDisc);
  958. if (($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6") && $(".hdn_invoiceid").val() != "0") {
  959. elements.find(".txtRowTotalwithAdjustment").val();
  960. elements.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmount, 2));
  961. }
  962. else {
  963. elements.find('.prodTotalPrice').text('');
  964. elements.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmount, 2));
  965. }
  966. Invoices.SplitItem.Instance().navigationHelper.closePopUp();
  967. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0) {
  968. let OrderId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_orderid") == undefined ? 0 : Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_orderid").Value);
  969. if (OrderId == 0) {
  970. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().GetPlanItems(elements.find(".selectedItemId").val(), TotalQuantity, elements);
  971. }
  972. }
  973. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_total();
  974. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().TotalAdjustment();
  975. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_discount_total();
  976. }
  977. bindDetails(response, element) {
  978. var data = JSON.parse(response.result);
  979. if (SplitItem.instance.Type == "MRP") {
  980. element.find(".select_" + SplitItem.Instance().Type).empty();
  981. element.find(".select_" + SplitItem.Instance().Type).append(new Option(data.Mrp + '(0)', data.MrpId, true));
  982. element.find(".hf_" + SplitItem.Instance().Type + "_Id").val(data.MrpId);
  983. Invoices.SplitItem.Instance().GetMrpandBatchQty(data.MrpId, element, "", 0, null);
  984. }
  985. else if (SplitItem.instance.Type == "Batch") {
  986. element.find(".select_" + SplitItem.Instance().Type).empty();
  987. element.find(".select_" + SplitItem.Instance().Type).append(new Option(data.BatchNo + '(0)', data.BatchId, true));
  988. element.find(".hf_" + SplitItem.Instance().Type + "_Id").val(data.BatchId);
  989. }
  990. }
  991. refreshInvoiceTypes() {
  992. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  993. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().refreshInvoiceTypes().then(function (response) {
  994. MessageHelper.Instance().showSuccess(response.message, '');
  995. });
  996. });
  997. }
  998. static Instance() {
  999. if (this.instance === undefined) {
  1000. this.instance = new Invoices.SplitItem();
  1001. }
  1002. return this.instance;
  1003. }
  1004. }
  1005. SplitItem.element = "";
  1006. Invoices.SplitItem = SplitItem;
  1007. })(Invoices = Controls.Invoices || (Controls.Invoices = {}));
  1008. })(Controls = Transact.Controls || (Transact.Controls = {}));
  1009. })(Transact = Apps.Transact || (Apps.Transact = {}));
  1010. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  1011. })(Bizgaze || (Bizgaze = {}));