MakeFlow.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakeFlow', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'core.form.Panel','pm.make.MakeFlow','core.grid.Panel2','core.toolbar.Toolbar',
  7. 'core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  8. 'core.trigger.DbfindTrigger','core.button.Print','core.button.MakeFlows'
  9. ],
  10. init:function(){
  11. var me = this;
  12. me.FormUtil = Ext.create('erp.util.FormUtil');
  13. me.GridUtil = Ext.create('erp.util.GridUtil');
  14. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  15. this.control({
  16. 'erpGridPanel2': {
  17. afterrender: function(grid){
  18. grid.setReadOnly(true);
  19. },
  20. itemclick:me.ItemClick
  21. },
  22. 'erpSaveButton' :{
  23. click:function(btn){
  24. var grid = Ext.getCmp('grid');
  25. var form = Ext.getCmp('form');
  26. var items = grid.store.data.items;
  27. var num=0;
  28. var id = Ext.getCmp('mf_id').value;
  29. if(Ext.getCmp('mf_qty').value==0||Ext.getCmp('mf_qty').value==null){
  30. showError("流程单数量不能为0!");
  31. return;
  32. }
  33. if(id!=0||id !=null||id!=""){
  34. Ext.each(items, function(item){
  35. if(item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''&&item.data['mf_id']!=id){
  36. num =num+item.data['mf_qty'];
  37. }
  38. });
  39. }else{
  40. Ext.each(items, function(item){
  41. if(item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  42. num =num+item.data['mf_qty'];
  43. }
  44. });
  45. }
  46. if(num+Ext.getCmp('mf_qty').value>Ext.getCmp('ma_qty').value){
  47. showError("流程单数量总数超过制造单总数!");
  48. return;
  49. }
  50. if(Ext.getCmp('mf_madeqty').value==""||Ext.getCmp('mf_madeqty').value==null){
  51. Ext.getCmp('mf_madeqty').setValue('0');
  52. }
  53. if(Ext.getCmp('mf_madeqty').value>Ext.getCmp('mf_qty').value){
  54. showError("数量不能少于已完工数!");
  55. return;
  56. }
  57. //this.FormUtil.beforeSave(this);
  58. //var data = grid.getGridStore();
  59. grid.setLoading(true);
  60. Ext.getCmp('mf_maid').setValue(Ext.getCmp('ma_id').value);
  61. /*if(Ext.getCmp('mf_code').value==""||Ext.getCmp('mf_code').value==null){
  62. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  63. }*/
  64. var formValue = form.getValues();
  65. var formstore = unescape(Ext.JSON.encode(formValue).replace(/\\/g,"%"));
  66. Ext.Ajax.request({
  67. url : basePath + "pm/make/saveMakeFlow.action",
  68. params: {
  69. gridStore: formstore
  70. },
  71. method : 'post',
  72. callback : function(options,success,response){
  73. grid.setLoading(false);
  74. var res = new Ext.decode(response.responseText);
  75. if(res.exceptionInfo){
  76. showError(res.exceptionInfo);return;
  77. }
  78. if(res.success){
  79. saveSuccess(function(){
  80. window.location.href = window.location.href;
  81. });
  82. };
  83. }
  84. });
  85. }
  86. },
  87. 'erpDeleteButton': {
  88. click: function(btn){
  89. Ext.Ajax.request({
  90. url : basePath + "pm/make/CheckdeleteMakeflow.action",
  91. params: {
  92. code: Ext.getCmp('mf_code').value
  93. },
  94. method : 'post',
  95. callback : function(options,success,response){
  96. var res = new Ext.decode(response.responseText);
  97. if(res.exceptionInfo){
  98. showError(res.exceptionInfo);return;
  99. }
  100. if(res.log!=null){
  101. showMessage('提示', res.log);
  102. return;
  103. }
  104. }
  105. });
  106. var grid = Ext.getCmp('grid');
  107. Ext.Ajax.request({
  108. url : basePath + "pm/make/deleteMakeflow.action",
  109. params: {
  110. id: Ext.getCmp('mf_id').value
  111. },
  112. method : 'post',
  113. callback : function(options,success,response){
  114. grid.setLoading(false);
  115. var res = new Ext.decode(response.responseText);
  116. if(res.exceptionInfo){
  117. showError(res.exceptionInfo);return;
  118. }
  119. if(res.success){
  120. delSuccess(function(){
  121. window.location.href = window.location.href;
  122. });
  123. };
  124. }
  125. });
  126. },
  127. afterrender:function(btn){
  128. btn.setDisabled(true);
  129. }
  130. },
  131. 'erpCloseButton':{
  132. click:function(btn){
  133. parent.Ext.getCmp('win').close();
  134. }
  135. },
  136. 'erpMakeFlowsButton':{
  137. click:function(btn){
  138. var grid = Ext.getCmp('grid');
  139. var items = grid.store.data.items;
  140. var num=0;
  141. var id = Ext.getCmp('mf_id').value;
  142. if(Ext.getCmp('mf_date').value==''||Ext.getCmp('mf_date').value==null){
  143. alert('请填写日期!');
  144. return;
  145. }
  146. if(Ext.getCmp('mf_qty').value==0||Ext.getCmp('mf_qty').value==null){
  147. alert("流程单数量不能为0!");
  148. return;
  149. }
  150. if(id!=0||id !=null||id!=""){
  151. Ext.each(items, function(item){
  152. if(item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  153. num =num+item.data['mf_qty'];
  154. }
  155. });
  156. }else{
  157. Ext.each(items, function(item){
  158. if(item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  159. num =num+item.data['mf_qty'];
  160. }
  161. });
  162. }
  163. if(num+Ext.getCmp('mf_qty').value>Ext.getCmp('ma_qty').value){
  164. showError("流程单数量总数超过制造单总数!");
  165. return;
  166. }
  167. warnMsg("确定要拆分流程单吗?", function(btn){
  168. if(btn == 'yes'){
  169. Ext.Ajax.request({
  170. url : basePath + 'pm/make/newmakeflows.action',
  171. params: {
  172. id: Ext.getCmp('ma_id').value,
  173. number:Ext.getCmp('ma_qty').value-num,
  174. mfqty:Ext.getCmp('mf_qty').value,
  175. date:Ext.getCmp('mf_date').value
  176. },
  177. method : 'post',
  178. callback : function(options,success,response){
  179. var localJson = new Ext.decode(response.responseText);
  180. if(localJson.success){
  181. Ext.Msg.alert("提示","分拆成功!");
  182. window.location.reload();
  183. } else {
  184. Ext.Msg.alert("提示","分拆失败!");
  185. }
  186. }
  187. });
  188. }
  189. });
  190. }
  191. },
  192. 'erpAddButton': {
  193. click: function(){
  194. if(caller=='MakeFlow'){
  195. Ext.getCmp('deletebutton').setDisabled(true);
  196. Ext.getCmp('mf_date').setValue("");
  197. Ext.getCmp('mf_madeqty').setValue("");
  198. Ext.getCmp('mf_qty').setValue("");
  199. Ext.getCmp('mf_maid').setValue("");
  200. Ext.getCmp('mf_code').setValue("");
  201. Ext.getCmp('mf_id').setValue("");
  202. }
  203. },
  204. afterrender:function(){
  205. if(caller=='MakeFlow'){
  206. Ext.getCmp('mf_date').setValue("");
  207. Ext.getCmp('mf_madeqty').setValue("");
  208. Ext.getCmp('mf_qty').setValue("");
  209. Ext.getCmp('mf_maid').setValue("");
  210. Ext.getCmp('mf_code').setValue("");
  211. Ext.getCmp('mf_id').setValue("");
  212. }
  213. }
  214. },
  215. 'erpPrintButton':{
  216. click: function(btn){
  217. var reportName="byqmakeflow";
  218. var condition='{makeflow.mf_id}='+Ext.getCmp('mf_id').value+'';
  219. var id=Ext.getCmp('mf_id').value;
  220. me.FormUtil.onwindowsPrint(id,reportName,condition);
  221. },
  222. afterrender:function(btn){
  223. btn.setDisabled(true);
  224. }
  225. }
  226. });
  227. },
  228. getForm: function(btn){
  229. return btn.ownerCt.ownerCt;
  230. },
  231. ItemClick:function(view ,record){
  232. if(record.data["mf_code"]!='' && record.data["mf_code"]!=null){
  233. if(caller=='MakeFlow'){
  234. Ext.getCmp('print').setDisabled(false);
  235. Ext.getCmp('deletebutton').setDisabled(false);
  236. var form=view.ownerCt.ownerCt.items.items[0];
  237. form.getForm().setValues(record.data);
  238. }
  239. }
  240. }
  241. });