Packing.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.reserve.Packing', {
  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.Packing','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',
  11. 'core.button.ResSubmit','core.button.CatchMadeIn','core.button.PrintByCondition',
  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.FormUtil.beforeSave(this);
  27. }
  28. },
  29. 'field[name=pi_currency]': {
  30. beforetrigger: function(field) {
  31. var t = field.up('form').down('field[name=pi_date]'),
  32. value = t.getValue();
  33. if(value) {
  34. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  35. }
  36. }
  37. },
  38. 'erpDeleteButton' : {
  39. afterrender: function(btn){
  40. var status = Ext.getCmp('pi_statuscode');
  41. if(status && status.value != 'ENTERING'){
  42. btn.hide();
  43. }
  44. },
  45. click: function(btn){
  46. me.FormUtil.onDelete(Ext.getCmp('pi_id').value);
  47. }
  48. },
  49. 'erpUpdateButton': {
  50. afterrender: function(btn){
  51. var status = Ext.getCmp('pi_statuscode');
  52. if(status && status.value != 'ENTERING'){
  53. btn.hide();
  54. }
  55. },
  56. click: function(btn){
  57. this.FormUtil.onUpdate(this);
  58. }
  59. },
  60. 'erpAddButton': {
  61. click: function(){
  62. me.FormUtil.onAdd('addPacking', '新增包装单', 'jsps/scm/reserve/packing.jsp');
  63. }
  64. },
  65. 'erpCloseButton': {
  66. click: function(btn){
  67. me.FormUtil.beforeClose(me);
  68. }
  69. },
  70. 'erpSubmitButton': {
  71. afterrender: function(btn){
  72. var status = Ext.getCmp('pi_statuscode');
  73. if(status && status.value != 'ENTERING'){
  74. btn.hide();
  75. }
  76. },
  77. click: function(btn){
  78. me.FormUtil.onSubmit(Ext.getCmp('pi_id').value);
  79. }
  80. },
  81. 'erpResSubmitButton': {
  82. afterrender: function(btn){
  83. var status = Ext.getCmp('pi_statuscode');
  84. if(status && status.value != 'COMMITED'){
  85. btn.hide();
  86. }
  87. },
  88. click: function(btn){
  89. me.FormUtil.onResSubmit(Ext.getCmp('pi_id').value);
  90. }
  91. },
  92. 'erpAuditButton': {
  93. afterrender: function(btn){
  94. var status = Ext.getCmp('pi_statuscode');
  95. if(status && status.value != 'COMMITED'){
  96. btn.hide();
  97. }
  98. },
  99. click: function(btn){
  100. me.FormUtil.onAudit(Ext.getCmp('pi_id').value);
  101. }
  102. },
  103. 'erpResAuditButton': {
  104. afterrender: function(btn){
  105. var status = Ext.getCmp('pi_statuscode');
  106. if(status && status.value != 'AUDITED'){
  107. btn.hide();
  108. }
  109. },
  110. click: function(btn){
  111. me.FormUtil.onResAudit(Ext.getCmp('pi_id').value);
  112. }
  113. },
  114. 'erpPrintButton': {
  115. click: function(btn){
  116. var reportName='';
  117. reportName="PIOPackinglist";
  118. var condition='{Packing.pi_id}='+Ext.getCmp('pi_id').value+'';
  119. var id=Ext.getCmp('pi_id').value;
  120. me.FormUtil.onwindowsPrint(id,reportName,condition);
  121. }
  122. },
  123. 'erpCatchMadeInButton' : {
  124. afterrender: function(btn){
  125. var status = Ext.getCmp('pi_statuscode');
  126. if(status && status.value != 'ENTERING'){
  127. btn.hide();
  128. }
  129. },
  130. click: function(btn){
  131. var form = btn.ownerCt.ownerCt,
  132. pi_id = Ext.getCmp('pi_id').value;
  133. form.setLoading(true);
  134. Ext.Ajax.request({
  135. url: basePath + 'scm/reserve/updateMadeIn.action',
  136. params: {
  137. pi_id: pi_id
  138. },
  139. callback: function(opt, s, r) {
  140. form.setLoading(false);
  141. var rs = Ext.decode(r.responseText);
  142. if(rs.success) {
  143. alert('更新成功!');
  144. me.GridUtil.loadNewStore(form.ownerCt.down('grid'), {caller: caller, condition: 'pd_piid=' + pi_id});
  145. }
  146. }
  147. });
  148. }
  149. },
  150. 'dbfindtrigger[name=pd_ordercode]': {
  151. focus: function(t){
  152. t.setHideTrigger(false);
  153. t.setReadOnly(false);
  154. if(Ext.getCmp('pi_custcode')){
  155. var code = Ext.getCmp('pi_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('pi_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. 'field[name=pi_code]': {
  174. afterrender:function(f){
  175. f.setFieldStyle({
  176. 'color': 'blue'
  177. });
  178. f.focusCls = 'mail-attach';
  179. var c = Ext.Function.bind(me.openInvoice, me);
  180. Ext.EventManager.on(f.inputEl, {
  181. mousedown : c,
  182. scope: f,
  183. buffer : 100
  184. });
  185. }
  186. },
  187. 'field[name=pi_relativecode]': {
  188. afterrender:function(f){
  189. f.setFieldStyle({
  190. 'color': 'blue'
  191. });
  192. f.focusCls = 'mail-attach';
  193. var c = Ext.Function.bind(me.openRelative, me);
  194. Ext.EventManager.on(f.inputEl, {
  195. mousedown : c,
  196. scope: f,
  197. buffer : 100
  198. });
  199. }
  200. },
  201. 'dbfindtrigger[name=pd_orderdetno]': {
  202. focus: function(t){
  203. t.setHideTrigger(false);
  204. t.setReadOnly(false);//用disable()可以,但enable()无效
  205. var record = Ext.getCmp('grid').selModel.lastSelected;
  206. var code = record.data['pd_ordercode'];
  207. if(code == null || code == ''){
  208. showError("请先选择关联单号!");
  209. t.setHideTrigger(true);
  210. t.setReadOnly(true);
  211. } else {
  212. t.dbBaseCondition = "sd_code='" + code + "'";
  213. }
  214. }
  215. },
  216. 'dbfindtrigger[name=pi_custcode2]': {
  217. afterrender:function(trigger){
  218. trigger.dbKey='pi_custcode';
  219. trigger.mappingKey='cu_code';
  220. trigger.dbMessage='请先选客户编号!';
  221. }
  222. },
  223. 'dbfindtrigger[name=pi_invoiceremark]': {
  224. afterrender:function(trigger){
  225. trigger.dbKey='pi_custcode';
  226. trigger.mappingKey='cu_code';
  227. trigger.dbMessage='请先选客户编号!';
  228. }
  229. },
  230. 'dbfindtrigger[name=pi_packingremark]': {
  231. afterrender:function(trigger){
  232. trigger.dbKey='pi_custcode';
  233. trigger.mappingKey='cu_code';
  234. trigger.dbMessage='请先选客户编号!';
  235. }
  236. },
  237. 'dbfindtrigger[name=pi_receivecode]': {
  238. afterrender:function(trigger){
  239. trigger.dbKey='pi_custcode';
  240. trigger.mappingKey='cu_code';
  241. trigger.dbMessage='请先选客户编号!';
  242. }
  243. }
  244. });
  245. },
  246. onGridItemClick: function(selModel, record){//grid行选择
  247. this.GridUtil.onGridItemClick(selModel, record);
  248. },
  249. getForm: function(btn){
  250. return btn.ownerCt.ownerCt;
  251. },
  252. getCodeCondition: function(){
  253. var field = null;
  254. var fields = '';
  255. var tablename = '';
  256. var myfield = '';
  257. var tFields = '';
  258. tFields = 'pi_custcode,pi_custname,pi_currency,pi_rate,pi_paymentcode,pi_payment,pi_sellercode,pi_seller,pi_address';
  259. fields = 'sa_custcode,sa_custname,sa_currency,sa_rate,sa_paymentscode,sa_payments,sa_sellercode,sa_seller,sa_toplace';
  260. tablename = 'Sale';
  261. myfield = 'sa_code';
  262. field = "sa_custcode";
  263. var obj = new Object();
  264. obj.field = field;
  265. obj.fields = fields;
  266. obj.tFields = tFields;
  267. obj.tablename = tablename;
  268. obj.myfield = myfield;
  269. return obj;
  270. },
  271. openInvoice: function(e, el, obj) {
  272. var f = obj.scope, form = f.ownerCt,
  273. i = form.down('#in_id');
  274. if(i && i.value) {
  275. url = 'jsps/scm/reserve/invoice.jsp?formCondition=in_idIS' + i.value + '&gridCondition=id_inidIS' + i.value;
  276. openUrl(url);
  277. }
  278. },
  279. openRelative: function(e, el, obj) {
  280. var f = obj.scope;
  281. if(f.value) {
  282. this.FormUtil.onAdd('ProdInOut', f.ownerCt.down('#pi_source').value,
  283. this.getRelativeUrl(f));
  284. }
  285. },
  286. getRelativeUrl: function(f) {
  287. var v = f.value, form = f.ownerCt,
  288. s = form.down('#pi_source'),
  289. cal = this.getRelativeCaller(s.value),
  290. u = '';
  291. if(!Ext.isEmpty(v)) {
  292. if(v.indexOf(',') > 0) {
  293. var _v = v.split(',');
  294. for(var i in _v) {
  295. _v[i] = "'" + _v[i] + "'";
  296. }
  297. var id = this.getRelativeId(_v.join(','), s.value);
  298. u = 'jsps/common/datalist.jsp?whoami=' + cal + '&urlcondition=pi_class=\''
  299. + s.value + '\' and pi_id in(' + id + ')';
  300. } else {
  301. var id = this.getRelativeId('\'' + v + '\'', s.value);
  302. u = 'jsps/scm/reserve/prodInOut.jsp?whoami=' + cal + '&formCondition=pi_idIS' +
  303. id + '&gridCondition=pd_piidIS' + id;
  304. }
  305. }
  306. return u;
  307. },
  308. getRelativeId: function(c, s) {
  309. var id = 0;
  310. Ext.Ajax.request({
  311. url : basePath + 'common/getFieldData.action',
  312. async: false,
  313. params: {
  314. caller: 'ProdInOut',
  315. field: 'wmsys.wm_concat(pi_id)',
  316. condition: 'pi_inoutno in(' + c + ') and pi_class=\'' + s + '\''
  317. },
  318. method : 'post',
  319. callback : function(o, s, r){
  320. var rs = new Ext.decode(r.responseText);
  321. if(rs.exceptionInfo){
  322. showError(rs.exceptionInfo);return;
  323. }
  324. if(rs.success){
  325. if(rs.data != null){
  326. id = rs.data;
  327. }
  328. }
  329. }
  330. });
  331. return id;
  332. },
  333. getRelativeCaller: function(v) {
  334. var c = '';
  335. switch (v) {
  336. case '出货单':
  337. c = 'ProdInOut!Sale';break;
  338. case '销售退货单':
  339. c = 'ProdInOut!SaleReturn';break;
  340. }
  341. return c;
  342. }
  343. });