Voucher.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.Voucher', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. GridUtil: Ext.create('erp.util.GridUtil'),
  7. views:[
  8. 'fa.ars.Voucher','core.form.Panel','core.grid.Panel2','core.toolbar.Toolbar',
  9. 'fa.ars.VoucherFlowGrid','fa.ars.DetailAssGrid', 'core.button.CreateTemplate',
  10. 'core.button.Add','core.button.Save','core.button.Close','core.button.Source','core.button.ExportTemplate',
  11. 'core.button.Submit','core.button.ResSubmit','core.button.Audit','core.button.ResAudit',
  12. 'core.button.Update','core.button.Delete','core.form.YnField','core.button.DeleteDetail',
  13. 'core.button.VoucherFlow', 'core.button.CopyAll','core.button.ExportExcelButton','core.button.Print',
  14. 'core.trigger.DbfindTrigger','core.grid.YnColumn','core.form.YnField', 'core.trigger.CateTreeDbfindTrigger'
  15. ],
  16. init:function(){
  17. var me = this;
  18. this.control({
  19. 'erpFormPanel': {
  20. afterload: function(form) {
  21. Ext.defer(function(){// 非手工做的、有来源的凭证,不能改凭证字
  22. var lead = Ext.getCmp('vo_lead'), sr = Ext.getCmp('vo_source'),
  23. sc = Ext.getCmp('vo_sourcecode');
  24. if(lead && ((sr && !Ext.isEmpty(sr.getValue())) ||
  25. (sc && !Ext.isEmpty(sc.getValue()))))
  26. lead.setReadOnly(true);
  27. }, 200);
  28. }
  29. },
  30. '#vo_id': {
  31. afterrender: function(f) {
  32. Ext.defer(function(){
  33. var id = f.getValue();
  34. me.getMonth(function(data){
  35. if (Ext.isEmpty(id) || id == 0) {
  36. Ext.getCmp('vo_yearmonth').setValue(data.PD_DETNO);
  37. Ext.getCmp('vo_date').setValue(new Date(data.PD_ENDDATE));
  38. } else {
  39. var ym = Ext.getCmp('vo_yearmonth').getValue() || Ext.Date.format(new Date(), 'Ym');
  40. if(ym < data.PD_DETNO) {
  41. form.readOnly = true;
  42. Ext.getCmp('grid').readOnly = true;
  43. }
  44. }
  45. });
  46. }, 20);
  47. },
  48. change: function(f){
  49. var grid = Ext.getCmp('flowgrid');
  50. if(grid) {
  51. if(!Ext.isEmpty(f.value) && f.value != 0){
  52. grid.getMyData(f.value);
  53. } else {
  54. if(grid.columns && grid.columns.length > 2){
  55. grid.GridUtil.add10EmptyItems(grid);
  56. } else {
  57. grid.getMyData(-1);
  58. }
  59. }
  60. }
  61. var ff = Ext.getCmp('form_disable');
  62. ff.FormUtil.loadNewStore(ff, {caller: ff.caller, condition: "vo_id=" + f.value});
  63. }
  64. },
  65. 'erpSaveButton': {
  66. click: function(btn){
  67. var form = me.getForm(btn);
  68. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  69. me.BaseUtil.getRandomNumber();//自动添加编号
  70. }
  71. //保存之前的一些前台的逻辑判定
  72. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  73. Ext.each(items,function(item,index){
  74. if(!Ext.isEmpty(item.data['vd_catecode']) || !Ext.isEmpty(item.data['vd_explanation'])){
  75. if((Ext.isEmpty(item.data['vd_debit']) || item.data['vd_debit'] == 0) && (Ext.isEmpty(item.data['vd_credit']) || item.data['vd_credit'] == 0)){
  76. showError('明细表第' + item.data['vd_detno'] + '行借、贷方金额均未填写!');
  77. }
  78. }
  79. });
  80. this.beforeSave();
  81. }
  82. },
  83. //查看来源
  84. 'erpSourceButton': {
  85. afterender: function(btn){
  86. Ext.defer(function(){
  87. var v = Ext.getCmp('vo_source').value;
  88. if(v == null || v == ''){
  89. btn.hide();
  90. }
  91. }, 200);
  92. },
  93. click: function(){
  94. var id = Ext.getCmp('vo_id').value;
  95. if(id != null && id > 0) {
  96. me.getSource(id);
  97. }
  98. }
  99. },
  100. 'erpExportExcelButton':{
  101. afterrender:function(btn){
  102. //btn.exportCaller="Voucher!DetailAss!Export";
  103. btn.exportCaller="Voucher!DetailandAss!Export";
  104. var status = Ext.getCmp('vo_statuscode').value;
  105. if(status&&status!='ENTERING'){
  106. btn.hide();
  107. }
  108. }
  109. },
  110. 'filefield[id=excelfile]':{
  111. change: function(field){
  112. warnMsg('确认要重新导入吗?', function(btn){
  113. if(btn == 'yes'){
  114. if(contains(field.value, "\\", true)){
  115. filename = field.value.substring(field.value.lastIndexOf('\\') + 1);
  116. } else {
  117. filename = field.value.substring(field.value.lastIndexOf('/') + 1);
  118. }
  119. field.ownerCt.getForm().submit({
  120. url: basePath + 'common/upload.action?em_code=' + em_code,
  121. waitMsg: "正在解析文件信息",
  122. success: function(fp,o){
  123. if(o.result.error){
  124. showError(o.result.error);
  125. } else {
  126. var filePath=o.result.filepath;
  127. var keyValue=Ext.getCmp('vo_id').getValue();
  128. Ext.Ajax.request({//拿到form的items
  129. url : basePath + 'fa/ars/ImportExcel.action',
  130. params:{
  131. id:keyValue,
  132. fileId:filePath
  133. },
  134. method : 'post',
  135. callback : function(options,success,response){
  136. var result=Ext.decode(response.responseText);
  137. if(result.success){
  138. Ext.Msg.alert('提示','导入成功!');
  139. window.location.reload();
  140. }else{
  141. var err = result.exceptionInfo || result.error;
  142. if(err != null){
  143. showError(err);
  144. }
  145. }
  146. }
  147. });
  148. }
  149. }
  150. });
  151. }
  152. });
  153. }
  154. },
  155. 'erpVoucherFlowButton': {
  156. click: function(){
  157. this.showVoucherFlow();
  158. }
  159. },
  160. 'erpCloseButton': {
  161. click: function(btn){
  162. this.FormUtil.beforeClose(this);
  163. }
  164. },
  165. 'erpCopyButton': {
  166. click: function(btn) {
  167. this.copy();
  168. }
  169. },
  170. 'erpUpdateButton': {
  171. click: function(btn){
  172. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  173. Ext.each(items,function(item,index){
  174. if(!Ext.isEmpty(item.data['vd_catecode']) || !Ext.isEmpty(item.data['vd_explanation'])){
  175. if((Ext.isEmpty(item.data['vd_debit']) || item.data['vd_debit'] == 0) && (Ext.isEmpty(item.data['vd_credit']) || item.data['vd_credit'] == 0)){
  176. showError('明细表第' + item.data['vd_detno'] + '行借、贷方金额均未填写!');
  177. }
  178. }
  179. });
  180. this.beforeUpdate();
  181. }
  182. },
  183. 'erpPrintButton': {
  184. click: function(btn) {
  185. var reportName = '';
  186. reportName = "vouclist_rmb";
  187. var condition = '{Voucher.vo_id}=' + Ext.getCmp('vo_id').value + '';
  188. var id = Ext.getCmp('vo_id').value;
  189. me.FormUtil.onwindowsPrint(id, reportName, condition);
  190. }
  191. },
  192. 'erpDeleteButton': {
  193. afterrender: function(btn){
  194. Ext.defer(function(){
  195. var source = Ext.getCmp('vo_source'),
  196. sourceCode = Ext.getCmp('vo_sourcecode');
  197. if((source && source.value) || (sourceCode && sourceCode.value)){
  198. btn.hide();
  199. }
  200. }, 200);
  201. },
  202. click: function(btn){
  203. me.FormUtil.onDelete(Ext.getCmp('vo_id').value);
  204. }
  205. },
  206. 'erpAddButton': {
  207. click: function(){
  208. var tab = me.FormUtil.getActiveTab();
  209. me.FormUtil.onAdd(null, '新增凭证资料', 'jsps/fa/ars/voucher.jsp');
  210. setTimeout(function(){
  211. if(tab) {
  212. tab.close();
  213. }
  214. }, 200);
  215. }
  216. },
  217. 'erpSubmitButton': {
  218. afterrender: function(btn){
  219. var status = Ext.getCmp('vo_statuscode');
  220. if(status && status.value != 'ENTERING'){
  221. btn.hide();
  222. }
  223. },
  224. click: function(btn){
  225. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  226. Ext.each(items,function(item,index){
  227. if(!Ext.isEmpty(item.data['vd_catecode']) || !Ext.isEmpty(item.data['vd_explanation'])){
  228. if((Ext.isEmpty(item.data['vd_debit']) || item.data['vd_debit'] == 0) && (Ext.isEmpty(item.data['vd_credit']) || item.data['vd_credit'] == 0)){
  229. showError('明细表第' + item.data['vd_detno'] + '行借、贷方金额均未填写!');
  230. return;
  231. }
  232. }
  233. });
  234. me.FormUtil.onSubmit(Ext.getCmp('vo_id').value);
  235. }
  236. },
  237. 'erpResSubmitButton': {
  238. afterrender: function(btn){
  239. var status = Ext.getCmp('vo_statuscode');
  240. if(status && status.value != 'COMMITED'){
  241. btn.hide();
  242. }
  243. },
  244. click: function(btn){
  245. me.FormUtil.onResSubmit(Ext.getCmp('vo_id').value);
  246. }
  247. },
  248. 'erpAuditButton': {
  249. afterrender: function(btn){
  250. var status = Ext.getCmp('vo_statuscode');
  251. if(status && status.value != 'COMMITED'){
  252. btn.hide();
  253. }
  254. },
  255. click: function(btn){
  256. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  257. Ext.each(items,function(item,index){
  258. if(!Ext.isEmpty(item.data['vd_catecode']) || !Ext.isEmpty(item.data['vd_explanation'])){
  259. if((Ext.isEmpty(item.data['vd_debit']) || item.data['vd_debit'] == 0) && (Ext.isEmpty(item.data['vd_credit']) || item.data['vd_credit'] == 0)){
  260. showError('明细表第' + item.data['vd_detno'] + '行借、贷方金额均未填写!');
  261. return;
  262. }
  263. }
  264. });
  265. me.FormUtil.onAudit(Ext.getCmp('vo_id').value);
  266. }
  267. },
  268. 'erpResAuditButton': {
  269. afterrender: function(btn){
  270. var status = Ext.getCmp('vo_statuscode');
  271. if(status && status.value != 'AUDITED'){
  272. btn.hide();
  273. }
  274. },
  275. click: function(btn){
  276. me.FormUtil.onResAudit(Ext.getCmp('vo_id').value);
  277. }
  278. },
  279. 'field[name=vo_errstring]': {
  280. afterrender: function(f){
  281. if(f.value != null && f.value != ''){
  282. f.inputEl.setStyle({color: 'OrangeRed'});
  283. } else {
  284. f.setValue('正常');
  285. f.inputEl.setStyle({color: '#B6E2FF'});
  286. f.originalValue = f.value;
  287. }
  288. },
  289. change: function(f){
  290. if(f.value != null && f.value != ''){
  291. f.inputEl.setStyle({color: 'OrangeRed'});
  292. } else {
  293. f.setValue('正常');
  294. f.inputEl.setStyle({color: '#B6E2FF'});
  295. f.originalValue = f.value;
  296. }
  297. }
  298. },
  299. 'field[name=vo_date]': {
  300. change: function(f){
  301. if(f.value == null){
  302. f.setValue(new Date());
  303. }
  304. }
  305. },
  306. 'field[name=vo_yearmonth]': {
  307. afterrender: function(f){
  308. if(f.value == null || f.value == 0){
  309. f.setValue(Ext.Date.format(new Date(), 'Ym'));
  310. }
  311. }
  312. },
  313. 'erpDeleteDetailButton': {
  314. afterrender: function(btn){
  315. //将当前行的 借方/贷方 以及外币借方/外币贷方 互换
  316. btn.ownerCt.add({
  317. text: '借贷调换',
  318. width: 85,
  319. disabled: true,
  320. cls: 'x-btn-gray',
  321. id: 'replace'
  322. });
  323. //当前行的借方 = 其它行的贷方总额-其它行的借方总额
  324. btn.ownerCt.add({
  325. text: '找平',
  326. width: 65,
  327. disabled: true,
  328. cls: 'x-btn-gray',
  329. id: 'level'
  330. });
  331. },
  332. afterdelete: function(d, r, btn){
  333. //更新凭证状态
  334. Ext.Ajax.request({
  335. url: basePath + 'fa/ars/validVoucher.action',
  336. params: {
  337. id: d.vd_void
  338. },
  339. callback: function(opt, s, r){
  340. var res = Ext.decode(r.responseText);
  341. if(res.success) {
  342. var f = Ext.getCmp('vo_errstring');
  343. f.setValue((res.errstring || ''));
  344. f.dirty = false;
  345. f.originalValue = f.value;
  346. }
  347. }
  348. });
  349. }
  350. },
  351. 'ExportExcelButton':{
  352. afterrender:function(btn){
  353. btn.caller='Voucher!DetailAss!Export';
  354. }
  355. },
  356. 'erpGridPanel2': {
  357. afterrender: function(grid){
  358. grid.plugins[0].on('beforeedit', function(args) {
  359. var iscashflow = Ext.getCmp('vo_iscashflow');
  360. if(iscashflow && iscashflow.value != 0){
  361. if (args.field == "vd_flowcode") {
  362. var bool = false;
  363. if (args.record.get('ca_cashflow') == 0){
  364. bool = true;
  365. }
  366. }
  367. return bool;
  368. } else {
  369. if (args.field == "vd_flowcode") {
  370. return false;
  371. }
  372. }
  373. if (args.field == "vd_debit") {
  374. var bool = true;
  375. if (args.record.get('vd_credit') != null && args.record.get('vd_credit') > 0){
  376. bool = false;
  377. }
  378. if (args.record.get('vd_doublecredit') != null && args.record.get('vd_doublecredit') > 0){
  379. bool = false;
  380. }
  381. return bool;
  382. }
  383. if (args.field == "vd_credit") {
  384. var bool = true;
  385. if (args.record.get('vd_debit') != null && args.record.get('vd_debit') > 0){
  386. bool = false;
  387. }
  388. if (args.record.get('vd_doubledebit') != null && args.record.get('vd_doubledebit') > 0){
  389. bool = false;
  390. }
  391. return bool;
  392. }
  393. if (args.field == "vd_doubledebit") {
  394. var bool = true;
  395. if (args.record.get('vd_doublecredit') != null && args.record.get('vd_doublecredit') > 0){
  396. bool = false;
  397. }
  398. if (args.record.get('vd_credit') != null && args.record.get('vd_credit') > 0){
  399. bool = false;
  400. }
  401. return bool;
  402. }
  403. if (args.field == "vd_doublecredit") {
  404. var bool = true;
  405. if (args.record.get('vd_doubledebit') != null && args.record.get('vd_doubledebit') > 0){
  406. bool = false;
  407. }
  408. if (args.record.get('vd_debit') != null && args.record.get('vd_debit') > 0){
  409. bool = false;
  410. }
  411. return bool;
  412. }
  413. });
  414. var f = Ext.getCmp('vo_currencytype');
  415. if(f) {
  416. Ext.defer( function(){
  417. me.changeCurrencyType(f);
  418. },200);
  419. }
  420. Ext.defer(function(){
  421. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  422. if(e.getKey() == 187 && ['vd_debit', 'vd_credit'].indexOf(e.target.name) > -1) {
  423. me.levelOut(e.target);
  424. }
  425. });
  426. }, 200);
  427. },
  428. /*storeloaded: function(grid){
  429. var f = Ext.getCmp('vo_currencytype');
  430. if(f) {
  431. me.changeCurrencyType(f);
  432. }
  433. },*/
  434. itemclick: function(selModel, record){
  435. var grid = selModel.ownerCt;
  436. if(!grid.readOnly) {
  437. this.GridUtil.onGridItemClick(selModel, record);
  438. var btn = Ext.getCmp('replace');
  439. btn.setDisabled(false);
  440. btn = Ext.getCmp('level');
  441. btn.setDisabled(false);
  442. }
  443. }
  444. },
  445. 'voucherflowgrid': {
  446. itemclick: function(selModel, record){
  447. var grid = Ext.getCmp('flowgrid');
  448. var index = record.data[grid.detno];
  449. if(index == grid.store.data.items[grid.store.data.items.length-1].index + 1){
  450. me.GridUtil.add10EmptyItems(grid);
  451. }
  452. }
  453. },
  454. 'field[name=vo_currencytype]': {
  455. change: function(c){
  456. me.changeCurrencyType(c);
  457. }
  458. },
  459. /**
  460. * 借调互换
  461. */
  462. 'button[id=replace]': {
  463. click: function(btn){
  464. var grid = btn.ownerCt.ownerCt;
  465. var record = grid.selModel.lastSelected;
  466. if(record){
  467. var v1 = record.data['vd_debit'];//借方
  468. var v2 = record.data['vd_credit'];//贷方
  469. var v3 = record.data['vd_doubledebit'];//原币借方
  470. var v4 = record.data['vd_doublecredit'];//原币贷方
  471. record.set('vd_debit', v2);
  472. record.set('vd_credit', v1);
  473. record.set('vd_doubledebit', v4);
  474. record.set('vd_doublecredit', v3);
  475. }
  476. }
  477. },
  478. /**
  479. * 找平
  480. */
  481. 'button[id=level]': {
  482. click: me.levelOut
  483. },
  484. 'field[name=vd_doubledebit]': {//原币借方
  485. focus : function(f) {
  486. var grid = Ext.getCmp('grid'),
  487. record = grid.selModel.lastSelected,
  488. val = record.get('vd_doublecredit');
  489. if( val != 0 ) {
  490. f.setReadOnly(true);
  491. } else {
  492. f.setReadOnly(false);
  493. }
  494. },
  495. change: function(f){
  496. if(!f.ownerCt && f.value != null && f.value != 0 ){
  497. var grid = Ext.getCmp('grid');
  498. var record = grid.selModel.lastSelected,
  499. rate = record.data['vd_rate'];
  500. if(rate != null && rate > 0){
  501. var val = me.BaseUtil.numberFormat(me.BaseUtil.multiply(f.value, rate), 2);
  502. if(record.data['vd_debit'] != val) {
  503. record.set('vd_debit', val);//本币
  504. }
  505. }
  506. }
  507. }
  508. },
  509. 'field[name=vd_doublecredit]': {//原币贷方
  510. focus : function(f) {
  511. var grid = Ext.getCmp('grid'),
  512. record = grid.selModel.lastSelected,
  513. val = record.get('vd_doubledebit');
  514. if( val != 0 ) {
  515. f.setReadOnly(true);
  516. } else {
  517. f.setReadOnly(false);
  518. }
  519. },
  520. change: function(f){
  521. if(!f.ownerCt && f.value != null && f.value != 0 ){
  522. var record = Ext.getCmp('grid').selModel.lastSelected,
  523. rate = record.data['vd_rate'];
  524. if(rate != null && rate > 0){
  525. var val = me.BaseUtil.numberFormat(me.BaseUtil.multiply(f.value, rate), 2);
  526. if(record.data['vd_credit'] != val) {
  527. record.set('vd_credit', val);//本币
  528. }
  529. }
  530. }
  531. }
  532. },
  533. 'field[name=vd_currency]': {
  534. afterrender: function(f){
  535. f.mappingKey = 'cm_yearmonth';
  536. f.dbKey = 'vo_yearmonth';
  537. },
  538. aftertrigger: function(f){
  539. if(f.value != null && f.value != '' ){
  540. var record = Ext.getCmp('grid').selModel.lastSelected;
  541. if(record.data['vd_rate'] != null && record.data['vd_rate'] > 0){
  542. if(record.data['vd_doubledebit'] != null){
  543. record.set('vd_debit',
  544. me.BaseUtil.numberFormat(me.BaseUtil.multiply(record.get('vd_doubledebit'), record.get('vd_rate')), 2));//原币计算本币
  545. }
  546. if(record.data['vd_doublecredit'] != null){
  547. record.set('vd_credit',
  548. me.BaseUtil.numberFormat(me.BaseUtil.multiply(record.get('vd_doublecredit'), record.get('vd_rate')), 2));//原币计算本币
  549. }
  550. }
  551. }
  552. }
  553. },
  554. 'field[name=vd_explanation]': {
  555. specialkey: function(f, e){//按ENTER自动把摘要复制到下一行
  556. if (e.getKey() == e.ENTER) {
  557. if(f.value != null && f.value != '' ){
  558. var grid = Ext.getCmp('grid'),
  559. record = grid.selModel.lastSelected,
  560. idx = grid.store.indexOf(record),
  561. next = grid.store.getAt(idx + 1);
  562. if(next) {
  563. var v = next.get('vd_explanation');
  564. if(Ext.isEmpty(v))
  565. next.set('vd_explanation', f.value);
  566. }
  567. }
  568. }
  569. },
  570. change: function(f) {
  571. if(f.value == '=') {
  572. var grid = Ext.getCmp('grid'),
  573. record = grid.selModel.lastSelected,
  574. idx = grid.store.indexOf(record),
  575. prev = grid.store.getAt(idx - 1);
  576. if(prev) {
  577. var v = prev.get('vd_explanation');
  578. if(!Ext.isEmpty(v))
  579. f.setValue(v);
  580. }
  581. }
  582. }
  583. },
  584. 'field[name=vd_debit]': {
  585. focus : function(f) {
  586. var grid = Ext.getCmp('grid'),
  587. record = grid.selModel.lastSelected,
  588. val = record.get('vd_credit');
  589. if( val != 0 ) {
  590. f.setReadOnly(true);
  591. } else {
  592. f.setReadOnly(false);
  593. }
  594. },
  595. specialkey: function(f, e){//按ENTER自动把摘要复制到下一行
  596. if (e.getKey() == e.ENTER) {
  597. var grid = Ext.getCmp('grid'),
  598. record = grid.selModel.lastSelected,
  599. val = record.get('vd_explanation'),
  600. idx = grid.store.indexOf(record),
  601. next = grid.store.getAt(idx + 1);
  602. if(!Ext.isEmpty(val)) {
  603. if(next) {
  604. var v = next.get('vd_explanation');
  605. if(Ext.isEmpty(v))
  606. next.set('vd_explanation', val);
  607. }
  608. }
  609. }
  610. }
  611. },
  612. 'field[name=vd_credit]': {
  613. focus : function(f) {
  614. var grid = Ext.getCmp('grid'),
  615. record = grid.selModel.lastSelected,
  616. val = record.get('vd_debit');
  617. if( val != 0 ) {
  618. f.setReadOnly(true);
  619. } else {
  620. f.setReadOnly(false);
  621. }
  622. },
  623. specialkey: function(f, e){//按ENTER自动把摘要复制到下一行
  624. console.log(e);
  625. if (e.getKey() == e.ENTER) {
  626. var grid = Ext.getCmp('grid'),
  627. record = grid.selModel.lastSelected,
  628. val = record.get('vd_explanation'),
  629. idx = grid.store.indexOf(record),
  630. next = grid.store.getAt(idx + 1);
  631. if(!Ext.isEmpty(val)) {
  632. if(next) {
  633. var v = next.get('vd_explanation');
  634. if(Ext.isEmpty(v))
  635. next.set('vd_explanation', val);
  636. }
  637. }
  638. }
  639. }
  640. },
  641. 'dbfindtrigger[name=vd_catecode]': {
  642. aftertrigger: function(f){
  643. var grid = Ext.getCmp('grid'),
  644. record = grid.selModel.lastSelected;
  645. var type = record.get('ca_assname'), ass = record.get('ass') || [];
  646. if(!Ext.isEmpty(type)){
  647. var oldType = Ext.Array.concate(ass, '#', 'vds_asstype');
  648. if(type != oldType) {
  649. var idx = me.getRecordIndex(grid, record), dd = [];
  650. Ext.Array.each(type.split('#'), function(t){
  651. dd.push({
  652. vds_vdid: idx,
  653. vds_asstype: t
  654. });
  655. });
  656. record.set('ass', dd);
  657. var view = grid.view, idx = grid.store.indexOf(record), rowNode = view.getNode(idx),
  658. expander = grid.plugins[2], row = Ext.fly(rowNode, '_rowExpander'),
  659. isCollapsed = row.hasCls(expander.rowCollapsedCls);
  660. if(isCollapsed)
  661. expander.toggleRow(idx, record);
  662. }
  663. } else
  664. record.set('ass', null);
  665. }
  666. },
  667. 'cateTreeDbfindTrigger[name=vd_catecode]': {
  668. aftertrigger: function(f, d){
  669. var grid = Ext.getCmp('grid'),
  670. record = grid.selModel.lastSelected;
  671. var type = record.get('ca_assname'), ass = record.get('ass') || [];
  672. if(!Ext.isEmpty(type)){
  673. var oldType = Ext.Array.concate(ass, '#', 'vds_asstype');
  674. if(type != oldType) {
  675. var idx = me.getRecordIndex(grid, record), dd = [];
  676. Ext.Array.each(type.split('#'), function(t){
  677. dd.push({
  678. vds_vdid: idx,
  679. vds_asstype: t
  680. });
  681. });
  682. record.set('ass', dd);
  683. }
  684. } else
  685. record.set('ass', null);
  686. },
  687. afterrender: function(f){
  688. f.onTriggerClick = function(){
  689. me.showCateTree(f);
  690. };
  691. }
  692. },
  693. /**
  694. * 导入凭证模板
  695. */
  696. 'erpExportTemplateButton': {
  697. click: function() {
  698. me.showTp();
  699. }
  700. },
  701. /**
  702. * 添加到模板
  703. */
  704. 'erpCreateTemplateButton': {
  705. click: function() {
  706. me.createTp();
  707. }
  708. }
  709. });
  710. },
  711. getForm: function(btn){
  712. return btn.ownerCt.ownerCt;
  713. },
  714. getRecordIndex: function(grid, record) {
  715. var me = this, id = record.get(grid.keyField);
  716. if(!id || id == 0) {
  717. me.rowCounter = me.rowCounter || 0;
  718. id = --me.rowCounter;
  719. record.set(grid.keyField, id);
  720. }
  721. return id;
  722. },
  723. changeCurrencyType: function(c){
  724. var grid = Ext.getCmp('grid');
  725. if(grid) {
  726. var cols = grid.headerCt.getGridColumns();
  727. if(c.checked){
  728. Ext.each(cols, function(cn){
  729. if(cn.dataIndex == 'vd_doubledebit' || cn.dataIndex == 'vd_doublecredit'){
  730. cn.width = 110;
  731. cn.setVisible(true);
  732. }
  733. if(cn.dataIndex == 'vd_currency' || cn.dataIndex == 'vd_rate'){
  734. cn.width = 60;
  735. cn.setVisible(true);
  736. }
  737. if(cn.dataIndex == 'vd_debit'){
  738. cn.setText('本币借方');
  739. }
  740. if(cn.dataIndex == 'vd_credit'){
  741. cn.setText('本币贷方');
  742. }
  743. });
  744. } else {
  745. Ext.each(cols, function(cn){
  746. if(cn.dataIndex == 'vd_currency' || cn.dataIndex == 'vd_rate'
  747. || cn.dataIndex == 'vd_doubledebit' || cn.dataIndex == 'vd_doublecredit'){
  748. cn.setVisible(false);
  749. }
  750. if(cn.dataIndex == 'vd_debit'){
  751. cn.setText('借方');
  752. }
  753. if(cn.dataIndex == 'vd_credit'){
  754. cn.setText('贷方');
  755. }
  756. });
  757. }
  758. }
  759. },
  760. beforeSave: function(){
  761. var me = this;
  762. var form = Ext.getCmp('form'), id = Ext.getCmp(form.keyField).value;
  763. if(! me.FormUtil.checkForm()){
  764. return;
  765. }
  766. if(Ext.isEmpty(id) || id == 0 || id == '0'){
  767. me.FormUtil.getSeqId(form);
  768. }
  769. var detail = Ext.getCmp('grid');
  770. var flow = Ext.getCmp('flowgrid');
  771. var ass = [];
  772. detail.store.each(function(record){
  773. if(record.get('ca_assname')) {
  774. var s = record.get('ass') || [];
  775. Ext.Array.each(s, function(t, i){
  776. t.vds_id = t.vds_id || 0;
  777. t.vds_detno = i + 1;
  778. t.vds_vdid = String(t.vds_vdid);
  779. ass.push(t);
  780. });
  781. }
  782. });
  783. var param2 = new Array();
  784. if(flow) {
  785. param2 = me.GridUtil.getGridStore(flow);
  786. }
  787. var param3 = Ext.encode(ass);
  788. Ext.each(detail.store.data.items, function(item, idx){
  789. if(item.data.vd_id == null || item.data.vd_id == 0){
  790. item.data.vd_id = -idx;
  791. }
  792. });
  793. var param1 = me.GridUtil.getGridStore(detail);
  794. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  795. showError($I18N.common.grid.emptyDetail);
  796. return;
  797. }
  798. var ex = new Array(),d;
  799. Ext.each(param1, function(){//摘要未填写
  800. d = Ext.decode(this);
  801. if(Ext.isEmpty(d.vd_explanation)) {
  802. ex.push(d.vd_detno);
  803. }
  804. });
  805. if(ex.length > 0) {
  806. warnMsg("摘要未填写,序号:" + ex.join(',') + " 是否继续保存?", function(btn){
  807. if(btn == 'yes') {
  808. me.onSave(form, param1, param2, param3);;
  809. }
  810. });
  811. } else {
  812. me.onSave(form, param1, param2, param3);
  813. }
  814. },
  815. onSave: function(form, param1, param2, param3) {
  816. var me = this;
  817. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  818. param2 = param2 == null ? [] : "[" + param2.toString().replace(/\\/g,"%") + "]";
  819. param3 = param3 == null ? [] : param3.toString().replace(/\\/g,"%");
  820. if(form.getForm().isValid()){
  821. Ext.each(form.items.items, function(item){
  822. if(item.xtype == 'numberfield'){
  823. if(item.value == null || item.value == ''){
  824. item.setValue(0);
  825. }
  826. }
  827. });
  828. var r = form.getValues();
  829. r.vo_currencytype = Ext.getCmp('vo_currencytype').value ? -1 : 0;
  830. r.vo_errstring = r.vo_errstring == '正常' ? '' : r.vo_errstring;
  831. me.FormUtil.save(r, param1, param2, param3);
  832. }else{
  833. me.FormUtil.checkForm();
  834. }
  835. },
  836. beforeUpdate: function(){
  837. var me = this;
  838. var form = Ext.getCmp('form');
  839. if(! me.FormUtil.checkForm()){
  840. return;
  841. }
  842. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  843. me.FormUtil.getSeqId(form);
  844. }
  845. var detail = Ext.getCmp('grid');
  846. var flow = Ext.getCmp('flowgrid');
  847. var param1 = me.GridUtil.getGridStore(detail);
  848. var param2 = new Array();
  849. if(flow) {
  850. param2 = me.GridUtil.getGridStore(flow);
  851. }
  852. var ass = [];
  853. detail.store.each(function(record){
  854. if(record.get('ca_assname')) {
  855. var s = record.get('ass') || [];
  856. Ext.Array.each(s, function(t, i){
  857. t.vds_id = t.vds_id || 0;
  858. t.vds_detno = i + 1;
  859. t.vds_vdid = String(t.vds_vdid);
  860. ass.push(t);
  861. });
  862. }
  863. });
  864. var param3 = Ext.encode(ass);
  865. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0) &&
  866. (!flow || (flow.necessaryField.length > 0 && (param2.length == 0)))
  867. && (param3.length <= 2)){
  868. showError($I18N.common.grid.emptyDetail);
  869. return;
  870. }
  871. // 摘要未填写判断
  872. var ex = new Array(),d;
  873. Ext.each(param1, function(){
  874. d = Ext.decode(this);
  875. if(Ext.isEmpty(d.vd_explanation)) {
  876. ex.push(d.vd_detno);
  877. }
  878. });
  879. if(ex.length > 0) {
  880. warnMsg("摘要未填写,序号:" + ex.join(',') + " 是否继续保存?", function(btn){
  881. if(btn == 'yes') {
  882. me.onUpdate(form, param1, param2, param3);;
  883. }
  884. });
  885. } else {
  886. me.onUpdate(form, param1, param2, param3);
  887. }
  888. },
  889. onUpdate: function(form, param1, param2, param3) {
  890. var me = this;
  891. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  892. param2 = param2 == null ? [] : "[" + param2.toString().replace(/\\/g,"%") + "]";
  893. param3 = param3 == null ? [] : param3.toString().replace(/\\/g,"%");
  894. if(form.getForm().isValid()){
  895. Ext.each(form.items.items, function(item){
  896. if(item.xtype == 'numberfield'){
  897. if(item.value == null || item.value == ''){
  898. item.setValue(0);
  899. }
  900. }
  901. });
  902. var r = form.getValues();
  903. r.vo_currencytype = Ext.getCmp('vo_currencytype').value ? -1 : 0;
  904. r.vo_errstring = r.vo_errstring == '正常' ? '' : r.vo_errstring;
  905. me.FormUtil.update(r, param1, param2, param3);
  906. }else{
  907. me.FormUtil.checkForm();
  908. }
  909. },
  910. showVoucherFlow: function(){
  911. var win = Ext.getCmp('flow_win');
  912. var voucherid = Ext.getCmp('vo_id').value;
  913. if(!win) {
  914. Ext.create('Ext.Window', {
  915. id: 'flow_win',
  916. height: "100%",
  917. width: "80%",
  918. iconCls: 'x-button-icon-set',
  919. closeAction: 'hide',
  920. autoShow: true,
  921. title: '现金流',
  922. maximizable : true,
  923. layout : 'anchor',
  924. items: [{
  925. anchor: '100% 100%',
  926. xtype: 'voucherflowgrid',
  927. listeners: {
  928. afterrender: function(grid){
  929. if(formCondition == null || formCondition.toString().trim() == ''){
  930. grid.getMyData(-1);
  931. } else {
  932. grid.getMyData(voucherid);
  933. }
  934. }
  935. }
  936. }],
  937. buttonAlign: 'center',
  938. buttons: [{
  939. text: $I18N.common.button.erpConfirmButton,
  940. iconCls: 'x-button-icon-save',
  941. cls: 'x-btn-gray',
  942. handler: function(btn){
  943. btn.ownerCt.ownerCt.close();
  944. }
  945. }]
  946. });
  947. } else {
  948. win.show();
  949. }
  950. },
  951. /**
  952. * 复制凭证
  953. */
  954. copy: function(){
  955. var form = Ext.getCmp('form');
  956. var v = form.down('#vo_id').value;
  957. if(v > 0) {
  958. form.setLoading(true);
  959. Ext.Ajax.request({
  960. url: basePath + 'fa/ars/copyVoucher.action',
  961. params: {
  962. id: v
  963. },
  964. callback: function(opt, s, r){
  965. form.setLoading(false);
  966. var res = Ext.decode(r.responseText);
  967. if(res.voucher) {
  968. showMessage('提示', '复制成功!<a href="javascript:openUrl(\'jsps/fa/ars/voucher.jsp?formCondition=vo_idIS' +
  969. + res.voucher.vo_id + '&gridCondition=vd_voidIS' + res.voucher.vo_id +
  970. '\')">\n凭证号:&lt;' + res.voucher.vo_number +
  971. '&gt;\n流水号:&lt;' + res.voucher.vo_code + '&gt;</a>');
  972. } else {
  973. showError(res.exceptionInfo);
  974. }
  975. }
  976. });
  977. }
  978. },
  979. getSource: function(id) {
  980. var me = this;
  981. Ext.Ajax.request({
  982. url : basePath + 'common/getFieldsData.action',
  983. params: {
  984. caller: 'VoucherBill',
  985. fields: 'vb_billcode,vb_vscode',
  986. condition: 'vb_void=' + id
  987. },
  988. method : 'post',
  989. callback : function(options,success,response){
  990. var localJson = new Ext.decode(response.responseText);
  991. if(localJson.exceptionInfo){
  992. showError(localJson.exceptionInfo);
  993. } else if(localJson.success){
  994. if(localJson.data != null && localJson.data.vb_vscode != null){
  995. me.showSourceList(localJson.data.vb_vscode, localJson.data.vb_billcode);
  996. } else {
  997. showMessage('提示', '当前凭证没有来源信息!');
  998. }
  999. }
  1000. }
  1001. });
  1002. },
  1003. showSourceList: function(vscode, pri) {
  1004. var me = this, cls = Ext.getCmp('vo_source').value,
  1005. cfg = me.getSourceConfig(vscode, cls),
  1006. merge = pri.indexOf(',') > 0 || /SELECT.*FROM.*/.test(pri.toUpperCase());
  1007. Ext.Ajax.request({
  1008. url : basePath + 'common/getFieldsData.action',
  1009. params: {
  1010. caller: 'VoucherStyle',
  1011. fields: 'vs_datalist,vs_prikey1,vs_pritable,vs_classfield',
  1012. condition: 'vs_code=\'' + vscode + '\''
  1013. },
  1014. method : 'post',
  1015. callback : function(opt, s, res){
  1016. var r = new Ext.decode(res.responseText);
  1017. if (r.exceptionInfo) {
  1018. showError(r.exceptionInfo);
  1019. } else if(r.success) {
  1020. if (r.data != null) {
  1021. if (merge || !cfg.url) {
  1022. if(r.data.vs_datalist)
  1023. me.showSourceGrid(vscode, r.data.vs_datalist, r.data.vs_prikey1,
  1024. r.data.vs_pritable, r.data.vs_classfield, cls, pri, cfg);
  1025. else
  1026. showError('凭证公式未配置列表参数,无法显示来源!');
  1027. } else
  1028. me.linkSource(vscode, r.data.vs_prikey1, r.data.vs_pritable,
  1029. r.data.vs_classfield, cls, pri, cfg);
  1030. } else {
  1031. showMessage('提示', '当前凭证没有来源信息!', 3000);
  1032. }
  1033. }
  1034. }
  1035. });
  1036. },
  1037. linkSource : function(vscode, key, tab, clsfield, cls, pri, cfg) {
  1038. var me = this, url = cfg.url, k = cfg.keyfield, m = cfg.mainfield;
  1039. if (url) {
  1040. Ext.Ajax.request({
  1041. url : basePath + 'common/getFieldData.action',
  1042. async: false,
  1043. params: {
  1044. caller: tab,
  1045. field: k,
  1046. condition: key + '=' + pri + (clsfield ? (' and ' + clsfield + '=\'' + cls + '\'') : '')
  1047. },
  1048. method : 'post',
  1049. callback : function(opt, s, res){
  1050. var r = new Ext.decode(res.responseText);
  1051. if(r.exceptionInfo){
  1052. showError(r.exceptionInfo);
  1053. } else if(r.success && r.data){
  1054. url += url.indexOf('?') > 0 ? '&' : '?';
  1055. me.FormUtil.onAdd(null, '来源', url + 'formCondition=' + k + 'IS' +
  1056. r.data + '&gridCondition=' + m + 'IS' + r.data);
  1057. }
  1058. }
  1059. });
  1060. }
  1061. },
  1062. showSourceGrid : function(vscode, cal, key, tab, clsfield, cls, pri, cfg) {
  1063. var me = this,
  1064. condition = key + ' in (' + pri + ')';
  1065. if('PRODINOUT' == vscode) {
  1066. condition += ' and pi_class=\'' + cls + '\'';
  1067. }
  1068. var w = Ext.isIE ? 800 : '80%',
  1069. h = Ext.isIE ? 500 : '100%';
  1070. var win = Ext.create('Ext.Window', {
  1071. width: w,
  1072. height: h,
  1073. title: '凭证来源',
  1074. layout: 'anchor',
  1075. items: [],
  1076. buttonAlign: 'center',
  1077. buttons: [{
  1078. text: $I18N.common.button.erpExportButton,
  1079. cls: 'x-btn-gray',
  1080. iconCls: 'x-button-icon-ecel',
  1081. handler: function(btn) {
  1082. me.BaseUtil.exportGrid(btn.ownerCt.ownerCt.down('grid'));
  1083. btn.ownerCt.ownerCt.close();
  1084. }
  1085. },{
  1086. text: $I18N.common.button.erpCloseButton,
  1087. cls: 'x-btn-gray',
  1088. iconCls: 'x-button-icon-close',
  1089. handler: function(btn) {
  1090. btn.ownerCt.ownerCt.close();
  1091. }
  1092. }]
  1093. }).show();
  1094. var grid = Ext.create('Ext.grid.Panel', {
  1095. anchor: '100% 100%',
  1096. columnLines: true,
  1097. columns: [],
  1098. store: []
  1099. });
  1100. win.add(grid);
  1101. me.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', {caller: cal, condition: condition});
  1102. grid.on('itemclick', function(s, r){
  1103. me.linkSource(vscode, key, tab, clsfield, cls, "\'" + r.get(key) + "\'", cfg);
  1104. });
  1105. },
  1106. getSourceConfig : function(vscode, vdclass) {
  1107. var url = null, keyfield = null, mainfield = null;
  1108. if(vscode == 'RecBalance') {
  1109. keyfield = 'rb_id';
  1110. mainfield = 'rbd_rbid';
  1111. switch (vdclass) {
  1112. case '应收冲应付':
  1113. url = 'jsps/fa/ars/recBalanceAP.jsp?whoami=RecBalance!RRCW';
  1114. break;
  1115. case '收款单':
  1116. url = 'jsps/fa/ars/recBalance.jsp?whoami=RecBalance!PBIL';
  1117. break;
  1118. case '冲应收款':
  1119. url = 'jsps/fa/ars/recBalance.jsp?whoami=RecBalance!IMRE';
  1120. break;
  1121. case '预收冲应收':
  1122. url = 'jsps/fa/ars/recBalancePRDetail.jsp?whoami=RecBalance!PTAR';
  1123. break;
  1124. case '应收票据':
  1125. url = 'jsps/fa/gs/billAR.jsp';
  1126. break;
  1127. case '应收款转销':
  1128. url = 'jsps/fa/ars/recBalance.jsp?whoami=RecBalance!ARRM';
  1129. break;
  1130. case '应收退款单':
  1131. url = 'jsps/fa/ars/recBalanceTK.jsp?whoami=RecBalance!TK';
  1132. break;
  1133. }
  1134. } else if(vscode == 'PreRec') {
  1135. keyfield = 'pr_id';
  1136. mainfield = 'prd_prid';
  1137. switch (vdclass) {
  1138. case '预收款':
  1139. url = 'jsps/fa/ars/preRec.jsp?whoami=PreRec!Ars!DERE';
  1140. break;
  1141. case '预收退款':
  1142. url = 'jsps/fa/ars/preRec.jsp?whoami=PreRec!Ars!DEPR';
  1143. break;
  1144. case '预收退款单':
  1145. url = 'jsps/fa/ars/preRec.jsp?whoami=PreRec!Ars!DEPR';
  1146. break;
  1147. }
  1148. } else if(vscode == 'PrePay') {
  1149. keyfield = 'pp_id';
  1150. mainfield = 'ppd_ppid';
  1151. switch (vdclass) {
  1152. case '预付款':
  1153. url = 'jsps/fa/arp/prepay.jsp?whoami=PrePay!Arp!PAMT';
  1154. break;
  1155. case '预付退款':
  1156. url = 'jsps/fa/arp/prepay.jsp?whoami=PrePay!Arp!PAPR';
  1157. break;
  1158. case '预付退款单':
  1159. url = 'jsps/fa/arp/prepay.jsp?whoami=PrePay!Arp!PAPR';
  1160. break;
  1161. }
  1162. } else if(vscode == 'PrePaid') {
  1163. keyfield = 'pp_id';
  1164. mainfield = 'pd_ppid';
  1165. switch (vdclass) {
  1166. case '摊销':
  1167. url = 'jsps/fa/gla/prePaid.jsp';
  1168. break;
  1169. }
  1170. } else if(vscode == 'PurcFee') {
  1171. keyfield = 'pi_id';
  1172. mainfield = 'pd_piid';
  1173. switch (vdclass) {
  1174. case '采购验收单':
  1175. url = 'jsps/scm/reserve/prodinout.jsp?whoami=ProdInOut!PurcCheckin';
  1176. break;
  1177. case '采购验退单':
  1178. url = 'jsps/scm/reserve/prodinout.jsp?whoami=ProdInOut!PurcCheckout';
  1179. break;
  1180. }
  1181. } else if(vscode == 'PayBalance') {
  1182. keyfield = 'pb_id';
  1183. mainfield = 'pbd_pbid';
  1184. switch (vdclass) {
  1185. case '冲应付款':
  1186. url = 'jsps/fa/arp/paybalance.jsp?whoami=PayBalance!CAID';
  1187. break;
  1188. case '应付款转销':
  1189. url = 'jsps/fa/arp/paybalance.jsp?whoami=PayBalance!APRM';
  1190. break;
  1191. case '预付冲应付':
  1192. url = 'jsps/fa/arp/payBalancePRDetail.jsp?whoami=PayBalance!Arp!PADW';
  1193. break;
  1194. case '付款单':
  1195. url = 'jsps/fa/arp/paybalance.jsp?whoami=PayBalance';
  1196. break;
  1197. case '应付冲应收':
  1198. url = 'jsps/fa/arp/paybalance.jsp?whoami=PayBalance!DWRC';
  1199. break;
  1200. case '应付退款单':
  1201. url = 'jsps/fa/arp/paybalanceTK.jsp?whoami=PayBalance!TK';
  1202. break;
  1203. }
  1204. } else if(vscode == 'AccountRegiste') {
  1205. keyfield = 'ar_id';
  1206. mainfield = 'ard_arid';
  1207. url = 'jsps/fa/gs/accountRegister.jsp?whoami=AccountRegister!Bank';
  1208. } else if(vscode == 'Estimate') {
  1209. keyfield = 'es_id';
  1210. mainfield = 'esd_esid';
  1211. url = 'jsps/fa/arp/estimate.jsp?whoami=Estimate';
  1212. } else if(vscode == 'GoodsSend') {
  1213. keyfield = 'gs_id';
  1214. mainfield = 'gsd_gsid';
  1215. url = 'jsps/fa/ars/goodsSend.jsp?whoami=GoodsSendGs';
  1216. } else if(vscode == 'ARBill') {
  1217. keyfield = 'ab_id';
  1218. mainfield = 'abd_abid';
  1219. switch (vdclass) {
  1220. case '其它应收单':
  1221. url = 'jsps/fa/ars/arbill.jsp?whoami=ARBill!OTRS';
  1222. break;
  1223. case '应收发票':
  1224. url = 'jsps/fa/ars/arbill.jsp?whoami=ARBill!IRMA';
  1225. break;
  1226. }
  1227. } else if(vscode == 'APBill') {
  1228. keyfield = 'ab_id';
  1229. mainfield = 'abd_abid';
  1230. switch (vdclass) {
  1231. case '其它应付单':
  1232. url = 'jsps/fa/ars/apbill.jsp?whoami=APBill!OTDW';
  1233. break;
  1234. case '应付发票':
  1235. url = 'jsps/fa/ars/apbill.jsp?whoami=APBill!CWIM';
  1236. break;
  1237. }
  1238. } else if(vscode == 'BillOut') {
  1239. keyfield = 'bi_id';
  1240. mainfield = 'ard_biid';
  1241. url = 'jsps/fa/ars/billOut.jsp';
  1242. } else if(vscode == 'BillOutAP') {
  1243. keyfield = 'bi_id';
  1244. mainfield = 'ard_biid';
  1245. url = 'jsps/fa/arp/billOutAP.jsp';
  1246. } else if(vscode == 'AssetsCard') {
  1247. keyfield = 'ac_id';
  1248. url = 'jsps/fa/fix/assetsCard.jsp';
  1249. } else if(vscode == 'Depreciation') {
  1250. keyfield = 'de_id';
  1251. mainfield = 'dd_deid';
  1252. switch (vdclass) {
  1253. case '折旧单':
  1254. url = 'jsps/fa/fix/assetsDepreciation.jsp?whoami=AssetsDepreciation';
  1255. break;
  1256. case '资产增加单':
  1257. url = 'jsps/fa/fix/assetsDepreciation.jsp?whoami=AssetsDepreciation!Add';
  1258. break;
  1259. case '资产减少单':
  1260. url = 'jsps/fa/fix/assetsDepreciation.jsp?whoami=AssetsDepreciation!Reduce';
  1261. break;
  1262. }
  1263. } else if(vscode == 'PRODINOUT') {
  1264. keyfield = 'pi_id';
  1265. mainfield = 'pd_piid';
  1266. url = 'jsps/scm/reserve/prodInOut.jsp';
  1267. var call;
  1268. switch (vdclass) {
  1269. case '采购验收单':
  1270. call = 'ProdInOut!PurcCheckin';
  1271. break;
  1272. case '采购验退单':
  1273. call = 'ProdInOut!PurcCheckout';
  1274. break;
  1275. case '出货单':
  1276. call = 'ProdInOut!Sale';
  1277. break;
  1278. case '拨入单':
  1279. call = 'ProdInOut!AppropriationIn';
  1280. break;
  1281. case '销售拨出单':
  1282. call = 'ProdInOut!SaleAppropriationOut';
  1283. break;
  1284. case '销售退货单':
  1285. call = 'ProdInOut!SaleReturn';
  1286. break;
  1287. case '拨出单':
  1288. call = 'ProdInOut!AppropriationOut';
  1289. break;
  1290. case '不良品入库单':
  1291. call = 'ProdInOut!DefectIn';
  1292. break;
  1293. case '不良品出库单':
  1294. call = 'ProdInOut!DefectOut';
  1295. break;
  1296. case '委外领料单':
  1297. call = 'ProdInOut!OutsidePicking';
  1298. break;
  1299. case '委外退料单':
  1300. call = 'ProdInOut!OutsideReturn';
  1301. break;
  1302. case '委外验收单':
  1303. call = 'ProdInOut!OutsideCheckIn';
  1304. break;
  1305. case '委外验退单':
  1306. call = 'ProdInOut!OutesideCheckReturn';
  1307. break;
  1308. case '借货归还单':
  1309. call = 'ProdInOut!OutReturn';
  1310. break;
  1311. case '研发采购验收单':
  1312. call = 'ProdInOut!PurcCheckin!PLM';
  1313. break;
  1314. case '研发采购验退单':
  1315. call = 'ProdInOut!PurcCheckout!PLM';
  1316. break;
  1317. case '换货入库单':
  1318. call = 'ProdInOut!ExchangeIn';
  1319. break;
  1320. case '换货出库单':
  1321. call = 'ProdInOut!ExchangeOut';
  1322. break;
  1323. case '生产补料单':
  1324. call = 'ProdInOut!Make!Give';
  1325. break;
  1326. case '完工入库单':
  1327. call = 'ProdInOut!Make!In';
  1328. break;
  1329. case '生产退料单':
  1330. call = 'ProdInOut!Make!Return';
  1331. break;
  1332. case '生产报废单':
  1333. call = 'ProdInOut!Make!Useless';
  1334. break;
  1335. case '无订单出货单':
  1336. call = 'ProdInOut!NoSale';
  1337. break;
  1338. case '委外补料单':
  1339. call = 'ProdInOut!OSMake!Give';
  1340. break;
  1341. case '其它入库单':
  1342. call = 'ProdInOut!OtherIn';
  1343. break;
  1344. case '其它出库单':
  1345. call = 'ProdInOut!OtherOut';
  1346. break;
  1347. case '其它采购入库单':
  1348. call = 'ProdInOut!OtherPurcIn';
  1349. break;
  1350. case '其它采购出库单':
  1351. call = 'ProdInOut!OtherPurcOut';
  1352. break;
  1353. case '拆件入库单':
  1354. call = 'ProdInOut!PartitionStockIn';
  1355. break;
  1356. case '生产领料单':
  1357. call = 'ProdInOut!Picking';
  1358. break;
  1359. case '库存初始化':
  1360. call = 'ProdInOut!ReserveInitialize';
  1361. break;
  1362. case '借货出货单':
  1363. call = 'ProdInOut!SaleBorrow';
  1364. break;
  1365. case '销售拨入单':
  1366. call = 'ProdInOut!SaleAppropriationIn';
  1367. break;
  1368. case '盘亏调整单':
  1369. call = 'ProdInOut!StockLoss';
  1370. break;
  1371. case '盘盈调整单':
  1372. call = 'ProdInOut!StockProfit';
  1373. break;
  1374. case '报废单':
  1375. call = 'ProdInOut!StockScrap';
  1376. break;
  1377. case '研发退料单':
  1378. call = 'ProdInOut!YFIN';
  1379. break;
  1380. case '研发领料单':
  1381. call = 'ProdInOut!YFOUT';
  1382. break;
  1383. case '成本调整单':
  1384. call = 'ProdInOut!CostChange';
  1385. break;
  1386. }
  1387. call && (url += '?whoami=' + call);
  1388. } else if(vscode == 'BillAR') {
  1389. url = 'jsps/fa/gs/billAR.jsp';
  1390. keyfield = 'bar_id';
  1391. } else if(vscode == 'BillAP') {
  1392. url = 'jsps/fa/gs/billAP.jsp';
  1393. keyfield = 'bap_id';
  1394. } else if(vscode == 'BillARChange') {
  1395. url = 'jsps/fa/gs/billARChange.jsp';
  1396. keyfield = 'brc_id';
  1397. mainfield = 'brd_brcid';
  1398. } else if(vscode == 'BillAPChange') {
  1399. url = 'jsps/fa/gs/billAPChange.jsp';
  1400. keyfield = 'bpc_id';
  1401. mainfield = 'bpd_bpcid';
  1402. }
  1403. return {url : url, keyfield : keyfield, mainfield : mainfield};
  1404. },
  1405. levelOut:function (target){
  1406. var grid = Ext.getCmp('grid'), me = this;
  1407. var record = grid.selModel.lastSelected;
  1408. if(record){
  1409. var f = Ext.getCmp('vo_currencytype');
  1410. var debit = 0;
  1411. var credit = 0;
  1412. var rate = record.get('vd_rate');
  1413. rate = rate == 0 ? 1 : rate;
  1414. grid.getStore().each(function(item){
  1415. if(item.id != record.id){
  1416. debit += item.get('vd_debit');
  1417. credit += item.get('vd_credit');
  1418. }
  1419. });
  1420. var targetName = target.name;
  1421. if(record.get('vd_debit') != 0)
  1422. targetName = 'vd_debit';
  1423. else if(record.get('vd_credit') != 0)
  1424. targetName = 'vd_credit';
  1425. if(targetName && typeof targetName == 'string') {
  1426. if(targetName == 'vd_debit') {
  1427. debit = credit - debit;
  1428. record.set('vd_debit', me.BaseUtil.numberFormat(debit, 4));
  1429. if(f.checked) {
  1430. record.set('vd_doubledebit', me.BaseUtil.numberFormat(debit/rate, 4));
  1431. }
  1432. } else if(targetName == 'vd_credit'){
  1433. credit = debit - credit;
  1434. record.set('vd_credit', me.BaseUtil.numberFormat(credit, 4));
  1435. if(f.checked) {
  1436. record.set('vd_doublecredit', me.BaseUtil.numberFormat(credit/rate, 4));
  1437. }
  1438. }
  1439. if(target.name == targetName)
  1440. target.value = record.get(targetName);
  1441. } else {
  1442. if(credit > debit) {
  1443. record.set('vd_debit', credit - debit);
  1444. if(f.checked) {
  1445. record.set('vd_doubledebit', me.BaseUtil.numberFormat((credit - debit)/rate, 4));
  1446. }
  1447. } else {
  1448. record.set('vd_credit', debit - credit);
  1449. if(f.checked) {
  1450. record.set('vd_doublecredit', me.BaseUtil.numberFormat((debit - credit)/rate, 4));
  1451. }
  1452. }
  1453. }
  1454. }
  1455. },
  1456. showCateTree: function(f) {
  1457. var cawin = Ext.getCmp('cawin');
  1458. if(!cawin) {
  1459. cawin = new Ext.window.Window({
  1460. id : 'cawin',
  1461. title: '科目查找',
  1462. height: "100%",
  1463. width: "80%",
  1464. maximizable : true,
  1465. buttonAlign : 'center',
  1466. layout : 'anchor',
  1467. modal:true,
  1468. items: [{
  1469. tag : 'iframe',
  1470. frame : true,
  1471. anchor : '100% 100%',
  1472. layout : 'fit',
  1473. html : '<iframe id="iframe_dbfind_'+caller+"_"+f.name+"="+f.value+'" src="'+basePath+'jsps/common/catetreepaneldbfind.jsp?key='+f.name+"&dbfind=&caller1="+caller+"&keyValue="+f.value+"&trigger="+f.id+'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  1474. }],
  1475. buttons : [{
  1476. text : '确 认',
  1477. iconCls: 'x-button-icon-save',
  1478. cls: 'x-btn-gray',
  1479. handler : function(btn){
  1480. var contentwindow = Ext.getCmp('cawin').body.dom.getElementsByTagName('iframe')[0].contentWindow;
  1481. var tree = contentwindow.Ext.getCmp('tree-panel');
  1482. var data = tree.getChecked(), record = Ext.getCmp('grid').selModel.lastSelected;
  1483. var dbfinds = Ext.getCmp('grid').dbfinds;
  1484. if(dbfinds != null && record){
  1485. Ext.each(dbfinds, function(dbfind,index){
  1486. record.set(dbfind.field, data[0].raw.data[dbfind.dbGridField]);
  1487. });
  1488. }
  1489. f.fireEvent('aftertrigger', f, data);
  1490. btn.ownerCt.ownerCt.hide();
  1491. }
  1492. },{
  1493. text : '关 闭',
  1494. iconCls: 'x-button-icon-close',
  1495. cls: 'x-btn-gray',
  1496. handler : function(btn){
  1497. btn.ownerCt.ownerCt.hide();
  1498. }
  1499. }]
  1500. });
  1501. }
  1502. cawin.show();
  1503. },
  1504. getMonth: function(callback) {
  1505. Ext.Ajax.request({
  1506. url: basePath + 'fa/getMonth.action',
  1507. params: {
  1508. votype: 'GL'
  1509. },
  1510. callback: function(opt, s, r) {
  1511. var rs = Ext.decode(r.responseText);
  1512. if(rs.data) {
  1513. callback.call(null, rs.data);
  1514. }
  1515. }
  1516. });
  1517. },
  1518. /**
  1519. * 显示模板
  1520. */
  1521. showTp: function() {
  1522. var me = this, win = me.tpWin;
  1523. if(!win) {
  1524. win = me.tpWin = new Ext.window.Window({
  1525. id: 'tp-win',
  1526. width: '84%',
  1527. height: '100%',
  1528. title: '选择模板',
  1529. layout: 'anchor',
  1530. closeAction: 'hide',
  1531. items: [{
  1532. xtype: 'container',
  1533. anchor: '100% 100%',
  1534. html: '<iframe src="' + basePath + 'jsps/common/datalist.jsp?whoami=Voucher!TP&&parentDoc=tp-win" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  1535. }],
  1536. listeners: {
  1537. 'itemselect': function(scope, data) {
  1538. me.loadTp(data.vo_id);
  1539. scope.hide();
  1540. },
  1541. 'close': function(scope) {
  1542. scope.hide();
  1543. }
  1544. }
  1545. });
  1546. }
  1547. win.show();
  1548. },
  1549. /**
  1550. * 加载模板
  1551. */
  1552. loadTp: function(id) {
  1553. Ext.Ajax.request({
  1554. url: basePath + 'fa/gla/getvotp.action',
  1555. params: {
  1556. id: id
  1557. },
  1558. callback: function(opt, s, r) {
  1559. var rs = Ext.decode(r.responseText);
  1560. if(rs.data) {
  1561. var form = Ext.getCmp('form'), grid = Ext.getCmp('grid');
  1562. form.getForm().setValues(rs.data.voucher);
  1563. grid.store.loadData(rs.data.voucherdetail);
  1564. var store = grid.store, i = 0, exp = grid.plugins[2];
  1565. grid.store.each(function(record){
  1566. exp.toggleRow(i++);
  1567. record.dirty = true;
  1568. });
  1569. } else {
  1570. showError(rs.exceptionInfo);
  1571. }
  1572. }
  1573. });
  1574. },
  1575. /**
  1576. * 添加到凭证模板
  1577. */
  1578. createTp: function(){
  1579. var form = Ext.getCmp('form');
  1580. var v = form.down('#vo_id').value;
  1581. if(v > 0) {
  1582. form.setLoading(true);
  1583. Ext.Ajax.request({
  1584. url: basePath + 'fa/gla/copyvotp.action',
  1585. params: {
  1586. id: v
  1587. },
  1588. callback: function(opt, s, r){
  1589. form.setLoading(false);
  1590. var res = Ext.decode(r.responseText);
  1591. if(res.data) {
  1592. showMessage('提示', '添加成功!<a href="javascript:openUrl(\'jsps/fa/gla/vouchertp.jsp?formCondition=vo_idIS' +
  1593. + res.data.vo_id + '&gridCondition=vd_voidIS' + res.data.vo_id +
  1594. '\')"> \n流水号:&lt;' + res.data.vo_code + '&gt;</a>');
  1595. } else {
  1596. showError(res.exceptionInfo);
  1597. }
  1598. }
  1599. });
  1600. }
  1601. }
  1602. });