BillOut.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.BillOut', {
  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.ars.BillOut','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  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.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. // 'erpGridPanel2': {
  18. // itemclick: this.onGridItemClick
  19. // },
  20. 'erpSaveButton': {
  21. click: function(btn){
  22. var form = me.getForm(btn);
  23. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  24. me.BaseUtil.getRandomNumber();//自动添加编号
  25. }
  26. this.getAmount();
  27. this.FormUtil.beforeSave(this);
  28. }
  29. },
  30. 'erpDeleteButton' : {
  31. click: function(btn){
  32. me.FormUtil.onDelete(Ext.getCmp('bi_id').value);
  33. }
  34. },
  35. 'erpUpdateButton': {
  36. click: function(btn){
  37. this.getAmount();
  38. this.FormUtil.onUpdate(this);
  39. }
  40. },
  41. 'erpAddButton': {
  42. click: function(){
  43. me.FormUtil.onAdd('addBillOut', '新增应收开票记录', 'jsps/fa/ars/billOut.jsp');
  44. }
  45. },
  46. 'erpCloseButton': {
  47. click: function(btn){
  48. me.FormUtil.beforeClose(me);
  49. }
  50. },
  51. 'erpSubmitButton': {
  52. afterrender: function(btn){
  53. var status = Ext.getCmp('bi_statuscode');
  54. if(status && status.value != 'ENTERING'){
  55. btn.hide();
  56. }
  57. },
  58. click: function(btn){
  59. me.beforeSubmit(btn);
  60. }
  61. },
  62. 'erpResSubmitButton': {
  63. afterrender: function(btn){
  64. var status = Ext.getCmp('bi_statuscode');
  65. if(status && status.value != 'COMMITED'){
  66. btn.hide();
  67. }
  68. },
  69. click: function(btn){
  70. me.FormUtil.onResSubmit(Ext.getCmp('bi_id').value);
  71. }
  72. },
  73. 'erpAuditButton': {
  74. afterrender: function(btn){
  75. var status = Ext.getCmp('bi_statuscode');
  76. if(status && status.value != 'COMMITED'){
  77. btn.hide();
  78. }
  79. },
  80. click: function(btn){
  81. me.FormUtil.onAudit(Ext.getCmp('bi_id').value);
  82. }
  83. },
  84. 'erpResAuditButton': {
  85. afterrender: function(btn){
  86. var status = Ext.getCmp('bi_statuscode');
  87. if(status && status.value != 'AUDITED'){
  88. btn.hide();
  89. }
  90. },
  91. click: function(btn){
  92. me.FormUtil.onResAudit(Ext.getCmp('bi_id').value);
  93. }
  94. },
  95. 'erpPostButton': {
  96. // afterrender: function(btn){
  97. // var status = Ext.getCmp('bi_statuscode');
  98. // if(status && status.value != 'AUDITED'){
  99. // btn.hide();
  100. // }
  101. // },
  102. click: function(btn){
  103. me.FormUtil.onPost(Ext.getCmp('bi_id').value);
  104. }
  105. },
  106. 'erpResPostButton': {
  107. // afterrender: function(btn){
  108. // var status = Ext.getCmp('bi_statuscode');
  109. // if(status && status.value != 'POSTED'){
  110. // btn.hide();
  111. // }
  112. // },
  113. click: function(btn){
  114. me.FormUtil.onResPost(Ext.getCmp('bi_id').value);
  115. }
  116. },
  117. 'erpPrintButton': {
  118. click: function(btn){
  119. var reportName = '';
  120. reportName = "billout_voice";
  121. var condition = '{billout.bi_id}=' + Ext.getCmp('bi_id').value + '';
  122. var id = Ext.getCmp('bi_id').value;
  123. me.FormUtil.onwindowsPrint(id, reportName, condition);
  124. }
  125. },
  126. 'dbfindtrigger[name=ard_ordercode]': {
  127. focus: function(t){
  128. t.setHideTrigger(false);
  129. t.setReadOnly(false);
  130. if(Ext.getCmp('bi_custcode')){
  131. var code = Ext.getCmp('bi_custcode').value;
  132. if(code != null && code != ''){
  133. t.dbBaseCondition = "ab_custcode" + "='" + code + "'";
  134. }
  135. }
  136. },
  137. aftertrigger: function(t, r) {
  138. if(Ext.getCmp('bi_custcode')){
  139. var obj = me.getCodeCondition();
  140. if(obj && obj.fields){
  141. me.FormUtil.getFieldsValue(obj.tablename, obj.fields, obj.myfield + "='" + t.value + "'", obj.tFields);
  142. }
  143. }
  144. }
  145. },
  146. 'dbfindtrigger[name=ard_orderdetno]': {
  147. focus: function(t){
  148. t.setHideTrigger(false);
  149. t.setReadOnly(false);//用disable()可以,但enable()无效
  150. var record = Ext.getCmp('grid').selModel.lastSelected;
  151. var code = record.data['ard_ordercode'];
  152. if(code == null || code == ''){
  153. showError("请先选择关联单号!");
  154. t.setHideTrigger(true);
  155. t.setReadOnly(true);
  156. } else {
  157. t.dbBaseCondition = "abd_code='" + code + "'";
  158. }
  159. }
  160. }
  161. });
  162. },
  163. //计算发票金额 并写入主表总额字段
  164. getAmount: function(){
  165. var grid = Ext.getCmp('grid');
  166. var items = grid.store.data.items;
  167. var amount = 0;
  168. Ext.each(items,function(item,index){
  169. if(item.data['ard_ordercode']!=null&&item.data['ard_ordercode']!=""){
  170. amount= amount + Number(item.data['ard_nowbalance']);
  171. }
  172. });
  173. Ext.getCmp('bi_amount').setValue(Ext.Number.toFixed(amount, 2));
  174. },
  175. beforeSubmit:function(btn){
  176. var me = this;
  177. var grid = Ext.getCmp('grid'),items=grid.store.data.items;
  178. var amount = Number(Ext.getCmp('bi_amount').getValue());
  179. var detailamount = 0;
  180. // Ext.each(items,function(item,index){
  181. // if(Ext.Number.toFixed(item.data['ard_nowqty'], 2) > Ext.Number.toFixed(item.data['ard_qty'], 2)){
  182. // //抛出异常
  183. // showError('明细开票数量大于发票数量,不能提交');return;
  184. // }
  185. // detailamount = detailamount+Number(item.data['ard_nowbalance']);
  186. // if(Ext.Number.toFixed(amount, 2) != Ext.Number.toFixed(detailamount, 2)){
  187. // //抛出异常
  188. // showError('明细开票方金额与开票总额不等,不能提交');return;
  189. // }
  190. // });
  191. me.FormUtil.onSubmit(Ext.getCmp('bi_id').value);
  192. },
  193. getCodeCondition: function(){
  194. var field = "ab_custcode";
  195. var tFields = 'bi_custcode,bi_custname,bi_currency,bi_rate,bi_seller';
  196. var fields = 'ab_custcode,ab_custname,ab_currency,ab_rate,ab_seller';
  197. var tablename = 'ARBill';
  198. var myfield = 'ab_code';
  199. var obj = new Object();
  200. obj.field = field;
  201. obj.fields = fields;
  202. obj.tFields = tFields;
  203. obj.tablename = tablename;
  204. obj.myfield = myfield;
  205. return obj;
  206. },
  207. onGridItemClick: function(selModel, record){//grid行选择
  208. this.GridUtil.onGridItemClick(selModel, record);
  209. },
  210. getForm: function(btn){
  211. return btn.ownerCt.ownerCt;
  212. }
  213. });