PayPlease2.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.arp.PayPlease2', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. ppdid:0,
  8. views:[
  9. 'core.form.Panel','fa.arp.PayPlease2','fa.arp.payplease.PayPleaseDetailDetGrid2','fa.arp.payplease.PayPleaseDetailGrid','core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  10. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.ResAccounted','core.button.AssMain','core.button.Accounted','core.form.FileField',
  11. 'core.button.StrikeBalance','core.grid.AssPanel','core.window.AssWindow','core.trigger.CateTreeDbfindTrigger','core.trigger.HrOrgTreeDbfindTrigger',
  12. 'core.button.Post','core.button.ResPost','core.button.Print','core.button.Submit','core.button.ResAudit','core.button.Audit','core.button.ResSubmit',
  13. 'erp.view.core.button.AddDetail','erp.view.core.button.DeleteDetail','erp.view.core.button.Copy','erp.view.core.button.Paste','erp.view.core.button.Up',
  14. 'erp.view.core.button.Down','erp.view.core.button.UpExcel','core.button.TurnPayBalance','core.button.TurnBankRegister',
  15. 'core.trigger.MultiDbfindTrigger', 'core.form.SeparNumber','core.form.MultiField','core.button.GetSumAmount'
  16. ],
  17. init:function(){
  18. var me = this;
  19. me.gridLastSelected = null;
  20. this.control({
  21. 'textfield[name=pp_thispayamount]':{
  22. beforerender: function(field){
  23. field.readOnly=false;
  24. }
  25. },
  26. 'erpGetSumAmountButton':{
  27. click: function(btn){
  28. var grid1 = Ext.getCmp("paypleasedetailGrid"),grid2 = Ext.getCmp("paypleasedetaildetGrid2"),items1 = grid1.store.data.items,items2 = grid2.store.data.items;
  29. var detailamount1 = 0;
  30. var detailamount2 = 0;
  31. Ext.each(items2,function(item,index){
  32. if(!me.GridUtil.isBlank(grid2,item.data)) {
  33. detailamount2 = detailamount2 + Number(item.data['ppdd_thisapplyamount']);
  34. }
  35. });
  36. me.gridLastSelected.set('ppd_applyamount',detailamount2);
  37. }
  38. },
  39. //第一个从表
  40. 'paypleasedetailGrid':{
  41. itemclick:me.onGridItemClick1,
  42. afterrender:function(grid){
  43. grid.plugins[0].on('afteredit',function(e){
  44. setTimeout(function(){
  45. var amount = 0;
  46. Ext.each(grid.store.data.items,function(item,index){
  47. amount=amount+Number(item.data['ppd_applyamount']);
  48. });
  49. Ext.getCmp('pp_total').setValue(Ext.util.Format.number(amount,'0.00'));
  50. },200);
  51. });
  52. }
  53. },
  54. //第二个从表
  55. 'paypleasedetaildetGrid2':{
  56. afterrender: function(g) {
  57. g.plugins[0].on('beforeedit', function(args) {
  58. var bool = true;
  59. if (args.field == "ppdd_pucode") {
  60. if (!Ext.isEmpty(args.record.get('ppdd_makecode'))){
  61. bool = false;
  62. }
  63. return bool;
  64. }
  65. if (args.field == "ppdd_makecode") {
  66. if (!Ext.isEmpty(args.record.get('ppdd_pucode'))){
  67. bool = false;
  68. }
  69. return bool;
  70. }
  71. });
  72. },
  73. itemclick:me.onGridItemClick2
  74. },
  75. //转付款单
  76. 'erpTurnPayBalanceButton':{
  77. click:function(btn){
  78. me.turnPayBalance();
  79. },
  80. afterrender: function(btn){
  81. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  82. if(status && status.value != 'AUDITED'){
  83. btn.hide();
  84. }
  85. }
  86. },
  87. //转银行登记
  88. 'erpTurnBankRegisterButton':{
  89. click:function(btn){
  90. me.turnBankRegister();
  91. },
  92. afterrender: function(btn){
  93. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  94. if(status && status.value != 'AUDITED'){
  95. btn.hide();
  96. }
  97. }
  98. },
  99. 'erpSaveButton': {
  100. click: function(btn){
  101. var form = me.getForm(btn);
  102. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  103. me.BaseUtil.getRandomNumber();
  104. }
  105. //保存之前的一些前台的逻辑判定
  106. this.beforeSavePayPlease();
  107. }
  108. },
  109. 'erpDeleteButton' : {
  110. click: function(btn){
  111. me.FormUtil.onDelete(Ext.getCmp('pp_id').value);
  112. }
  113. },
  114. 'erpUpdateButton': {
  115. click: function(btn){
  116. this.beforeUpdatePayPlease();
  117. }
  118. },
  119. 'erpAddButton': {
  120. click: function(){
  121. me.FormUtil.onAdd('addPayPlease', '新增预付款申请单', 'jsps/fa/arp/payplease2.jsp');
  122. }
  123. },
  124. 'erpCloseButton': {
  125. click: function(btn){
  126. me.FormUtil.beforeClose(me);
  127. }
  128. },
  129. 'erpSubmitButton': {
  130. afterrender: function(btn){
  131. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  132. if(status && status.value != 'ENTERING'){
  133. btn.hide();
  134. }
  135. },
  136. click: function(btn){
  137. me.beforeSubmit(btn);
  138. }
  139. },
  140. 'erpResSubmitButton': {
  141. afterrender: function(btn){
  142. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  143. if(status && status.value != 'COMMITED'){
  144. btn.hide();
  145. }
  146. },
  147. click: function(btn){
  148. me.FormUtil.onResSubmit(Ext.getCmp('pp_id').value);
  149. }
  150. },
  151. 'erpAuditButton': {
  152. afterrender: function(btn){
  153. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  154. if(status && status.value != 'COMMITED'){
  155. btn.hide();
  156. }
  157. },
  158. click: function(btn){
  159. me.FormUtil.onAudit(Ext.getCmp('pp_id').value);
  160. }
  161. },
  162. 'erpResAuditButton': {
  163. afterrender: function(btn){
  164. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  165. if(status && status.value != 'AUDITED'){
  166. btn.hide();
  167. }
  168. },
  169. click: function(btn){
  170. me.FormUtil.onResAudit(Ext.getCmp('pp_id').value);
  171. }
  172. },
  173. 'erpPrintButton': {
  174. click: function(btn){
  175. var reportName="APPay_app2";
  176. var condition = '{PayPlease.pp_id}=' + Ext.getCmp('pp_id').value + '';
  177. var id = Ext.getCmp('pp_id').value;
  178. me.FormUtil.onwindowsPrint(id, reportName, condition);
  179. }
  180. },
  181. 'dbfindtrigger[name=ppdd_pucode]':{
  182. focus: function(t){
  183. t.setHideTrigger(false);
  184. t.setReadOnly(false);
  185. var record = Ext.getCmp('paypleasedetailGrid').selModel.selected.first();
  186. if(!record || !record.data['ppd_vendcode']) {
  187. showError("请先选择供应商!");
  188. t.setHideTrigger(true);
  189. t.setReadOnly(true);
  190. } else {
  191. var code = record.data['ppd_vendcode'];
  192. t.dbBaseCondition = " pu_vendcode = '" + code + "'";
  193. }
  194. }
  195. },
  196. 'multidbfindtrigger[name=ppdd_pucode]':{
  197. focus: function(t){
  198. t.setHideTrigger(false);
  199. t.setReadOnly(false);
  200. var record = Ext.getCmp('paypleasedetailGrid').selModel.selected.first();
  201. if(!record || !record.data['ppd_vendcode']) {
  202. showError("请先选择供应商!");
  203. t.setHideTrigger(true);
  204. t.setReadOnly(true);
  205. } else {
  206. var code = record.data['ppd_vendcode'];
  207. t.dbBaseCondition = " pu_vendcode = '" + code + "'";
  208. }
  209. }
  210. },
  211. 'dbfindtrigger[name=ppdd_makecode]':{
  212. focus: function(t){
  213. t.setHideTrigger(false);
  214. t.setReadOnly(false);
  215. var record = Ext.getCmp('paypleasedetailGrid').selModel.selected.first();
  216. if(!record || !record.data['ppd_vendcode']) {
  217. showError("请先选择供应商!");
  218. t.setHideTrigger(true);
  219. t.setReadOnly(true);
  220. } else {
  221. var code = record.data['ppd_vendcode'];
  222. t.dbBaseCondition = " ma_vendcode = '" + code + "'";
  223. }
  224. }
  225. },
  226. 'multidbfindtrigger[name=ppdd_makecode]':{
  227. focus: function(t){
  228. t.setHideTrigger(false);
  229. t.setReadOnly(false);
  230. var record = Ext.getCmp('paypleasedetailGrid').selModel.selected.first();
  231. if(!record || !record.data['ppd_vendcode']) {
  232. showError("请先选择供应商!");
  233. t.setHideTrigger(true);
  234. t.setReadOnly(true);
  235. } else {
  236. var code = record.data['ppd_vendcode'];
  237. t.dbBaseCondition = " ma_vendcode = '" + code + "'";
  238. }
  239. }
  240. }
  241. });
  242. },
  243. turnPayBalance: function(){
  244. var grid = Ext.getCmp('paypleasedetailGrid');
  245. var items = grid.selModel.getSelection();
  246. if(items.length==0){
  247. Ext.Msg.alert('警告','请勾选需要转预付款单的明细行!');
  248. return;
  249. }
  250. Ext.each(items, function(item, index){
  251. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  252. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  253. grid.multiselected.push(item);
  254. }
  255. });
  256. var form = Ext.getCmp('form');
  257. var records = Ext.Array.unique(grid.multiselected);
  258. var r = form.getValues();
  259. if(records.length > 0){
  260. var params = new Object();
  261. params.caller = caller;
  262. var data = new Array();
  263. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  264. var bool = false;
  265. Ext.each(records, function(record, index){
  266. var f = form.fo_detailMainKeyField;
  267. if(((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  268. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  269. ||(f && this.data[f] != null && this.data[f] != ''
  270. && this.data[f] != '0' && this.data[f] != 0))&&(record.data['ppd_statuscode']!='TURNPP')){
  271. bool = true;
  272. var o = new Object();
  273. if(grid.keyField){
  274. o[grid.keyField] = record.data[grid.keyField];
  275. } else {
  276. params.id[index] = record.data[form.fo_detailMainKeyField];
  277. }
  278. if(grid.toField){
  279. Ext.each(grid.toField, function(f, index){
  280. var v = Ext.getCmp(f).value;
  281. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  282. o[f] = v;
  283. }
  284. });
  285. }
  286. if(grid.necessaryFields){
  287. Ext.each(grid.necessaryFields, function(f, index){
  288. var v = record.data[f];
  289. if(Ext.isDate(v)){
  290. v = Ext.Date.toString(v);
  291. }
  292. o[f] = v;
  293. });
  294. }
  295. data.push(o);
  296. }
  297. });
  298. if(bool){
  299. params.data = Ext.encode(data);
  300. var main = parent.Ext.getCmp("content-panel");
  301. main.getActiveTab().setLoading(true);//loading...
  302. Ext.Ajax.request({
  303. url : basePath + 'fa/PayPleaseController/turnPayBalance.action',
  304. params: params,
  305. method : 'post',
  306. callback : function(options,success,response){
  307. main.getActiveTab().setLoading(false);
  308. var localJson = new Ext.decode(response.responseText);
  309. if(localJson.exceptionInfo){
  310. showError(localJson.exceptionInfo);
  311. return "";
  312. }
  313. if(localJson.success){
  314. if(localJson.log){
  315. showMessage("提示", localJson.log);
  316. }
  317. Ext.Msg.alert("提示", "处理成功!", function(){
  318. var me = this;
  319. //add成功后刷新页面进入可编辑的页面
  320. var value = r[form.keyField];
  321. var formCondition = form.keyField + "IS" + value ;
  322. if(me.contains(window.location.href, '?', true)){
  323. window.location.href = window.location.href + '&formCondition=' +
  324. formCondition;
  325. } else {
  326. window.location.href = window.location.href + '?formCondition=' +
  327. formCondition;
  328. }
  329. });
  330. }
  331. }
  332. });
  333. } else {
  334. showError("没有需要处理的数据!");
  335. }
  336. }
  337. },
  338. //点击第一个grid
  339. onGridItemClick1: function(selModel,record){
  340. var me = this;
  341. me.gridLastSelected = record;
  342. var ppd_id = record.data['ppd_id'];
  343. this.ppdid = ppd_id;
  344. var grid = Ext.getCmp('paypleasedetailGrid');
  345. var ppddgrid = Ext.getCmp('paypleasedetaildetGrid2');
  346. if(ppd_id > 0 && !me.GridUtil.isBlank(grid,record.data)){
  347. var condition = "ppdd_ppdid='"+ppd_id+"'";
  348. ppddgrid.getMyData(condition);
  349. }
  350. this.onGridItemClick(selModel,record,'paypleasedetailGrid');
  351. },
  352. //点击第二个GRID
  353. onGridItemClick2: function(selModel,record){
  354. this.onGridItemClick(selModel,record,'paypleasedetaildetGrid2');
  355. },
  356. onGridItemClick: function(selModel, record,id){//grid行选择
  357. this.GridUtil.onGridItemClick(selModel, record,id);
  358. },
  359. getForm: function(btn){
  360. return btn.ownerCt.ownerCt;
  361. },
  362. beforeSavePayPlease: function(){
  363. this.beforeSave();
  364. },
  365. beforeUpdatePayPlease:function(){
  366. var s = ' ';
  367. var ppdgrid = Ext.getCmp('paypleasedetailGrid');
  368. var items = ppdgrid.store.data.items;
  369. var bool = true;
  370. var amount = 0;
  371. Ext.each(items,function(item){
  372. var keys = Ext.Object.getKeys(item.modified);
  373. Ext.each(keys,function(key){
  374. if(key=='ppd_auditamount'||key=='ppd_ifpay'){
  375. item.set('ppd_editor',em_name);
  376. item.set('ppd_editorid',em_uu);
  377. }
  378. });
  379. var applyamount = item.data['ppd_applyamount'];
  380. var auditamount = item.data['ppd_auditamount'];
  381. if(applyamount<auditamount){
  382. s=s+(item.index+1)+' ';
  383. bool=false;
  384. }
  385. amount=amount+Number(applyamount);
  386. });
  387. if(bool){
  388. this.beforeUpdate();
  389. }else{
  390. showError($I18N.common.grid.auditApplyPayPlease1 + s + $I18N.common.grid.auditApplyPayPlease2);
  391. }
  392. },
  393. /**
  394. * 检查form未完善的字段
  395. */
  396. checkForm: function(){
  397. var s = '';
  398. var form = Ext.getCmp('form');
  399. form.getForm().getFields().each(function (item,index,length){
  400. if(!item.isValid()){
  401. if(s != ''){
  402. s = s + ',';
  403. }
  404. if(item.fieldLabel){
  405. s = s + item.fieldLabel.replace(/&nbsp;/g,'');
  406. }
  407. }
  408. });
  409. if(s == ''){
  410. return true;
  411. }
  412. showError($I18N.common.form.necessaryInfo1 + '(<font color=green>'+s+'</font>)' + $I18N.common.form.necessaryInfo2);
  413. return false;
  414. },
  415. beforeUpdate: function(me){
  416. var mm = this;
  417. if(! this.checkForm()){
  418. return;
  419. }
  420. var grids = Ext.ComponentQuery.query('paypleasedetailGrid');
  421. var gridsDet = Ext.ComponentQuery.query('paypleasedetaildetGrid2');
  422. var currency1 = '';
  423. if(this.gridLastSelected){
  424. if(this.gridLastSelected.data['ppd_id']){
  425. currency1 = this.gridLastSelected.data['ppd_currency'];
  426. mm.ppdid = this.gridLastSelected.data['ppd_id'];
  427. }
  428. }else{
  429. currency1 = grids[0].store.data.items[0].data['ppd_currency'];
  430. }
  431. var sameCurrency = true;
  432. Ext.each(gridsDet[0].store.data.items,function(item, index){
  433. if(item.dirty && !mm.GridUtil.isBlank(gridsDet[0], item.data)){
  434. var thisapplyamount = item.data['ppdd_thisapplyamount'];
  435. if(thisapplyamount == 0 || thisapplyamount == null){
  436. showError('明细表第' + item.data['ppdd_detno'] + '行本次申请金额不能为空!');return;
  437. return;
  438. }
  439. if(item.data['ppdd_currency'] != currency1){
  440. sameCurrency = false;
  441. }
  442. }
  443. });
  444. if(!sameCurrency){
  445. showError($I18N.common.msg.failure_update_currency);
  446. return;
  447. }
  448. if(mm.ppdid == 0 || mm.ppdid == null){
  449. if(grids[0]){
  450. mm.ppdid = grids[0].store.data.items[0].data['ppd_id'];
  451. }else{
  452. mm.ppdid = 0;
  453. }
  454. }
  455. //如果ppdid == 0 则次页面为新建页面 活着以前也没有在grid1中添加数据
  456. //grid1 中的数据
  457. var param1 = mm.GridUtil.getGridStore(grids[0]);
  458. //grid2中的数据
  459. var param2 = mm.getGridStoreDet(gridsDet[0]);
  460. //ppdid==0的情况为 grid1第一条没有数据的情况 次情况只能保存grid1中的数据 grid2中的数据保存不上
  461. //如果ppdid!=0 则可能的情况为 1.点击grid1选择了一条数据 2.没有点击grid1 但是grid1中有数据 此时
  462. //grid2中的数据自动保存在grid1中第一条数据下
  463. if(mm.ppdid == 0){
  464. if(param2 == null || param2 == ''){
  465. //此时grid2数据为空 可以保存grid1的数据
  466. mm.onUpdate(param1);
  467. }else{
  468. warnMsg('不能保存从表二中的数据,是否只保存从表一?',function(btn){
  469. if(btn =='yes'){
  470. //保存从表一中的数据
  471. mm.onUpdate(param1);
  472. }else{
  473. //return
  474. return;
  475. }
  476. });
  477. }
  478. }else{
  479. if(param2 ==null||param2==''){
  480. mm.onUpdate(param1);
  481. }else{
  482. mm.onUpdate(param1,param2);
  483. }
  484. }
  485. },
  486. beforeSave: function(me){
  487. var mm = this;
  488. var form = Ext.getCmp('form');
  489. if(! this.checkForm()){
  490. return;
  491. }
  492. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  493. mm.FormUtil.getSeqId(form);
  494. }
  495. var grids = Ext.getCmp('paypleasedetailGrid');
  496. var gridsDet = Ext.getCmp('paypleasedetaildetGrid2');
  497. var currency1 = '';
  498. if(this.gridLastSelected){
  499. currency1 = this.gridLastSelected.data['ppd_currency'];
  500. mm.ppdid = this.gridLastSelected.data['ppd_id'];
  501. } else{
  502. currency1 = grids.store.first().data['ppd_currency'];
  503. }
  504. var sameCurrency = true;
  505. Ext.each(gridsDet.store.data.items,function(item, index){
  506. if(item.dirty && !mm.GridUtil.isBlank(gridsDet,item.data)){
  507. if(item.data['ppdd_currency'] != currency1){
  508. sameCurrency = false;
  509. }
  510. }
  511. });
  512. if(mm.ppdid == 0 || mm.ppdid == null){
  513. if(grids[0]){
  514. mm.ppdid = grids[0].store.data.items[0].data['ppd_id'];
  515. }else{
  516. mm.ppdid = 0;
  517. }
  518. }
  519. //如果ppdid == 0 则次页面为新建页面 活着以前也没有在grid1中添加数据
  520. //grid1 中的数据
  521. var param1 = mm.GridUtil.getGridStore(grids);
  522. //grid2中的数据
  523. var param2 = mm.getGridStoreDet(gridsDet);
  524. //ppdid==0的情况为 grid1第一条没有数据的情况 次情况只能保存grid1中的数据 grid2中的数据保存不上
  525. //如果ppdid!=0 则可能的情况为 1.点击grid1选择了一条数据 2.没有点击grid1 但是grid1中有数据 此时
  526. //grid2中的数据自动保存在grid1中第一条数据下
  527. if(mm.ppdid == 0){
  528. if(param2 == null || param2 == ''){
  529. //此时grid2数据为空 可以保存grid1的数据
  530. mm.onSave(param1);
  531. }else{
  532. warnMsg('不能保存从表二中的数据,是否只保存从表一?',function(btn){
  533. if(btn =='yes'){
  534. //保存从表一中的数据
  535. mm.onSave(param1);
  536. }else{
  537. //return
  538. return;
  539. }
  540. });
  541. }
  542. }else{
  543. if(param2 ==null||param2==''){
  544. mm.onSave(param1);
  545. }else{
  546. mm.onSave(param1,param2);
  547. }
  548. }
  549. },
  550. beforeSubmit: function(){
  551. var me = this;
  552. var grid2 = Ext.getCmp('paypleasedetaildetGrid2'),items2=grid2.store.data.items;
  553. var bool = true;
  554. Ext.each(items2,function(item,index){
  555. if(!me.GridUtil.isBlank(grid2, item.data)){
  556. if(Math.abs(Number(item.data['ppdd_billamount']))<Math.abs(Number(item.data['ppdd_account']))){
  557. bool = false;
  558. showError('采购单的已预付金额大于采购金额,不能提交');return;
  559. }
  560. if(!Ext.isEmpty(item.get('ppdd_ordercode'))) {
  561. if(Math.abs(Number(item.data['ppdd_billamount'])-Number(item.data['ppdd_account'])) < Math.abs(Number(item.data['ppdd_thisapplyamount']))){
  562. bool = false;
  563. showError('本次预付金额大于采购单未付的金额,不能提交');return;
  564. }
  565. }
  566. }
  567. });
  568. if(bool)
  569. me.FormUtil.onSubmit(Ext.getCmp('pp_id').value);
  570. },
  571. /**
  572. * 拿到grid里面要提交的数据
  573. */
  574. getGridStoreDet: function(grid){
  575. if(grid == null){
  576. grid = Ext.getCmp('grid');
  577. }
  578. var jsonGridData = new Array();
  579. var s = grid.getStore().data.items;//获取store里面的数据
  580. var dd;
  581. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  582. var data = s[i].data;
  583. dd = new Object();
  584. if(s[i].dirty && !grid.GridUtil.isBlank(grid, data)){
  585. Ext.each(grid.columns, function(c){
  586. if(c.logic != 'ignore'){//只需显示,无需后台操作的字段,自动略去
  587. if(c.xtype == 'datecolumn'){
  588. if(Ext.isDate(data[c.dataIndex])){
  589. dd[c.dataIndex] = Ext.Date.toString(data[c.dataIndex]);//在这里把GMT日期转化成Y-m-d格式日期
  590. } else {
  591. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d');//如果用户没输入日期,或输入有误,就给个默认日期,
  592. //或干脆return;并且提示一下用户
  593. }
  594. } else if(c.xtype == 'datetimecolumn'){
  595. if(Ext.isDate(data[c.dataIndex])){
  596. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
  597. } else {
  598. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
  599. }
  600. } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  601. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  602. dd[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  603. } else {
  604. dd[c.dataIndex] = String(s[i].data[c.dataIndex]);
  605. }
  606. } else {
  607. dd[c.dataIndex] = s[i].data[c.dataIndex];
  608. }
  609. }
  610. });
  611. if(grid.mainField){//例如,将pu_id的值赋给pd_puid
  612. dd[grid.mainField] = this.ppdid;
  613. }
  614. jsonGridData.push(Ext.JSON.encode(dd));
  615. }
  616. }
  617. return jsonGridData;
  618. },
  619. onUpdate:function(param1,param2){
  620. var me = this;
  621. var form =Ext.getCmp('form');
  622. param1 = param1 == null ? [] : "[" + param1.toString() + "]";
  623. param2 = param2 == null ? [] : "[" + param2.toString() + "]";
  624. if(form.getForm().isValid()){
  625. //form里面数据
  626. Ext.each(form.items.items, function(item){
  627. if(item.xtype == 'numberfield'){
  628. //number类型赋默认值,不然sql无法执行
  629. if(item.value == null || item.value == ''){
  630. item.setValue(0);
  631. }
  632. }
  633. });
  634. var r = form.getValues();
  635. if(!me.contains(form.updateUrl, '?caller=', true)){
  636. form.updateUrl = form.updateUrl + "?caller=" + caller;
  637. }
  638. me.update(r, param1,param2);
  639. }else{
  640. me.checkForm();
  641. }
  642. },
  643. onSave:function(param1,param2){
  644. var me = this;
  645. var form =Ext.getCmp('form');
  646. param1 = param1 == null ? [] : "[" + param1.toString() + "]";
  647. param2 = param2 == null ? [] : "[" + param2.toString() + "]";
  648. if(form.getForm().isValid()){
  649. //form里面数据
  650. Ext.each(form.items.items, function(item){
  651. if(item.xtype == 'numberfield'){
  652. //number类型赋默认值,不然sql无法执行
  653. if(item.value == null || item.value == ''){
  654. item.setValue(0);
  655. }
  656. }
  657. });
  658. var r = form.getValues();
  659. if(!me.contains(form.saveUrl, '?caller=', true)){
  660. form.saveUrl = form.saveUrl + "?caller=" + caller;
  661. }
  662. me.save(r, param1,param2);
  663. }else{
  664. me.checkForm();
  665. }
  666. },
  667. /*
  668. * 修改
  669. */
  670. update:function(){
  671. var params = new Object();
  672. var r = arguments[0];
  673. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  674. if(contains(k, 'ext-', true)){
  675. delete r[k];
  676. }
  677. });
  678. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  679. params.param1 = unescape(arguments[1].toString().replace(/\\/g,"%"));
  680. for(var i=2; i<arguments.length; i++) { //兼容多参数
  681. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  682. }
  683. var me = this;
  684. var form = Ext.getCmp('form');
  685. me.getActiveTab().setLoading(true);//loading...
  686. Ext.Ajax.request({
  687. url : basePath + form.updateUrl,
  688. params : params,
  689. method : 'post',
  690. callback : function(options,success,response){
  691. me.getActiveTab().setLoading(false);
  692. var localJson = new Ext.decode(response.responseText);
  693. if(localJson.success){
  694. saveSuccess(function(){
  695. //add成功后刷新页面进入可编辑的页面
  696. var value = r[form.keyField];
  697. var formCondition = form.keyField + "IS" + value ;
  698. if(me.contains(window.location.href, '?', true)){
  699. window.location.href = window.location.href + '&formCondition=' +
  700. formCondition;
  701. } else {
  702. window.location.href = window.location.href + '?formCondition=' +
  703. formCondition;
  704. }
  705. });
  706. } else if(localJson.exceptionInfo){
  707. var str = localJson.exceptionInfo;
  708. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  709. str = str.replace('AFTERSUCCESS', '');
  710. saveSuccess(function(){
  711. //add成功后刷新页面进入可编辑的页面
  712. var value = r[form.keyField];
  713. var formCondition = form.keyField + "IS" + value ;
  714. if(me.contains(window.location.href, '?', true)){
  715. window.location.href = window.location.href + '&formCondition=' +
  716. formCondition;
  717. } else {
  718. window.location.href = window.location.href + '?formCondition=' +
  719. formCondition;
  720. }
  721. });
  722. showError(str);
  723. } else {
  724. showError(str);
  725. return;
  726. }
  727. } else{
  728. saveFailure();//@i18n/i18n.js
  729. }
  730. }
  731. });
  732. },
  733. /**
  734. * 保存
  735. */
  736. save: function(){
  737. var params = new Object();
  738. var r = arguments[0];
  739. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  740. if(contains(k, 'ext-', true)){
  741. delete r[k];
  742. }
  743. });
  744. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  745. params.param1 = unescape(arguments[1].toString().replace(/\\/g,"%"));
  746. for(var i=2; i<arguments.length; i++) { //兼容多参数
  747. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  748. }
  749. var me = this;
  750. var form = Ext.getCmp('form');
  751. me.getActiveTab().setLoading(true);//loading...
  752. Ext.Ajax.request({
  753. url : basePath + form.saveUrl,
  754. params : params,
  755. method : 'post',
  756. callback : function(options,success,response){
  757. me.getActiveTab().setLoading(false);
  758. var localJson = new Ext.decode(response.responseText);
  759. if(localJson.success){
  760. saveSuccess(function(){
  761. //add成功后刷新页面进入可编辑的页面
  762. var value = r[form.keyField];
  763. var formCondition = form.keyField + "IS" + value ;
  764. if(me.contains(window.location.href, '?', true)){
  765. window.location.href = window.location.href + '&formCondition=' +
  766. formCondition;
  767. } else {
  768. window.location.href = window.location.href + '?formCondition=' +
  769. formCondition;
  770. }
  771. });
  772. } else if(localJson.exceptionInfo){
  773. var str = localJson.exceptionInfo;
  774. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  775. str = str.replace('AFTERSUCCESS', '');
  776. saveSuccess(function(){
  777. //add成功后刷新页面进入可编辑的页面
  778. var value = r[form.keyField];
  779. var formCondition = form.keyField + "IS" + value ;
  780. if(me.contains(window.location.href, '?', true)){
  781. window.location.href = window.location.href + '&formCondition=' +
  782. formCondition;
  783. } else {
  784. window.location.href = window.location.href + '?formCondition=' +
  785. formCondition;
  786. }
  787. });
  788. showError(str);
  789. } else {
  790. showError(str);
  791. return;
  792. }
  793. } else{
  794. saveFailure();//@i18n/i18n.js
  795. }
  796. }
  797. });
  798. },
  799. getActiveTab: function(){
  800. var tab = null;
  801. if(Ext.getCmp("content-panel")){
  802. tab = Ext.getCmp("content-panel").getActiveTab();
  803. }
  804. if(!tab && parent.Ext.getCmp("content-panel"))
  805. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  806. if(!tab && parent.parent.Ext.getCmp("content-panel"))
  807. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  808. if(!tab){
  809. var win = parent.Ext.ComponentQuery.query('window');
  810. if(win.length > 0){
  811. tab = win[win.length-1];
  812. }
  813. }
  814. return tab;
  815. },
  816. /**
  817. * string:原始字符串
  818. * substr:子字符串
  819. * isIgnoreCase:忽略大小写
  820. */
  821. contains: function(string,substr,isIgnoreCase){
  822. if(isIgnoreCase){
  823. string=string.toLowerCase();
  824. substr=substr.toLowerCase();
  825. }
  826. var startChar=substr.substring(0,1);
  827. var strLen=substr.length;
  828. for(var j=0;j<string.length-strLen+1;j++){
  829. if(string.charAt(j)==startChar){//如果匹配起始字符,开始查找
  830. if(string.substring(j,j+strLen)==substr){//如果从j开始的字符与str匹配,那ok
  831. return true;
  832. }
  833. }
  834. }
  835. return false;
  836. },
  837. turnBankRegister: function(){
  838. var grid = Ext.getCmp('paypleasedetailGrid'), catecode = Ext.getCmp('pp_paymentcode').value;
  839. var items = grid.selModel.getSelection();
  840. var thisamount = Ext.getCmp('pp_thispayamount').value, amount = 0;
  841. var ppamount = Ext.getCmp('pp_total').value;
  842. Ext.each(grid.store.data.items,function(item,index){
  843. amount=amount+Number(item.data['ppd_account']);
  844. });
  845. if(thisamount-(ppamount-amount)>0.01){
  846. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  847. }
  848. if(items.length==0){
  849. Ext.Msg.alert('警告','请勾选需要转银行登记的明细行!');
  850. return;
  851. }
  852. if(catecode == null || catecode == ''){
  853. Ext.Msg.alert('警告','请填写需要转银行登记的付款方信息!');
  854. return;
  855. }
  856. if(thisamount == null || thisamount=='' || thisamount==0){
  857. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  858. }
  859. Ext.each(items, function(item, index){
  860. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  861. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  862. grid.multiselected.push(item);
  863. }
  864. });
  865. var form = Ext.getCmp('form');
  866. var records = Ext.Array.unique(grid.multiselected);
  867. var r = form.getValues();
  868. if(records.length > 0){
  869. var params = new Object();
  870. params.caller = caller;
  871. var data = new Array();
  872. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  873. var bool = false;
  874. Ext.each(records, function(record, index){
  875. var f = form.fo_detailMainKeyField;
  876. if(((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  877. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  878. ||(f && this.data[f] != null && this.data[f] != ''
  879. && this.data[f] != '0' && this.data[f] != 0))&&(record.data['ppd_statuscode']!='TURNPB')){
  880. bool = true;
  881. var o = new Object();
  882. if(grid.keyField){
  883. o[grid.keyField] = record.data[grid.keyField];
  884. } else {
  885. params.id[index] = record.data[form.fo_detailMainKeyField];
  886. }
  887. if(grid.toField){
  888. Ext.each(grid.toField, function(f, index){
  889. var v = Ext.getCmp(f).value;
  890. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  891. o[f] = v;
  892. }
  893. });
  894. }
  895. if(grid.necessaryFields){
  896. Ext.each(grid.necessaryFields, function(f, index){
  897. var v = record.data[f];
  898. if(Ext.isDate(v)){
  899. v = Ext.Date.toString(v);
  900. }
  901. o[f] = v;
  902. });
  903. }
  904. data.push(o);
  905. }
  906. });
  907. if(bool){
  908. params.data = Ext.encode(data);
  909. var main = parent.Ext.getCmp("content-panel");
  910. main.getActiveTab().setLoading(true);//loading...
  911. Ext.Ajax.request({
  912. url : basePath + 'fa/PayPleaseController/turnBankRegister.action',
  913. params: params,
  914. method : 'post',
  915. callback : function(options,success,response){
  916. main.getActiveTab().setLoading(false);
  917. var localJson = new Ext.decode(response.responseText);
  918. if(localJson.exceptionInfo){
  919. showError(localJson.exceptionInfo);
  920. return "";
  921. }
  922. if(localJson.success){
  923. if(localJson.log){
  924. showMessage("提示", localJson.log);
  925. }
  926. Ext.Msg.alert("提示", "处理成功!", function(){
  927. var me = this;
  928. //add成功后刷新页面进入可编辑的页面
  929. var value = r[form.keyField];
  930. var formCondition = form.keyField + "IS" + value ;
  931. if(me.contains(window.location.href, '?', true)){
  932. window.location.href = window.location.href + '&formCondition=' +
  933. formCondition;
  934. } else {
  935. window.location.href = window.location.href + '?formCondition=' +
  936. formCondition;
  937. }
  938. });
  939. }
  940. }
  941. });
  942. } else {
  943. showError("没有需要处理的数据!");
  944. }
  945. }
  946. }
  947. });