EnsureCheckMoneyCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. define([ 'app/app' ], function(app) {
  2. app.register.controller('EnsureCheckMoneyCtrl', ['$scope', '$anchorScroll', '$location', '$http','$filter' , 'ngTableParams', 'BaseService', '$stateParams','$state' ,'Receipt','DateParse' , '$modal' , 'bankInfoService', 'bankTransferService' , 'toaster' ,function($scope , $anchorScroll, $location, $http, $filter ,ngTableParams, BaseService, $stateParams, $state , Receipt, DateParse, $modal,bankInfoService , bankTransferService , toaster) {
  3. $scope.dateZoneText = '不限';
  4. $scope.condition = {dateZone: -1};
  5. if($stateParams.uu) {
  6. //控制变量
  7. $scope.kind = true;
  8. $scope.startDateError = false;
  9. $scope.endDateError = false;
  10. var hideBankFilter = $filter("hideBankFilter");
  11. $scope.active = 'available';
  12. /*
  13. * 待结算 (notsettled) 显示还有出入库单未结算的企业 ,
  14. * 已结算 (settled)显示还有出入库单已结算的企业 ,
  15. */
  16. var getState = function() {
  17. var state = 516;
  18. switch($scope.active) {
  19. case 'available' :
  20. state = 516; break;
  21. case 'unavailable' :
  22. state = 517; break;
  23. case 'availableToBeMakeBill':
  24. state = 518; break;
  25. }
  26. return state;
  27. };
  28. $scope.setActive = function(state) {
  29. if($scope.active != state) {
  30. $scope.active = state;
  31. }
  32. if($scope.receiptTableParams.page() == 1)
  33. $scope.receiptTableParams.reload();
  34. else
  35. $scope.receiptTableParams.page(1);
  36. };
  37. //控制单号换行
  38. $scope.getIndex = function($index) {
  39. if($index > 3) {
  40. var boo = $index + 1;
  41. if(boo%5 == 0) {
  42. return true;
  43. }
  44. }
  45. return false;
  46. }
  47. // 改变单据日期范围
  48. $scope.changeDateZone = function(zone) {
  49. $scope.condition.dateZone = zone;
  50. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  51. $scope.condition.$dateZoneOpen = false;
  52. getDateCondition(zone, $scope.condition);
  53. $scope.receiptTableParams.reload();
  54. };
  55. // 打开日期选择框
  56. $scope.openDatePicker = function($event, item, openParam) {
  57. $event.preventDefault();
  58. $event.stopPropagation();
  59. item[openParam] = !item[openParam];
  60. };
  61. // 选择查找日期
  62. $scope.onDateCondition = function(){
  63. $scope.receiptTableParams.page(1);
  64. $scope.receiptTableParams.reload();
  65. };
  66. $scope.receiptTableParams = new ngTableParams({
  67. page : 1,
  68. count : 5,
  69. sorting : {
  70. createtime: 'DESC'
  71. }
  72. }, {
  73. total : 0,
  74. counts: [5, 10, 25, 50, 100],
  75. getData : function($defer, params) {
  76. var param = BaseService.parseParams(params.url());
  77. param.keyword = $scope.keyword;
  78. //日期筛选
  79. param.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  80. param.toDate = $scope.condition.dateTo ? $scope.condition.dateTo.setDate($scope.condition.dateTo.getDate()+1) : null;// datepicker默认选中时间为当天0:00,所以选中截至时间+1天
  81. param.enuu = $stateParams.uu
  82. param.available = getState();
  83. param.status = 514;
  84. Receipt.getReceiptByuu(param, function(page) {
  85. if (page) {
  86. params.total(page.totalElements);
  87. $defer.resolve(page.content);
  88. clearData();
  89. //那就只修改这个备份的数据,原数据不做改变
  90. $scope.localRecepit = angular.copy(page.content);
  91. $scope.count = 0;//代表当前选中的行数 用在button
  92. var orderCount = page.content.length;
  93. while($scope.checkCodes.length < orderCount) {
  94. $scope.checkCodes.push(false);
  95. }
  96. }
  97. });
  98. }
  99. });
  100. //重新勾选
  101. $scope.cancelCheck = function() {
  102. $scope.batchCheckStatus = false;
  103. delete $scope.noticeInfo;
  104. }
  105. //根据采购单号搜索采购单
  106. $scope.onSearch = function() {
  107. if($scope.startDate){
  108. if(DateParse.match($scope.startDate) == false){
  109. $scope.startDateError = true;
  110. } else {
  111. $scope.startDateError = false;
  112. $scope.condition.dateFrom = new Date($scope.startDate);
  113. }
  114. } else {
  115. $scope.startDateError = false;
  116. }
  117. //暂时没有截止日期
  118. // if($scope.endDate){
  119. // if(DateParse.match($scope.endDate) == false){
  120. // $scope.endDateError = true;
  121. // } else {
  122. // $scope.endDateError = false;
  123. // $scope.condition.dateTo = new Date($scope.endDate);
  124. // }
  125. // } else {
  126. // $scope.endDateError = false;
  127. // }
  128. if(!$scope.startDateError) {
  129. $scope.receiptTableParams.reload();
  130. $scope.receiptTableParams.page(1);
  131. }
  132. }
  133. //清数据
  134. var clearData = function (){
  135. delete $scope.startDateError;
  136. delete $scope.endDateError;
  137. delete $scope.noticeInfo;
  138. delete $scope.batchCheckStatus;
  139. $scope.checks = {
  140. checked : false
  141. };
  142. $scope.checkCodes = [];
  143. }
  144. /**
  145. * 多选、单选操作
  146. */
  147. $scope.checks = {
  148. checked : false
  149. };
  150. $scope.checkCodes = [];
  151. // 点击勾选Code全部的复选框
  152. $scope.checkAll = function(){
  153. if($scope.checks.checked) {
  154. $scope.count = $scope.localRecepit.length;
  155. }else {
  156. $scope.count = 0;
  157. }
  158. angular.forEach($scope.checkCodes, function(item, key) {
  159. $scope.checkCodes[key] = $scope.checks.checked;
  160. });
  161. };
  162. //点击Code单选
  163. $scope.checkOne = function(index) {
  164. var result = true;
  165. if($scope.checkCodes[index]) {
  166. $scope.count++;
  167. }else {
  168. $scope.count--;
  169. }
  170. angular.forEach($scope.checkCodes, function(item, key) {
  171. if(!item){
  172. result = false;
  173. return;
  174. }
  175. });
  176. $scope.checks.checked = result;
  177. };
  178. // 最大日期为当天
  179. $scope.maxDate = new Date();
  180. $scope.imageUrl = 'static/img/upload/cont.jpg';
  181. $scope.showImageDialog = function() {
  182. $modal.open({
  183. templateUrl : 'offer/image/insert.html',
  184. controller : 'ImageInsertCtrl',
  185. backdrop : 'static'
  186. }).result.then(function(image){
  187. if(!image.src || !image) {
  188. $scope.logoUrl = false;
  189. $scope.imageUrl = false;
  190. }else {
  191. $scope.logoUrl = image.src;
  192. $scope.imageUrl = image.thumb;
  193. }
  194. }, function() {
  195. $scope.logoUrl = false;
  196. $scope.imageUrl =false;
  197. });
  198. }
  199. //删除平台账户
  200. $scope.deleteAccount = function(buyAccount) {
  201. var resurt = confirm('是否删除此银行账户,删除后将不能恢复,谨慎操作!');
  202. if(resurt){
  203. bankInfoService.deleteBank({id: buyAccount.id}, function(data) {
  204. toaster.pop('success', '删除成功');
  205. getBuyAccount();
  206. //TODO 这个需要用编码变身
  207. if($stateParams.uu == 10030994) {
  208. getVenderAccount();
  209. }
  210. }, function(response) {
  211. toaster.pop('error', '删除失败');
  212. })
  213. }
  214. }
  215. //新增账户
  216. $scope.newAccount = function(data) {
  217. var modalInstance = $modal.open({
  218. templateUrl : 'static/view/common/bankInfoAdmin.html',
  219. controller : 'BankInfoCtrl',
  220. resolve : {
  221. kind : function() {
  222. //深拷贝一份
  223. return angular.copy($scope.kind);
  224. },
  225. account : function() {
  226. //深拷贝一份
  227. return angular.copy(data);
  228. }
  229. }
  230. });
  231. modalInstance.result.then(function(account) {
  232. //企业账户
  233. bankInfoService.saveBuyEnterpriseBank({}, account, function(data) {
  234. toaster.pop('success', '保存成功','信息已添加');
  235. $scope.kind = account.kind;
  236. getBuyAccount();
  237. //TODO 这个需要用编码变身
  238. if($stateParams.uu == 10030994) {
  239. getVenderAccount();
  240. }
  241. }, function(res) {
  242. toaster.pop('error', '错误', res.data);
  243. });
  244. }, function() {
  245. });
  246. };
  247. //选中账号
  248. $scope.select = function(account, isVender) {
  249. if(isVender) {
  250. $scope.venderAccount = account;
  251. }else {
  252. $scope.b2cAccount = account;
  253. }
  254. }
  255. /**
  256. * 批量转出货
  257. */
  258. //expose代表展开的状态,isBuyd代表当前操作的数据
  259. $scope.doExpose = function(expose, isVender) {
  260. if(isVender) {
  261. $scope.venderExpose = expose;
  262. }else {
  263. $scope.salexpose = expose;
  264. }
  265. }
  266. $scope.getBatch = function() {
  267. var batchRecepit = [];
  268. for (var i = 0; i < $scope.checkCodes.length; i++) {
  269. if($scope.checkCodes[i]) {
  270. batchRecepit.push($scope.localRecepit[i]);
  271. };
  272. }
  273. return batchRecepit;
  274. }
  275. $scope.batchCheckMoney = function(recepit) {
  276. $location.hash('batchCheckMoney');
  277. $anchorScroll();
  278. var idArray = [];
  279. if(recepit) {
  280. $scope.count = 1;
  281. $scope.batchRecepit = [];
  282. $scope.batchRecepit.push(recepit);
  283. }else {
  284. $scope.noticeInfo = true;
  285. $scope.batchRecepit = $scope.getBatch();
  286. }
  287. $scope.total = 0;
  288. angular.forEach($scope.batchRecepit, function(item) {
  289. //$scope.total += item.price;
  290. idArray.push(item.id);
  291. });
  292. // TODO huxz 获取ID
  293. console.log('PRINT ARRAY IDS OF RECEIPT');
  294. console.log(idArray.join('-'));
  295. Receipt.settleReceipt({ids:idArray.join('-')}, {}, function (data) {
  296. if (data.status == 'success') {
  297. $scope.total = data.total;
  298. }
  299. }, function (resp) {
  300. console.log('ERROR');
  301. console.log(resp);
  302. });
  303. $scope.batchCheckStatus = true;
  304. $scope.oneCheckStatus = false;
  305. }
  306. //解析数据,从返回的数据中找到要解析的数据
  307. var resolveData = function(data) {
  308. var arr = new Array();
  309. for(var key in data) {
  310. var numb= Number(key);
  311. if(angular.isNumber(numb)&&(!isNaN(numb))) {
  312. arr.push(data[key]);
  313. }
  314. }
  315. return arr;
  316. };
  317. //排序
  318. var getOriginalData = function(data) {
  319. var result = null;
  320. if(data&&data.length) {
  321. result = data[0];
  322. }
  323. return result;
  324. };
  325. var getBuyAccount = function() {
  326. //平台应付账号
  327. bankInfoService.getAdminEnterAccount('', function(data) {
  328. $scope.b2cAccountInfos = resolveData(data);
  329. angular.forEach($scope.b2cAccountInfos, function(b2cAccountInfos) {
  330. b2cAccountInfos.filterAccount = hideBankFilter(b2cAccountInfos.number);
  331. });
  332. $scope.b2cAccount = getOriginalData($scope.b2cAccountInfos);
  333. }, function(res) {
  334. toaster.pop('error', '错误', '获取卖家信息失败');
  335. });
  336. }
  337. getBuyAccount();
  338. //供应商应收账户
  339. var getVenderAccount = function() {
  340. bankInfoService.getVenderBank({venduu:$stateParams.uu},null, function(data) {
  341. $scope.venderAccountInfos = resolveData(data);
  342. angular.forEach($scope.venderAccountInfos, function(venderAccountInfos) {
  343. venderAccountInfos.filterAccount = hideBankFilter(venderAccountInfos.number);
  344. });
  345. $scope.venderAccount = getOriginalData($scope.venderAccountInfos);
  346. }, function(res) {
  347. toaster.pop('error', '错误', '获取卖家信息失败');
  348. });
  349. }
  350. getVenderAccount();
  351. $scope.confirm = function(transferTime) {
  352. console.log(transferTime);
  353. $scope.transferTime = transferTime;
  354. if(angular.isUndefined($scope.venderAccount) || angular.equals("{}", angular.toJson($scope.venderAccount))) {
  355. toaster.pop('error', '错误', '请选择卖家账户');
  356. return ;
  357. }
  358. if(angular.isUndefined($scope.b2cAccount) || angular.equals("{}", angular.toJson($scope.b2cAccount))) {
  359. toaster.pop('error', '错误', '请选择平台账户');
  360. return ;
  361. }
  362. if(angular.isUndefined($scope.logoUrl) || angular.equals($scope.logoUrl, 'static/img/upload/cont.jpg')) {
  363. toaster.pop('error', '错误', '请上传付款截图');
  364. return ;
  365. }
  366. if(angular.isUndefined($scope.count) || $scope.count == 0) {
  367. toaster.pop('error', '错误', '没有选择要付款的出入库单');
  368. return ;
  369. }
  370. if(!$scope.transferTime) {
  371. toaster.pop('error', '错误', '请选择付款日期');
  372. return ;
  373. }
  374. delete $scope.b2cAccount.filterAccount;
  375. delete $scope.venderAccount.filterAccount;
  376. var jsonPament = angular.toJson($scope.b2cAccount);
  377. var jsonReceive = angular.toJson($scope.venderAccount);
  378. var transfer = {};
  379. transfer.jsonPament = jsonPament;
  380. transfer.jsonReceive = jsonReceive;
  381. transfer.imgUrl = $scope.logoUrl;
  382. transfer.transferTime = $scope.transferTime.getTime();
  383. transfer.total = 0;
  384. $scope.receiptids = "";
  385. angular.forEach($scope.batchRecepit, function(item) {
  386. transfer.total += item.price;
  387. $scope.receiptids += item.receiptid + "-";
  388. });
  389. bankTransferService.saveTransferFvender({receiptes: $scope.receiptids}, transfer, function(data) {
  390. toaster.pop("success", '成功', '保存成功!');
  391. $scope.receiptTableParams.reload();
  392. //删除多余的变量
  393. delete $scope.batchCheckStatus;
  394. // var modalInstance = $modal.open({
  395. // templateUrl : 'static/view/common/timeClose.html',
  396. // controller : 'timeCtrl'
  397. // });
  398. //
  399. // modalInstance.result.then(function(time) {
  400. // $state.go('histTransfer');
  401. // }, function() {
  402. //
  403. // });
  404. }, function(res) {
  405. toaster.pop("error", '失败', '信息保存失败');
  406. });
  407. }
  408. }
  409. }]);
  410. app.register.controller('BankInfoCtrl', ['$scope', '$modalInstance', 'account', 'kind', function($scope, $modalInstance, account, kind){
  411. $scope.account = account;
  412. $scope.kind = kind;
  413. if($scope.account) {
  414. $scope.title = "修改账户";
  415. }else {
  416. $scope.title = "新增账户";
  417. $scope.account = {};
  418. }
  419. $scope.set = function(kind) {
  420. $scope.kind = kind;
  421. }
  422. $scope.confirm = function() {
  423. $scope.account.kind = $scope.kind;
  424. $modalInstance.close($scope.account);
  425. }
  426. $scope.cancel = function() {
  427. $modalInstance.dismiss();
  428. }
  429. }]);
  430. app.register.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
  431. $scope.image = {src: null};
  432. // 图片上传成功之后
  433. $scope.onUploadSuccess = function(data){
  434. var path = data.path;
  435. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  436. $scope.$apply(function(){
  437. $scope.image.src = data.path;
  438. $scope.image.thumb = path;
  439. });
  440. };
  441. $scope.close = function() {
  442. $modalInstance.dismiss();
  443. };
  444. $scope.confirm = function() {
  445. $modalInstance.close($scope.image);
  446. $scope.imageUrl = null;
  447. };
  448. }]);
  449. });