Sale.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.plm.scm.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','plm.scm.Sale','core.grid.Panel2','core.toolbar.Toolbar','core.form.FileField','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit',
  11. 'core.button.Consign','core.button.End','core.button.ResEnd','core.button.TurnNotify','core.button.FeatureDefinition','core.button.FeatureView',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.form.SpecialContainField'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpGridPanel2': {
  18. itemclick: function(selModel, record){
  19. if(record.data.sd_id != 0 && record.data.sd_id != null && record.data.sd_id != ''){
  20. Ext.getCmp('featuredefinition').setDisabled(false);
  21. Ext.getCmp('featureview').setDisabled(false);
  22. Ext.getCmp('bomopen').setDisabled(false);
  23. }
  24. if(!Ext.getCmp('grid').readOnly){
  25. this.onGridItemClick(selModel, record);
  26. }
  27. }
  28. },
  29. 'erpSaveButton': {
  30. click: function(btn){
  31. var form = me.getForm(btn), s=Ext.getCmp('sa_source');
  32. if(s) {
  33. var source = s.value;
  34. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  35. me.getSetting(function(s){
  36. if(s) {
  37. if(source == 'TBNOTIFY'){
  38. me.BaseUtil.getRandomNumber('Sale!PLM!TB');//自动添加编号
  39. } else if(source == 'MAKENOTIFY'){
  40. me.BaseUtil.getRandomNumber('Sale!PLM!ZZ');//自动添加编号
  41. } else if(source == 'TRIAL'){
  42. me.BaseUtil.getRandomNumber('Sale!PLM!BL');//自动添加编号
  43. } else if(source == 'EVTFAC'){
  44. me.BaseUtil.getRandomNumber('Sale!PLM!ES');//自动添加编号
  45. } else if(source == 'EVTPROJECT'){
  46. me.BaseUtil.getRandomNumber('Sale!PLM!ES');//自动添加编号
  47. } else if(source == 'DVT'){
  48. me.BaseUtil.getRandomNumber('Sale!PLM!DS');//自动添加编号
  49. } else {
  50. me.BaseUtil.getRandomNumber(caller);
  51. }
  52. } else {
  53. me.BaseUtil.getRandomNumber();
  54. }
  55. });
  56. }
  57. } else {
  58. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  59. me.BaseUtil.getRandomNumber();
  60. }
  61. }
  62. this.beforeSaveSale();
  63. }
  64. },
  65. 'erpDeleteButton' : {
  66. click: function(btn){
  67. me.FormUtil.onDelete({id: Number(Ext.getCmp('sa_id').value)});
  68. }
  69. },
  70. 'erpUpdateButton': {
  71. afterrender: function(btn){
  72. var status = Ext.getCmp('sa_statuscode');
  73. if(status && status.value != 'ENTERING'){
  74. btn.hide();
  75. }
  76. },
  77. click: function(btn){
  78. me.beforeUpdate();
  79. }
  80. },
  81. 'erpAddButton': {
  82. click: function(){
  83. me.FormUtil.onAdd('addSale', '试产订单', 'jsps/plm/scm/sale.jsp');
  84. }
  85. },
  86. 'erpDeleteDetailButton': {
  87. afterrender: function(btn){
  88. btn.ownerCt.add({
  89. xtype: 'erpFeatureDefinitionButton'
  90. });
  91. btn.ownerCt.add({
  92. xtype: 'erpFeatureViewButton'
  93. });
  94. btn.ownerCt.add({
  95. xtype:'button',
  96. text:'BOM多级展开',
  97. width:120,
  98. iconCls: 'x-button-icon-check',
  99. cls: 'x-btn-gray',
  100. id:'bomopen',
  101. style: {
  102. marginLeft: '10px'
  103. },
  104. disabled:true,
  105. handler:function(){
  106. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  107. var pr_code=record.data.sd_prodcode;
  108. var url="jsps/pm/bom/BOMStructQuery.jsp?whoami=BOMStruct!Struct!Query";
  109. var condition="";
  110. if(pr_code){
  111. condition+="pr_codeIS'"+pr_code+"'";
  112. }
  113. me.FormUtil.onAdd('BOMStruct'+ pr_code, 'BOM多级展开', url+"&condition="+condition);
  114. }
  115. });
  116. }
  117. },
  118. 'erpCloseButton': {
  119. click: function(btn){
  120. me.FormUtil.beforeClose(me);
  121. }
  122. },
  123. 'erpSubmitButton': {
  124. afterrender: function(btn){
  125. var status = Ext.getCmp('sa_statuscode');
  126. if(status && status.value != 'ENTERING'){
  127. btn.hide();
  128. }
  129. },
  130. click: function(btn){
  131. me.FormUtil.onSubmit(Ext.getCmp('sa_id').value);
  132. }
  133. },
  134. 'erpResSubmitButton': {
  135. afterrender: function(btn){
  136. var status = Ext.getCmp('sa_statuscode');
  137. if(status && status.value != 'COMMITED'){
  138. btn.hide();
  139. }
  140. },
  141. click: function(btn){
  142. me.FormUtil.onResSubmit(Ext.getCmp('sa_id').value);
  143. }
  144. },
  145. 'erpAuditButton': {
  146. afterrender: function(btn){
  147. var status = Ext.getCmp('sa_statuscode');
  148. if(status && status.value != 'COMMITED'){
  149. btn.hide();
  150. }
  151. },
  152. click: function(btn){
  153. me.FormUtil.onAudit(Ext.getCmp('sa_id').value);
  154. }
  155. },
  156. 'erpResAuditButton': {
  157. afterrender: function(btn){
  158. var status = Ext.getCmp('sa_statuscode');
  159. if(status && status.value != 'AUDITED'){
  160. btn.hide();
  161. }
  162. },
  163. click: function(btn){
  164. me.FormUtil.onResAudit(Ext.getCmp('sa_id').value);
  165. }
  166. },
  167. 'erpEndButton': {
  168. afterrender: function(btn){
  169. var status = Ext.getCmp('sa_statuscode');
  170. if(status && status.value != 'AUDITED'){
  171. btn.hide();
  172. }
  173. },
  174. click: function(btn){
  175. me.FormUtil.onEnd(Ext.getCmp('sa_id').value);
  176. }
  177. },
  178. 'combo[name=sa_source]':{
  179. change:function (field){
  180. var href=window.location.href;
  181. var arrstr=href.split("?");
  182. if(formCondition!=""){
  183. window.location.href =arrstr[0]+'?whoami=Sale!PLM!'+field.value+ '&formCondition=' +
  184. formCondition + '&gridCondition=' + gridCondition+'&source='+field.value;
  185. }else window.location.href =arrstr[0]+'?whoami=Sale!PLM!'+field.value+ '&source='+field.value;
  186. }
  187. },
  188. 'erpResEndButton': {
  189. afterrender: function(btn){
  190. var status = Ext.getCmp('sa_statuscode');
  191. if(status && status.value != 'FINISH'){
  192. btn.hide();
  193. }
  194. },
  195. click: function(btn){
  196. me.FormUtil.onResEnd(Ext.getCmp('sa_id').value);
  197. }
  198. },
  199. 'erpPrintButton': {
  200. click: function(btn){
  201. me.FormUtil.onPrint(Ext.getCmp('sa_id').value);
  202. }
  203. },
  204. 'field[name=sa_statuscode]': {
  205. change: function(f){
  206. var grid = Ext.getCmp('grid');
  207. if(grid && f.value != 'ENTERING' && f.value != 'COMMITED'){
  208. grid.setReadOnly(true);//只有未审核的订单,grid才能编辑
  209. }
  210. }
  211. },
  212. 'erpConsignButton': {
  213. afterrender: function(btn){
  214. var status = Ext.getCmp('sa_statuscode');
  215. if(status && status.value != 'AUDITED'){
  216. btn.hide();
  217. }
  218. }
  219. },
  220. 'dbfindtrigger[name=sd_batchcode]': {
  221. focus: function(t){
  222. t.setHideTrigger(false);
  223. t.setReadOnly(false);//用disable()可以,但enable()无效
  224. var record = Ext.getCmp('grid').selModel.getLastSelected();
  225. var pr = record.data['sd_prodcode'];
  226. if(pr == null || pr == ''){
  227. showError("请先选择料号!");
  228. t.setHideTrigger(true);
  229. t.setReadOnly(true);
  230. } else {
  231. var id = record.data['sd_warehouseid'];
  232. if(id == null || id == ''){
  233. id = Ext.getCmp('sd_warehouseid');
  234. if(id == null || id == '' || id== 0 ){
  235. showError("请先选择仓库!");
  236. t.setHideTrigger(true);
  237. t.setReadOnly(true);
  238. }
  239. } else {
  240. t.dbBaseCondition = "ba_warehouseid='" + id + "' AND ba_prodcode='" + pr + "'";
  241. }
  242. }
  243. }
  244. },
  245. 'erpFeatureDefinitionButton':{
  246. click: function(btn){
  247. var grid = Ext.getCmp('grid');
  248. var record = grid.selModel.lastSelected;
  249. if(record.data.sd_prodcode != null){
  250. Ext.Ajax.request({//拿到grid的columns
  251. url : basePath + "pm/bom/getDescription.action",
  252. params: {
  253. tablename: 'Product',
  254. field: 'pr_specvalue',
  255. condition: "pr_code='" + record.data.sd_prodcode + "'"
  256. },
  257. method : 'post',
  258. async: false,
  259. callback : function(options,success,response){
  260. var res = new Ext.decode(response.responseText);
  261. if(res.exceptionInfo){
  262. showError(res.exceptionInfo);return;
  263. }
  264. if(res.success){
  265. if(res.description != '' && res.description != null && res.description == 'NOTSPECIFIC'){
  266. var win = new Ext.window.Window({
  267. id : 'win',
  268. title: '生成特征料号',
  269. height: "90%",
  270. width: "70%",
  271. maximizable : true,
  272. buttonAlign : 'center',
  273. layout : 'anchor',
  274. items: [{
  275. tag : 'iframe',
  276. frame : true,
  277. anchor : '100% 100%',
  278. layout : 'fit',
  279. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  280. "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>'
  281. }]
  282. });
  283. win.show();
  284. } else {
  285. showError('物料特征必须为虚拟特征件');return;
  286. }
  287. }
  288. }
  289. });
  290. }
  291. }
  292. },
  293. 'erpFeatureViewButton':{
  294. click: function(btn){
  295. var grid = Ext.getCmp('grid');
  296. var record = grid.selModel.lastSelected;
  297. if(record.data.sd_prodcode != null){
  298. Ext.Ajax.request({//拿到grid的columns
  299. url : basePath + "pm/bom/getDescription.action",
  300. params: {
  301. tablename: 'Product',
  302. field: 'pr_specvalue',
  303. condition: "pr_code='" + record.data.sd_prodcode + "'"
  304. },
  305. method : 'post',
  306. async: false,
  307. callback : function(options,success,response){
  308. var res = new Ext.decode(response.responseText);
  309. if(res.exceptionInfo){
  310. showError(res.exceptionInfo);return;
  311. }
  312. if(res.success){
  313. if(res.description != '' && res.description != null && res.description == 'SPECIFIC'){
  314. var win = new Ext.window.Window({
  315. id : 'win' + record.data.sd_id,
  316. title: '特征查看',
  317. height: "90%",
  318. width: "70%",
  319. maximizable : true,
  320. buttonAlign : 'center',
  321. layout : 'anchor',
  322. items: [{
  323. tag : 'iframe',
  324. frame : true,
  325. anchor : '100% 100%',
  326. layout : 'fit',
  327. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  328. "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>'
  329. }]
  330. });
  331. win.show();
  332. } else {
  333. showError('物料特征必须为 虚拟特征件');return;
  334. }
  335. }
  336. }
  337. });
  338. }
  339. }
  340. },
  341. });
  342. },
  343. getSetting : function(fn) {
  344. var me = this;
  345. Ext.Ajax.request({
  346. url : basePath + 'common/getFieldData.action',
  347. async: false,
  348. params: {
  349. caller: 'Setting',
  350. field: 'se_value',
  351. condition: 'se_what=\'SalePLMType\''
  352. },
  353. method : 'post',
  354. callback : function(opt, s, res){
  355. var r = new Ext.decode(res.responseText);
  356. var t = false;
  357. if(r.exceptionInfo){
  358. showError(r.exceptionInfo);return;
  359. }
  360. if(r.success && r.data){
  361. t = r.data == 'true';
  362. }
  363. fn.call(me, t);
  364. }
  365. });
  366. },
  367. onGridItemClick: function(selModel, record){//grid行选择
  368. this.GridUtil.onGridItemClick(selModel, record);
  369. },
  370. getRecordByPrCode: function(){
  371. if(this.gridLastSelected && this.gridLastSelected.findable){
  372. var data = Ext.getCmp('grid').store.data.items[this.gridLastSelected.index].data;
  373. var code = data.pd_prodcode;
  374. if(code != null && code!= ''){//看用户输入了编号没有
  375. var str = "sd_prodcode='" + code + "'";
  376. this.GridUtil.getRecordByCode({caller: 'Sale', condition: str});
  377. }
  378. }
  379. },
  380. getForm: function(btn){
  381. return btn.ownerCt.ownerCt;
  382. },
  383. beforeSaveSale: function(){
  384. var grid = Ext.getCmp('grid');
  385. var items = grid.store.data.items,sacode=Ext.getCmp('sa_code').value;
  386. var bool = true;
  387. //数量不能为空或0
  388. var recorddate = Ext.Date.format(Ext.getCmp('sa_recorddate').value, 'Ymd');
  389. Ext.each(items, function(item){
  390. item.set('sd_code', sacode);
  391. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  392. if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
  393. || item.data['sd_qty'] == 0){
  394. bool = false;
  395. showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
  396. }
  397. }
  398. });
  399. var basedate=null,index=0;
  400. Ext.each(items, function(item){
  401. item.set('sd_code',sacode);
  402. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  403. if(item.data['sd_delivery'] == null){
  404. if(index!=0){
  405. item.set('sd_delivery',basedate);
  406. }else {
  407. bool=false;
  408. showError('明细行第'+item.data['sd_detno']+'行交货日期为空 不能更新!');
  409. return ;
  410. }
  411. } else if(Ext.Date.format(item.data['sd_delivery'], 'Ymd') < recorddate){
  412. bool = false;
  413. showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
  414. }else {
  415. basedate=item.data['sd_delivery'];
  416. }
  417. index++;
  418. }
  419. });
  420. //保存sale
  421. if(bool)
  422. this.FormUtil.beforeSave(this);
  423. },
  424. beforeUpdate: function(){
  425. var grid = Ext.getCmp('grid');
  426. var sacode = Ext.getCmp('sa_code').value;
  427. var items = grid.store.data.items;
  428. var bool = true;
  429. var recorddate = Ext.Date.format(Ext.getCmp('sa_recorddate').value, 'Ymd');
  430. //数量不能为空或0
  431. Ext.each(items, function(item){
  432. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  433. if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
  434. || item.data['sd_qty'] == 0){
  435. bool = false;
  436. showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
  437. }
  438. }
  439. });
  440. var recorddate = Ext.Date.format(Ext.getCmp('sa_date').value, 'Ymd');
  441. var basedate=null,index=0;
  442. Ext.each(items, function(item){
  443. item.set('sd_code',sacode);
  444. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  445. if(item.data['sd_delivery'] == null){
  446. if(index!=0){
  447. item.set('sd_delivery',basedate);
  448. }else {
  449. bool=false;
  450. showError('明细行第'+item.data['sd_detno']+'行交货日期为空 不能更新!');
  451. return ;
  452. }
  453. } else if(Ext.Date.format(item.data['sd_delivery'], 'Ymd') < recorddate){
  454. bool = false;
  455. showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
  456. }else {
  457. basedate=item.data['sd_delivery'];
  458. }
  459. index++;
  460. }
  461. });
  462. //保存
  463. if(bool)
  464. this.FormUtil.onUpdate(this);
  465. }
  466. });