PrePay.js 18 KB

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