AccountRegister.js 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153
  1. Ext.define('erp.controller.fa.gs.AccountRegister', {
  2. extend: 'Ext.app.Controller',
  3. FormUtil: Ext.create('erp.util.FormUtil'),
  4. BaseUtil: Ext.create('erp.util.BaseUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. views:[
  7. 'fa.gs.AccountRegister','core.form.Panel','core.grid.Panel2','core.toolbar.Toolbar',
  8. 'fa.gs.DetailAssGrid','core.form.MultiField','core.button.TurnPayBalance','core.button.TurnRecBalance',
  9. 'core.button.Add','core.button.Save','core.button.Close','core.button.Accounted','core.button.ResAccounted',
  10. 'core.button.Submit','core.button.ResSubmit','core.button.Audit','core.button.ResAudit','core.button.UpdateRemark',
  11. 'core.button.Update','core.button.Delete','core.form.YnField','core.button.DeleteDetail','core.button.AssMain','core.button.Print',
  12. 'core.button.CopyAll','core.button.confirmType','core.button.TurnRecBalanceIMRE','core.button.GetRefNum',
  13. 'core.trigger.DbfindTrigger','core.grid.YnColumn','core.trigger.TextAreaTrigger', 'core.form.SeparNumber','core.button.ExportExcelButton'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'textfield[name=ar_memo]':{
  19. beforerender: function(field){
  20. field.readOnly=false;
  21. }
  22. },
  23. 'textfield[name=ar_deposit]':{
  24. beforerender: function(field){
  25. if(Ext.getCmp('ar_type')&&Ext.getCmp('ar_type').value=="暂收款"){
  26. if(Ext.getCmp('ar_source')&&Ext.getCmp('ar_source').value!=""){
  27. field.readOnly=true;
  28. }
  29. }
  30. }
  31. },
  32. 'field[name=ar_vendcode]':{
  33. beforerender: function(field){
  34. if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value=="付款申请"){
  35. field.readOnly=true;
  36. }
  37. }
  38. },
  39. 'textfield[name=ar_payment]':{
  40. beforerender: function(field){
  41. var type = Ext.getCmp('ar_type');
  42. if(type &&type.value=="暂收款"){
  43. if(Ext.getCmp('ar_source')&&Ext.getCmp('ar_source').value!=""){
  44. field.readOnly=true;
  45. }
  46. }
  47. if(type&&(type.value=="应付款"||type.value=="预付款")){
  48. if(Ext.getCmp('ar_source')&&Ext.getCmp('ar_source').value!=""){
  49. if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value=="付款申请"){
  50. field.readOnly=false;
  51. } else {
  52. field.readOnly=true;
  53. }
  54. }
  55. }
  56. }
  57. },
  58. 'field[name=ar_precurrency]': {
  59. beforetrigger: function(field) {
  60. var t = field.up('form').down('field[name=ar_date]'),
  61. value = t.getValue();
  62. if(value) {
  63. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  64. }
  65. }
  66. },
  67. 'erpFormPanel' : {
  68. afterload : function(form) {
  69. form.getForm().getFields().each(function() {
  70. var val = getUrlParam(this.name);
  71. if(!Ext.isEmpty(val) && Ext.isEmpty(this.getValue())) {
  72. this.setValue(val);
  73. }
  74. });
  75. var t = form.down('#ar_type');
  76. /*if(t.value == '应收票据收款'||t.value == '应付票据付款'){
  77. form.getForm().getFields().each(function(field) {
  78. if(typeof field.setReadOnly == 'function' && field.name != 'ar_memo' && field.name != 'ar_accountcurrency' && field.name != 'ar_accountrate' && field.name != 'ar_deposit' && field.name != 'ar_payment')
  79. field.setReadOnly(true);
  80. });
  81. }*/
  82. this.hidecolumns(t);
  83. }
  84. },
  85. 'erpCopyButton': {
  86. click: function(btn) {
  87. this.copy();
  88. }
  89. },
  90. 'erpSaveButton': {
  91. click: function(btn){
  92. var form = me.getForm(btn);
  93. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  94. me.BaseUtil.getRandomNumber();//自动添加编号
  95. }
  96. this.getApamount();
  97. //保存之前的一些前台的逻辑判定
  98. this.beforeSave();
  99. }
  100. },
  101. 'erpCloseButton': {
  102. click: function(btn){
  103. this.FormUtil.beforeClose(this);
  104. }
  105. },
  106. 'erpUpdateButton': {
  107. afterrender: function(btn){
  108. var status = Ext.getCmp('ar_statuscode');
  109. if(status && status.value != 'ENTERING' && status.value != 'COMMITED'){
  110. btn.hide();
  111. } else {
  112. btn.show();
  113. }
  114. },
  115. click: function(btn){
  116. this.getApamount();
  117. this.beforeUpdate();
  118. }
  119. },
  120. 'erpPrintButton': {
  121. click: function(btn) {
  122. var reportName = '';
  123. reportName = "AccountCount";
  124. var condition = '{AccountRegister.ar_id}=' + Ext.getCmp('ar_id').value + '';
  125. var id = Ext.getCmp('ar_id').value;
  126. me.FormUtil.onwindowsPrint(id, reportName, condition);
  127. }
  128. },
  129. 'erpExportExcelButton':{
  130. afterrender:function(btn){
  131. btn.exportCaller="AccountRegisterDetailAss!Export";
  132. var status = Ext.getCmp('ar_statuscode').value;
  133. if(status&&status!='ENTERING'){
  134. btn.hide();
  135. }
  136. }
  137. },
  138. 'erpDeleteButton': {
  139. afterrender: function(btn){
  140. var status = Ext.getCmp('ar_statuscode');
  141. if(status && status.value != 'ENTERING'){
  142. btn.hide();
  143. }
  144. },
  145. click: function(btn){
  146. var source = Ext.getCmp('ar_sourcetype');
  147. if(!Ext.isEmpty(source.value)){
  148. if(source.value != '付款申请' && source.value != '应收发票' && source.value != '模具付款申请' && source.value != '费用报销单' && source.value != '总务申请单' && source.value != '还款申请单' && source.value != '借款申请单' && source.value != '差旅费报销单'){
  149. showError("请在来源:"+source.value+",单号:"+Ext.getCmp('ar_source').value+"中进行反记账操作!");
  150. return;
  151. }
  152. if(source.value == '应收发票'){
  153. showError("请在来源:"+source.value+",单号:"+Ext.getCmp('ar_source').value+"中进行取消收款操作!");
  154. return;
  155. }
  156. }
  157. me.FormUtil.onDelete(Ext.getCmp('ar_id').value);
  158. }
  159. },
  160. 'erpAddButton': {
  161. click: function(b){
  162. url = 'jsps/fa/gs/accountRegister.jsp?whoami=' + caller;
  163. var cacode = Ext.getCmp('ar_accountcode').value;
  164. if(cacode != null && cacode != ""){
  165. url += '&ar_cateid=' + Ext.getCmp('ar_cateid').value;
  166. url += '&ar_accountcode=' + cacode;
  167. url += '&ar_accountname=' + Ext.getCmp('ar_accountname').value;
  168. url += '&ar_accountcurrency=' + Ext.getCmp('ar_accountcurrency').value;
  169. url += '&ar_accountrate=' +Ext.getCmp('ar_accountrate').value;
  170. }
  171. var tab = me.FormUtil.getActiveTab();
  172. me.FormUtil.onAdd('addAccountRegister', '新增银行存款登记', url);
  173. setTimeout(function(){
  174. if(tab) {
  175. tab.close();
  176. }
  177. }, 200);
  178. }
  179. },
  180. 'filefield[id=excelfile]':{
  181. change: function(field){
  182. warnMsg('确认要重新导入吗?', function(btn){
  183. if(btn == 'yes'){
  184. var keyValue=Ext.getCmp('ar_id').getValue();
  185. if(contains(field.value, "\\", true)){
  186. filename = field.value.substring(field.value.lastIndexOf('\\') + 1);
  187. } else {
  188. filename = field.value.substring(field.value.lastIndexOf('/') + 1);
  189. }
  190. field.ownerCt.getForm().submit({
  191. url: basePath + 'common/upload.action?em_code=' + em_code,
  192. waitMsg: "正在解析文件信息",
  193. success: function(fp,o){
  194. if(o.result.error){
  195. showError(o.result.error);
  196. } else {
  197. var filePath=o.result.filepath;
  198. Ext.Ajax.request({//拿到form的items
  199. url : basePath + 'fa/gs/ImportRegisterExcel.action',
  200. params:{
  201. id:keyValue,
  202. fileId:filePath
  203. },
  204. method : 'post',
  205. callback : function(options,success,response){
  206. var result=Ext.decode(response.responseText);
  207. if(result.success){
  208. Ext.Msg.alert('提示','导入成功!');
  209. window.location.reload();
  210. }else{
  211. if(result.exceptionInfo != null){
  212. showError(res.exceptionInfo);return;
  213. }
  214. }
  215. }
  216. });
  217. }
  218. }
  219. });
  220. }
  221. });
  222. }
  223. },
  224. 'erpSubmitButton': {
  225. afterrender: function(btn){
  226. var status = Ext.getCmp('ar_statuscode');
  227. if(status && status.value != 'ENTERING'){
  228. btn.hide();
  229. }
  230. },
  231. click: function(btn){
  232. me.beforeSubmit(btn);
  233. }
  234. },
  235. 'erpResSubmitButton': {
  236. afterrender: function(btn){
  237. var status = Ext.getCmp('ar_statuscode');
  238. if(status && status.value != 'COMMITED'){
  239. btn.hide();
  240. }
  241. },
  242. click: function(btn){
  243. me.FormUtil.onResSubmit(Ext.getCmp('ar_id').value);
  244. }
  245. },
  246. 'erpAccountedButton': {
  247. afterrender: function(btn){
  248. var status = Ext.getCmp('ar_statuscode');
  249. if(status && status.value != 'COMMITED'){
  250. btn.hide();
  251. }
  252. },
  253. click: function(btn){
  254. me.beforeAccount(btn);
  255. }
  256. },
  257. /*'erpConfirmTypeButton':{
  258. afterrender: function(btn){
  259. if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
  260. btn.hide();
  261. }
  262. }
  263. },*/
  264. 'erpResAccountedButton': {
  265. afterrender: function(btn){
  266. var status = Ext.getCmp('ar_statuscode');
  267. if(status && status.value != 'POSTED'){
  268. btn.hide();
  269. }
  270. },
  271. click: function(btn){
  272. me.FormUtil.onResAccounted(Ext.getCmp('ar_id').value);
  273. }
  274. },
  275. 'erpTurnPayBalanceButton': {
  276. afterrender: function(btn){
  277. var status = Ext.getCmp('ar_statuscode');
  278. if(status && status.value != 'ACCOUNT'){
  279. btn.hide();
  280. }
  281. },
  282. click: function(b){
  283. warnMsg("确定要转入付款单吗?", function(btn){
  284. if(btn == 'yes'){
  285. me.turnPayBalance(b.ownerCt.ownerCt);
  286. }
  287. });
  288. }
  289. },
  290. 'erpTurnRecBalanceIMREButton':{
  291. afterrender: function(btn){
  292. var status = Ext.getCmp('ar_statuscode'), type = Ext.getCmp('ar_type');
  293. if(status && status.value != 'POSTED'){
  294. btn.hide();
  295. }
  296. if(type && type.value != '暂收款'){
  297. btn.hide();
  298. }
  299. },
  300. click: function(btn){
  301. var me = this, win = Ext.getCmp('Complaint-win');
  302. if(!win) {
  303. var amount = Ext.getCmp('ar_deposit'), yamount = Ext.getCmp('ar_recamount'),
  304. val1 = amount ? (amount.value-yamount.value) : 0;
  305. win = Ext.create('Ext.Window', {
  306. id: 'Complaint-win',
  307. title: '转冲应收款单',
  308. height: 200,
  309. width: 400,
  310. items: [{
  311. xtype: 'form',
  312. height: '100%',
  313. width: '100%',
  314. bodyStyle: 'background:#f1f2f5;',
  315. items: [{
  316. margin: '10 0 0 0',
  317. xtype: 'dbfindtrigger',
  318. fieldLabel: '客户编号',
  319. id: 'cu_code',
  320. name:'cu_code',
  321. allowBlank: false,
  322. listeners:{
  323. aftertrigger:function(t, d){
  324. t.ownerCt.down('textfield[name=cu_name]').setValue(d.get('cu_name'));
  325. }
  326. }
  327. },{
  328. margin: '3 0 0 0',
  329. xtype: 'textfield',
  330. fieldLabel: '客户名称',
  331. readOnly:true,
  332. id: 'cu_name',
  333. name:'cu_name',
  334. allowBlank: false
  335. },{
  336. margin: '3 0 0 0',
  337. xtype: 'textfield',
  338. fieldLabel: '本次转金额',
  339. id: 'ar_thisamount',
  340. readOnly:false,
  341. allowBlank: false,
  342. value: val1
  343. }],
  344. closeAction: 'hide',
  345. buttonAlign: 'center',
  346. layout: {
  347. type: 'vbox',
  348. align: 'center'
  349. },
  350. buttons: [{
  351. text: $I18N.common.button.erpConfirmButton,
  352. cls: 'x-btn-blue',
  353. handler: function(btn) {
  354. var thisform = btn.ownerCt.ownerCt;
  355. Ext.Ajax.request({
  356. url: basePath + '/fa/gs/arTurnRecBalanceIMRE.action',
  357. params: {
  358. id: Ext.getCmp('ar_id').value,
  359. custcode: thisform.down("#cu_code").value,
  360. thisamount: thisform.down("#ar_thisamount").value
  361. },
  362. callback : function(options,success,response){
  363. thisform.setLoading(false);
  364. var localJson = new Ext.decode(response.responseText);
  365. if(localJson.exceptionInfo){
  366. showError(localJson.exceptionInfo);
  367. }
  368. if(localJson.success){
  369. turnSuccess(function(){
  370. var id = localJson.id;
  371. var url = "jsps/fa/ars/recBalance.jsp?formCondition=rb_id=" + id +"&whoami=RecBalance!IMRE";
  372. me.FormUtil.onAdd('RecBalance' + id, '冲应收款' + id, url);
  373. });
  374. }
  375. window.location.reload();
  376. }
  377. });
  378. }
  379. }, {
  380. text: $I18N.common.button.erpCloseButton,
  381. cls: 'x-btn-blue',
  382. handler: function(btn) {
  383. btn.up('window').hide();
  384. }
  385. }]
  386. }]
  387. });
  388. }
  389. win.show();
  390. }
  391. },
  392. 'erpTurnRecBalanceButton': {
  393. afterrender: function(btn){
  394. var status = Ext.getCmp('ar_statuscode');
  395. if(status && status.value != 'ACCOUNT'){
  396. btn.hide();
  397. }
  398. },
  399. click: function(b){
  400. warnMsg("确定要转入收款单吗?", function(btn){
  401. if(btn == 'yes'){
  402. me.turnRecBalance(b.ownerCt.ownerCt);
  403. }
  404. });
  405. }
  406. },
  407. 'erpUpdateRemarkButton':{
  408. click:function(){
  409. var remark=Ext.getCmp('ar_memo');
  410. me.updateRemark(remark.value,Ext.getCmp('ar_id').value);
  411. }
  412. },
  413. 'field[name=ar_errstring]': {
  414. afterrender: function(f){
  415. if(f.value != null && f.value != ''){
  416. f.inputEl.setStyle({color: 'OrangeRed'});
  417. } else {
  418. f.setValue('正常');
  419. f.inputEl.setStyle({color: '#B6E2FF'});
  420. f.originalValue = f.value;
  421. }
  422. },
  423. change: function(f){
  424. if(f.value != null && f.value != ''){
  425. f.inputEl.setStyle({color: 'OrangeRed'});
  426. } else {
  427. f.setValue('正常');
  428. f.inputEl.setStyle({color: '#B6E2FF'});
  429. f.originalValue = f.value;
  430. }
  431. }
  432. },
  433. 'field[name=ar_date]': {
  434. change: function(f){
  435. if(f.value == null){
  436. var d = new Date();
  437. f.setValue(d);
  438. }
  439. }
  440. },
  441. 'field[name=ard_explanation]': {
  442. change: function(f) {
  443. if(f.value == '=') {
  444. f.setValue(Ext.getCmp('ar_memo').value);
  445. }
  446. }
  447. },
  448. //计算转存汇率
  449. 'field[name = ar_payment]' : {
  450. change : function(f){
  451. var payment = f.ownerCt.down('#ar_payment').getValue(); //支出金额
  452. var preamount = f.ownerCt.down('#ar_preamount').getValue(); //转存金额
  453. var rate = f.ownerCt.down('#ar_prerate');
  454. var grid = Ext.getCmp('grid');
  455. var items = grid.store.data.items, form = Ext.getCmp('form');
  456. var apamount = 0;
  457. Ext.each(items,function(item,index){
  458. if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode'])){
  459. apamount= apamount + Number(item.data['ard_debit']);
  460. }
  461. });
  462. if(!Ext.isEmpty(payment) && payment != 0){
  463. var prerate = form.BaseUtil.numberFormat((preamount+apamount)/payment,8);
  464. if(rate.value !=prerate ){
  465. rate.setValue(prerate);
  466. }
  467. }
  468. }
  469. },
  470. 'field[name = ar_preamount]' : {
  471. change : function(f){
  472. var payment = f.ownerCt.down('#ar_payment').value; //支出金额
  473. var preamount = f.ownerCt.down('#ar_preamount').value; //转存金额
  474. var rate = f.ownerCt.down('#ar_prerate');
  475. var grid = Ext.getCmp('grid');
  476. var items = grid.store.data.items, form = Ext.getCmp('form');
  477. var apamount = 0;
  478. Ext.each(items,function(item,index){
  479. if((item.data['ard_explanation']!=null&&item.data['ard_explanation']!="")|| (item.data['ard_catecode']!=null&&item.data['ard_catecode']!="")){
  480. apamount= apamount + Number(item.data['ard_debit']);
  481. }
  482. });
  483. if(!Ext.isEmpty(payment) && payment != 0){
  484. var prerate = form.BaseUtil.numberFormat((preamount+apamount)/payment,12);
  485. if(rate.value !=prerate ){
  486. rate.setValue(prerate);
  487. }
  488. }
  489. }
  490. },
  491. 'checkbox[name=ar_currencytype]' : {
  492. beforerender : function(f) {
  493. f.readOnly = false;
  494. }
  495. },
  496. 'erpDeleteDetailButton': {
  497. afterrender: function(btn){
  498. //将当前行的 借方/贷方 以及外币借方/外币贷方 互换
  499. btn.ownerCt.add({
  500. text: '借贷调换',
  501. width: 85,
  502. disabled: true,
  503. cls: 'x-btn-gray',
  504. id: 'replace'
  505. });
  506. //当前行的借方 = 其它行的贷方总额-其它行的借方总额
  507. btn.ownerCt.add({
  508. text: '找平',
  509. width: 65,
  510. disabled: true,
  511. cls: 'x-btn-gray',
  512. id: 'level'
  513. });
  514. //复制一个相同的纪录,id不同, 但借方/贷方 互换
  515. btn.ownerCt.add({
  516. text: '冲红',
  517. width: 65,
  518. disabled: true,
  519. cls: 'x-btn-gray',
  520. id: 'bonus'
  521. });
  522. //辅助核算
  523. btn.ownerCt.add({
  524. text: '辅助核算',
  525. width: 85,
  526. disabled: true,
  527. cls: 'x-btn-gray',
  528. id: 'assdetail'
  529. });
  530. },
  531. afterdelete: function(d, r, btn){
  532. //更新状态
  533. Ext.Ajax.request({
  534. url: basePath + 'fa/gs/validAccountRegister.action',
  535. params: {
  536. id: d.ard_arid
  537. },
  538. callback: function(opt, s, r){
  539. var res = Ext.decode(r.responseText);
  540. if(res.success) {
  541. var f = Ext.getCmp('ar_errstring');
  542. f.setValue(res.errstring);
  543. f.dirty = false;
  544. f.originalValue = f.value;
  545. }
  546. }
  547. });
  548. }
  549. },
  550. 'erpGridPanel2': {
  551. afterrender: function(g) {
  552. g.plugins[0].on('beforeedit', function(args) {
  553. if(args.field == "ard_nowbalance") {
  554. if(Ext.getCmp('ar_type').value == '预付款'){
  555. return true;
  556. } else if (Ext.getCmp('ar_type').value == '转存' || Ext.getCmp('ar_type').value == '其它收款' || Ext.getCmp('ar_type').value == '其它付款'){
  557. return false;
  558. }
  559. }
  560. if (args.field == "ard_debit") {
  561. var bool = true;
  562. if (args.record.get('ard_credit') != null && args.record.get('ard_credit') > 0){
  563. bool = false;
  564. }
  565. if (args.record.get('ard_doublecredit') != null && args.record.get('ard_doublecredit') > 0){
  566. bool = false;
  567. }
  568. return bool;
  569. }
  570. if (args.field == "ard_credit") {
  571. var bool = true;
  572. if (args.record.get('ard_debit') != null && args.record.get('ard_debit') > 0){
  573. bool = false;
  574. }
  575. if (args.record.get('ard_doubledebit') != null && args.record.get('ard_doubledebit') > 0){
  576. bool = false;
  577. }
  578. return bool;
  579. }
  580. if (args.field == "ard_doubledebit") {
  581. var bool = true;
  582. if (args.record.get('ard_doublecredit') != null && args.record.get('ard_doublecredit') > 0){
  583. bool = false;
  584. }
  585. if (args.record.get('ard_credit') != null && args.record.get('ard_credit') > 0){
  586. bool = false;
  587. }
  588. return bool;
  589. }
  590. if (args.field == "ard_doublecredit") {
  591. var bool = true;
  592. if (args.record.get('ard_doubledebit') != null && args.record.get('ard_doubledebit') > 0){
  593. bool = false;
  594. }
  595. if (args.record.get('ard_debit') != null && args.record.get('ard_debit') > 0){
  596. bool = false;
  597. }
  598. return bool;
  599. }
  600. });
  601. },
  602. reconfigure: function(grid){
  603. var f = Ext.getCmp('ar_currencytype');
  604. if(f) {
  605. me.changeCurrencyType(f);
  606. }
  607. Ext.defer(function(){
  608. var form = grid.ownerCt.down('form'), status = form.down('#' + form.statuscodeField);
  609. source = Ext.getCmp('ar_source'), type = Ext.getCmp('ar_type');
  610. if(status && (status.value == 'ENTERING' || status.value == 'COMMITED')) {
  611. if(type && (type.value == '预付款' || type.value == '应付款')){
  612. if(source && source.value){
  613. grid.readOnly = false;
  614. } else {
  615. grid.readOnly = true;
  616. }
  617. } else {
  618. grid.readOnly = false;
  619. }
  620. }
  621. }, 500);
  622. },
  623. itemclick: function(selModel, record){
  624. this.GridUtil.onGridItemClick(selModel, record);
  625. var btn = Ext.getCmp('replace');
  626. btn.setDisabled(false);
  627. btn = Ext.getCmp('level');
  628. btn.setDisabled(false);
  629. btn = Ext.getCmp('bonus');
  630. btn.setDisabled(false);
  631. btn = Ext.getCmp('assdetail');
  632. var ass = record.data['ca_asstype'];
  633. if(!Ext.isEmpty(ass)){//辅助核算
  634. btn.setDisabled(false);
  635. } else {
  636. btn.setDisabled(true);
  637. }
  638. }
  639. },
  640. 'combo[name=ar_type]': {
  641. /*beforerender: function(field){
  642. if(Ext.getCmp('ar_code')&&Ext.getCmp('ar_code').value){
  643. field.readOnly=true;
  644. }
  645. },*/
  646. delay: 200,
  647. change: function(m){
  648. this.hidecolumns(m);
  649. var source = Ext.getCmp('ar_source'), grid = Ext.getCmp('grid');
  650. if(m.value == '应付款' || m.value == '预付款'){
  651. if(source && source.value){
  652. grid.readOnly = false;
  653. } else {
  654. grid.readOnly = true;
  655. }
  656. } else if(m.value == '应收款' || m.value == '预收款'|| m.value == '应付退款'|| m.value == '预付退款'||m.value == '应收退款'||m.value == '预收退款'){
  657. grid.readOnly = true;
  658. } else {
  659. grid.readOnly = false;
  660. }
  661. if(m.value == '应付票据付款' || m.value == '应收票据收款'){
  662. showError('应付票据付款/应收票据收款不能手工新增!');
  663. }
  664. }
  665. },
  666. 'field[name=ar_currencytype]': {
  667. change: function(c){
  668. me.changeCurrencyType(c);
  669. }
  670. },
  671. /**
  672. * 借调互换
  673. */
  674. 'button[id=replace]': {
  675. click: function(btn){
  676. var grid = btn.ownerCt.ownerCt;
  677. var record = grid.selModel.lastSelected;
  678. if(record){
  679. var v1 = record.data['ard_debit'];//借方
  680. var v2 = record.data['ard_credit'];//贷方
  681. var v3 = record.data['ard_doubledebit'];//原币借方
  682. var v4 = record.data['ard_doublecredit'];//原币贷方
  683. record.set('ard_debit', v2);
  684. record.set('ard_credit', v1);
  685. record.set('ard_doubledebit', v4);
  686. record.set('ard_doublecredit', v3);
  687. }
  688. }
  689. },
  690. /**
  691. * 找平
  692. */
  693. 'button[id=level]': {
  694. click: function(btn){
  695. var grid = btn.ownerCt.ownerCt;
  696. var record = grid.selModel.lastSelected;
  697. if(record){
  698. var items = grid.store.data.items;
  699. var f = Ext.getCmp('ar_currencytype'),
  700. debitF = 'ard_debit',creditF = 'ard_credit';
  701. if(f.checked) {
  702. debitF = 'ard_doubledebit';
  703. creditF = 'ard_doublecredit';
  704. }
  705. var debit = 0;
  706. var credit = 0;
  707. Ext.each(items, function(item, index){
  708. if(item.id != record.id){
  709. debit += item.data[debitF];
  710. credit += item.data[creditF];
  711. }
  712. });
  713. if(credit > debit) {
  714. record.set(debitF, credit - debit);
  715. } else {
  716. record.set(creditF, debit - credit);
  717. }
  718. }
  719. }
  720. },
  721. /**
  722. * 冲红
  723. */
  724. 'button[id=bonus]': {
  725. click: function(btn){
  726. var grid = btn.ownerCt.ownerCt;
  727. var record = grid.selModel.lastSelected;
  728. if(record){
  729. var keys = Ext.Object.getKeys(record.data);
  730. var values = Ext.Object.getValues(record.data);
  731. var o = new Object();
  732. var ard_debit = 0;
  733. var ard_credit = 0;
  734. Ext.each(keys, function(key, index){
  735. if(key != grid.detno && key != grid.keyField){//排序字段和主键字段的值均不复制
  736. var v = values[index];
  737. if(key == 'ard_debit'){
  738. ard_debit = v;
  739. }
  740. if(key == 'ard_credit'){
  741. ard_credit = v;
  742. }
  743. o[key] = v;
  744. }
  745. });
  746. o.ard_debit = ard_credit;//借方/贷方互换
  747. o.ard_credit = ard_debit;
  748. grid.copyData = o;//需要粘贴时,直接取grid.copyData即可
  749. }
  750. }
  751. },
  752. /**
  753. * 辅助核算
  754. */
  755. 'button[id=assdetail]': {
  756. click: function(btn){
  757. var grid = btn.ownerCt.ownerCt;
  758. var record = grid.selModel.lastSelected;
  759. if(record){
  760. var id = record.data[grid.keyField] || (-record.index), win = Ext.getCmp('dass-win');
  761. if(win){
  762. win.show();
  763. Ext.getCmp('win-form').removeAll(true);
  764. Ext.getCmp('win-form').add(me.createForm(grid));
  765. Ext.getCmp('assgrid').cacheAss[id] = record.data['ca_asstype'].toString();
  766. Ext.getCmp('assgrid').asstype = record.data['ca_asstype'].toString().split('#');
  767. Ext.getCmp('assgrid').getMyData(id);
  768. } else {
  769. win = Ext.create('Ext.window.Window', {
  770. id: 'dass-win',
  771. height: "100%",
  772. width: "80%",
  773. iconCls: 'x-button-icon-set',
  774. closeAction: 'hide',
  775. title: '银行登记明细辅助核算',
  776. maximizable : true,
  777. layout : 'anchor',
  778. items: [{
  779. anchor: '100% 30%',
  780. xtype: 'form',
  781. id: 'win-form',
  782. layout : 'column',
  783. autoScroll: true,
  784. labelSeparator : ':',
  785. bodyStyle: 'background:#f1f1f1;',
  786. fieldDefaults : {
  787. labelAlign : "left"
  788. },
  789. items: me.createForm(grid),
  790. buttonAlign: 'center',
  791. buttons: [{
  792. name: 'confirm',
  793. cls: 'x-btn-gray',
  794. text: $I18N.common.button.erpConfirmButton
  795. },{
  796. cls: 'x-btn-gray',
  797. text: $I18N.common.button.erpOffButton,
  798. handler: function(btn){
  799. btn.ownerCt.ownerCt.ownerCt.close();
  800. }
  801. },{
  802. cls: 'x-btn-gray',
  803. text: "上一条",
  804. handler: function(btn){
  805. me.prev(grid);
  806. }
  807. },{
  808. cls: 'x-btn-gray',
  809. text: "下一条",
  810. handler: function(btn){
  811. me.next(grid);
  812. }
  813. }]
  814. },{
  815. anchor: '100% 70%',
  816. xtype: 'detailassgrid',
  817. asstype: record.data['ca_asstype'].toString().split('#')
  818. }]
  819. }).show();
  820. Ext.getCmp('assgrid').getMyData(id, caller);
  821. }
  822. }
  823. }
  824. },
  825. 'button[name=confirm]': {
  826. click: function(btn){
  827. var record = Ext.getCmp('grid').selModel.lastSelected;
  828. var data = new Array();
  829. Ext.each(Ext.getCmp('assgrid').store.data.items, function(){
  830. data.push(this.data);
  831. });
  832. if(data.length > 0){
  833. Ext.getCmp('assgrid').cacheStore[record.data[Ext.getCmp('grid').keyField] || (-record.index)] = data;
  834. }
  835. btn.ownerCt.ownerCt.ownerCt.close();
  836. }
  837. },
  838. 'field[name=ard_doubledebit]': {//原币借方
  839. change: function(f){
  840. if(!f.ownerCt && f.value != null && f.value != 0 ){
  841. var grid = Ext.getCmp('grid');
  842. var record = grid.selModel.lastSelected,
  843. rate = record.data['ard_rate'];
  844. if(rate != null && rate > 0){
  845. var val = grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(f.value, rate), 2);
  846. if(record.data['ard_debit'] != val) {
  847. record.set('ard_debit', val);//本币
  848. }
  849. }
  850. }
  851. }
  852. },
  853. 'field[name=ard_doublecredit]': {//原币贷方
  854. change: function(f){
  855. if(!f.ownerCt && f.value != null && f.value != 0 ){
  856. var grid = Ext.getCmp('grid'), record = grid.selModel.lastSelected,
  857. rate = record.data['ard_rate'];
  858. if(rate != null && rate > 0){
  859. var val = grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(f.value, rate), 2);
  860. if(record.data['ard_credit'] != val) {
  861. record.set('ard_credit', val);//本币
  862. }
  863. }
  864. }
  865. }
  866. },
  867. 'field[name=ard_currency]': {
  868. aftertrigger: function(f){
  869. if(f.value != null && f.value != '' ){
  870. var grid = Ext.getCmp('grid');
  871. var record = grid.selModel.lastSelected;
  872. if(record.data['ard_rate'] != null && record.data['ard_rate'] > 0){
  873. if(record.data['ard_doubledebit'] != null){
  874. record.set('ard_debit',
  875. grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(record.data['ard_doubledebit'], record.data['ard_rate']), 2));//原币计算本币
  876. }
  877. if(record.data['ard_doublecredit'] != null){
  878. record.set('ard_credit',
  879. grid.BaseUtil.numberFormat(grid.BaseUtil.multiply(record.data['ard_doublecredit'], record.data['ard_rate']), 2));//原币计算本币
  880. }
  881. }
  882. }
  883. }
  884. },
  885. 'dbfindtrigger[name=ard_catecode]': {
  886. aftertrigger: function(f, item){
  887. var record = Ext.getCmp('grid').selModel.lastSelected;
  888. var ass = record.data['ca_asstype'];
  889. var btn = Ext.getCmp('assdetail');
  890. if(!Ext.isEmpty(ass)){
  891. btn.setDisabled(false);
  892. } else {
  893. btn.setDisabled(true);
  894. }
  895. var idx = record.data[grid.keyField] || (-record.index);
  896. if(Ext.getCmp('assgrid') && Ext.getCmp('assgrid').cacheAss[idx] != ass){//科目改变,对应的辅助核算也置空
  897. Ext.getCmp('assgrid').cacheAss[idx] = ass;
  898. Ext.getCmp('assgrid').cacheStore[idx] = null;
  899. }
  900. }
  901. },
  902. 'field[name=ar_deposit]' : {
  903. afterrender : function(f) {
  904. f.setFieldStyle({
  905. 'color' : 'blue'
  906. });
  907. },
  908. change: me.changecmrate
  909. },
  910. 'field[name=ar_payment]' : {
  911. afterrender : function(f) {
  912. f.setFieldStyle({
  913. 'color' : 'red'
  914. });
  915. },
  916. change: me.changecmrate
  917. },
  918. 'field[name=ar_aramount]':{
  919. afterrender : function(f) {
  920. var sourcetype = Ext.getCmp('ar_sourcetype');
  921. if(sourcetype && sourcetype.value == '付款申请'){
  922. f.setReadOnly(true);
  923. }
  924. },
  925. change: me.changecmrate
  926. },
  927. 'field[name=ca_asstype]':{
  928. change: function(f){
  929. var btn = Ext.getCmp('assmainbutton');
  930. btn && btn.setDisabled(Ext.isEmpty(f.value));
  931. }
  932. },
  933. 'erpAssMainButton':{
  934. afterrender:function(btn){
  935. if(Ext.isEmpty(Ext.getCmp('ca_asstype').getValue())){
  936. btn.setDisabled(true);
  937. } else {
  938. btn.setDisabled(false);
  939. }
  940. }
  941. },
  942. 'erpGetRefNumButton':{
  943. afterrender:function(btn){
  944. var status=Ext.getCmp('ar_statuscode');
  945. if(status && status.value !='ENTERING'){
  946. btn.hide();
  947. }
  948. },
  949. click:function(btn){
  950. var payment=Ext.getCmp('ar_payment').value,posit=Ext.getCmp('ar_deposit').value,leadcode=null,refno=Ext.getCmp('ar_refno').value;
  951. if(refno!=null && refno!='' && Ext.String.trim(refno).length!=2) {
  952. showError('当前参考号已经存在不能重复获取!');
  953. return;
  954. }
  955. if(refno !=null && Ext.String.trim(refno).length==2) leadcode=Ext.String.trim(refno);
  956. else if(payment>0) leadcode='BP';
  957. else if(posit>0) leadcode='BR';
  958. else leadcode='TR';
  959. Ext.Ajax.request({
  960. url : basePath + 'fa/gs/getRefCode.action',
  961. params:{
  962. leadcode:leadcode,
  963. datemonth:Ext.Date.format(Ext.getCmp('ar_date').getValue(),'Ym')
  964. },
  965. async:false,
  966. method : 'get',
  967. callback : function(options,success,response){
  968. var result=Ext.decode(response.responseText);
  969. if(result.success){
  970. Ext.getCmp('ar_refno').setValue(result.code);
  971. }else{
  972. if(result.exceptionInfo != null){
  973. showError(res.exceptionInfo);return;
  974. }
  975. }
  976. }
  977. });
  978. }
  979. }
  980. });
  981. },
  982. getForm: function(btn){
  983. return btn.ownerCt.ownerCt;
  984. },
  985. //冲账汇率计算 = 冲账金额/预收金额
  986. changecmrate: function(){
  987. var form = Ext.getCmp('form');
  988. if(Ext.getCmp('ar_payment') && Ext.getCmp('ar_araprate') && Ext.getCmp('ar_deposit')) {
  989. var rbamount = Ext.Number.from(Ext.getCmp('ar_payment').getValue(), 0) + Ext.Number.from(Ext.getCmp('ar_deposit').getValue(), 0);
  990. var cmamount = Ext.Number.from(Ext.getCmp('ar_aramount').getValue(), 0);
  991. if(rbamount != 0){
  992. if(cmamount !=0){
  993. Ext.getCmp('ar_araprate').setValue(form.BaseUtil.numberFormat(cmamount/rbamount, 8));
  994. }
  995. }
  996. }
  997. },
  998. changeCurrencyType: function(c){
  999. var grid = Ext.getCmp('grid');
  1000. if(c.checked){
  1001. Ext.each(grid.columns, function(cn){
  1002. if(cn.dataIndex == 'ard_doubledebit' || cn.dataIndex == 'ard_doublecredit'){
  1003. cn.width = 110;
  1004. cn.setVisible(true);
  1005. }
  1006. if(cn.dataIndex == 'ard_currency' || cn.dataIndex == 'ard_rate'){
  1007. cn.width = 60;
  1008. cn.setVisible(true);
  1009. }
  1010. if(cn.dataIndex == 'ard_debit'){
  1011. cn.setText('本币借方');
  1012. }
  1013. if(cn.dataIndex == 'ard_credit'){
  1014. cn.setText('本币贷方');
  1015. }
  1016. });
  1017. } else {
  1018. Ext.each(grid.columns, function(cn){
  1019. if(cn.dataIndex == 'ard_currency' || cn.dataIndex == 'ard_rate'
  1020. || cn.dataIndex == 'ard_doubledebit' || cn.dataIndex == 'ard_doublecredit'){
  1021. cn.setVisible(false);
  1022. }
  1023. if(cn.dataIndex == 'ard_debit'){
  1024. cn.setText('借方');
  1025. }
  1026. if(cn.dataIndex == 'ard_credit'){
  1027. cn.setText('贷方');
  1028. }
  1029. });
  1030. }
  1031. },
  1032. beforeSave: function(){
  1033. var me = this;
  1034. var form = Ext.getCmp('form');
  1035. if(! me.FormUtil.checkForm()){
  1036. return;
  1037. }
  1038. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  1039. me.FormUtil.getSeqId(form);
  1040. }
  1041. var ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
  1042. ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
  1043. deposit = Ext.getCmp('ar_deposit').value, //收入
  1044. payment = Ext.getCmp('ar_payment').value, //支出
  1045. type = Ext.getCmp('ar_type').value,
  1046. sellercode = Ext.getCmp('ar_sellercode').value;
  1047. var grid = Ext.getCmp('grid'), items = grid.store.data.items, bool = true,
  1048. ar_accountrate = Ext.getCmp('ar_accountrate').value, //账户汇率
  1049. ar_aramount = Ext.getCmp('ar_aramount').value, //冲账金额
  1050. ar_preamount = Ext.getCmp('ar_preamount').value, //转存金额
  1051. ar_prerate = Ext.getCmp('ar_prerate').value, //转存汇率
  1052. ctype = Ext.getCmp('ar_currencytype');
  1053. var debit = 0, credit = 0;
  1054. Ext.each(items,function(item,index){
  1055. if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
  1056. debit= debit + Number(item.data['ard_debit']);
  1057. credit= credit + Number(item.data['ard_credit']);
  1058. }
  1059. });
  1060. if(type != null && type != '' ){
  1061. if(type == '应付款' || type == '预付款' || type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款' || type == '应收退款' || type == '预收退款'){
  1062. if(ar_arapcurrency == null || ar_arapcurrency==''){
  1063. Ext.getCmp('ar_arapcurrency').setValue(ar_accountcurrency);
  1064. ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value;
  1065. }
  1066. }
  1067. if(type == '应付票据付款' || type == '应收票据收款'){
  1068. showError('应付票据付款/应收票据收款不能手工新增!');
  1069. return;
  1070. }
  1071. if(type == '应收款'){
  1072. if(Ext.isEmpty(sellercode)){
  1073. showError('业务员编号不能为空!');
  1074. return;
  1075. }
  1076. }
  1077. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
  1078. if(deposit == 0 || deposit == null || deposit == '' ){
  1079. showError('收入金额不能为空!');
  1080. return;
  1081. }
  1082. }
  1083. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款') {
  1084. if(ar_accountcurrency != ar_arapcurrency){
  1085. if(Ext.getCmp('ar_araprate').value == '1'){
  1086. showError('币别不一致,冲账汇率为1,请修改!');
  1087. return;
  1088. }
  1089. }
  1090. if(ar_accountcurrency == ar_arapcurrency){
  1091. Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(deposit), Number(Ext.getCmp('ar_araprate').value)));
  1092. }
  1093. }
  1094. if (type == '预付款' || type == '应付款' || type == '应收退款' || type == '预收退款'){
  1095. if(payment == 0 || payment == null || payment == '' ){
  1096. showError('支出金额不能为空!');
  1097. return;
  1098. }
  1099. }
  1100. if(type == '预付款' || type == '应付款' || type == '应收退款' || type == '预收退款'){
  1101. if(ar_accountcurrency != ar_arapcurrency){
  1102. if(Ext.getCmp('ar_araprate').value == '1'){
  1103. showError('币别不一致,冲账汇率为1,请修改!');
  1104. return;
  1105. }
  1106. }
  1107. if(ar_accountcurrency == ar_arapcurrency){
  1108. Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(payment), Number(Ext.getCmp('ar_araprate').value)));
  1109. }
  1110. }
  1111. if(type == '应收票据收款' || type == '应付票据付款'){
  1112. if(type == '应收票据收款') {
  1113. if(deposit == 0 || deposit == null || deposit == '' ){
  1114. showError('收入金额不能为空!');
  1115. return;
  1116. }
  1117. if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)) > 0.01){
  1118. showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
  1119. return;
  1120. }
  1121. } else if(type == '应付票据付款'){
  1122. if(payment == 0 || payment == null || payment == '' ){
  1123. showError('支出金额不能为空!');
  1124. return;
  1125. }
  1126. }
  1127. }
  1128. if(type == '转存'){
  1129. if(!Ext.isEmpty(debit)){
  1130. var prerate = form.BaseUtil.numberFormat((ar_preamount+(debit-credit))/(payment-deposit),8);
  1131. if(ar_prerate != prerate ){
  1132. Ext.getCmp('ar_prerate').setValue(prerate);
  1133. }
  1134. }
  1135. }
  1136. if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
  1137. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
  1138. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2)) > 0.01){
  1139. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
  1140. return;
  1141. }
  1142. }
  1143. if(type == '应付款' || type == '应收退款' || type == '预收退款'){
  1144. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2)) > 0.01){
  1145. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  1146. return;
  1147. }
  1148. }
  1149. if(type == '预付款'){
  1150. if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
  1151. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2)) > 0.01){
  1152. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  1153. return;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. }
  1159. var detail = Ext.getCmp('grid'), items = detail.store.data.items, bool = true;
  1160. var ass = Ext.getCmp('assgrid');
  1161. var param3 = ass == null ? '[]' : Ext.encode(ass.getEffectData());
  1162. Ext.each(items, function(item){
  1163. if(item.data.ard_id == null || item.data.ard_id == 0){
  1164. item.data.ard_id = -item.index;
  1165. }
  1166. });
  1167. Ext.Array.each(items, function(item){
  1168. if(!Ext.isEmpty(item.data['ard_catecode'])){
  1169. if(item.data['ca_currencytype'] != 0){
  1170. if(ctype && ctype.value != '1'){
  1171. ctype.setValue('1');
  1172. }
  1173. if(Ext.isEmpty(item.data['ard_currency'])){
  1174. bool = false;
  1175. showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
  1176. return;
  1177. }
  1178. if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
  1179. bool = false;
  1180. showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
  1181. return;
  1182. }
  1183. }
  1184. if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
  1185. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
  1186. bool = false;
  1187. showError('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
  1188. return;
  1189. }
  1190. }
  1191. if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
  1192. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
  1193. bool = false;
  1194. showError('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
  1195. return;
  1196. }
  1197. }
  1198. }
  1199. });
  1200. var param1 = me.GridUtil.getGridStore(detail);
  1201. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  1202. showError($I18N.common.grid.emptyDetail);
  1203. return;
  1204. }
  1205. var ex = new Array(),d;
  1206. Ext.each(param1, function(){//摘要未填写
  1207. d = Ext.decode(this);
  1208. if(Ext.isEmpty(d.ard_explanation)) {
  1209. ex.push(d.ard_detno);
  1210. }
  1211. });
  1212. if(ex.length > 0) {
  1213. warnMsg("摘要未填写,序号:" + ex.join(',') + " 是否继续保存?", function(btn){
  1214. if(btn == 'yes') {
  1215. me.onSave(form, param1, param3);;
  1216. }
  1217. });
  1218. } else {
  1219. if(bool)
  1220. me.onSave(form, param1, param3);
  1221. }
  1222. },
  1223. onSave: function(form, param1, param3) {
  1224. var me = this;
  1225. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  1226. param3 = param3 == null ? [] : param3.toString().replace(/\\/g,"%");
  1227. if(form.getForm().isValid()){
  1228. Ext.each(form.items.items, function(item){
  1229. if(item.xtype == 'numberfield'){
  1230. if(item.value == null || item.value == ''){
  1231. item.setValue(0);
  1232. }
  1233. }
  1234. });
  1235. var r = form.getValues();
  1236. form.getForm().getFields().each(function(){
  1237. if(this.logic == 'ignore') {
  1238. delete r[this.name];
  1239. }
  1240. });
  1241. var ctype = Ext.getCmp('ar_currencytype');
  1242. r.ar_currencytype = (typeof ctype.value == 'boolean' && ctype.value) ? -1 : 0;
  1243. r.ar_errstring = r.ar_errstring == '正常' ? '' : r.ar_errstring;
  1244. me.FormUtil.save(r, param1, param3);
  1245. }else{
  1246. me.FormUtil.checkForm();
  1247. }
  1248. },
  1249. beforeUpdate: function(){
  1250. var me = this;
  1251. var form = Ext.getCmp('form');
  1252. if(! me.FormUtil.checkForm()){
  1253. return;
  1254. }
  1255. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  1256. me.FormUtil.getSeqId(form);
  1257. }
  1258. var ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
  1259. ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
  1260. deposit = Ext.getCmp('ar_deposit').value, //收入
  1261. payment = Ext.getCmp('ar_payment').value, //支出
  1262. type = Ext.getCmp('ar_type').value,
  1263. sellercode = Ext.getCmp('ar_sellercode').value,
  1264. ctype = Ext.getCmp('ar_currencytype');
  1265. var grid = Ext.getCmp('grid'), items = grid.store.data.items, bool = true;
  1266. ar_accountrate = Ext.getCmp('ar_accountrate').value; //账户汇率
  1267. ar_aramount = Ext.getCmp('ar_aramount').value; //冲账金额
  1268. var debit = 0, credit = 0;
  1269. Ext.each(items,function(item,index){
  1270. if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
  1271. debit= debit + Number(item.data['ard_debit']);
  1272. credit= credit + Number(item.data['ard_credit']);
  1273. }
  1274. });
  1275. if(type != null && type != '' ){
  1276. if(type == '应付款' || type == '预付款' || type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款' || type == '应收退款' || type == '预收退款'){
  1277. if(ar_arapcurrency == null || ar_arapcurrency==''){
  1278. Ext.getCmp('ar_arapcurrency').setValue(ar_accountcurrency);
  1279. ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value;
  1280. }
  1281. }
  1282. if(type == '应收款'){
  1283. if(Ext.isEmpty(sellercode)){
  1284. showError('业务员编号不能为空!');
  1285. return;
  1286. }
  1287. }
  1288. if(type == '应收款' || type == '预收款' || type == '应付退款'){
  1289. if(deposit == 0 || deposit == null || deposit == '' ){
  1290. showError('收入金额不能为空!');
  1291. return;
  1292. }
  1293. }
  1294. if(type == '应收款' || type == '预收款' || type == '应付退款'){
  1295. if(ar_accountcurrency != ar_arapcurrency){
  1296. if(Ext.getCmp('ar_araprate').value == '1'){
  1297. showError('币别不一致,冲账汇率为1,请修改!');
  1298. return;
  1299. }
  1300. }
  1301. if(ar_accountcurrency == ar_arapcurrency){
  1302. Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(deposit),Number(Ext.getCmp('ar_araprate').value)));
  1303. }
  1304. }
  1305. if (type == '预付款' || type == '应付款' || type == '应收退款'){
  1306. if(payment == 0 || payment == null || payment == '' ){
  1307. showError('支出金额不能为空!');
  1308. return;
  1309. }
  1310. }
  1311. if(type == '预付款' || type == '应付款' || type == '应收退款'){
  1312. if(ar_accountcurrency != ar_arapcurrency){
  1313. if(Ext.getCmp('ar_araprate').value == '1'){
  1314. showError('币别不一致,冲账汇率为1,请修改!');
  1315. return;
  1316. }
  1317. }
  1318. if(ar_accountcurrency == ar_arapcurrency){
  1319. Ext.getCmp('ar_aramount').setValue(form.BaseUtil.multiply(Number(payment), Number(Ext.getCmp('ar_araprate').value)));
  1320. }
  1321. }
  1322. if(type == '应收票据收款' || type == '应付票据付款'){
  1323. if(type == '应收票据收款') {
  1324. if(deposit == 0 || deposit == null || deposit == '' ){
  1325. showError('收入金额不能为空!');
  1326. return;
  1327. }
  1328. if(form.BaseUtil.numberFormat(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)),2) > 0.01){
  1329. showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
  1330. return;
  1331. }
  1332. } else if(type == '应付票据付款'){
  1333. if(payment == 0 || payment == null || payment == '' ){
  1334. showError('支出金额不能为空!');
  1335. return;
  1336. }
  1337. }
  1338. }
  1339. if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
  1340. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
  1341. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2))>0.011){
  1342. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
  1343. return;
  1344. }
  1345. }
  1346. if(type == '应付款' || type == '应收退款' || type == '预收退款'){
  1347. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  1348. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  1349. return;
  1350. }
  1351. }
  1352. if(type == '预付款'){
  1353. if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
  1354. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  1355. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  1356. return;
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. var detail = Ext.getCmp('grid'), ass = Ext.getCmp('assgrid'), bool = true,
  1363. items = detail.store.data.items;
  1364. Ext.each(items, function(item){
  1365. if(item.data.ard_id == null || item.data.ard_id == 0){
  1366. item.data.ard_id = -item.index;
  1367. }
  1368. });
  1369. Ext.Array.each(items, function(item){
  1370. if(!Ext.isEmpty(item.data['ard_catecode'])){
  1371. if(item.data['ca_currencytype'] != 0){
  1372. if(ctype && ctype.value != '1'){
  1373. ctype.setValue('1');
  1374. }
  1375. if(Ext.isEmpty(item.data['ard_currency'])){
  1376. bool = false;
  1377. showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
  1378. return;
  1379. }
  1380. if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
  1381. bool = false;
  1382. showError('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
  1383. return;
  1384. }
  1385. }
  1386. if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
  1387. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
  1388. bool = false;
  1389. showError('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
  1390. return;
  1391. }
  1392. }
  1393. if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
  1394. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
  1395. bool = false;
  1396. showError('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
  1397. return;
  1398. }
  1399. }
  1400. }
  1401. });
  1402. var param1 = me.GridUtil.getGridStore(detail);
  1403. var param2 = ass == null ? '[]' : Ext.encode(ass.getEffectData());
  1404. var param3 = new Array();
  1405. if(Ext.getCmp('assmainbutton')){
  1406. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  1407. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  1408. d['ass_conid'] = key;
  1409. param3.push(d);
  1410. });
  1411. });
  1412. }
  1413. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0) &&
  1414. (param3.length <= 2)){
  1415. showError($I18N.common.grid.emptyDetail);
  1416. return;
  1417. } else {
  1418. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  1419. param2 = param2 == null ? [] : param2.toString().replace(/\\/g,"%");
  1420. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  1421. if(form.getForm().isValid()){
  1422. Ext.each(form.items.items, function(item){
  1423. if(item.xtype == 'numberfield'){
  1424. if(item.value == null || item.value == ''){
  1425. item.setValue(0);
  1426. }
  1427. }
  1428. });
  1429. var r = form.getValues();
  1430. form.getForm().getFields().each(function(){
  1431. if(this.logic == 'ignore') {
  1432. delete r[this.name];
  1433. }
  1434. });
  1435. var ctype = Ext.getCmp('ar_currencytype');
  1436. r.ar_currencytype = (typeof ctype.value == 'boolean' && ctype.value) ? -1 : 0;
  1437. r.ar_errstring = r.ar_errstring == '正常' ? '' : r.ar_errstring;
  1438. if(bool)
  1439. me.FormUtil.update(r, param1, param2, param3);
  1440. }else{
  1441. me.FormUtil.checkForm();
  1442. }
  1443. }
  1444. },
  1445. createForm: function(grid){
  1446. var record = grid.selModel.lastSelected;
  1447. var data = new Object();
  1448. if(record){
  1449. data = record.data;
  1450. }
  1451. var items = new Array();
  1452. var item;
  1453. Ext.each(grid.columns, function(c){
  1454. item = new Object();
  1455. item.id = c.dataIndex;
  1456. item.name = c.dataIndex;
  1457. item.fieldLabel = c.text || c.header;
  1458. item.value = data[c.dataIndex];
  1459. item.columnWidth = .33;
  1460. item.readOnly = true;
  1461. item.xtype = 'textfield';
  1462. item.fieldStyle = 'background:#f0f0f0;border: 1px solid #8B8970';
  1463. item.cls = 'form-field-border';
  1464. if(c.hidden){
  1465. item.xtype = 'hidden';
  1466. item.cls = "";
  1467. }
  1468. if(c.dataIndex == grid.detno){
  1469. item.fieldStyle = 'background:#e0f0f0;font-weight:bold;border: 1px solid #8B8970';
  1470. }
  1471. items.push(item);
  1472. });
  1473. return items;
  1474. },
  1475. /**
  1476. * 明细辅助核算的上一条
  1477. */
  1478. prev: function(grid, record){
  1479. record = record || grid.selModel.lastSelected;
  1480. if(record){
  1481. //先保存当前数据
  1482. var data = new Array();
  1483. Ext.each(Ext.getCmp('assgrid').store.data.items, function(){
  1484. data.push(this.data);
  1485. });
  1486. if(data.length > 0){
  1487. Ext.getCmp('assgrid').cacheStore[record.data[grid.keyField] || (-record.index)] = data;
  1488. }
  1489. //递归查找上一条,并取到数据
  1490. var d = grid.store.getAt(record.index - 1);
  1491. if(d){
  1492. Ext.getCmp('win-form').getForm().setValues(d.data);
  1493. var idx = d.data[grid.keyField] || (-d.index);
  1494. Ext.getCmp('assgrid').cacheAss[idx] = d.data['ca_asstype'];
  1495. Ext.getCmp('assgrid').asstype = Ext.isEmpty(d.data['ca_asstype']) ?
  1496. new Array() : d.data['ca_asstype'].toString().split('#');
  1497. Ext.getCmp('assgrid').getMyData(idx, caller);
  1498. grid.selModel.select(d);
  1499. } else {
  1500. if(record.index - 1 > 0){
  1501. this.prev(grid, d);
  1502. }
  1503. }
  1504. }
  1505. },
  1506. /**
  1507. * 明细辅助核算的下一条
  1508. */
  1509. next: function(grid, record){
  1510. record = record || grid.selModel.lastSelected;
  1511. if(record){
  1512. //先保存当前数据
  1513. var data = new Array();
  1514. Ext.each(Ext.getCmp('assgrid').store.data.items, function(){
  1515. data.push(this.data);
  1516. });
  1517. if(data.length > 0){
  1518. Ext.getCmp('assgrid').cacheStore[record.data[grid.keyField] || (-record.index)] = data;
  1519. }
  1520. //递归查找下一条,并取到数据
  1521. var d = grid.store.getAt(record.index + 1);
  1522. if(d){
  1523. Ext.getCmp('win-form').getForm().setValues(d.data);
  1524. var idx = d.data[grid.keyField] || (-d.index);
  1525. Ext.getCmp('assgrid').cacheAss[idx] = d.data['ca_asstype'];
  1526. Ext.getCmp('assgrid').asstype = Ext.isEmpty(d.data['ca_asstype']) ?
  1527. new Array() : d.data['ca_asstype'].toString().split('#');
  1528. Ext.getCmp('assgrid').getMyData(idx, caller);
  1529. grid.selModel.select(d);
  1530. } else {
  1531. if(record.index + 1 < grid.store.data.items.length){
  1532. this.next(grid, d);
  1533. }
  1534. }
  1535. }
  1536. },
  1537. turnPayBalance: function(form) {
  1538. var me = this;
  1539. form.setLoading(true);//loading...
  1540. Ext.Ajax.request({
  1541. url : basePath + 'fa/gs/arTurnPayBalance.action',
  1542. params: {
  1543. id: Ext.getCmp('ar_id').value
  1544. },
  1545. method : 'post',
  1546. callback : function(options,success,response){
  1547. form.setLoading(false);
  1548. var localJson = new Ext.decode(response.responseText);
  1549. if(localJson.exceptionInfo){
  1550. showError(localJson.exceptionInfo);
  1551. }
  1552. if(localJson.success){
  1553. turnSuccess(function(){
  1554. var id = localJson.id;
  1555. var url = "jsps/fa/arp/paybalance.jsp?formCondition=pb_id=" + id + "&whoami=PayBalance";
  1556. me.FormUtil.onAdd('PayBalance' + id, '付款单' + id, url);
  1557. });
  1558. }
  1559. }
  1560. });
  1561. },
  1562. turnRecBalance: function(form) {
  1563. var me = this;
  1564. form.setLoading(true);//loading...
  1565. Ext.Ajax.request({
  1566. url : basePath + 'fa/gs/arTurnRecBalance.action',
  1567. params: {
  1568. id: Ext.getCmp('ar_id').value
  1569. },
  1570. method : 'post',
  1571. callback : function(options,success,response){
  1572. form.setLoading(false);
  1573. var localJson = new Ext.decode(response.responseText);
  1574. if(localJson.exceptionInfo){
  1575. showError(localJson.exceptionInfo);
  1576. }
  1577. if(localJson.success){
  1578. turnSuccess(function(){
  1579. var id = localJson.id;
  1580. var url = "jsps/fa/ars/recBalance.jsp?formCondition=rb_id=" + id +"&whoami=RecBalance!PBIL";
  1581. me.FormUtil.onAdd('RecBalance' + id, '收款单' + id, url);
  1582. });
  1583. }
  1584. }
  1585. });
  1586. },
  1587. updateRemark:function(remark,id){
  1588. Ext.Ajax.request({
  1589. url : basePath + 'fa/gs/updateRemark.action',
  1590. params: {remark:remark,id:id},
  1591. method : 'post',
  1592. async:false,
  1593. callback : function(options,success,response){
  1594. var res = new Ext.decode(response.responseText);
  1595. if(res.exceptionInfo != null){
  1596. showError(res.exceptionInfo);return;
  1597. }
  1598. showMessage("提示", '更新成功!');
  1599. window.location.reload();
  1600. }
  1601. });
  1602. },
  1603. hidecolumns:function(m){
  1604. if(!Ext.isEmpty(m.getValue())) {
  1605. var form = m.ownerCt;
  1606. if(m.value == '应付款' || m.value == '预付款' || m.value == '预付退款'|| m.value == '应付退款'){
  1607. form.down('#ar_custcode').hide();
  1608. form.down('#ar_custname').hide();
  1609. form.down('#ar_sellercode').hide();
  1610. form.down('#ar_sellername').hide();
  1611. if(m.value == '应付款' || m.value == '预付款'){
  1612. form.down('#ar_deposit').hide();
  1613. form.down('#ar_payment').show();
  1614. form.down('#ar_apamount') && form.down('#ar_apamount').show();
  1615. } else if(m.value == '预付退款'|| m.value == '应付退款'){
  1616. form.down('#ar_deposit').show();
  1617. form.down('#ar_payment').hide();
  1618. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1619. }
  1620. form.down('#ar_arapcurrency').show();
  1621. form.down('#ar_araprate').show();
  1622. form.down('#ar_aramount').show();
  1623. form.down('#ar_vendcode').show();
  1624. form.down('#ar_vendname').show();
  1625. form.down('#ar_category').hide();
  1626. form.down('#ar_catedesc').hide();
  1627. form.down('#ar_precurrency').hide();
  1628. form.down('#ar_prerate').hide();
  1629. form.down('#ar_preamount').hide();
  1630. form.down('#ar_recamount') && form.down('#ar_recamount').hide();
  1631. } else if(m.value == '应收款' || m.value == '预收款' || m.value == '预收退款' || m.value == '应收退款'){
  1632. form.down('#ar_custcode').show();
  1633. form.down('#ar_custname').show();
  1634. form.down('#ar_sellercode').show();
  1635. form.down('#ar_sellername').show();
  1636. form.down('#ar_arapcurrency').show();
  1637. form.down('#ar_araprate').show();
  1638. form.down('#ar_aramount').show();
  1639. form.down('#ar_vendcode').hide();
  1640. form.down('#ar_vendname').hide();
  1641. form.down('#ar_category').hide();
  1642. form.down('#ar_catedesc').hide();
  1643. form.down('#ar_precurrency').hide();
  1644. form.down('#ar_prerate').hide();
  1645. form.down('#ar_preamount').hide();
  1646. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1647. if(m.value == '应收款' || m.value == '预收款'){
  1648. form.down('#ar_payment').hide();
  1649. form.down('#ar_deposit').show();
  1650. } else if(m.value == '预收退款' || m.value == '应收退款'){
  1651. form.down('#ar_payment').show();
  1652. form.down('#ar_deposit').hide();
  1653. }
  1654. form.down('#ar_recamount') && form.down('#ar_recamount').hide();
  1655. } else if(m.value == '应收票据收款' || m.value == '应付票据付款'){
  1656. form.down('#ar_arapcurrency').show();
  1657. form.down('#ar_araprate').show();
  1658. form.down('#ar_aramount').show();
  1659. form.down('#ar_category').hide();
  1660. form.down('#ar_catedesc').hide();
  1661. form.down('#ar_precurrency').hide();
  1662. form.down('#ar_prerate').hide();
  1663. form.down('#ar_preamount').hide();
  1664. form.down('#ar_arapcurrency').hide();
  1665. form.down('#ar_araprate').hide();
  1666. form.down('#ar_aramount').hide();
  1667. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1668. if(m.value == '应收票据收款'){
  1669. form.down('#ar_payment').hide();
  1670. form.down('#ar_deposit').show();
  1671. form.down('#ar_vendcode').hide();
  1672. form.down('#ar_vendname').hide();
  1673. form.down('#ar_custcode').show();
  1674. form.down('#ar_custname').show();
  1675. form.down('#ar_sellercode').show();
  1676. form.down('#ar_sellername').show();
  1677. } else if (m.value == '应付票据付款'){
  1678. form.down('#ar_payment').show();
  1679. form.down('#ar_deposit').hide();
  1680. form.down('#ar_vendcode').show();
  1681. form.down('#ar_vendname').show();
  1682. form.down('#ar_custcode').hide();
  1683. form.down('#ar_custname').hide();
  1684. form.down('#ar_sellercode').hide();
  1685. form.down('#ar_sellername').hide();
  1686. }
  1687. form.down('#ar_checkno') && form.down('#ar_checkno').hide();
  1688. form.down('#ar_recamount') && form.down('#ar_recamount').hide();
  1689. } else if(m.value == '转存' || m.value == '自动转存'){
  1690. form.down('#ar_custcode').hide();
  1691. form.down('#ar_custname').hide();
  1692. form.down('#ar_sellercode').hide();
  1693. form.down('#ar_sellername').hide();
  1694. form.down('#ar_arapcurrency').hide();
  1695. form.down('#ar_araprate').hide();
  1696. form.down('#ar_aramount').hide();
  1697. form.down('#ar_vendcode').hide();
  1698. form.down('#ar_vendname').hide();
  1699. form.down('#ar_category').show();
  1700. form.down('#ar_catedesc').show();
  1701. form.down('#ar_precurrency').show();
  1702. form.down('#ar_prerate').show();
  1703. form.down('#ar_preamount').show();
  1704. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1705. if(m.value == '转存'){
  1706. form.down('#ar_payment').show();
  1707. form.down('#ar_deposit').hide();
  1708. }
  1709. if(m.value == '自动转存'){
  1710. form.down('#ar_payment').hide();
  1711. form.down('#ar_deposit').show();
  1712. }
  1713. form.down('#ar_checkno') && form.down('#ar_checkno').hide();
  1714. form.down('#ar_recamount') && form.down('#ar_recamount').hide();
  1715. } else if(m.value == '暂收款'){
  1716. form.down('#ar_custcode').hide();
  1717. form.down('#ar_custname').hide();
  1718. form.down('#ar_sellercode').hide();
  1719. form.down('#ar_sellername').hide();
  1720. form.down('#ar_arapcurrency').hide();
  1721. form.down('#ar_araprate').hide();
  1722. form.down('#ar_aramount').hide();
  1723. form.down('#ar_vendcode').hide();
  1724. form.down('#ar_vendname').hide();
  1725. form.down('#ar_category').hide();
  1726. form.down('#ar_catedesc').hide();
  1727. form.down('#ar_precurrency').hide();
  1728. form.down('#ar_prerate').hide();
  1729. form.down('#ar_preamount').hide();
  1730. form.down('#ar_recamount') && form.down('#ar_recamount').show();
  1731. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1732. } else if(m.value == '其它付款' || m.value == '其它收款'){
  1733. form.down('#ar_custcode').hide();
  1734. form.down('#ar_custname').hide();
  1735. form.down('#ar_sellercode').hide();
  1736. form.down('#ar_sellername').hide();
  1737. form.down('#ar_arapcurrency').hide();
  1738. form.down('#ar_araprate').hide();
  1739. form.down('#ar_aramount').hide();
  1740. form.down('#ar_vendcode').hide();
  1741. form.down('#ar_checkno').hide();
  1742. form.down('#ar_vendname').hide();
  1743. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1744. if(m.value == '其它付款'){
  1745. form.down('#ar_deposit').hide();
  1746. form.down('#ar_payment').show();
  1747. }
  1748. if(m.value == '其它收款'){
  1749. form.down('#ar_deposit').show();
  1750. form.down('#ar_payment').hide();
  1751. }
  1752. form.down('#ar_category').hide();
  1753. form.down('#ar_catedesc').hide();
  1754. form.down('#ar_precurrency').hide();
  1755. form.down('#ar_prerate').hide();
  1756. form.down('#ar_preamount').hide();
  1757. form.down('#ar_recamount') && form.down('#ar_recamount').hide();
  1758. form.down('#ar_pleaseman') && form.down('#ar_pleaseman').show();
  1759. } else {
  1760. form.down('#ar_custcode').hide();
  1761. form.down('#ar_custname').hide();
  1762. form.down('#ar_sellercode').hide();
  1763. form.down('#ar_sellername').hide();
  1764. form.down('#ar_arapcurrency').hide();
  1765. form.down('#ar_araprate').hide();
  1766. form.down('#ar_aramount').hide();
  1767. form.down('#ar_vendcode').hide();
  1768. form.down('#ar_vendname').hide();
  1769. form.down('#ar_category').hide();
  1770. form.down('#ar_catedesc').hide();
  1771. form.down('#ar_precurrency').hide();
  1772. form.down('#ar_prerate').hide();
  1773. form.down('#ar_preamount').hide();
  1774. form.down('#ar_payment').show();
  1775. form.down('#ar_deposit').hide();
  1776. form.down('#ar_checkno') && form.down('#ar_checkno').hide();
  1777. form.down('#ar_recamount') && form.down('#ar_recamount').hide();
  1778. form.down('#ar_apamount') && form.down('#ar_apamount').hide();
  1779. }
  1780. if(m.value == '费用'||m.value == '应付款'||m.value == '预付款'){
  1781. form.down('#ar_pleaseman') && form.down('#ar_pleaseman').show();
  1782. }else{
  1783. form.down('#ar_pleaseman') && form.down('#ar_pleaseman').hide();
  1784. }
  1785. }
  1786. },
  1787. beforeAccount:function(){
  1788. var ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
  1789. ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
  1790. ar_araprate = Ext.getCmp('ar_araprate').value, //冲账汇率
  1791. ar_accountrate = Ext.getCmp('ar_accountrate').value, //账户汇率
  1792. ar_aramount = Ext.getCmp('ar_aramount').value //冲账金额
  1793. ar_category = Ext.getCmp('ar_category').value //转存科目
  1794. ar_precurrency = Ext.getCmp('ar_precurrency').value //转存币别
  1795. ar_preamount = Ext.getCmp('ar_preamount').value //转存金额
  1796. ar_prerate = Ext.getCmp('ar_prerate').value //转存汇率
  1797. f = Ext.getCmp('ar_aramount'),
  1798. form = Ext.getCmp('form');
  1799. var deposit = Ext.getCmp('ar_deposit').value,
  1800. payment = Ext.getCmp('ar_payment').value,
  1801. type = Ext.getCmp('ar_type').value;
  1802. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  1803. var debit = 0, credit = 0, me = this;
  1804. Ext.each(items,function(item,index){
  1805. if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
  1806. debit= debit + Number(item.data['ard_debit']);
  1807. credit= credit + Number(item.data['ard_credit']);
  1808. }
  1809. });
  1810. if(type == '转存'){
  1811. if(!Ext.isEmpty(debit)){
  1812. var prerate = form.BaseUtil.numberFormat((ar_preamount+(debit-credit))/(payment-deposit),12);
  1813. if(ar_prerate != prerate ){
  1814. Ext.getCmp('ar_prerate').setValue(prerate);
  1815. }
  1816. }
  1817. }
  1818. var errs = [];
  1819. Ext.Array.each(items, function(item){
  1820. if(!Ext.isEmpty(item.data['ard_catecode'])){
  1821. if(item.data['ca_currencytype'] != 0){
  1822. if(Ext.isEmpty(item.data['ard_currency'])){
  1823. errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
  1824. return;
  1825. }
  1826. if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
  1827. errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
  1828. return;
  1829. }
  1830. }
  1831. if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
  1832. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
  1833. errs.push('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
  1834. return;
  1835. }
  1836. }
  1837. if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
  1838. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
  1839. errs.push('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
  1840. return;
  1841. }
  1842. }
  1843. } else {
  1844. if(type == '其它收款' || type == '其它付款' || type == '费用'){
  1845. errs.push('明细表第' + item.data['ard_detno'] + '行,科目未填写!');
  1846. return;
  1847. }
  1848. }
  1849. });
  1850. if(errs.length > 0) {
  1851. showError(errs.join('<br>'));
  1852. return;
  1853. }
  1854. if(type != null && type != '' ){
  1855. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '应收票据收款'){
  1856. if(deposit == 0 || deposit == null || deposit == '' ){
  1857. showError('收入金额不能为空!');
  1858. return;
  1859. }
  1860. if(type == '应收款' || type == '预收款' || type == '应付退款'){
  1861. if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/deposit,8)){
  1862. showError('冲账汇率不正确!');
  1863. return;
  1864. }
  1865. }
  1866. } else if (type == '预付款' || type == '应付款' || type == '应收退款' || type == '应付票据付款'){
  1867. if(payment == 0 || payment == null || payment == '' ){
  1868. showError('支出金额不能为空!');
  1869. return;
  1870. }
  1871. if(type == '预付款' || type == '应付款' || type == '应收退款'){
  1872. if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/payment,8)){
  1873. showError('冲账汇率不正确!');
  1874. return;
  1875. }
  1876. }
  1877. } else if(type == '转存') {
  1878. if(payment == 0 || payment == null || payment == '' ){
  1879. showError('支出金额不能为空!');
  1880. return;
  1881. }
  1882. if(Ext.isEmpty(ar_category)){
  1883. showError('转存科目不能为空!');
  1884. return;
  1885. }
  1886. if(Ext.isEmpty(ar_precurrency)){
  1887. showError('转存币别不能为空!');
  1888. return;
  1889. }
  1890. if(ar_preamount == 0 || ar_preamount == null || ar_preamount == '' ){
  1891. showError('转存金额不能为空!');
  1892. return;
  1893. }
  1894. if(ar_accountcurrency != ar_precurrency){
  1895. if(ar_prerate == 1){
  1896. showError('币别不一致,转存汇率为1,不能记账!');
  1897. return;
  1898. }
  1899. }
  1900. }
  1901. if(type != '应收票据收款' && type != '应付票据付款' && type != '费用' && type != '转存' && type != '其它收款' && type != '其它付款'){
  1902. if(ar_accountcurrency != ar_arapcurrency){
  1903. if(Ext.getCmp('ar_araprate').value == '1'){
  1904. showError('币别不一致,冲账汇率为1,不能记账!');
  1905. return;
  1906. }
  1907. }
  1908. }
  1909. if(type == '应收票据收款' || type == '其它收款'){
  1910. if(form.BaseUtil.numberFormat(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)),2) > 0.01){
  1911. showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致,不能记账!');
  1912. return;
  1913. }
  1914. }
  1915. if(type == '应付票据付款' || type == '其它付款' || type == '费用'){
  1916. if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2)- form.BaseUtil.numberFormat(debit-credit, 2),2)) > 0.01){
  1917. showError('支出金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致,不能记账!');
  1918. return;
  1919. }
  1920. }
  1921. if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
  1922. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
  1923. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2)) > 0.01){
  1924. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2)+ '不一致!');
  1925. return;
  1926. }
  1927. }
  1928. if(type == '应付款' || type == '应收退款' || type == '预收退款'){
  1929. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  1930. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  1931. return;
  1932. }
  1933. }
  1934. if(type == '预付款'){
  1935. if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
  1936. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  1937. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  1938. return;
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. this.FormUtil.onAccounted(Ext.getCmp('ar_id').value);
  1945. },
  1946. beforeSubmit:function(){
  1947. var ar_accountcurrency = Ext.getCmp('ar_accountcurrency').value,
  1948. ar_arapcurrency = Ext.getCmp('ar_arapcurrency').value,
  1949. ar_araprate = Ext.getCmp('ar_araprate').value, //冲账汇率
  1950. ar_accountrate = Ext.getCmp('ar_accountrate').value, //账户汇率
  1951. ar_aramount = Ext.getCmp('ar_aramount').value //冲账金额
  1952. ar_category = Ext.getCmp('ar_category').value //转存科目
  1953. ar_precurrency = Ext.getCmp('ar_precurrency').value //转存币别
  1954. ar_preamount = Ext.getCmp('ar_preamount').value //转存金额
  1955. ar_prerate = Ext.getCmp('ar_prerate').value //转存汇率
  1956. f = Ext.getCmp('ar_aramount'),
  1957. form = Ext.getCmp('form');
  1958. var deposit = Ext.getCmp('ar_deposit').value,
  1959. payment = Ext.getCmp('ar_payment').value,
  1960. type = Ext.getCmp('ar_type').value;
  1961. var grid = Ext.getCmp('grid'), items = grid.store.data.items;
  1962. var debit = 0, credit = 0, me = this;
  1963. if(type != null && type != '' ){
  1964. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '应收票据收款'){
  1965. if(deposit == 0 || deposit == null || deposit == '' ){
  1966. showError('收入金额不能为空!');
  1967. return;
  1968. }
  1969. if(type == '应收款' || type == '预收款' || type == '应付退款'){
  1970. if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/deposit,8)){
  1971. showError('冲账汇率不正确!');
  1972. return;
  1973. }
  1974. }
  1975. } else if (type == '预付款' || type == '应付款' || type == '应收退款' || type == '应付票据付款'){
  1976. if(payment == 0 || payment == null || payment == '' ){
  1977. showError('支出金额不能为空!');
  1978. return;
  1979. }
  1980. if(type == '预付款' || type == '应付款' || type == '应收退款'){
  1981. if(form.BaseUtil.numberFormat(ar_araprate,8) != form.BaseUtil.numberFormat(ar_aramount/payment,8)){
  1982. showError('冲账汇率不正确!');
  1983. return;
  1984. }
  1985. }
  1986. } else if(type == '转存') {
  1987. if(payment == 0 || payment == null || payment == '' ){
  1988. showError('支出金额不能为空!');
  1989. return;
  1990. }
  1991. if(Ext.isEmpty(ar_category)){
  1992. showError('转存科目不能为空!');
  1993. return;
  1994. }
  1995. if(Ext.isEmpty(ar_precurrency)){
  1996. showError('转存币别不能为空!');
  1997. return;
  1998. }
  1999. if(ar_preamount == 0 || ar_preamount == null || ar_preamount == '' ){
  2000. showError('转存金额不能为空!');
  2001. return;
  2002. }
  2003. if(ar_accountcurrency != ar_precurrency){
  2004. if(ar_prerate == 1){
  2005. showError('币别不一致,转存汇率为1,不能提交!');
  2006. return;
  2007. }
  2008. }
  2009. }
  2010. if(type != '应收票据收款' && type != '应付票据付款' && type != '费用' && type != '转存' && type != '其它收款' && type != '其它付款'){
  2011. if(ar_accountcurrency != ar_arapcurrency){
  2012. if(ar_araprate == '1'){
  2013. showError('币别不一致,冲账汇率为1,不能提交!');
  2014. return;
  2015. }
  2016. }
  2017. }
  2018. }
  2019. Ext.each(items,function(item,index){
  2020. if(!Ext.isEmpty(item.data['ard_explanation']) || !Ext.isEmpty(item.data['ard_catecode']) || !Ext.isEmpty(item.data['ard_ordercode']) || !Ext.isEmpty(item.data['ard_makecode'])){
  2021. debit= debit + Number(item.data['ard_debit']);
  2022. credit= credit + Number(item.data['ard_credit']);
  2023. }
  2024. });
  2025. if(!Ext.isEmpty(Ext.getCmp('ar_source').value)){
  2026. if(type == '应收款' || type == '预收款' || type == '应付退款' || type == '预付退款'){
  2027. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(credit-debit, 2))>0.011){
  2028. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
  2029. return;
  2030. }
  2031. }
  2032. if(type == '应付款' || type == '应收退款' || type == '预收退款'){
  2033. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  2034. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  2035. return;
  2036. }
  2037. }
  2038. if(type == '预付款'){
  2039. if(Ext.getCmp('ar_sourcetype')&&Ext.getCmp('ar_sourcetype').value!="付款申请"){
  2040. if(Math.abs(form.BaseUtil.numberFormat(ar_aramount, 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  2041. showError('冲账金额' + form.BaseUtil.numberFormat(ar_aramount, 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  2042. return;
  2043. }
  2044. }
  2045. }
  2046. if(type == '应收票据收款'){
  2047. console.log(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2)));
  2048. if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2)-form.BaseUtil.numberFormat(credit-debit, 2))>0.011){
  2049. showError('收入金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(deposit, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(credit-debit, 2) + '不一致!');
  2050. return;
  2051. }
  2052. }
  2053. if(type == '应付票据付款'){
  2054. if(Math.abs(form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2)-form.BaseUtil.numberFormat(debit-credit, 2))>0.011){
  2055. showError('支出金额' + form.BaseUtil.numberFormat(form.BaseUtil.multiply(payment, ar_accountrate), 2) + '与从表金额' + form.BaseUtil.numberFormat(debit-credit, 2) + '不一致!');
  2056. return;
  2057. }
  2058. }
  2059. }
  2060. var errs = [];
  2061. Ext.Array.each(items, function(item){
  2062. if(!Ext.isEmpty(item.data['ard_catecode'])){
  2063. if(item.data['ca_currencytype'] != 0){
  2064. if(Ext.isEmpty(item.data['ard_currency'])){
  2065. errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,币别不能为空!');
  2066. return;
  2067. }
  2068. if(Ext.isEmpty(item.data['ard_rate']) || item.data['ard_rate'] == 0){
  2069. errs.push('明细表第' + item.data['ard_detno'] + '行的科目是外币科目,汇率不能为0!');
  2070. return;
  2071. }
  2072. }
  2073. if(item.data['ard_doubledebit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_debit'] != 0){
  2074. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doubledebit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_debit'],2)) {
  2075. errs.push('明细表第' + item.data['ard_detno'] + '行,原币借方*汇率不等于本币借方!');
  2076. return;
  2077. }
  2078. }
  2079. if(item.data['ard_doublecredit'] != 0 && item.data['ard_rate'] != 0 && item.data['ard_credit'] != 0){
  2080. if (me.BaseUtil.numberFormat(me.BaseUtil.multiply(item.data['ard_doublecredit'], item.data['ard_rate']),2) != me.BaseUtil.numberFormat(item.data['ard_credit'],2)) {
  2081. errs.push('明细表第' + item.data['ard_detno'] + '行,原币贷方*汇率不等于本币贷方!');
  2082. return;
  2083. }
  2084. }
  2085. }
  2086. });
  2087. if(errs.length > 0) {
  2088. showError(errs.join('<br>'));
  2089. return;
  2090. }
  2091. this.FormUtil.onSubmit(Ext.getCmp('ar_id').value, false, this.beforeUpdate, this);
  2092. },
  2093. copy: function(){
  2094. var me = this;
  2095. var form = Ext.getCmp('form');
  2096. var v = form.down('#ar_id').value;
  2097. if(v > 0) {
  2098. form.setLoading(true);
  2099. Ext.Ajax.request({
  2100. url: basePath + 'fa/gs/copyAccountRegister.action',
  2101. params: {
  2102. id: v
  2103. },
  2104. callback: function(opt, s, r){
  2105. form.setLoading(false);
  2106. var res = Ext.decode(r.responseText);
  2107. if(res.ar) {
  2108. turnSuccess(function(){
  2109. var id = res.ar.ar_id;
  2110. var url = "jsps/fa/gs/accountRegister.jsp?formCondition=ar_idIS" +
  2111. + id + "&gridCondition=ard_aridIS" + id + "&whoami=AccountRegister!Bank";
  2112. me.FormUtil.onAdd('accountRegister' + id, '银行登记' + id, url);
  2113. });
  2114. } else {
  2115. showError(res.exceptionInfo);
  2116. }
  2117. }
  2118. });
  2119. }
  2120. },
  2121. getApamount: function(){
  2122. var grid = Ext.getCmp('grid');
  2123. var items = grid.store.data.items;
  2124. var apamount = 0, type = Ext.getCmp('ar_type').value;
  2125. if(type != null && type != '' ){
  2126. if(type == '应付款'){
  2127. Ext.each(items,function(item,index){
  2128. if(!Ext.isEmpty(item.data['ard_ordercode'])){
  2129. apamount= apamount + Number(item.data['ard_nowbalance']);
  2130. }
  2131. });
  2132. Ext.getCmp('ar_apamount').setValue(Ext.util.Format.number(apamount,'0.00'));
  2133. }
  2134. if(type == '预付款'){
  2135. var cmamount = Ext.Number.from(Ext.getCmp('ar_aramount').getValue(), 0);
  2136. Ext.each(items,function(item,index){
  2137. if(Ext.isEmpty(item.data['ard_ordercode']) && Ext.isEmpty(item.data['ard_makecode'])){
  2138. apamount= apamount + Number(item.data['ard_nowbalance']);
  2139. }
  2140. });
  2141. Ext.getCmp('ar_apamount').setValue(Ext.util.Format.number(cmamount-apamount,'0.00'));
  2142. }
  2143. }
  2144. }
  2145. });