Invoice.js 9.4 KB

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