BillOutAP.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.arp.BillOutAP', {
  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.BillOutAP','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField','core.form.SeparNumber',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  11. 'core.button.ResSubmit','core.button.Flow','core.trigger.MultiDbfindTrigger','core.button.Post','core.button.ResPost',
  12. 'core.button.PrintVoucherCode', 'core.button.TicketTaxes',
  13. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. // 'erpGridPanel2': {
  19. // itemclick: this.onGridItemClick
  20. // },
  21. 'erpSaveButton': {
  22. click: function(btn){
  23. var form = me.getForm(btn);
  24. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  25. me.BaseUtil.getRandomNumber();//自动添加编号
  26. }
  27. this.getAmount();
  28. this.getTaxamount();
  29. this.FormUtil.beforeSave(this);
  30. }
  31. },
  32. 'field[name=bi_currency]': {
  33. beforetrigger: function(field) {
  34. var t = field.up('form').down('field[name=bi_date]'),
  35. value = t.getValue();
  36. if(value) {
  37. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  38. }
  39. }
  40. },
  41. 'erpDeleteButton' : {
  42. click: function(btn){
  43. me.FormUtil.onDelete(Ext.getCmp('bi_id').value);
  44. }
  45. },
  46. 'erpUpdateButton': {
  47. click: function(btn){
  48. this.getAmount();
  49. this.getTaxamount();
  50. this.FormUtil.onUpdate(this);
  51. }
  52. },
  53. 'erpAddButton': {
  54. click: function(){
  55. me.FormUtil.onAdd('addBillOutAP', '新增应付开票记录', 'jsps/fa/arp/billOutAP.jsp');
  56. }
  57. },
  58. 'erpCloseButton': {
  59. click: function(btn){
  60. me.FormUtil.beforeClose(me);
  61. }
  62. },
  63. 'erpSubmitButton': {
  64. afterrender: function(btn){
  65. var status = Ext.getCmp('bi_statuscode');
  66. if(status && status.value != 'ENTERING'){
  67. btn.hide();
  68. }
  69. },
  70. click: function(btn){
  71. me.beforeSubmit(btn);
  72. }
  73. },
  74. 'erpResSubmitButton': {
  75. afterrender: function(btn){
  76. var status = Ext.getCmp('bi_statuscode');
  77. if(status && status.value != 'COMMITED'){
  78. btn.hide();
  79. }
  80. },
  81. click: function(btn){
  82. me.FormUtil.onResSubmit(Ext.getCmp('bi_id').value);
  83. }
  84. },
  85. 'erpAuditButton': {
  86. afterrender: function(btn){
  87. var status = Ext.getCmp('bi_statuscode');
  88. if(status && status.value != 'COMMITED'){
  89. btn.hide();
  90. }
  91. },
  92. click: function(btn){
  93. me.FormUtil.onAudit(Ext.getCmp('bi_id').value);
  94. }
  95. },
  96. 'erpResAuditButton': {
  97. afterrender: function(btn){
  98. var status = Ext.getCmp('bi_statuscode');
  99. if(status && status.value != 'AUDITED'){
  100. btn.hide();
  101. }
  102. },
  103. click: function(btn){
  104. me.FormUtil.onResAudit(Ext.getCmp('bi_id').value);
  105. }
  106. },
  107. 'erpPostButton': {
  108. afterrender: function(btn){
  109. var status = Ext.getCmp('bi_statuscode');
  110. if(status && status.value != 'COMMITED'){
  111. btn.hide();
  112. }
  113. },
  114. click: function(btn){
  115. me.FormUtil.onPost(Ext.getCmp('bi_id').value);
  116. }
  117. },
  118. 'erpResPostButton': {
  119. afterrender: function(btn){
  120. var status = Ext.getCmp('bi_statuscode');
  121. if(status && status.value != 'POSTED'){
  122. btn.hide();
  123. }
  124. },
  125. click: function(btn){
  126. me.FormUtil.onResPost(Ext.getCmp('bi_id').value);
  127. }
  128. },
  129. 'erpPrintButton': {
  130. click: function(btn){
  131. var reportName = '';
  132. reportName = "billoutap_voice";
  133. var condition = '{billoutap.bi_id}=' + Ext.getCmp('bi_id').value + '';
  134. var id = Ext.getCmp('bi_id').value;
  135. me.FormUtil.onwindowsPrint(id, reportName, condition);
  136. }
  137. },
  138. 'erpPrintVoucherCodeButton': {
  139. click: function(btn){
  140. if(Ext.getCmp('bi_vouchercode').value ==null || Ext.getCmp('bi_vouchercode').value ==''){
  141. showError('当前发票还没有制作凭证,不能打印');
  142. }else{
  143. var reportName = '';
  144. reportName = "billoutap_voice";
  145. var condition = '{billoutap.bi_vouchercode}=\'' + Ext.getCmp('bi_vouchercode').value +'\'';
  146. var id=Ext.getCmp('bi_id').value;
  147. me.FormUtil.onwindowsPrint(id, reportName, condition);
  148. }
  149. }
  150. },
  151. 'erpTicketTaxesButton': {
  152. click: function(btn){
  153. var me = this, win = Ext.getCmp('ticketTaxes-win');
  154. if(!win){
  155. var bi_refno = Ext.getCmp('bi_refno').value, bi_remark = Ext.getCmp('bi_remark').value,
  156. win = Ext.create('Ext.Window', {
  157. id: 'ticketTaxes-win',
  158. title: '更新税票信息',
  159. height: 200,
  160. width: 400,
  161. items: [{
  162. xtype: 'form',
  163. height: '100%',
  164. width: '100%',
  165. bodyStyle: 'background:#f1f2f5;',
  166. items: [{
  167. margin: '10 0 0 0',
  168. xtype: 'textfield',
  169. fieldLabel: '税票编号',
  170. name:'bi_refno',
  171. value: bi_refno
  172. },{
  173. margin: '10 0 0 0',
  174. xtype: 'textfield',
  175. fieldLabel: '备注',
  176. name:'bi_remark',
  177. value: bi_remark
  178. }],
  179. closeAction: 'hide',
  180. buttonAlign: 'center',
  181. layout: {
  182. type: 'vbox',
  183. align: 'center'
  184. },
  185. buttons: [{
  186. text: $I18N.common.button.erpConfirmButton,
  187. cls: 'x-btn-blue',
  188. handler: function(btn) {
  189. var form = btn.ownerCt.ownerCt,
  190. a = form.down('textfield[name=bi_refno]'),
  191. b = form.down('textfield[name=bi_remark]');
  192. if(form.getForm().isDirty()) {
  193. me.updateTaxcode(Ext.getCmp('bi_id').value, a.value, b.value);
  194. }
  195. }
  196. }, {
  197. text: $I18N.common.button.erpCloseButton,
  198. cls: 'x-btn-blue',
  199. handler: function(btn) {
  200. btn.up('window').hide();
  201. }
  202. }]
  203. }]
  204. });
  205. }
  206. win.show();
  207. }
  208. },
  209. 'dbfindtrigger[name=ard_ordercode]': {
  210. focus: function(t){
  211. t.setHideTrigger(false);
  212. t.setReadOnly(false);
  213. if(Ext.getCmp('bi_vendcode')){
  214. var code = Ext.getCmp('bi_vendcode').value;
  215. if(code != null && code != ''){
  216. t.dbBaseCondition = "ab_vendcode" + "='" + code + "'";
  217. }
  218. }
  219. },
  220. aftertrigger: function(t, r) {
  221. if(Ext.getCmp('bi_vendcode')){
  222. var obj = me.getCodeCondition();
  223. if(obj && obj.fields){
  224. me.FormUtil.getFieldsValue(obj.tablename, obj.fields, obj.myfield + "='" + t.value + "'", obj.tFields);
  225. }
  226. }
  227. }
  228. },
  229. 'dbfindtrigger[name=ard_orderdetno]': {
  230. focus: function(t){
  231. t.setHideTrigger(false);
  232. t.setReadOnly(false);//用disable()可以,但enable()无效
  233. var record = Ext.getCmp('grid').selModel.lastSelected;
  234. var code = record.data['ard_ordercode'];
  235. if(code == null || code == ''){
  236. showError("请先选择关联单号!");
  237. t.setHideTrigger(true);
  238. t.setReadOnly(true);
  239. } else {
  240. t.dbBaseCondition = "abd_code='" + code + "'";
  241. }
  242. }
  243. }
  244. });
  245. },
  246. getCodeCondition: function(){
  247. var field = "ab_vendcode";
  248. var tFields = 'bi_vendcode,bi_vendname,bi_currency,bi_rate';
  249. var fields = 'ab_vendcode,ab_vendname,ab_currency,ab_rate';
  250. var tablename = 'APBill';
  251. var myfield = 'ab_code';
  252. var obj = new Object();
  253. obj.field = field;
  254. obj.fields = fields;
  255. obj.tFields = tFields;
  256. obj.tablename = tablename;
  257. obj.myfield = myfield;
  258. return obj;
  259. },
  260. //计算发票金额 并写入主表总额字段
  261. getAmount: function(){
  262. var grid = Ext.getCmp('grid');
  263. var items = grid.store.data.items;
  264. var amount = 0;
  265. Ext.each(items,function(item,index){
  266. if(!Ext.isEmpty(item.data['ard_ordercode'])){
  267. var a = Number(grid.BaseUtil.numberFormat(Number(item.data['ard_nowprice']),8));
  268. var b = Number(grid.BaseUtil.numberFormat(Number(item.data['ard_nowqty']),2));
  269. amount = amount + Number(grid.BaseUtil.numberFormat(a*b,2));
  270. }
  271. });
  272. Ext.getCmp('bi_amount').setValue(Ext.Number.toFixed(amount, 2));
  273. },
  274. //计算税金 然后写入主表税金总计字段
  275. getTaxamount:function(){
  276. var grid = Ext.getCmp('grid');
  277. var items = grid.store.data.items;
  278. var taxsum = 0, differ = Ext.getCmp('bi_taxdiffer');
  279. Ext.each(items,function(item,index){
  280. if(!Ext.isEmpty(item.data['ard_ordercode'])){
  281. var a = Number(grid.BaseUtil.numberFormat(Number(item.data['ard_nowprice']),8));
  282. var b = Number(grid.BaseUtil.numberFormat(Number(item.data['ard_nowqty']),2));
  283. var rate = Number(grid.BaseUtil.numberFormat(Number(item.data['ard_taxrate']),2));
  284. taxsum = taxsum + Number(grid.BaseUtil.numberFormat((a*b*rate/100)/(1+rate/100),2));
  285. }
  286. });
  287. if(differ && !Ext.isEmpty(differ.value)){
  288. // Ext.getCmp('bi_taxamount').setValue(Ext.util.Format.number(taxsum+differ.value, "0.00"));
  289. Ext.getCmp('bi_taxamount').setValue(Ext.Number.toFixed(taxsum+differ.value, 2));
  290. console.log("215A"+Ext.Number.toFixed(taxsum+differ.value, 2));
  291. } else {
  292. // Ext.getCmp('bi_taxamount').setValue(Ext.util.Format.number(taxsum, "0.00"));
  293. Ext.getCmp('bi_taxamount').setValue(Ext.Number.toFixed(taxsum, 2));
  294. console.log("220A"+Ext.Number.toFixed(taxsum, 2));
  295. }
  296. },
  297. beforeSubmit:function(btn){
  298. var me = this;
  299. var grid = Ext.getCmp('grid'),items=grid.store.data.items;
  300. var amount = Number(Ext.getCmp('bi_amount').getValue());
  301. var detailamount = 0;
  302. // Ext.each(items,function(item,index){
  303. // if(Ext.Number.toFixed(item.data['ard_nowqty'], 2) > Ext.Number.toFixed(item.data['ard_qty'], 2)){
  304. // //抛出异常
  305. // showError('明细开票数量大于发票数量,不能提交');return;
  306. // }
  307. // detailamount = detailamount+Number(item.data['ard_nowbalance']);
  308. // if(Ext.Number.toFixed(amount, 2) != Ext.Number.toFixed(detailamount, 2)){
  309. // //抛出异常
  310. // showError('明细开票方金额与开票总额不等,不能提交');return;
  311. // }
  312. // });
  313. me.FormUtil.onSubmit(Ext.getCmp('bi_id').value);
  314. },
  315. onGridItemClick: function(selModel, record){//grid行选择
  316. this.GridUtil.onGridItemClick(selModel, record);
  317. },
  318. getForm: function(btn){
  319. return btn.ownerCt.ownerCt;
  320. },
  321. updateTaxcode: function(biid, val1, val2) {
  322. var me = this;
  323. Ext.Ajax.request({
  324. url: basePath + 'fa/arp/updateBillOutTaxcode.action',
  325. params: {
  326. caller: caller,
  327. bi_id: biid,
  328. bi_refno: val1,
  329. bi_remark: val2
  330. },
  331. callback: function(opt, s, r) {
  332. var rs = Ext.decode(r.responseText);
  333. if(rs.exceptionInfo) {
  334. showError(rs.exceptionInfo);
  335. } else {
  336. alert('更新成功!');
  337. window.location.reload();
  338. }
  339. }
  340. });
  341. }
  342. });