OutFinishOprCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. define([ 'app/app','service/Purc','service/SupportServices' ], function(app) {
  2. app.register.controller('OutFinishOprCtrl',['$scope', '$http', '$rootScope', '$location', '$filter','$stateParams','$modal','toaster', 'SupportUtil','OutOper','Ring', 'Online','ngTableParams','$q','PurcOrderItem', function($scope, $http, $rootScope,$location,$filter,$stateParams,$modal,toaster ,SupportUtil,OutOper, Ring,Online,ngTableParams,$q,PurcOrderItem){
  3. $scope.grid = $rootScope.outFingrid||[];
  4. $scope.getOnline = Online.getOnline;
  5. setTimeout( function(){
  6. try{
  7. document.getElementById("bi_barcode").focus();
  8. } catch(e){}
  9. }, 200);
  10. var getOrder = function(code) {//根据路径中的id号获取对应的单据
  11. var result = null;
  12. angular.forEach($rootScope.outFinOrders, function(value, key){
  13. if(value.PI_INOUTNO == code) {
  14. result = value;
  15. return result;
  16. }
  17. });
  18. return result;
  19. };
  20. $scope.changeSelection = function(item) {//table with row selection,表格选中列操作
  21. $scope.ordercode = item.PD_ORDERCODE;
  22. $scope.bi_prodcode = item.PD_PRODCODE;
  23. $scope.bi_prodid = item.PR_ID;
  24. //$scope.bi_outqty = item.PR_ZXBZS;
  25. $scope.pr_fbzs = item.PD_OUTQTY;
  26. $scope.detno = item.PD_PDNO;
  27. $scope.bi_prodname = item.PR_DETAIL;
  28. $scope.pr_detail = item.PR_DETAIL+item.PR_SPEC;
  29. $scope.pd_id = item.PD_ID;
  30. $scope.pr_id = item.PR_ID;
  31. $scope.batchcode = item.PD_BATCHCODE;
  32. }
  33. $scope.order = getOrder($stateParams.code);
  34. $rootScope.title = {};
  35. $rootScope.title.pi_inoutno =$scope.order.PI_INOUTNO +' '+$scope.order.PI_WHCODE;
  36. if($scope.order){
  37. var keepGoing = true;
  38. angular.forEach($scope.order.product, function(value, key){
  39. if( keepGoing ){
  40. if(value.PD_OUTQTY == 0 && $scope.order.product[key+1].PD_OUTQTY != 0){
  41. $scope.changeSelection($scope.order.product[key+1]);
  42. keepGoing = false ;
  43. }else {
  44. $scope.changeSelection($scope.order.product[key]);
  45. keepGoing = false;
  46. }
  47. }
  48. });
  49. $scope.tableParams = new ngTableParams({//未完成料号名称规格及剩余数量表格
  50. page: 1,
  51. count: 10,
  52. filter: {
  53. },
  54. sorting: {
  55. }
  56. }, {
  57. total: $scope.order.product.length,
  58. getData: function ($defer, params) {
  59. var filteredData = params.filter() ?
  60. $filter('filter')($scope.order.product, params.filter()) :
  61. data;
  62. var orderedData = params.sorting() ?
  63. $filter('orderBy')(filteredData, params.orderBy()) :
  64. data;
  65. params.total(orderedData.length); // set total for recalc pagination
  66. $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
  67. }
  68. });
  69. }
  70. var checkMakeSerial = function(defer){
  71. //如果有设定的归属工单,必须序列号归属于选定的工单,或者订单(关联MakeSerial表判断)
  72. PurcOrderItem.checkMakeSerial({ms_sncode:$scope.bi_barcode,makeCode:$scope.makeCode,saleCode:$scope.saleCode,whcode:$scope.order.PI_WHCODE}, {},function(data){
  73. if(data.exceptionInfo){
  74. defer.reject(data.exceptionInfo);
  75. }else{
  76. document.getElementById("makeCode").focus();
  77. defer.resolve(data.message);
  78. }
  79. },function(response){
  80. defer.reject(response.data.exceptionInfo);
  81. });
  82. };
  83. var checkOutbox = function(defer){
  84. //包装箱号 内所有序列号的bar_remain值为1,代表没有出库 。箱内总数不需要输入
  85. OutOper.checkOutbox({barcode:$scope.bi_outboxcode,prodcode:$scope.bi_prodcode,whcode:$scope.order.PI_WHCODE}, {},function(data){
  86. if(data.exceptionInfo){
  87. defer.reject(data.exceptionInfo);
  88. }else{
  89. $scope.bi_outqty = data.message;
  90. document.getElementById("bi_outboxcode").focus();
  91. defer.resolve(data.message);
  92. }
  93. },function(response){
  94. defer.reject(response.data.exceptionInfo);
  95. });
  96. };
  97. var checkSerialqty = function(defer){
  98. //输入的是序列号的话,bar_remain 为1,剩余数减一;深圳华商龙:判断该序列号是否对应出货单明细行中的批号
  99. OutOper.checkSerialqty({pr_fbzs:$scope.pr_fbzs,barcode:$scope.bi_barcode,whcode:$scope.order.PI_WHCODE,prodcode:$scope.bi_prodcode,batchcode:$scope.batchcode},{},function(data){
  100. if(data.exceptionInfo){
  101. defer.reject(data.exceptionInfo);
  102. }else{
  103. $scope.bi_outqty = 1;
  104. defer.resolve(data.message);
  105. }
  106. },function(response){
  107. defer.reject(response.data.exceptionInfo);
  108. });
  109. }
  110. //进入界面,表单值默认为grid中的第一行
  111. var check = function (productCode){
  112. //校验:1、物料编号存在, 2、数量不超过剩余数量,3、条码号唯一性
  113. //条码储位不允许为空
  114. var defer = $q.defer();
  115. var reg = /^[0-9]*[1-9][0-9]*$/; 
  116. if(!$scope.bi_barcode && !$scope.bi_outboxcode){
  117. defer.reject("请输入序列号或者包装箱号!");
  118. document.getElementById("bi_barcode").focus();
  119. }else {
  120. var item = SupportUtil.contains(JSON.stringify($scope.order.product),productCode,"PD_PRODCODE");
  121. if(item){
  122. /*//是否条码校验
  123. if($scope.ifbarcodecheck == '1'){
  124. var pr_idlen =$scope.order.barcodeset.BS_LENPRID;
  125. //比较物料ID的前几位是否等于条码号的前几位
  126. var pr_id = new String($scope.pr_id);
  127. var bar_code = new String($scope.bi_barcode);
  128. if (SupportUtil.lap(pr_id,pr_idlen) != SupportUtil.lap(bar_code,pr_idlen)){
  129. Ring.error();
  130. $scope.bi_barcode ='';
  131. defer.reject("条码校验错误,该条码与物料不匹配")
  132. }
  133. }*/
  134. if($rootScope.outFingrid && SupportUtil.contains(JSON.stringify($rootScope.outFingrid) ,$scope.bi_barcode,"bi_barcode")){
  135. document.getElementById("bi_barcode").focus();
  136. defer.reject("序列号重复");
  137. }else if($scope.bi_barcode && ($scope.makeCode || $scope.saleCode)){
  138. checkMakeSerial(defer);
  139. checkSerialqty(defer);
  140. }else if($scope.bi_barcode){
  141. checkSerialqty(defer);
  142. }else{
  143. checkOutbox(defer);
  144. }
  145. }else {
  146. defer.reject("物料不存在");
  147. Ring.error();
  148. }
  149. }
  150. return defer.promise;
  151. }
  152. $scope.scan = function(){//确认按钮事件
  153. var q = check($scope.bi_prodcode);
  154. q.then(function(message){
  155. $scope.barcodes = {};
  156. $scope.barcodes.bi_barcode = $scope.bi_barcode;
  157. $scope.barcodes.bi_prodcode = $scope.bi_prodcode ;
  158. $scope.barcodes.bi_prodid = $scope.bi_prodid ;
  159. $scope.barcodes.bi_inoutno = $scope.order.PI_INOUTNO;
  160. $scope.barcodes.bi_outqty = $scope.bi_outqty;
  161. $scope.barcodes.bi_whcode = $scope.order.PI_WHCODE;
  162. $scope.barcodes.bi_prodname = $scope.bi_prodname;
  163. $scope.barcodes.bi_pdno = $scope.detno;
  164. $scope.barcodes.bi_pdid = $scope.pd_id;
  165. $scope.barcodes.bi_piid = $scope.order.PI_ID;
  166. $scope.barcodes.bi_outboxcode = $scope.bi_outboxcode;
  167. //插入数据到待提交缓存列表中grid(barcode,prodcode,inqty,location)
  168. $scope.grid.push($scope.barcodes);
  169. $rootScope.outFingrid = $scope.grid;
  170. $scope.pr_fbzs -= $scope.barcodes.bi_outqty;
  171. $scope.bi_barcode ='';
  172. angular.forEach($scope.order.product, function(value, key){
  173. if(value.PD_ID == $scope.pd_id) {
  174. value.PD_OUTQTY = $scope.pr_fbzs ;
  175. $scope.tableParams.reload();
  176. if(value.PD_OUTQTY == 0 && $scope.order.product[key+1] ){
  177. $scope.changeSelection($scope.order.product[key+1]);
  178. }
  179. }
  180. });
  181. var keepGoing = true;
  182. angular.forEach($scope.order.product, function(value, key){
  183. if(keepGoing){
  184. if(value.PD_OUTQTY != 0 ){
  185. keepGoing = false ;
  186. }
  187. }
  188. });
  189. if(keepGoing){
  190. if(confirm("已完成,请提交采集")){
  191. $location.path('outFinWaitSubmit/' + $scope.order.PI_INOUTNO);
  192. }
  193. }
  194. }, function(error){
  195. toaster.pop('error', '错误',error);
  196. });
  197. };
  198. $scope.enter = function (event){
  199. SupportUtil.nextFocus(event);
  200. };
  201. /* $scope.search = function($event, productCode){
  202. if($event.keyCode == 13) {//Enter事件 、回车事件
  203. //完成“确认”前判断,判断通过则自动执行“确认”
  204. console.log('scan');
  205. $scope.scan();
  206. }
  207. };*/
  208. $scope.submitGet = function(){//提交采集操作,与后台交互
  209. if($scope.grid.length == 0){
  210. toaster.pop('error', '没有需要提交的数据');
  211. return;
  212. }
  213. OutOper.saveOutBarcode({}, JSON.stringify($scope.grid),function(data) {//获取成功
  214. if(data.exceptionInfo){
  215. toaster.pop('error', '查询失败',data.exceptionInfo);
  216. Ring.error();
  217. }else{
  218. toaster.pop('success', '提交成功');
  219. $rootScope.outFingrid = $scope.grid ='';
  220. }
  221. }, function(response){//获取失败处理
  222. if(response.status == 0){ //无网络错误
  223. Online.setOnline(false);//修改网络状态
  224. toaster.pop('error', '提交失败',"网络连接不可用,请稍后再试");
  225. }
  226. else {
  227. toaster.pop('error', '提交失败',response.data.exceptionInfo);
  228. }
  229. });
  230. };
  231. $scope.getList = function(argOrder){//点击
  232. if(argOrder){
  233. $location.path('outFinWaitSubmit/' + argOrder);
  234. }
  235. };
  236. $scope.returnInput = function(){//当前单据有未提交的,提示先提交。
  237. if($scope.grid.length != 0){
  238. if(confirm("返回将清空未提交数据,确认返回?")){
  239. angular.forEach($scope.order.product, function(value, key){
  240. for (var gs in $scope.grid){
  241. if (value.PD_ID == $scope.grid[gs].bi_pdid) {
  242. value.PD_OUTQTY = eval($scope.grid[gs].bi_outqty+"+"+value.PD_OUTQTY);
  243. }
  244. }
  245. });
  246. $rootScope.outMMgrid = $scope.grid ='';
  247. $location.path('outFinish');
  248. }
  249. }else{
  250. var status = '101';
  251. angular.forEach($scope.order.product, function(value, key){
  252. if(value.PD_OUTQTY !=0) {
  253. status = '102'
  254. }
  255. });
  256. if(status == '101'){//修改采集状态
  257. $scope.order.ENAUDITSTATUS='101';
  258. }
  259. $location.path('outFinish');
  260. }
  261. }
  262. $scope.findProdcode = function (){
  263. var modalInstance = $modal.open({
  264. templateUrl: 'prodModalContent.html',
  265. controller: 'ProdModalInstanceCtrl',
  266. resolve: {
  267. items: function () {
  268. return $scope.order.product;
  269. }
  270. }
  271. });
  272. modalInstance.result.then(function(selectedItem) {
  273. $scope.changeSelection(selectedItem);
  274. });
  275. }
  276. }])
  277. });