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.

manageprice.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. class ManagePrice extends Unibase.Platform.Core.BaseComponent {
  10. constructor() {
  11. super(...arguments);
  12. this.EstimateId = 0;
  13. this.EstimateTypeId = Bizgaze.Apps.Transact.Controls.Estimate.Instance().g_EstimateTypeId;
  14. this.containerid = "";
  15. }
  16. init() {
  17. var instance = this;
  18. instance.navigationHelper.popup(0, "", Bizgaze.Apps.Transact.Controls.ManagePrice.Instance(), null, Unibase.Platform.Helpers.Size.DockLeft);
  19. }
  20. jsFiles() {
  21. return ["apps/transact/managers/estimates/estimatemanager.js", "apps/transact/managers/orders/ordermanager.js", "apps/transact/enums/enum.js"];
  22. }
  23. cssFiles() {
  24. return [];
  25. }
  26. html(id, containerid) {
  27. let instance = this;
  28. instance.EstimateTypeId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_estimatetypeid").Value);
  29. let html;
  30. if (instance.EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesContract || instance.EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseContract) {
  31. html = '<header class="header bg-white"><strong class="text-dark Title">Manage Price</strong><div class="btn-group ml-auto"><a class="btn btn-sm"><i class="ti-help-alt" title = "help" href = "" target = "_blank"></i></a></div></header>' +
  32. '<div class="scrollable"><div id="estimateitem_errormessage"></div><div id = "divContainer" class="table table-responsive mt-10" style = "overflow-x:auto;width:auto"><div class="wrapper" ><div class="bg-white" ><table border="0" cellpadding = "0" cellspacing = "0" class="result-set" id = "estimateItems" style = "overflow-x:auto;width:100%;"><thead class="thead-light"><tr>' +
  33. '<th style="width:auto" > Item Name - SKU</th><th class="pl-40">Qty</th><th> Discount </th><th> Contract Price </th></tr></thead><tbody id = "tblbody"></tbody></table></div></div></div></div>' +
  34. '<footer class="bg-white modal-footer pa-10"><a href = "javascript:;" id = "btn_manageprice_Close" class="btn btn-light btn-sm mr-auto">Close</a><a href = "javascript:;" id ="btn_Manageprice_Save" class="btn btn-primary btn-sm pull-right btn">Save</a></footer>';
  35. }
  36. else {
  37. html = '<header class="header bg-white"><strong class="text-dark Title">Manage Price</strong><div class="btn-group ml-auto"><a class="btn btn-sm"><i class="ti-help-alt" title = "help" href = "" target = "_blank"></i></a></div></header>' +
  38. '<div class="scrollable"><div id="estimateitem_errormessage"></div><div id = "divContainer" class="table table-responsive mt-10" style = "overflow-x:auto;width:auto"><div class="wrapper" ><div class="bg-white" ><table border="0" cellpadding = "0" cellspacing = "0" class="result-set" id = "estimateItems" style = "overflow-x:auto;width:100%;"><thead class="thead-light"><tr>' +
  39. '<th style="width:auto" > Item Name - SKU</th><th class="pl-40">Qty</th><th> Discount </th><th> Exp Price </th><th> Quoted Price </th></tr></thead><tbody id = "tblbody"></tbody></table></div></div></div></div>' +
  40. '<footer class="bg-white modal-footer pa-10"><a href = "javascript:;" id = "btn_manageprice_Close" class="btn btn-light btn-sm mr-auto">Close</a><a href = "javascript:;" id ="btn_Manageprice_Save" class="btn btn-primary btn-sm pull-right btn">Save</a></footer>';
  41. }
  42. return html;
  43. }
  44. load(id, containerid, callback) {
  45. var instance = this;
  46. instance.containerid = containerid;
  47. instance.EstimateTypeId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_estimatetypeid").Value);
  48. $("#btn_manageprice_Close").click(function () {
  49. $('#' + containerid).modal('hide');
  50. $('#' + containerid).remove();
  51. });
  52. $("#btn_Manageprice_Save").click(function () {
  53. Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().save();
  54. });
  55. instance.getEstimateItems();
  56. }
  57. getEstimateItems() {
  58. var instance = this;
  59. instance.EstimateId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_estimateid").Value);
  60. Bizgaze.Apps.Transact.Managers.EstimateManager.Instance().getEstimateItems(instance.EstimateId).then(function (response) {
  61. var html = '';
  62. let TextBox;
  63. if (instance.EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesContract || instance.EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseContract) {
  64. TextBox;
  65. }
  66. else {
  67. TextBox = '<td data-label="ExpectedPrice" class="tbd" ><input type="text" class="form - control text - center editexpprice" style="width: 100px; height: 31px; " onkeypress="Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().isNumberKey(event)" id="expprice" value=';
  68. }
  69. for (var i = 0; i < response.result.length; i++) {
  70. var data = response.result[i];
  71. if (data.ExchangeDC)
  72. return false;
  73. var discount = data.DiscountValue;
  74. var valDiscType = 'selected';
  75. var perDiscType = '';
  76. if (data.DiscountPercent != 0) {
  77. discount = data.DiscountPercent;
  78. perDiscType = 'selected';
  79. valDiscType = '';
  80. }
  81. html = '<tr class="value-row bg-white Estimate-Item" id="estitem' + i + '" style="">' +
  82. '<td class="tbd" data-label="ItemName" style="text-align:left;width:28%" class="text-sm ItemName m-l-xs">' + data.ItemName + '-' + data.SKU +
  83. '<input type="hidden" id="hf_ItemId" value=' + data.ItemId + '>' +
  84. '<input type ="hidden" id ="hf_EstimateItemId" value =' + data.EstimateItemId + '>' +
  85. '<input type ="hidden" id ="hf_ItemTax" value =' + data.ItemTax + '>' +
  86. '<input type ="hidden" id ="hf_TaxTotal" value =' + data.TaxTotal + '>' +
  87. '<input type ="hidden" id ="hf_RowTotal" value =' + data.RowTotal + '></td>' +
  88. '<td data-label="Quantity" class="text-center" style="text-align:center; width:auto;height:26px;font-size:13px" ><input type="text" class="form-control text-center editQuantity" style="width:80px; height: 35px;" onkeypress="return Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().isNumberKey(event)" onchange="Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().RefreshValueSummary($(estitem' + i + '));" id="Quantity" value=' + data.Quantity + '><input type ="hidden" id ="hf_Quantity" value =' + data.Quantity + ' ></td>' +
  89. '<td style="text-align:center; width:auto;height:26px;font-size:13px">' +
  90. '<div class="input-group flex-nowrap">' +
  91. '<input type="text" id="Ord_txtdiscount" placeholder="Discount" style="width:55px; height:35px;" data-isdynamic="false" onchange="Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().RefreshValueSummary($(estitem' + i + '))";data-placeholder="0.00" data-label="Discount" class="form-control ord_txtaddldiscount floating-label-control" value="' + discount + '">' +
  92. '<input type="hidden" id="hfOrder_DiscountGroupId" value="0" />' +
  93. '<div class="input-group-btn">' +
  94. '<select class="btnOrder_DiscType form-control" style="width:70px; height:35px;" onchange="Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().RefreshValueSummary($(estitem' + i + '))"><option value="2" ' + valDiscType + '>Val</option><option value="1" ' + perDiscType + '>%</option></select>' +
  95. '</div>' +
  96. '</div>' +
  97. '</div></td>' +
  98. TextBox + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(data.ExpectedPrice, 2) + '><input type ="hidden" id ="hf_ExpectedPrice" value =' + data.ExpectedPrice + ' ></td>' +
  99. '<td data-label="UnitPrice" style="width:auto;font-size:13px;text-align:center;" class="tbd"><input type="text" class="form-control text-center editQuotedPrice" style="width:100px; height: 35px;"onchange="Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().RefreshValueSummary($(estitem' + i + '));" onkeypress="return Bizgaze.Apps.Transact.Controls.ManagePrice.Instance().isNumberKey(event)" id="QuotedPrice" value=' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(data.UnitPrice, 2) + '><input type ="hidden" id ="hf_UnitPrice" value =' + data.UnitPrice + ' ><span class="pull-right text-danger Uprice-error"></span></td></tr>';
  100. $("#tblbody").append(html);
  101. $("#Ord_txtdiscount").on("keyup", function () {
  102. if ($(".btnOrder_DiscType").val() == 1 && $("#Ord_txtdiscount").val() > 100) {
  103. instance.PercentAlert();
  104. }
  105. });
  106. }
  107. });
  108. }
  109. isNumberKey(evt) {
  110. if (evt.which != 8 && evt.which != 0 && (evt.which < 48 || evt.which > 57)) {
  111. return false;
  112. }
  113. return true;
  114. }
  115. RefreshValueSummary(element) {
  116. var instance = this;
  117. var disc = Number(element.find("#Ord_txtdiscount").val());
  118. var ItemId = Number(element.find("#hf_ItemId").val());
  119. var discType = Number(element.find(".btnOrder_DiscType").val());
  120. var Qty = Number(element.find(".editQuantity").val());
  121. var Unitprice = Number(element.find(".editQuotedPrice").val());
  122. var rowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Qty * Unitprice), 2);
  123. element.find("#hf_RowTotal").val(rowTotal);
  124. var aftrdiscamnt = rowTotal;
  125. if (disc > 0) {
  126. if (discType == 1) {
  127. var discperAmnt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(Unitprice * (disc / 100)), 2);
  128. Unitprice -= discperAmnt;
  129. aftrdiscamnt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Qty * Unitprice), 2);
  130. }
  131. else {
  132. Unitprice -= disc;
  133. aftrdiscamnt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Qty * Unitprice), 2);
  134. }
  135. }
  136. var estimateType = Bizgaze.Apps.Transact.Enums.OrderType[instance.EstimateTypeId];
  137. var billingAddressId = Unibase.Platform.Membership.Infos.Identity.getSetting("branchid");
  138. var BillToAddressId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_billingaddressid").Value);
  139. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getItemTaxDetails(ItemId, aftrdiscamnt, estimateType, billingAddressId, BillToAddressId, $('#chkCFormNoRequired').is(':checked'), false).then(function (response) {
  140. if (response.result != null) {
  141. element.find("#hf_TaxTotal").val(response.result.TaxAmount);
  142. }
  143. });
  144. }
  145. GetPriceDetails() {
  146. var instance = this;
  147. var ManagedPrices = new Array();
  148. $("#tblbody").find(".value-row").each(function () {
  149. var a = this;
  150. if ($('.Estimate-Item').find("#hf_EstimateItemId").val() != undefined) {
  151. var hf_ExpectedPrice = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(a).find("#hf_ExpectedPrice").val()), 2);
  152. var hf_UnitPrice = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#hf_UnitPrice").val()), 2);
  153. var QuotedPrice = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#QuotedPrice").val()), 2);
  154. var discval = 0.00;
  155. var discper = 0.00;
  156. if ($(this).find(".btnOrder_DiscType").val() == 1) {
  157. discval = 0;
  158. discper = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#Ord_txtdiscount").val()), 2);
  159. }
  160. else {
  161. discper = 0;
  162. discval = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#Ord_txtdiscount").val()), 2);
  163. }
  164. var expprice = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#expprice").val()), 2);
  165. var hf_Quantity = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#hf_Quantity").val()), 2);
  166. var Quantity = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#Quantity").val()), 2);
  167. var Taxamnt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($(this).find("#hf_TaxTotal").val()), 2);
  168. ManagedPrices.push({
  169. EstimateItemId: Number($(this).find("#hf_EstimateItemId").val()), ItemId: Number($(this).find("#hf_ItemId").val()),
  170. DiscountValue: Number(discval), DiscountPercent: Number(discper), ExpectedPrice: Number(expprice), UnitPrice: Number(QuotedPrice), Quantity: Number(Quantity), RowTotal: Number($(this).find("#hf_RowTotal").val()), TaxTotal: Number(Taxamnt)
  171. });
  172. }
  173. });
  174. return ManagedPrices;
  175. }
  176. Amounts() {
  177. var TotalAmount = 0.0;
  178. var TaxAmount = 0.0;
  179. var Amounts = new Array();
  180. $("#estimateItems").find(".Estimate-Item").each(function () {
  181. TotalAmount += Number($(this).find("#hf_RowTotal").val());
  182. TaxAmount += Number($(this).find("#hf_TaxTotal").val());
  183. });
  184. Amounts.push({ TotalAmount: TotalAmount, TaxAmount: TaxAmount });
  185. return Amounts;
  186. }
  187. save() {
  188. var instance = this;
  189. if ($(".btnOrder_DiscType").val() == 1 && $("#Ord_txtdiscount").val() > 100) {
  190. instance.PercentAlert();
  191. }
  192. else {
  193. var EstimateItems = instance.GetPriceDetails();
  194. if (instance.EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesContract || instance.EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseContract) {
  195. for (var i = 0; i < EstimateItems.length; i++) {
  196. EstimateItems[i].ExpectedPrice = 0;
  197. }
  198. ;
  199. }
  200. var Amounts = instance.Amounts();
  201. var TotalAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Amounts[0].TotalAmount, 2);
  202. var TaxAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Amounts[0].TaxAmount, 2);
  203. var postData = {
  204. EstimateId: instance.EstimateId,
  205. TotalAmount: Number(TotalAmount),
  206. TaxAmount: Number(TaxAmount),
  207. EstimateItems: EstimateItems,
  208. IsManagePrice: true,
  209. RefNo: "",
  210. };
  211. Bizgaze.Apps.Transact.Managers.EstimateManager.Instance().managePrice(postData).then(function (response) {
  212. let result = response.result;
  213. if (result != null) {
  214. $('#' + instance.containerid).modal('hide');
  215. $('#' + instance.containerid).remove();
  216. var detailInstance = Unibase.Themes.Compact.Components.Details.Instance();
  217. var panel = "#" + detailInstance._containerId;
  218. var obj = Unibase.Themes.Compact.Components.Details.Instance();
  219. obj._recordId = Unibase.Themes.Providers.DetailHelper.recordId;
  220. obj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  221. detailInstance.loadAppDefaultWidget(obj, panel, detailInstance._containerId, function () {
  222. detailInstance.loadDefaultWidgets(obj._installedAppId, panel);
  223. detailInstance.LoadApprovals(obj._recordId, obj._installedAppId);
  224. });
  225. MessageHelper.Instance().showSuccess(response.message, '');
  226. }
  227. else {
  228. MessageHelper.Instance().showError(response.message, 'estimateitem_errormessage');
  229. }
  230. });
  231. }
  232. }
  233. PercentAlert() {
  234. bootbox.alert("Discount percentage must be less then 100");
  235. }
  236. static Instance() {
  237. if (this.instance === undefined) {
  238. this.instance = new ManagePrice();
  239. }
  240. return this.instance;
  241. }
  242. }
  243. Controls.ManagePrice = ManagePrice;
  244. })(Controls = Transact.Controls || (Transact.Controls = {}));
  245. })(Transact = Apps.Transact || (Apps.Transact = {}));
  246. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  247. })(Bizgaze || (Bizgaze = {}));