Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. (function() {
  2.  
  3. 'use strict';
  4.  
  5. angular.module("purchaseOrderModule")
  6. .controller("LookupProductPurchaseOrderController", LookupProductPurchaseOrderController);
  7.  
  8. LookupProductPurchaseOrderController.$inject = ['$uibModalInstance', 'items','$scope' ,'RestService', 'PurchasingApiConstant', '$filter', 'LeafCommonConstant'];
  9.  
  10. function LookupProductPurchaseOrderController($uibModalInstance, items, $scope, RestService, PurchasingApiConstant, $filter, LeafCommonConstant) {
  11. var ctrl = $scope;
  12.  
  13. ctrl.checkAll = checkAll;
  14. ctrl.doSearch = doSearch;
  15. ctrl.pageChanged = pageChanged;
  16. ctrl.doAddProduct = doAddProduct;
  17. ctrl.close = close;
  18.  
  19. ctrl.errors = [];
  20. ctrl.productList = [];
  21. ctrl.totalItems = 0;
  22. ctrl.currentPage = 1;
  23. ctrl.limit = 5;
  24.  
  25. ctrl.input = {
  26. "keyword": "",
  27. "ctgrProductId": null,
  28. "subCtgrProductId": null,
  29. "brand": "",
  30. "limit": ctrl.limit,
  31. "currentPage": ctrl.currentPage,
  32. "checked": false,
  33. "productSelected": []
  34. };
  35.  
  36. doSearch();
  37.  
  38. function pageChanged(){
  39. ctrl.input.offset = (ctrl.input.currentPage-1)*ctrl.input.limit;
  40. doSearch();
  41. }
  42.  
  43. function doSearch() {
  44. var input = angular.copy(ctrl.input);
  45.  
  46. input.ctgrProductId = (input.ctgrProductId != null)? input.ctgrProductId : -99;
  47. input.subCtgrProductId = (input.subCtgrProductId != null)? input.subCtgrProductId : -99;
  48.  
  49. RestService.call(PurchasingApiConstant.COUNT_GET_PRODUCT_LIST_FOR_PURCHASE_ORDER, input)
  50. .then(function (result) {
  51. input.offset = (ctrl.input.currentPage-1)*input.limit;
  52. ctrl.totalItems = result.result.count;
  53. ctrl.totalPages = Math.ceil(ctrl.totalItems / input.limit);
  54. getProductListForPurchaseOrder(input);
  55. })
  56.  
  57. }
  58.  
  59. function getProductListForPurchaseOrder(input) {
  60. RestService.call(PurchasingApiConstant.GET_PRODUCT_LIST_FOR_PURCHASE_ORDER, input)
  61. .then(function (response) {
  62. var result = response.result;
  63. if(result.status == "OK") {
  64. ctrl.productList = result.productList;
  65. } else {
  66. onTop();
  67. ctrl.errors = result;
  68. }
  69.  
  70. })
  71. }
  72.  
  73. function checkAll() {
  74. var condition = !ctrl.input.checked;
  75.  
  76. if(condition){
  77. if(ctrl.input.productSelected.length == 0) {
  78. ctrl.input.productSelected = angular.copy(ctrl.productList);
  79. } else {
  80. if(ctrl.input.productSelected.length >= 0 && condition) {
  81. ctrl.input.productSelected = angular.copy(ctrl.productList);
  82. } else {
  83. ctrl.input.productSelected = [];
  84. }
  85. }
  86. } else {
  87. ctrl.input.productSelected = [];
  88. }
  89.  
  90. }
  91.  
  92. function doAddProduct() {
  93.  
  94. try {
  95.  
  96. if(items.id == -99) {
  97.  
  98. var arrayData = [];
  99.  
  100. _.forEach(ctrl.input.productSelected, function(value, key) {
  101. value.qty = 1;
  102. value.unitPrice = value.lastPrice;
  103. value.itemAmountGross = value.lastPrice*value.qty;
  104. arrayData.push(value)
  105. });
  106.  
  107. $uibModalInstance.close(arrayData);
  108.  
  109. }
  110.  
  111. } catch (e) {
  112.  
  113. }
  114.  
  115. }
  116.  
  117. function close() {
  118. $uibModalInstance.dismiss();
  119. }
  120.  
  121. }
  122.  
  123. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement