EmplCost.js 14 KB

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