BatchDealer.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.BatchDealer', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'common.batchDeal.ViewPorter','common.batchDeal.Former','common.batchDeal.GriderPanel','core.trigger.AddDbfindTrigger',
  7. 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField',
  8. 'core.trigger.TextAreaTrigger','core.form.YnField', 'core.form.MonthDateField','core.form.ConMonthDateField','core.trigger.SchedulerTrigger',
  9. 'core.grid.YnColumn','core.form.DateHourMinuteField','core.form.SeparNumber','core.grid.YnColumnNV','common.batchDeal.Toolbar'
  10. ],
  11. BaseUtil: Ext.create('erp.util.BaseUtil'),
  12. FormUtil: Ext.create('erp.util.FormUtil'),
  13. init:function(){
  14. var me = this;
  15. me.resized = false;
  16. this.control({
  17. 'erpBatchDealerFormPanel': {
  18. alladded: function(form){
  19. var grid = Ext.getCmp('batchDealerGridPanel');
  20. me.resize(form, grid);
  21. /**
  22. * 手动加锁
  23. */
  24. var sacode = getUrlParam("sacode");
  25. var prodcode = getUrlParam("prodcode"),detno = getUrlParam("detno"),ob_noallqty=getUrlParam("ob_noallqty"),prodname=getUrlParam("prodname");
  26. if(caller=="HandLocked!Deal"&&sacode&&prodcode){
  27. var prodcode_ = Ext.getCmp("prodcode_"),code_ = Ext.getCmp("code_"),pr_name = Ext.getCmp("pr_name"),qty=Ext.getCmp("qty"),pd_detno=Ext.getCmp("pd_detno");
  28. prodcode_.setValue(prodcode);
  29. code_.setValue(sacode);
  30. pr_name.setValue(prodname);
  31. qty.setValue(ob_noallqty);
  32. pd_detno.setValue(detno);
  33. }
  34. // form.onQuery();
  35. var items = form.items.items, autoQuery = false;
  36. Ext.each(items, function() {
  37. var val = getUrlParam(this.name);
  38. if(!Ext.isEmpty(val)) {
  39. this.setValue(val);
  40. autoQuery = true;
  41. if(this.xtype == 'dbfindtrigger') {
  42. this.autoDbfind('form', caller, this.name, this.name + " like '%" + val + "%'");
  43. }
  44. }
  45. });
  46. if(autoQuery) {
  47. setTimeout(function(){
  48. form.onQuery();
  49. }, 1000);
  50. }
  51. if(form.source=='allnavigation'){
  52. Ext.each(form.dockedItems.items[0].items.items,function(btn){
  53. btn.setDisabled(true);
  54. });
  55. }
  56. }
  57. },
  58. 'erpBatchDealerGridPanel': {
  59. afterrender: function(grid){
  60. var form = Ext.getCmp('dealerform');
  61. me.resize(form, grid);
  62. grid.store.on('datachanged', function(store){//dataChanged事件
  63. me.getProductWh(grid);
  64. });
  65. if(caller == 'ARBill!ToBillOut!Deal'||caller == 'APBill!ToBillOutAP!Deal'){
  66. grid.plugins[0].on('afteredit',function(){
  67. me.countAmount(grid);
  68. });
  69. grid.on('selectionchange',function(){
  70. me.countAmount(grid);
  71. });
  72. }
  73. },
  74. edit:function(ed,d){
  75. if(caller == "UpdateMakeSubMaterial" && d.field=='mp_canuseqty'){
  76. //发送请求更新可替代数
  77. me.updateMakeSub(d);
  78. }
  79. },
  80. itemclick: function(selModel, record, item, index, event){//grid行选择
  81. if(event.target.getAttribute('class')!='x-grid-row-checker'){
  82. if(caller == 'Make!Cost!Deal'){
  83. url = 'jsps/common/batchDeal.jsp?whoami=Make!OnCost!Deal';
  84. if(record) {
  85. url += '&ma_code=' + record.data.cd_makecode;
  86. url += '&cd_yearmonth=' + record.data.cd_yearmonth;
  87. url += '&ma_tasktype=' + record.data.cd_maketype;
  88. }
  89. me.FormUtil.onAdd('addCostDetailMateria', '月结表', url);
  90. }
  91. }
  92. }
  93. },
  94. 'field[name=differ]': {
  95. change: function(field){
  96. var grid = Ext.getCmp('batchDealerGridPanel');
  97. me.countAmount(grid);
  98. }
  99. },
  100. 'erpVastDealButton': {
  101. click: {
  102. fn: function(btn){
  103. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  104. },
  105. lock: 2000
  106. }
  107. },
  108. 'erpVastAnalyseButton': {
  109. click: function(btn){
  110. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  111. }
  112. },
  113. 'erpVastPrintButton': {
  114. click: function(btn){
  115. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  116. }
  117. },
  118. 'erpVastAllotButton':{
  119. click:function(btn){
  120. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  121. }
  122. },
  123. 'erpSaveCostDetailButton':{
  124. click:function(btn){
  125. me.vastDeal('cost/vastSaveCostDetail.action');
  126. }
  127. },
  128. 'erpDifferVoucherCreditButton':{
  129. click:function(btn){
  130. me.vastDeal('cost/vastDifferVoucherCredit.action');
  131. }
  132. },
  133. 'erpNowhVoucherCreditButton':{
  134. click:function(btn){
  135. me.vastDeal('cost/vastNowhVoucherCredit.action');
  136. }
  137. },
  138. 'SchedulerTrigger':{
  139. afterrender:function(trigger){
  140. trigger.setFields=[{field:'va_vecard',mappingfield:'ID'},{field:'va_driver',mappingfield:'VA_DRIVER'}];
  141. }
  142. },
  143. 'erpEndCRMButton':{
  144. click:function(btn){
  145. me.vastDeal('crm/chanceTurnEnd.action');
  146. }
  147. },
  148. 'monthdatefield': {
  149. afterrender: function(f) {
  150. var type = '', con = null;
  151. if(f.name == 'vo_yearmonth' && caller == 'Voucher!Audit!Deal') {
  152. type = 'MONTH-A';
  153. con = Ext.getCmp('condatefield');
  154. } else if(f.name == 'vo_yearmonth' && caller == 'Voucher!ResAudit!Deal') {
  155. type = 'MONTH-A';
  156. con = Ext.getCmp('condatefield');
  157. } else if(f.name == 'vo_yearmonth' && caller == 'CashFlowSet') {
  158. type = 'MONTH-A';
  159. con = Ext.getCmp('condatefield');
  160. } else if(f.name == 'vm_yearmonth' && caller == 'VendMonth!Cyf!Batch') {
  161. type = 'MONTH-V';
  162. con = Ext.getCmp('condatefield');
  163. } else if(f.name == 'cm_yearmonth' && caller == 'CustMonth!Cys!Batch') {
  164. type = 'MONTH-C';
  165. con = Ext.getCmp('condatefield');
  166. } else if(f.name == 'cd_yearmonth' && (caller == 'Make!Cost!Deal' || caller == 'Make!OnCost!Deal')) {
  167. type = 'MONTH-T';
  168. con = Ext.getCmp('condatefield');
  169. } else if(f.name == 'pc_yearmonth' && caller == 'ProjectCost!Deal') {
  170. type = 'MONTH-O';
  171. con = Ext.getCmp('condatefield');
  172. }
  173. if(type != '') {
  174. this.getCurrentMonth(f, type, con);
  175. }
  176. },
  177. change: function(f) {
  178. if(f.name == 'vo_yearmonth' &&( caller == 'Voucher!Audit!Deal'||caller == 'Voucher!ResAudit!Deal')){
  179. if(!Ext.isEmpty(f.value)) {
  180. var d = Ext.ComponentQuery.query('condatefield');
  181. if(d && d.length > 0)
  182. d[0].setMonthValue(f.value);
  183. }
  184. }
  185. }
  186. },
  187. 'erpRefreshQtyButton': {
  188. click : function() {
  189. this.refreshQty(caller);
  190. }
  191. },
  192. 'gridcolumn[dataIndex=md_canuseqty]':{
  193. beforerender:function(column){
  194. }
  195. }
  196. });
  197. },
  198. checkTempStore:function(){//查看暂存区
  199. var me = this, grid = Ext.getCmp('batchDealerGridPanel');
  200. var checkdata=[];
  201. Ext.each(grid.tempStore,function(d){
  202. var keys=Ext.Object.getKeys(d);//getKeys(Object object):获取所有对象的key组成的数组.
  203. Ext.each(keys, function(k){
  204. checkdata.push(d[k].data);
  205. });
  206. });
  207. var checkwin=Ext.getCmp('checkwin'+caller);
  208. if(checkwin){
  209. checkwin.show();
  210. }else{
  211. var checkwin = Ext.create('Ext.Window', {
  212. id : 'checkwin'+caller,
  213. height: "100%",
  214. width: "80%",
  215. maximizable : true,
  216. buttonAlign : 'center',
  217. layout : 'anchor',
  218. items: [{
  219. tag : 'iframe',
  220. frame : true,
  221. anchor : '100% 100%',
  222. layout : 'fit',
  223. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/common/tempStore.jsp?caller=' + caller
  224. +"&condition= " +'' +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  225. }],
  226. buttons : [{
  227. name: 'cancle',
  228. text : $I18N.common.button.erpCancelButton,
  229. iconCls: 'x-button-icon-delete',
  230. cls: 'x-btn-gray',
  231. listeners: {
  232. click: function(btn) {
  233. var checkgrid=Ext.getCmp('checkwin'+caller).items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.Ext.getCmp("tempStoreGridPanel");
  234. checkgrid.setLoading(true);
  235. var grid=Ext.getCmp('batchDealerGridPanel'),form=Ext.getCmp('dealerform');
  236. var tempStore = grid.tempStore;
  237. var select=checkgrid.getMultiSelected();
  238. var keys=new Array();
  239. if(form.detailkeyfield){
  240. keys=form.detailkeyfield.split('#');
  241. }else{
  242. keys.push(grid.keyField);
  243. }
  244. var bool=false;
  245. Ext.each(select ,function(s){
  246. var key='';
  247. Ext.each(keys,function(k){
  248. key+=s.data[k];
  249. });
  250. delete tempStore[key+'temp'];
  251. checkgrid.getStore().remove(s);
  252. Ext.each(grid.store.data.items, function(item){
  253. Ext.each(keys,function(k){
  254. if(item.data[k]==s.data[k]){
  255. bool=true;
  256. }else{
  257. bool=false;
  258. return false;
  259. }
  260. });
  261. if(bool){
  262. item.set('turned','否');
  263. }
  264. });
  265. });
  266. checkgrid.summary();
  267. checkgrid.setLoading(false);
  268. }
  269. }
  270. },{
  271. text :$I18N.common.button.erpExportButton,
  272. iconCls: 'x-button-icon-excel',
  273. cls: 'x-btn-gray',
  274. handler : function(btn){
  275. var checkgrid=Ext.getCmp('checkwin'+caller).items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.Ext.getCmp("tempStoreGridPanel");
  276. checkgrid.BaseUtil.exportGrid(checkgrid,checkgrid.title);
  277. }
  278. } , {
  279. text : $I18N.common.button.erpCloseButton,
  280. iconCls: 'x-button-icon-close',
  281. cls: 'x-btn-gray',
  282. handler : function(btn){
  283. btn.ownerCt.ownerCt.close();
  284. }
  285. }]
  286. });
  287. checkwin.show();
  288. }
  289. },
  290. addToTempStore:function(){
  291. var me = this,grid = Ext.getCmp('batchDealerGridPanel'),form=Ext.getCmp('dealerform');
  292. grid.setLoading(true);
  293. var keys=new Array();
  294. if(form.detailkeyfield){
  295. keys=form.detailkeyfield.split('#');//唯一标识
  296. }else{
  297. keys.push(grid.keyField);
  298. }
  299. var items = grid.getMultiSelected();
  300. Ext.each(items, function(item, index){
  301. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  302. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  303. var key='';
  304. var r=this.data;
  305. Ext.each(keys,function(k){
  306. key+=r[k.toString()];
  307. });
  308. grid.tempStore[key+"temp"]=item;//key+temp作为key,解决key为id值只有数字时没有按照添加顺序排序
  309. item.set('turned','是');//是否已暂存
  310. grid.getSelectionModel().deselect(item);//取消勾选
  311. }
  312. });
  313. grid.setLoading(false);
  314. },
  315. resize: function(form, grid){
  316. if(!this.resized && form && grid && form.items.items.length > 0){
  317. var height = window.innerHeight,
  318. fh = form.getEl().down('.x-panel-body>.x-column-inner').getHeight();
  319. if(Ext.isIE){
  320. height = screen.height*0.75;
  321. }
  322. form.setHeight(35 + fh);
  323. grid.setHeight(height - fh - 35);
  324. this.resized = true;
  325. }
  326. },
  327. countGrid: function(){
  328. //重新计算合计栏值
  329. var grid = Ext.getCmp('batchDealerGridPanel');
  330. Ext.each(grid.columns, function(column){
  331. if(column.summary){
  332. var sum = 0;
  333. Ext.each(grid.store.data.items, function(item){
  334. if(item.value != null && item.value != ''){
  335. sum += Number(item.value);
  336. }
  337. });
  338. Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum);
  339. } else if(column.average) {
  340. var average = 0;
  341. Ext.each(grid.store.data.items, function(item){
  342. if(item.value != null && item.value != ''){
  343. average += Number(item.value);
  344. }
  345. });
  346. average = average/grid.store.data.items.length;
  347. Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average);
  348. } else if(column.count) {
  349. var count = 0;
  350. Ext.each(grid.store.data.items, function(item){
  351. if(item.value != null && item.value != ''){
  352. count++;
  353. }
  354. });
  355. Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count);
  356. }
  357. });
  358. },
  359. vastDeal: function(url){
  360. var me = this, grid = Ext.getCmp('batchDealerGridPanel'),form = Ext.getCmp('dealerform');
  361. var checkdata=[];
  362. Ext.each(grid.tempStore,function(d){
  363. var keys=Ext.Object.getKeys(d);
  364. Ext.each(keys, function(k){
  365. checkdata.push(d[k]);
  366. });
  367. });
  368. var items = grid.getMultiSelected(); //勾选的数据
  369. var boolAll = false;
  370. if(checkdata.length>0&&items.length>0){
  371. showError('暂存区已经有数据,当前筛选界面勾选的数据无效,请取消勾选或添加到暂存区');
  372. return;
  373. }else if(items.length>0){
  374. var data = grid.store.data.items; //本页展示的数据
  375. Ext.each(items, function(item, index){
  376. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  377. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  378. item.index = this.data[grid.keyField];
  379. grid.multiselected.push(item);
  380. }
  381. });
  382. }else if(checkdata.length>0){
  383. grid.multiselected=checkdata;
  384. }
  385. var records = Ext.Array.unique(grid.multiselected);
  386. var itemCheck = grid.selModel.getSelection(); //勾选的数据
  387. var dataAll = grid.store.data.items; //数据
  388. Ext.each(itemCheck, function(item, index){
  389. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  390. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  391. if(itemCheck.length == dataAll.length){
  392. if(itemCheck.length > 10){
  393. boolAll = true;
  394. }
  395. }
  396. }
  397. });
  398. if(records.length > 0){
  399. if(contains(url,'common/form/vastPost.action',true) || contains(url,'common/vastPostProcess.action',true)) {//流程批量抛转
  400. this.vastPost(grid, records, url);
  401. return;
  402. }
  403. var params = new Object();
  404. params.id=new Array();
  405. params.caller = caller;
  406. var data = new Array();
  407. var bool = false;
  408. Ext.each(records, function(record, index){
  409. var f = form.fo_detailMainKeyField;
  410. if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  411. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  412. ||(f && this.data[f] != null && this.data[f] != ''
  413. && this.data[f] != '0' && this.data[f] != 0)){
  414. bool = true;
  415. var o = new Object();
  416. if(grid.keyField){
  417. o[grid.keyField] = record.data[grid.keyField];
  418. } else {
  419. params.id[index] = record.data[form.fo_detailMainKeyField];
  420. }
  421. if(grid.toField){
  422. Ext.each(grid.toField, function(f, index){
  423. var v = Ext.getCmp(f).value;
  424. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  425. if(Ext.isDate(v)){
  426. v = Ext.Date.toString(v);
  427. }
  428. o[f] = v;
  429. } else {
  430. o[f] = '';
  431. }
  432. });
  433. }
  434. if(grid.necessaryFields){
  435. Ext.each(grid.necessaryFields, function(f, index){
  436. var v = record.data[f];
  437. if(Ext.isDate(v)){
  438. v = Ext.Date.toString(v);
  439. }
  440. if(Ext.isNumber(v)){
  441. v = (v).toString();
  442. }
  443. o[f] = v;
  444. });
  445. }
  446. data.push(o);
  447. }
  448. });
  449. if(bool && !me.dealing){
  450. var main = parent.Ext.getCmp("content-panel");
  451. if(boolAll){
  452. warnMsg('是否按照筛选条件批量处理符合条件的数据?', function(btn){
  453. if(btn == 'yes'){
  454. main.getActiveTab().setLoading(true);//loading...
  455. var cond = form.getCondition();
  456. if(Ext.isEmpty(cond)) {
  457. cond = '1=1';
  458. }
  459. var constr=form.beforeQuery(caller, cond);//执行查询前逻辑
  460. cond+=constr!=null && constr!=''?" AND ("+constr+")":"";
  461. Ext.Ajax.request({
  462. url : basePath + url,
  463. params: {
  464. caller:caller,
  465. /*param:cond + form.getOrderBy(grid),*/
  466. param:cond,
  467. type:'ALL',
  468. },
  469. method : 'post',
  470. timeout: 6000000,
  471. callback : function(options,success,response){
  472. main.getActiveTab().setLoading(false);
  473. me.dealing = false;
  474. var localJson = new Ext.decode(response.responseText);
  475. if(localJson.exceptionInfo){
  476. var str = localJson.exceptionInfo;
  477. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  478. str = str.replace('AFTERSUCCESS', '');
  479. grid.multiselected = new Array();
  480. Ext.getCmp('dealerform').onQuery();
  481. }
  482. showError(str);return;
  483. }
  484. if(localJson.success){
  485. grid.tempStore={};//操作成功后清空暂存区数据
  486. if(localJson.log){
  487. showMessage("提示", localJson.log);
  488. }
  489. grid.multiselected = new Array();
  490. Ext.getCmp('dealerform').onQuery();
  491. Ext.Msg.alert("提示", "处理成功!", function(){
  492. grid.multiselected = new Array();
  493. Ext.getCmp('dealerform').onQuery();
  494. });
  495. }
  496. }
  497. });
  498. } else if(btn == 'no'){
  499. return;
  500. }
  501. })
  502. }else{
  503. params.data = unescape(Ext.JSON.encode(data).replace(/\\/g,"%"));
  504. me.dealing = true;
  505. main.getActiveTab().setLoading(true);//loading...
  506. Ext.Ajax.request({
  507. url : basePath + url,
  508. /*params: params,*/
  509. params: {
  510. caller:caller,
  511. param:params.data,
  512. type:'',
  513. },
  514. method : 'post',
  515. timeout: 6000000,
  516. callback : function(options,success,response){
  517. main.getActiveTab().setLoading(false);
  518. me.dealing = false;
  519. var localJson = new Ext.decode(response.responseText);
  520. if(localJson.exceptionInfo){
  521. var str = localJson.exceptionInfo;
  522. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  523. str = str.replace('AFTERSUCCESS', '');
  524. grid.multiselected = new Array();
  525. Ext.getCmp('dealerform').onQuery();
  526. }
  527. showError(str);return;
  528. }
  529. if(localJson.success){
  530. grid.tempStore={};//操作成功后清空暂存区数据
  531. if(localJson.log){
  532. showMessage("提示", localJson.log);
  533. }
  534. grid.multiselected = new Array();
  535. Ext.getCmp('dealerform').onQuery();
  536. /*Ext.Msg.alert("提示", "处理成功!", function(){
  537. grid.multiselected = new Array();
  538. Ext.getCmp('dealerform').onQuery();
  539. });*/
  540. }
  541. }
  542. });
  543. }
  544. } else {
  545. showError("没有需要处理的数据!");
  546. }
  547. } else {
  548. showError("请勾选需要的明细!");
  549. }
  550. },
  551. getCurrentMonth: function(f, type, con) {
  552. Ext.Ajax.request({
  553. url: basePath + 'fa/getMonth.action',
  554. params: {
  555. type: type
  556. },
  557. callback: function(opt, s, r) {
  558. var rs = Ext.decode(r.responseText);
  559. if(rs.data) {
  560. f.setValue(rs.data.PD_DETNO);
  561. if(con != null) {
  562. con.setMonthValue(rs.data.PD_DETNO);
  563. }
  564. }
  565. }
  566. });
  567. },
  568. vastPost: function(grid, records, url) {
  569. var me = this, win = Ext.getCmp('win-post');
  570. grid._postrecords = records;
  571. if(!win) {
  572. win = Ext.create('Ext.Window', {
  573. id: 'win-post',
  574. width: '90%',
  575. height: '60%',
  576. modal: true,
  577. layout: 'anchor',
  578. items: [{
  579. xtype: 'form',
  580. anchor: '100% 100%',
  581. bodyStyle: 'background: #f1f1f1;',
  582. layout: 'column',
  583. autoScroll:true,
  584. defaults: {
  585. xtype: 'checkbox',
  586. margin: '2 10 2 10',
  587. columnWidth: .33
  588. },
  589. items: [{
  590. xtype: 'displayfield',
  591. fieldLabel: '当前账套',
  592. id: 'ma_name'
  593. },{
  594. xtype: 'displayfield',
  595. fieldLabel: '账套描述',
  596. margin: '2 10 30 10',
  597. id: 'ma_function',
  598. columnWidth: .65
  599. },{
  600. xtype: 'displayfield',
  601. fieldLabel: '目标账套',
  602. columnWidth: 1
  603. },{
  604. boxLabel: '全选',
  605. columnWidth: 1,
  606. listeners: {
  607. change: function(f) {
  608. var form = f.up('form');
  609. form.getForm().getFields().each(function(a){
  610. if(a.xtype == 'checkbox' && a.id != f.id) {
  611. a.setValue(f.value);
  612. }
  613. });
  614. }
  615. }
  616. }]
  617. }],
  618. buttonAlign: 'center',
  619. buttons: [{
  620. text: $I18N.common.button.erpConfirmButton,
  621. cls: 'x-btn-blue',
  622. handler: function(btn) {
  623. var w = btn.ownerCt.ownerCt, form = w.down('form'),
  624. from = form.down('#ma_name').value,
  625. items = form.query('checkbox[checked=true]'),
  626. data = new Array();
  627. Ext.each(items, function(item){
  628. if (item.ma_name)
  629. data.push(item.ma_name);
  630. });
  631. if(data.length > 0)
  632. me.post(w, grid, url, from, data.join(','));
  633. }
  634. },{
  635. text: $I18N.common.button.erpCloseButton,
  636. cls: 'x-btn-blue',
  637. handler: function(btn) {
  638. btn.ownerCt.ownerCt.hide();
  639. }
  640. }]
  641. });
  642. if(contains(url,'?_out=1',true)) this.getOutMasters(win);
  643. else this.getMasters(win);
  644. }
  645. win.show();
  646. },
  647. post: function(w, grid, url, from, to) {
  648. var records = grid._postrecords;
  649. w.setLoading(true);
  650. var d = new Array(), f = grid.keyField;
  651. Ext.each(records, function(r) {
  652. d.push(r.get(f));
  653. });
  654. Ext.Ajax.request({
  655. url: basePath + url,
  656. params: {
  657. caller: caller,
  658. data: d.join(','),
  659. to: to
  660. },
  661. callback: function(opt, s, r) {
  662. w.setLoading(false);
  663. if(s) {
  664. var rs = Ext.decode(r.responseText);
  665. if(rs.data) {
  666. showMessage('提示', rs.data);
  667. } else {
  668. alert('抛转成功!');
  669. }
  670. grid.multiselected = new Array();
  671. grid._postrecords = null;
  672. Ext.getCmp('dealerform').onQuery();
  673. w.hide();
  674. }
  675. }
  676. });
  677. },
  678. /**
  679. * 加载系统所有账套
  680. */
  681. getMasters: function(win){
  682. Ext.Ajax.request({
  683. url: basePath + 'common/getMasters.action',
  684. method: 'get',
  685. callback: function(opt, s, res){
  686. var r = Ext.decode(res.responseText), c = r.currentMaster;
  687. if(r.masters){
  688. var form = win.down('form'), items = new Array();
  689. for(var i in r.masters) {
  690. var d = r.masters[i];
  691. if(d.ma_name != c) {
  692. if(d.ma_type == 3) {
  693. var o = {boxLabel: d.ma_name + '(' + d.ma_function + ')', ma_name: d.ma_name};
  694. items.push(o);
  695. }
  696. } else {
  697. form.down('#ma_name').setValue(c);
  698. form.down('#ma_function').setValue(d.ma_function);
  699. }
  700. }
  701. form.add(items);
  702. }
  703. }
  704. });
  705. },
  706. getOutMasters:function(win){
  707. Ext.Ajax.request({
  708. url: basePath + 'common/getOutMasters.action',
  709. method: 'get',
  710. callback: function(opt, s, res){
  711. var r = Ext.decode(res.responseText), c = r.currentMaster;
  712. if(r.data){
  713. var form = win.down('form'), items = new Array();
  714. Ext.Array.each(r.data,function(d){
  715. var o = {boxLabel: d.MO_LOCATION + '(' + d.MO_NAME + ')', ma_name: d.MO_LOCATION};
  716. items.push(o);
  717. });
  718. form.down('#ma_name').setValue(c);
  719. //form.down('#ma_function').setValue(d.ma_function);
  720. form.add(items);
  721. }
  722. }
  723. });
  724. },
  725. refreshQty : function(cal) {
  726. var tab = null;
  727. switch(cal) {
  728. case 'Purchase!ToCheckAccept!Deal' :
  729. tab = 'Purchase';
  730. break;
  731. case 'Purchase!ToNotify!Deal' :
  732. tab = 'Purchase';
  733. break;
  734. case 'Sale!ToAccept!Deal':
  735. tab = 'Sale';
  736. break;
  737. case 'SendNotify!ToProdIN!Deal':
  738. tab = 'SendNotify';
  739. break;
  740. }
  741. var form = Ext.getCmp('dealerform');
  742. form.setLoading(true);
  743. Ext.Ajax.request({
  744. url : basePath + 'common/resetqty.action',
  745. params : {
  746. tab : tab
  747. },
  748. callback : function(opt, s, res) {
  749. form.setLoading(false);
  750. var r = Ext.decode(res.responseText);
  751. if (r.success) {
  752. alert('已转数量重置成功!');
  753. // form.onQuery();
  754. }
  755. }
  756. });
  757. },
  758. getProductWh: function(grid) {
  759. var prodfield = grid.getProdField();
  760. if(prodfield) {
  761. var codes = [];
  762. grid.store.each(function(d){
  763. codes.push("'" + d.get(prodfield) + "'");
  764. });
  765. Ext.Ajax.request({
  766. url: basePath + 'scm/product/getProductwh.action',
  767. params: {
  768. codes: codes.join(',')
  769. },
  770. callback: function (opt, s, r) {
  771. if(s) {
  772. var rs = Ext.decode(r.responseText);
  773. if(rs.data) {
  774. grid.productwh = rs.data;
  775. }
  776. }
  777. }
  778. });
  779. }
  780. },
  781. countAmount: function(grid){
  782. var me = this;
  783. var items = grid.selModel.selected.items;
  784. var countamount=0;
  785. var taxsum = 0,
  786. differ = Ext.getCmp('differ');
  787. priceFormat = grid.down('gridcolumn[dataIndex=abd_thisvoprice]').format,
  788. fsize = (priceFormat && priceFormat.indexOf('.') > -1) ?
  789. priceFormat.substr(priceFormat.indexOf('.') + 1).length : 6;
  790. Ext.each(items,function(item,index){
  791. var a = Number(item.data['abd_thisvoprice']);
  792. var b = Number(item.data['abd_thisvoqty']);
  793. var rate = Number(item.data['abd_taxrate']);
  794. countamount = countamount + Number(grid.BaseUtil.numberFormat(a*b,2));
  795. taxsum = taxsum + Number(grid.BaseUtil.numberFormat((a*b*rate/100)/(1+rate/100),2));
  796. });
  797. //金额合计 不能填写 自动显示所选数据条目的本次发票数*本次发票单价 的总和
  798. Ext.getCmp('pi_amounttotal').setValue(Ext.util.Format.number(countamount, "0.00"));
  799. if(differ && !Ext.isEmpty(differ.value)){
  800. Ext.getCmp('taxsum').setValue(Ext.util.Format.number(taxsum+differ.value, "0.00"));
  801. } else {
  802. Ext.getCmp('taxsum').setValue(Ext.util.Format.number(taxsum, "0.00"));
  803. }
  804. },
  805. //确认投放数量,在修改完计划投放数量时候点击按钮,将选中行的数量保存,并且限制不能超过建议变更数
  806. ConfirmThrowQty:function(){
  807. var grid = Ext.getCmp('batchDealerGridPanel');
  808. var count=0;
  809. if(grid.multiselected.length==0){
  810. var items = grid.selModel.getSelection();
  811. Ext.each(items, function(item, index){
  812. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  813. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  814. grid.multiselected.push(item);
  815. }
  816. });
  817. }
  818. var records = Ext.Array.unique(grid.multiselected);
  819. var gridStore = new Array();
  820. var dd;
  821. if(records.length>0){
  822. Ext.each(records, function(records, index){
  823. if(records.data.md_prodcode!=''){
  824. dd=new Object();
  825. dd['mr_mpsid']=records.data.mr_mpsid;
  826. gridStore[index] = Ext.JSON.encode(dd);
  827. count++;
  828. }
  829. });
  830. this.ConfirmThrow(gridStore);
  831. } else {
  832. showError("没有需要处理的数据!");
  833. }
  834. },
  835. ComfirmThrow:function(store){
  836. if(this.throwing) {
  837. alert('正在执行...不要重复点击!');
  838. return;
  839. }
  840. var me = this, gridstore = store;
  841. var main = parent.Ext.getCmp("content-panel");
  842. main.getActiveTab().setLoading(true);//loading...
  843. var btn = Ext.getCmp('erpConfirmThrowQtyButton');
  844. if(btn) btn.setDisabled(true);
  845. this.throwing = true;
  846. Ext.Ajax.request({
  847. url : basePath + "pm/MPSMain/NeedThrow.action",
  848. params: {
  849. mainCode:Ext.getCmp('md_mpscode').value,
  850. caller:caller,
  851. gridStore:unescape(gridstore.toString().replace(/\\/g,"%")),
  852. toWhere:'AUTO',
  853. toCode:Ext.getCmp('md_ordercode').value,
  854. condition:''
  855. },
  856. timeout: 60000,
  857. method : 'post',
  858. callback : function(options,success,response){
  859. btn.setDisabled(false);
  860. me.throwing = false;
  861. main.getActiveTab().setLoading(false);
  862. var localJson = new Ext.decode(response.responseText);
  863. if(localJson.exceptionInfo){
  864. var str = localJson.exceptionInfo;
  865. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  866. str = str.replace('AFTERSUCCESS', '');
  867. showMessage("提示", str);
  868. } else {
  869. showError(str);return;
  870. }
  871. }
  872. if(localJson.success){
  873. if(localJson.log){
  874. showMessage("提示", localJson.log);
  875. }
  876. Ext.Msg.alert("提示", "处理成功!", function(){
  877. Ext.getCmp('dealerform').onQuery();
  878. });
  879. }
  880. }
  881. });
  882. },
  883. updateMakeSub:function(d){
  884. if(d.record.dirty){
  885. if(Ext.isNumber(d.value) && (d.value==0 ||d.value>0)){
  886. Ext.Ajax.request({
  887. url : basePath + "pm/make/updateMakeSubMaterial.action",
  888. params: {
  889. data:unescape(escape(Ext.JSON.encode(d.record.data))),
  890. caller:caller
  891. },
  892. method : 'post',
  893. callback : function(options,success,response){
  894. var localJson = new Ext.decode(response.responseText);
  895. if(localJson.exceptionInfo){
  896. d.record.set('mp_canuseqty',d.originalValue);
  897. showError(localJson.exceptionInfo);
  898. }
  899. if(localJson.success){
  900. d.record.commit();
  901. showMessage("提示", "修改锁库数量成功");
  902. }
  903. }
  904. });
  905. }else{
  906. d.record.set('mp_canuseqty',d.originalValue);
  907. }
  908. }
  909. }
  910. });