Application.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.purchase.Application', {
  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.purchase.Application','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','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.TurnPurc','core.button.Flow','core.button.ImportExcel', 'core.button.UpdateRemark','core.button.ProduceBatch',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn','core.form.FileField','core.button.MRPResourceScan'
  13. ],
  14. init:function(){
  15. var me = this;
  16. me.gridLastSelected = null;
  17. this.control({
  18. 'field[name=ap_remark]':{
  19. afterrender: function(field){
  20. Ext.defer(function(){
  21. field.setReadOnly(false);
  22. }, 200);
  23. }
  24. },
  25. 'erpGridPanel2': {
  26. itemclick: function(selModel, record){
  27. if(record.data.ad_prodcode != null && record.data.ad_prodcode != ''){
  28. var btn = Ext.getCmp('erpMRPResourceScan_button');
  29. if(btn){
  30. btn.setDisabled(false);
  31. btn._ad_prodcode = record.data.ad_prodcode;
  32. }
  33. }
  34. this.onGridItemClick(selModel, record);
  35. }
  36. },
  37. '#erpMRPResourceScan_button':{
  38. click:function(btn){
  39. var refcode = Ext.getCmp('ap_refcode').getValue();
  40. var prodcode = btn._ad_prodcode;
  41. if(Ext.isEmpty(refcode)){
  42. showError("[MRP单号]为空,不能查看MRP来源!");
  43. return;
  44. }
  45. if (!Ext.isEmpty(refcode)&&!Ext.isEmpty(prodcode)){
  46. var win = new Ext.window.Window({
  47. id : 'win_Resource',
  48. height : '90%',
  49. width : '95%',
  50. maximizable : true,
  51. buttonAlign : 'center',
  52. layout : 'anchor',
  53. items : [ {
  54. tag : 'iframe',
  55. frame : true,
  56. anchor : '100% 100%',
  57. layout : 'fit',
  58. html : '<iframe id="iframe_MRPResourceScanWin'+refcode+'" src="'+basePath+'jsps/common/datalist.jsp?_noc=1&whoami=Desk!MrpResultDetail&urlcondition=md_mrpcode=\''+refcode+'\' and md_prodcode=\''+prodcode+'\'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  59. } ]
  60. });
  61. win.show();
  62. }
  63. }
  64. },
  65. 'field[name=ap_currency]': {
  66. beforetrigger: function(field) {
  67. var t = field.up('form').down('field[name=ap_date]'),
  68. value = t.getValue();
  69. if(value) {
  70. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  71. }
  72. }
  73. },
  74. 'erpSaveButton': {
  75. click: function(btn){
  76. var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField);
  77. if(codeField.value == null || codeField.value == ''){
  78. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  79. var res = me.getLeadCode(Ext.getCmp('ap_kind').value);
  80. if(res != null && res != ''){
  81. codeField.setValue(res + codeField.getValue());
  82. }
  83. }
  84. var bool = true;
  85. var grid = Ext.getCmp('grid');
  86. //数量不能为空或0
  87. //给从表赋值:vendcode、vendname
  88. var firstItem = grid.store.getAt(0);
  89. items = grid.store.data.items,
  90. recorddate = Ext.getCmp('ap_recorddate').value;
  91. Ext.each(items, function(item){
  92. //当点击保存或者更新按钮时,默认把明细行第一行的项目编号和项目名称赋值给后面带编号的明细行
  93. if(firstItem.get('ad_prodcode')&&firstItem.get('ad_prjcode')&&firstItem.get('ad_prjname')) {
  94. var ad_prjcode = firstItem.get('ad_prjcode');
  95. var ad_prjname = firstItem.get('ad_prjname');
  96. if(!Ext.isEmpty(item.get('ad_prodcode'))){
  97. if(Ext.isEmpty(item.get('ad_prjcode'))) {
  98. /*item.set('ad_prjcode', ad_prjcode);*/
  99. item.data['ad_prjcode']=ad_prjcode;
  100. item.dirty=true;
  101. }
  102. if(Ext.isEmpty(item.get('ad_prjname'))) {
  103. /*item.set('ad_prjname', ad_prjname);*/
  104. item.data['ad_prjname']=ad_prjname;
  105. item.dirty=true;
  106. }
  107. }
  108. }
  109. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  110. if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
  111. || item.data['pd_qty'] == 0){
  112. bool = false;
  113. showError('明细表第' + item.data['ad_detno'] + '行的数量为空');
  114. return false;
  115. }
  116. if(Ext.isEmpty(item.data['ad_delivery'])){
  117. bool = false;
  118. showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');
  119. return false;
  120. }
  121. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
  122. bool = false;
  123. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');
  124. return false;
  125. }
  126. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  127. bool = false;
  128. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');
  129. return false;
  130. }
  131. }
  132. });
  133. if(bool){
  134. this.FormUtil.beforeSave(this);
  135. }
  136. }
  137. },
  138. 'erpDeleteButton' : {
  139. click: function(btn){
  140. me.FormUtil.onDelete(Ext.getCmp('ap_id').value);
  141. }
  142. },
  143. 'erpProduceBatchButton':{
  144. beforerender:function(btn){
  145. btn.setText("计 算");
  146. },
  147. click: function(btn){
  148. var id=Ext.getCmp('ap_id').value;
  149. grid = Ext.getCmp('grid');
  150. Ext.Ajax.request({
  151. url : basePath + "scm/purchase/applicationdataupdate.action",
  152. params: {
  153. id:id
  154. },
  155. method : 'post',
  156. async: false,
  157. callback : function(options,success,response){
  158. var res = new Ext.decode(response.responseText);
  159. if(res.exceptionInfo){
  160. showError(res.exceptionInfo);
  161. return;
  162. }
  163. grid.GridUtil.loadNewStore(grid,{
  164. caller:'Application',
  165. condition:gridCondition,
  166. _noc:1
  167. });
  168. showError("计算成功!");
  169. }
  170. });
  171. }
  172. },
  173. 'erpImportExcelButton':{
  174. afterrender:function(btn){
  175. var statuscode=Ext.getCmp('ap_statuscode').getValue();
  176. if(statuscode&&statuscode!='ENTERING'){
  177. btn.hide();
  178. }
  179. }
  180. },
  181. 'filefield[id=excelfile]':{
  182. change: function(field){
  183. var filename = '';
  184. if(contains(field.value, "\\", true)){
  185. filename = field.value.substring(field.value.lastIndexOf('\\') + 1);
  186. } else {
  187. filename = field.value.substring(field.value.lastIndexOf('/') + 1);
  188. }
  189. field.ownerCt.getForm().submit({
  190. url: basePath + 'common/upload.action?em_code=' + em_code,
  191. waitMsg: "正在解析文件信息",
  192. success: function(fp,o){
  193. if(o.result.error){
  194. showError(o.result.error);
  195. } else {
  196. var filePath=o.result.filepath;
  197. var keyValue=Ext.getCmp('ap_id').getValue();
  198. Ext.Ajax.request({//拿到form的items
  199. url : basePath + 'scm/application/ImportExcel.action',
  200. params:{
  201. id:keyValue,
  202. fileId:filePath
  203. },
  204. method : 'post',
  205. callback : function(options,success,response){
  206. var result=Ext.decode(response.responseText);
  207. if(result.success){
  208. var grid=Ext.getCmp('grid');
  209. var param={
  210. caller:'Application',
  211. condition:'ad_apid='+keyValue
  212. };
  213. grid.GridUtil.loadNewStore(grid,param);
  214. }else{
  215. if(result.exceptionInfo != null){
  216. showError(res.exceptionInfo);return;
  217. }
  218. }
  219. }
  220. });
  221. }
  222. }
  223. });
  224. }
  225. },
  226. 'erpUpdateButton': {
  227. click: function(btn){
  228. var form = me.getForm(btn);
  229. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  230. me.BaseUtil.getRandomNumber();//自动添加编号
  231. }
  232. var bool = true;
  233. //数量不能为空或0
  234. //给从表赋值:vendcode、vendname
  235. var grid = Ext.getCmp('grid');
  236. var items = grid.store.data.items;
  237. var firstItem = grid.store.getAt(0);
  238. var c = Ext.getCmp('ap_code').value;
  239. var recorddate = Ext.getCmp('ap_recorddate').value;
  240. Ext.each(items, function(item){
  241. //把明细行第一行的项目名称和项目编号赋值给下面带编号的行
  242. if(firstItem.get('ad_prjcode')&&firstItem.get('ad_prjname')) {
  243. var ad_prjcode = firstItem.get('ad_prjcode');
  244. var ad_prjname = firstItem.get('ad_prjname');
  245. if(!Ext.isEmpty(item.get('ad_prodcode'))){
  246. if(Ext.isEmpty(item.get('ad_prjcode'))) {
  247. /*item.set('ad_prjcode', ad_prjcode);*/
  248. item.data['ad_prjcode']=ad_prjcode;
  249. item.dirty=true;
  250. }
  251. if(Ext.isEmpty(item.get('ad_prjname'))) {
  252. /*item.set('ad_prjname', ad_prjname);*/
  253. item.data['ad_prjname']=ad_prjname;
  254. item.dirty=true;
  255. }
  256. }
  257. }
  258. //item.set('ad_code',c);
  259. item['ad_code']=c;
  260. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  261. if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
  262. || item.data['pd_qty'] == 0){
  263. bool = false;
  264. showError('明细表第' + item.data['ad_detno'] + '行的数量为空');
  265. return false;
  266. }
  267. if(Ext.isEmpty(item.data['ad_delivery'])){
  268. bool = false;
  269. showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');
  270. return false;
  271. }
  272. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
  273. bool = false;
  274. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');
  275. return false;
  276. }
  277. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  278. bool = false;
  279. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');
  280. return false;
  281. }
  282. }
  283. });
  284. if(bool){
  285. this.FormUtil.onUpdate(this);
  286. }
  287. }
  288. },
  289. 'erpAddButton': {
  290. click: function(){
  291. me.FormUtil.onAdd('addApplication', '新增请购单', 'jsps/scm/purchase/application.jsp');
  292. }
  293. },
  294. 'erpCloseButton': {
  295. click: function(btn){
  296. me.FormUtil.beforeClose(me);
  297. }
  298. },
  299. 'erpSubmitButton': {
  300. afterrender: function(btn){
  301. var status = Ext.getCmp('ap_statuscode');
  302. if(status && status.value != 'ENTERING'){
  303. btn.hide();
  304. }
  305. },
  306. click: function(btn){
  307. var grid = Ext.getCmp('grid'), c = Ext.getCmp('ap_code').value,
  308. items = grid.store.data.items, recorddate = Ext.getCmp('ap_recorddate').value;
  309. var bool = true;
  310. Ext.each(items, function(item){
  311. item['ad_code']=c;
  312. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  313. if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
  314. || item.data['pd_qty'] == 0){
  315. bool = false;
  316. showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
  317. }
  318. if(Ext.isEmpty(item.data['ad_delivery'])){
  319. bool = false;
  320. showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
  321. }
  322. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
  323. bool = false;
  324. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
  325. }
  326. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  327. bool = false;
  328. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
  329. }
  330. }
  331. });
  332. if(bool){
  333. me.FormUtil.onSubmit(Ext.getCmp('ap_id').value);
  334. }
  335. }
  336. },
  337. 'erpResSubmitButton': {
  338. afterrender: function(btn){
  339. var status = Ext.getCmp('ap_statuscode');
  340. if(status && status.value != 'COMMITED'){
  341. btn.hide();
  342. }
  343. },
  344. click: function(btn){
  345. me.FormUtil.onResSubmit(Ext.getCmp('ap_id').value);
  346. }
  347. },
  348. 'erpAuditButton': {
  349. afterrender: function(btn){
  350. var status = Ext.getCmp('ap_statuscode');
  351. if(status && status.value != 'COMMITED'){
  352. btn.hide();
  353. }
  354. },
  355. click: function(btn){
  356. me.FormUtil.onAudit(Ext.getCmp('ap_id').value);
  357. }
  358. },
  359. 'erpResAuditButton': {
  360. afterrender: function(btn){
  361. var status = Ext.getCmp('ap_statuscode');
  362. if(status && status.value != 'AUDITED'){
  363. btn.hide();
  364. }
  365. },
  366. click: function(btn){
  367. me.FormUtil.onResAudit(Ext.getCmp('ap_id').value);
  368. }
  369. },
  370. 'erpPrintButton': {
  371. click:function(btn){
  372. var reportName="application";
  373. var condition='{Application.ap_id}='+Ext.getCmp('ap_id').value+'';
  374. var id=Ext.getCmp('ap_id').value;
  375. me.FormUtil.onwindowsPrint(id,reportName,condition);
  376. }
  377. },
  378. 'erpUpdateRemarkButton': {
  379. afterrender: function(btn){
  380. var status = Ext.getCmp('ap_statuscode');
  381. if (status && status.value == 'ENTERING') {
  382. btn.hide();
  383. }
  384. },
  385. click : function(btn) {
  386. Ext.Ajax.request({
  387. url : basePath + 'common/updateByCondition.action',
  388. params : {
  389. caller : caller,
  390. table : 'Application',
  391. update : 'ap_remark=\'' + Ext.getCmp('ap_remark').value + '\'',
  392. condition : 'ap_id=' + Ext.getCmp('ap_id').value
  393. },
  394. callback : function(opt, s, res) {
  395. var r = Ext.decode(res.responseText);
  396. if (r.success) {
  397. alert('修改成功!');
  398. }
  399. }
  400. });
  401. }
  402. },
  403. /*'field[name=ad_qty]':{
  404. change: function(f){
  405. if(f.value == null || f.value == ''){
  406. f.value = 0;
  407. }
  408. var record = Ext.getCmp('grid').selModel.getLastSelected();
  409. var value=record.data['ad_qty'];
  410. if(!record.data['ad_minorder'] || record.data['ad_minorder']==null){
  411. showError('最小订购量为空,请先填写最小订购量');
  412. return;
  413. }
  414. if(!record.data['ad_minpack'] || record.data['ad_minpack']==null){
  415. showError('最小包装量为空,请先填写最小包装量');
  416. return;
  417. }
  418. if(value<record.data['ad_minorder']){
  419. showError('需求数量小于最小订购量,请重新填写!');
  420. record.set('ad_minorder',null);
  421. return;
  422. }
  423. if(value/record.data['ad_minpack'] !=0){
  424. showError('需求数量不是最小包装量的整数倍,请重新填写!');
  425. record.set('ad_minorder',null);
  426. return;
  427. }
  428. }
  429. },*/
  430. 'erp2PurcButton': {
  431. afterrender: function(btn){
  432. var status = Ext.getCmp('ap_turnstatuscode');
  433. if(status && status.value != 'PARTPURC'){
  434. btn.hide();
  435. }
  436. },
  437. click: function(btn){
  438. warnMsg("确定要转入采购单吗?", function(btn){
  439. if(btn == 'yes'){
  440. me.FormUtil.getActiveTab().setLoading(true);//loading...
  441. Ext.Ajax.request({
  442. url : basePath + 'scm/purchase/turnPurchase.action',
  443. params: {
  444. id: Ext.getCmp('ap_id').value
  445. },
  446. method : 'post',
  447. callback : function(options,success,response){
  448. me.FormUtil.getActiveTab().setLoading(false);
  449. var localJson = new Ext.decode(response.responseText);
  450. if(localJson.exceptionInfo){
  451. showError(localJson.exceptionInfo);
  452. }
  453. if(localJson.success){
  454. turnSuccess(function(){
  455. window.location.reload();
  456. });
  457. }
  458. }
  459. });
  460. }
  461. });
  462. }
  463. }
  464. });
  465. },
  466. onGridItemClick: function(selModel, record){//grid行选择
  467. this.GridUtil.onGridItemClick(selModel, record);
  468. },
  469. getForm: function(btn){
  470. return btn.ownerCt.ownerCt;
  471. },
  472. getLeadCode: function(type) {
  473. var result = null;
  474. Ext.Ajax.request({
  475. url : basePath + 'common/getFieldData.action',
  476. async: false,
  477. params: {
  478. caller: 'PurchaseKind',
  479. field: 'pk_excode',
  480. condition: 'pk_name=\'' + type + '\''
  481. },
  482. method : 'post',
  483. callback : function(opt, s, res){
  484. var r = new Ext.decode(res.responseText);
  485. if(r.exceptionInfo){
  486. showError(r.exceptionInfo);return;
  487. } else if(r.success){
  488. result = r.data;
  489. }
  490. }
  491. });
  492. return result;
  493. }
  494. });