Sale.js 57 KB

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