Invoice.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.reserve.Invoice', {
  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','scm.reserve.Invoice','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit',
  11. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.PrintDelivery'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. 'erpGridPanel2': {
  17. itemclick: this.onGridItemClick
  18. },
  19. 'erpSaveButton': {
  20. click: function(btn){
  21. var form = me.getForm(btn);
  22. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  23. me.BaseUtil.getRandomNumber();//自动添加编号
  24. }
  25. this.FormUtil.beforeSave(this);
  26. }
  27. },
  28. 'erpDeleteButton' : {
  29. afterrender: function(btn){
  30. var status = Ext.getCmp('in_statuscode');
  31. if(status && status.value != 'ENTERING'){
  32. btn.hide();
  33. }
  34. },
  35. click: function(btn){
  36. me.FormUtil.onDelete(Ext.getCmp('in_id').value);
  37. }
  38. },
  39. 'erpUpdateButton': {
  40. afterrender: function(btn){
  41. var status = Ext.getCmp('in_statuscode');
  42. if(status && status.value != 'ENTERING'){
  43. btn.hide();
  44. }
  45. },
  46. click: function(btn){
  47. this.FormUtil.onUpdate(this);
  48. }
  49. },
  50. 'erpAddButton': {
  51. click: function(){
  52. me.FormUtil.onAdd('addInvoice', '新增发票', 'jsps/scm/reserve/invoice.jsp');
  53. }
  54. },
  55. 'erpCloseButton': {
  56. click: function(btn){
  57. me.FormUtil.beforeClose(me);
  58. }
  59. },
  60. 'erpSubmitButton': {
  61. afterrender: function(btn){
  62. var status = Ext.getCmp('in_statuscode');
  63. if(status && status.value != 'ENTERING'){
  64. btn.hide();
  65. }
  66. },
  67. click: function(btn){
  68. me.FormUtil.onSubmit(Ext.getCmp('in_id').value);
  69. }
  70. },
  71. 'erpResSubmitButton': {
  72. afterrender: function(btn){
  73. var status = Ext.getCmp('in_statuscode');
  74. if(status && status.value != 'COMMITED'){
  75. btn.hide();
  76. }
  77. },
  78. click: function(btn){
  79. me.FormUtil.onResSubmit(Ext.getCmp('in_id').value);
  80. }
  81. },
  82. 'erpAuditButton': {
  83. afterrender: function(btn){
  84. var status = Ext.getCmp('in_statuscode');
  85. if(status && status.value != 'COMMITED'){
  86. btn.hide();
  87. }
  88. },
  89. click: function(btn){
  90. me.FormUtil.onAudit(Ext.getCmp('in_id').value);
  91. }
  92. },
  93. 'erpResAuditButton': {
  94. afterrender: function(btn){
  95. var status = Ext.getCmp('in_statuscode');
  96. if(status && status.value != 'AUDITED'){
  97. btn.hide();
  98. }
  99. },
  100. click: function(btn){
  101. me.FormUtil.onResAudit(Ext.getCmp('in_id').value);
  102. }
  103. },
  104. 'erpPrintButton': {
  105. click: function(btn){
  106. var reportName='';
  107. reportName="PIOSaleInvoice";
  108. var condition='{Invoice.in_id}='+Ext.getCmp('in_id').value;
  109. var id=Ext.getCmp('in_id').value;
  110. me.FormUtil.onwindowsPrint(id,reportName,condition);
  111. }
  112. },
  113. 'erpPrintDeliveryButton': {
  114. click: function(btn){
  115. var reportName='';
  116. reportName="PIOSendList";
  117. var condition='{Invoice.in_id}='+Ext.getCmp('in_id').value;
  118. var id=Ext.getCmp('in_id').value;
  119. me.FormUtil.onwindowsPrint(id,reportName,condition);
  120. }
  121. },
  122. 'field[name=in_code]':{
  123. afterrender:function(f){
  124. f.setFieldStyle({
  125. 'color': 'blue'
  126. });
  127. f.focusCls = 'mail-attach';
  128. var c = Ext.Function.bind(me.openPacking, me);
  129. Ext.EventManager.on(f.inputEl, {
  130. mousedown : c,
  131. scope: f,
  132. buffer : 100
  133. });
  134. }
  135. },
  136. 'field[name=in_relativecode]': {
  137. afterrender:function(f){
  138. f.setFieldStyle({
  139. 'color': 'blue'
  140. });
  141. f.focusCls = 'mail-attach';
  142. var c = Ext.Function.bind(me.openRelative, me);
  143. Ext.EventManager.on(f.inputEl, {
  144. mousedown : c,
  145. scope: f,
  146. buffer : 100
  147. });
  148. }
  149. },
  150. 'dbfindtrigger[name=id_ordercode]': {
  151. focus: function(t){
  152. t.setHideTrigger(false);
  153. t.setReadOnly(false);
  154. if(Ext.getCmp('in_custcode')){
  155. var code = Ext.getCmp('in_custcode').value;
  156. if(code != null && code != ''){
  157. var obj = me.getCodeCondition();
  158. if(obj && obj.field){
  159. t.dbBaseCondition = obj.field + "='" + code + "'";
  160. }
  161. }
  162. }
  163. },
  164. aftertrigger: function(t){
  165. if(Ext.getCmp('in_custcode')){
  166. var obj = me.getCodeCondition();
  167. if(obj && obj.fields){
  168. me.FormUtil.getFieldsValue(obj.tablename, obj.fields, obj.myfield + "='" + t.value + "'", obj.tFields);
  169. }
  170. }
  171. }
  172. },
  173. 'dbfindtrigger[name=id_orderdetno]': {
  174. focus: function(t){
  175. t.setHideTrigger(false);
  176. t.setReadOnly(false);//用disable()可以,但enable()无效
  177. var record = Ext.getCmp('grid').selModel.lastSelected;
  178. var code = record.data['id_ordercode'];
  179. if(code == null || code == ''){
  180. showError("请先选择关联单号!");
  181. t.setHideTrigger(true);
  182. t.setReadOnly(true);
  183. } else {
  184. t.dbBaseCondition = "sd_code='" + code + "'";
  185. }
  186. }
  187. },'dbfindtrigger[name=in_custcode2]': {
  188. afterrender:function(trigger){
  189. trigger.dbKey='in_custcode';
  190. trigger.mappingKey='cu_code';
  191. trigger.dbMessage='请先选客户编号!';
  192. }
  193. },
  194. 'dbfindtrigger[name=in_invoiceremark]': {
  195. afterrender:function(trigger){
  196. trigger.dbKey='in_custcode';
  197. trigger.mappingKey='cu_code';
  198. trigger.dbMessage='请先选客户编号!';
  199. }
  200. },
  201. 'dbfindtrigger[name=in_packingremark]': {
  202. afterrender:function(trigger){
  203. trigger.dbKey='in_custcode';
  204. trigger.mappingKey='cu_code';
  205. trigger.dbMessage='请先选客户编号!';
  206. }
  207. },
  208. 'dbfindtrigger[name=in_receivecode]': {
  209. afterrender:function(trigger){
  210. trigger.dbKey='in_custcode';
  211. trigger.mappingKey='cu_code';
  212. trigger.dbMessage='请先选客户编号!';
  213. }
  214. }
  215. });
  216. },
  217. onGridItemClick: function(selModel, record){//grid行选择
  218. this.GridUtil.onGridItemClick(selModel, record);
  219. },
  220. getForm: function(btn){
  221. return btn.ownerCt.ownerCt;
  222. },
  223. getCodeCondition: function(){
  224. var field = null;
  225. var fields = '';
  226. var tablename = '';
  227. var myfield = '';
  228. var tFields = '';
  229. tFields = 'in_custcode,in_custname,in_currency,in_rate,in_paymentcode,in_payment,in_sellercode,em_name,in_address';
  230. fields = 'sa_custcode,sa_custname,sa_currency,sa_rate,sa_paymentscode,sa_payments,sa_sellercode,sa_seller,sa_toplace';
  231. tablename = 'Sale';
  232. myfield = 'sa_code';
  233. field = "sa_custcode";
  234. var obj = new Object();
  235. obj.field = field;
  236. obj.fields = fields;
  237. obj.tFields = tFields;
  238. obj.tablename = tablename;
  239. obj.myfield = myfield;
  240. return obj;
  241. },
  242. openPacking : function(e, el, obj) {
  243. var f = obj.scope, form = f.ownerCt,
  244. i = form.down('#pi_id');
  245. if(i && i.value) {
  246. url = 'jsps/scm/reserve/packing.jsp?formCondition=pi_idIS' + i.value + '&gridCondition=pd_piidIS' + i.value;
  247. openUrl(url);
  248. }
  249. },
  250. openRelative: function(e, el, obj) {
  251. var f = obj.scope;
  252. if(f.value) {
  253. this.FormUtil.onAdd('ProdInOut', f.ownerCt.down('#in_source').value,
  254. this.getRelativeUrl(f));
  255. }
  256. },
  257. getRelativeUrl: function(f) {
  258. var v = f.value, form = f.ownerCt,
  259. s = form.down('#in_source'),
  260. cal = this.getRelativeCaller(s.value),
  261. u = '';
  262. if(!Ext.isEmpty(v)) {
  263. if(v.indexOf(',') > 0) {
  264. var _v = v.split(',');
  265. for(var i in _v) {
  266. _v[i] = "'" + _v[i] + "'";
  267. }
  268. var id = this.getRelativeId(_v.join(','), s.value);
  269. u = 'jsps/common/datalist.jsp?whoami=' + cal + '&urlcondition=pi_class=\''
  270. + s.value + '\' and pi_id in(' + id + ')';
  271. } else {
  272. var id = this.getRelativeId('\'' + v + '\'', s.value);
  273. u = 'jsps/scm/reserve/prodInOut.jsp?whoami=' + cal + '&formCondition=pi_idIS' +
  274. id + '&gridCondition=pd_piidIS' + id;
  275. }
  276. }
  277. return u;
  278. },
  279. getRelativeId: function(c, s) {
  280. var id = 0;
  281. Ext.Ajax.request({
  282. url : basePath + 'common/getFieldData.action',
  283. async: false,
  284. params: {
  285. caller: 'ProdInOut',
  286. field: 'wmsys.wm_concat(pi_id)',
  287. condition: 'pi_inoutno in(' + c + ') and pi_class=\'' + s + '\''
  288. },
  289. method : 'post',
  290. callback : function(o, s, r){
  291. var rs = new Ext.decode(r.responseText);
  292. if(rs.exceptionInfo){
  293. showError(rs.exceptionInfo);return;
  294. }
  295. if(rs.success){
  296. if(rs.data != null){
  297. id = rs.data;
  298. }
  299. }
  300. }
  301. });
  302. return id;
  303. },
  304. getRelativeCaller: function(v) {
  305. var c = '';
  306. switch (v) {
  307. case '出货单':
  308. c = 'ProdInOut!Sale';break;
  309. case '销售退货单':
  310. c = 'ProdInOut!SaleReturn';break;
  311. }
  312. return c;
  313. }
  314. });