BillAR.js 13 KB

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