SaleAsk.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.drp.distribution.SaleAsk', {
  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','drp.distribution.SaleAsk','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.TurnSale','core.button.End','core.button.ResEnd','core.button.TurnNotify','core.button.FeatureDefinition',
  12. 'core.button.FeatureView','core.button.OutSchedule',
  13. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'erpGridPanel2': {
  19. itemclick: function(selModel, record){
  20. if(!Ext.getCmp('grid').readOnly){
  21. if(record.data.sd_id != 0 && record.data.sd_id != null && record.data.sd_id != ''){
  22. Ext.getCmp('featuredefinition').setDisabled(false);
  23. Ext.getCmp('featureview').setDisabled(false);
  24. Ext.getCmp('outschedule').setDisabled(false);
  25. }
  26. this.onGridItemClick(selModel, record);
  27. }
  28. }
  29. },
  30. 'erpDeleteDetailButton': {
  31. afterrender: function(btn){
  32. btn.ownerCt.add({
  33. xtype: 'erpFeatureDefinitionButton'
  34. });
  35. btn.ownerCt.add({
  36. xtype: 'erpFeatureViewButton'
  37. });
  38. btn.ownerCt.add({
  39. xtype: 'erpOutScheduleButton'
  40. });
  41. }
  42. },
  43. 'erpSaveButton': {
  44. click: function(btn){
  45. var form = me.getForm(btn);
  46. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  47. me.BaseUtil.getRandomNumber();//自动添加编号
  48. }
  49. this.beforeSaveSale();
  50. }
  51. },
  52. 'erpDeleteButton' : {
  53. click: function(btn){
  54. me.FormUtil.onDelete({id: Number(Ext.getCmp('sa_id').value)});
  55. }
  56. },
  57. 'erpUpdateButton': {
  58. afterrender: function(btn){
  59. var status = Ext.getCmp('sa_statuscode');
  60. if(status && status.value != 'ENTERING'){
  61. btn.hide();
  62. }
  63. },
  64. click: function(btn){
  65. me.beforeUpdate();
  66. }
  67. },
  68. 'erpAddButton': {
  69. click: function(){
  70. me.FormUtil.onAdd('addSaleAsk', '待确认销售单', 'jsps/drp/distribution/saleAsk.jsp');
  71. }
  72. },
  73. 'erpCloseButton': {
  74. click: function(btn){
  75. me.FormUtil.beforeClose(me);
  76. }
  77. },
  78. 'erpSubmitButton': {
  79. afterrender: function(btn){
  80. var status = Ext.getCmp('sa_statuscode');
  81. if(status && status.value != 'ENTERING'){
  82. btn.hide();
  83. }
  84. },
  85. click: function(btn){
  86. me.FormUtil.onSubmit(Ext.getCmp('sa_id').value);
  87. }
  88. },
  89. 'erpResSubmitButton': {
  90. afterrender: function(btn){
  91. var status = Ext.getCmp('sa_statuscode');
  92. if(status && status.value != 'COMMITED'){
  93. btn.hide();
  94. }
  95. },
  96. click: function(btn){
  97. me.FormUtil.onResSubmit(Ext.getCmp('sa_id').value);
  98. }
  99. },
  100. 'erpAuditButton': {
  101. afterrender: function(btn){
  102. var status = Ext.getCmp('sa_statuscode');
  103. if(status && status.value != 'COMMITED'){
  104. btn.hide();
  105. }
  106. },
  107. click: function(btn){
  108. me.FormUtil.onAudit(Ext.getCmp('sa_id').value);
  109. }
  110. },
  111. 'erpResAuditButton': {
  112. afterrender: function(btn){
  113. var status = Ext.getCmp('sa_statuscode');
  114. if(status && status.value != 'AUDITED'){
  115. btn.hide();
  116. }
  117. },
  118. click: function(btn){
  119. me.FormUtil.onResAudit(Ext.getCmp('sa_id').value);
  120. }
  121. },
  122. 'erpEndButton': {
  123. afterrender: function(btn){
  124. var status = Ext.getCmp('sa_statuscode');
  125. if(status && status.value != 'AUDITED'){
  126. btn.hide();
  127. }
  128. },
  129. click: function(btn){
  130. me.FormUtil.onEnd(Ext.getCmp('sa_id').value);
  131. }
  132. },
  133. 'erpResEndButton': {
  134. afterrender: function(btn){
  135. var status = Ext.getCmp('sa_statuscode');
  136. if(status && status.value != 'FINISH'){
  137. btn.hide();
  138. }
  139. },
  140. click: function(btn){
  141. me.FormUtil.onResEnd(Ext.getCmp('sa_id').value);
  142. }
  143. },
  144. 'erpPrintButton':{
  145. click:function(btn){
  146. var reportName="salelist";
  147. var condition='{Sale.sa_id}='+Ext.getCmp('sa_id').value+'';
  148. var id=Ext.getCmp('sa_id').value;
  149. me.FormUtil.onwindowsPrint(id,reportName,condition);
  150. }
  151. },
  152. 'field[name=sa_statuscode]': {
  153. change: function(f){
  154. var grid = Ext.getCmp('grid');
  155. if(grid && f.value != 'ENTERING' && f.value != 'COMMITED'){
  156. grid.setReadOnly(true);//只有未审核的订单,grid才能编辑
  157. }
  158. }
  159. },
  160. 'erpTurnSaleButton': {
  161. afterrender: function(btn){
  162. var status = Ext.getCmp('sa_statuscode');
  163. if(status && status.value != 'AUDITED'){
  164. btn.hide();
  165. }
  166. },
  167. click: function(btn){
  168. var grid = Ext.getCmp('grid');
  169. var form = Ext.getCmp('form');
  170. if(form.getForm().isValid()){
  171. //form里面数据
  172. Ext.each(form.items.items, function(item){
  173. if(item.xtype == 'numberfield'){
  174. //number类型赋默认值,不然sql无法执行
  175. if(item.value == null || item.value == ''){
  176. item.setValue(0);
  177. }
  178. }
  179. });
  180. var r = form.getValues();
  181. //去除ignore字段
  182. var keys = Ext.Object.getKeys(r), f;
  183. var reg = /[!@#$%^&*()'":,\/?]/;
  184. Ext.each(keys, function(k){
  185. f = form.down('#' + k);
  186. if(f && f.logic == 'ignore') {
  187. delete r[k];
  188. }
  189. //codeField值强制大写,自动过滤特殊字符
  190. if(k == form.codeField && !Ext.isEmpty(r[k])) {
  191. r[k] = r[k].trim().toUpperCase().replace(reg, '');
  192. }
  193. //获取新id
  194. if(k==form.keyField){
  195. Ext.Ajax.request({
  196. url : basePath + 'common/getId.action?seq=SALE_SEQ',
  197. method : 'get',
  198. async: false,
  199. callback : function(options,success,response){
  200. var rs = new Ext.decode(response.responseText);
  201. if(rs.exceptionInfo){
  202. showError(rs.exceptionInfo);return;
  203. }
  204. if(rs.success){
  205. r[k]=rs.id
  206. }
  207. }
  208. });
  209. }
  210. });
  211. }
  212. var param=new Array();
  213. var s = grid.getStore().data.items;//获取store里面的数据
  214. var dd;
  215. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  216. var data = s[i].data;
  217. dd = new Object();
  218. if(s[i].dirty){
  219. Ext.each(grid.columns, function(c){
  220. if((!c.isCheckerHd)&&(c.logic != 'ignore')){//只需显示,无需后台操作的字段,自动略去
  221. if(c.xtype == 'datecolumn'){
  222. c.format = c.format || 'Y-m-d';
  223. if(Ext.isDate(data[c.dataIndex])){
  224. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], c.format);
  225. } else {
  226. if(c.editor){
  227. dd[c.dataIndex] = Ext.Date.format(new Date(), c.format);//如果用户没输入日期,或输入有误,就给个默认日期,
  228. }
  229. }
  230. } else if(c.xtype == 'datetimecolumn'){
  231. if(Ext.isDate(data[c.dataIndex])){
  232. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
  233. } else {
  234. if(c.editor){
  235. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
  236. }
  237. }
  238. } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  239. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  240. dd[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  241. } else {
  242. dd[c.dataIndex] = s[i].data[c.dataIndex];
  243. }
  244. } else {
  245. dd[c.dataIndex] = s[i].data[c.dataIndex];
  246. }
  247. }
  248. });
  249. if(grid.mainField && form && form.keyField){//例如,将pu_id的值赋给pd_puid
  250. dd[grid.mainField] = r[form.keyField];
  251. }
  252. param.push(Ext.JSON.encode(dd));
  253. }
  254. }
  255. var params = new Object();
  256. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  257. if(contains(k, 'ext-', true)){
  258. delete r[k];
  259. }
  260. });
  261. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  262. params.param = unescape(param.toString().replace(/\\/g,"%"));
  263. for(var i=2; i<arguments.length; i++) { //兼容多参数
  264. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  265. }
  266. var me = this;
  267. var form = Ext.getCmp('form');
  268. /* me.getActiveTab().setLoading(true);//loading...
  269. */ Ext.Ajax.request({
  270. url : basePath + 'scm/sale/saveSale.action?caller=Sale',
  271. params : params,
  272. method : 'post',
  273. callback : function(options,success,response){
  274. var localJson = new Ext.decode(response.responseText);
  275. if(localJson.success){
  276. saveSuccess(function(){
  277. });
  278. } else if(localJson.exceptionInfo){
  279. var str = localJson.exceptionInfo;
  280. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  281. str = str.replace('AFTERSUCCESS', '');
  282. saveSuccess(function(){
  283. //add成功后刷新页面进入可编辑的页面
  284. var value = r[form.keyField];
  285. var formCondition = form.keyField + "IS" + value ;
  286. var gridCondition = '';
  287. var grid = Ext.getCmp('grid');
  288. if(grid && grid.mainField){
  289. gridCondition = grid.mainField + "IS" + value;
  290. }
  291. if(me.contains(window.location.href, '?', true)){
  292. window.location.href = window.location.href + '&formCondition=' +
  293. formCondition + '&gridCondition=' + gridCondition;
  294. } else {
  295. window.location.href = window.location.href + '?formCondition=' +
  296. formCondition + '&gridCondition=' + gridCondition;
  297. }
  298. });
  299. showError(str);
  300. } else {
  301. showError(str);
  302. return;
  303. }
  304. } else{
  305. saveFailure();//@i18n/i18n.js
  306. }
  307. }
  308. });
  309. }
  310. },
  311. 'erpFeatureDefinitionButton':{
  312. click: function(btn){
  313. var grid = Ext.getCmp('grid');
  314. var record = grid.selModel.lastSelected;
  315. if(record.data.sd_prodcode != null){
  316. Ext.Ajax.request({//拿到grid的columns
  317. url : basePath + "pm/bom/getDescription.action",
  318. params: {
  319. tablename: 'Product',
  320. field: 'pr_specvalue',
  321. condition: "pr_code='" + record.data.sd_prodcode + "'"
  322. },
  323. method : 'post',
  324. async: false,
  325. callback : function(options,success,response){
  326. var res = new Ext.decode(response.responseText);
  327. if(res.exceptionInfo){
  328. showError(res.exceptionInfo);return;
  329. }
  330. if(res.success){
  331. if(res.description != '' && res.description != null && res.description == 'NOTSPECIFIC'){
  332. var win = new Ext.window.Window({
  333. id : 'win' + record.data.sd_id,
  334. title: '生成特征料号',
  335. height: "90%",
  336. width: "70%",
  337. maximizable : true,
  338. buttonAlign : 'center',
  339. layout : 'anchor',
  340. items: [{
  341. tag : 'iframe',
  342. frame : true,
  343. anchor : '100% 100%',
  344. layout : 'fit',
  345. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  346. "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>'
  347. }]
  348. });
  349. win.show();
  350. } else {
  351. showError('物料特征必须为虚拟特征件');return;
  352. }
  353. }
  354. }
  355. });
  356. }
  357. }
  358. },
  359. 'erpFeatureViewButton':{
  360. click: function(btn){
  361. var grid = Ext.getCmp('grid');
  362. var record = grid.selModel.lastSelected;
  363. if(record.data.sd_prodcode != null){
  364. Ext.Ajax.request({//拿到grid的columns
  365. url : basePath + "pm/bom/getDescription.action",
  366. params: {
  367. tablename: 'Product',
  368. field: 'pr_specvalue',
  369. condition: "pr_code='" + record.data.sd_prodcode + "'"
  370. },
  371. method : 'post',
  372. async: false,
  373. callback : function(options,success,response){
  374. var res = new Ext.decode(response.responseText);
  375. if(res.exceptionInfo){
  376. showError(res.exceptionInfo);return;
  377. }
  378. if(res.success){
  379. if(res.description != '' && res.description != null && res.description == 'SPECIFIC'){
  380. var win = new Ext.window.Window({
  381. id : 'win' + record.data.sd_id,
  382. title: '特征查看',
  383. height: "90%",
  384. width: "70%",
  385. maximizable : true,
  386. buttonAlign : 'center',
  387. layout : 'anchor',
  388. items: [{
  389. tag : 'iframe',
  390. frame : true,
  391. anchor : '100% 100%',
  392. layout : 'fit',
  393. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  394. "jsps/pm/bom/FeatureValueView.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>'
  395. }]
  396. });
  397. win.show();
  398. } else {
  399. showError('物料特征必须为 虚拟特征件');return;
  400. }
  401. }
  402. }
  403. });
  404. }
  405. }
  406. },
  407. 'dbfindtrigger[name=sd_batchcode]': {
  408. focus: function(t){
  409. t.setHideTrigger(false);
  410. t.setReadOnly(false);//用disable()可以,但enable()无效
  411. var record = Ext.getCmp('grid').selModel.getLastSelected();
  412. var pr = record.data['sd_prodcode'];
  413. if(pr == null || pr == ''){
  414. showError("请先选择料号!");
  415. t.setHideTrigger(true);
  416. t.setReadOnly(true);
  417. } else {
  418. var id = record.data['sd_warehouseid'];
  419. if(id == null || id == ''){
  420. id = Ext.getCmp('sd_warehouseid');
  421. if(id == null || id == '' || id== 0 ){
  422. showError("请先选择仓库!");
  423. t.setHideTrigger(true);
  424. t.setReadOnly(true);
  425. }
  426. } else {
  427. t.dbBaseCondition = "ba_warehouseid='" + id + "' AND ba_prodcode='" + pr + "'";
  428. }
  429. }
  430. }
  431. },
  432. 'erpOutScheduleButton': {
  433. click: function() {
  434. var grid = Ext.getCmp('grid'),record = grid.selModel.lastSelected;
  435. if(record) {
  436. me.schedule(record);
  437. }
  438. }
  439. }
  440. });
  441. },
  442. onGridItemClick: function(selModel, record){//grid行选择
  443. this.GridUtil.onGridItemClick(selModel, record);
  444. },
  445. getRecordByPrCode: function(){
  446. if(this.gridLastSelected && this.gridLastSelected.findable){
  447. var data = Ext.getCmp('grid').store.data.items[this.gridLastSelected.index].data;
  448. var code = data.pd_prodcode;
  449. if(code != null && code!= ''){//看用户输入了编号没有
  450. var str = "sd_prodcode='" + code + "'";
  451. this.GridUtil.getRecordByCode({caller: 'Sale', condition: str});
  452. }
  453. }
  454. },
  455. getForm: function(btn){
  456. return btn.ownerCt.ownerCt;
  457. },
  458. beforeSaveSale: function(){
  459. var cop = Ext.getCmp('sa_cop');
  460. if(cop) {
  461. cop.setValue(en_uu);
  462. }
  463. var grid = Ext.getCmp('grid');
  464. var cust = Ext.getCmp('sa_custid').value;
  465. if(cust == null || cust == '' || cust == '0' || cust == 0){
  466. showError('未选择客户,或客户编号无效!');
  467. return;
  468. }
  469. var items = grid.store.data.items;
  470. var bool = true;
  471. //数量不能为空或0
  472. Ext.each(items, function(item){
  473. item.set('sd_code', Ext.getCmp('sa_code').value);
  474. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  475. if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
  476. || item.data['sd_qty'] == 0){
  477. bool = false;
  478. showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
  479. }
  480. }
  481. });
  482. /*//销售价格不能为0
  483. if(Ext.getCmp('sa_getprice').value == 0){//是否自动获取单价
  484. Ext.each(items, function(item){
  485. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  486. if(item.data['sd_price'] == null){
  487. bool = false;
  488. showError('明细表第' + item.data['sd_detno'] + '行的价格为空');return;
  489. } else if(item.data['sd_price'] == 0 || item.data['sd_price'] == '0'){
  490. bool = false;
  491. showError('明细表第' + item.data['sd_detno'] + '行的价格为0');return;
  492. }
  493. }
  494. });
  495. }*/
  496. //物料交货日期不能小于录入日期
  497. var recorddate = Ext.getCmp('sa_recorddate').value;
  498. Ext.each(items, function(item){
  499. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  500. if(item.data['sd_delivery'] == null){
  501. item.set('sd_delivery', recorddate);
  502. } else if(item.data['sd_delivery'] < recorddate){
  503. bool = false;
  504. showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
  505. }
  506. }
  507. });
  508. //保存sale
  509. if(bool)
  510. this.FormUtil.beforeSave(this);
  511. },
  512. beforeUpdate: function(){
  513. var grid = Ext.getCmp('grid');
  514. var cust = Ext.getCmp('sa_custid').value;
  515. var items = grid.store.data.items, sacode = Ext.getCmp('sa_code').value;
  516. var bool = true;
  517. if(cust == null || cust == '' || cust == '0' || cust == 0){
  518. showError('未选择客户,或客户编号无效!');
  519. return;
  520. }
  521. //数量不能为空或0
  522. Ext.each(items, function(item){
  523. item.set('sd_code',sacode);
  524. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  525. if(item.data['sd_qty'] == null || item.data['sd_qty'] == '' || item.data['sd_qty'] == '0'
  526. || item.data['sd_qty'] == 0){
  527. bool = false;
  528. showError('明细表第' + item.data['sd_detno'] + '行的数量为空');return;
  529. }
  530. }
  531. });
  532. //物料交货日期不能小于录入日期
  533. var recorddate = Ext.getCmp('sa_recorddate').value;
  534. Ext.each(items, function(item){
  535. item.set('sd_code',sacode);
  536. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  537. if(item.data['sd_delivery'] == null){
  538. item.set('sd_delivery', recorddate);
  539. } else if(item.data['sd_delivery'] < recorddate){
  540. bool = false;
  541. showError('明细表第' + item.data['sd_detno'] + '行的交货日期小于单据录入日期');return;
  542. }
  543. }
  544. });
  545. //保存
  546. if(bool)
  547. this.FormUtil.onUpdate(this);
  548. },
  549. /**
  550. * 排程
  551. */
  552. schedule: function(record) {
  553. var width = Ext.isIE ? screen.width*0.7*0.9 : '80%',
  554. height = Ext.isIE ? screen.height*0.75 : '100%';
  555. var sd_id = record.get('sd_id');
  556. Ext.create('Ext.Window', {
  557. width: width,
  558. height: height,
  559. autoShow: true,
  560. items: [{
  561. tag : 'iframe',
  562. frame : true,
  563. anchor : '100% 100%',
  564. layout : 'fit',
  565. html : '<iframe id="iframe_dbfind" src="' + basePath + 'jsps/scm/sale/saleDetail.jsp?formCondition=sd_id='
  566. + sd_id + '&gridCondition=sdd_sdid=' + sd_id + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  567. }]
  568. });
  569. }
  570. });