PrePay.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.arp.PrePay', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'core.form.Panel','fa.arp.PrePay','core.grid.Panel2','core.toolbar.Toolbar', 'core.form.SeparNumber',
  9. 'core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Submit','core.button.ResAudit','core.button.Print',
  10. 'core.button.Audit','core.button.ResSubmit','core.button.Post','core.button.ResPost','core.button.Update','core.button.DeleteDetail',
  11. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.ResAccounted','core.button.AssMain','core.button.Accounted','core.button.StrikeBalance',
  12. 'core.grid.AssPanel','core.window.AssWindow','core.trigger.CateTreeDbfindTrigger','core.trigger.HrOrgTreeDbfindTrigger','core.button.Print','core.button.AssDetail','core.button.AssMain'
  13. ,'core.button.GetSumAmount'
  14. ],
  15. init:function(){
  16. var me = this;
  17. me.gridLastSelected = null;
  18. this.control({
  19. 'erpGridPanel2': {
  20. itemclick:function(selModel, record){
  21. me.onGridItemClick(selModel, record);
  22. var btn = Ext.getCmp('assdetail');
  23. var ass = record.data['ca_asstype'];
  24. if(!Ext.isEmpty(ass)){
  25. btn.setDisabled(false);
  26. } else {
  27. btn.setDisabled(true);
  28. }
  29. }
  30. },
  31. 'field[name=pp_currency]': {
  32. beforetrigger: function(field) {
  33. var t = field.up('form').down('field[name=pp_date]'),
  34. value = t.getValue();
  35. if(value) {
  36. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  37. }
  38. }
  39. },
  40. 'field[name=ca_assname]':{
  41. change: function(m){
  42. if(Ext.isEmpty(m)){
  43. Ext.getCmp('assmainbutton').setDisabled(true);
  44. }else{
  45. Ext.getCmp('assmainbutton').setDisabled(false);
  46. }
  47. }
  48. },
  49. 'field[name=pp_amount]':{
  50. beforerender: function(field){
  51. if(Ext.getCmp('pp_sourcecode')&&Ext.getCmp('pp_sourcecode').value!=""){
  52. field.readOnly=true;
  53. }
  54. }
  55. },
  56. 'erpAssMainButton':{
  57. afterrender:function(btn){
  58. if(Ext.getCmp('ca_assname').getValue()==null||Ext.getCmp('ca_assname').getValue()==""){
  59. btn.setDisabled(true);
  60. }else{
  61. btn.setDisabled(false);
  62. }
  63. }
  64. },
  65. 'erpGetSumAmountButton':{
  66. click: function(btn){
  67. var grid = Ext.getCmp("grid"),items = grid.store.data.items;
  68. var detailamount1 = 0;
  69. Ext.each(items,function(item,index){
  70. if(!me.GridUtil.isBlank(grid,item.data)) {
  71. detailamount1 = detailamount1 + Number(item.data['ppd_nowbalance']);
  72. }
  73. });
  74. Ext.getCmp("pp_amount").setValue(detailamount1);
  75. Ext.getCmp("pp_vmamount").setValue(detailamount1);
  76. }
  77. },
  78. 'erpSaveButton': {
  79. click: function(btn){
  80. var form = me.getForm(btn);
  81. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  82. me.BaseUtil.getRandomNumber('PrePay');
  83. }
  84. me.changeVmrateOrVmamount();
  85. me.getJsamount();
  86. //保存之前的一些前台的逻辑判定
  87. this.beforeSaveAccountRegister();
  88. }
  89. },
  90. 'erpDeleteDetailButton': {
  91. afterrender: function(btn){
  92. //辅助核算
  93. btn.ownerCt.add({
  94. xtype:'erpAssDetailButton',
  95. disabled:true
  96. });
  97. },
  98. beforedelete:function(data,record,btn){
  99. if(record.get('pbd_pbid') !=null){
  100. btn.canDelete=false;
  101. showError('当前行存在来源不允许修改!');
  102. }
  103. }
  104. },
  105. 'erpDeleteButton' : {
  106. click: function(btn){
  107. var source = Ext.getCmp('pp_source');
  108. if(source && source.value){
  109. showError("请在来源:"+source.value+",单号:"+Ext.getCmp('pp_sourcecode').value+"中进行反审核或者反记账操作!");
  110. return;
  111. }
  112. me.FormUtil.onDelete(Ext.getCmp('pp_id').value);
  113. }
  114. },
  115. 'erpPostButton' : {
  116. afterrender: function(btn){
  117. var status = Ext.getCmp('pp_statuscode');
  118. if(status && status.value != 'UNPOST'){
  119. btn.hide();
  120. }
  121. },
  122. click: function(btn){
  123. var amount = Number(Ext.getCmp('pp_amount').getValue());
  124. var cmamount =Number(Ext.getCmp('pp_vmamount').getValue());
  125. var cmcurrency = Ext.getCmp('pp_vmcurrency').getValue();
  126. var cmrate = Number(Ext.getCmp('pp_vmrate').getValue());
  127. var currency = Ext.getCmp('pp_currency').getValue();
  128. if(amount != 0 && cmamount != 0){
  129. if(Ext.Number.toFixed(cmrate, 8)!= Ext.Number.toFixed(cmamount/amount, 8)){
  130. showError('冲账汇率不正确,不能过账!');
  131. return;
  132. }
  133. }
  134. if(currency == cmcurrency){
  135. if(cmrate != 1){
  136. showError('币别相同,冲账汇率不等于1,不能过账!');
  137. return;
  138. }
  139. }
  140. if(currency != cmcurrency){
  141. if(cmrate == 1){
  142. showError('币别不相同,冲账汇率等于1,不能过账!');
  143. return;
  144. }
  145. }
  146. me.FormUtil.onPost(Ext.getCmp('pp_id').value);
  147. }
  148. },
  149. 'erpResPostButton' : {
  150. afterrender: function(btn){
  151. var status = Ext.getCmp('pp_statuscode');
  152. if(status && status.value != 'POSTED'){
  153. btn.hide();
  154. }
  155. },
  156. click: function(btn){
  157. me.FormUtil.onResPost(Ext.getCmp('pp_id').value);
  158. }
  159. },
  160. 'erpPrintButton': {
  161. click:function(btn){
  162. var reportName='';
  163. reportName="APPrePay";
  164. var condition='{PrePay.pp_id}='+Ext.getCmp('pp_id').value+'';
  165. var id=Ext.getCmp('pp_id').value;
  166. me.FormUtil.onwindowsPrint(id,reportName,condition);
  167. }
  168. },
  169. 'erpUpdateButton': {
  170. click: function(btn){
  171. me.changeVmrateOrVmamount();
  172. me.getJsamount();
  173. me.beforeUpdate();
  174. }
  175. },
  176. 'erpAddButton': {
  177. click: function(){
  178. var form = Ext.getCmp('form');
  179. var title = '新增';
  180. if(form){
  181. if(form.title){
  182. title = title+form.title;
  183. }
  184. }
  185. me.FormUtil.onAdd('addPrePay', title, 'jsps/fa/arp/prepay.jsp?whoami='+caller);
  186. }
  187. },
  188. 'erpCloseButton': {
  189. click: function(btn){
  190. me.FormUtil.beforeClose(me);
  191. }
  192. },
  193. 'erpSubmitButton': {
  194. afterrender: function(btn){
  195. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  196. poststatus = Ext.getCmp('pp_statuscode');
  197. if(status && status.value != 'ENTERING'){
  198. btn.hide();
  199. }
  200. if(poststatus && poststatus.value == 'POSTED'){
  201. btn.hide();
  202. }
  203. },
  204. click: function(btn){
  205. var amount = Number(Ext.getCmp('pp_amount').getValue());
  206. var cmamount =Number(Ext.getCmp('pp_vmamount').getValue());
  207. var cmcurrency = Ext.getCmp('pp_vmcurrency').getValue();
  208. var cmrate = Number(Ext.getCmp('pp_vmrate').getValue());
  209. var currency = Ext.getCmp('pp_currency').getValue();
  210. if(amount != 0 && cmamount != 0){
  211. if(Ext.Number.toFixed(cmrate, 8)!= Ext.Number.toFixed(cmamount/amount, 8)){
  212. showError('冲账汇率不正确,不能提交!');
  213. return;
  214. }
  215. }
  216. if(currency == cmcurrency){
  217. if(cmrate != 1){
  218. showError('币别相同,冲账汇率不等于1,不能提交!');
  219. return;
  220. }
  221. }
  222. if(currency != cmcurrency){
  223. if(cmrate == 1){
  224. showError('币别不相同,冲账汇率等于1,不能提交!');
  225. return;
  226. }
  227. }
  228. me.FormUtil.onSubmit(Ext.getCmp('pp_id').value);
  229. }
  230. },
  231. 'erpResSubmitButton': {
  232. afterrender: function(btn){
  233. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  234. poststatus = Ext.getCmp('pp_statuscode');
  235. if(status && status.value != 'COMMITED'){
  236. btn.hide();
  237. }
  238. if(poststatus && poststatus.value == 'POSTED'){
  239. btn.hide();
  240. }
  241. },
  242. click: function(btn){
  243. me.FormUtil.onResSubmit(Ext.getCmp('pp_id').value);
  244. }
  245. },
  246. 'erpAuditButton': {
  247. afterrender: function(btn){
  248. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  249. poststatus = Ext.getCmp('pp_statuscode');
  250. if(status && status.value != 'COMMITED'){
  251. btn.hide();
  252. }
  253. if(poststatus && poststatus.value == 'POSTED'){
  254. btn.hide();
  255. }
  256. },
  257. click: function(btn){
  258. me.FormUtil.onAudit(Ext.getCmp('pp_id').value);
  259. }
  260. },
  261. 'erpResAuditButton': {
  262. afterrender: function(btn){
  263. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  264. postStatus = Ext.getCmp('pp_statuscode');
  265. if((status && status.value != 'AUDITED') ||(postStatus && postStatus.value == 'POSTED')){
  266. btn.hide();
  267. }
  268. },
  269. click: function(btn){
  270. me.FormUtil.onResAudit(Ext.getCmp('pp_id').value);
  271. }
  272. },
  273. 'cateTreeDbfindTrigger[name=pp_accountcode]':{
  274. aftertrigger:function(trigger, data){
  275. Ext.getCmp('pp_accountname').setValue(data[0].raw.data.ca_name);
  276. var asstype = data[0].raw.data.ca_asstype;
  277. var btn = Ext.getCmp("assmainbutton");
  278. if (Ext.isEmpty(asstype)){
  279. btn.setDisabled(true);
  280. } else {
  281. btn.setDisabled(false);
  282. }
  283. }
  284. },
  285. 'dbfindtrigger[name=ppd_ordercode]':{
  286. afterrender:function(t){
  287. t.gridKey="pp_vendcode";
  288. t.mappinggirdKey="pu_vendcode";
  289. t.gridErrorMessage="请先选择供应商";
  290. }
  291. },
  292. 'dbfindtrigger[name=ppd_makecode]':{
  293. afterrender:function(t){
  294. t.gridKey="pp_vendcode";
  295. t.mappinggirdKey="ma_vendcode";
  296. t.gridErrorMessage="请先选择供应商";
  297. }
  298. },
  299. 'textfield[name=pp_amount]':{
  300. change: function(){
  301. me.changeVmrateOrVmamount();
  302. }
  303. },
  304. 'textfield[name=pp_vmrate]':{
  305. change: function(){
  306. me.changeVmrateOrVmamount();
  307. }
  308. },
  309. 'textfield[name=pp_vmamount]':{
  310. change: function(){
  311. me.changeVmrateOrVmamount();
  312. }
  313. }
  314. });
  315. },
  316. changeVmrateOrVmamount: function () {
  317. var me = this;
  318. if(Ext.getCmp('pp_vmrate').readOnly){
  319. me.changeVmrate();
  320. }else{
  321. me.changeVmamount();
  322. }
  323. },
  324. changeVmrate:function () {
  325. if(Ext.getCmp('pp_vmamount')&&Ext.getCmp('pp_amount')&&Ext.getCmp('pp_vmrate')){
  326. var vmamount = Ext.getCmp('pp_vmamount').getValue();;
  327. var amount = Ext.getCmp('pp_amount').getValue();
  328. var rate = Number(vmamount/amount);
  329. rate = Ext.Number.toFixed(rate,8);
  330. Ext.getCmp('pp_vmrate').setValue(rate);
  331. }
  332. },
  333. //计算冲账金额 = 预收金额*冲账汇率
  334. changeVmamount:function(){
  335. if(Ext.getCmp('pp_amount')&&Ext.getCmp('pp_vmrate')){
  336. var ppamount = Ext.getCmp('pp_amount').getValue();
  337. var ppvmrate = Ext.getCmp('pp_vmrate').getValue();
  338. if(!Ext.isNumber(ppamount)){
  339. ppamount = Ext.Number.from(ppamount,0);
  340. }
  341. if(!Ext.isNumber(ppvmrate)){
  342. ppvmrate = Ext.Number.from(ppvmrate,0);
  343. }
  344. var vmamount = ppamount*ppvmrate;
  345. Ext.getCmp('pp_vmamount').setValue(Ext.util.Format.number(vmamount,'0.00'));
  346. }
  347. },
  348. getJsamount: function(){
  349. var grid = Ext.getCmp('grid');
  350. var items = grid.store.data.items;
  351. var jsamount = 0;
  352. var detailcount = 0;
  353. var cateamount = 0;
  354. Ext.each(items,function(item,index){
  355. if(item.data['ppd_catecode']!=null&&item.data['ppd_catecode']!=""){
  356. cateamount = cateamount + Number(item.data['ppd_nowbalance']);
  357. }
  358. });
  359. Ext.getCmp('pp_jsamount').setValue(Ext.Number.from(Ext.getCmp('pp_vmamount').getValue())-cateamount);
  360. },
  361. onGridItemClick: function(selModel, record){//grid行选择
  362. this.gridLastSelected = record;
  363. var grid = Ext.getCmp('grid');
  364. if(record.data[grid.necessaryField] == null || record.data[grid.necessaryField] == ''){
  365. this.gridLastSelected.findable = true;//空数据可以在输入完code,并移开光标后,自动调出该条数据
  366. } else {
  367. this.gridLastSelected.findable = false;
  368. }
  369. this.GridUtil.onGridItemClick(selModel, record);
  370. },
  371. getForm: function(btn){
  372. return btn.ownerCt.ownerCt;
  373. },
  374. beforeSaveAccountRegister: function(){
  375. var me = this;
  376. var grid = Ext.getCmp('grid');
  377. var items = grid.store.data.items;
  378. var bool = true;
  379. var warnStr='';
  380. Ext.each(items,function(item,index){
  381. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  382. var orderamount =item.data['ppd_orderamount']; //订单金额
  383. var havebalance = item.data['ppd_havebalance']; //已预付金额
  384. var nowbalance = item.data['ppd_nowbalance']; //本次预付额
  385. //订单金额>=已预收金额+本次预收额
  386. //此种情况不能进行保存
  387. if(havebalance+nowbalance>orderamount){
  388. var i = index+1;
  389. if(warnStr ==''||warnStr.length<=0){
  390. warnStr = warnStr +i;
  391. }else{
  392. warnStr = warnStr +','+i;
  393. }
  394. bool = false;
  395. }
  396. }
  397. });
  398. if(bool){
  399. this.beforeSave(this);
  400. }else{
  401. if(warnStr != ''||warnStr.length>0){
  402. showError('明细表第'+warnStr+'行 已预收金额与本次预收额的合计超过订单金额,不能保存');return;
  403. }
  404. }
  405. },
  406. beforeSave:function(){
  407. var me = this;
  408. var form = Ext.getCmp('form');
  409. if(! me.FormUtil.checkForm()){
  410. return;
  411. }
  412. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  413. me.FormUtil.getSeqId(form);
  414. }
  415. var detail = Ext.getCmp('grid');
  416. var param2 = new Array();
  417. var param3 = new Array();
  418. if(Ext.getCmp('assdetail')){
  419. Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
  420. Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
  421. d['dass_condid'] = key;
  422. param2.push(d);
  423. });
  424. });
  425. }
  426. if(Ext.getCmp('assmainbutton')){
  427. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  428. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  429. d['ass_conid'] = key;
  430. param3.push(d);
  431. });
  432. });
  433. }
  434. Ext.each(detail.store.data.items, function(item){
  435. if(item.data.prd_id == null || item.data.prd_id == 0){
  436. item.data.prd_id = -item.index;
  437. }
  438. });
  439. var param1 = me.GridUtil.getGridStore(detail);
  440. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  441. showError($I18N.common.grid.emptyDetail);
  442. return;
  443. }
  444. me.onSave(form, param1, param2,param3);
  445. },
  446. onSave: function(form, param1, param2,param3) {
  447. var me = this;
  448. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  449. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  450. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  451. if(form.getForm().isValid()){
  452. Ext.each(form.items.items, function(item){
  453. if(item.xtype == 'numberfield'){
  454. if(item.value == null || item.value == ''){
  455. item.setValue(0);
  456. }
  457. }
  458. });
  459. var r = form.getValues();
  460. form.getForm().getFields().each(function(){
  461. if(this.logic == 'ignore') {
  462. delete r[this.name];
  463. }
  464. });
  465. me.FormUtil.save(r, param1, param2,param3);
  466. }else{
  467. me.FormUtil.checkForm();
  468. }
  469. },
  470. beforeUpdate: function(){
  471. var me = this;
  472. var grid = Ext.getCmp('grid');
  473. Ext.Array.each(grid.store.data.items, function(item){
  474. item.set('ppd_ppid',Ext.getCmp('pp_id').value);
  475. });
  476. //采购价格不能为0
  477. var grid = Ext.getCmp('grid');
  478. var items = grid.store.data.items;
  479. var bool = true;
  480. var warnStr='';
  481. Ext.each(items,function(item,index){
  482. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  483. var orderamount =item.data['ppd_orderamount']; //订单金额
  484. var havebalance = item.data['ppd_havebalance']; //已预付金额
  485. var nowbalance = item.data['ppd_nowbalance']; //本次预付额
  486. //订单金额>=已预收金额+本次预收额
  487. //此种情况不能进行保存
  488. if(havebalance+nowbalance>orderamount){
  489. var i = index+1;
  490. if(warnStr ==''||warnStr.length<=0){
  491. warnStr = warnStr +i;
  492. }else{
  493. warnStr = warnStr +','+i;
  494. }
  495. bool = false;
  496. }
  497. }
  498. });
  499. if(bool){
  500. me.onUpdate(this);
  501. }else{
  502. if(warnStr != ''||warnStr.length>0){
  503. showError('明细表第'+warnStr+'行 已预付金额与本次预付额的合计超过订单金额,不能保存');return;
  504. }
  505. }
  506. },
  507. onUpdate: function(){
  508. var me = this;
  509. var form = Ext.getCmp('form');
  510. if(! me.FormUtil.checkForm()){
  511. return;
  512. }
  513. var detail = Ext.getCmp('grid');
  514. Ext.each(detail.store.data.items, function(item){
  515. if(item.data.prd_id == null || item.data.prd_id == 0){
  516. item.data.prd_id = -item.index;
  517. }
  518. });
  519. var param1 = me.GridUtil.getGridStore(detail);
  520. var param2 = new Array();
  521. var param3 = new Array();
  522. if(Ext.getCmp('assdetail')){
  523. Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
  524. Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
  525. d['dass_condid'] = key;
  526. param2.push(d);
  527. });
  528. });
  529. }
  530. if(Ext.getCmp('assmainbutton')){
  531. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  532. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  533. d['ass_conid'] = key;
  534. param3.push(d);
  535. });
  536. });
  537. }
  538. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
  539. && param2.length == 0&& param3.length == 0){
  540. showError($I18N.common.grid.emptyDetail);
  541. return;
  542. } else {
  543. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  544. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  545. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  546. if(form.getForm().isValid()){
  547. Ext.each(form.items.items, function(item){
  548. if(item.xtype == 'numberfield'){
  549. if(item.value == null || item.value == ''){
  550. item.setValue(0);
  551. }
  552. }
  553. });
  554. var r = form.getValues();
  555. form.getForm().getFields().each(function(){
  556. if(this.logic == 'ignore') {
  557. delete r[this.name];
  558. }
  559. });
  560. me.FormUtil.update(r, param1, param2, param3);
  561. }else{
  562. me.FormUtil.checkForm();
  563. }
  564. }
  565. }
  566. });