Sale.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.Sale', {
  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.sale.Sale','core.grid.Panel2','core.toolbar.Toolbar','core.form.FileField','core.form.MultiField','core.form.CheckBoxGroup',
  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.button.Consign','core.button.TurnNotify','core.button.FeatureDefinition','core.button.PrintA4',
  12. 'core.button.FeatureView','core.button.OutSchedule','core.button.ResSubmitTurnSale','core.button.SubmitTurnSale','core.button.TurnNormalSale',
  13. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn','core.form.FileField',
  14. 'core.button.CopyAll','core.button.RunATP','core.button.TurnProdInOutSale','core.button.TurnCustomer', 'core.button.RefreshSync',
  15. 'core.button.MrpOpen','core.button.MrpClose','core.button.RefreshQty','core.grid.YnColumnNV'
  16. ],
  17. init:function(){
  18. var me = this;
  19. this.control({
  20. 'erpGridPanel2': {
  21. itemclick: function(selModel, record){
  22. if(record.data.sd_id != 0 && record.data.sd_id != null && record.data.sd_id != ''){
  23. var btn = Ext.getCmp('featuredefinition');
  24. btn && btn.setDisabled(false);
  25. btn = Ext.getCmp('featureview');
  26. btn && btn.setDisabled(false);
  27. btn = Ext.getCmp('outschedule');
  28. btn && btn.setDisabled(false);
  29. btn = Ext.getCmp('updatepmc');
  30. btn && btn.setDisabled(false);
  31. btn = Ext.getCmp('yesdate');
  32. btn && btn.setDisabled(false);
  33. btn = Ext.getCmp('splitSaleButton');
  34. btn && btn.setDisabled(false);
  35. btn = Ext.getCmp('bomopen');
  36. btn && btn.setDisabled(false);
  37. btn = Ext.getCmp('updateDiscount');
  38. btn && btn.setDisabled(false);
  39. btn = Ext.getCmp('MrpOpen');
  40. btn && btn.setDisabled(false);
  41. btn = Ext.getCmp('MrpClose');
  42. btn && btn.setDisabled(false);
  43. }
  44. this.onGridItemClick(selModel, record);
  45. }
  46. },
  47. /**
  48. * 订单分拆
  49. */
  50. '#splitSaleButton': {
  51. click: function(btn) {
  52. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  53. me.SaleSplit(record);
  54. }
  55. },
  56. /**
  57. * 更改PMC日期
  58. */
  59. '#updatepmc': {
  60. click: function(btn) {
  61. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  62. me.UpdatePmc(record);
  63. }
  64. },
  65. /**
  66. * 更改PMC承诺出货日期
  67. */
  68. '#yesdate': {
  69. click: function(btn) {
  70. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  71. me.UpdateYesDate(record);
  72. }
  73. },
  74. /**
  75. * BOM多级展开
  76. */
  77. '#bomopen': {
  78. click: function(btn) {
  79. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  80. var pr_code=record.data.sd_prodcode;
  81. var url="jsps/pm/bom/BOMStructQuery.jsp?whoami=BOMStruct!Struct!Query";
  82. var condition="";
  83. //母件编号带出展开的料号不对 参照万利达配置
  84. if(pr_code){
  85. condition+="pr_codeIS'"+pr_code+"'";
  86. }
  87. me.FormUtil.onAdd('BOMStruct'+ pr_code, 'BOM多级展开', url+"&condition="+condition);
  88. }
  89. },
  90. /**
  91. * 更新比例
  92. */
  93. '#updateDiscount': {
  94. afterrender: function(btn) {
  95. Ext.defer(function(){
  96. var status = Ext.getCmp('sa_statuscode');
  97. if(status && status.value == 'ENTERING'){
  98. btn.hide();
  99. }
  100. }, 100);
  101. },
  102. click: function() {
  103. me.updateDiscount();
  104. }
  105. },
  106. 'erpSaveButton': {
  107. click: function(btn){
  108. var form = me.getForm(btn);
  109. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  110. me.getRandomNumber();//自动添加编号
  111. }
  112. this.beforeSaveSale();
  113. }
  114. },
  115. 'erpDeleteButton' : {
  116. click: function(btn){
  117. me.FormUtil.onDelete({id: Number(Ext.getCmp('sa_id').value)});
  118. }
  119. },
  120. 'erpUpdateButton': {
  121. afterrender: function(btn){
  122. var status = Ext.getCmp('sa_statuscode');
  123. if(status && status.value != 'ENTERING'){
  124. btn.hide();
  125. }
  126. },
  127. click: function(btn){
  128. me.beforeUpdate();
  129. }
  130. },
  131. 'erpAddButton': {
  132. click: function(){
  133. me.FormUtil.onAdd('addSale', '销售单', 'jsps/scm/sale/sale.jsp?whoami=' + caller);
  134. }
  135. },
  136. 'erpCloseButton': {
  137. click: function(btn){
  138. me.FormUtil.beforeClose(me);
  139. }
  140. },
  141. 'dbfindtrigger[name=sa_toplace]': {
  142. afterrender:function(trigger){
  143. trigger.dbKey='sa_custcode';
  144. trigger.mappingKey='cu_code';
  145. trigger.dbMessage='请先选客户编号!';
  146. }
  147. },
  148. 'dbfindtrigger[name=sa_paymentscode]': {
  149. afterrender:function(trigger){
  150. if(trigger.fieldConfig == 'PT') {
  151. trigger.dbKey='sa_custcode';
  152. trigger.mappingKey='cu_code';
  153. trigger.dbMessage='请先选客户编号!';
  154. }
  155. }
  156. },
  157. 'erpSubmitButton': {
  158. afterrender: function(btn){
  159. var status = Ext.getCmp('sa_statuscode');
  160. if(status && status.value != 'ENTERING'){
  161. btn.hide();
  162. }
  163. },
  164. click: function(btn){
  165. me.FormUtil.onSubmit(Ext.getCmp('sa_id').value);
  166. }
  167. },
  168. 'erpMrpOpenButton' : {
  169. click: function(btn){
  170. var grid = Ext.getCmp('grid');
  171. var record = grid.selModel.lastSelected;
  172. var id = record.data.sd_id;
  173. if (id && id>0){
  174. Ext.Ajax.request({
  175. url : basePath + "scm/sale/saleMrpOpen.action",
  176. params: {
  177. id:id,
  178. caller:caller
  179. },
  180. method : 'post',
  181. async: false,
  182. callback : function(options,success,response){
  183. var res = new Ext.decode(response.responseText);
  184. if(res.exceptionInfo){
  185. showError(res.exceptionInfo);
  186. return;
  187. }
  188. showError("打开Mrp成功!");
  189. }
  190. });
  191. }
  192. }
  193. },
  194. 'erpMrpCloseButton' : {
  195. click: function(btn){
  196. var grid = Ext.getCmp('grid');
  197. var record = grid.selModel.lastSelected;
  198. var id = record.data.sd_id;
  199. if (id && id>0){
  200. Ext.Ajax.request({
  201. url : basePath + "scm/sale/saleMrpClose.action",
  202. params: {
  203. id:id,
  204. caller:caller
  205. },
  206. method : 'post',
  207. async: false,
  208. callback : function(options,success,response){
  209. var res = new Ext.decode(response.responseText);
  210. if(res.exceptionInfo){
  211. showError(res.exceptionInfo);
  212. return;
  213. }
  214. showError("关闭Mrp成功!");
  215. }
  216. });
  217. }
  218. }
  219. },
  220. //刷新已转数
  221. 'erpRefreshQtyButton':{
  222. click: function(btn){
  223. warnMsg("确定要刷新已转数?", function(btn){
  224. if(btn == 'yes'){
  225. me.FormUtil.getActiveTab().setLoading(true);//loading...
  226. Ext.Ajax.request({
  227. url : basePath + 'scm/sale/refreshSaleYQTY.action',
  228. params: {
  229. id: Ext.getCmp('sa_id').value
  230. },
  231. method : 'post',
  232. callback : function(options,success,response){
  233. me.FormUtil.getActiveTab().setLoading(false);
  234. var localJson = new Ext.decode(response.responseText);
  235. if(localJson.exceptionInfo){
  236. showError(localJson.exceptionInfo);
  237. }
  238. if(localJson.success){
  239. Ext.Msg.alert("提示","刷新成功!");
  240. window.location.reload();
  241. }
  242. }
  243. });
  244. }
  245. });
  246. }
  247. },
  248. //帕诺迪专用
  249. 'erpTurnCustomerButton': {
  250. beforerender:function(btn){
  251. btn.setText("收款情况");
  252. },
  253. afterrender:function(btn){
  254. var status = Ext.getCmp('sa_statuscode');
  255. if(status.value != 'AUDITED'){
  256. btn.hide();
  257. }
  258. },
  259. click:function(){
  260. var sacode=Ext.getCmp('sa_id').value;
  261. var formCondition="sp_saleid IS"+sacode;
  262. var linkCaller='SalePayment';
  263. var win = new Ext.window.Window({
  264. id : 'win',
  265. height : '90%',
  266. width : '95%',
  267. maximizable : true,
  268. buttonAlign : 'center',
  269. layout : 'anchor',
  270. items : [ {
  271. tag : 'iframe',
  272. frame : true,
  273. anchor : '100% 100%',
  274. layout : 'fit',
  275. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/scm/sale/salepayment.jsp?_noc=1&whoami='+linkCaller+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  276. } ],
  277. listeners:{
  278. 'beforeclose':function(view ,opt){
  279. //grid 刷新一次
  280. var grid=Ext.getCmp('grid');
  281. var gridParam = {caller: caller, condition: gridCondition};
  282. grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  283. }
  284. }
  285. });
  286. win.show();
  287. }
  288. },
  289. 'erpResSubmitButton': {
  290. afterrender: function(btn){
  291. var status = Ext.getCmp('sa_statuscode');
  292. if(status && status.value != 'COMMITED'){
  293. btn.hide();
  294. }
  295. },
  296. click: function(btn){
  297. me.FormUtil.onResSubmit(Ext.getCmp('sa_id').value);
  298. }
  299. },
  300. 'erpAuditButton': {
  301. afterrender: function(btn){
  302. var status = Ext.getCmp('sa_statuscode');
  303. if(status && status.value != 'COMMITED'){
  304. btn.hide();
  305. }
  306. },
  307. click: function(btn){
  308. me.FormUtil.onAudit(Ext.getCmp('sa_id').value);
  309. }
  310. },
  311. 'erpResAuditButton': {
  312. afterrender: function(btn){
  313. var status = Ext.getCmp('sa_statuscode');
  314. if(status && status.value != 'AUDITED'){
  315. btn.hide();
  316. }
  317. },
  318. click: function(btn){
  319. me.FormUtil.onResAudit(Ext.getCmp('sa_id').value);
  320. }
  321. },
  322. 'erpSubmitTurnSaleButton':{
  323. click:function(btn){
  324. var id=Ext.getCmp('sa_id').getValue();
  325. Ext.Ajax.request({//拿到grid的columns
  326. url : basePath + "scm/sale/submitTurnSale.action",
  327. params: {
  328. id:id
  329. },
  330. method : 'post',
  331. callback : function(options,success,response){
  332. var res = new Ext.decode(response.responseText);
  333. if(res.exceptionInfo){
  334. var str = res.exceptionInfo;
  335. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  336. str = str.replace('AFTERSUCCESS', '');
  337. submitSuccess(function(){
  338. window.location.reload();
  339. });
  340. }
  341. showMessage("提示", str);return;
  342. }
  343. else if(res.success){
  344. submitSuccess(function(){
  345. window.location.reload();
  346. });
  347. }
  348. }
  349. });
  350. },
  351. afterrender:function(btn){
  352. var sa_commitstatus=Ext.getCmp('sa_commitstatus').getValue();
  353. var sa_statuscode=Ext.getCmp('sa_statuscode').getValue();
  354. var sa_source=Ext.getCmp('sa_source').getValue();
  355. var bool=true;
  356. if((Ext.isEmpty(sa_commitstatus)||sa_commitstatus=='未提交')&&sa_statuscode=='AUDITED'&&sa_source=='非正常'){
  357. bool=false;
  358. }
  359. if(bool) btn.hide();
  360. }
  361. },
  362. 'erpResSubmitTurnSaleButton':{
  363. click:function(btn){
  364. var id=Ext.getCmp('sa_id').getValue();
  365. Ext.Ajax.request({//拿到grid的columns
  366. url : basePath + "scm/sale/resSubmitTurnSale.action",
  367. params: {
  368. id:id
  369. },
  370. method : 'post',
  371. callback : function(options,success,response){
  372. var res = new Ext.decode(response.responseText);
  373. if(res.exceptionInfo){
  374. showError(res.exceptionInfo);return;
  375. }
  376. if(res.success){
  377. resSubmitSuccess();
  378. window.location.reload();
  379. }
  380. }
  381. });
  382. },
  383. afterrender:function(btn){
  384. var sa_commitstatus=Ext.getCmp('sa_commitstatus').getValue();
  385. if(sa_commitstatus!='已提交'){
  386. btn.hide();
  387. }
  388. }
  389. },
  390. 'erpTurnNormalSaleButton':{
  391. click:function(btn){
  392. var id=Ext.getCmp('sa_id').getValue();
  393. Ext.Ajax.request({//拿到grid的columns
  394. url : basePath + "scm/sale/TurnNormalSale.action",
  395. params: {
  396. id:id
  397. },
  398. method : 'post',
  399. callback : function(options,success,response){
  400. var res = new Ext.decode(response.responseText);
  401. if(res.exceptionInfo){
  402. showError(res.exceptionInfo);return;
  403. }
  404. if(res.success){
  405. Ext.Msg.alert('提示','转正式订单成功!',function(){
  406. window.location.reload();
  407. });
  408. }
  409. }
  410. });
  411. },
  412. afterrender:function(btn){
  413. var sa_commitstatus=Ext.getCmp('sa_commitstatus');
  414. if(sa_commitstatus && sa_commitstatus.value!='已提交'){
  415. btn.hide();
  416. }
  417. }
  418. },
  419. 'erpPrintButton':{
  420. click:function(btn){
  421. var reportName="salelist";
  422. var condition='{Sale.sa_id}='+Ext.getCmp('sa_id').value+'';
  423. var id=Ext.getCmp('sa_id').value;
  424. me.FormUtil.onwindowsPrint(id,reportName,condition);
  425. }
  426. },
  427. 'erpPrintA4Button':{
  428. click:function(btn){
  429. var reportName="SaleCheck";
  430. var condition='{Sale.sa_id}='+Ext.getCmp('sa_id').value+'';
  431. var id=Ext.getCmp('sa_id').value;
  432. me.FormUtil.onwindowsPrint(id,reportName,condition);
  433. }
  434. },
  435. 'field[name=sa_statuscode]': {
  436. change: function(f){
  437. var grid = Ext.getCmp('grid');
  438. if(grid && f.value != 'ENTERING' && f.value != 'COMMITED'){
  439. grid.setReadOnly(true);//只有未审核的订单,grid才能编辑
  440. }
  441. }
  442. },
  443. 'erpConsignButton': {
  444. afterrender: function(btn){
  445. var status = Ext.getCmp('sa_statuscode');
  446. if(status && status.value != 'AUDITED'){
  447. btn.hide();
  448. }
  449. }
  450. },
  451. 'erpTurnProdInOutSaleButton': {
  452. afterrender: function(btn){
  453. var status = Ext.getCmp('sa_statuscode');
  454. if(status && status.value != 'AUDITED'){
  455. btn.hide();
  456. }
  457. }
  458. },
  459. 'erpFeatureDefinitionButton':{
  460. click: function(btn){
  461. var grid = Ext.getCmp('grid');
  462. var record = grid.selModel.lastSelected;
  463. if(record.data.sd_prodcode != null){
  464. Ext.Ajax.request({//拿到grid的columns
  465. url : basePath + "pm/bom/getDescription.action",
  466. params: {
  467. tablename: 'Product',
  468. field: 'pr_specvalue',
  469. condition: "pr_code='" + record.data.sd_prodcode + "'"
  470. },
  471. method : 'post',
  472. async: false,
  473. callback : function(options,success,response){
  474. var res = new Ext.decode(response.responseText);
  475. if(res.exceptionInfo){
  476. showError(res.exceptionInfo);return;
  477. }
  478. if(res.success){
  479. if(res.description != '' && res.description != null && res.description == 'NOTSPECIFIC'){
  480. var win = new Ext.window.Window({
  481. id : 'win',
  482. title: '生成特征料号',
  483. height: "90%",
  484. width: "95%",
  485. maximizable : true,
  486. buttonAlign : 'center',
  487. layout : 'anchor',
  488. items: [{
  489. tag : 'iframe',
  490. frame : true,
  491. anchor : '100% 100%',
  492. layout : 'fit',
  493. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  494. "jsps/pm/bom/FeatureValueSet.jsp?fromwhere=SaleDetail&condition=formidIS" + record.data.sd_id + ' AND pr_codeIS' + record.data.sd_prodcode + ' AND pr_nameIS' + record.data.pr_detail +'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
  495. }]
  496. });
  497. win.show();
  498. } else {
  499. showError('物料特征必须为虚拟特征件');return;
  500. }
  501. }
  502. }
  503. });
  504. }
  505. }
  506. },
  507. 'erpFeatureViewButton':{
  508. click: function(btn){
  509. var grid = Ext.getCmp('grid');
  510. var record = grid.selModel.lastSelected;
  511. if(record.data.sd_prodcode != null){
  512. Ext.Ajax.request({//拿到grid的columns
  513. url : basePath + "pm/bom/getDescription.action",
  514. params: {
  515. tablename: 'Product',
  516. field: 'pr_specvalue',
  517. condition: "pr_code='" + record.data.sd_prodcode + "'"
  518. },
  519. method : 'post',
  520. async: false,
  521. callback : function(options,success,response){
  522. var res = new Ext.decode(response.responseText);
  523. if(res.exceptionInfo){
  524. showError(res.exceptionInfo);return;
  525. }
  526. if(res.success){
  527. if(res.description != '' && res.description != null && res.description == 'SPECIFIC'){
  528. var win = new Ext.window.Window({
  529. id : 'win' + record.data.sd_id,
  530. title: '特征查看',
  531. height: "90%",
  532. width: "70%",
  533. maximizable : true,
  534. buttonAlign : 'center',
  535. layout : 'anchor',
  536. items: [{
  537. tag : 'iframe',
  538. frame : true,
  539. anchor : '100% 100%',
  540. layout : 'fit',
  541. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  542. "jsps/pm/bom/FeatureValueView.jsp?fromwhere=SaleDetail&formid=" + record.data.sd_id + '&pr_code=' + record.data.sd_prodcode +'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
  543. }]
  544. });
  545. win.show();
  546. } else {
  547. showError('物料特征必须为 虚拟特征件');return;
  548. }
  549. }
  550. }
  551. });
  552. }
  553. }
  554. },
  555. 'erpRunATPButton':{
  556. click: function(btn){
  557. if(Ext.getCmp('sa_code').value != null){
  558. var mb = new Ext.window.MessageBox();
  559. mb.wait('正在运算中','请稍后...',{
  560. interval: 10000, //bar will move fast!
  561. duration: 1000000,
  562. increment: 20,
  563. scope: this
  564. });
  565. Ext.Ajax.request({//拿到grid的columns
  566. url : basePath + "/pm/atp/runATPFromOther.action",
  567. params: {
  568. fromcode:Ext.getCmp('sa_code').value,
  569. fromwhere:'SALE'
  570. },
  571. method : 'post',
  572. timeout: 600000,
  573. callback : function(options,success,response){
  574. mb.close();
  575. var res = new Ext.decode(response.responseText);
  576. if(res.exceptionInfo){
  577. showError(res.exceptionInfo);return;
  578. }
  579. if(res.success){
  580. if(res.atpid != '' && res.atpid != null && res.atpid>0){
  581. me.FormUtil.onAdd(null, 'ATP运算', 'jsps/pm/atp/ATPMain.jsp?formCondition=am_id=' + res.atpid + '&&gridCondition=ad_amid='+res.atpid+'&_noc=1');
  582. } else {
  583. showError('无数据,运算失败');return;
  584. }
  585. }
  586. }
  587. });
  588. }
  589. }
  590. },
  591. 'dbfindtrigger[name=sd_batchcode]': {
  592. focus: function(t){
  593. t.setHideTrigger(false);
  594. t.setReadOnly(false);//用disable()可以,但enable()无效
  595. var record = Ext.getCmp('grid').selModel.getLastSelected();
  596. var pr = record.data['sd_prodcode'];
  597. if(pr == null || pr == ''){
  598. showError("请先选择料号!");
  599. t.setHideTrigger(true);
  600. t.setReadOnly(true);
  601. } else {
  602. var id = record.data['sd_warehouseid'];
  603. if(id == null || id == ''){
  604. id = Ext.getCmp('sd_warehouseid');
  605. if(id == null || id == '' || id== 0 ){
  606. showError("请先选择仓库!");
  607. t.setHideTrigger(true);
  608. t.setReadOnly(true);
  609. }
  610. } else {
  611. t.dbBaseCondition = "ba_warehouseid='" + id + "' AND ba_prodcode='" + pr + "'";
  612. }
  613. t.dbBaseCondition = "ba_prodcode='" + pr + "'";
  614. }
  615. }
  616. },
  617. 'erpOutScheduleButton': {
  618. click: function() {
  619. var grid = Ext.getCmp('grid'),record = grid.selModel.lastSelected;
  620. if(record) {
  621. me.schedule(record);
  622. }
  623. }
  624. },
  625. 'erpCopyButton': {
  626. click: function(btn) {
  627. me.copy();
  628. }
  629. },
  630. 'dbfindtrigger[name=sd_forecastdetno]': {
  631. focus: function(t){
  632. t.setHideTrigger(false);
  633. t.setReadOnly(false);
  634. var record = Ext.getCmp('grid').selModel.lastSelected;
  635. var code = record.data['sd_forecastcode'];
  636. if(code == null || code == ''){
  637. showError("请先选择预测单号!");
  638. t.setHideTrigger(true);
  639. t.setReadOnly(true);
  640. } else {
  641. t.dbBaseCondition = "sf_code='" + code + "'";
  642. }
  643. }
  644. },
  645. /* 'field[name=sa_sellercode]' : {// 自动带事业部
  646. aftertrigger: function(f, r) {
  647. var v = r.get('em_depart');
  648. if(!Ext.isEmpty(v)) {
  649. var n = f.up('form').down('#sa_parentorname');
  650. console.log(n);
  651. if (n && n.store.findRecord('value', v)) {
  652. n.setValue(v);
  653. }
  654. }
  655. }
  656. },*/
  657. /**
  658. * 是否使用客户物料对照表
  659. */
  660. 'field[name=sa_statuscode]': {
  661. afterrender: function(f) {
  662. if('ENTERING' == f.getValue()) {
  663. me['UseCustomerProduct'] = me.getSetting('UseCustomerProduct');
  664. }
  665. }
  666. },
  667. /**
  668. * 将客户编号传入
  669. */
  670. 'dbfindtrigger[name=sd_prodcode]': {
  671. focus: function(t) {
  672. if(me.UseCustomerProduct) {
  673. t.setHideTrigger(false);
  674. t.setReadOnly(false);
  675. var cust = Ext.getCmp('sa_custcode').getValue();
  676. if(cust != null && cust != '') {
  677. t.dbOrderby = "ORDER BY case when cp_custcode='" + cust + "' then 0 else 1 end,PR_CODE DESC";
  678. } else {
  679. t.dbOrderby = null;
  680. }
  681. }
  682. }
  683. },
  684. 'erpRefreshSyncButton': {
  685. afterrender: function(btn) {
  686. var form = btn.ownerCt.ownerCt,
  687. s = form.down('#sa_statuscode'),
  688. v = form.down('#sa_sync');
  689. if (s.getValue() != 'AUDITED' || (v && v.getValue() == null)) {
  690. btn.hide();
  691. }
  692. }
  693. }
  694. });
  695. },
  696. onGridItemClick: function(selModel, record){//grid行选择
  697. if(!selModel.ownerCt.readOnly){
  698. this.GridUtil.onGridItemClick(selModel, record);
  699. }
  700. },
  701. getRecordByPrCode: function(){
  702. if(this.gridLastSelected && this.gridLastSelected.findable){
  703. var data = Ext.getCmp('grid').store.data.items[this.gridLastSelected.index].data;
  704. var code = data.pd_prodcode;
  705. if(code != null && code!= ''){//看用户输入了编号没有
  706. var str = "sd_prodcode='" + code + "'";
  707. this.GridUtil.getRecordByCode({caller: 'Sale', condition: str});
  708. }
  709. }
  710. },
  711. getForm: function(btn){
  712. return btn.ownerCt.ownerCt;
  713. },
  714. beforeSaveSale: function(){
  715. var cop = Ext.getCmp('sa_cop');
  716. if(cop && (!cop.value || cop.value=='')) {
  717. cop.setValue(en_uu);
  718. }
  719. var grid = Ext.getCmp('grid');
  720. var cust = Ext.getCmp('sa_custid').value;
  721. if(cust == null || cust == '' || cust == '0' || cust == 0){
  722. showError('未选择客户,或客户编号无效!');
  723. return;
  724. }
  725. var items = grid.store.data.items;
  726. var bool = true, code = Ext.getCmp('sa_code').value;
  727. //数量不能为空或0
  728. Ext.each(items, function(item){
  729. item.set('sd_code', code);
  730. if('sd_bodycost' in item.data && 'sd_flash' in item.data && 'sd_sisvel' in item.data) {// check if {key} in {Object}
  731. item.set('sd_bodycost',item.data['sd_price'] - item.data['sd_flash'] - item.data['sd_sisvel']);
  732. }
  733. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  734. if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
  735. || item.data['sd_qty'] == 0){
  736. bool = false;
  737. showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
  738. }
  739. }
  740. });
  741. //物料交货日期不能小于录入日期
  742. /*var recorddate = Ext.Date.format(Ext.getCmp('sa_recorddate').value, 'Ymd');
  743. var basedate=null,index=0;
  744. Ext.each(items, function(item){
  745. if(item.dirty&&item.data[grid.necessaryField]!=null&&item.data[grid.necessaryField]!=""){
  746. //不要给默认录入日期 提示交期不能为空不让保存
  747. if(item.data['sd_delivery'] == null){
  748. if(index!=0){
  749. item.set('sd_delivery',basedate);
  750. }else {
  751. bool=false;
  752. showError('明细行第'+item.data['sd_detno']+'行交货日期为空 不能保存!');
  753. return ;
  754. }
  755. } else if(Ext.Date.format(item.data['sd_delivery'], 'Ymd') < recorddate){
  756. bool = false;
  757. showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
  758. }else {
  759. basedate=item.data['sd_delivery'];
  760. }
  761. index++;
  762. }
  763. });*/
  764. var cr = Ext.getCmp('sa_currency');
  765. if(cr && cr.getValue() == 'RMB') {
  766. var record = grid.store.findRecord('sd_taxrate', 0);
  767. if (record) {
  768. }
  769. }
  770. //保存sale
  771. if(bool)
  772. this.FormUtil.beforeSave(this);
  773. },
  774. beforeUpdate: function(){
  775. var grid = Ext.getCmp('grid');
  776. var cust = Ext.getCmp('sa_custid').value;
  777. var items = grid.store.data.items, sacode = Ext.getCmp('sa_code').value;
  778. var bool = true;
  779. if(cust == null || cust == '' || cust == '0' || cust == 0){
  780. showError('未选择客户,或客户编号无效!');
  781. return;
  782. }
  783. //数量不能为空或0
  784. Ext.each(items, function(item){
  785. item.set('sd_code', sacode);
  786. if('sd_bodycost' in item.data && 'sd_flash' in item.data && 'sd_sisvel' in item.data) {// check if {key} in {Object}
  787. item.set('sd_bodycost',item.data['sd_price'] - item.data['sd_flash'] - item.data['sd_sisvel']);
  788. }
  789. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  790. if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
  791. || item.data['sd_qty'] == 0){
  792. bool = false;
  793. showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
  794. }
  795. }
  796. });
  797. //保存
  798. if(bool)
  799. this.FormUtil.onUpdate(this);
  800. },
  801. getPmcWindow : function() {
  802. var me = this;
  803. return Ext.create('Ext.window.Window',{
  804. width: 330,
  805. height: 180,
  806. closeAction: 'hide',
  807. cls: 'custom-blue',
  808. title:'<h1>更改PMC交期</h1>',
  809. layout: {
  810. type: 'vbox'
  811. },
  812. items:[{
  813. width:'100%',
  814. html: '<div style="background:transparent;border:none;width:100%;height:30px;' +
  815. 'color:#036;vertical-align:middle;line-height:30px;font-size:14px;">' +
  816. '*注:修改订单交期请制作销售变更单<a style="float:right" href="javascript:' +
  817. 'openTable(\'变更交期\',\'jsps/scm/sale/saleChange.jsp?whoami=SaleChange\',\'SaleChange\');">进入</a></div>'
  818. },{
  819. margin: '5 0 0 5',
  820. xtype:'datefield',
  821. fieldLabel:'PMC回复交期',
  822. name:'pmcdate',
  823. format:'Y-m-d',
  824. id:'pmcdate'
  825. },{
  826. margin: '5 0 0 5',
  827. xtype: 'fieldcontainer',
  828. fieldLabel: '全部更新',
  829. combineErrors: false,
  830. defaults: {
  831. hideLabel: true
  832. },
  833. layout: {
  834. type: 'column',
  835. defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
  836. },
  837. items: [{
  838. xtype:'checkbox',
  839. columnidth: 0.4,
  840. fieldLabel:'全部更新',
  841. name:'allupdate',
  842. id:'allupdate'
  843. },{
  844. xtype:'displayfield',
  845. fieldStyle:'color:red',
  846. columnidth: 0.6,
  847. value:' *更改当前所有明细'
  848. }]
  849. }],
  850. buttonAlign:'center',
  851. buttons:[{
  852. xtype:'button',
  853. text:'保存',
  854. width:60,
  855. iconCls: 'x-button-icon-save',
  856. handler:function(btn){
  857. var w = btn.up('window');
  858. me.savePmc(w);
  859. w.hide();
  860. }
  861. },{
  862. xtype:'button',
  863. columnWidth:0.1,
  864. text:'关闭',
  865. width:60,
  866. iconCls: 'x-button-icon-close',
  867. margin:'0 0 0 10',
  868. handler:function(btn){
  869. btn.up('window').hide();
  870. }
  871. }]
  872. });
  873. },
  874. getYesWindow : function() {
  875. var me = this;
  876. return Ext.create('Ext.window.Window',{
  877. width: 330,
  878. height: 180,
  879. closeAction: 'hide',
  880. cls: 'custom-blue',
  881. title:'<h1>更改PMC承诺出货日期</h1>',
  882. layout: {
  883. type: 'vbox'
  884. },
  885. items:[{
  886. margin: '5 0 0 5',
  887. xtype:'datefield',
  888. fieldLabel:'PMC承诺出货日期',
  889. name:'yesdate',
  890. format:'Y-m-d',
  891. id:'yesdate'
  892. },{
  893. margin: '5 0 0 5',
  894. xtype: 'fieldcontainer',
  895. fieldLabel: '全部更新',
  896. combineErrors: false,
  897. defaults: {
  898. hideLabel: true
  899. },
  900. layout: {
  901. type: 'column',
  902. defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
  903. },
  904. items: [{
  905. xtype:'checkbox',
  906. columnidth: 0.4,
  907. fieldLabel:'全部更新',
  908. name:'allupdate',
  909. id:'allupdate'
  910. },{
  911. xtype:'displayfield',
  912. fieldStyle:'color:red',
  913. columnidth: 0.6,
  914. value:' *更改当前所有明细'
  915. }]
  916. }],
  917. buttonAlign:'center',
  918. buttons:[{
  919. xtype:'button',
  920. text:'保存',
  921. width:60,
  922. iconCls: 'x-button-icon-save',
  923. handler:function(btn){
  924. var w = btn.up('window');
  925. me.saveYes(w);
  926. w.hide();
  927. }
  928. },{
  929. xtype:'button',
  930. columnWidth:0.1,
  931. text:'关闭',
  932. width:60,
  933. iconCls: 'x-button-icon-close',
  934. margin:'0 0 0 10',
  935. handler:function(btn){
  936. btn.up('window').hide();
  937. }
  938. }]
  939. });
  940. },
  941. saveYes: function(w) {
  942. var pmcdate = w.down('field[name=yesdate]').getValue(),
  943. grid = Ext.getCmp('grid'),
  944. record = grid.getSelectionModel().getLastSelected();
  945. if(!pmcdate && !delivery) {
  946. showError('请先设置PMC承诺出货日期.') ;
  947. return;
  948. } else if(Ext.Date.format(pmcdate, 'Y-m-d') < Ext.Date.format(record.data.sd_pmcdate, 'Y-m-d')){
  949. showError('PMC承诺出货日期小于PMC承诺入库日期') ;
  950. return;
  951. } else {
  952. var allupdate = w.down('field[name=allupdate]').getValue();
  953. var dd = {
  954. sd_id : record.data.sd_id,
  955. sd_said : record.data.sd_said,
  956. yesdate : pmcdate ? Ext.Date.format(pmcdate,'Y-m-d') : null,
  957. allupdate : allupdate ? 1 : 0
  958. };
  959. Ext.Ajax.request({
  960. url : basePath +'scm/sale/updateyesdate.action',
  961. params : {
  962. _noc: 1,
  963. data: unescape(Ext.JSON.encode(dd))
  964. },
  965. method : 'post',
  966. callback : function(opt, s, res){
  967. var r = new Ext.decode(res.responseText);
  968. if(r.success){
  969. showMessage('提示', '更新成功!', 1000);
  970. } else if(r.exceptionInfo){
  971. showError(r.exceptionInfo);
  972. } else{
  973. saveFailure();
  974. }
  975. }
  976. });
  977. }
  978. },
  979. savePmc: function(w) {
  980. var pmcdate = w.down('field[name=pmcdate]').getValue(),
  981. grid = Ext.getCmp('grid'),
  982. record = grid.getSelectionModel().getLastSelected();
  983. if(!pmcdate && !delivery) {
  984. showError('请先设置PMC回复日期.') ;
  985. return;
  986. } else {
  987. var allupdate = w.down('field[name=allupdate]').getValue();
  988. var dd = {
  989. sd_id : record.data.sd_id,
  990. sd_said : record.data.sd_said,
  991. pmcdate : pmcdate ? Ext.Date.format(pmcdate,'Y-m-d') : null,
  992. allupdate : allupdate ? 1 : 0
  993. };
  994. Ext.Ajax.request({
  995. url : basePath +'scm/sale/updatepmc.action',
  996. params : {
  997. _noc: 1,
  998. data: unescape(Ext.JSON.encode(dd))
  999. },
  1000. method : 'post',
  1001. callback : function(opt, s, res){
  1002. var r = new Ext.decode(res.responseText);
  1003. if(r.success){
  1004. showMessage('提示', '更新成功!', 1000);
  1005. } else if(r.exceptionInfo){
  1006. showError(r.exceptionInfo);
  1007. } else{
  1008. saveFailure();
  1009. }
  1010. }
  1011. });
  1012. }
  1013. },
  1014. UpdatePmc:function(record){
  1015. var win = this.pmcwindow;
  1016. if (!win) {
  1017. win = this.getPmcWindow();
  1018. }
  1019. win.show();
  1020. },
  1021. UpdateYesDate:function(record){
  1022. var win = this.yeswindow;
  1023. if (!win) {
  1024. win = this.getYesWindow();
  1025. }
  1026. win.show();
  1027. },
  1028. /**
  1029. *销售订单拆分
  1030. * */
  1031. SaleSplit:function(record){
  1032. var me=this,originaldetno=Number(record.data.sd_detno);
  1033. var said=record.data.sd_said;
  1034. var sdid=record.data.sd_id;
  1035. Ext.create('Ext.window.Window',{
  1036. width:850,
  1037. height:'80%',
  1038. iconCls:'x-grid-icon-partition',
  1039. title:'<h1>销售订单拆分</h1>',
  1040. id:'win',
  1041. items:[{
  1042. xtype:'form',
  1043. layout:'column',
  1044. region:'north',
  1045. frame:true,
  1046. defaults:{
  1047. xtype:'textfield',
  1048. columnWidth:0.5,
  1049. readOnly:true,
  1050. fieldStyle:'background:#f0f0f0;border: 0px solid #8B8970;color:blue;'
  1051. },
  1052. items:[{
  1053. fieldLabel:'销售单号',
  1054. value:record.data.sd_code,
  1055. id:'sacode'
  1056. },{
  1057. fieldLabel:'产品编号' ,
  1058. value:record.data.sd_prodcode
  1059. },{
  1060. fieldLabel:'产品名称',
  1061. value:record.data.pr_detail
  1062. },{
  1063. fieldLabel:'原序号' ,
  1064. value:record.data.sd_detno
  1065. },{
  1066. fieldLabel:'原数量',
  1067. value:record.data.sd_qty
  1068. }],
  1069. buttonAlign:'center',
  1070. buttons:[{
  1071. xtype:'button',
  1072. columnWidth:0.12,
  1073. text:'保存',
  1074. width:60,
  1075. iconCls: 'x-button-icon-save',
  1076. margin:'0 0 0 30',
  1077. handler:function(btn){
  1078. var store=Ext.getCmp('smallgrid').getStore();
  1079. var count=0;
  1080. var jsonData=new Array();
  1081. var dd;
  1082. Ext.Array.each(store.data.items,function(item){
  1083. if(item.data.sd_qty!=0&&item.data.sd_delivery!=null&&item.data.sd_qty>0){
  1084. if(item.dirty){
  1085. dd=new Object();
  1086. //说明是新增批次
  1087. if(item.data.sd_delivery)
  1088. dd['sd_delivery']=Ext.Date.format(item.data.sd_delivery, 'Y-m-d');
  1089. if(item.data.sd_pmcdate)
  1090. dd['sd_pmcdate']=Ext.Date.format(item.data.sd_pmcdate, 'Y-m-d');
  1091. dd['sd_qty']=item.data.sd_qty;
  1092. dd['sd_id']=item.data.sd_id;
  1093. dd['sd_detno']=item.data.sd_detno;
  1094. jsonData.push(Ext.JSON.encode(dd));
  1095. }
  1096. count+=Number(item.data.sd_qty);
  1097. }
  1098. });
  1099. var assqty=Number(record.data.sd_qty);
  1100. if(count!=assqty){
  1101. showError('分拆数量必须等于原数量!') ;
  1102. return;
  1103. }else{
  1104. var r=new Object();
  1105. r['sd_id']=record.data.sd_id;
  1106. r['sd_said']=record.data.sd_said;
  1107. r['sd_detno']=record.data.sd_detno;
  1108. if(record.data.sd_pmcdate)
  1109. r['sd_pmcdate']=Ext.Date.format(record.data.sd_pmcdate,'Y-m-d');
  1110. if(record.data.sd_delivery)
  1111. r['sd_delivery']=Ext.Date.format(record.data.sd_delivery,'Y-m-d');
  1112. var params=new Object();
  1113. params.formdata = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  1114. params.data = unescape(jsonData.toString().replace(/\\/g,"%"));
  1115. Ext.Ajax.request({
  1116. url : basePath +'scm/sale/splitSale.action',
  1117. params : params,
  1118. waitMsg:'拆分中...',
  1119. method : 'post',
  1120. callback : function(options,success,response){
  1121. var localJson = new Ext.decode(response.responseText);
  1122. if(localJson.success){
  1123. saveSuccess(function(){
  1124. //add成功后刷新页面进入可编辑的页面
  1125. me.loadSplitData(originaldetno,said,record);
  1126. });
  1127. } else if(localJson.exceptionInfo){
  1128. var str = localJson.exceptionInfo;
  1129. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1130. str = str.replace('AFTERSUCCESS', '');
  1131. saveSuccess(function(){
  1132. //add成功后刷新页面进入可编辑的页面
  1133. me.loadSplitData(originaldetno,said,record);
  1134. });
  1135. showError(str);
  1136. } else {
  1137. showError(str);
  1138. return;
  1139. }
  1140. } else{
  1141. saveFailure();
  1142. }
  1143. }
  1144. });
  1145. }
  1146. }
  1147. },{
  1148. xtype:'button',
  1149. columnWidth:0.1,
  1150. text:'关闭',
  1151. width:60,
  1152. iconCls: 'x-button-icon-close',
  1153. margin:'0 0 0 10',
  1154. handler:function(btn){
  1155. Ext.getCmp('win').close();
  1156. }
  1157. }]
  1158. },{
  1159. xtype:'gridpanel',
  1160. region:'south',
  1161. id:'smallgrid',
  1162. layout:'fit',
  1163. height:'80%',
  1164. columnLines:true,
  1165. store:Ext.create('Ext.data.Store',{
  1166. fields:[{name:'sd_delivery',type:'date'},{name:'sd_qty',type:'int'},{name:'sd_sendqty',type:'int'},{name:'sd_ysendnotify',type:'int'},{name:'sd_id',type:'int'},{name:'sd_pmcdate',type:'date'}],
  1167. data:[]
  1168. }),
  1169. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  1170. clicksToEdit: 1,
  1171. listeners:{
  1172. 'edit':function(editor,e,Opts){
  1173. var record=e.record;
  1174. var version=record.data.ma_version;
  1175. if(version){
  1176. e.record.reject();
  1177. Ext.Msg.alert('提示','不能修改已拆分明细!');
  1178. }
  1179. }
  1180. }
  1181. })],
  1182. tbar: [{
  1183. tooltip: '添加批次',
  1184. iconCls: 'x-button-icon-add',
  1185. width:25,
  1186. handler : function() {
  1187. var store = Ext.getCmp('smallgrid').getStore();
  1188. var r = new Object();
  1189. r.sd_delivery=record.get('sd_delivery');
  1190. r.sd_pmcdate=record.get('sd_pmcdate');
  1191. r.sd_qty=0;
  1192. r.sd_id=0;
  1193. r.sd_detno=store.getCount()+1;
  1194. store.insert(store.getCount(), r);
  1195. }
  1196. }, {
  1197. tooltip: '删除批次',
  1198. width:25,
  1199. itemId: 'delete',
  1200. iconCls: 'x-button-icon-delete',
  1201. handler: function(btn) {
  1202. var sm = Ext.getCmp('smallgrid').getSelectionModel();
  1203. var record=sm.getSelection();
  1204. var sd_id=record[0].data.sd_id;
  1205. if(sd_id&&sd_id!=0){
  1206. Ext.Msg.alert('提示','不能删除已拆批次或原始行号!');
  1207. return;
  1208. }
  1209. var store=Ext.getCmp('smallgrid').getStore();
  1210. store.remove(record);
  1211. if (store.getCount() > 0) {
  1212. sm.select(0);
  1213. }
  1214. },
  1215. disabled: true
  1216. }],
  1217. listeners:{
  1218. itemmousedown:function(selmodel, record){
  1219. selmodel.ownerCt.down('#delete').setDisabled(false);
  1220. },
  1221. afterrender : function(grid) {
  1222. var res = me.getSetting('Sale.sd_delivery');
  1223. if(res) {
  1224. grid.down('gridcolumn[dataIndex=sd_delivery]').hide();
  1225. }
  1226. res = me.getSetting('Sale.sd_pmcdate');
  1227. if(res) {
  1228. grid.down('gridcolumn[dataIndex=sd_pmcdate]').hide();
  1229. }
  1230. }
  1231. },
  1232. columns:[{
  1233. dataIndex:'sd_detno',
  1234. header:'序号',
  1235. format:'0',
  1236. xtype:'numbercolumn'
  1237. },{
  1238. dataIndex:'sd_delivery',
  1239. header:'交货日期',
  1240. xtype:'datecolumn',
  1241. width:120,
  1242. editable:true,
  1243. renderer:function(val,meta,record){
  1244. if(record.data.ma_version){
  1245. meta.tdCls = "x-grid-cell-renderer-cl";
  1246. }
  1247. if(val)
  1248. return Ext.Date.format(val, 'Y-m-d');
  1249. else return null;
  1250. },
  1251. editor:{
  1252. xtype: 'datefield',
  1253. format:'Y-m-d'
  1254. }
  1255. },{
  1256. dataIndex:'sd_pmcdate',
  1257. header:'PMC回复日期',
  1258. xtype:'datecolumn',
  1259. width:120,
  1260. editable:true,
  1261. renderer:function(val,meta,record){
  1262. if(record.data.ma_version){
  1263. meta.tdCls = "x-grid-cell-renderer-cl";
  1264. }
  1265. if(val)
  1266. return Ext.Date.format(val, 'Y-m-d');
  1267. else return null;
  1268. },
  1269. editor:{
  1270. xtype: 'datefield',
  1271. format:'Y-m-d'
  1272. }
  1273. },{
  1274. dataIndex:'sd_qty',
  1275. header:'数量',
  1276. width:120,
  1277. xtype:'numbercolumn',
  1278. editable:true,
  1279. renderer:function(val,meta,record){
  1280. if(record.data.ma_version){
  1281. meta.tdCls = "x-grid-cell-renderer-cl";
  1282. }
  1283. return val;
  1284. },
  1285. editor:{
  1286. xtype:'numberfield',
  1287. format:'0',
  1288. hideTrigger: true
  1289. }
  1290. },{
  1291. dataIndex:'sd_yqty',
  1292. header:'已转发货数',
  1293. xtype:'numbercolumn',
  1294. width:100,
  1295. editable:false
  1296. },{
  1297. dataIndex:'sd_sendqty',
  1298. header:'已转通知数',
  1299. xtype:'numbercolumn',
  1300. width:100,
  1301. editable:false
  1302. },{
  1303. dataIndex:'sd_id',
  1304. header:'sdid',
  1305. width:0,
  1306. xtype:'numbercolumn',
  1307. editable:true,
  1308. editor:{
  1309. xtype:'numberfield',
  1310. format:'0',
  1311. hideTrigger: true
  1312. }
  1313. }]
  1314. }]
  1315. }).show();
  1316. this.loadSplitData(originaldetno,said,record);
  1317. },
  1318. loadSplitData:function(detno,said,record){
  1319. var grid=Ext.getCmp('smallgrid');
  1320. grid.setLoading(true);//loading...
  1321. Ext.Ajax.request({//拿到grid的columns
  1322. url : basePath + "common/loadNewGridStore.action",
  1323. params:{
  1324. caller:'SaleSplit',
  1325. condition:"sd_detno="+detno+" AND sd_said="+said+" order by sd_id asc"
  1326. },
  1327. method : 'post',
  1328. callback : function(options,success,response){
  1329. grid.setLoading(false);
  1330. var res = new Ext.decode(response.responseText);
  1331. if(res.exceptionInfo){
  1332. showError(res.exceptionInfo);return;
  1333. }
  1334. var data = res.data;
  1335. if(!data || data.length == 0){
  1336. grid.store.removeAll();
  1337. var o=new Object();
  1338. o.sd_detno=detno;
  1339. o.sd_delivery=record.data.sd_delivery;
  1340. o.sd_pmcdate=record.data.sd_pmcdate;
  1341. o.sd_qty=record.data.sd_qty;
  1342. o.sd_yqty=record.data.sd_yqty;
  1343. o.sd_sendqty=record.data.sd_sendqty;
  1344. o.sd_id=record.data.sd_id;
  1345. data.push(o);
  1346. }
  1347. grid.store.loadData(data);
  1348. }
  1349. });
  1350. },
  1351. /**
  1352. * 排程
  1353. */
  1354. schedule: function(record) {
  1355. var width = Ext.isIE ? screen.width*0.7*0.9 : '80%',
  1356. height = Ext.isIE ? screen.height*0.75 : '100%';
  1357. var sd_id = record.get('sd_id');
  1358. Ext.Ajax.request({
  1359. url : basePath + "scm/sale/checkSaleDetailDet.action",
  1360. params: {
  1361. whereString: "sd_id="+sd_id
  1362. },
  1363. method : 'post',
  1364. async: false,
  1365. callback:function(options,success,response){
  1366. var res = new Ext.decode(response.responseText);
  1367. if(res.exceptionInfo){
  1368. showError(res.exceptionInfo);return;
  1369. }
  1370. }
  1371. });
  1372. Ext.create('Ext.Window', {
  1373. width: width,
  1374. height: height,
  1375. autoShow: true,
  1376. layout: 'anchor',
  1377. items: [{
  1378. tag : 'iframe',
  1379. frame : true,
  1380. anchor : '100% 100%',
  1381. layout : 'fit',
  1382. html : '<iframe id="iframe_dbfind" src="' + basePath + 'jsps/scm/sale/saleDetail.jsp?formCondition=sd_id='
  1383. + sd_id + '&gridCondition=sdd_sdid=' + sd_id + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  1384. }]
  1385. });
  1386. },
  1387. /**
  1388. * 复制订单
  1389. */
  1390. copy: function(){
  1391. var me = this, form = Ext.getCmp('form');
  1392. var v = form.down('#sa_id').value;
  1393. if(v > 0) {
  1394. form.setLoading(true);
  1395. Ext.Ajax.request({
  1396. url: basePath + 'scm/sale/copySale.action',
  1397. params: {
  1398. caller : caller,
  1399. id : v
  1400. },
  1401. callback: function(opt, s, r){
  1402. form.setLoading(false);
  1403. var res = Ext.decode(r.responseText);
  1404. if(res.data) {
  1405. var url = 'jsps/scm/sale/sale.jsp?whoami=' + caller
  1406. + '&formCondition=sa_idIS' + res.data.id + '&gridCondition=sd_saidIS'
  1407. + res.data.id;
  1408. showMessage('提示', '复制成功', 2000);
  1409. me.FormUtil.onAdd(null, '订单', url);
  1410. } else {
  1411. showError(res.exceptionInfo);
  1412. }
  1413. }
  1414. });
  1415. }
  1416. },
  1417. /**
  1418. * 更新比例
  1419. */
  1420. updateDiscount: function() {
  1421. var win = this.discountWin;
  1422. if(!win) {
  1423. win = this.discountWin = this.createDiscountWin();
  1424. }
  1425. win.show();
  1426. },
  1427. createDiscountWin: function() {
  1428. var me = this, grid = Ext.getCmp('grid'), arr = new Array();
  1429. grid.store.each(function(){
  1430. if(this.get('sd_id') > 0) {
  1431. arr.push({
  1432. sd_code: this.get('sd_code'),
  1433. sd_detno: this.get('sd_detno'),
  1434. sd_olddiscount: this.get('sd_discount'),
  1435. sd_discount: this.get('sd_discount')
  1436. });
  1437. }
  1438. });
  1439. return new Ext.window.Window({
  1440. width: 600,
  1441. height: 400,
  1442. title: '更新比例',
  1443. cls: 'custom-blue',
  1444. closeAction: 'hide',
  1445. items: [{
  1446. xtype: 'grid',
  1447. width: '100%',
  1448. height: 300,
  1449. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  1450. clicksToEdit: 1
  1451. })],
  1452. columnLines: true,
  1453. columns: [{
  1454. text: '订单号',
  1455. hidden: true,
  1456. dataIndex: 'sd_code'
  1457. },{
  1458. text: '序号',
  1459. xtype: 'numbercolumn',
  1460. dataIndex: 'sd_detno',
  1461. format: '0',
  1462. flex: 1
  1463. },{
  1464. text: '原比例%',
  1465. dataIndex: 'sd_olddiscount',
  1466. align: 'center',
  1467. flex: 4
  1468. },{
  1469. text: '新比例%',
  1470. dataIndex: 'sd_discount',
  1471. align: 'center',
  1472. editor: {
  1473. xtype: 'numberfield',
  1474. format: '0.00'
  1475. },
  1476. flex: 4
  1477. }],
  1478. store: new Ext.data.Store({
  1479. fields: ['sd_code','sd_detno','sd_olddiscount','sd_discount'],
  1480. data: arr
  1481. })
  1482. },{
  1483. margin: '0 0 0 5',
  1484. xtype: 'checkbox',
  1485. checked: true,
  1486. boxLabel: '同时修改到通知单、出货单、Invoice和包装单'
  1487. }],
  1488. buttonAlign: 'center',
  1489. buttons: [{
  1490. text: $I18N.common.button.erpConfirmButton,
  1491. cls: 'x-btn-blue',
  1492. handler: function(b) {
  1493. var w = b.ownerCt.ownerCt;
  1494. me.onDiscountChange(w.down('grid'), w.down('checkbox').getValue());
  1495. w.hide();
  1496. }
  1497. },{
  1498. text: $I18N.common.button.erpCloseButton,
  1499. cls: 'x-btn-blue',
  1500. handler: function(b) {
  1501. b.ownerCt.ownerCt.hide();
  1502. }
  1503. }]
  1504. });
  1505. },
  1506. onDiscountChange: function(grid, oth) {
  1507. var data = new Array(), id = Ext.getCmp('sa_id').value;
  1508. grid.store.each(function(){
  1509. if(this.dirty)
  1510. data.push(this.data);
  1511. });
  1512. Ext.Ajax.request({
  1513. url: basePath + 'scm/sale/updateDiscount.action',
  1514. params: {
  1515. caller: caller,
  1516. id: id,
  1517. data: Ext.encode(data),
  1518. _noc: 1,
  1519. oth: oth
  1520. },
  1521. callback: function(opt, s, res) {
  1522. var r = Ext.decode(res.responseText);
  1523. if(r.success) {
  1524. alert('修改成功.');
  1525. var g = Ext.getCmp('grid');
  1526. g.GridUtil.loadNewStore(g, {
  1527. caller: caller,
  1528. condition: 'sd_said=' + id
  1529. });
  1530. } else {
  1531. alert('操作失败.');
  1532. }
  1533. }
  1534. });
  1535. },
  1536. getSetting: function(type) {
  1537. var result = false;
  1538. Ext.Ajax.request({
  1539. url : basePath + 'common/getFieldData.action',
  1540. async: false,
  1541. params: {
  1542. caller: 'Setting',
  1543. field: 'se_value',
  1544. condition: 'se_what=\'' + type + '\''
  1545. },
  1546. method : 'post',
  1547. callback : function(opt, s, res){
  1548. var r = new Ext.decode(res.responseText);
  1549. if(r.exceptionInfo){
  1550. showError(r.exceptionInfo);return;
  1551. } else if(r.success && r.data){
  1552. result = r.data == 'true';
  1553. }
  1554. }
  1555. });
  1556. return result;
  1557. },
  1558. getRandomNumber: function(table, type, codeField){
  1559. var me = this;
  1560. if(Ext.getCmp('sa_kind')){
  1561. var form = Ext.getCmp('form');
  1562. if(form){
  1563. table = table == null ? form.tablename : table;
  1564. }
  1565. type = type == null ? 2 : type;
  1566. codeField = codeField || form.codeField;
  1567. Ext.Ajax.request({
  1568. url : basePath + 'scm/sale/getCodeString.action',
  1569. async: false,//同步ajax请求
  1570. params: {
  1571. caller: caller,//如果table==null,则根据caller去form表取对应table
  1572. table: table,
  1573. type: type,
  1574. conKind:Ext.getCmp('sa_kind').getValue()
  1575. },
  1576. method : 'post',
  1577. callback : function(options,success,response){
  1578. var localJson = new Ext.decode(response.responseText);
  1579. if(localJson.exceptionInfo){
  1580. showError(localJson.exceptionInfo);
  1581. }
  1582. if(localJson.success){
  1583. Ext.getCmp(codeField).setValue(localJson.code);
  1584. }
  1585. }
  1586. });
  1587. } else {
  1588. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  1589. }
  1590. }
  1591. });