MakeBase.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakeBase', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'core.form.Panel','pm.make.MakeBase','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField','core.form.YnField',
  7. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.PrintA4','core.button.Upload','core.button.ResAudit',
  8. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit',
  9. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.grid.YnColumn','core.button.Flow','core.button.Get',
  10. 'core.button.GetMaterial','core.button.DeleteMaterial','core.button.ChangeMaterial','core.button.GetCraft','core.button.HistoryProdIO',
  11. 'core.button.RefreshQty','core.button.MakeFlow','core.trigger.MultiDbfindTrigger','core.button.EnforceEnd',
  12. 'core.button.CalMake','core.button.Check','core.button.ResCheck', 'core.button.End', 'core.button.ResEnd','core.button.ModifyMaterial',
  13. 'core.button.SubRelation','core.button.TurnOSMake','core.button.GetOSVendor','core.button.UpdateRemark',
  14. 'core.button.UpdateTeamcode','core.button.GetPrice','core.button.OSInfoUpdate','core.button.UpdateMaterialWH',
  15. 'core.button.TurnOSToMake','core.button.BomUseMatch','erp.view.core.grid.HeaderFilter','core.button.UpdateMaStyle',
  16. 'core.button.ShiPAddressUpdate','core.button.MrpOpen','core.button.MrpClose'
  17. ],
  18. init:function(){
  19. var me = this;
  20. me.FormUtil = Ext.create('erp.util.FormUtil');
  21. me.GridUtil = Ext.create('erp.util.GridUtil');
  22. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  23. this.control({
  24. '#ma_remark':{
  25. beforerender: function(field){
  26. field.readOnly=false;
  27. }
  28. },
  29. '#ma_teamcode':{
  30. beforerender: function(field){
  31. field.readOnly=false;
  32. }
  33. },
  34. '#ma_style':{
  35. beforerender: function(field){
  36. field.readOnly=false;
  37. }
  38. },
  39. 'erpGridPanel2': {
  40. afterrender: function(grid){
  41. var status = Ext.getCmp('ma_statuscode');
  42. if(status && status.value != 'ENTERING' ){
  43. grid.setReadOnly(true);
  44. }
  45. },
  46. reconfigure:function(grid){
  47. var items = grid.store.data.items;
  48. var totaluseqty = grid.store.getSum(items, 'mm_totaluseqty');
  49. var havegetqty = grid.store.getSum(items, 'mm_havegetqty');
  50. if( totaluseqty!=0 || havegetqty!=0){
  51. /*Ext.getCmp('resAudit').hide();
  52. Ext.getCmp('resCheck').hide();*/
  53. }
  54. },
  55. itemclick: function(view,record){
  56. me.itemclick(view,record,me);
  57. }
  58. },
  59. 'field[name=ma_currency]': {
  60. beforetrigger: function(field) {
  61. var value = Ext.getCmp('ma_date').value;
  62. if(value) {
  63. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  64. }
  65. }
  66. },
  67. 'field[name=ma_tasktype]': {
  68. afterrender:function(field){
  69. if (field.value=='OS' && caller=='Make!Base'){
  70. window.location.href=window.location.href.replace('whoami=Make!Base','whoami=Make');
  71. }
  72. }
  73. },
  74. 'erpBomUseMatchButton':{
  75. afterrender:function(btn){
  76. btn.setDisabled(true);
  77. }
  78. },
  79. 'erpMakeFlowButton':{
  80. click: function(btn){
  81. var id=Ext.getCmp('ma_id').value;
  82. var formCondition="ma_idIS"+id;
  83. var gridCondition = "mf_maid="+Ext.getCmp('ma_id').value;
  84. var linkCaller='MakeFlow';
  85. var win = new Ext.window.Window(
  86. {
  87. id : 'win',
  88. height : '90%',
  89. width : '95%',
  90. maximizable : true,
  91. buttonAlign : 'center',
  92. layout : 'anchor',
  93. items : [ {
  94. tag : 'iframe',
  95. frame : true,
  96. anchor : '100% 100%',
  97. layout : 'fit',
  98. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/pm/make/makeflow.jsp?_noc=1&whoami='+linkCaller+'&gridCondition='+gridCondition+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  99. } ]
  100. });
  101. win.show();
  102. }
  103. },
  104. 'erpSaveButton': {
  105. click: function(btn){
  106. var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField);
  107. if(codeField.value == null || codeField.value == ''){
  108. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  109. var res = me.getLeadCode(Ext.getCmp('ma_kind').value);
  110. if(res != null && res != ''){
  111. codeField.setValue(res + codeField.getValue());
  112. }
  113. }
  114. this.FormUtil.beforeSave(this);
  115. }
  116. },
  117. 'erpCloseButton': {
  118. click: function(btn){
  119. this.FormUtil.beforeClose(this);
  120. }
  121. },
  122. 'erpDeleteDetailButton': {
  123. afterrender: function(btn){
  124. btn.ownerCt.add({
  125. xtype: 'erpSubRelationButton'
  126. });
  127. btn.ownerCt.add({
  128. xtype: 'erpModifyMaterialButton'
  129. });
  130. btn.ownerCt.add({
  131. xtype: 'erpMrpOpenButton'
  132. });
  133. btn.ownerCt.add({
  134. xtype: 'erpMrpCloseButton'
  135. });
  136. }
  137. },
  138. 'erpUpdateButton': {
  139. afterrender: function(btn){
  140. var status = Ext.getCmp('ma_statuscode');
  141. if(status && status.value != 'ENTERING' ){
  142. btn.hide();
  143. }
  144. },
  145. click: function(btn){
  146. var oldmaqty=0;
  147. if (Ext.getCmp('ma_id').value>0){
  148. oldmaqty=me.getFdValue('make','ma_qty','ma_id='+Ext.getCmp('ma_id').value);
  149. }
  150. this.FormUtil.onUpdate(this);
  151. if (oldmaqty-Ext.getCmp('ma_qty').value!=0){
  152. alert('工单需求数量已经被修改,请重新计算用料!');
  153. }
  154. }
  155. },
  156. 'erpDeleteButton': {
  157. click: function(btn){
  158. me.FormUtil.onDelete(Ext.getCmp('ma_id').value);
  159. }
  160. },
  161. 'erpAddButton': {
  162. click: function(){
  163. me.FormUtil.onAdd('addMakeBase', '新增单据', 'jsps/pm/make/makeBase.jsp?whoami=' + caller);
  164. }
  165. },
  166. 'erpSubmitButton': {
  167. afterrender: function(btn){
  168. var status = Ext.getCmp('ma_statuscode');
  169. if(status && status.value != 'AUDITED'){
  170. btn.hide();
  171. }
  172. status = Ext.getCmp('ma_checkstatuscode');
  173. if(status && status.value != 'UNAPPROVED'){
  174. btn.hide();
  175. }
  176. },
  177. click: function(btn){
  178. /*var type = Ext.getCmp('ma_tasktype').getValue();
  179. if(type != 'MAKE'){// 委外工单 考虑加工单价
  180. var p = Ext.getCmp('ma_price');
  181. if(p && (Ext.isEmpty(p.value) || p.value == 0)){
  182. Ext.Msg.alert("提示","请先填写加工单价后再提交!");
  183. return;
  184. }
  185. }*/
  186. me.FormUtil.onSubmit(Ext.getCmp('ma_id').value);
  187. }
  188. },
  189. 'erpResSubmitButton': {
  190. afterrender: function(btn){
  191. var status = Ext.getCmp('ma_checkstatuscode');
  192. if(status && status.value != 'COMMITED'){
  193. btn.hide();
  194. }
  195. },
  196. click: function(btn){
  197. me.FormUtil.onResSubmit(Ext.getCmp('ma_id').value);
  198. }
  199. },
  200. 'erpAuditButton': {
  201. afterrender: function(btn){
  202. var status = Ext.getCmp('ma_statuscode');
  203. if(status && status.value != 'ENTERING'){
  204. btn.hide();
  205. }
  206. },
  207. click: function(btn){
  208. me.FormUtil.onAudit(Ext.getCmp('ma_id').value);
  209. }
  210. },
  211. 'erpResAuditButton': {
  212. afterrender: function(btn){
  213. var status = Ext.getCmp('ma_statuscode');
  214. if(status && status.value != 'AUDITED'){
  215. btn.hide();
  216. }
  217. var checkStatus = Ext.getCmp('ma_checkstatuscode');
  218. if(checkStatus && checkStatus.value == 'COMMITED'){
  219. btn.hide();
  220. }
  221. },
  222. click: function(btn){
  223. if (!confirm('确定要反审核单据?')){
  224. return;
  225. }
  226. me.FormUtil.onResAudit(Ext.getCmp('ma_id').value);
  227. }
  228. },
  229. 'erpPrintButton':{
  230. click:function(btn){
  231. var maclass=Ext.getCmp('ma_tasktype').value;
  232. var reportName="";
  233. var condition="";
  234. if(maclass == "MAKE"){
  235. reportName="MAKE";
  236. condition='{Make.ma_id}='+Ext.getCmp('ma_id').value;
  237. //+' and (' + 'isnull({MAKEMATERIAL.MM_MATERIALSTATUS}) or {MAKEMATERIAL.MM_MATERIALSTATUS}=\' \')';
  238. } else {
  239. reportName="MAKEWW";
  240. condition='{Make.ma_id}='+Ext.getCmp('ma_id').value;
  241. //+' and (' + 'isnull({MAKEMATERIAL.MM_MATERIALSTATUS}) or {MAKEMATERIAL.MM_MATERIALSTATUS}=\' \')';
  242. }
  243. var id=Ext.getCmp('ma_id').value;
  244. me.FormUtil.onwindowsPrint2(id,reportName,condition);
  245. }
  246. },
  247. 'erpPrintA4Button':{
  248. click:function(btn){
  249. var maclass=Ext.getCmp('ma_tasktype').value;console.log(maclass);
  250. var reportName="";
  251. var condition="";
  252. if(maclass == "MAKE"){
  253. reportName="MAKE";
  254. condition='{MA_MAKEUSEPRE.ma_id}='+Ext.getCmp('ma_id').value;
  255. } else {
  256. reportName="MAKEWWA4";
  257. condition='{Make.ma_id}='+Ext.getCmp('ma_id').value;
  258. }
  259. //var condition='{MA_MAKEUSEPRE.ma_id}='+Ext.getCmp('ma_id').value;
  260. var id=Ext.getCmp('ma_id').value;
  261. me.FormUtil.onwindowsPrint(id,reportName,condition);
  262. }
  263. },
  264. 'erpGetMaterialButton':{
  265. afterrender: function(btn){
  266. btn.hide();//暂时不启用
  267. var status = Ext.getCmp('ma_chechkstatuscode');
  268. if(status && status.value != 'APPROVE'){
  269. btn.hide();
  270. }
  271. }
  272. },
  273. 'erpDeleteMaterialButton':{
  274. afterrender: function(btn){
  275. btn.hide();//暂时不启用
  276. var status = Ext.getCmp('ma_statuscode');
  277. if(status && status.value != 'ENTERING'){
  278. btn.hide();
  279. }
  280. }
  281. },
  282. 'erpEnforceEndButton':{
  283. afterrender: function(btn){
  284. var status = Ext.getCmp('ma_statuscode');
  285. if(status && status.value == 'FINISH'){
  286. btn.hide();
  287. }
  288. },
  289. click: function(btn){
  290. warnMsg("确定要强制结案吗?", function(btn){
  291. if(btn == 'yes'){
  292. Ext.Ajax.request({
  293. url : basePath + 'pm/make/enforceEndMake.action',
  294. params: {
  295. id: Ext.getCmp('ma_id').value
  296. },
  297. method : 'post',
  298. callback : function(options,success,response){
  299. var localJson = new Ext.decode(response.responseText);
  300. if(localJson.success){
  301. Ext.Msg.alert("提示","操作成功!");
  302. window.location.reload();
  303. } else {
  304. if(localJson.exceptionInfo){
  305. var str = localJson.exceptionInfo;
  306. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  307. str = str.replace('AFTERSUCCESS', '');
  308. showMessage('提示', str);
  309. window.location.reload();
  310. } else if(str == 'OK'){
  311. Ext.Msg.alert("提示","强制结案成功!");
  312. } else {
  313. showError(str);return;
  314. }
  315. }
  316. }
  317. }
  318. });
  319. }
  320. });
  321. }
  322. },
  323. 'erpGetOSVendorButton': {
  324. afterrender: function(btn){
  325. var status = Ext.getCmp('ma_statuscode');
  326. if(status && (status.value == 'FINISH')){
  327. btn.hide();
  328. }
  329. var tasktype = Ext.getCmp('ma_tasktype');
  330. if(tasktype && (tasktype.value != 'OS')){
  331. btn.hide();
  332. }
  333. },
  334. click: function(btn){
  335. if (!confirm('确定要自动获取委外商和单价?')){
  336. return;
  337. }
  338. Ext.Ajax.request({
  339. url: basePath + '/scm/purchase/getMakeVendorPrice.action',
  340. params: {
  341. id: Ext.getCmp('ma_id').value
  342. },
  343. callback: function(opt, s, r) {
  344. var rs = Ext.decode(r.responseText);
  345. if(rs.exceptionInfo) {
  346. showError(rs.exceptionInfo);
  347. } else {
  348. Ext.Msg.alert("提示","获取成功!");
  349. window.location.reload();
  350. }
  351. }
  352. });
  353. }
  354. },
  355. 'erpGetCraftButton':{
  356. afterrender: function(btn){
  357. btn.hide();//暂时不启用
  358. var status = Ext.getCmp('ma_statuscode');
  359. if(status && status.value != 'AUDITED'){
  360. btn.hide();
  361. }
  362. if(status && status.value != 'APPROVE'){
  363. btn.hide();
  364. }
  365. },
  366. click: function(btn){
  367. me.FormUtil.onResAudit(Ext.getCmp('ma_id').value);
  368. }
  369. },
  370. 'erpChangeMaterialButton': {
  371. afterrender: function(btn){
  372. btn.hide();//暂时不启用
  373. var status = Ext.getCmp('ma_statuscode');
  374. if(status && status.value != 'AUDITED'){
  375. btn.hide();
  376. }
  377. }
  378. },
  379. 'erpGetPriceButton':{
  380. afterrender: function(btn){
  381. var status = Ext.getCmp('ma_statuscode');
  382. if(status && status.value == 'FINISH'){
  383. btn.hide();
  384. }
  385. status = Ext.getCmp('ma_checkstatuscode');
  386. if (status && status.value == 'APPROVE'){
  387. btn.hide();
  388. }
  389. },
  390. click: function(btn){
  391. Ext.Ajax.request({
  392. url: basePath + '/scm/purchase/getMakeVendorPrice.action',
  393. params: {
  394. id: Ext.getCmp('ma_id').value
  395. },
  396. callback: function(opt, s, r) {
  397. var rs = Ext.decode(r.responseText);
  398. if(rs.exceptionInfo) {
  399. showError(rs.exceptionInfo);
  400. } else {
  401. Ext.Msg.alert("提示","获取成功!");
  402. window.location.reload();
  403. }
  404. }
  405. });
  406. }
  407. },
  408. 'erpCalMakeButton': {
  409. afterrender: function(btn){
  410. var status = Ext.getCmp('ma_statuscode');
  411. if(status && status.value != 'ENTERING' && status.value != 'AUDITED'){
  412. btn.hide();
  413. }
  414. } ,
  415. click: function(btn){
  416. if (!confirm('确定要计算用料?')){
  417. return;
  418. }
  419. var code = Ext.getCmp('ma_code').getValue();
  420. if (code) {
  421. Ext.Ajax.request({
  422. url : basePath + 'pm/make/setMakeMaterial.action',
  423. params: {
  424. caller: caller,
  425. code: code
  426. },
  427. method : 'post',
  428. callback : function(options,success,response){
  429. var res = new Ext.decode(response.responseText);
  430. if(res.exceptionInfo){
  431. showError(res.exceptionInfo);return;
  432. } else {
  433. window.location.reload();
  434. };
  435. }
  436. });
  437. }
  438. }
  439. },
  440. 'dbfindtrigger[name=ma_saledetno]': {
  441. afterrender: function(t){
  442. t.dbKey = "ma_salecode";
  443. t.mappingKey = "sd_code";
  444. t.dbMessage = "请先选择订单编号!";
  445. }
  446. },
  447. 'combo[name=ma_sourcekind]':{
  448. change:function(field,newValue){
  449. var codefield=Ext.getCmp('ma_salecode');
  450. var detnofield=Ext.getCmp('ma_saledetno');
  451. if(newValue=='Sale'){
  452. //销售预测
  453. codefield.dbCaller='Make!Base';
  454. detnofield.dbCaller='Make!Base';
  455. }else if(newValue=='SaleForeCast'){
  456. codefield.dbCaller='Make!Base!ForeCast';
  457. detnofield.dbCaller='Make!Base!ForeCast';
  458. }
  459. }
  460. },
  461. 'dbfindtrigger[name=mm_prodcode]': {
  462. /*focus: function(t){
  463. var grid = Ext.getCmp('grid');
  464. var c = null;
  465. Ext.each(grid.store.data.items, function(item){
  466. if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != ''){
  467. if(c == null){
  468. c = "(pr_code<>'" + item.data['mm_prodcode'] + "'";
  469. } else {
  470. c += " and pr_code<>'" + item.data['mm_prodcode'] + "'";
  471. }
  472. }
  473. });
  474. if(c != null){
  475. t.dbBaseCondition = c + ")";
  476. }
  477. }*/
  478. },
  479. 'textfield[name=ma_wccode]': {
  480. change: function(field){
  481. if(field.value != null && field.value != ''){
  482. var grid = Ext.getCmp('grid');
  483. var d = field.value;
  484. Ext.Array.each(grid.getStore().data.items,function(item){
  485. if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != '' ){
  486. if(item.data['mm_wccode'] == null ||item.data['mm_wccode'] == '' ){
  487. item.set('mm_wccode',d);
  488. }
  489. }
  490. });
  491. }
  492. }
  493. },
  494. 'datefield[name=ma_planenddate]':{
  495. change: function(f) {
  496. var c = Ext.getCmp('ma_planbegindate').getValue();
  497. var value = f.value;
  498. if( c != null && c != '' && value !=null && value != ''){
  499. if(c > value){
  500. Ext.getCmp('ma_planbegindate').setValue('');
  501. showError('计划完工日期不能早于计划开工日期');
  502. }
  503. }
  504. }
  505. },
  506. 'datefield[name=ma_planbegindate]':{
  507. change: function(f) {
  508. var c = Ext.getCmp('ma_planenddate').getValue();
  509. var value = f.value;
  510. if( value !=null && value != ''){
  511. var formatV = new Date(Ext.util.Format.date(value, 'Y-m-d'));
  512. var now = new Date(Ext.util.Format.date(new Date(),'Y-m-d'))
  513. if(now > formatV){
  514. Ext.getCmp('ma_planenddate').setValue('');
  515. showError('计划开工日期不能早于今天的日期');
  516. }
  517. if(c != null && c != '' ){
  518. if(value > c){
  519. Ext.getCmp('ma_planenddate').setValue('');
  520. showError('计划完工日期不能早于计划开工日期');
  521. }
  522. }
  523. }
  524. }
  525. },
  526. 'erpCheckButton': {
  527. afterrender: function(btn){
  528. var status = Ext.getCmp('ma_checkstatuscode');
  529. if(status && status.value != 'COMMITED'){
  530. btn.hide();
  531. }
  532. },
  533. click: function(btn){
  534. me.FormUtil.onCheck(Ext.getCmp('ma_id').value);
  535. }
  536. },
  537. 'erpResCheckButton': {
  538. afterrender: function(btn){
  539. var status = Ext.getCmp('ma_checkstatuscode');
  540. if(status && status.value != 'APPROVE' ){
  541. btn.hide();
  542. }
  543. /*if(status && status.value != 'APPROVE' || Ext.getCmp('ma_statuscode').value != 'AUDITED'){
  544. btn.hide();
  545. }*/
  546. },
  547. click: function(btn){
  548. me.FormUtil.onResCheck(Ext.getCmp('ma_id').value);
  549. }
  550. },
  551. 'erpEndButton': {
  552. afterrender: function(btn){
  553. var status = Ext.getCmp('ma_statuscode');
  554. if(status && status.value != 'AUDITED'){
  555. btn.hide();
  556. }
  557. },
  558. click: function(btn){
  559. me.FormUtil.onEnd(Ext.getCmp('ma_id').value);
  560. }
  561. },
  562. 'erpResEndButton': {
  563. afterrender: function(btn){
  564. var status = Ext.getCmp('ma_statuscode');
  565. if(status && status.value != 'FINISH'){
  566. btn.hide();
  567. }
  568. },
  569. click: function(btn){
  570. me.FormUtil.onResEnd(Ext.getCmp('ma_id').value);
  571. }
  572. },
  573. 'erpSubRelationButton':{
  574. click:function(btn){
  575. var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["mm_id"];
  576. var formCondition="mm_id IS"+id;
  577. var gridCondition="mp_mmid IS"+id;
  578. var linkCaller='MakeBase!Sub';
  579. var win = new Ext.window.Window(
  580. {
  581. id : 'win',
  582. height : '90%',
  583. width : '95%',
  584. maximizable : true,
  585. buttonAlign : 'center',
  586. layout : 'anchor',
  587. items : [ {
  588. tag : 'iframe',
  589. frame : true,
  590. anchor : '100% 100%',
  591. layout : 'fit',
  592. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/pm/make/makeCommon.jsp?_noc=1&whoami='+linkCaller+'&gridCondition='+gridCondition+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  593. } ]
  594. });
  595. win.show();
  596. },
  597. afterrender:function(btn){
  598. btn.setDisabled(true);
  599. }
  600. },
  601. 'erpModifyMaterialButton':{
  602. click:function(btn){
  603. var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["mm_id"];
  604. var formCondition="mm_id IS"+id;
  605. var linkCaller='MakeMaterial!Modify';
  606. var win = new Ext.window.Window(
  607. {
  608. id : 'win',
  609. height : '90%',
  610. width : '95%',
  611. maximizable : true,
  612. buttonAlign : 'center',
  613. layout : 'anchor',
  614. items : [ {
  615. tag : 'iframe',
  616. frame : true,
  617. anchor : '100% 100%',
  618. layout : 'fit',
  619. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/pm/make/modifyForm.jsp?_noc=0&whoami='+linkCaller+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  620. } ],
  621. listeners:{
  622. 'beforeclose':function(view ,opt){
  623. var grid = Ext.getCmp('grid');
  624. var value = Ext.getCmp('ma_id').value;
  625. var gridCondition = grid.mainField + '=' + value,
  626. gridParam = {caller: caller, condition: gridCondition};
  627. me.GridUtil.loadNewStore(grid, gridParam);
  628. }
  629. }
  630. });
  631. win.show();
  632. },
  633. afterrender:function(btn){
  634. btn.setDisabled(true);
  635. }
  636. },
  637. 'erpBomUseMatchButton' :{
  638. click: function(btn){
  639. var ma_code = Ext.getCmp('ma_code').value;
  640. Ext.Ajax.request({
  641. url : basePath + 'pm/make/MakeMaterialCheck.action',
  642. params: {
  643. code:ma_code
  644. },
  645. async:false,
  646. method : 'post',
  647. callback : function(options,success,response){
  648. var res = new Ext.decode(response.responseText);
  649. if(res.exceptionInfo){
  650. showError(res.exceptionInfo);return;
  651. } else {
  652. // var grid = Ext.getCmp('grid');
  653. // var value = Ext.getCmp('ma_id').value;
  654. // var gridCondition = grid.mainField + '=' + value,
  655. // gridParam = {caller: caller, condition: gridCondition};
  656. // me.GridUtil.loadNewStore(grid, gridParam);
  657. var win = new Ext.window.Window(
  658. {
  659. id : 'winMatch',
  660. height : '90%',
  661. width : '95%',
  662. maximizable : true,
  663. buttonAlign : 'center',
  664. layout : 'anchor',
  665. items : [ {
  666. tag : 'iframe',
  667. frame : true,
  668. anchor : '100% 100%',
  669. layout : 'fit',
  670. html : '<iframe id="iframe_BomUseMatchWin'+ma_code+'" src="'+basePath+'jsps/common/datalist.jsp?_noc=1&whoami=BomUseMatchWin&urlcondition=mc_makecode=\''+ma_code+'\'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  671. } ]
  672. });
  673. win.show();
  674. };
  675. }
  676. });
  677. },
  678. afterrender:function(btn){
  679. btn.setDisabled(false);
  680. }
  681. },
  682. 'erpHistoryProdIOButton':{
  683. click: function(){
  684. var macode = Ext.getCmp('ma_code').value;
  685. var record = Ext.getCmp('grid').selModel.lastSelected;
  686. if(record){
  687. var detno = record.data['mm_detno'],prod = record.data['mm_prodcode'];
  688. var win = Ext.getCmp('history-win');
  689. if(win == null){
  690. win = Ext.create('Ext.window.Window', {
  691. id: 'history-win',
  692. width: '80%',
  693. height: '100%',
  694. maximizable : true,
  695. layout: 'anchor',
  696. closeAction: 'hide',
  697. setMyTitle: function(code){//@param code 料号
  698. this.setTitle('物料编号:<font color=blue>' + code + '</font>&nbsp;工单号:<font color=blue>' + macode + '</font>&nbsp;的出入库明细&nbsp;&nbsp;');
  699. },
  700. reload: function(no, code){//@param code 料号
  701. var g = this.down('grid[id=history]');
  702. g.GridUtil.loadNewStore(g, {
  703. caller: g.caller,
  704. condition: "pd_ordercode ='" + macode + "' and pd_orderdetno="+ no + " order by pi_date desc"
  705. });
  706. g = this.down('grid[id=makescrap]');
  707. g.GridUtil.loadNewStore(g, {
  708. caller: g.caller,
  709. condition: "md_mmcode='" + macode + "' AND md_mmdetno=" + no
  710. });
  711. this.setMyTitle(code);
  712. }
  713. });
  714. win.setMyTitle(prod);
  715. win.show();
  716. win.add(Ext.create('erp.view.core.grid.Panel2', {
  717. id: 'history',
  718. anchor: '100% 60%',
  719. caller: 'ProdInOut!Make!History',
  720. condition: "pd_ordercode ='" + macode + "' and pd_orderdetno='"+ detno + "' order by pi_date desc",
  721. bbar: null,
  722. listeners: {
  723. reconfigure: function(){
  724. win.add(Ext.create('erp.view.core.grid.Panel2', {
  725. id: 'makescrap',
  726. title: '报废单',
  727. anchor: '100% 40%',
  728. caller: 'MakeScrap!JM',
  729. condition: "md_mmcode='" + macode + "' AND md_mmdetno=" + detno,
  730. bbar: null
  731. }));
  732. }
  733. }
  734. }));
  735. } else {
  736. win.reload(detno, prod);
  737. win.show();
  738. }
  739. } else {
  740. Ext.Msg.alert("提示","请先选择明细!");
  741. }
  742. }
  743. },
  744. 'erpRefreshQtyButton':{
  745. click: function(btn){
  746. var maid=Ext.getCmp('ma_id').value;
  747. Ext.Ajax.request({
  748. url : basePath + "pm/make/refreshqty.action",
  749. params:{
  750. id: maid
  751. },
  752. method:'post',
  753. callback:function(options,success,response){
  754. var localJson = new Ext.decode(response.responseText);
  755. if(localJson.success){
  756. Ext.Msg.alert("提示","刷新成功!");
  757. window.location.reload();
  758. } else {
  759. if(localJson.exceptionInfo){
  760. var str = localJson.exceptionInfo;
  761. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  762. str = str.replace('AFTERSUCCESS', '');
  763. showError(str);
  764. } else {
  765. showError(str);return;
  766. }
  767. }
  768. }
  769. }
  770. });
  771. }
  772. },
  773. 'erpTurnOSMakeButton':{
  774. click: function(btn){
  775. if (!confirm('确定要转本单据为委外单?')){
  776. return;
  777. }
  778. var kind = Ext.getCmp('ma_kind'),
  779. bg = 'background:#fffac0;color:#515151;';
  780. Ext.create('Ext.window.Window',{
  781. width:300,
  782. height:120,
  783. id:'win',
  784. title:'<h1>请选择委外单工单类型</h1>',
  785. items:[{
  786. xtype:'dbfindtrigger',
  787. fieldLabel:'工单类型',
  788. name:'makind',
  789. editable:false,
  790. id:'makind',
  791. fieldStyle: kind.allowBlank ? '' : bg
  792. }],
  793. buttonAlign:'center',
  794. buttons:[{
  795. xtype:'button',
  796. columnWidth:0.12,
  797. text:'确认',
  798. width:60,
  799. iconCls: 'x-button-icon-save',
  800. handler:function(btn){
  801. var kind=Ext.getCmp('makind').getValue();
  802. var maid=Ext.getCmp('ma_id').value;
  803. if(kind == null ||kind == ''){
  804. showError("请选择工单类型");
  805. return ;
  806. }
  807. Ext.Ajax.request({
  808. url : basePath + "pm/make/turnOSMake.action",
  809. params:{
  810. id: maid,
  811. kind:kind,
  812. caller:caller
  813. },
  814. method:'post',
  815. callback:function(options,success,response){
  816. var localJson = new Ext.decode(response.responseText);
  817. if(localJson.success){
  818. Ext.Msg.alert("提示","已成功转委外单!");
  819. var main = parent.Ext.getCmp("content-panel");
  820. main.getActiveTab().close();
  821. } else {
  822. if(localJson.exceptionInfo){
  823. var str = localJson.exceptionInfo;
  824. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  825. str = str.replace('AFTERSUCCESS', '');
  826. showError(str);
  827. } else {
  828. showError(str);return;
  829. }
  830. }
  831. }
  832. }
  833. });
  834. }
  835. },{
  836. xtype:'button',
  837. columnWidth:0.1,
  838. text:'关闭',
  839. width:60,
  840. iconCls: 'x-button-icon-close',
  841. margin:'0 0 0 10',
  842. handler:function(btn){
  843. Ext.getCmp('win').close();
  844. }
  845. }]
  846. }).show();
  847. }
  848. },
  849. 'erpTurnOSToMakeButton':{
  850. click: function(btn){
  851. if (!confirm('确定要转本单据为制造单?')){
  852. return;
  853. }
  854. var kind = Ext.getCmp('ma_kind'),
  855. bg = 'background:#fffac0;color:#515151;';
  856. Ext.create('Ext.window.Window',{
  857. width:300,
  858. height:120,
  859. id:'win',
  860. title:'<h1>请选择制造工单类型</h1>',
  861. items:[{
  862. xtype:'dbfindtrigger',
  863. fieldLabel:'工单类型',
  864. name:'makind',
  865. editable:false,
  866. id:'makind',
  867. fieldStyle: kind.allowBlank ? '' : bg
  868. }],
  869. buttonAlign:'center',
  870. buttons:[{
  871. xtype:'button',
  872. columnWidth:0.12,
  873. text:'确认',
  874. width:60,
  875. iconCls: 'x-button-icon-save',
  876. handler:function(btn){
  877. var kind=Ext.getCmp('makind').getValue();
  878. var maid=Ext.getCmp('ma_id').value;
  879. if(kind == null ||kind == ''){
  880. showError("请选择工单类型");
  881. return ;
  882. }
  883. Ext.Ajax.request({
  884. url : basePath + "pm/make/turnOSToMake.action",
  885. params:{
  886. id: maid,
  887. kind:kind,
  888. caller:caller
  889. },
  890. method:'post',
  891. callback:function(options,success,response){
  892. var localJson = new Ext.decode(response.responseText);
  893. if(localJson.success){
  894. Ext.Msg.alert("提示","已成功转制造单!");
  895. var main = parent.Ext.getCmp("content-panel");
  896. main.getActiveTab().close();
  897. } else {
  898. if(localJson.exceptionInfo){
  899. var str = localJson.exceptionInfo;
  900. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  901. str = str.replace('AFTERSUCCESS', '');
  902. showError(str);
  903. } else {
  904. showError(str);return;
  905. }
  906. }
  907. }
  908. }
  909. });
  910. }
  911. },{
  912. xtype:'button',
  913. columnWidth:0.1,
  914. text:'关闭',
  915. width:60,
  916. iconCls: 'x-button-icon-close',
  917. margin:'0 0 0 10',
  918. handler:function(btn){
  919. Ext.getCmp('win').close();
  920. }
  921. }]
  922. }).show();
  923. }
  924. },
  925. 'erpMrpOpenButton':{
  926. click: function(btn){
  927. var grid = Ext.getCmp('grid');
  928. var record = grid.selModel.lastSelected;
  929. var id = record.data.mm_id;
  930. Ext.Ajax.request({
  931. url : basePath + "pm/make/openMrp.action",
  932. params: {
  933. id:id,
  934. caller:caller
  935. },
  936. method : 'post',
  937. async: false,
  938. callback : function(options,success,response){
  939. var res = new Ext.decode(response.responseText);
  940. if(res.exceptionInfo){
  941. showError(res.exceptionInfo);
  942. return;
  943. }
  944. Ext.Msg.alert('提示','打开Mrp成功!');
  945. var condition='mm_maid='+Ext.getCmp('ma_id').value;
  946. me.GridUtil.loadNewStore(grid,{caller:caller,condition:condition});
  947. }
  948. });
  949. },
  950. afterrender:function(btn){
  951. btn.setDisabled(true);
  952. }
  953. },
  954. 'erpMrpCloseButton': {
  955. click: function(btn){
  956. var grid = Ext.getCmp('grid');
  957. var record = grid.selModel.lastSelected;
  958. var id = record.data.mm_id;
  959. Ext.Ajax.request({
  960. url : basePath + "pm/make/CloseMrp.action",
  961. params: {
  962. id:id,
  963. caller:caller
  964. },
  965. method : 'post',
  966. async: false,
  967. callback : function(options,success,response){
  968. var res = new Ext.decode(response.responseText);
  969. if(res.exceptionInfo){
  970. showError(res.exceptionInfo);
  971. return;
  972. }
  973. Ext.Msg.alert('提示','关闭Mrp成功!');
  974. var condition='mm_maid='+Ext.getCmp('ma_id').value;
  975. me.GridUtil.loadNewStore(grid,{caller:caller,condition:condition});
  976. }
  977. });
  978. },
  979. afterrender:function(btn){
  980. btn.setDisabled(true);
  981. }
  982. },
  983. 'field[name=ma_prodcode]': {
  984. change: function(f){
  985. if(f.value != null && f.value != ''){
  986. me.FormUtil.getFieldValue('BOM', 'bo_id', "bo_mothercode='" + f.value + "'", 'ma_bomid');
  987. }
  988. }
  989. },
  990. 'field[name=ma_qty]': {
  991. /*
  992. change: function(f){
  993. if(f.value == null || f.value == ''){
  994. f.value = 0;
  995. }
  996. if(Ext.getCmp('ma_total')){
  997. Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_price').value);
  998. }
  999. var grid = Ext.getCmp('grid');
  1000. if(grid){
  1001. var items = grid.store.data.items;
  1002. Ext.each(items, function(item){//制单需求=制单套数*单位用量
  1003. if(item.data['mm_oneuseqty'] != null && item.data['mm_oneuseqty'] != 0){
  1004. item.set('mm_qty', item.data['mm_oneuseqty']*f.value);
  1005. }
  1006. });
  1007. }
  1008. }
  1009. */
  1010. },
  1011. 'erpUpdateRemarkButton':{
  1012. click:function(){
  1013. var remark=Ext.getCmp('ma_remark');
  1014. me.updateRemark(remark.value,Ext.getCmp('ma_id').value);
  1015. }
  1016. },
  1017. 'erpUpdateTeamcodeButton':{
  1018. click:function(){
  1019. var teamcode=Ext.getCmp('ma_teamcode');
  1020. me.updateTeamcode(teamcode.value,Ext.getCmp('ma_id').value);
  1021. }
  1022. },
  1023. 'erpUpdateMaStyleButton':{//更新流程类型
  1024. click:function(){
  1025. var mastyle=Ext.getCmp('ma_style');
  1026. me.updateMaStyle(mastyle.value,Ext.getCmp('ma_id').value);
  1027. },
  1028. afterrender:function(btn){
  1029. var checkstatus = Ext.getCmp("ma_checkstatuscode");
  1030. var status = Ext.getCmp("ma_statuscode");
  1031. if((checkstatus && (checkstatus.value == 'APPROVE'||checkstatus.value == 'COMMITED'))||(status && status.valueOf() == 'ENTERING')){
  1032. btn.hide();
  1033. }
  1034. }
  1035. },
  1036. 'field[name=ma_price]': {
  1037. change: function(f){
  1038. if(f.value == null || f.value == ''){
  1039. f.value = 0;
  1040. }
  1041. if(Ext.getCmp('ma_total')){//字段存在赋值,不存在不赋值
  1042. Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_qty').value);
  1043. }
  1044. }
  1045. },
  1046. 'field[name=mm_oneuseqty]': {
  1047. change: function(f){//制单需求=制单套数*单位用量
  1048. if(f.value != null && f.value > 0 && Ext.getCmp('ma_qty') && Ext.getCmp('ma_qty').value > 0){
  1049. var record = Ext.getCmp('grid').selModel.getLastSelected();
  1050. if(record.data['mm_qty'] != f.value*Ext.getCmp('ma_qty').value){
  1051. record.set('mm_qty', f.value*Ext.getCmp('ma_qty').value);
  1052. }
  1053. }
  1054. }
  1055. }
  1056. });
  1057. },
  1058. getForm: function(btn){
  1059. return btn.ownerCt.ownerCt;
  1060. },
  1061. itemclick:function(view,record,me){
  1062. var show=0;
  1063. me.GridUtil.onGridItemClick(view,record);
  1064. var fieldValue=record.data["mm_prodcode"];
  1065. if(fieldValue==undefined||fieldValue==""||fieldValue==null){
  1066. show=1;
  1067. return;
  1068. }
  1069. var status = Ext.getCmp('ma_statuscode').getValue();
  1070. if(show==1 || status=='FINISH' ){
  1071. Ext.getCmp('SubRelation').setDisabled(true);
  1072. Ext.getCmp('ModifyMaterial').setDisabled(true);
  1073. Ext.getCmp('MrpClose').setDisabled(true);
  1074. Ext.getCmp('MrpOpen').setDisabled(true);
  1075. }else {
  1076. Ext.getCmp('SubRelation').setDisabled(false);
  1077. Ext.getCmp('ModifyMaterial').setDisabled(false);
  1078. Ext.getCmp('MrpClose').setDisabled(false);
  1079. Ext.getCmp('MrpOpen').setDisabled(false);
  1080. }
  1081. },
  1082. updateRemark:function(remark,id){
  1083. Ext.Ajax.request({
  1084. url : basePath + 'pm/make/updateRemark.action',
  1085. params: {remark:remark,id:id},
  1086. method : 'post',
  1087. async:false,
  1088. callback : function(options,success,response){
  1089. var res = new Ext.decode(response.responseText);
  1090. if(res.exceptionInfo != null){
  1091. showError(res.exceptionInfo);return;
  1092. }
  1093. showMessage("提示", '更新成功!');
  1094. window.location.reload();
  1095. }
  1096. });
  1097. },
  1098. updateTeamcode:function(value,id){
  1099. Ext.Ajax.request({
  1100. url : basePath + 'pm/make/updateTeamcode.action',
  1101. params: {value:value,id:id},
  1102. method : 'post',
  1103. async:false,
  1104. callback : function(options,success,response){
  1105. var res = new Ext.decode(response.responseText);
  1106. if(res.exceptionInfo != null){
  1107. showError(res.exceptionInfo);return;
  1108. }
  1109. showMessage("提示", '更新成功!');
  1110. window.location.reload();
  1111. }
  1112. });
  1113. },
  1114. updateMaStyle:function(value,id){
  1115. Ext.Ajax.request({
  1116. url : basePath + 'pm/make/updateMaStyle.action',
  1117. params: {value:value,id:id},
  1118. method : 'post',
  1119. async:false,
  1120. callback : function(options,success,response){
  1121. var res = new Ext.decode(response.responseText);
  1122. if(res.exceptionInfo != null){
  1123. showError(res.exceptionInfo);return;
  1124. }
  1125. showMessage("提示", '更新成功!');
  1126. window.location.reload();
  1127. }
  1128. });
  1129. },
  1130. getFdValue: function(tablename,field, condition){//根据特征项code和特征值码获取特征值
  1131. var result = '';
  1132. Ext.Ajax.request({
  1133. url : basePath + "/common/getFieldData.action",
  1134. params: {
  1135. caller: tablename,
  1136. field: field,
  1137. condition: condition
  1138. },
  1139. method : 'post',
  1140. async: false,
  1141. callback : function(options,success,response){
  1142. var res = new Ext.decode(response.responseText);
  1143. if(res.exceptionInfo){
  1144. showError(res.exceptionInfo);return;
  1145. }
  1146. if(res.success){
  1147. result = res.data;
  1148. }
  1149. }
  1150. });
  1151. return result;
  1152. },
  1153. getRandomNumber: function(table, type, codeField){
  1154. if(Ext.getCmp('ma_kind')){
  1155. var form = Ext.getCmp('form');
  1156. if(form){
  1157. table = table == null ? form.tablename : table;
  1158. }
  1159. type = type == null ? 2 : type;
  1160. codeField = codeField == null ? form.codeField : codeField;
  1161. Ext.Ajax.request({
  1162. url : basePath + 'pm/make/getCodeString.action',
  1163. async: false,//同步ajax请求
  1164. params: {
  1165. caller: caller,//如果table==null,则根据caller去form表取对应table
  1166. table: table,
  1167. type: type,
  1168. conKind:Ext.getCmp('ma_kind').getValue()
  1169. },
  1170. method : 'post',
  1171. callback : function(options,success,response){
  1172. var localJson = new Ext.decode(response.responseText);
  1173. if(localJson.exceptionInfo){
  1174. showError(localJson.exceptionInfo);
  1175. }
  1176. if(localJson.success){
  1177. Ext.getCmp(codeField).setValue(localJson.code);
  1178. }
  1179. }
  1180. });
  1181. } else {
  1182. this.BaseUtil.getRandomNumber(caller);//自动添加编号
  1183. }
  1184. },
  1185. getLeadCode: function(type) {
  1186. var result = null;
  1187. Ext.Ajax.request({
  1188. url : basePath + 'common/getFieldData.action',
  1189. async: false,
  1190. params: {
  1191. caller: 'MakeKind',
  1192. field: 'mk_excode',
  1193. condition: 'mk_name=\'' + type + '\''
  1194. },
  1195. method : 'post',
  1196. callback : function(opt, s, res){
  1197. var r = new Ext.decode(res.responseText);
  1198. if(r.exceptionInfo){
  1199. showError(r.exceptionInfo);return;
  1200. } else if(r.success){
  1201. result = r.data;
  1202. }
  1203. }
  1204. });
  1205. return result;
  1206. }
  1207. });