DeptCost.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.gla.DeptCost', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views: ['core.trigger.DbfindTrigger', 'fa.gla.DeptCost', 'fa.gla.DeptCostGrid', 'core.form.MonthDateField', 'core.trigger.CateTreeDbfindTrigger',
  7. 'core.form.ConMonthDateField', 'core.form.ConDateField', 'core.form.YearDateField', 'core.trigger.MultiDbfindTrigger'],
  8. init:function(){
  9. var me = this;
  10. this.control({
  11. 'button[id=query]': {
  12. afterrender: function(btn) {
  13. setTimeout(function(){
  14. var y = getUrlParam('y'),
  15. c = getUrlParam('c'),
  16. cr = getUrlParam('cr'),
  17. at = getUrlParam('at'),
  18. ac = getUrlParam('ac'),
  19. an = getUrlParam('an'),
  20. un = getUrlParam('un');
  21. me.showFilterPanel(btn, y, c, cr, at, ac, an, un);
  22. me.getCateSetting();
  23. if(y && y != 'undefined') {
  24. var fl = Ext.getCmp('query-filter'),
  25. con = me.getCondition(fl);
  26. con.querytype = 'current';
  27. me.query(con);
  28. }
  29. }, 200);
  30. },
  31. click: function(btn) {
  32. me.showFilterPanel(btn);
  33. }
  34. },
  35. 'deptcostgrid': {
  36. itemclick: function(selModel, record) {
  37. me.loadVoucher(record);
  38. }
  39. },
  40. 'button[name=export]': {
  41. click: function() {
  42. var grid = Ext.getCmp('deptcost');
  43. me.BaseUtil.exportGrid(grid, '部门费用');
  44. }
  45. }
  46. });
  47. },
  48. getCateSetting : function() {
  49. var me = this;
  50. Ext.Ajax.request({
  51. url : basePath + 'common/getFieldData.action',
  52. params: {
  53. caller: 'Setting',
  54. field: 'se_value',
  55. condition: 'se_what=\'CateTreeSearch\''
  56. },
  57. method : 'post',
  58. async : false,
  59. callback : function(opt, s, res){
  60. var r = new Ext.decode(res.responseText);
  61. if(r.exceptionInfo){
  62. showError(r.exceptionInfo);
  63. } else if(r.success && r.data == 'true' ){
  64. me.CateTreeSearch = true;
  65. }
  66. }
  67. });
  68. },
  69. showFilterPanel: function(btn, ym, caCode, curr, at, ac, an, un) {
  70. var filter = Ext.getCmp(btn.getId() + '-filter');
  71. if(!filter) {
  72. filter = this.createFilterPanel(btn);
  73. }
  74. filter.show();
  75. if(ym && ym != 'undefined') {
  76. filter.down('#sl_yearmonth').setValue(ym);
  77. filter.hide();
  78. }
  79. if(caCode && caCode != 'undefined') {
  80. filter.down('#ca_code').setValue(caCode);
  81. this.catecode = caCode;//当前科目
  82. }
  83. if(at && at != 'undefined') {
  84. filter.down('#ak_name').setValue(at);
  85. filter.down('#ak_name').asskind = {
  86. ak_name: at
  87. };
  88. filter.down('#ak_name').autoDbfind('form', caller, 'ak_name', 'ak_name like \'%' + at + '%\'');
  89. }
  90. if(ac && ac != 'undefined') {
  91. filter.down('#ak_asscode').setValue(ac);
  92. filter.down('#chkall').setValue(true);
  93. }
  94. if(an && an != 'undefined') {
  95. filter.down('#ak_assname').setValue(an);
  96. }
  97. if(un && un != 'undefined') {
  98. filter.down('#chkhaveun').setValue(un);
  99. }
  100. },
  101. hideFilterPanel: function(btn) {
  102. var filter = Ext.getCmp(btn.getId() + '-filter');
  103. if(filter) {
  104. filter.hide();
  105. }
  106. },
  107. query: function(cond) {
  108. var me = this,
  109. grid = Ext.getCmp('deptcost');
  110. grid.setLoading(true);
  111. Ext.Ajax.request({
  112. url: basePath + 'fa/ars/getDeptCost.action',
  113. params: {
  114. condition: Ext.encode(cond)
  115. },
  116. callback: function(opt, s, r) {
  117. var res = Ext.decode(r.responseText);
  118. var clmlist = [];
  119. Ext.each(grid.columns,function(column,index){
  120. if(column.type == 'add'){
  121. clmlist.push(column);
  122. }
  123. });
  124. Ext.each(clmlist,function(column,index){
  125. grid.headerCt.remove(column);
  126. });
  127. if(grid && res.column) {
  128. Ext.each(res.column,function(colu, index){
  129. grid.headerCt.insert(grid.columns.length, new Ext.grid.column.Column({
  130. type:'add',
  131. dataIndex: 'dpcode_'+colu.dp_code,
  132. cls: 'x-grid-header-1',
  133. sortable: false,
  134. text: colu.dp_name,
  135. width: 120,
  136. xtype: 'numbercolumn',
  137. format: '0,000.000',
  138. align: 'right'
  139. }));
  140. });
  141. grid.getView().refresh();
  142. if(res.data != null){
  143. grid.store.loadData(res.data);
  144. }
  145. /* if(res.data.length > 0) {
  146. if(res.data[0].ca_code) {
  147. cond.catecode = me.catecode = res.data[0].ca_code;
  148. cond.catename = res.data[0].ca_name;
  149. }
  150. cond.asstype = res.data[0].asl_asstype;
  151. cond.asscode = res.data[0].asl_asscode;
  152. cond.assname = res.data[0].asl_assname;
  153. Ext.getCmp('ak_name').asskind = {
  154. ak_name: cond.asstype
  155. };
  156. Ext.getCmp('ak_name').setValue(cond.asstype);
  157. Ext.getCmp('ak_asscode').setValue(cond.asscode);
  158. Ext.getCmp('ak_assname').setValue(cond.assname);
  159. } else {
  160. cond.catecode = me.catecode;
  161. cond.catename = '<font color=red>(无数据)</font>';
  162. cond.asstype = null;
  163. cond.asscode = null;
  164. cond.assname = null;
  165. }
  166. me._updateInfo(cond);*/
  167. }
  168. grid.setLoading(false);
  169. }
  170. });
  171. },
  172. getCondition: function(pl) {
  173. var r = new Object(),v;
  174. Ext.each(pl.items.items, function(item){
  175. if(item.getValue !== undefined) {
  176. v = item.getValue();
  177. if(!Ext.isEmpty(v)) {
  178. r[item.id] = v;
  179. }
  180. }
  181. });
  182. if(this.catecode) {
  183. r.catecode = this.catecode;
  184. }
  185. return r;
  186. },
  187. _updateInfo: function(r) {
  188. var tb = Ext.getCmp('gl_info_ym');
  189. if(tb)
  190. tb.updateInfo(r);
  191. tb = Ext.getCmp('gl_info_c');
  192. if(tb)
  193. tb.updateInfo(r);
  194. tb = Ext.getCmp('gl_info_ass');
  195. if(tb)
  196. tb.updateInfo(r);
  197. },
  198. loadVoucher: function(record) {
  199. var me = this, vc = record.get('sl_vocode');
  200. Ext.Ajax.request({
  201. url : basePath + 'common/getFieldData.action',
  202. params: {
  203. caller: 'Voucher',
  204. field: 'vo_id',
  205. condition: 'vo_code=\'' + vc + '\''
  206. },
  207. method : 'post',
  208. callback : function(options,success,response){
  209. var rs = new Ext.decode(response.responseText);
  210. if(rs.exceptionInfo){
  211. showError(rs.exceptionInfo);return null;
  212. }
  213. if(rs.success){
  214. if(rs.data != null){
  215. me.BaseUtil.onAdd('Voucher_' + vc, '凭证', 'jsps/fa/ars/voucher.jsp?formCondition=vo_idIS' + rs.data +
  216. '&gridCondition=vd_voidIS' + rs.data);
  217. }
  218. }
  219. }
  220. });
  221. },
  222. createYearmonthField : function() {
  223. return Ext.create('Ext.form.FieldContainer', {
  224. margin: '10 2 2 10',
  225. columnWidth: 1,
  226. layout: 'column',
  227. id:'yearmonth',
  228. name:'yearmonth',
  229. items: [{
  230. fieldLabel:'期间',
  231. id: 'am_yearmonth',
  232. labelWidth: 80,
  233. name: 'am_yearmonth',
  234. xtype: 'conmonthdatefield',
  235. columnWidth: 1,
  236. getValue: function() {
  237. if(!Ext.isEmpty(this.value)) {
  238. return {begin: this.firstVal, end: this.secondVal};
  239. }
  240. return null;
  241. }
  242. }],
  243. getValue: function() {
  244. var a = Ext.getCmp('am_yearmonth');
  245. return a.getValue();
  246. }
  247. });
  248. },
  249. createCateField : function() {
  250. var me = this, t, t1;
  251. if (me.CateTreeSearch) {
  252. t = Ext.create('erp.view.core.trigger.CateTreeDbfindTrigger', {
  253. name: 'vd_catecode',
  254. id: 'vd_catecode',
  255. autoDbfind: false,
  256. columnWidth: 0.4,
  257. listeners: {
  258. change: function() {
  259. me.catecode = null;
  260. },
  261. aftertrigger: function(t, d) {
  262. t.ownerCt.down('#vd_catename').setValue(d[0].raw.data.ca_name);
  263. }
  264. }
  265. });
  266. t1 = Ext.create('erp.view.core.trigger.CateTreeDbfindTrigger', {
  267. name: 'vd_catecode1',
  268. id: 'vd_catecode1',
  269. autoDbfind: false,
  270. columnWidth: 0.4,
  271. listeners: {
  272. change: function() {
  273. me.catecode = null;
  274. },
  275. aftertrigger: function(t, d) {
  276. t.ownerCt.down('#vd_catename1').setValue(d[0].raw.data.ca_name);
  277. }
  278. }
  279. });
  280. } else {
  281. t = Ext.create('erp.view.core.trigger.DbfindTrigger', {
  282. id: 'vd_catecode',
  283. name: 'vd_catecode',
  284. columnWidth: 0.4,
  285. listeners: {
  286. aftertrigger: function(t, d) {
  287. if (d) {
  288. t.setValue(d.data.ca_code);
  289. t.ownerCt.down('#vd_catename').setValue(d.data.ca_name);
  290. }
  291. }
  292. }
  293. });
  294. t1 = Ext.create('erp.view.core.trigger.DbfindTrigger', {
  295. id: 'vd_catecode1',
  296. name: 'vd_catecode1',
  297. columnWidth: 0.4,
  298. listeners: {
  299. aftertrigger: function(t, d) {
  300. if (d) {
  301. t.setValue(d.data.ca_code);
  302. t.ownerCt.down('#vd_catename1').setValue(d.data.ca_name);
  303. }
  304. }
  305. }
  306. });
  307. }
  308. return Ext.create('Ext.form.FieldContainer', {
  309. id: 'ca_code',
  310. margin: '2 2 2 10',
  311. columnWidth: 1,
  312. height: 100,
  313. layout: 'column',
  314. items: [{
  315. fieldLabel:'科目',
  316. labelWidth: 80,
  317. layout: 'column',
  318. columnWidth: 0.7,
  319. height: 56,
  320. xtype: 'fieldcontainer',
  321. id: 'con_vd_catecode',
  322. defaults: {
  323. fieldStyle : "background:#FFFAFA;color:#515151;"
  324. },
  325. items: [t, {
  326. xtype: 'textfield',
  327. name: 'vd_catename',
  328. id: 'vd_catename',
  329. columnWidth: 0.6,
  330. readOnly: true,
  331. fieldStyle: 'background:#f1f1f1;'
  332. },t1 ,{
  333. xtype: 'textfield',
  334. name: 'vd_catename1',
  335. id: 'vd_catename1',
  336. columnWidth: 0.6,
  337. readOnly: true,
  338. fieldStyle: 'background:#f1f1f1;'
  339. }],
  340. getValue: function() {
  341. var a = this.down('#vd_catecode').value,b = this.down('#vd_catecode1').value,
  342. x = Ext.isEmpty(a), y = Ext.isEmpty(b);
  343. if(x && y) {
  344. return null;
  345. } else if(x && !y) {
  346. a = b;
  347. } else if(!x && y){
  348. b = a;
  349. }
  350. return {begin: a, end: b};
  351. }
  352. }],
  353. getValue: function() {
  354. var a = Ext.getCmp('con_vd_catecode');
  355. var val = a.getValue();
  356. if(val) {
  357. if(me.catecode == null) {
  358. me.catecode = val.begin;
  359. }
  360. return {continuous: true,value: val};
  361. }
  362. return null;
  363. },
  364. setValue: function(v) {
  365. Ext.getCmp('vd_catecode').setValue(v);
  366. Ext.getCmp('vd_catecode1').setValue(v);
  367. }
  368. });
  369. },
  370. createCateLevelField : function() {
  371. return Ext.create('Ext.form.FieldContainer', {
  372. fieldLabel: '科目级别',
  373. labelWidth: 80,
  374. height: 23,
  375. layout: 'hbox',
  376. columnWidth: .51,
  377. id: 'ca_level',
  378. defaults: {
  379. fieldStyle : "background:#FFFAFA;color:#515151;"
  380. },
  381. items: [{
  382. xtype: 'combo',
  383. flex: 1,
  384. editable: false,
  385. name: 'ca_level1',
  386. id: 'ca_level1',
  387. displayField: 'display',
  388. valueField: 'value',
  389. queryMode: 'local',
  390. value: 1,
  391. store: Ext.create('Ext.data.Store', {
  392. fields: ['display', 'value'],
  393. data : [
  394. {"display": 1, "value": 1},
  395. {"display": 2, "value": 2},
  396. {"display": 3, "value": 3},
  397. {"display": 4, "value": 4},
  398. {"display": 5, "value": 5}
  399. ]
  400. })
  401. },{
  402. xtype: 'combo',
  403. flex: 1,
  404. name: 'ca_level2',
  405. id: 'ca_level2',
  406. editable: false,
  407. displayField: 'display',
  408. valueField: 'value',
  409. queryMode: 'local',
  410. value: 5,
  411. store: Ext.create('Ext.data.Store', {
  412. fields: ['display', 'value'],
  413. data : [
  414. {"display": 1, "value": 1},
  415. {"display": 2, "value": 2},
  416. {"display": 3, "value": 3},
  417. {"display": 4, "value": 4},
  418. {"display": 5, "value": 5}
  419. ]
  420. })
  421. }],
  422. getValue: function() {
  423. var a = this.down('#ca_level1').value,b = this.down('#ca_level2').value;
  424. return {begin: Math.min(a, b), end: Math.max(a, b)};
  425. },
  426. setValue: function() {
  427. }
  428. });
  429. },
  430. createAssField : function() {
  431. return Ext.create('Ext.form.FieldContainer', {
  432. fieldLabel: '辅助核算',
  433. labelWidth: 80,
  434. height: 23,
  435. layout: 'hbox',
  436. columnWidth: 1,
  437. id: 'vds_asscode',
  438. defaults: {
  439. fieldStyle : "background:#FFFAFA;color:#515151;"
  440. },
  441. items: [{
  442. labelWidth: 35,
  443. xtype: 'dbfindtrigger',
  444. flex: 0.2,
  445. id: 'ak_name',
  446. name: 'ak_name',
  447. value:'部门',
  448. readOnly:true,
  449. asskind:{
  450. ak_asscode:'dp_code',
  451. ak_assname:'dp_name',
  452. ak_code:'Dept',
  453. ak_dbfind:'Department',
  454. ak_table:'Department',
  455. ak_name:'部门'
  456. },
  457. listeners: {
  458. aftertrigger: function(f, r) {
  459. if(!Ext.isEmpty(f.value)) {
  460. f.asskind = r.data;
  461. var c = Ext.getCmp('ak_asscode'),
  462. n = Ext.getCmp('ak_assname');
  463. c.name = r.data.ak_asscode;
  464. n.name = r.data.ak_assname;
  465. } else {
  466. f.asskind = null;
  467. }
  468. },
  469. change: function() {
  470. var a = Ext.getCmp('ak_asscode'),
  471. b = Ext.getCmp('ak_assname');
  472. a.setValue(null);
  473. b.setValue(null);
  474. }
  475. }
  476. },{
  477. xtype: 'dbfindtrigger',
  478. id: 'ak_asscode',
  479. name:'dp_code',
  480. flex: 0.2,
  481. listeners: {
  482. beforetrigger: function(f) {
  483. var a = Ext.getCmp('ak_name');
  484. f.dbBaseCondition = null;
  485. if(!a.asskind) {
  486. a.focus(false, 200);
  487. showError('请先选择核算项!');
  488. return false;
  489. } else if(f.name == 'akd_asscode') {
  490. f.dbBaseCondition = 'ak_name=\'' + a.value + '\'';
  491. }
  492. },
  493. aftertrigger: function(f, r) {
  494. var a = Ext.getCmp('ak_name'),
  495. n = Ext.getCmp('ak_assname');
  496. if(a.asskind) {
  497. f.setValue(r.data[a.asskind.ak_asscode]);
  498. n.setValue(r.data[a.asskind.ak_assname]);
  499. }
  500. }
  501. }
  502. },{
  503. xtype: 'textfield',
  504. id: 'ak_assname',
  505. name:'dp_name',
  506. flex: 0.6,
  507. readOnly: true,
  508. fieldStyle: 'background:#f1f1f1;'
  509. }],
  510. getValue: function() {
  511. var a = Ext.getCmp('ak_name'),
  512. c = Ext.getCmp('ak_asscode');
  513. if(a.asskind) {
  514. return {am_asstype: a.asskind.ak_name, am_asscode: c.value};
  515. }
  516. return null;
  517. }
  518. });
  519. },
  520. createFilterPanel: function(btn) {
  521. var me = this;
  522. var filter = Ext.create('Ext.Window', {
  523. id: btn.getId() + '-filter',
  524. style: 'background:#f1f1f1',
  525. title: '筛选条件',
  526. width: 500,
  527. height: 500,
  528. layout: 'column',
  529. defaults: {
  530. margin: '2 2 2 10'
  531. },
  532. items: [me.createYearmonthField(), me.createCateField(), me.createCateLevelField(), me.createAssField(),
  533. {
  534. xtype: 'checkbox',
  535. id: 'chkhaveun',
  536. name: 'chkhaveun',
  537. columnWidth: .5,
  538. boxLabel: '包括未过账凭证'
  539. }],
  540. buttonAlign: 'center',
  541. buttons: [{
  542. text: '确定',
  543. width: 60,
  544. cls: 'x-btn-blue',
  545. handler: function(btn) {
  546. var fl = Ext.getCmp('query-filter'),
  547. con = me.getCondition(fl);
  548. con.querytype = 'current';
  549. me.query(con);
  550. fl.hide();
  551. }
  552. },{
  553. text: '关闭',
  554. width: 60,
  555. cls: 'x-btn-blue',
  556. handler: function(btn) {
  557. var fl = btn.ownerCt.ownerCt;
  558. fl.hide();
  559. }
  560. }]
  561. });
  562. this.getCurrentMonth(filter.down('#am_yearmonth'));
  563. return filter;
  564. },
  565. getCurrentMonth: function(f) {
  566. Ext.Ajax.request({
  567. url: basePath + 'fa/getMonth.action',
  568. params: {
  569. type: 'MONTH-A'
  570. },
  571. callback: function(opt, s, r) {
  572. var rs = Ext.decode(r.responseText);
  573. if(rs.data) {
  574. f.setValue(rs.data.PD_DETNO);
  575. }
  576. }
  577. });
  578. }
  579. });