Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1. (function() {
  2.  
  3. 'use strict';
  4.  
  5. angular.module("receiveGoodsModule")
  6. .controller("InputReceiveGoodsController", InputReceiveGoodsController);
  7.  
  8. InputReceiveGoodsController.$inject = ['$scope' ,'RestService', '$filter', '$state', 'NotificationService', 'ReceiveGoodsApiConstant','LeafCommonConstant','SupplierApiConstant','$uibModal'];
  9.  
  10. function InputReceiveGoodsController($scope, RestService, $filter, $state, NotificationService, ReceiveGoodsApiConstant, LeafCommonConstant, SupplierApiConstant, $uibModal) {
  11. onTop();
  12. document.title = $state.params.title;
  13. var ctrl = $scope;
  14.  
  15. ctrl.doAction = doAction;
  16. ctrl.submitReceiveGoods = submitReceiveGoods;
  17.  
  18. var id = getParams("detailReceiveGoods");
  19. ctrl.summary = {};
  20. ctrl.receiveGoodsItemList = [];
  21. ctrl.errors = [];
  22. ctrl.readOnly = false;
  23. ctrl.disabled = false;
  24.  
  25. var date = new Date();
  26.  
  27. if(id == -99)
  28. {
  29. ctrl.input = {
  30. "refId": -99,
  31. "refDocTypeId": -99,
  32. "docDate": date,
  33. "extDocNo" : "",
  34. "extDc": "",
  35. "remark": "",
  36. "supplierId": "",
  37. "dateConfirm" : ""
  38. }
  39. }
  40. else{
  41. ctrl.input = {};
  42. findReceiveGoodsById();
  43. }
  44.  
  45. doReset();
  46. getSupplierList();
  47.  
  48.  
  49. function doReset()
  50. {
  51. ctrl.errors = [];
  52. }
  53.  
  54. function getSupplierList() {
  55. var input = {};
  56.  
  57. RestService.call(SupplierApiConstant.GET_SUPPLIER_LIST, input)
  58. .then(function (response) {
  59. var result = response.result;
  60. if(result.status == "OK") {
  61. ctrl.supplierList = result.supplierList;
  62. } else {
  63. onTop();
  64. NotificationService.errorData();
  65. ctrl.errors = result;
  66. }
  67. })
  68.  
  69. }
  70.  
  71. function findReceiveGoodsById(){
  72. RestService.call(ReceiveGoodsApiConstant.FIND_RECEIVE_GOODS_BY_ID,{"id" : id})
  73. .then(function (response){
  74. var result = response.result;
  75.  
  76. console.log(" findReceiveGoodsById");
  77. console.log(result);
  78.  
  79. if(result.status == 'OK')
  80. {
  81. ctrl.input = result;
  82. ctrl.input.DocDate = $filter("converterDate")(ctrl.input.docDate);
  83. ctrl.input.extDocDate = $filter("converterDate")(ctrl.input.extDocDate);
  84.  
  85. if(ctrl.input.statusDoc = 'D')
  86. {
  87. ctrl.disabled = true;
  88. ctrl.readOnly = true;
  89. }
  90.  
  91.  
  92. getReceiveGoodsItemList();
  93. findSummaryReceiveGoodsById();
  94.  
  95. }
  96. else
  97. {
  98. onTop();
  99. NotificationService.errorData();
  100. ctrl.errors = result;
  101. }
  102. })
  103. }
  104.  
  105. function getReceiveGoodsItemList(){
  106. RestService.call(ReceiveGoodsApiConstant.GET_RECEIVE_GOODS_ITEM_LIST, {"receiveGoodsId" : id})
  107. .then(function(response) {
  108. var result = response.result;
  109.  
  110. console.log(" getReceiveGoodsItemList ");
  111. console.log(result);
  112.  
  113. if(result.satus == "OK")
  114. {
  115. ctrl.receiveGoodsItemList = result.receiveGoodsItemList;
  116. }
  117. else
  118. {
  119. onTop();
  120. NotificationService.errorData();
  121. ctrl.errors = result;
  122. }
  123. })
  124. }
  125.  
  126. function findSummaryReceiveGoodsById() {
  127. RestService.call(ReceiveGoodsApiConstant.FIND_SUMMARY_RECEIVE_GOODS_BY_ID, {"receiveGoodsId" : id})
  128. .then(function(response){
  129. var result = response.result;
  130.  
  131. if(result.status == "OK"){
  132. ctrl.summary = result;
  133. }
  134. else{
  135. onTop();
  136. NotificationService.errorData();
  137. ctrl.errors = result
  138. }
  139. })
  140. }
  141.  
  142. function doAction(){
  143. doReset();
  144. doPrepareEditDocument();
  145. }
  146.  
  147. function doPrepareEditDocument(){
  148. var input = angular.copy(ctrl.input);
  149. input.extDocDate = $filter("converterDateString")(ctrl.input.extDocDate);
  150.  
  151. RestService.call(ReceiveGoodsApiConstant.EDIT_RECEIVE_GOODS, input)
  152. .then(function(response){
  153. var result = response.result;
  154. if(result.status == "OK")
  155. {
  156. NotificationService.editData();
  157. findReceiveGoodsById();
  158. }
  159. else
  160. {
  161. NotificationService.errorData();
  162. ctrl.errors = result
  163. }
  164. })
  165. }
  166.  
  167. function submitReceiveGoods(){
  168. onTop();
  169.  
  170. var input = {
  171. "receiveGoodsId" : id,
  172. "version" : ctrl.input.version,
  173. "statusDoc" : "R",
  174. "dateConfirm" : $filter("converterDateString")(ctrl.input.dateConfirm)
  175. };
  176.  
  177. altertify.confirm('Apakah anda yakin submit dokumen'+ctrl.input.docNo+'?', function(){
  178. RestService.call(ReceiveGoodsApiConstant.SUBMIT_PURCHASE_ORDER, input)
  179. .then(function(){
  180. var result = response.result;
  181. if(result.response == "OK"){
  182. NotificationService.submitData();
  183. findReceiveGoodsById();
  184. }
  185. else{
  186. onTop();
  187. NotificationService.errorData();
  188. ctrl.errors = result;
  189. }
  190. })
  191. });
  192. }
  193. }
  194. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement