TestPost.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.plm.test.TestPost', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil','erp.util.BaseUtil'],
  5. views: ['plm.test.TestPost'],
  6. init:function(){
  7. var me = this;
  8. me.FormUtil = Ext.create('erp.util.FormUtil');
  9. me.GridUtil = Ext.create('erp.util.GridUtil');
  10. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  11. this.control({
  12. 'button': {
  13. click: function(btn){
  14. var cal = btn.caller;
  15. switch(cal) {
  16. case 'ProdInOut!PurcCheckin':
  17. me.test(cal, btn.text,"采购验收单");
  18. break;
  19. case 'ProdInOut!PurcCheckout':
  20. me.test(cal, btn.text,"采购验退单");
  21. break;
  22. case 'ProdInOut!Sale':
  23. break;
  24. case 'ProdInOut!SaleReturn':
  25. break;
  26. case 'ProdInOut!Picking':
  27. break;
  28. case 'ProdInOut!Make!Return':
  29. break;
  30. }
  31. }
  32. }
  33. });
  34. },
  35. test: function(caller, title, piclass){
  36. var me = this;
  37. Ext.create('Ext.Window', {
  38. id: 'test-win',
  39. height: '100%',
  40. width: '100%',
  41. title: title,
  42. layout: 'border',
  43. caller: caller,
  44. items: [{
  45. region: 'center',
  46. layout: 'anchor',
  47. items: [{
  48. xtype: 'form',
  49. anchor: '100% 5%',
  50. layout: 'hbox',
  51. items: [{
  52. fieldLabel: '压力指数',
  53. xtype: 'combo',
  54. editable: false,
  55. store: Ext.create('Ext.data.Store', {
  56. fields: ['display', 'value'],
  57. data: [{display: 10, value: 10}, {display: 20, value: 20}, {display: 50, value: 50},
  58. {display: 100, value: 100}, {display: 200, value: 200}, {display: 500, value: 500},
  59. {display: 1000, value: 1000}]
  60. }),
  61. displayField: 'display',
  62. valueField: 'value',
  63. queryMode: 'local',
  64. value: 10
  65. },{
  66. xtype: 'button',
  67. text: '生成测试单据',
  68. cls: 'x-btn-blue',
  69. width: 100,
  70. handler: function(btn){
  71. me.createPreData(caller, btn.ownerCt.down('combo').value,piclass);
  72. }
  73. },{
  74. xtype: 'button',
  75. text: '过账',
  76. cls: 'x-btn-blue',
  77. width: 100,
  78. handler: function(){
  79. me.post();
  80. }
  81. },{
  82. xtype: 'button',
  83. text: '查看物料库存',
  84. cls: 'x-btn-blue',
  85. width: 100,
  86. handler: function(){
  87. me.wareHouse();
  88. }
  89. },{
  90. xtype: 'button',
  91. text: '清除测试数据',
  92. cls: 'x-btn-blue',
  93. width: 100,
  94. handler: function(){
  95. me.clear();
  96. }
  97. }]
  98. },{
  99. xtype: 'panel',
  100. anchor: '100% 95%',
  101. layout : 'fit',
  102. html : '<iframe src="' + basePath + 'jsps/scm/reserve/prodInOut.jsp?whoami=' + caller + '" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  103. }]
  104. },{
  105. region: 'east',
  106. width: '30%',
  107. id: 'log',
  108. xtype: 'panel',
  109. title: '<div style="padding-top:5px;color:#FF6A6A;background: #E0EEEE url(' + basePath +
  110. 'resource/ext/resources/themes/images/default/grid/grid-blue-hd.gif) repeat center center">&nbsp;测试记录</div>',
  111. layout: 'anchor',
  112. items: [{
  113. anchor: '100% 100%',
  114. xtype: 'textarea',
  115. value: ''
  116. }],
  117. append: function(val){
  118. var v = this.down('textarea').value || '';
  119. this.down('textarea').setValue(v + '\n' + '时间:' + Ext.Date.format(new Date(), 'Y-m-d H:i:s')
  120. + '\n>>>>' + val + '\n');
  121. },
  122. clear: function(){
  123. this.down('textarea').setValue('');
  124. }
  125. }],
  126. listeners: {
  127. close: function(){
  128. me.clear();
  129. }
  130. }
  131. }).show();
  132. },
  133. createPreData: function(caller, count, piclass){
  134. var me = this,w = Ext.getCmp('test-win');
  135. w.down('#log').clear();
  136. me.logger('正在生成采购单数据');
  137. //生成采购
  138. Ext.Ajax.request({
  139. url: basePath + 'plm/test/initPurchase.action',
  140. params: {
  141. count: count
  142. },
  143. callback: function(opt, s, r){
  144. var res = Ext.decode(r.responseText);
  145. if(res.exceptionInfo) {
  146. me.logger(res.exceptionInfo.replace(/<BR>|<br>|<br\/>/g, '\n'));return;
  147. }
  148. if(res.data) {
  149. var c = Ext.decode(res.data)[0].pd_code;
  150. me.logger('生成采购单,单号:' + c);
  151. w.preData = c;
  152. me.createTestData(caller, count, res.data, piclass);
  153. }
  154. }
  155. });
  156. },
  157. createTestData: function(caller, count, data, piclass){
  158. var me = this;
  159. me.logger('正在生成出入库单数据');
  160. var t1 = new Date().getTime();
  161. var win = Ext.getCmp('test-win');
  162. win.setLoading(true);
  163. //生成采购
  164. Ext.Ajax.request({
  165. url: basePath + 'plm/test/initProdIOPurc.action',
  166. params: {
  167. data: data,
  168. count: count,
  169. piclass:piclass,
  170. caller:caller
  171. },
  172. timeout: 100000,
  173. callback: function(opt, s, r){
  174. win.setLoading(false);
  175. var res = Ext.decode(r.responseText);
  176. if(res.exceptionInfo) {
  177. me.logger(res.exceptionInfo.replace(/<BR>|<br>|<br\/>/g, '\n'));return;
  178. }
  179. if(res.data) {
  180. me.logger("已生成" + count + "条出入库单据\n>>>>耗时:" + (new Date().getTime() - t1)/1000 + "秒");
  181. win.testData = res.data;
  182. var co = res.data[0];
  183. var iframe = win.getEl().select('iframe').elements[0];
  184. iframe.src = basePath + 'jsps/scm/reserve/prodInOut.jsp?whoami=' + caller +
  185. '&formCondition=pi_inoutnoIS\'' + co + '\'&gridCondition=pd_inoutnoIS\'' + co + '\'';
  186. }
  187. }
  188. });
  189. },
  190. post: function(){
  191. var w = Ext.getCmp('test-win'), me = this;
  192. if(w) {
  193. if(w.testData) {
  194. var ok = 0,ng = 0, len = w.testData.length,t = new Date().getTime();
  195. w.setLoading(true);
  196. Ext.each(w.testData, function(c){
  197. Ext.Ajax.request({
  198. url: basePath + 'plm/test/postProdIOPurc.action',
  199. params: {
  200. code: c
  201. },
  202. timeout: 150000,
  203. callback: function(opt, s, r) {
  204. var res = Ext.decode(r.responseText);
  205. if(res.result) {
  206. me.logger('过账失败,单号:' + c + '\n原因:' + res.result);
  207. ng++;
  208. } else {
  209. ok++;
  210. }
  211. if(ok + ng == len) {
  212. w.setLoading(true);
  213. me.logger('过账通过率:' + (100 * ok/len) + '%\n' + '>>>>过账失败率:' + (100 * ng/len) + '%\n' +
  214. '>>>>总用时:' + ((new Date().getTime() - t)/1000) + '秒');
  215. var iframe = w.getEl().select('iframe').elements[0];
  216. iframe.src = iframe.src;
  217. }
  218. }
  219. });
  220. });
  221. }
  222. }
  223. },
  224. wareHouse: function(){
  225. var w = Ext.getCmp('test-win');
  226. if(w) {
  227. if(w.preData) {
  228. var ww = Ext.create('Ext.Window', {
  229. width: '70%',
  230. height: '90%',
  231. title: '物料库存查询',
  232. layout: 'anchor',
  233. items: [{
  234. anchor: '100% 100%',
  235. xtype: 'grid',
  236. columnLines: true,
  237. columns: [{
  238. text: '物料编号',
  239. width: 160,
  240. dataIndex: 'PD_PRODCODE'
  241. },{
  242. text: '数量',
  243. width: 400,
  244. columns: [{
  245. text: 'Productwh',
  246. flex: 1,
  247. xtype: 'numbercolumn',
  248. dataIndex: 'PW_ONHAND'
  249. },{
  250. text: 'PurchaseDetail',
  251. flex: 1,
  252. dataIndex: 'PD_ACCEPTQTY'
  253. },{
  254. text: 'Batch',
  255. flex: 1,
  256. dataIndex: 'BA_REMAIN'
  257. },{
  258. text: 'ProdIoDetail',
  259. flex: 1,
  260. dataIndex: 'PD_INQTY'
  261. }]
  262. },{
  263. width: 400,
  264. renderer: function(val, meta, record){
  265. return (record.get('PW_ONHAND') == record.get('PD_ACCEPTQTY') == record.get('BA_REMAIN')
  266. == record.get('PD_INQTY')) ? "正常" : "数量有异";
  267. }
  268. }],
  269. store: Ext.create('Ext.data.Store', {
  270. fields: ['PD_PRODCODE', 'PW_ONHAND', 'PD_ACCEPTQTY', 'BA_REMAIN', 'PD_INQTY'],
  271. data: []
  272. })
  273. }]
  274. });
  275. ww.show();
  276. ww.setLoading(true);
  277. Ext.Ajax.request({
  278. url : basePath + 'common/getFieldsDatas.action',
  279. params: {
  280. caller: 'PurchaseDetail left join io_pdinqty_view ' +
  281. 'on PurchaseDetail.pd_prodcode=io_pdinqty_view.pd_prodcode ' +
  282. 'left join io_pwonhand_view on PurchaseDetail.pd_prodcode=io_pwonhand_view.pw_prodcode ' +
  283. 'left join io_batch_remain_view on PurchaseDetail.pd_prodcode=io_batch_remain_view.ba_prodcode',
  284. fields: 'PurchaseDetail.pd_prodcode pd_prodcode,pw_onhand,pd_inqty,ba_remain,pd_acceptqty',
  285. condition: 'pd_code=\'' + w.preData + '\''
  286. },
  287. method : 'post',
  288. callback : function(options,success,response){
  289. ww.setLoading(false);
  290. var localJson = new Ext.decode(response.responseText);
  291. if(localJson.exceptionInfo){
  292. showError(localJson.exceptionInfo);return;
  293. }
  294. if(localJson.success){
  295. var data = localJson.data;
  296. ww.down('grid').store.loadData(Ext.decode(data));
  297. }
  298. }
  299. });
  300. }
  301. }
  302. },
  303. clear: function(){
  304. var w = Ext.getCmp('test-win');
  305. if(w) {
  306. if(w.preData) {
  307. var codes = new Array();
  308. Ext.each(w.testData, function(){
  309. codes.push('\'' + this + '\'');
  310. });
  311. w.setLoading(true);
  312. Ext.Ajax.request({
  313. url: basePath + 'plm/test/clearProdIOPurc.action',
  314. params: {
  315. code: w.preData,
  316. codes: Ext.Array.concate(codes, ',')
  317. },
  318. callback: function(opt, s, r) {
  319. w.setLoading(false);
  320. var res = Ext.decode(r.responseText);
  321. if(res.success) {
  322. alert('测试数据已清除');
  323. w.down('#log').clear();
  324. w.preData = null;
  325. w.testData = null;
  326. var iframe = w.getEl().select('iframe').elements[0];
  327. iframe.src = basePath + 'jsps/scm/reserve/prodInOut.jsp?whoami=' + w.caller;
  328. }
  329. }
  330. });
  331. }
  332. }
  333. },
  334. logger: function(msg){
  335. Ext.getCmp('log').append(msg);
  336. }
  337. });