BillAP.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.gs.BillAP', {
  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. 'fa.gs.BillAP','core.form.Panel','core.form.MultiField','core.form.FileField','core.form.MultiField',
  9. 'core.button.Add','core.button.Submit','core.button.Audit','core.button.Save','core.button.Close',
  10. 'core.button.ResSubmit','core.button.Update','core.button.Delete','core.button.Nullify',
  11. 'core.button.ResAudit','core.button.UpdateInfo','core.window.AssWindow','core.button.AssMain',
  12. 'core.button.CopyAll',
  13. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.form.YnField','core.form.SeparNumber'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'field[name=bap_duedate]':{
  19. beforerender: function(field){
  20. field.readOnly=false;
  21. }
  22. },
  23. 'field[name=bap_currency]': {
  24. beforetrigger: function(field) {
  25. var t = field.up('form').down('field[name=bap_date]'),
  26. value = t.getValue();
  27. if(value) {
  28. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  29. }
  30. }
  31. },
  32. 'field[name=bap_vendcode]':{
  33. beforerender: function(field){
  34. if(Ext.getCmp('bap_paybillcode')&& !Ext.isEmpty(Ext.getCmp('bap_paybillcode').value)){
  35. field.readOnly=true;
  36. }
  37. }
  38. },
  39. 'field[name=ca_asstype]':{
  40. change: function(f){
  41. var btn = Ext.getCmp('assmainbutton');
  42. if(Ext.getCmp('bap_billkind').value != '其他付款'){
  43. btn.hide();
  44. } else {
  45. btn && btn.setDisabled(Ext.isEmpty(f.value));
  46. }
  47. }
  48. },
  49. 'erpAssMainButton':{
  50. afterrender:function(btn){
  51. if(Ext.getCmp('bap_billkind').value != '其他付款'){
  52. btn.hide();
  53. } else {
  54. if(Ext.getCmp('ca_asstype') && Ext.isEmpty(Ext.getCmp('ca_asstype').getValue())){
  55. btn.setDisabled(true);
  56. } else {
  57. btn.setDisabled(false);
  58. }
  59. }
  60. }
  61. },
  62. 'erpSaveButton': {
  63. click: function(btn){
  64. if(Ext.getCmp('bap_duedate').value < Ext.getCmp('bap_date').value){
  65. showError('到期日期小于票据日期'); return;
  66. }
  67. if(Ext.getCmp('bap_outdate').value > Ext.getCmp('bap_duedate').value){
  68. showError('出票日期大于到期日期'); return;
  69. }
  70. var form = me.getForm(btn);
  71. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  72. me.BaseUtil.getRandomNumber();
  73. }
  74. var param = new Array();
  75. if(Ext.getCmp('assmainbutton')){
  76. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  77. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  78. d['ass_conid'] = key;
  79. param.push(d);
  80. });
  81. });
  82. }
  83. if(Ext.isEmpty(me.FormUtil.checkFormDirty(form)) && param.length == 0){
  84. showError($I18N.common.grid.emptyDetail);
  85. return;
  86. } else {
  87. param = param == null ? [] : Ext.encode(param).replace(/\\/g,"%");
  88. if(form.getForm().isValid()){
  89. Ext.each(form.items.items, function(item){
  90. if(item.xtype == 'numberfield'){
  91. if(item.value == null || item.value == ''){
  92. item.setValue(0);
  93. }
  94. }
  95. });
  96. var r = form.getValues();
  97. form.getForm().getFields().each(function(){
  98. if(this.logic == 'ignore') {
  99. delete r[this.name];
  100. }
  101. });
  102. me.FormUtil.beforeSave(r, param);
  103. }else{
  104. me.FormUtil.checkForm();
  105. }
  106. }
  107. }
  108. },
  109. 'erpCloseButton': {
  110. click: function(btn){
  111. this.FormUtil.beforeClose(this);
  112. }
  113. },
  114. 'erpAddButton': {
  115. click: function(){
  116. me.FormUtil.onAdd('addBillAP', '新增应付票据', 'jsps/fa/gs/billAP.jsp');
  117. }
  118. },
  119. 'erpUpdateButton': {
  120. click: function(btn){
  121. var form = me.getForm(btn);
  122. if(Ext.getCmp('bap_duedate').value < Ext.getCmp('bap_date').value){
  123. showError('到期日期小于票据日期'); return;
  124. }
  125. if(Ext.getCmp('bap_outdate').value > Ext.getCmp('bap_duedate').value){
  126. showError('出票日期大于到期日期'); return;
  127. }
  128. var param = new Array();
  129. if(Ext.getCmp('assmainbutton')){
  130. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  131. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  132. d['ass_conid'] = key;
  133. param.push(d);
  134. });
  135. });
  136. }
  137. if(Ext.isEmpty(me.FormUtil.checkFormDirty(form)) && param.length == 0){
  138. showError($I18N.common.grid.emptyDetail);
  139. return;
  140. } else {
  141. param = param == null ? [] : Ext.encode(param).replace(/\\/g,"%");
  142. if(form.getForm().isValid()){
  143. Ext.each(form.items.items, function(item){
  144. if(item.xtype == 'numberfield'){
  145. if(item.value == null || item.value == ''){
  146. item.setValue(0);
  147. }
  148. }
  149. });
  150. var r = form.getValues();
  151. form.getForm().getFields().each(function(){
  152. if(this.logic == 'ignore') {
  153. delete r[this.name];
  154. }
  155. });
  156. me.FormUtil.update(r, param);
  157. }else{
  158. me.FormUtil.checkForm();
  159. }
  160. }
  161. }
  162. },
  163. 'erpDeleteButton': {
  164. click: function(btn){
  165. this.FormUtil.onDelete(Ext.getCmp('bap_id').value);
  166. }
  167. },
  168. 'erpSubmitButton': {
  169. afterrender: function(btn){
  170. var status = Ext.getCmp('bap_statuscode');
  171. if(status && status.value != 'ENTERING'){
  172. btn.hide();
  173. }
  174. },
  175. click: function(btn){
  176. if(Ext.getCmp('bap_duedate').value < Ext.getCmp('bap_date').value){
  177. showError('到期日期小于票据日期'); return;
  178. }
  179. if(Ext.getCmp('bap_outdate').value > Ext.getCmp('bap_duedate').value){
  180. showError('出票日期大于到期日期'); return;
  181. }
  182. if(Ext.Number.toFixed(Ext.getCmp('bap_cmrate').value,8) != Ext.Number.toFixed(Ext.getCmp('bap_topaybalance').value/Ext.getCmp('bap_doublebalance').value,8)){
  183. showError('冲账汇率不正确!');
  184. return;
  185. }
  186. var cmcurrency = Ext.getCmp('bap_cmcurrency').getValue();
  187. var currency = Ext.getCmp('bap_currency').getValue();
  188. var cmrate = Number(Ext.getCmp('bap_cmrate').getValue());
  189. if(currency == cmcurrency){
  190. if(cmrate != 1){
  191. showError('币别相同,冲账汇率不等于1,不能过账!');
  192. return;
  193. }
  194. }
  195. if(currency != cmcurrency){
  196. if(cmrate == 1){
  197. showError('币别不相同,冲账汇率等于1,不能过账!');
  198. return;
  199. }
  200. }
  201. me.FormUtil.onSubmit(Ext.getCmp('bap_id').value);
  202. }
  203. },
  204. 'erpResSubmitButton': {
  205. afterrender: function(btn){
  206. var status = Ext.getCmp('bap_statuscode');
  207. if(status && status.value != 'COMMITED'){
  208. btn.hide();
  209. }
  210. },
  211. click: function(btn){
  212. me.FormUtil.onResSubmit(Ext.getCmp('bap_id').value);
  213. }
  214. },
  215. 'erpAuditButton':{
  216. afterrender: function(btn){
  217. var status = Ext.getCmp('bap_statuscode');
  218. if(status && status.value != 'COMMITED'){
  219. btn.hide();
  220. }
  221. },
  222. click: {
  223. fn:function(btn){
  224. me.auditBillAP();
  225. },
  226. lock:2000
  227. }
  228. },
  229. 'erpResAuditButton': {
  230. afterrender: function(btn){
  231. var status = Ext.getCmp('bap_statuscode');
  232. if(status && status.value != 'AUDITED'){
  233. btn.hide();
  234. }
  235. },
  236. click: function(btn){
  237. me.FormUtil.onResAudit(Ext.getCmp('bap_id').value);
  238. }
  239. },
  240. 'erpNullifyButton': {
  241. afterrender: function(btn){
  242. var status = Ext.getCmp('bap_nowstatus');
  243. if(status && status.value != '已作废'){
  244. btn.hide();
  245. }
  246. },
  247. click: function(btn){
  248. me.FormUtil.onNullify(Ext.getCmp('bap_id').value);
  249. }
  250. },
  251. 'textfield[name=bap_cmrate]':{
  252. beforerender: function(field){
  253. if(Ext.getCmp('bap_paybillcode') && !Ext.isEmpty(Ext.getCmp('bap_paybillcode').value)){
  254. field.readOnly=true;
  255. }
  256. },
  257. change: me.gettopaybalance
  258. },
  259. 'textfield[name=bap_doublebalance]':{
  260. beforerender: function(field){
  261. if(Ext.getCmp('bap_paybillcode')&&Ext.getCmp('bap_paybillcode').value!=""){
  262. field.readOnly=true;
  263. }
  264. },
  265. change: me.gettopaybalance
  266. },
  267. 'field[name=bap_cmcurrency]':{
  268. beforerender: function(field){
  269. if(Ext.getCmp('bap_paybillcode') && !Ext.isEmpty(Ext.getCmp('bap_paybillcode').value)){
  270. field.readOnly=true;
  271. }
  272. }
  273. },
  274. 'field[name=bap_topaybalance]':{
  275. beforerender: function(field){
  276. if(Ext.getCmp('bap_paybillcode') && Ext.isEmpty(Ext.getCmp('bap_paybillcode').value)){
  277. field.readOnly=true;
  278. }
  279. },
  280. change: me.gettopaybalance
  281. },
  282. 'erpUpdateInfoButton':{
  283. click:function(){
  284. var text=Ext.getCmp('bap_duedate');
  285. me.updateInfo(text.value,Ext.getCmp('bap_id').value);
  286. }
  287. },
  288. 'erpCopyButton': {
  289. click: function(btn) {
  290. this.copy();
  291. }
  292. }
  293. });
  294. },
  295. updateInfo:function(text,id){
  296. Ext.Ajax.request({
  297. url : basePath + 'fa/gs/billap/updateInfo.action',
  298. params: {text:text,id:id,caller:caller},
  299. method : 'post',
  300. async:false,
  301. callback : function(options,success,response){
  302. var res = new Ext.decode(response.responseText);
  303. if(res.exceptionInfo != null){
  304. showError(res.exceptionInfo);return;
  305. }
  306. showMessage("提示", '更新成功!');
  307. window.location.reload();
  308. }
  309. });
  310. },
  311. auditBillAP:function(){
  312. var me = this;
  313. if(Ext.getCmp('bap_duedate').value < Ext.getCmp('bap_date').value){
  314. showError('到期日期小于票据日期'); return;
  315. }
  316. if(Ext.getCmp('bap_outdate').value > Ext.getCmp('bap_duedate').value){
  317. showError('出票日期大于到期日期'); return;
  318. }
  319. var cmcurrency = Ext.getCmp('bap_cmcurrency').getValue();
  320. var currency = Ext.getCmp('bap_currency').getValue();
  321. var cmrate = Number(Ext.getCmp('bap_cmrate').getValue());
  322. if(currency == cmcurrency){
  323. if(cmrate != 1){
  324. showError('币别相同,冲账汇率不等于1,不能过账!');
  325. return;
  326. }
  327. }
  328. if(currency != cmcurrency){
  329. if(cmrate == 1){
  330. showError('币别不相同,冲账汇率等于1,不能过账!');
  331. return;
  332. }
  333. }
  334. me.FormUtil.onAudit(Ext.getCmp('bap_id').value);
  335. },
  336. copy: function(){
  337. var me = this;
  338. var form = Ext.getCmp('form');
  339. var v = form.down('#bap_id').value;
  340. if(v > 0) {
  341. form.setLoading(true);
  342. Ext.Ajax.request({
  343. url: basePath + 'fa/gs/copyBillAP.action',
  344. params: {
  345. id: v
  346. },
  347. callback: function(opt, s, r){
  348. form.setLoading(false);
  349. var res = Ext.decode(r.responseText);
  350. if(res.ar) {
  351. turnSuccess(function(){
  352. var id = res.ar.bar_id;
  353. var url = "jsps/fa/gs/billAP.jsp?formCondition=bap_idIS"+ id ;
  354. me.FormUtil.onAdd('billAP' + id, '应付票据' + id, url);
  355. });
  356. } else {
  357. showError(res.exceptionInfo);
  358. }
  359. }
  360. });
  361. }
  362. },
  363. getForm: function(btn){
  364. return btn.ownerCt.ownerCt;
  365. },
  366. gettopaybalance: function(){
  367. if(Ext.isEmpty(Ext.getCmp('bap_paybillcode').value)){
  368. var doublebalance = Ext.Number.from(Ext.getCmp('bap_doublebalance').getValue(), 0);
  369. var cmrate = Ext.Number.from(Ext.getCmp('bap_cmrate').getValue(), 0);
  370. Ext.getCmp('bap_topaybalance').setValue(Ext.Number.toFixed(doublebalance*cmrate, 2));
  371. if (typeof (f = Ext.getCmp('bap_leftamount')) != 'undefined' ) {
  372. var v1 = (Ext.getCmp('bap_settleamount').value || 0);
  373. Ext.getCmp('bap_leftamount').setValue(Ext.Number.toFixed(doublebalance-v1, 2));
  374. }
  375. } else if(!Ext.isEmpty(Ext.getCmp('bap_paybillcode').value)) {
  376. var doublebalance = Ext.Number.from(Ext.getCmp('bap_doublebalance').getValue(), 0);
  377. var topaybalance = Ext.Number.from(Ext.getCmp('bap_topaybalance').getValue(), 0);
  378. Ext.getCmp('bap_cmrate').setValue(Ext.Number.toFixed(topaybalance/doublebalance, 8));
  379. if (typeof (f = Ext.getCmp('bap_leftamount')) != 'undefined' ) {
  380. var v1 = (Ext.getCmp('bap_settleamount').value || 0);
  381. Ext.getCmp('bap_leftamount').setValue(Ext.Number.toFixed(doublebalance-v1, 2));
  382. }
  383. }
  384. }
  385. });