MakeMaterialGive.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.outsource.MakeMaterialGive', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.RenderUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'pm.outsource.MakeMaterialGive', 'core.grid.Panel5', 'common.editorColumn.GridPanel', 'core.grid.YnColumn',
  7. 'core.button.CreateDetail', 'core.button.PrintDetail', 'core.trigger.DbfindTrigger'
  8. ],
  9. init:function(){
  10. var me = this;
  11. me.GridUtil = Ext.create('erp.util.GridUtil');
  12. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  13. this.control({
  14. 'button[id=create]': {
  15. click: function(btn){
  16. warnMsg("确定要生成补料单吗?", function(btn){
  17. if(btn == 'yes'){
  18. var grid = Ext.getCmp('editorColumnGridPanel');
  19. var material = grid.getEffectData();
  20. if(material != null){
  21. grid.setLoading(true);//loading...
  22. Ext.Ajax.request({
  23. url : basePath + 'pm/make/turnAdd.action',
  24. params: {
  25. data: Ext.encode(material),
  26. wh: Ext.getCmp('whcode').checked,
  27. caller: caller,
  28. type: 'OS'
  29. },
  30. method : 'post',
  31. callback : function(options,success,response){
  32. grid.setLoading(false);
  33. var localJson = new Ext.decode(response.responseText);
  34. if(localJson.exceptionInfo){
  35. showError(localJson.exceptionInfo);
  36. }
  37. if(localJson.log){
  38. showMessage('提示', localJson.log);
  39. }
  40. if(localJson.success){
  41. turnSuccess(function(){
  42. grid.multiselected = new Array();
  43. });
  44. }
  45. }
  46. });
  47. }
  48. }
  49. });
  50. }
  51. },
  52. 'button[name=query]': {
  53. click: function(btn){
  54. var grid = Ext.getCmp('grid');
  55. //计算thisqty
  56. this.calAddQty(grid);
  57. //Query
  58. var condition = null;
  59. Ext.each(grid.store.data.items, function(item){
  60. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  61. if(condition == null){
  62. condition = "(mm_code='" + item.data['ma_code'] + "'";
  63. } else {
  64. condition += " OR mm_code='" + item.data['ma_code'] + "'";
  65. }
  66. }
  67. });
  68. if (Ext.getCmp('pr_location')){
  69. var location=Ext.getCmp('pr_location');
  70. if (location && location.value!=''){
  71. if (Ext.getCmp('ifnulllocation').checked){
  72. condition+="and (pr_location like '%"+location.value+"%' or NVL(pr_location,' ')=' ')";
  73. }else{
  74. condition+="and pr_location like '%"+location.value+"%' ";
  75. }
  76. }
  77. }
  78. if(condition != null){
  79. grid.multiselected = new Array();
  80. grid.busy = true;
  81. var dg = Ext.getCmp('editorColumnGridPanel');
  82. dg.busy = true;
  83. condition += ") AND (nvl(mm_materialstatus,' ')=' ') AND (mm_thisqty > 0)";
  84. dg.getGridColumnsAndStore(condition + ' order by mm_maid,mm_detno');
  85. this.showReplace(condition, dg);
  86. setTimeout(function(){
  87. dg.busy = false;
  88. grid.busy = false;
  89. }, 1000);
  90. }
  91. }
  92. },
  93. 'checkbox[id=whcode]' : {
  94. afterrender : function(f) {
  95. me.getSetting(f);
  96. }
  97. },
  98. 'erpEditorColumnGridPanel' : {
  99. afterlayout: function(grid) {
  100. grid.store.on('load', function(store){
  101. me.getProductWh(grid);
  102. });
  103. }
  104. }
  105. });
  106. },
  107. /**
  108. * 计算可补料数
  109. **/
  110. calAddQty: function(grid){
  111. var items = grid.store.data.items, idx = new Array();
  112. Ext.each(items, function(item){
  113. if(item.data['ma_code'] != null && item.data['ma_code'] != ''){
  114. idx.push(item.data['ma_id']);
  115. }
  116. });
  117. if(idx.length > 0) {
  118. Ext.Ajax.request({
  119. url : basePath + 'pm/make/calAddQty.action',
  120. async: false,
  121. params: {
  122. ids: Ext.Array.concate(idx, ',')
  123. },
  124. callback: function(opt, s, r){
  125. var res = Ext.decode(r.responseText);
  126. if(res.exceptionInfo) {
  127. showError(res.exceptionInfo);
  128. }
  129. }
  130. });
  131. }
  132. },
  133. /**
  134. * 替代料
  135. */
  136. showReplace: function(condition, grid){
  137. Ext.Ajax.request({
  138. url : basePath + 'common/getFieldsDatas.action',
  139. params: {
  140. caller: 'MakeMaterialReplace left join MakeMaterial on mm_id=mp_mmid left join Product on mp_prodcode=pr_code left join make on ma_id=mm_maid' +
  141. ' left join WareHouse on wh_id=mp_warehouseid',
  142. fields: 'mp_mmid,mp_detno,mm_thisqty as mp_thisqty,mp_canuseqty,mp_repqty,mp_remark,mp_prodcode,pr_detail,pr_spec,pr_unit,pr_location,wh_code,ma_vendcode',
  143. condition: condition + ' and ( mm_thisqty>0)'
  144. },
  145. async: false,
  146. method : 'post',
  147. callback : function(options,success,response){
  148. var localJson = new Ext.decode(response.responseText);
  149. if(localJson.exceptionInfo){
  150. showError(localJson.exceptionInfo);return;
  151. }
  152. if(localJson.success){
  153. var data = Ext.decode(localJson.data);
  154. if(data && data.length > 0) {
  155. var idx, store = grid.store, record;
  156. grid.lockrender = true;
  157. Ext.each(data, function(d){
  158. idx = store.find('mm_id', d.MP_MMID);
  159. record = store.getAt(idx);
  160. if(idx != null && idx >= 0) {
  161. store.insert(idx + 1, {
  162. mm_prodcode: d.MP_PRODCODE,
  163. mm_oneuseqty: record.data.mm_oneuseqty,
  164. mm_code: record.data.mm_code,
  165. pr_detail: d.PR_DETAIL,
  166. pr_spec: d.PR_SPEC,
  167. pr_unit: d.PR_UNIT,
  168. mm_canuserepqty: d.MP_CANUSEQTY,
  169. mm_thisqty: d.MP_THISQTY,
  170. mm_totaluseqty: d.MP_REPQTY,
  171. mm_ifrep: 1,
  172. mm_remark: d.MP_REMARK,
  173. mm_whcode: d.WH_CODE,
  174. mm_detno: d.MP_DETNO,
  175. mm_id: d.MP_MMID,
  176. isrep: true,
  177. pr_location:d.PR_LOCATION,
  178. ma_vendcode: d.MA_VENDCODE
  179. });
  180. }
  181. });
  182. grid.lockrender = false;
  183. }
  184. grid.store.fireEvent('load', grid.store);
  185. }
  186. }
  187. });
  188. },
  189. getProductWh: function(grid) {
  190. var codes = [];
  191. grid.store.each(function(d){
  192. codes.push("'" + d.get('mm_prodcode') + "'");
  193. });
  194. Ext.Ajax.request({
  195. url: basePath + 'scm/product/getProductwh.action',
  196. params: {
  197. codes: codes.join(',')
  198. },
  199. callback: function (opt, s, r) {
  200. if(s) {
  201. var rs = Ext.decode(r.responseText);
  202. if(rs.data) {
  203. grid.productwh = rs.data;
  204. }
  205. }
  206. }
  207. });
  208. },
  209. getSetting : function(f) {
  210. Ext.Ajax.request({
  211. url : basePath + 'common/getFieldData.action',
  212. async: false,
  213. params: {
  214. caller: 'Setting',
  215. field: 'se_value',
  216. condition: 'se_what=\'GroupWarehouse.OS\''
  217. },
  218. method : 'post',
  219. callback : function(opt, s, res){
  220. var r = new Ext.decode(res.responseText);
  221. if(r.exceptionInfo){
  222. showError(r.exceptionInfo);return;
  223. }
  224. if(r.success && r.data){
  225. if (r.data == 'false') {
  226. f.setValue(false);
  227. }
  228. }
  229. }
  230. });
  231. }
  232. });