Application.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. //数量不能为空或0
  86. //给从表赋值:vendcode、vendname
  87. var grid = Ext.getCmp('grid'),
  88. items = grid.store.data.items,
  89. recorddate = Ext.getCmp('ap_recorddate').value;
  90. Ext.each(items, function(item){
  91. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  92. if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
  93. || item.data['pd_qty'] == 0){
  94. bool = false;
  95. showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
  96. }
  97. if(Ext.isEmpty(item.data['ad_delivery'])){
  98. bool = false;
  99. showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
  100. }
  101. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
  102. bool = false;
  103. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
  104. }
  105. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  106. bool = false;
  107. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
  108. }
  109. }
  110. });
  111. if(bool){
  112. this.FormUtil.beforeSave(this);
  113. }
  114. }
  115. },
  116. 'erpDeleteButton' : {
  117. click: function(btn){
  118. me.FormUtil.onDelete(Ext.getCmp('ap_id').value);
  119. }
  120. },
  121. 'erpProduceBatchButton':{
  122. beforerender:function(btn){
  123. btn.setText("计 算");
  124. },
  125. click: function(btn){
  126. var id=Ext.getCmp('ap_id').value;
  127. grid = Ext.getCmp('grid');
  128. Ext.Ajax.request({
  129. url : basePath + "scm/purchase/applicationdataupdate.action",
  130. params: {
  131. id:id
  132. },
  133. method : 'post',
  134. async: false,
  135. callback : function(options,success,response){
  136. var res = new Ext.decode(response.responseText);
  137. if(res.exceptionInfo){
  138. showError(res.exceptionInfo);
  139. return;
  140. }
  141. grid.GridUtil.loadNewStore(grid,{
  142. caller:'Application',
  143. condition:gridCondition,
  144. _noc:1
  145. });
  146. showError("计算成功!");
  147. }
  148. });
  149. }
  150. },
  151. 'erpImportExcelButton':{
  152. afterrender:function(btn){
  153. var statuscode=Ext.getCmp('ap_statuscode').getValue();
  154. if(statuscode&&statuscode!='ENTERING'){
  155. btn.hide();
  156. }
  157. }
  158. },
  159. 'filefield[id=excelfile]':{
  160. change: function(field){
  161. var filename = '';
  162. if(contains(field.value, "\\", true)){
  163. filename = field.value.substring(field.value.lastIndexOf('\\') + 1);
  164. } else {
  165. filename = field.value.substring(field.value.lastIndexOf('/') + 1);
  166. }
  167. field.ownerCt.getForm().submit({
  168. url: basePath + 'common/upload.action?em_code=' + em_code,
  169. waitMsg: "正在解析文件信息",
  170. success: function(fp,o){
  171. if(o.result.error){
  172. showError(o.result.error);
  173. } else {
  174. var filePath=o.result.filepath;
  175. var keyValue=Ext.getCmp('ap_id').getValue();
  176. Ext.Ajax.request({//拿到form的items
  177. url : basePath + 'scm/application/ImportExcel.action',
  178. params:{
  179. id:keyValue,
  180. fileId:filePath
  181. },
  182. method : 'post',
  183. callback : function(options,success,response){
  184. var result=Ext.decode(response.responseText);
  185. if(result.success){
  186. var grid=Ext.getCmp('grid');
  187. var param={
  188. caller:'Application',
  189. condition:'ad_apid='+keyValue
  190. };
  191. grid.GridUtil.loadNewStore(grid,param);
  192. }else{
  193. if(result.exceptionInfo != null){
  194. showError(res.exceptionInfo);return;
  195. }
  196. }
  197. }
  198. });
  199. }
  200. }
  201. });
  202. }
  203. },
  204. 'erpUpdateButton': {
  205. click: function(btn){
  206. var form = me.getForm(btn);
  207. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  208. me.BaseUtil.getRandomNumber();//自动添加编号
  209. }
  210. var bool = true;
  211. //数量不能为空或0
  212. //给从表赋值:vendcode、vendname
  213. var grid = Ext.getCmp('grid'), items = grid.store.data.items,
  214. c = Ext.getCmp('ap_code').value,
  215. recorddate = Ext.getCmp('ap_recorddate').value;
  216. Ext.each(items, function(item){
  217. item.set('ad_code',c);
  218. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  219. if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
  220. || item.data['pd_qty'] == 0){
  221. bool = false;
  222. showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
  223. }
  224. if(Ext.isEmpty(item.data['ad_delivery'])){
  225. bool = false;
  226. showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
  227. }
  228. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
  229. bool = false;
  230. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
  231. }
  232. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  233. bool = false;
  234. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
  235. }
  236. }
  237. });
  238. if(bool){
  239. this.FormUtil.onUpdate(this);
  240. }
  241. }
  242. },
  243. 'erpAddButton': {
  244. click: function(){
  245. me.FormUtil.onAdd('addApplication', '新增请购单', 'jsps/scm/purchase/application.jsp');
  246. }
  247. },
  248. 'erpCloseButton': {
  249. click: function(btn){
  250. me.FormUtil.beforeClose(me);
  251. }
  252. },
  253. 'erpSubmitButton': {
  254. afterrender: function(btn){
  255. var status = Ext.getCmp('ap_statuscode');
  256. if(status && status.value != 'ENTERING'){
  257. btn.hide();
  258. }
  259. },
  260. click: function(btn){
  261. var grid = Ext.getCmp('grid'), c = Ext.getCmp('ap_code').value,
  262. items = grid.store.data.items, recorddate = Ext.getCmp('ap_recorddate').value
  263. var bool = true;
  264. Ext.each(items, function(item){
  265. item.set('ad_code',c);
  266. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  267. if(item.data['ad_qty'] == null || item.data['ad_qty'] == '' || item.data['ad_qty'] == '0'
  268. || item.data['pd_qty'] == 0){
  269. bool = false;
  270. showError('明细表第' + item.data['ad_detno'] + '行的数量为空');return;
  271. }
  272. if(Ext.isEmpty(item.data['ad_delivery'])){
  273. bool = false;
  274. showError('明细表第' + item.data['ad_detno'] + '行的需求日期不能为空');return;
  275. }
  276. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(recorddate,'Y-m-d')){
  277. bool = false;
  278. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据录入日期');return;
  279. }
  280. if(Ext.Date.format(item.data['ad_delivery'],'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){
  281. bool = false;
  282. showError('明细表第' + item.data['ad_detno'] + '行的需求日期小于单据当前日期');return;
  283. }
  284. }
  285. });
  286. if(bool){
  287. me.FormUtil.onSubmit(Ext.getCmp('ap_id').value);
  288. }
  289. }
  290. },
  291. 'erpResSubmitButton': {
  292. afterrender: function(btn){
  293. var status = Ext.getCmp('ap_statuscode');
  294. if(status && status.value != 'COMMITED'){
  295. btn.hide();
  296. }
  297. },
  298. click: function(btn){
  299. me.FormUtil.onResSubmit(Ext.getCmp('ap_id').value);
  300. }
  301. },
  302. 'erpAuditButton': {
  303. afterrender: function(btn){
  304. var status = Ext.getCmp('ap_statuscode');
  305. if(status && status.value != 'COMMITED'){
  306. btn.hide();
  307. }
  308. },
  309. click: function(btn){
  310. me.FormUtil.onAudit(Ext.getCmp('ap_id').value);
  311. }
  312. },
  313. 'erpResAuditButton': {
  314. afterrender: function(btn){
  315. var status = Ext.getCmp('ap_statuscode');
  316. if(status && status.value != 'AUDITED'){
  317. btn.hide();
  318. }
  319. },
  320. click: function(btn){
  321. me.FormUtil.onResAudit(Ext.getCmp('ap_id').value);
  322. }
  323. },
  324. 'erpPrintButton': {
  325. click:function(btn){
  326. var reportName="application";
  327. var condition='{Application.ap_id}='+Ext.getCmp('ap_id').value+'';
  328. var id=Ext.getCmp('ap_id').value;
  329. me.FormUtil.onwindowsPrint(id,reportName,condition);
  330. }
  331. },
  332. 'erpUpdateRemarkButton': {
  333. afterrender: function(btn){
  334. var status = Ext.getCmp('ap_statuscode');
  335. if (status && status.value == 'ENTERING') {
  336. btn.hide();
  337. }
  338. },
  339. click : function(btn) {
  340. Ext.Ajax.request({
  341. url : basePath + 'common/updateByCondition.action',
  342. params : {
  343. caller : caller,
  344. table : 'Application',
  345. update : 'ap_remark=\'' + Ext.getCmp('ap_remark').value + '\'',
  346. condition : 'ap_id=' + Ext.getCmp('ap_id').value
  347. },
  348. callback : function(opt, s, res) {
  349. var r = Ext.decode(res.responseText);
  350. if (r.success) {
  351. alert('修改成功!');
  352. }
  353. }
  354. });
  355. }
  356. },
  357. /*'field[name=ad_qty]':{
  358. change: function(f){
  359. if(f.value == null || f.value == ''){
  360. f.value = 0;
  361. }
  362. var record = Ext.getCmp('grid').selModel.getLastSelected();
  363. var value=record.data['ad_qty'];
  364. if(!record.data['ad_minorder'] || record.data['ad_minorder']==null){
  365. showError('最小订购量为空,请先填写最小订购量');
  366. return;
  367. }
  368. if(!record.data['ad_minpack'] || record.data['ad_minpack']==null){
  369. showError('最小包装量为空,请先填写最小包装量');
  370. return;
  371. }
  372. if(value<record.data['ad_minorder']){
  373. showError('需求数量小于最小订购量,请重新填写!');
  374. record.set('ad_minorder',null);
  375. return;
  376. }
  377. if(value/record.data['ad_minpack'] !=0){
  378. showError('需求数量不是最小包装量的整数倍,请重新填写!');
  379. record.set('ad_minorder',null);
  380. return;
  381. }
  382. }
  383. },*/
  384. 'erp2PurcButton': {
  385. afterrender: function(btn){
  386. var status = Ext.getCmp('ap_turnstatuscode');
  387. if(status && status.value != 'PARTPURC'){
  388. btn.hide();
  389. }
  390. },
  391. click: function(btn){
  392. warnMsg("确定要转入采购单吗?", function(btn){
  393. if(btn == 'yes'){
  394. me.FormUtil.getActiveTab().setLoading(true);//loading...
  395. Ext.Ajax.request({
  396. url : basePath + 'scm/purchase/turnPurchase.action',
  397. params: {
  398. id: Ext.getCmp('ap_id').value
  399. },
  400. method : 'post',
  401. callback : function(options,success,response){
  402. me.FormUtil.getActiveTab().setLoading(false);
  403. var localJson = new Ext.decode(response.responseText);
  404. if(localJson.exceptionInfo){
  405. showError(localJson.exceptionInfo);
  406. }
  407. if(localJson.success){
  408. turnSuccess(function(){
  409. window.location.reload();
  410. });
  411. }
  412. }
  413. });
  414. }
  415. });
  416. }
  417. }
  418. });
  419. },
  420. onGridItemClick: function(selModel, record){//grid行选择
  421. this.GridUtil.onGridItemClick(selModel, record);
  422. },
  423. getForm: function(btn){
  424. return btn.ownerCt.ownerCt;
  425. },
  426. getLeadCode: function(type) {
  427. var result = null;
  428. Ext.Ajax.request({
  429. url : basePath + 'common/getFieldData.action',
  430. async: false,
  431. params: {
  432. caller: 'PurchaseKind',
  433. field: 'pk_excode',
  434. condition: 'pk_name=\'' + type + '\''
  435. },
  436. method : 'post',
  437. callback : function(opt, s, res){
  438. var r = new Ext.decode(res.responseText);
  439. if(r.exceptionInfo){
  440. showError(r.exceptionInfo);return;
  441. } else if(r.success){
  442. result = r.data;
  443. }
  444. }
  445. });
  446. return result;
  447. }
  448. });