MESServiceImpl.java 240 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426
  1. package com.uas.eis.service.Impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.alibaba.fastjson.serializer.SerializerFeature;
  6. import com.uas.eis.dao.BaseDao;
  7. import com.uas.eis.dao.SqlRowList;
  8. import com.uas.eis.dto.Key;
  9. import com.uas.eis.entity.*;
  10. import com.uas.eis.sdk.entity.ApiResult;
  11. import com.uas.eis.sdk.resp.ApiResponse;
  12. import com.uas.eis.service.MESService;
  13. import com.uas.eis.utils.*;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import javax.servlet.http.HttpServletRequest;
  21. import java.io.IOException;
  22. import java.util.*;
  23. /**
  24. * @author koul
  25. * @email koul@usoftchina.com
  26. * @date 2021-12-08 9:32
  27. */
  28. @Service
  29. public class MESServiceImpl implements MESService {
  30. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  31. @Autowired
  32. private BaseDao baseDao;
  33. @Autowired
  34. private TransferRepository transferRepository;
  35. @Override
  36. public ApiResult<String> checkVerifyApply(HttpServletRequest request) {
  37. String requestId = request.getHeader("RequestId");
  38. JSONObject jsonData = getJsonData(request);
  39. String mesCode = StringUtil.nvl(jsonData.get("mesCode"), "");
  40. if ("".equals(mesCode)){
  41. return ApiResponse.failRsp("10011",requestId,"MES编号不能为空!");
  42. }
  43. VerifyApply verifyApply = baseDao.getJdbcTemplate().queryForObject("select va_id,va_mescode,va_code,to_char(va_date,'yyyy-MM-dd HH24:mi:ss') va_date,va_vendcode,va_vendname,va_currency,va_rate,va_paymentscode,va_payments,va_transport,va_sendcode,va_emcode,va_emname,va_departmentcode,va_department,va_recorder,case when nvl(va_cop,' ')=' ' then 'BYT' else va_cop end va_cop,va_remark,va_ancode,va_factory,0 version,va_type,va_pucode,case when nvl(va_pucode,' ')=' ' then 0 else (select pu_id from purchase where pu_code=va_pucode) end pu_id,va_status,1 posted,to_char(va_auditdate,'yyyy-MM-dd HH24:mi:ss') va_auditdate,va_auditman,va_custcode,va_custname from VerifyApply where va_statuscode='AUDITED' and va_mescode=?",
  44. new BeanPropertyRowMapper<VerifyApply>(VerifyApply.class), mesCode);
  45. if (verifyApply==null) {
  46. return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
  47. }
  48. SqlRowList rs = baseDao.queryForRowSet("select case when va_custcode='AR214' or nvl(va_custcode,' ')=' ' then 'BYT' else nvl(cu_mescode,cu_code) end cu_code,cu_name from verifyapply left join customer on va_custcode=cu_code where va_statuscode='AUDITED' and va_mescode='"+mesCode+"'");
  49. if (rs.next()){
  50. verifyApply.setVa_custcode(rs.getString("cu_code"));
  51. }
  52. List<VerifyApplyDetail> verifyApplyDetails = baseDao.query("select vad_code,vad_prodcode,pr_detail,replace(PR_SPEC,'''','''''') pr_spec,pr_unit,va_recorder,va_date,pr_kh_user,cu_name,sum(nvl(vad_qty,0)) vad_qty,vad_salecode from ( select vad_code,vad_prodcode,pr_detail,pr_spec,pr_unit,vad_qty,va_recorder,to_char(va_date,'yyyy-MM-dd HH24:mi:ss') va_date,case when pr_kh_user='柏英特' or nvl(pr_kh_user,' ')=' ' then 'BYT' else nvl(cu_mescode,cu_code) end pr_kh_user,cu_name,vad_salecode from verifyapplydetail left join VerifyApply on va_id=vad_vaid left join product on vad_prodcode=pr_code left join customer on cu_shortname=pr_kh_user where nvl(vad_qty,0)>0 and vad_vaid="+verifyApply.getVa_id()+") group by vad_code,vad_prodcode,pr_detail,pr_spec,pr_unit,va_recorder,va_date,pr_kh_user,cu_name,vad_salecode", VerifyApplyDetail.class);
  53. verifyApply.setDetail(verifyApplyDetails);
  54. String s = JSON.toJSONString(verifyApply, SerializerFeature.WriteMapNullValue);
  55. return ApiResponse.successRsp("0","获取成功!",requestId,s);
  56. }
  57. @Override
  58. public ApiResult<String> purcCheckin(HttpServletRequest request) {
  59. String requestId = request.getHeader("RequestId");
  60. Map<String, JSONArray> data = getData(request);
  61. JSONArray jsonArray = data.get("main");
  62. Object vaid=0;
  63. String caller="VerifyApply!ToOtherIn";
  64. String type="其它入库单";
  65. String djcaller="ProdInOut!OtherIn";
  66. String sellerName="";
  67. for (int i = 0; i <jsonArray.size() ; i++) {
  68. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  69. String mesCode = StringUtil.nvl(jsonObject.get("mesCode"),"");
  70. if ("".equals(mesCode)){
  71. return ApiResponse.failRsp("10011",requestId,"ERP单据编号不能为空!");
  72. }
  73. int count = baseDao.getCountByCondition("verifyApply", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
  74. if (count<1){
  75. return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
  76. }
  77. vaid = baseDao.getFieldDataByCondition("verifyApply", "va_id", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
  78. String vaClass = StringUtil.nvl(baseDao.getFieldDataByCondition("VerifyApply", "va_class", "va_id=" + vaid), "");
  79. if ("委外收料单".equals(vaClass)) {
  80. caller = "VerifyApply!ToOutsideCheckIn";
  81. type = "委外验收单";
  82. djcaller = "ProdInOut!OutsideCheckIn";
  83. }else if("采购收料单".equals(vaClass)){
  84. int count1 = baseDao.getCount("select count(1) from VerifyApplyDetail where nvl(vad_pucode,' ')<>' ' and vad_vaid=" + vaid);
  85. if (count1 > 0) {
  86. caller = "VerifyApply!ToPurcIn";
  87. type = "采购验收单";
  88. djcaller = "ProdInOut!PurcCheckin";
  89. }
  90. }
  91. //判断已转数
  92. Object chekQty = baseDao.getJdbcTemplate().queryForObject("select wmsys.wm_concat('收料单:'||vad_code||'序号:'||vad_detno) from VerifyApplyDetail where vad_qty < vad_yqty and nvl(vad_qty,0)>0 and nvl(vad_prodcode,' ')<>' ' and vad_vaid = "+vaid, String.class);
  93. if(chekQty !=null){
  94. return ApiResponse.failRsp("10013",requestId,"检测到" + chekQty + ",本次数量超出可转数量!");
  95. }
  96. if ("VerifyApply!ToPurcIn".equals(caller)) {
  97. // 判断该收料单是否已经转入过采购验收单
  98. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  99. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and " + "PI_REFNO='采购收料单' and pi_class='采购验收单'");
  100. if (code != null && !code.equals("")) {
  101. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过采购验收单,验收单号[" + code + "]");
  102. }
  103. }
  104. if ("VerifyApply!ToOtherIn".equals(caller)) {
  105. // 判断该收料单是否已经转入过其它入库单
  106. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  107. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='其它入库单'");
  108. if (code != null && !code.equals("")) {
  109. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过其它入库单,单号[" + code + "]");
  110. }
  111. }
  112. if ("VerifyApply!ToOutsideCheckIn".equals(caller)) {
  113. // 判断该收料单是否已经转入过委外验收单
  114. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  115. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='委外验收单'");
  116. if (code != null && !code.equals("")) {
  117. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过委外验收单,单号[" + code + "]");
  118. }
  119. }
  120. sellerName = StringUtil.nvl(jsonObject.get("sellerName"), "mes");
  121. }
  122. JSONArray array = data.get("detail");
  123. for (int i = 0; i <array.size() ; i++) {
  124. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  125. String itemNo = StringUtil.nvl(json.get("itemNo"), "");
  126. Double qty = Double.parseDouble(StringUtil.nvl(json.get("qty"), "0"));
  127. Double vadQty = baseDao.getSummaryByField("verifyapplydetail", "vad_qty", "vad_prodcode='" + itemNo + "' and vad_vaid=" + vaid);
  128. int compare = qty.compareTo(vadQty);
  129. if (compare>0){
  130. return ApiResponse.failRsp("10017",requestId, "物料:"+itemNo+",收料数量:"+qty+"超出ERP收料单数量:"+vadQty+ ",不允许入库!");
  131. }
  132. if (compare<0){
  133. return ApiResponse.failRsp("10018",requestId,"物料:"+itemNo+",收料数量:"+qty+"少于ERP收料单数量:"+vadQty+",不允许入库!");
  134. }
  135. String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
  136. if ("".equals(whcode)){
  137. return ApiResponse.failRsp("10015",requestId,"MES仓库编号不能为空!");
  138. }
  139. int coun = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  140. if (coun<=0){
  141. return ApiResponse.failRsp("10016",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  142. }
  143. }
  144. int piid =0;
  145. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_name=?",
  146. new BeanPropertyRowMapper<Employee>(Employee.class), sellerName);
  147. // 转采购验收单
  148. Key key = transferRepository.transfer(caller, vaid,employee);
  149. piid = key.getId();
  150. // 转入明细
  151. transferRepository.transferDetail(caller, vaid, key,employee);
  152. if (piid != 0) {
  153. baseDao.execute("delete from prodiodetail where nvl(pd_inqty,0)<=0 and pd_piid="+piid);
  154. //更新仓库
  155. for (int i = 0; i <array.size() ; i++) {
  156. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  157. String itemNo = StringUtil.nvl(json.get("itemNo"), "");
  158. String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
  159. Object[] warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  160. baseDao.updateByCondition("prodiodetail", "pd_whcode='"+warehouses[0]+"',pd_whname='"+warehouses[1]+"'", "pd_prodcode='"+itemNo+"' and pd_piid=" + piid);
  161. }
  162. //baseDao.updateByCondition("prodinout", "pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"'","pi_id=" + piid);
  163. baseDao.execute("update prodiodetail set pd_prodid=(select pr_id from product where pd_prodcode=pr_code) where pd_piid=" + piid
  164. + " and nvl(pd_prodcode,' ')<>' '");
  165. baseDao.execute("update prodiodetail set pd_whid=(select wh_id from warehouse where wh_code=pd_whcode) where pd_piid=" + piid
  166. + " and nvl(pd_whcode,' ')<>' '");
  167. baseDao.updateByCondition("ProdInOut",
  168. "pi_total=(SELECT round(sum(nvl(pd_orderprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid="
  169. + piid + ")", "pi_id=" + piid);
  170. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + piid);
  171. if ("VerifyApply!ToPurcIn".equals(caller)) {
  172. baseDao.execute("Insert into ProdChargeDetail(pd_id,pd_piid,pd_detno,pd_type,pd_amount,pd_currency,pd_rate) "
  173. + "select ProdChargeDetail_seq.nextval, " + piid + ", pd_detno, pd_type,pd_amount,pd_currency,pd_rate "
  174. + "from ProdChargeDetailAN where PD_ANID=" + vaid);
  175. SqlRowList rs = baseDao.queryForRowSet("select vad_pucode,vad_pudetno,vad_qty from VerifyApplyDetail where vad_vaid=" + vaid);
  176. String pCode = null;
  177. int pDetno = 0;
  178. double yq = 0;
  179. Set<String> pCodes = new HashSet<String>();
  180. while (rs.next()) {
  181. pCode = rs.getString("vad_pucode");
  182. if (!pCodes.contains(pCode)) {
  183. pCodes.add(pCode);
  184. }
  185. pDetno = rs.getInt("vad_pudetno");
  186. yq = rs.getDouble("vad_qty");
  187. baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno);
  188. baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno
  189. + " and pd_qty=" + yq);
  190. }
  191. Iterator<String> iter = pCodes.iterator();
  192. while (iter.hasNext()) {
  193. pCode = iter.next();
  194. int total = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "'");
  195. int aud = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "' AND nvl(pd_acceptqty,0)=0");
  196. int turn = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode
  197. + "' AND nvl(pd_acceptqty,0)=nvl(pd_qty,0)");
  198. String statuscode = aud == total ? "" : (turn == total ? "TURNIN" : "PART2IN");
  199. String status = aud == total ? "" : (turn == total ? "已入库" : "部分入库");
  200. baseDao.updateByCondition("Purchase",
  201. "pu_turnstatuscode='" + statuscode + "',pu_turnstatus='" + status + "'", "pu_code='" + pCode + "'");
  202. }
  203. }
  204. // 修改收料状态
  205. baseDao.updateByCondition("VerifyApplyDetail", "vad_yqty=vad_qty", "vad_vaid=" + vaid);
  206. baseDao.updateByCondition("VerifyApply", "va_turnstatuscode='TURNIN',va_turnstatus='已入库'", "va_id=" + vaid);
  207. String s = postProdInOut(piid, djcaller, employee);
  208. logger.info("收料单入库=="+s);
  209. if (s!=null){
  210. return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",过账失败,请在ERP重新过账!");
  211. }
  212. return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",请在ERP查看!");
  213. }
  214. return ApiResponse.failRsp("10019",requestId,"ERP生成单据失败!");
  215. }
  216. @Override
  217. public ApiResult<String> prodInOutMakeIn(HttpServletRequest request) {
  218. String requestId = request.getHeader("RequestId");
  219. Map<String, JSONArray> data = getData(request);
  220. JSONArray jsonArray = data.get("main");
  221. String ma_tasktype="";
  222. int piid=0;
  223. String picode="";
  224. String piclass="完工入库单";
  225. String picaller="ProdInOut!Make!In";
  226. int ma_id=0;
  227. List<String> sqls = new ArrayList<>();
  228. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  229. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  230. JSONArray array = data.get("detail");
  231. if(array!=null&&array.size()>0) {
  232. for (int i = 0; i < array.size(); i++) {
  233. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  234. String macode = StringUtil.nvl(json.get("FICMOBillNo"),"");
  235. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
  236. if (data1 != null && data1.length > 0) {
  237. ma_tasktype = StringUtil.nvl(data1[0], "");
  238. ma_id = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  239. } else {
  240. return ApiResponse.failRsp("10077", requestId, "工单在ERP不存在,请核对!");
  241. }
  242. /*float fauxqty = json.get("Fauxqty") == null ? 0 : Float.parseFloat(json.get("Fauxqty").toString());
  243. String msg = baseDao.callProcedure("USER_WGRKCHECK", new Object[]{ma_id, fauxqty});
  244. if (msg != null && !msg.trim().equals("")){
  245. return ApiResponse.failRsp("10078",requestId,msg);
  246. }*/
  247. }
  248. }
  249. if ("OS".equals(ma_tasktype)) {
  250. picaller = "ProdInOut!OutsideCheckIn";
  251. piclass = "委外验收单";
  252. }
  253. for (int i = 0; i <jsonArray.size() ; i++) {
  254. Object obj = jsonArray.get(i);
  255. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(obj, ""));
  256. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  257. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
  258. if (result!=null){
  259. return result;
  260. }
  261. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDCStockID")));
  262. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  263. Map<Object, Object> map6 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  264. Map<Object, Object> map7 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  265. Map<Object, Object> map8 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  266. String whcode = StringUtil.nvl(map4.get("FNumber"), "");
  267. if ("".equals(whcode)) {
  268. return ApiResponse.failRsp("10073", requestId, "MES仓库编号不能为空!");
  269. }
  270. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  271. if (count <= 0) {
  272. return ApiResponse.failRsp("10074", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  273. }
  274. Object[] warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  275. if ("OS".equals(ma_tasktype)) {
  276. // 转入委外验收单主记录
  277. piid = baseDao.getSeqId("PRODINOUT_SEQ");
  278. picode = baseDao.sGetMaxNumber(picaller, 2);
  279. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_whcode,pi_whname,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_mescode) " +
  280. "values (" + piid + ",'" + picode + "','"+piclass+"',to_date('" + jsonObject2.get("Fdate") + "','yyyy-MM-dd HH24:mi:ss'),'UNPOST'," + "'未过账','" + warehouses[0] + "','" + warehouses[1] + "','" + map5.get("FNumber") + "','" + map5.get("FName") + "','" + map6.get("FNumber") + "','" + map7.get("FName") + "','ENTERING','在录入','" + map8.get("FName") + "',to_date('" + jsonObject2.get("Fdate") + "','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+fSelBillNo+"')");
  281. sqls.add("update prodinout set (pi_cardcode,pi_title,pi_currency,pi_rate,pi_receivecode," +
  282. "pi_receivename,pi_cardid,pi_paymentcode,pi_payment,pi_cop,pi_belongs," +
  283. "pi_sourcecode,pi_sellercode)=(select ma_vendcode,ma_vendname,ma_currency,ma_rate,ve_apvendcode," +
  284. "ve_apvendname,ve_id,ma_paymentscode,ma_payments,ma_cop,ve_buyername,ma_code,em_code from make left " +
  285. "join Vendor on ma_vendcode=ve_code left join employee on ve_buyerid=em_id where ma_id="+ma_id+") where pi_class='"+piclass+"' and pi_id="+piid);
  286. sqls.add("update ProdinOut set pi_sellername=pi_belongs where pi_class='"+piclass+"' and pi_id=" + piid);
  287. sqls.add("update ProdinOut set pi_rate=(select CR_RATE from Currencys where pi_currency=cr_name) where pi_class='"+piclass+"' and pi_id=" + piid + " and nvl(pi_rate,0)=0");
  288. } else {
  289. piid = baseDao.getSeqId("PRODINOUT_SEQ");
  290. picode = baseDao.sGetMaxNumber(picaller, 2);
  291. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_whcode,pi_whname,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_mescode) " +
  292. "values (" + piid + ",'" + picode + "','"+piclass+"',to_date('" + jsonObject2.get("Fdate") + "','yyyy-MM-dd HH24:mi:ss'),'UNPOST'," + "'未过账','" + warehouses[0] + "','" + warehouses[1] + "','" + map5.get("FNumber") + "','" + map5.get("FName") + "','" + map6.get("FNumber") + "','" + map7.get("FName") + "','ENTERING','在录入','" + map8.get("FName") + "',to_date('" + jsonObject2.get("Fdate") + "','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+fSelBillNo+"')");
  293. }
  294. }
  295. int detno=1;
  296. for (int i = 0; i <array.size(); i++) {
  297. Object obj = array.get(i);
  298. JSONObject jsonObject3 = JSON.parseObject(StringUtil.nvl(obj, ""));
  299. Map<Object, Object> map11 = JSONUtil.toMap(StringUtil.valueOf(jsonObject3.get("FItemID")));
  300. Map<Object, Object> map12 = JSONUtil.toMap(StringUtil.valueOf(jsonObject3.get("FDCStockID1")));
  301. String whcode = StringUtil.nvl(map12.get("FNumber"), "");
  302. if ("".equals(whcode)){
  303. return ApiResponse.failRsp("10075",requestId,"MES仓库编号不能为空!");
  304. }
  305. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  306. if (count<=0){
  307. return ApiResponse.failRsp("10076",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  308. }
  309. Object[] warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  310. String fBatchNo = StringUtil.nvl(jsonObject3.get("FBatchNo"), "");
  311. float fauxqty = jsonObject3.get("Fauxqty") == null ? 0 : Float.parseFloat(jsonObject3.get("Fauxqty").toString());
  312. String fSecUnitID = StringUtil.nvl(jsonObject3.get("FSecUnitID"), "");
  313. float fSecCoefficient = jsonObject3.get("FSecCoefficient") == null ? 0 : Float.parseFloat(jsonObject3.get("FSecCoefficient").toString());
  314. float fSecQty = jsonObject3.get("FSecQty") == null ? 0 : Float.parseFloat(jsonObject3.get("FSecQty").toString());
  315. float fAuxPlanPrice = jsonObject3.get("FAuxPlanPrice") == null ? 0 : Float.parseFloat(jsonObject3.get("FAuxPlanPrice").toString());
  316. float fPlanAmount = jsonObject3.get("FPlanAmount") == null ? 0 : Float.parseFloat(jsonObject3.get("FPlanAmount").toString());
  317. float fauxprice = jsonObject3.get("Fauxprice") == null ? 0 : Float.parseFloat(jsonObject3.get("Fauxprice").toString());
  318. float famount = jsonObject3.get("Famount") == null ? 0 : Float.parseFloat(jsonObject3.get("Famount").toString());
  319. String fnote = StringUtil.nvl(jsonObject3.get("Fnote"), "");
  320. String fKFDate = StringUtil.nvl(jsonObject3.get("FKFDate"), "");
  321. String fPeriodDate = StringUtil.nvl(jsonObject3.get("FPeriodDate"), "");
  322. int fDCSPID = jsonObject3.get("FDCSPID") == null ? 0 : Integer.parseInt(jsonObject3.get("FDCSPID").toString());
  323. Object location="";
  324. if (fDCSPID>0){
  325. location = baseDao.getFieldDataByCondition("ProductLocation", "pl_name", "pl_id=" + fDCSPID);
  326. }
  327. String fSourceBillNo = StringUtil.nvl(jsonObject3.get("FSourceBillNo"), "");
  328. String fICMOBillNo = StringUtil.nvl(jsonObject3.get("FICMOBillNo"), "");
  329. String fEntrySelfA0248 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0248"), "");
  330. String fEntrySelfA0245 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0245"), "");
  331. String fEntrySelfA0246 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0246"), "");
  332. String fEntrySelfA0247 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0247"), "0");
  333. String fEntrySelfA0242 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0242"), "0");
  334. if ("OS".equals(ma_tasktype)) {
  335. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_ordercode,pd_prodcode," +
  336. "pd_batchcode,pd_inqty,pd_nxlh,pd_purcrate,pd_notinqty,pd_orderprice,pd_ordertotal,pd_price," +
  337. "pd_total,pd_whcode,pd_whname,pd_remark,pd_prodmadedate,pd_replydate,pd_location,pd_macode,pd_xb," +
  338. "pd_bz,pd_dbds,pd_zds,pd_status) values (PRODIODETAIL_SEQ.nextval," + piid + ",'" + picode + "','"+piclass+
  339. "'," + detno + ",'" + fSourceBillNo +
  340. "','" + map11.get("FNumber") + "','" + fBatchNo + "'," + fauxqty + ",'" + fSecUnitID + "'," + fSecCoefficient + "," + fSecQty + "," + fAuxPlanPrice + "," + fPlanAmount + "," + fauxprice + "," +
  341. "" + famount + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + fnote + "',to_date('" + fEntrySelfA0248 + "'," +
  342. "'yyyy-MM-dd HH24:mi:ss'),to_date('" + fPeriodDate + "','yyyy-MM-dd HH24:mi:ss'),'" + location + "','" + fICMOBillNo + "','" + fEntrySelfA0246 + "','" + fEntrySelfA0245 + "'," + fEntrySelfA0247 + "," + fEntrySelfA0242 + ",0)");
  343. detno++;
  344. }else {
  345. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_ordercode,pd_prodcode," +
  346. "pd_batchcode,pd_inqty,pd_nxlh,pd_purcrate,pd_notinqty,pd_orderprice,pd_ordertotal,pd_price," +
  347. "pd_total,pd_whcode,pd_whname,pd_remark,pd_prodmadedate,pd_replydate,pd_location,pd_macode,pd_xb," +
  348. "pd_bz,pd_dbds,pd_zds,pd_status) values (PRODIODETAIL_SEQ.nextval," + piid + ",'" + picode + "','"+piclass+
  349. "'," + detno + ",'" + fSourceBillNo +
  350. "','" + map11.get("FNumber") + "','" + fBatchNo + "'," + fauxqty + ",'" + fSecUnitID + "'," + fSecCoefficient + "," + fSecQty + "," + fAuxPlanPrice + "," + fPlanAmount + "," + fauxprice + "," +
  351. "" + famount + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + fnote + "',to_date('" + fEntrySelfA0248 + "'," +
  352. "'yyyy-MM-dd HH24:mi:ss'),to_date('" + fPeriodDate + "','yyyy-MM-dd HH24:mi:ss'),'" + location + "','" + fICMOBillNo + "','" + fEntrySelfA0246 + "','" + fEntrySelfA0245 + "'," + fEntrySelfA0247 + "," + fEntrySelfA0242 + ",0)");
  353. detno++;
  354. }
  355. }
  356. if ("OS".equals(ma_tasktype)) {
  357. sqls.add("update prodiodetail set (pd_location,pd_orderprice,pd_taxrate,pd_prodid,pd_orderid,pd_wccode)=" +
  358. "(select pr_location,ma_price,ma_taxrate,pr_id,ma_id,ma_wccode from make left join Product on " +
  359. "ma_prodcode=pr_code where ma_id="+ma_id+") where pd_piid="+piid);
  360. sqls.add("update Prodiodetail set pd_whname=(select wh_description from warehouse where pd_whcode=wh_code) where pd_piid="
  361. + piid);
  362. sqls.add("update Prodiodetail set pd_total=round(pd_inqty*pd_orderprice,2) where pd_piid=" + piid);
  363. }
  364. //更新已转完工数
  365. sqls.add("update make set ma_tomadeqty=nvl((select sum(pd_inqty)-sum(case when pd_status=99 then pd_outqty else 0 end) from prodiodetail where pd_ordercode=ma_code and pd_piclass in('完工入库单','委外验收单','委外验退单')),0) where ma_id=" + ma_id);
  366. sqls.add("update make set ma_tomadeqty=ma_madeqty where ma_id=" + ma_id + " and nvl(ma_madeqty,0)>nvl(ma_tomadeqty,0)");
  367. //更新最大套料数
  368. sqls.add("update make set ma_canmadeqty=nvl((select min(case when NVL(mm_havegetqty,0)-NVL(mm_scrapqty,0)>=mm_qty then ma_qty else floor(( nvl(mm_havegetqty, 0)-nvl(mm_scrapqty,0))*1.0/mm_oneuseqty )end) from makematerial where mm_maid=ma_id and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0 and mm_oneuseqty*ma_qty<=mm_qty+0.1 ),0) where ma_id in (" + ma_id + ") ");
  369. sqls.add("update make set ma_canmadeqty=ma_qty where ma_id in (" + ma_id
  370. + ") and ma_id not in (select ma_id from make left join makematerial on ma_id=mm_maid where ma_id in (" + ma_id
  371. + ") and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0 and mm_oneuseqty*ma_qty<=mm_qty+0.1)");
  372. sqls.add("update make set ma_canmadeqty=0 where ma_id in (" + ma_id + ") and NVL(ma_canmadeqty,0)<=0");
  373. baseDao.execute(sqls);
  374. String s = postProdInOut(piid, picaller, employee);
  375. logger.info("完工过账信息=="+s);
  376. if (s!=null){
  377. return ApiResponse.successRsp("0",requestId,piclass+":"+picode+",过账失败,请在ERP重新过账!");
  378. }
  379. return ApiResponse.successRsp("0",requestId,piclass+":"+picode+",请在ERP查看!");
  380. }
  381. @Override
  382. public ApiResult<String> makeDeleteCheck(HttpServletRequest request) {
  383. String requestId = request.getHeader("RequestId");
  384. JSONObject jsonData = getJsonData(request);
  385. Object maId = jsonData.get("finterid");
  386. // 只能删除在录入的单据!
  387. SqlRowList status =
  388. baseDao.queryForRowSet("select ma_statuscode,ma_checkstatuscode from make where ma_code='"+maId+"'");
  389. if (status.next()) {
  390. if (!status.getString("ma_statuscode").equals("ENTERING") && (status.getString("ma_checkstatuscode").equals("APPROVE") || status.getString("ma_checkstatuscode").equals("COMMITED"))) {
  391. return ApiResponse.failRsp("10015",requestId,"只能删除在录入且批准状态不等于已批准或已提交的工单");
  392. }
  393. }
  394. // 启用工厂模式 有对应的作业单 制造单不能删除
  395. if (baseDao.isDBSetting("sys","usingMakeCraft")) {
  396. int count = baseDao.getCount("Select count(1) from makecraft left join make on mc_makecode=ma_code where ma_code='"+maId+"'");
  397. if (count > 0) {
  398. return ApiResponse.failRsp("10016",requestId,"当前工单存在作业单,不能删除");
  399. }
  400. }
  401. return ApiResponse.successRsp("0",requestId,"校验通过!");
  402. }
  403. @Override
  404. public ApiResult<String> initMakeScrap(HttpServletRequest request) {
  405. String requestId = request.getHeader("RequestId");
  406. Map<String, JSONArray> data = getData(request);
  407. JSONArray jsonArray = data.get("main");
  408. int id=0;
  409. String code="";
  410. String msclass="生产报废单";
  411. String caller="MakeScrap";
  412. List<String> sqls = new ArrayList<>();
  413. for (int i = 0; i <jsonArray.size() ; i++) {
  414. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  415. String fSelBillNo = StringUtil.nvl(jsonObject.get("FSelBillNo"), "");
  416. if ("".equals(fSelBillNo)){
  417. return ApiResponse.failRsp("10029", requestId, "MES单号不能为空!");
  418. }
  419. int count = baseDao.getCount("select count(1) from MakeScrap where ms_class='" + msclass + "' and ms_mescode='" + fSelBillNo + "'");
  420. if (count>0){
  421. Object co = baseDao.getFieldDataByCondition("MakeScrap", "ms_code", "ms_class='" + msclass + "' and ms_mescode='" + fSelBillNo + "'");
  422. return ApiResponse.successRsp("0",requestId,"MES单号:"+fSelBillNo+"已存在,请在ERP查看"+msclass+",单据编号:"+co);
  423. }
  424. id = baseDao.getSeqId("MAKESCRAP_SEQ");
  425. code = baseDao.sGetMaxNumber(caller, 2);
  426. String fdateTime = StringUtil.nvl(jsonObject.get("FdateTime"), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
  427. String fwcCode = StringUtil.nvl(jsonObject.get("FwcCode"), "");
  428. if ("".equals(fwcCode)) {
  429. return ApiResponse.failRsp("10021", requestId, "工作中心不能为空!");
  430. }
  431. String createdUser = StringUtil.nvl(jsonObject.get("createdUser"), "mes");
  432. String createdDateTime = StringUtil.nvl(jsonObject.get("createdDateTime"), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
  433. String companyNo = StringUtil.nvl(jsonObject.get("companyNo"), "BYT");
  434. String fremark = StringUtil.nvl(jsonObject.get("Fremark"), "");
  435. sqls.add("insert into MakeScrap (ms_id,ms_code,ms_class,ms_statuscode,ms_status,ms_printstatuscode,ms_printstatus,ms_date,ms_wccode,ms_recordman,ms_indate,ms_cop,ms_remark,ms_mescode) values (" + id + ",'" + code + "','"+msclass+ "','ENTERING','在录入','UNPRINT','未打印',to_date('" + fdateTime + "','yyyy-MM-dd HH24:mi:ss'),'" + fwcCode + "','" + createdUser + "',to_date('" + createdDateTime + "','yyyy-MM-dd HH24:mi:ss'),'" + companyNo + "','" + fremark + "','"+fSelBillNo+"')");
  436. }
  437. JSONArray array = data.get("detail");
  438. int detno=1;
  439. for (int i = 0; i <array.size(); i++) {
  440. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  441. String lineId = StringUtil.nvl(object.get("lineId"), "");
  442. if ("".equals(lineId)){
  443. return ApiResponse.failRsp("10022",requestId,"工单明细ID不能为空!");
  444. }
  445. Object mmdetno = baseDao.getFieldDataByCondition("MakeMaterial", "mm_detno", "mm_id in (" + lineId+")");
  446. String prodNo = StringUtil.nvl(object.get("prodNo"), "");
  447. if ("".equals(prodNo)){
  448. return ApiResponse.failRsp("10023",requestId,"工单单号不能为空!");
  449. }
  450. String prodDetno = StringUtil.nvl(object.get("prodDetno"), "");
  451. if ("".equals(prodDetno)){
  452. return ApiResponse.failRsp("10024",requestId,"工单行号不能为空!");
  453. }
  454. String itemNo = StringUtil.nvl(object.get("itemNo"), "");
  455. if ("".equals(itemNo)){
  456. return ApiResponse.failRsp("10024",requestId,"物料不能为空!");
  457. }
  458. String qty = StringUtil.nvl(object.get("qty"), "");
  459. if ("".equals(qty)){
  460. return ApiResponse.failRsp("10025",requestId,"报废数量不能为空!");
  461. }
  462. String reason = StringUtil.nvl(object.get("reason"), "");
  463. if ("".equals(reason)){
  464. return ApiResponse.failRsp("10026",requestId,"报废原因不能为空!");
  465. }
  466. String fDeptID = StringUtil.nvl(object.get("FDeptID"), "");
  467. if ("".equals(fDeptID)){
  468. return ApiResponse.failRsp("10027",requestId,"责任部门编号不能为空!");
  469. }
  470. String fDept = StringUtil.nvl(object.get("FDept"), "");
  471. if ("".equals(fDept)){
  472. return ApiResponse.failRsp("10028",requestId,"责任部门不能为空!");
  473. }
  474. String allScrapQty = StringUtil.nvl(object.get("AllScrapQty"), "0");
  475. String remark = StringUtil.nvl(object.get("remark"), "");
  476. sqls.add("insert into MakeScrapdetail (md_id,md_msid,md_detno,md_mmid,md_mmcode,md_mmdetno,md_prodcode,md_qty,md_reason,md_department,md_departmentname,md_allscrapqty,md_remark) values " +
  477. "(MAKESCRAPDETAIL_SEQ.nextval,"+id+","+detno+","+lineId+",'"+prodNo+"',"+mmdetno+",'"+itemNo+ "',"+qty+",'"+reason+"','"+fDeptID+"','"+fDept+"',"+allScrapQty+",'"+remark+"')");
  478. detno++;
  479. }
  480. baseDao.execute(sqls);
  481. return ApiResponse.successRsp("0",requestId,"生产报废单:"+code+",请在ERP查看!");
  482. }
  483. @Override
  484. public ApiResult<String> prodInOutOtherOut(HttpServletRequest request) {
  485. String requestId = request.getHeader("RequestId");
  486. Map<String, JSONArray> data = getData(request);
  487. JSONArray jsonArray = data.get("main");
  488. int id=0;
  489. String code="";
  490. String caller="ProdInOut!OtherOut";
  491. String piclass="其它出库单";
  492. List<String> sqls = new ArrayList<>();
  493. for (int i = 0; i <jsonArray.size() ; i++) {
  494. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  495. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  496. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
  497. if (result!=null){
  498. return result;
  499. }
  500. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  501. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillTypeID")));
  502. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  503. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  504. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  505. //客户编号 客户单号
  506. String fCustCode = StringUtil.nvl(jsonObject2.get("FCustCode"), "");
  507. String fCustNo = StringUtil.nvl(jsonObject2.get("FCustNo"), "");
  508. Object cuname="";
  509. if (!"".equals(fCustCode)){
  510. cuname = baseDao.getFieldDataByCondition("Customer", "cu_name", "cu_code='" + fCustCode + "'");
  511. }
  512. id = baseDao.getSeqId("PRODINOUT_SEQ");
  513. code = baseDao.sGetMaxNumber(caller, 2);
  514. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_type,pi_mescode,pi_cardcode,pi_title,pi_custno) " +
  515. "values ("+id+",'"+code+"','"+piclass+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPOST','未过账','"+map1.get("FNumber")+"','"+map1.get("FName")+"','"+map3.get("FNumber")+"','"+map3.get("FName")+"','AUDITED','已审核','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+map2.get("FName")+"','"+fSelBillNo+"','"+fCustCode+"','"+cuname+"','"+fCustNo+"')");
  516. }
  517. JSONArray array = data.get("detail");
  518. int detno=1;
  519. for (int i = 0; i <array.size(); i++) {
  520. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  521. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  522. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  523. if ("".equals(itemNo)){
  524. return ApiResponse.failRsp("10031",requestId,"物料不能为空!");
  525. }
  526. String qty = StringUtil.nvl(object.get("FAuxQtyMust"), "");
  527. if ("".equals(qty)){
  528. return ApiResponse.failRsp("10032",requestId,"实出数量不能为空!");
  529. }
  530. String fnote = StringUtil.nvl(object.get("Fnote"), "");
  531. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDCStockID1")));
  532. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  533. String whname = StringUtil.nvl(map1.get("FName"), "");
  534. if ("".equals(whcode)){
  535. return ApiResponse.failRsp("10034",requestId,"MES仓库编号不能为空!");
  536. }
  537. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  538. if (count<=0){
  539. return ApiResponse.failRsp("10035",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  540. }
  541. Object[] warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  542. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_prodcode,pd_outqty,pd_whcode,pd_whname,pd_remark) " +
  543. "values (PRODIODETAIL_SEQ.nextval,"+id+",'"+code+"','其它出库单',"+detno+",'"+itemNo+ "',"+qty+",'"+warehouses[0]+"','"+warehouses[1]+"','"+fnote+"')");
  544. detno++;
  545. }
  546. baseDao.execute(sqls);
  547. /*Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  548. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  549. String s = postProdInOut(id, caller, employee);
  550. logger.info("其它出库单过账信息=="+s);
  551. if (s!=null){
  552. return ApiResponse.successRsp("0",requestId,"其它出库单:"+code+",过账失败,请在ERP重新过账!");
  553. }*/
  554. return ApiResponse.successRsp("0",requestId,"其它出库单:"+code+",请在ERP查看!");
  555. }
  556. @Override
  557. public ApiResult<String> prodInOutPicking(HttpServletRequest request) {
  558. String requestId = request.getHeader("RequestId");
  559. Map<String, JSONArray> data = getData(request);
  560. JSONArray jsonArray = data.get("main");
  561. String bccode = null;
  562. int bcpiid = 0;
  563. String llcode = null;
  564. int llpiid=0;
  565. String ma_tasktype=null;
  566. int maid=0;
  567. String llpiclass = "生产领料单", llcaller = "ProdInOut!Picking", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
  568. // 是否生成调拨单,勾选不生成,不勾选默认生成
  569. Boolean notCreateAppropriation = baseDao.isDBSetting("MultiMakeSendLS", "notCreateAppropriation");
  570. List<String> sqls = new ArrayList<>();
  571. JSONArray array = data.get("detail");
  572. if(array!=null&&array.size()>0){
  573. String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "{}")).get("FICMOBillNo"));
  574. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
  575. if (data1!=null&&data1.length>0) {
  576. ma_tasktype = StringUtil.nvl(data1[0], "");
  577. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  578. }else {
  579. return ApiResponse.failRsp("10046", requestId, "工单在ERP不存在,请核对!");
  580. }
  581. }
  582. for (int i = 0; i <jsonArray.size() ; i++) {
  583. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  584. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  585. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FPurposeID")));
  586. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  587. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  588. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  589. if ("OS".equals(ma_tasktype)) {
  590. llpiclass = "委外领料单";
  591. llcaller = "ProdInOut!OutsidePicking";
  592. }
  593. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  594. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, llpiclass);
  595. if (result!=null){
  596. return result;
  597. }
  598. ApiResult<String> result1 = checkMESCode(requestId, fSelBillNo, bcpiclass);
  599. if (result1!=null){
  600. return result1;
  601. }
  602. if(!notCreateAppropriation){
  603. //生成拨出单
  604. bcpiid = baseDao.getSeqId("PRODINOUT_SEQ");
  605. bccode = baseDao.sGetMaxNumber(bccaller, 2);
  606. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_type,pi_mescode) " +
  607. "values ("+bcpiid+",'"+bccode+"','"+bcpiclass+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPOST','未过账','"+map1.get("FNumber")+"','"+map1.get("FName")+"','"+map4.get("FNumber")+"','"+map4.get("FName")+"','ENTERING','在录入','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','库存转移','"+fSelBillNo+"')");
  608. }
  609. //生成领料单
  610. llpiid = baseDao.getSeqId("PRODINOUT_SEQ");
  611. llcode = baseDao.sGetMaxNumber(llcaller, 2);
  612. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_type,pi_mescode) " +
  613. "values ("+llpiid+",'"+llcode+"','"+llpiclass+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPOST','未过账','"+map1.get("FNumber")+"','"+map1.get("FName")+"','"+map4.get("FNumber")+"','"+map4.get("FName")+"','ENTERING','在录入','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+map2.get("FName")+"','"+fSelBillNo+"')");
  614. // 标示领料单的拨出单号
  615. sqls.add("update ProdInOut set pi_fromcode='" + bccode + "' where pi_id=" + llpiid);
  616. }
  617. Object[] warehouses=null;
  618. Object[] warehouses2=null;
  619. int detno=1;
  620. int det=1;
  621. for (int i = 0; i <array.size(); i++) {
  622. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  623. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  624. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  625. if ("".equals(itemNo)){
  626. return ApiResponse.failRsp("10041",requestId,"物料不能为空!");
  627. }
  628. String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
  629. if ("0".equals(fAuxQty)){
  630. return ApiResponse.failRsp("10042",requestId,"实发数量不能为空!");
  631. }
  632. Double qty = Double.parseDouble(fAuxQty);
  633. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  634. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  635. if ("".equals(whcode)){
  636. return ApiResponse.failRsp("10043",requestId,"发料仓库不能为空!");
  637. }
  638. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  639. if (count<=0){
  640. return ApiResponse.failRsp("10044",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  641. }
  642. warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  643. String fSourceInterId = StringUtil.nvl(object.get("FSourceInterId"), "");
  644. String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
  645. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  646. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  647. if ("".equals(whcode2)){
  648. return ApiResponse.failRsp("10043",requestId,"物料所在仓库不能为空!");
  649. }
  650. int count2 = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  651. if (count2<=0){
  652. return ApiResponse.failRsp("10044",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  653. }
  654. warehouses2 = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  655. int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
  656. int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  657. if (count4<=0){
  658. return ApiResponse.failRsp("10046",requestId,"工单BOM在ERP没有不存在,明细ID:"+lineId+",请联系管理员!");
  659. }
  660. Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial", "mm_detno,mm_maid","mm_id in (" + lineId + ")");
  661. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  662. if(bccode!=null) {
  663. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_prodcode,pd_outqty,pd_whcode,pd_whname,pd_inwhcode,pd_inwhname,pd_macode,pd_madetno) values (PRODIODETAIL_SEQ.nextval," + bcpiid + ",'" + bccode + "','"+bcpiclass+"'," + detno + ",'" + itemNo + "'," + qty + ",'" + warehouses2[0] + "','" + warehouses2[1] + "','" + warehouses[0] + "','" + warehouses[1] + "','"+ficmoBillNo+"',"+data1[0]+")");
  664. detno++;
  665. }
  666. int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_prodcode='" + itemNo + "' and mm_id in (" + lineId + ")");
  667. if (count1>0) {
  668. SqlRowList sqlRowList = baseDao.queryForRowSet("select sum(round((mm_qty-nvl(mm_canuserepqty,0)-(nvl(mm_havegetqty,0)-nvl(mm_haverepqty,0)+(nvl(mm_returnmqty,0)-nvl(mm_repreturnmqty,0))-(nvl(mm_addqty,0)-NVL(mm_repaddqty,0)))-nvl(mm_totaluseqty,0)+NVL(mm_repqty,0))-NVL(mm_stepinqty,0),7)) mmqty from MakeMaterial where mm_prodcode='" + itemNo + "' and mm_id in (" + lineId + ")");
  669. if (sqlRowList.next()) {
  670. Double mmqty = sqlRowList.getGeneralDouble("mmqty");
  671. qty = qty.compareTo(mmqty) > 0 ? mmqty : qty;
  672. }
  673. }else {
  674. int count3 = baseDao.getCount("select count(1) from MakeMaterialreplace where mp_prodcode='" + itemNo + "' and mp_mmid in (" + lineId + ")");
  675. if (count3>0){
  676. SqlRowList sqlRowList1 = baseDao.queryForRowSet("select sum(nvl(mp_canuseqty,0)-(nvl(mp_haverepqty,0)-NVL(mp_addqty,0)+NVL(mp_returnmqty,0))-nvl(mp_repqty,0)) mpqty from MakeMaterialreplace where mp_prodcode='" + itemNo + "' and mp_mmid in (" + lineId + ")");
  677. if (sqlRowList1.next()){
  678. Double mpqty = sqlRowList1.getGeneralDouble("mpqty");
  679. qty = qty.compareTo(mpqty) > 0 ? mpqty : qty;
  680. }
  681. }
  682. }
  683. if (qty>0) {
  684. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_prodcode,pd_outqty,pd_whcode,pd_whname,pd_ordercode,pd_orderdetno,pd_macode,pd_madetno,pd_status) values (PRODIODETAIL_SEQ.nextval," + llpiid + ",'" + llcode + "','" + llpiclass + "'," + det + ",'" + itemNo + "'," + qty + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + ficmoBillNo + "'," + data1[0] + ",'" + ficmoBillNo + "'," + data1[0] + ",0)");
  685. det++;
  686. }
  687. }
  688. if ("OS".equals(ma_tasktype)) {
  689. sqls.add("update prodinout set(pi_cardcode,pi_title,pi_receivecode,pi_receivename) = (select max(ma_vendcode),max(ma_vendname),max(nvl(ma_apvendcode,ma_vendcode)),max(nvl(ma_apvendname,ma_vendname)) from make where ma_id in (" + maid + ")) where pi_id=" + llpiid);
  690. }
  691. if (warehouses2!=null){
  692. sqls.add("update prodinout set pi_whcode='"+warehouses2[0]+"',pi_whname='"+warehouses2[1]+"' where " + "pi_id="+bcpiid);
  693. }
  694. if (warehouses!=null){
  695. sqls.add("update prodinout set pi_purpose='"+warehouses[0]+"',pi_purposename='"+warehouses[1]+"' where pi_id="+bcpiid);
  696. }
  697. baseDao.execute(sqls);
  698. refreshTurnQty(maid,0);
  699. setBackQty(String.valueOf(maid),0);
  700. int count = baseDao.getCount("select count(1) from prodiodetail where pd_piid=" + llpiid);
  701. if (count<=0){
  702. baseDao.deleteById("prodinout","pi_id",llpiid);
  703. }
  704. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  705. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  706. String s = postProdInOut(bcpiid, bccaller, employee);
  707. logger.info("S=="+s);
  708. if (s!=null){
  709. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+",过账失败,请在ERP重新过账!");
  710. }else {
  711. if (count>0) {
  712. String s1 = postProdInOut(llpiid, llcaller, employee);
  713. logger.info("S1==" + s1);
  714. refreshTurnQty(maid,0);
  715. setBackQty(String.valueOf(maid),0);
  716. if (s1 != null) {
  717. return ApiResponse.successRsp("0", requestId, llpiclass+":" + llcode + ",过账失败,请在ERP重新过账!");
  718. }
  719. }
  720. }
  721. return ApiResponse.successRsp("0",requestId,llpiclass+":"+llcode+","+bcpiclass+":"+bccode+ ",请在ERP查看!");
  722. }
  723. @Override
  724. public ApiResult<String> prodInOutMakeReturn(HttpServletRequest request) {
  725. String requestId = request.getHeader("RequestId");
  726. Map<String, JSONArray> data = getData(request);
  727. JSONArray jsonArray = data.get("main");
  728. int id=0;
  729. String code="";
  730. int tlid=0;
  731. String tlcode = "";
  732. String macode="";
  733. String ma_tasktype="制程不良";
  734. //良品退仓、来料不良、制程不良
  735. String taskType=null;
  736. int maid=0;
  737. String tlpiclass = "生产退料单", tlcaller = "ProdInOut!Make!Return", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
  738. List<String> sqls = new ArrayList<>();
  739. int frob=99;
  740. JSONArray array = data.get("detail");
  741. Object[] warehouses=null;
  742. Object[] warehouses2=null;
  743. if(array!=null&&array.size()>0) {
  744. macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "")).get("FICMOBillNo"));
  745. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
  746. if (data1 != null && data1.length > 0) {
  747. ma_tasktype = StringUtil.nvl(data1[0], "");
  748. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  749. } else {
  750. return ApiResponse.failRsp("10057", requestId, "工单在ERP不存在,请核对!");
  751. }
  752. for (int i = 0; i <array.size(); i++) {
  753. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  754. Object lineId = object.get("lineId");
  755. //线边仓
  756. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  757. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  758. if ("".equals(whcode)) {
  759. return ApiResponse.failRsp("10053", requestId, "仓库编号不能为空!");
  760. }
  761. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  762. if (count <= 0) {
  763. return ApiResponse.failRsp("10054", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  764. }
  765. //大仓
  766. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  767. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  768. if ("".equals(whcode2)) {
  769. return ApiResponse.failRsp("10055", requestId, "物料退回仓库不能为空!");
  770. }
  771. int count2 = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  772. if (count2 <= 0) {
  773. return ApiResponse.failRsp("10056", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  774. }
  775. /*warehouses2 = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  776. //获取领料单拨出仓库
  777. int mmdetno = Integer.parseInt(StringUtil.nvl(baseDao.getFieldDataByCondition("MakeMaterial","mm_detno","mm_id in (" + lineId + ")"), "0"));
  778. Object data2 = baseDao.getFieldDataByCondition("prodiodetail", "min(pd_batchcode)","pd_piclass='生产领料单' and pd_ordercode='" + macode + "' and pd_orderdetno=" + mmdetno);
  779. Object pdwhcode = baseDao.getFieldDataByCondition("prodiodetail", "pd_whcode","pd_piclass='拨出单' and pd_batchcode='" + data2 + "'");
  780. int nocost = Integer.parseInt(StringUtil.nvl(baseDao.getFieldDataByCondition("Warehouse", "nvl(wh_nocost,0)", "wh_code='" + pdwhcode + "'"), "0"));
  781. int nocost1 = Integer.parseInt(StringUtil.nvl(baseDao.getFieldDataByCondition("Warehouse", "nvl(wh_nocost,0)", "wh_code='" + warehouses2[0] + "'"), "0"));
  782. if (nocost != nocost1) {
  783. if (nocost == -1) {
  784. return ApiResponse.failRsp("10058", requestId, "工单BOM领料仓是零值仓,不允许退有值仓!");
  785. }
  786. if (nocost == 0) {
  787. return ApiResponse.failRsp("10059", requestId, "工单BOM领料仓是有值仓,不允许退零值仓!");
  788. }
  789. }*/
  790. }
  791. }
  792. for (int i = 0; i <jsonArray.size() ; i++) {
  793. Object obj = jsonArray.get(i);
  794. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(obj, ""));
  795. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FDeptID"),"{}"));
  796. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FPurposeID"),"{}"));
  797. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FFManagerID"),"{}"));
  798. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FSManagerID"),"{}"));
  799. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FBillerID"),"{}"));
  800. frob = Integer.parseInt(StringUtil.nvl(jsonObject2.get("FROB"), "99"));
  801. taskType = StringUtil.nvl(jsonObject2.get("TaskType"), "");
  802. if ("OS".equals(ma_tasktype)) {
  803. tlpiclass = "委外退料单";
  804. tlcaller = "ProdInOut!OutsideReturn";
  805. }
  806. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  807. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, tlpiclass);
  808. if (result!=null){
  809. return result;
  810. }
  811. ApiResult<String> result1 = checkMESCode(requestId, fSelBillNo, bcpiclass);
  812. if (result1!=null){
  813. return result1;
  814. }
  815. if (frob==0||"制程不良".equals(taskType)){
  816. tlid = baseDao.getSeqId("PRODINOUT_SEQ");
  817. tlcode = baseDao.sGetMaxNumber(tlcaller, 2);
  818. sqls.add("INSERT INTO ProdInOut(pi_id, pi_inoutno, pi_date, pi_class,pi_invostatus,pi_invostatuscode,pi_recordman, pi_recorddate, pi_statuscode,pi_status,pi_updatedate,pi_updateman,pi_printstatuscode,pi_printstatus,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_mescode) VALUES ("+tlid+",'"+tlcode+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'"+tlpiclass+"','已审核','AUDITED','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPOST','未过账',sysdate,'"+map5.get("FName")+"','UNPRINT','未打印','"+map1.get("FNumber")+"','"+map1.get("FName")+"','"+map4.get("FNumber")+"','"+map4.get("FName")+"','"+fSelBillNo+"')");
  819. }
  820. id = baseDao.getSeqId("PRODINOUT_SEQ");
  821. code = baseDao.sGetMaxNumber(bccaller, 2);
  822. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_inoutman,pi_type,pi_mescode) values ("+id+",'"+code+"','"+bcpiclass+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPOST','未过账','"+map1.get("FNumber")+"','"+map1.get("FName")+"','"+map4.get("FNumber")+"','"+map4.get("FName")+"','AUDITED','已审核','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+map3.get("FName")+"','库存转移','"+fSelBillNo+"')");
  823. }
  824. int detno=1;
  825. int det=1;
  826. for (int i = 0; i <array.size(); i++) {
  827. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  828. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  829. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  830. if ("".equals(itemNo)){
  831. return ApiResponse.failRsp("10051",requestId,"物料不能为空!");
  832. }
  833. Double qty =Double.parseDouble(StringUtil.nvl(object.get("FAuxQty"), ""));
  834. if ("".equals(qty)){
  835. return ApiResponse.failRsp("10052",requestId,"实发数量不能为空!");
  836. }
  837. String fnote = StringUtil.nvl(object.get("Fnote"), "");
  838. Object lineId = object.get("lineId");
  839. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  840. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  841. warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  842. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  843. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  844. warehouses2 = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  845. String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
  846. String fBatchNo = StringUtil.nvl(object.get("FBatchNo"), "");
  847. int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  848. if (count1<=0){
  849. return ApiResponse.failRsp("10075",requestId,"工单BOM不存在或ID不一致,请联系管理员处理!");
  850. }
  851. Object[] objs = baseDao.getFieldsDataByCondition("Make left join MakeMaterial on ma_id=mm_maid", new String[] { "mm_id", "mm_code","mm_detno", "mm_mdcode", "mm_prodcode", "mm_wccode"}, "mm_id in (" + lineId+")");
  852. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_prodcode,pd_outqty,pd_whcode,pd_whname,pd_inwhcode,pd_inwhname,pd_macode,pd_madetno) values (PRODIODETAIL_SEQ.nextval,"+id+",'"+code+"','"+bcpiclass+"',"+detno+",'"+itemNo+"',"+qty+",'"+warehouses[0]+"','"+warehouses[1]+"','"+warehouses2[0]+"','"+warehouses2[1]+"','"+ficmoBillNo+"',"+objs[2]+")");
  853. if (frob==0||"制程不良".equals(taskType)) {
  854. Object prid = baseDao.getFieldDataByCondition("Product", "pr_id", "pr_code='" + itemNo + "'");
  855. Double remain = baseDao.getSummaryByField("batch", "ba_remain", "ba_prodcode='" + itemNo + "' and ba_macode='" + macode + "' and ba_whcode='" + warehouses[0] + "'");
  856. /*Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial left join Make on ma_id=mm_maid",
  857. "mm_totaluseqty,mm_havegetqty,ma_tomadeqty,mm_oneuseqty,ma_qty", "mm_id=" + objs[0]);*/
  858. if (qty.compareTo(remain) > 0){
  859. double sub = DoubleUtils.sub(qty, remain);
  860. sqls.add("INSERT INTO ProdIODetail(pd_id, pd_piid, pd_inoutno, pd_piclass, pd_pdno, pd_status,pd_auditstatuscode,pd_auditstatus,pd_prodcode,pd_ordercode, pd_orderdetno,pd_macode,pd_madetno,pd_plancode, pd_wccode, pd_orderid, pd_prodid,pd_whcode,pd_whname,pd_inqty,pd_description) VALUES (PRODIODETAIL_SEQ.nextval,"+tlid+",'"+tlcode+"','"+tlpiclass+"',"+det+ ",0,'ENTERING','在录入','"+itemNo+"','"+ficmoBillNo+"',"+objs[2]+",'"+ficmoBillNo+"',"+objs[2]+ ",'"+objs[3]+"','"+objs[5]+"',"+lineId+","+prid+",'"+warehouses[0]+"','"+warehouses[1]+"',"+sub+ ",'良品退仓')");
  861. det++;
  862. }
  863. }
  864. detno++;
  865. }
  866. if (frob==0){
  867. sqls.add("update prodiodetail set (pd_mcid,pd_jobcode)=(select mc_id,mm_mdcode from MakeMaterial,makecraft where pd_orderdetno=mm_detno and pd_ordercode=mm_code and mm_mdcode=mc_code) where pd_piid="
  868. + tlid);
  869. sqls.add("update prodiodetail set pd_purcinqty=Round(Pd_Inqty/nvl((Select case when nvl(Pr_Purcrate,0)=0 then 1 else Pr_Purcrate end From Product Where Pd_Prodcode=Pr_Code),1),8) where pd_piid="
  870. + tlid);
  871. }
  872. if ("OS".equals(ma_tasktype)) {
  873. sqls.add("update prodinout set(pi_cardcode,pi_title,pi_receivecode,pi_receivename) = (select max(ma_vendcode),max(ma_vendname),max(nvl(ma_apvendcode,ma_vendcode)),max(nvl(ma_apvendname,ma_vendname)) from make where ma_id in (" + maid + ")) where pi_id=" + tlid);
  874. }
  875. if (warehouses!=null){
  876. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+id);
  877. }
  878. if (warehouses2!=null){
  879. sqls.add("update prodinout set pi_purpose='"+warehouses2[0]+"',pi_purposename='"+warehouses2[1]+"' where pi_id="+id);
  880. }
  881. baseDao.execute(sqls);
  882. baseDao.execute("delete from prodiodetail where pd_inqty=0 and pd_piclass='"+tlpiclass+"' and pd_piid="+tlid);
  883. int count = baseDao.getCount("select count(1) from prodiodetail where pd_piid=" + tlid);
  884. if (count<=0){
  885. baseDao.deleteById("prodinout","pi_id",tlid);
  886. }
  887. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  888. if (count>0) {
  889. String s1 = postProdInOut(tlid, tlcaller, employee);
  890. logger.info("S1==" + s1);
  891. if (s1 != null) {
  892. return ApiResponse.successRsp("0", requestId, tlpiclass+":" + tlcode + ",过账失败,请在ERP重新过账!");
  893. }
  894. }
  895. String s = postProdInOut(id, bccaller, employee);
  896. logger.info("S=="+s);
  897. if (s!=null){
  898. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
  899. }
  900. return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",请在ERP查看!");
  901. }
  902. @Override
  903. public ApiResult<String> prodInOutAppropriationOut(HttpServletRequest request) {
  904. String requestId = request.getHeader("RequestId");
  905. Map<String, JSONArray> data = getData(request);
  906. JSONArray jsonArray = data.get("main");
  907. int id=0;
  908. String code="";
  909. String picaller="ProdInOut!AppropriationOut";
  910. String piclass="拨出单";
  911. List<String> sqls = new ArrayList<>();
  912. for (int i = 0; i <jsonArray.size() ; i++) {
  913. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  914. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  915. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FRefType")));
  916. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  917. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  918. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  919. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  920. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
  921. if (result!=null){
  922. return result;
  923. }
  924. id = baseDao.getSeqId("PRODINOUT_SEQ");
  925. code = baseDao.sGetMaxNumber(picaller, 2);
  926. sqls.add("insert into prodinout (pi_id,pi_inoutno,pi_class,pi_date,pi_statuscode,pi_status,pi_departmentcode,pi_departmentname,pi_emcode,pi_emname,pi_invostatuscode,pi_invostatus,pi_recordman,pi_recorddate,pi_printstatuscode,pi_printstatus,pi_type,pi_inoutman,pi_mescode) values ("+id+ ",'"+code+"','"+piclass+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPOST','未过账','"+map1.get("FNumber")+"','"+map1.get("FName")+"','"+map4.get("FNumber")+"','"+map4.get("FName")+"','ENTERING','在录入','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+map2.get("FName")+"','"+map3.get("FName")+"','"+fSelBillNo+"')");
  927. }
  928. JSONArray array = data.get("detail");
  929. Object[] warehouses=null;
  930. Object[] warehouses2=null;
  931. int detno=1;
  932. for (int i = 0; i <array.size(); i++) {
  933. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  934. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  935. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  936. if ("".equals(itemNo)){
  937. return ApiResponse.failRsp("10061",requestId,"物料不能为空!");
  938. }
  939. String qty = StringUtil.nvl(object.get("Fauxqty"), "");
  940. if ("".equals(qty)){
  941. return ApiResponse.failRsp("10062",requestId,"实转数量不能为空!");
  942. }
  943. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  944. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  945. String whname = StringUtil.nvl(map1.get("FName"), "");
  946. if ("".equals(whcode)){
  947. return ApiResponse.failRsp("10063",requestId,"发货仓库不能为空!");
  948. }
  949. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  950. if (count<=0){
  951. return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  952. }
  953. warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  954. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDCStockID1")));
  955. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  956. String whname2 = StringUtil.nvl(map2.get("FName"), "");
  957. if ("".equals(whcode2)){
  958. return ApiResponse.failRsp("10065",requestId,"收货仓库不能为空!");
  959. }
  960. int count2 = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  961. if (count2<=0){
  962. return ApiResponse.failRsp("10066",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  963. }
  964. warehouses2 = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode2 + "'");
  965. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_prodcode,pd_outqty,pd_whcode,pd_whname,pd_inwhcode,pd_inwhname) values (PRODIODETAIL_SEQ.nextval,"+id+",'"+code+"','拨出单',"+detno+",'"+itemNo+"',"+qty+",'"+warehouses[0]+"','"+warehouses[1]+"','"+warehouses2[0]+"','"+warehouses2[1]+"')");
  966. detno++;
  967. }
  968. if (warehouses!=null){
  969. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where " + "pi_id="+id);
  970. }
  971. if (warehouses2!=null){
  972. sqls.add("update prodinout set pi_purpose='"+warehouses2[0]+"',pi_purposename='"+warehouses2[1]+"' where pi_id="+id);
  973. }
  974. baseDao.execute(sqls);
  975. return ApiResponse.successRsp("0",requestId,"拨出单:"+code+",请在ERP查看!");
  976. }
  977. @Override
  978. public ApiResult<String> makeCheckOutStock(HttpServletRequest request) {
  979. String requestId = request.getHeader("RequestId");
  980. try {
  981. String data = PSHttpUtils.readRaw(request.getInputStream());
  982. JSONArray jsonArray = JSON.parseArray(data);
  983. for (int i = 0; i <jsonArray.size() ; i++) {
  984. JSONObject jsonObject = jsonArray.getJSONObject(i);
  985. String whcode = StringUtil.nvl(jsonObject.getString("outwhcode"), "");
  986. if ("".equals(whcode)){
  987. return ApiResponse.failRsp("10081",requestId,"拨出仓库不能为空!");
  988. }
  989. int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  990. if (count<=0){
  991. return ApiResponse.failRsp("10082",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  992. }
  993. Object outwhcode = baseDao.getFieldDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id", "cd_varchar50_3", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  994. jsonObject.put("outwhcode",outwhcode);
  995. String whcode1 = StringUtil.nvl(jsonObject.getString("inwhcode"), "");
  996. if ("".equals(whcode1)){
  997. return ApiResponse.failRsp("10083",requestId,"拨入仓库不能为空!");
  998. }
  999. int count1 = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode1 + "'");
  1000. if (count1<=0){
  1001. return ApiResponse.failRsp("10084",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1002. }
  1003. Object inwhcode = baseDao.getFieldDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id", "cd_varchar50_3", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode1 + "'");
  1004. jsonObject.put("inwhcode",inwhcode);
  1005. }
  1006. String msg = baseDao.callProcedure("USER_CHECKOUTSTOCK", new Object[] {null,JSON.toJSONString(jsonArray)});
  1007. if (msg != null && !msg.trim().equals("")){
  1008. return ApiResponse.failRsp("10085",requestId,msg);
  1009. }
  1010. return ApiResponse.successRsp("0",requestId,"校验通过!");
  1011. } catch (IOException e) {
  1012. logger.error("makeCheckOutStock==="+e.getMessage());
  1013. return ApiResponse.failRsp("10086",requestId,e.getMessage());
  1014. }
  1015. }
  1016. @Override
  1017. public ApiResult<String> makeECNCheck(HttpServletRequest request) {
  1018. String requestId = request.getHeader("RequestId");
  1019. JSONObject jsonData = getJsonData(request);
  1020. if (jsonData!=null){
  1021. String makeCode = StringUtil.nvl(jsonData.get("MakeCode"), "");
  1022. Object mcCode = baseDao.getFieldDataByCondition("makematerialchange", "wm_concat(mc_code)",
  1023. "mc_id in (select md_mcid from makematerialchangedet where md_makecode='"+makeCode+"' and nvl(md_didstatus,' ')<>'执行成功')");
  1024. if (mcCode!=null){
  1025. return ApiResponse.failRsp("10091",requestId,"ERP有未执行的制造单ECN:"+mcCode);
  1026. }
  1027. Object ecnCode = baseDao.getFieldDataByCondition("ecn", "wm_concat(ecn_code)",
  1028. "nvl(ecn_didstatus,' ')<>'已执行' and ecn_id in (select ed_ecnid from ecndetail left join make on ed_boid=ma_bomid where ma_code='"+makeCode+"')");
  1029. if (ecnCode!=null){
  1030. return ApiResponse.failRsp("10092",requestId,"ERP有未执行的ECN:"+ecnCode);
  1031. }
  1032. return ApiResponse.successRsp("0",requestId,"校验通过!");
  1033. }else {
  1034. return ApiResponse.failRsp("10093",requestId,"参数异常!");
  1035. }
  1036. }
  1037. @Override
  1038. public ApiResult<String> canMadeQty(HttpServletRequest request) {
  1039. String requestId = request.getHeader("RequestId");
  1040. JSONObject jsonData = getJsonData(request);
  1041. if (jsonData!=null){
  1042. String makeCode = StringUtil.nvl(jsonData.get("MakeCode"), "");
  1043. int count = baseDao.getCount("select count(1) from make where ma_code ='" + makeCode + "'");
  1044. if (count<=0){
  1045. return ApiResponse.failRsp("10094",requestId,"工单:"+makeCode+"在ERP不存在,请核对!");
  1046. }
  1047. Object[] data = baseDao.getFieldsDataByCondition("make", "ma_canmadeqty,ma_code,ma_qty,ma_madeqty,ma_tomadeqty",
  1048. "ma_code='" + makeCode + "'");
  1049. if (data!=null&&data.length>0) {
  1050. Map<String, Object> map = new HashMap<>();
  1051. map.put("code",data[1]);
  1052. //备料齐套数量
  1053. map.put("canmadeqty",data[0]);
  1054. //工单数量
  1055. map.put("qty",data[2]);
  1056. //完工数量
  1057. map.put("madeqty",data[3]);
  1058. //已转完工数
  1059. map.put("tomadeqty",data[4]);
  1060. return ApiResponse.successRsp("0", "获取成功!",requestId, JSON.toJSONString(map));
  1061. }else {
  1062. return ApiResponse.failRsp("10095",requestId,"未找到数据!");
  1063. }
  1064. }else {
  1065. return ApiResponse.failRsp("10096",requestId,"参数异常!");
  1066. }
  1067. }
  1068. @Override
  1069. public ApiResult<String> prodInOutMakeGive(HttpServletRequest request) {
  1070. String requestId = request.getHeader("RequestId");
  1071. Map<String, JSONArray> data = getData(request);
  1072. JSONArray jsonArray = data.get("main");
  1073. String piCaller="ProdInOut!Make!Give";
  1074. String piClass="生产补料单";
  1075. Object piid=null;
  1076. String inoutno="";
  1077. for (int i = 0; i <jsonArray.size() ; i++) {
  1078. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  1079. inoutno = StringUtil.nvl(jsonObject.get("FSelBillNo"), "");
  1080. if ("".equals(inoutno)){
  1081. return ApiResponse.failRsp("10019",requestId,"生产补料单号不能为空!");
  1082. }
  1083. int count = baseDao.getCount("select count(1) from prodinout where pi_inoutno='" + inoutno + "' and pi_invostatuscode='AUDITED' and pi_statuscode='UNPOST' and pi_class='生产补料单'");
  1084. if (count>0) {
  1085. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1086. piid = baseDao.getFieldDataByCondition("prodinout", "pi_id", "pi_inoutno='" + inoutno + "'");
  1087. String s = postProdInOut(Integer.parseInt(StringUtil.nvl(piid,"0")), piCaller, employee);
  1088. logger.info("s==" + s);
  1089. if (s != null) {
  1090. return ApiResponse.successRsp("108", requestId, piClass+":" + inoutno + ",过账失败,请在ERP重新过账!");
  1091. }
  1092. }else {
  1093. return ApiResponse.successRsp("107", requestId, piClass+":" + inoutno + ",不存在或未审核,或已过帐!");
  1094. }
  1095. }
  1096. return ApiResponse.successRsp("0",requestId,piClass+":"+inoutno+"自动过账,请在ERP查看!");
  1097. }
  1098. private Map<String, JSONArray> getData(HttpServletRequest request){
  1099. Map<String, JSONArray> map = new HashMap<>();
  1100. try {
  1101. String data = PSHttpUtils.readRaw(request.getInputStream());
  1102. JSONObject jsonObject = JSON.parseObject(data);
  1103. Object data1 = jsonObject.get("Data");
  1104. JSONObject jsonObject1 = JSON.parseObject(StringUtil.nvl(data1,""));
  1105. Object page1 = jsonObject1.get("Page1");
  1106. Object page2 = jsonObject1.get("Page2");
  1107. JSONArray jsonArray = JSON.parseArray(StringUtil.nvl(page1, ""));
  1108. map.put("main",jsonArray);
  1109. JSONArray jsonArray1 = JSON.parseArray(StringUtil.nvl(page2, ""));
  1110. map.put("detail",jsonArray1);
  1111. } catch (IOException e) {
  1112. logger.info("参数解析异常信息:"+e.getMessage());
  1113. e.printStackTrace();
  1114. }
  1115. return map;
  1116. }
  1117. private JSONObject getJsonData(HttpServletRequest request){
  1118. JSONObject jsonObject=null;
  1119. try {
  1120. String data = PSHttpUtils.readRaw(request.getInputStream());
  1121. jsonObject = JSON.parseObject(data);
  1122. } catch (IOException e) {
  1123. logger.info("参数解析异常信息:"+e.getMessage());
  1124. e.printStackTrace();
  1125. }
  1126. return jsonObject;
  1127. }
  1128. private ApiResult<String> checkMESCode(String requestId,String mesNo,String piclass){
  1129. if ("".equals(mesNo)){
  1130. return ApiResponse.failRsp("10100", requestId, "MES单号不能为空!");
  1131. }
  1132. int count = baseDao.getCount("select count(1) from prodinout where pi_class='" + piclass + "' and pi_mescode='" + mesNo + "'");
  1133. if (count>0){
  1134. Object code = baseDao.getFieldDataByCondition("prodinout", "pi_inoutno", "pi_class='" + piclass + "' and pi_mescode='" + mesNo + "'");
  1135. return ApiResponse.successRsp("0",requestId,"MES单号:"+mesNo+"已存在,请在ERP查看"+piclass+",单据编号:"+code);
  1136. }
  1137. return null;
  1138. }
  1139. private synchronized String postProdInOut(int pi_id, String caller,Employee employee) {
  1140. // 增加系统参数 出入库日期小于等于当前日期才允许过账 maz 2018020006
  1141. if (baseDao.isDBSetting("sys", "limitPostAfter")) {
  1142. Object pi_date = baseDao.getFieldDataByCondition("ProdInOut", "pi_date", "pi_id=" + pi_id);
  1143. String sysdate = DateUtil.getCurrentDate();
  1144. int sign = 0;
  1145. sign = DateUtil.compare(pi_date.toString(), sysdate);
  1146. if (sign == 1) {
  1147. return "单据日期大于当前日期,不能过账";
  1148. }
  1149. }
  1150. // 只能对状态为[未过账]的单据进行过账操作!
  1151. Object[] status = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_statuscode", "pi_invostatuscode", "pi_date", "pi_class", "pi_recordman", "pi_inoutno" }, "pi_id=" + pi_id);
  1152. if (status[0].equals("POSTED")) {
  1153. return "只能对未过账的" + status[3] + "[" + status[5] + "]进行过账操作!";
  1154. }
  1155. // 2018030244 maz 送货单号不一致不允许提交
  1156. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!DefectIn".equals(caller)) {
  1157. if (baseDao.isDBSetting("VerifyApplyDetail!Deal", "turnByDeliver")) {
  1158. SqlRowList rs = baseDao
  1159. .queryForRowSet("select pd_pdno from prodinout left join prodiodetail on pi_id=pd_piid left join VerifyApply on va_code=pd_vacode where pi_id="
  1160. + pi_id + " and nvl(pi_sendcode,' ')<>nvl(va_sendcode,' ')");
  1161. if (rs.next()) {
  1162. return "行号:" + rs.getInt("pd_pdno") + "送货单号不一致,不允许操作";
  1163. }
  1164. }
  1165. }
  1166. // 明细中如果有属于物料等级属于库存不可用的,就提示这些物料当前等级库存不可用
  1167. SqlRowList rowList = baseDao
  1168. .queryForRowSet(
  1169. "select wm_concat(pd_prodcode) prodcode from (select distinct pd_prodcode from prodiodetail "
  1170. + "left join product on pd_prodcode=pr_code left join productlevel on pr_level=pl_levcode where pd_piid=? and pl_id>0 "
  1171. + "and pl_isuseable=0 ) where rownum<=20", pi_id);
  1172. if (rowList.next()) {
  1173. if (rowList.getString("prodcode") != null) {
  1174. return "这些物料当前等级库存不可用,物料编号:" + rowList.getString("prodcode");
  1175. }
  1176. }
  1177. baseDao.execute("update prodinout set (pi_whcode,pi_whname)=(select pd_whcode,pd_whname from prodiodetail where pd_piid=pi_id and nvl(pd_whcode,' ')<>' ' and rownum<2) where pi_id="
  1178. + pi_id + " and nvl(pi_whcode,' ')= ' '");
  1179. // 判断已审核才允许过账
  1180. if (baseDao.isDBSetting(caller, "postNeedAudit")) {
  1181. if (!status[1].equals("AUDITED")) {
  1182. return status[3] + "[" + status[5] + "]未审核,不允许过账!";
  1183. }
  1184. }
  1185. String dets = baseDao
  1186. .getJdbcTemplate()
  1187. .queryForObject(
  1188. "select wm_concat(distinct pi_class||'['||pi_inoutno||']') from prodinout left join prodiodetail a on pi_id=pd_piid where exists (select 1 from prodiodetail B WHERE B.PD_IOID=A.PD_ID AND B.PD_PIID=?) AND Pi_STATUSCODE='UNPOST'",
  1189. String.class, pi_id);
  1190. if (dets != null) {
  1191. return "来源的" + dets + "未过账,本单据不允许过账!";
  1192. }
  1193. // 无来源订单不能直接过账
  1194. if (baseDao.isDBSetting(caller, "isWuPO")) {
  1195. int count = baseDao
  1196. .getCount("select count(*) from ProdIODetail where (pd_ordercode is null or pd_orderdetno is null) and pd_piid="
  1197. + pi_id);
  1198. if (!status[1].equals("AUDITED") && count != 0) {
  1199. return "无来源订单审核后才能过账";
  1200. }
  1201. }
  1202. boolean isProdIn=baseDao.isProdIn(caller);
  1203. if (isProdIn) {
  1204. // 检测入库单明细生产日期是否大于系统时间
  1205. if (baseDao.isDBSetting("sys","inOverNow")) {
  1206. dets = baseDao
  1207. .getJdbcTemplate()
  1208. .queryForObject(
  1209. "select wm_concat(PD_PDNO) from ProdIODetail left join ProdInOut on pd_piid=pi_id where pi_id=? and pd_prodmadedate is not null and to_char(pd_prodmadedate,'yyyy-mm') > to_char(sysdate,'yyyy-mm') ",
  1210. String.class, pi_id);
  1211. if (dets != null) {
  1212. return "行:" + dets + ",明细生产日期不能大于系统日期所在年月!";
  1213. }
  1214. }
  1215. SqlRowList rs = null;
  1216. // 入库类单据:如果pd_location为空,默认等于物料资料里的仓位pr_location
  1217. baseDao.execute(
  1218. "update prodiodetail set pd_location=(select pr_location from product where pr_code=pd_prodcode) where pd_piid=? and nvl(pd_location,' ')=' '",
  1219. pi_id);
  1220. rs = baseDao.queryForRowSet("SELECT pd_id FROM ProdioDetail where pd_piid=? and nvl(pd_batchcode,' ')=' '", pi_id);
  1221. while (rs.next()) {
  1222. baseDao.execute("update prodiodetail set pd_batchcode=? where pd_id=?", baseDao.getBatchcode(caller), rs.getInt("pd_id"));
  1223. }
  1224. // 入库单有生成条码但条码对应的物料或数量或批次号与明细行不一致则不允许过账
  1225. rs = baseDao.queryForRowSet(
  1226. "select wm_concat(pd_pdno)no,count(1)cn from prodiodetail left join (select sum(bi_inqty)inqty,bi_pdno,max(bi_prodcode)bi_prodcode,max(bi_batchcode)bi_batchcode from barcodeio"
  1227. + " where bi_piid=? group by bi_pdno) on bi_pdno=pd_pdno where pd_piid=? and pd_inqty>0 and inqty>0 "
  1228. + " and (nvl(inqty,0)<>pd_inqty or bi_prodcode<>pd_prodcode or bi_batchcode<>pd_batchcode) and rownum<30",
  1229. pi_id, pi_id);
  1230. if (rs.next() && rs.getInt("cn") > 0) {
  1231. return "条码与明细行中的物料或数量或批次号不一致,不允许过账,请先清除不一致条码!行号:" + rs.getString("no");
  1232. }
  1233. } else {
  1234. SqlRowList rs = null;
  1235. rs = baseDao
  1236. .queryForRowSet(
  1237. "SELECT pd_id,ba_purcrate FROM ProdioDetail,batch where pd_batchid=ba_id and pd_piid=? and nvl(pd_batchid,0)<>0 and nvl(pd_outqty,0)>0",
  1238. pi_id);
  1239. while (rs.next()) {
  1240. if (rs.getGeneralDouble("ba_purcrate") != 0) {
  1241. baseDao.execute("update prodiodetail set pd_purcoutqty=round(nvl(pd_outqty,0)/" + rs.getGeneralDouble("ba_purcrate")
  1242. + ",8) where pd_id=" + rs.getObject("pd_id"));
  1243. } else {
  1244. baseDao.execute("update prodiodetail set pd_purcoutqty=nvl(pd_outqty,0) where pd_id=" + rs.getObject("pd_id"));
  1245. }
  1246. }
  1247. }
  1248. useDefaultTax(caller, pi_id);
  1249. String s = allowZeroTax(caller, pi_id);
  1250. if (s!=null){
  1251. return s;
  1252. }
  1253. String s1 = checkFreezeMonth(caller, status[2]);
  1254. if (s1!=null){
  1255. return s1;
  1256. }
  1257. String s2 = checkCloseMonth(status[2]);
  1258. if (s2!=null){
  1259. return s2;
  1260. }
  1261. String s3 = checkFirstMonth(caller, status[2]);
  1262. if (s3!=null){
  1263. return s3;
  1264. }
  1265. String s4 = checkCommit(caller, pi_id);
  1266. if (s4!=null){
  1267. return s4;
  1268. }
  1269. String s5 = checkBatch(caller, pi_id);
  1270. if (s5!=null){
  1271. return s5;
  1272. }
  1273. String copcheck = copcheck(pi_id, caller);
  1274. if (copcheck!=null){
  1275. return copcheck;
  1276. }
  1277. String factorycheck = factorycheck(pi_id, caller);
  1278. if (factorycheck!=null){
  1279. return factorycheck;
  1280. }
  1281. // 制造工单加工类型
  1282. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  1283. String s6 = checkMakeKindType(caller, pi_id);
  1284. if (s6!=null){
  1285. return s6;
  1286. }
  1287. }
  1288. // 暂时不启用平台 销售仓模式checkWhIsB2C(caller, pi_id);
  1289. /**
  1290. * 委外验收单,委外验退单 过账限制,判断明细行中的应付供应商或币别与主表是否一致,不一致则不允许过账;
  1291. */
  1292. if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  1293. SqlRowList rs = baseDao
  1294. .queryForRowSet(
  1295. "select wm_concat(pd_pdno) c from (select nvl(nvl(ma_apvendcode,ve_apvendcode),ve_code) apvendcode, pi_receivecode,pd_pdno "
  1296. + "from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join vendor "
  1297. + "on ma_vendcode=ve_code where pi_id=?) t where t.apvendcode <> t.pi_receivecode and rownum<30", pi_id);
  1298. if (rs.next()) {
  1299. if (rs.getObject("c") != null) {
  1300. return "明细行中委外加工单的应付供应商与主表中的应付供应商不一致!";
  1301. }
  1302. }
  1303. SqlRowList rs2 = baseDao.queryForRowSet("select wm_concat(pd_pdno) x from (select ma_currency,pi_currency,pd_pdno"
  1304. + " from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode"
  1305. + " where pi_id=?) t where t.ma_currency <> t.pi_currency and rownum<30", pi_id);
  1306. if (rs2.next()) {
  1307. if (rs2.getObject("x") != null) {
  1308. return "明细行中委外加工单的币别与主表中的币别不一致!";
  1309. }
  1310. }
  1311. }
  1312. // 完工入库,委外验收限制,入库数量不允许大于到当前pi_date的月份为止的(制造单生产的总数数量-已入库总数)
  1313. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  1314. // 存在pi_date 年月之后的 出入库单
  1315. int ym = DateUtil.getYearmonth(status[2].toString());
  1316. SqlRowList rs = baseDao
  1317. .queryForRowSet(
  1318. "select A.pd_ordercode pd_ordercode,sum(A.pd_inqty)inqty from prodiodetail A left join make on ma_code=A.pd_ordercode left join makekind ON mk_name=ma_Kind"
  1319. + " where A.pd_piid=? AND NVL(mk_finishunget, 0) = 0 and exists (select 1 from prodiodetail B left join prodinout on pi_id=B.pd_piid "
  1320. + " where A.pd_ordercode=B.pd_ordercode and to_char(pi_date,'yyyyMM')>? and "
  1321. + " pi_class in('生产领料单','生产退料单','生产补料单','委外补料单','委外领料单','委外退料单') and B.pd_status=99) group by A.pd_ordercode",
  1322. pi_id, ym);
  1323. while (rs.next()) {
  1324. Object[] obs = baseDao
  1325. .getFieldsDataByCondition(
  1326. "make left join makematerial on mm_maid=ma_id",
  1327. new String[] {
  1328. " nvl(min(case when mm_oneuseqty*ma_qty>mm_qty+0.1 then ma_qty else ceil((nvl(mm_havegetqty, 0)-(select sum(nvl(pd_outqty,0)-nvl(pd_inqty,0)) from prodinout left join prodiodetail on pd_piid=pi_id "
  1329. + " where to_char(pi_date,'yyyyMM')>'"
  1330. + ym
  1331. + "' and pd_ordercode=ma_code and pd_orderdetno=mm_detno and pi_class in('生产领料单','生产退料单','生产补料单','委外补料单','委外领料单','委外退料单'))"
  1332. + " -nvl(mm_scrapqty,0))*1.0/mm_oneuseqty)end),0) as canmadeqty",
  1333. "nvl(max(ma_madeqty),0) -"
  1334. + "nvl(max((select SUM(NVL(pd_inqty,0)-NVL(pd_outqty,0)) from prodinout LEFT JOIN prodiodetail ON pd_piid=pi_id "
  1335. + " WHERE TO_CHAR(pi_date,'yyyyMM')>'" + ym + "' and pd_ordercode='"
  1336. + rs.getString("pd_ordercode")
  1337. + "' and pi_class in('完工入库单','委外验收单','委外验退单'))),0) as madeqty" },
  1338. " mm_code='" + rs.getString("pd_ordercode") + "' and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0");
  1339. if (obs != null) {// 比较
  1340. if (rs.getDouble("inqty") > (Double.valueOf(obs[0].toString()).doubleValue() - Double.valueOf(obs[1].toString())
  1341. .doubleValue())) {
  1342. return "工单[" + rs.getString("pd_ordercode") + "]当前月份领料套数(" + obs[0] + ")不足完工数";
  1343. }
  1344. }
  1345. }
  1346. }
  1347. /**
  1348. * 采购验收单、委外验收单 从表单位pr_unit与采购单位pr_purcunit不一致的时候,
  1349. * 数量pd_inqty与采购单位入库数量pd_purcinqty不能一致,否则无法提交、过账
  1350. */
  1351. if (baseDao.isDBSetting("sys","usePurcUnit") && ("ProdInOut!PurcCheckin".equals(caller) || ("ProdInOut" +
  1352. "!OutsideCheckIn").equals(caller))) {
  1353. String dets1 = baseDao.getJdbcTemplate().queryForObject(
  1354. "select wm_concat(pd_pdno) from ProdIODetail left join Product on pd_prodcode=pr_code where pd_piid=? "
  1355. + "and PR_UNIT is not null and pr_purcunit is not null "
  1356. + "and (nvl(pd_inqty,0)>0) and (nvl(pd_purcinqty,0)>0) "
  1357. + "and nvl(PR_UNIT,'')<>nvl(pr_purcunit,'') and nvl(pd_inqty,0)=nvl(pd_purcinqty,0)", String.class, pi_id);
  1358. if (dets1 != null) {
  1359. return "行" + dets1 + ",明细入库数量和采购单位入库数量需不一致,否则无法过账!";
  1360. }
  1361. }
  1362. /**
  1363. * 新增生产退料和委外退料判断,替代料退料数量不能大于替代料已领数量,禁用物料判断mm_updatetype='R',
  1364. *
  1365. * @date 2016年10月17日 下午12:30:58
  1366. */
  1367. if (("ProdInOut!Make!Return").equals(caller) || ("ProdInOut!OutsideReturn").equals(caller)) {
  1368. checkRepQty(pi_id);
  1369. /**
  1370. * 生产退料单,委外退料单 校验退料数量不能大于截止到单据日期月份 已过账的领料-退料-报废+补料-完工数*单位用量
  1371. */
  1372. checkMmBackOver(caller,pi_id);
  1373. }
  1374. /**
  1375. * 新增限制,拆件类型制造单不允许走完工入库单
  1376. *
  1377. * @author XiaoST 2016年12月9日 下午4:26:34
  1378. */
  1379. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  1380. dets = baseDao
  1381. .getJdbcTemplate()
  1382. .queryForObject(
  1383. "select wm_concat('行号:'||pd_pdno||'工单:'||pd_ordercode) from ProdIODetail left join make on ma_code=pd_ordercode left join makekind ON mk_name=ma_kind where pd_piid=? and mk_type='D' and rownum<20",
  1384. String.class, pi_id);
  1385. if (dets != null) {
  1386. return "拆件工单必须走拆件入库单!" + dets;
  1387. }
  1388. }
  1389. baseDao.getEndDate(caller, pi_id);
  1390. String res = null;
  1391. // 平台生成的销售订单转出货单过账必须等于销售订单明细序号和数量
  1392. if ("ProdInOut!Sale".equals(caller)) {
  1393. SqlRowList rs = baseDao
  1394. .queryForRowSet(
  1395. "select distinct sa_code,sum(pd_outqty) out_qty,pd_orderdetno from prodiodetail left join sale on sa_code=pd_ordercode where sa_ordertype='B2C' and nvl(sa_b2ccode,' ')<>' ' and pd_piid=? group by sa_code,pd_orderdetno",
  1396. pi_id);
  1397. while (rs.next()) {
  1398. rs = baseDao
  1399. .queryForRowSet(
  1400. "select distinct pd_ordercode pd_ordercode from prodiodetail where pd_piid=? and (pd_orderdetno not in (select sd_detno from saledetail where sd_code=?))"
  1401. + " OR "
  1402. + rs.getDouble("out_qty")
  1403. + " <>(select sd_qty from saledetail where sd_code=? and sd_detno=?) and pd_ordercode =?", pi_id,
  1404. rs.getString("sa_code"), rs.getString("sa_code"), rs.getString("pd_orderdetno"), rs.getString("sa_code"));
  1405. if (rs.next()) {
  1406. return "通过优软商城平台生成的发货单必须一次性发货,销售单号[" + rs.getString("pd_ordercode") + "]";
  1407. }
  1408. // 维护物流公司和物流单号
  1409. Object[] obs = baseDao.getFieldsDataByCondition("prodinout", new String[] { "pi_logisticscompany", "pi_logisticscode" },
  1410. "pi_id=" + pi_id);
  1411. if (obs[0] == null || obs[1] == null) {
  1412. return "请维护出货单的物流公司和物料单号信息!";
  1413. }
  1414. }
  1415. }
  1416. // 委外领、退、补单过账前
  1417. if ("ProdInOut!OutsidePicking".equals(caller) || "ProdInOut!OutsideReturn".equals(caller) || "ProdInOut!OSMake!Give".equals(caller)) {
  1418. // 更新:如果主表的应付供应商空,则取第一个工单的应付供应商ma_apvendcode,空则取工单供应商ma_vendcode
  1419. baseDao.execute("update prodinout set (pi_receivecode,pi_receivename)=(select code,ve_name from "
  1420. + "(select nvl(ma_apvendcode,ma_vendcode)code,ve_name from prodiodetail left join make on "
  1421. + "pd_ordercode=ma_code left join vendor on nvl(ma_apvendcode,ma_vendcode)=ve_code "
  1422. + "where pd_piid=? order by pd_pdno) where rownum=1 )" + "where nvl(pi_receivecode,' ')=' ' and pi_id=?", pi_id, pi_id);
  1423. // 判断主表应付供应商与从表工单应付供应商是否一致
  1424. SqlRowList pdnos = baseDao
  1425. .queryForRowSet(
  1426. "select wm_concat(pd_pdno) c from (select nvl(nvl(ma_apvendcode,ve_apvendcode),ve_code) apvendcode, pi_receivecode,pd_pdno "
  1427. + "from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join vendor "
  1428. + "on ma_vendcode=ve_code where pi_id=?) t where t.apvendcode <> t.pi_receivecode and rownum<30", pi_id);
  1429. if (pdnos.next()) {
  1430. if (pdnos.getObject("c") != null) {
  1431. return "行" + pdnos.getObject("c") + "工单应付供应商与主表应付供应商不一致,不能过账";
  1432. }
  1433. }
  1434. }
  1435. // @add20171103
  1436. if ("ProdInOut!PurcCheckin".equals(caller)) {// 采购验收单根据采购单号、序号,更新入库销售单号、序号
  1437. baseDao.execute(
  1438. "update prodiodetail set (pd_salecode,pd_saledetno,pd_topmothercode)=(select d.pd_salecode,d.pd_saledetno,d.pd_topmothercode from purchase left join purchasedetail d on pu_id=pd_puid where "
  1439. + " pd_ordercode=pu_code and pd_orderdetno=pd_detno) where pd_piid=?", pi_id);
  1440. }
  1441. // 生产退料单、委外退料单、拆件入库单、完工入库单、委外验收单,根据工单的订单号、订单序号能匹配到销售单号和序号(如果是预测单则不锁批记录)则更新到入库单明细的销售单号、序号
  1442. if ("ProdInOut!OutsideReturn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!Make!In".equals(caller)
  1443. || "ProdInOut!PartitionStockIn".equals(caller) || "ProdInOut!Make!Return".equals(caller)) {
  1444. baseDao.execute(
  1445. "update prodiodetail set (pd_salecode,pd_saledetno,pd_topmothercode)=(select ma_salecode,ma_saledetno,nvl(ma_topmothercode,ma_prodcode)topmothercode from make where pd_ordercode=ma_code)"
  1446. + " where pd_piid=? and exists (select 1 from make left join sale on sa_code=ma_salecode left join saledetail on sd_said=sa_id and sd_detno=ma_saledetno where pd_ordercode=ma_code and sd_detno>0)",
  1447. pi_id);
  1448. }
  1449. // 销售退货明细客户为空时=主表客户
  1450. if ("ProdInOut!SaleReturn".equals(caller)) {
  1451. baseDao.execute(
  1452. "update prodiodetail set (pd_custcode,pd_custname)=(select pi_cardcode,pi_title from prodinout where pd_piid=pi_id)"
  1453. + " where pd_piid=? and nvl(pd_custcode,' ')=' '", pi_id);
  1454. }
  1455. /*
  1456. * 退料数量不能大于维护的可退数量 String SQLStr_s = ""; SqlRowList rs_s; SQLStr_s=
  1457. * "select * from ProdIODetail left join make on ma_code=pd_ordercode"
  1458. * +" left join IO_MAKEMATERIAL_DETNO_VIEW on pd_orderdetno = mm_detno"
  1459. * +" where ma_id=mm_maid and pd_piid= '"+pi_id+"'"; rs_s =
  1460. * baseDao.queryForRowSet(SQLStr_s); if(rs_s.next()){ if
  1461. * (rs_s.getInt("pd_inqty")>rs_s.getInt("mm_havegetqty")) {
  1462. * BaseUtil.showError("工单序号[" + rs_s.getString("pd_orderdetno") +
  1463. * "]的退料数量不能大于维护的可退数量!'"); } }
  1464. */
  1465. // 过账前的其它逻辑
  1466. getTotal(pi_id, caller);// 调用过账存储过程前后都掉用一次gettotal方法,解决出入库单税率与发票不一致
  1467. getQtyTotal(pi_id, caller);
  1468. // 执行过账操作
  1469. Object[] objs = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_class", "pi_inoutno" }, "pi_id=" + pi_id);
  1470. if ("ProdInOut!CostChange".equals(caller)) {
  1471. res = baseDao.callProcedure("SP_PRODUCTCOSTADJUST", new Object[] { objs[0].toString(), objs[1].toString(), "" });
  1472. if (res != null && !res.trim().equals("")) {
  1473. return res;
  1474. }
  1475. } else {
  1476. baseDao.procedure("SP_GetCostPrice", new Object[] { objs[0].toString(), objs[1].toString() });
  1477. if (baseDao.isDBSetting("sys","SplitprodoutByseller")) {// 出单过账前取批号按照业务员pi_sellercode获取
  1478. res = baseDao.callProcedure("Sp_Splitprodout_Byseller",
  1479. new Object[] { objs[0].toString(), objs[1].toString(),employee.getEm_name()});
  1480. } else {
  1481. res = baseDao.callProcedure("Sp_SplitProdOut",
  1482. new Object[] { objs[0].toString(), objs[1].toString(),employee.getEm_name()});
  1483. }
  1484. if (res != null && !res.trim().equals("")) {
  1485. // 重新添加提示限制信息
  1486. return res + " " + objs[0].toString() + objs[1].toString() + ",过账失败";
  1487. // BaseUtil.showError(res);
  1488. }
  1489. // @add 20170614 抓取批次号成功之后更新出库单据的备料状态
  1490. updatePdaStatus(caller, pi_id);
  1491. if (baseDao.isDBSetting(caller, "ifBatchCodeNotChange") && baseDao.isDBSetting(caller, "autoPostIn")) {
  1492. // 拨出单过账后产生的拨入单批号不变,同一物料同仓库不能同时入两次相同的批号
  1493. SqlRowList rs1 = baseDao
  1494. .queryForRowSet("select count(1)n, wm_concat(pd_pdno)detno from (select pd_batchcode,pd_inwhcode,pd_prodcode,min(pd_pdno)pd_pdno,count(1)c from ProdIODetail where pd_piid="
  1495. + pi_id + " and pd_batchcode<>' ' group by pd_batchcode,pd_inwhcode,pd_prodcode ) where c> 1");
  1496. if (rs1.next()) {
  1497. if (rs1.getInt("n") > 0) {
  1498. return "拨出单过账后产生的拨入单批号不变,同一物料同拨入仓库批号不能相同!行号:" + rs1.getString("detno");
  1499. }
  1500. }
  1501. }
  1502. String s7 = checkBatchRemain(pi_id);
  1503. if (s7!=null){
  1504. return s7;
  1505. }
  1506. dets = baseDao
  1507. .getJdbcTemplate()
  1508. .queryForObject(
  1509. "select wmsys.wm_concat(a2.pd_pdno) from prodinout a1 left join prodiodetail a2 on a1.pi_id=a2.pd_piid " +
  1510. "left join prodiodetail b2 on a2.pd_batchcode=b2.pd_batchcode and a2.pd_prodcode=b2.pd_prodcode and a2.pd_whcode=b2.pd_whcode " +
  1511. "left join prodinout b1 on b2.pd_piid=b1.pi_id where a2.pd_piid=? and nvl(b2.pd_inqty,0)>0 and nvl(a2.pd_outqty,0)>0 " +
  1512. "and to_char(a1.pi_date,'yyyymm')<to_char(b1.pi_date,'yyyymm') and rownum<20",
  1513. String.class, pi_id);
  1514. if (dets != null) {
  1515. return "出库单据日期所在期间小于批次入库日期所在期间,不能过账!行号:" + dets;
  1516. }
  1517. // 存储过程
  1518. res = baseDao.callProcedure("Sp_CommitProdInout",
  1519. new Object[] { objs[0].toString(), objs[1].toString(), employee.getEm_name()});
  1520. if (res != null && !res.trim().equals("")) {
  1521. return res;
  1522. }
  1523. if (baseDao.isDBSetting("sys","autoCreateApBill")) {
  1524. if ("采购验收单".equals(status[3]) || "采购验退单".equals(status[3]) || "委外验收单".equals(status[3]) || "委外验退单".equals(status[3])
  1525. || "用品验收单".equals(status[3]) || "用品验退单".equals(status[3])) {
  1526. dets = baseDao.queryForObject("select wm_concat(ab_code) from apbill where ab_source=? and ab_statuscode<>'POSTED'",
  1527. String.class, status[5]);
  1528. if (dets != null) {
  1529. return "发票" + dets + "未过账成功,请手工过账!";
  1530. }
  1531. }
  1532. }
  1533. if (baseDao.isDBSetting("sys","autoCreateArBill")) {
  1534. if ("出货单".equals(status[3]) || "销售退货单".equals(status[3])) {
  1535. dets = baseDao.queryForObject(
  1536. "select wm_concat(ab_code) from arbill where AB_SOURCECODE=? and ab_statuscode<>'POSTED'", String.class,
  1537. status[5]);
  1538. if (dets != null) {
  1539. return "发票" + dets + "未过账成功,请手工过账!";
  1540. }
  1541. }
  1542. }
  1543. }
  1544. getTotal(pi_id, caller);
  1545. getQtyTotal(pi_id, caller);
  1546. baseDao.updateByCondition("ProdInOut", "pi_statuscode='POSTED',pi_status='已过账',pi_inoutman='"+employee.getEm_name()+"'," + "pi_date1=sysdate,pi_sendstatus='待上传'", "pi_id=" + pi_id);
  1547. if (!baseDao.isIn(caller)) {// 出库类单据过账时,根据批号抓取batch.ba_vendorrate到prodiodetail.pd_vendorrate
  1548. baseDao.execute("update prodiodetail set pd_vendorrate=(select ba_vendorrate from batch where ba_code=pd_batchcode"
  1549. + " and ba_whcode =pd_whcode and ba_prodcode=pd_prodcode ) where pd_piid=" + pi_id + " and nvl(pd_vendorrate,0)=0");
  1550. }
  1551. if (baseDao.isDBSetting("sys","updateBusinessChance") && !"ProdInOut!GoodsIn".equals(caller)) {// 更新当前商机阶段
  1552. Object bsname = baseDao.getFieldDataByCondition("BusinessChanceStage", "bs_name", "bs_relativeitem='Shipment'");
  1553. Object date = baseDao.getFieldDataByCondition("ProdInOut", "to_char(pi_recorddate,'yyyy-MM-dd')", "pi_id=" + pi_id);
  1554. List<Object[]> data = baseDao.getFieldsDatasByCondition("prodiodetail left join ProdInOut on pd_piid=pi_id", new String[] {
  1555. "pd_bcid", "pd_prodcode", "pd_pdno" }, "pd_piid=" + pi_id);
  1556. for (Object[] os : data) {
  1557. if (os[0] == null || os[0].equals("") || os[0].equals("0") || Integer.parseInt(os[0].toString()) == 0) {
  1558. String sql = "update Prodiodetail set pd_bcid=nvl((select sd_bcid from saledetail "
  1559. + "where pd_ordercode=sd_code and pd_orderdetno=sd_detno),0) where pd_piid=" + pi_id + " and nvl(pd_bcid,0)=0";
  1560. baseDao.execute(sql);
  1561. }
  1562. Object pd_bcid = baseDao.getFieldDataByCondition("Prodiodetail", "pd_bcid", " pd_prodcode='" + os[1] + "' and pd_piid="
  1563. + pi_id);
  1564. if (pd_bcid == null || pd_bcid.equals("") || pd_bcid.equals("0") || Integer.parseInt(pd_bcid.toString()) == 0) {
  1565. String sql = "update prodiodetail set pd_bcid=nvl((select max(bc_id) from prodinout,businesschance "
  1566. + "where pi_id=pd_piid and pi_cardcode=bc_custcode and pd_prodcode=bc_model and bc_status<>'已结案'),0) where nvl(pd_bcid,0)=0 and pd_piid="
  1567. + pi_id + " and nvl(pd_bcid,0)=0";
  1568. baseDao.execute(sql);
  1569. }
  1570. Object bc_id = baseDao.getFieldDataByCondition("Prodiodetail", "pd_bcid", " pd_prodcode='" + os[1] + "' and pd_piid="
  1571. + pi_id);
  1572. Integer bs_detno = baseDao.getFieldValue("businesschancestage", "bs_detno", "bs_name='" + bsname + "'", Integer.class);
  1573. Integer bs_detno1 = baseDao.getFieldValue("businesschance left join businesschancestage on bs_name=bc_currentprocess",
  1574. "nvl(bs_detno,0)", "bc_id=" + bc_id, Integer.class);
  1575. if (bs_detno != null && bs_detno1 != null) {
  1576. if (bs_detno >= bs_detno1) {
  1577. baseDao.updateByCondition("BusinessChance", "bc_currentprocess='" + bsname + "',bc_desc" + bs_detno + "='" + bsname
  1578. + "',bc_date" + bs_detno + "=to_date('" + date.toString() + "','yyyy-MM-dd')", "bc_id=" + bc_id);
  1579. if (bsname != null && Integer.parseInt(pd_bcid.toString()) != 0) {
  1580. Object bscode = baseDao.getFieldDataByCondition("BusinessChanceStage", "bs_code", "bs_name='" + bsname + "'");
  1581. // 插入一条记录到商机动态表
  1582. int bcd_id = baseDao.getSeqId("BusinessChanceData_seq");
  1583. String link = "jsps/scm/reserve/prodInOut.jsp?whoami=ProdInOut!Sale&formCondition=pi_idIS" + pi_id
  1584. + "&gridCondition=pd_piidIS" + pi_id;
  1585. String contactSql = "insert into BusinessChanceData (bcd_id,bcd_bcid,bcd_code,bcd_bscode,bcd_bsname,bcd_date,bcd_man,bcd_statuscode,bcd_status,bcd_sourcecode,bcd_sourcelink) values ("
  1586. + bcd_id
  1587. + ","
  1588. + bc_id
  1589. + ",'"
  1590. + baseDao.sGetMaxNumber("BusinessChanceData", 2)
  1591. + "','"
  1592. + bscode
  1593. + "','"
  1594. + bsname
  1595. + "',"
  1596. + "to_date('"
  1597. + date.toString()
  1598. + "','yyyy-MM-dd')"
  1599. + ",'"
  1600. + status[4]
  1601. + "','"
  1602. + "ENTERING" + "','在录入','" + status[5] + "','" + link + "')";
  1603. baseDao.execute(contactSql);
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. // 调用冲销
  1610. createSaleClash(pi_id, "ProdInOut",employee);
  1611. if ("ProdInOut!AppropriationOut".equals(caller) || "ProdInOut!SaleAppropriationOut".equals(caller)) {
  1612. dets = null;
  1613. if (baseDao.isDBSetting(caller, "autoPostIn")) {
  1614. // 过账销售拨入单
  1615. dets = turnProdIO(pi_id,employee);
  1616. // 过账失败提醒
  1617. boolean showTurnProdIOError = baseDao.checkIf("ProdInOut",
  1618. "pi_class='拨入单' and pi_statuscode='UNPOST' and pi_inoutno=(select pi_relativeplace from ProdInOut where pi_class='拨出单' and pi_id="
  1619. + pi_id + ")");
  1620. if (showTurnProdIOError) {
  1621. return "自动过账失败";
  1622. }
  1623. }
  1624. if (dets != null) {
  1625. return "拨入单明细行仓库对应的仓管员与当前过账人不一致,不允许进行当前操作!行号:" + dets;
  1626. }
  1627. if (baseDao.isDBSetting(caller, "autoPostMakeLSSend")) {// MakeSendLS
  1628. // 拉式发料
  1629. // 拨出单过账,拨入也过账时自动过账领料单
  1630. String SQLStr = "";
  1631. String Outpiclass = "";
  1632. SQLStr = "select pi_inoutno from prodinout where pi_id=" + pi_id + " and pi_statuscode='POSTED'";
  1633. SqlRowList rs0 = baseDao.queryForRowSet(SQLStr);
  1634. if (rs0.next()) {
  1635. SQLStr = "select pi_id,pi_class,pi_inoutno from prodinout where pi_fromcode='" + rs0.getString("pi_inoutno")
  1636. + "' and pi_statuscode='UNPOST' ";
  1637. SqlRowList rs = baseDao.queryForRowSet(SQLStr);
  1638. if (rs.next()) {
  1639. Outpiclass = rs.getObject("pi_class").toString();
  1640. if (Outpiclass.equals("生产领料单")) {
  1641. postProdInOut(rs.getInt("pi_id"), "ProdInOut!Picking",employee);
  1642. } else if (Outpiclass.equals("委外领料单")) {
  1643. postProdInOut(rs.getInt("pi_id"), "ProdInOut!OutsidePicking",employee);
  1644. }
  1645. SQLStr = "select pi_statuscode from prodinout where pi_id=" + rs.getInt("pi_id") + " and pi_statuscode='POSTED' ";
  1646. rs0 = baseDao.queryForRowSet(SQLStr);
  1647. if (rs0.next()) {
  1648. return null;
  1649. } else {
  1650. return Outpiclass + ":" + rs.getString("pi_inoutno") + "过账不成功!";
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. // 委外验收,验退,完工入库单,过账更新完工状态
  1657. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
  1658. || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  1659. SqlRowList rs = baseDao.queryForRowSet(
  1660. "select distinct ma_id from prodiodetail left join make on ma_code=pd_ordercode where pd_piid=?", pi_id);
  1661. while (rs.next()) {// 更新完工状态
  1662. updateMakeFinishStatus(rs.getInt("ma_id"));
  1663. }
  1664. }
  1665. /*if ("ProdInOut!AppropriationOut".equals(caller)) {
  1666. SqlRowList rs3 = baseDao
  1667. .queryForRowSet(
  1668. "select b.pi_id pi_id,a.pi_relativeplace pi_relativeplace from prodinout a left join prodinout b on a.pi_relativeplace=b.pi_inoutno where a.pi_id=? and b.pi_class='拨入单'",
  1669. pi_id);
  1670. if (rs3.next()) {
  1671. return "拨出单过账成功!系统产生的拨入单号 "+ rs3.getString("pi_relativeplace");
  1672. }
  1673. }*/
  1674. if ("ProdInOut!PurcCheckin".equals(caller)) {// 采购验收单过账根据采购单+采购单序号更新pd_vendorrate
  1675. // ba_vendorrate
  1676. SqlRowList pdRowList = baseDao
  1677. .queryForRowSet("select pd_id,nvl(pd_batchid,0) pd_batchid,nvl(pd_ordercode,' ') pd_ordercode,nvl(pd_orderdetno,0) pd_orderdetno from prodiodetail where pd_piid="
  1678. + pi_id);
  1679. while (pdRowList.next()) {
  1680. baseDao.execute("update prodiodetail set pd_vendorrate=(select pd_vendorrate from purchasedetail where pd_code='"
  1681. + pdRowList.getObject("pd_ordercode") + "' and pd_detno='" + pdRowList.getObject("pd_orderdetno")
  1682. + "') where pd_id=" + pdRowList.getObject("pd_id"));
  1683. baseDao.execute("update batch set ba_vendorrate=(select pd_vendorrate from purchasedetail where pd_code='"
  1684. + pdRowList.getObject("pd_ordercode") + "' and pd_detno='" + pdRowList.getObject("pd_orderdetno")
  1685. + "') where ba_id=" + pdRowList.getObject("pd_batchid"));
  1686. }
  1687. }
  1688. if ("ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller) || "ProdInOut!Picking".equals(caller)
  1689. || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
  1690. || "ProdInOut!OutsidePicking".equals(caller)) {
  1691. changeMaStatus(pi_id);
  1692. }
  1693. // 2017-08-30 重新根据pdno更新批号仓库属性
  1694. if (isProdIn) {
  1695. baseDao.execute(
  1696. "update barcodeio set (bi_batchcode,bi_batchid,bi_whcode)=(select pd_batchcode,pd_batchid,pd_whcode from prodiodetail where bi_piid=pd_piid and pd_pdno=bi_pdno) where bi_piid=? and nvl(bi_status,0)=0",
  1697. pi_id);
  1698. baseDao.execute(
  1699. "update batch set ba_hasbarcode=-1 where ba_id in (select pd_batchid from prodiodetail "
  1700. + " where pd_piid=?) and NVL(ba_hasbarcode,0)=0 and ba_id in (select bi_batchid from barcodeio where bi_inqty>0 and bi_status=0) ",
  1701. pi_id);
  1702. }
  1703. /**
  1704. * @author wsy
  1705. * 其它入库单:如果选择了采购单号、采购序号后,提交、审核的时候要判断采购单号+采购序号+物料编号是否一致,不一致限制提交
  1706. * 、审核
  1707. */
  1708. if ("ProdInOut!OtherIn".equals(caller)) {
  1709. baseDao.execute("update purchasedetail set pd_beipinacceptqty=(nvl((select sum(nvl(pd_purcinqty,0)) from prodiodetail where pd_piclass='其它入库单' and pd_ordercode=pd_code and pd_orderdetno=pd_detno and pd_status=99),0))where (pd_code,pd_detno) in (select pd_ordercode,pd_orderdetno from prodiodetail where pd_piid="
  1710. + pi_id + " and pd_piclass='其它入库单')");
  1711. }
  1712. prodinout_post_updatesourceqty(pi_id);
  1713. return null;
  1714. }
  1715. /**
  1716. * 过账后扣除待检数量、收料数量 scm->prodinout->post->after
  1717. *
  1718. * @author madan
  1719. */
  1720. public void prodinout_post_updatesourceqty(Integer id) {
  1721. Object[] piclass = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_class", "pi_type" }, "pi_id=" + id);
  1722. if (!(piclass[0].toString().equals("采购验收单") || piclass[0].toString().equals("委外验收单") || piclass[0].toString().equals("不良品入库单"))) {
  1723. return;
  1724. }
  1725. List<Object[]> objs = baseDao.getFieldsDatasByCondition("prodioDetail", new String[] { "pd_orderdetno", "pd_ordercode",
  1726. "sum(pd_inqty)", "pd_prodcode" }, "pd_piid=" + id + " and pd_qcid>0 group by pd_ordercode, pd_orderdetno, pd_prodcode");
  1727. for (Object[] obj : objs) {
  1728. if ("采购验收单".equals(piclass[0].toString())) {
  1729. baseDao.updateByCondition("PurchaseDetail", "pd_reconhand = nvl(pd_reconhand,0)-" + obj[2]
  1730. + ",pd_totested=NVL(pd_totested,0)-" + obj[2], "pd_code='" + obj[1] + "' and pd_detno = " + obj[0]);
  1731. } else if ("委外验收单".equals(piclass[0].toString()) || "完工入库单".equals(piclass[0].toString())) {
  1732. baseDao.updateByCondition("Make", "ma_reconhand = nvl(ma_reconhand,0)-" + obj[2] + ",ma_totested=NVL(ma_totested,0)-"
  1733. + obj[2], "ma_code='" + obj[1] + "'");
  1734. } else if ("不良品入库单".equals(piclass[0].toString())) {
  1735. if ("PURC".equals(piclass[1].toString()) || "采购不良品入库".equals(piclass[1].toString())) {
  1736. baseDao.updateByCondition("PurchaseDetail", "pd_reconhand = nvl(pd_reconhand,0)-" + obj[2]
  1737. + ",pd_totested=NVL(pd_totested,0)-" + obj[2], "pd_code='" + obj[1] + "' and pd_detno = " + obj[0]);
  1738. } else {
  1739. baseDao.updateByCondition("Make", "ma_reconhand = nvl(ma_reconhand,0)-" + obj[2] + ",ma_totested=NVL(ma_totested,0)-"
  1740. + obj[2], "ma_code='" + obj[1] + "'");
  1741. }
  1742. }
  1743. baseDao.updateByCondition("Product", "pr_reconhand = nvl(pr_reconhand,0)-" + obj[2] + ",pr_totested=NVL(pr_totested,0)-"
  1744. + obj[2], "pr_code='" + obj[3] + "'");
  1745. }
  1746. }
  1747. // 税率强制等于币别表的默认税率
  1748. private void useDefaultTax(String caller, Object pi_id) {
  1749. if (baseDao.isDBSetting(caller, "useDefaultTax")) {
  1750. baseDao.execute("update ProdIODetail set pd_taxrate=(select cr_taxrate from currencys left join ProdInOut on pi_currency=cr_name and cr_statuscode='CANUSE' where pd_piid=pi_id)"
  1751. + " where pd_piid=" + pi_id);
  1752. }
  1753. String defaultTax = baseDao.getDBSetting(caller, "defaultTax");
  1754. if (defaultTax != null) {
  1755. // 税率强制等于币别表的默认税率
  1756. if ("1".equals(defaultTax)) {
  1757. baseDao.execute("update ProdIODetail set pd_taxrate=(select cr_taxrate from currencys left join ProdInOut on pi_currency=cr_name and cr_statuscode='CANUSE' where pd_piid=pi_id)"
  1758. + " where pd_piid=" + pi_id);
  1759. }
  1760. // 税率强制等于供应商资料的默认税率
  1761. if ("2".equals(defaultTax)) {
  1762. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)
  1763. || "ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  1764. baseDao.execute("update ProdIODetail set pd_taxrate=(select nvl(ve_taxrate,0) from Vendor left join ProdInOut on pi_cardcode=ve_code and ve_auditstatuscode='AUDITED' where pi_id=pd_piid)"
  1765. + " where pd_piid=" + pi_id);
  1766. }
  1767. if ("ProdInOut!SaleReturn".equals(caller) || "ProdInOut!Sale".equals(caller)) {
  1768. baseDao.execute("update ProdIODetail set pd_taxrate=(select nvl(cu_taxrate,0) from Customer left join ProdInOut on pi_cardcode=cu_code and cu_auditstatuscode='AUDITED' where pi_id=pd_piid)"
  1769. + " where pd_piid=" + pi_id);
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // 本位币允许税率为0
  1775. private String allowZeroTax(String caller, Object pi_id) {
  1776. String currency = baseDao.getDBSetting("sys","defaultCurrency");
  1777. boolean allowZeroTax = baseDao.isDBSetting(caller, "allowZeroTax");
  1778. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller)) {
  1779. allowZeroTax = baseDao.isDBSetting("Sale", "allowZeroTax");
  1780. }
  1781. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)) {
  1782. allowZeroTax = baseDao.isDBSetting("Purchase", "allowZeroTax");
  1783. }
  1784. if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  1785. allowZeroTax = baseDao.isDBSetting("Make", "allowZeroTax");
  1786. }
  1787. if (!allowZeroTax) {
  1788. String dets = baseDao.getJdbcTemplate().queryForObject(
  1789. "select WM_CONCAT(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id where nvl(pd_taxrate,0)=0 and pi_currency='"
  1790. + currency + "' and pi_id=?", String.class, pi_id);
  1791. if (dets != null) {
  1792. return "本位币税率为0,不允许进行当前操作!行号:" + dets;
  1793. }
  1794. }
  1795. return null;
  1796. }
  1797. String checkCloseMonth(Object pidate) {
  1798. boolean bool = baseDao.checkIf("PeriodsDetail", "pd_code='MONTH-P' and pd_status=99 and pd_detno=to_char(to_date('" + pidate
  1799. + "','yyyy-mm-dd hh24:mi:ss'), 'yyyymm')");
  1800. if (bool) {
  1801. return "单据日期所属期间已结账,不允许进行当前操作!";
  1802. }
  1803. return null;
  1804. }
  1805. String checkMakeKindType(String caller, Object pi_id) {
  1806. if (baseDao.isDBSetting(caller, "makeKindType")) {
  1807. String sql = "select count(1)cn from (select count(1) cn, mk_type from make left join makekind on mk_name =ma_kind"
  1808. + " left join prodiodetail on pd_ordercode = ma_code where pd_piid=? group by mk_type) ";
  1809. SqlRowList sqlRowList = baseDao.queryForRowSet(sql, pi_id);
  1810. if (sqlRowList.next()) {
  1811. if (sqlRowList.getInt("cn") > 1) {
  1812. return "明细行制造单加工类型不同,不能使用同一张完工入库单";
  1813. }
  1814. }
  1815. }
  1816. return null;
  1817. }
  1818. String checkFreezeMonth(String caller, Object pidate) {
  1819. if (!"ProdInOut!CostChange".equals(caller)) {
  1820. String freeze = baseDao.getDBSetting("sys","freezeMonth");
  1821. if (freeze != null && !freeze.equals("")) {
  1822. if (Integer.parseInt(freeze) == DateUtil.getYearmonth(pidate.toString())) {
  1823. return "单据日期所属期间已冻结,不允许进行当前操作!";
  1824. }
  1825. }
  1826. }
  1827. return null;
  1828. }
  1829. String checkFirstMonth(String caller, Object pidate) {
  1830. if ("ProdInOut!ReserveInitialize".equals(caller)) {
  1831. Object first = baseDao.getFieldDataByCondition("periods", "nvl(PE_FIRSTDAY,0)", "PE_CODE='MONTH-P'");
  1832. if ("0".equals(first.toString())) {
  1833. return "请前往【初始化期间设置】确认开账期间!";
  1834. } else {
  1835. if (Integer.parseInt(first.toString()) != DateUtil.getYearmonth(pidate.toString())) {
  1836. return "库存初始化单据只能发生在库存模块的开账期间!当前库存模块开账期间为[" + first + "],请前往【初始化期间设置】确认开账期间!";
  1837. }
  1838. }
  1839. }
  1840. return null;
  1841. }
  1842. /*
  1843. * 提交,审核,过账之前的限制
  1844. */
  1845. private String checkCommit(String caller, Object pi_id) {
  1846. checkIOMaPick(caller,pi_id);
  1847. if (!caller.equals("ProdInOut!AppropriationOut") && !caller.equals("ProdInOut!AppropriationIn")) {
  1848. baseDao.execute("update prodiodetail set pd_whcode=(select pi_whcode from prodinout where pd_piid=pi_id) where pd_piid="
  1849. + pi_id + " and NVL(pd_whcode,' ')=' '");
  1850. }
  1851. if (caller.equals("ProdInOut!Make!Return") || caller.equals("ProdInOut!OutsideReturn")) {
  1852. baseDao.execute("update prodiodetail a set pd_prodmadedate=(select min(ba_date) from prodiodetail b left join batch on b.pd_batchid=ba_id where a.pd_ordercode=b.pd_ordercode and a.pd_prodcode=b.pd_prodcode and nvl(b.pd_batchcode,' ')<>' ' and ((b.pd_piclass ='生产领料单' and a.pd_piclass='生产退料单') or (b.pd_piclass ='委外领料单' and a.pd_piclass='委外退料单'))) where pd_piid="
  1853. + pi_id + " and pd_prodmadedate is null");
  1854. }
  1855. baseDao.execute("update prodiodetail set pd_prodmadedate=(select pi_date from prodinout where pd_piid=pi_id) where pd_piid="
  1856. + pi_id + " and pd_prodmadedate is null");
  1857. if ("ProdInOut!CostChange".equals(caller)) {
  1858. baseDao.execute(
  1859. "update prodiodetail set (pd_orderqty,pd_orderprice)=(select ba_remain,ba_price from batch where ba_code=pd_batchcode and pd_prodcode=ba_prodcode and ba_whcode=pd_whcode) where pd_piid=?",
  1860. pi_id);
  1861. baseDao.execute(
  1862. "update prodiodetail set pd_total=round(nvl(pd_orderqty,0)*(nvl(pd_price,0)-nvl(pd_orderprice,0)),2) where pd_piid=?",
  1863. pi_id);
  1864. }
  1865. baseDao.execute("update prodiodetail set pd_qctype=(select ve_class from qua_verifyapplydetail left join qua_verifyapplydetaildet on ved_veid=ve_id where pd_qcid=ved_id) where pd_piid="
  1866. + pi_id + " and nvl(pd_qcid,0)<>0");
  1867. String dets = baseDao
  1868. .getJdbcTemplate()
  1869. .queryForObject(
  1870. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join product on pr_code=pd_prodcode where pd_piid=? and NVL(pr_statuscode,' ')<>'AUDITED'",
  1871. String.class, pi_id);
  1872. if (dets != null) {
  1873. return "明细行物料不存在或者状态不等于已审核,不允许进行当前操作!" + dets;
  1874. }
  1875. dets = baseDao
  1876. .getJdbcTemplate()
  1877. .queryForObject(
  1878. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail where pd_piid=? and nvl(pd_whcode,' ')=' '",
  1879. String.class, pi_id);
  1880. if (dets != null) {
  1881. return "明细行仓库为空,不允许进行当前操作!" + dets;
  1882. }
  1883. /**
  1884. * 限制当仓库编号不为空时,明细行仓库至少有一行与主记录一致;为空则不判断
  1885. */
  1886. /*
  1887. * 暂不启用该逻辑限制 int c = baseDao.getCountByCondition(
  1888. * "ProdInOut left join ProdIODetail on pi_id=pd_piid", "pi_id=" + pi_id
  1889. * +
  1890. * " and ((NVL(pd_whcode,' ')=nvl(pi_whcode,' ') AND pi_whcode IS NOT NULL) or pi_whcode is null )"
  1891. * ); if (c < 1) { BaseUtil.showError("无一明细仓库与主表仓库一致,不允许进行当前操作!"); }
  1892. */
  1893. if (!caller.equals("ProdInOut!StockProfit") && !caller.equals("ProdInOut!StockLoss")) {
  1894. dets = baseDao
  1895. .getJdbcTemplate()
  1896. .queryForObject(
  1897. "select wm_concat(pd_pdno) from ProdIODetail inner join Prodinout on pd_piid=pi_id left join product on pr_code=pd_prodcode where "
  1898. + "pd_piid=? and round(pd_outqty+pd_inqty,0)<>pd_outqty+pd_inqty and pd_status=0 and NVL(pr_precision,0)=0 and NVL(pr_groupcode,' ')<>'用品' ",
  1899. String.class, pi_id);
  1900. if (dets != null) {
  1901. return "计算精度是0的物料不能以小数出入库!行号:" + dets;
  1902. }
  1903. }
  1904. if (baseDao.isDBSetting("sys","warehouseCheck") || baseDao.isDBSetting(caller, "warehouseCheck")) {
  1905. // 出入库单主记录与明细行仓库必须一致
  1906. dets = baseDao
  1907. .getJdbcTemplate()
  1908. .queryForObject(
  1909. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join ProdInOut on pd_piid=pi_id where pi_id=? and (nvl(pi_whcode,' ')<>nvl(pd_whcode,' ') or nvl(pi_purpose,' ')<>nvl(pd_inwhcode,' '))",
  1910. String.class, pi_id);
  1911. if (dets != null) {
  1912. return "明细行仓库与当前单主表仓库不一致,不允许进行当前操作!" + dets;
  1913. }
  1914. }
  1915. dets = baseDao
  1916. .getJdbcTemplate()
  1917. .queryForObject(
  1918. "select wmsys.wm_concat(pd_piclass||':'||pd_inoutno||',行:'||pd_pdno||',仓库:'||pd_whcode) from prodiodetail left join warehouse on wh_code=pd_whcode where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(wh_statuscode,' ')='DISABLE'",
  1919. String.class, pi_id);
  1920. if (dets != null) {
  1921. return "仓库已禁用,不允许进行当前操作!" + dets;
  1922. }
  1923. dets = baseDao
  1924. .getJdbcTemplate()
  1925. .queryForObject(
  1926. "select wmsys.wm_concat(pd_piclass||':'||pd_inoutno||',行:'||pd_pdno||',仓库:'||pd_whcode) from prodiodetail left join warehouse on wh_code=pd_whcode where pd_piid=? and nvl(pd_whcode,' ')<>' ' and pd_whcode not in (select wh_code from warehouse)",
  1927. String.class, pi_id);
  1928. if (dets != null) {
  1929. return "仓库不存在,不允许进行当前操作!" + dets;
  1930. }
  1931. String maxprice = baseDao.getDBSetting(caller, "maxPrice");
  1932. if (maxprice != null) {
  1933. dets = baseDao
  1934. .getJdbcTemplate()
  1935. .queryForObject(
  1936. "select wmsys.wm_concat(pd_piclass||':'||pd_inoutno||',行:'||pd_pdno||',单价:'||pd_price) from prodiodetail where pd_piid=? and nvl(pd_price,0)>?",
  1937. String.class, pi_id, maxprice);
  1938. if (dets != null) {
  1939. return "单价超过设置上限,不允许进行当前操作!" + dets;
  1940. }
  1941. }
  1942. if ("ProdInOut!Picking".equals(caller) || "ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller)
  1943. || "ProdInOut!OutsidePicking".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
  1944. || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!Make!In".equals(caller)
  1945. || "ProdInOut!PartitionStockIn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
  1946. || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  1947. dets = baseDao
  1948. .getJdbcTemplate()
  1949. .queryForObject(
  1950. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and pd_piclass in ('生产领料单','生产补料单','生产退料单','委外领料单','委外退料单','委外补料单') and not exists (select 1 from make left join makematerial on ma_id=mm_maid where pd_ordercode=ma_code and pd_orderdetno=mm_detno)",
  1951. String.class, pi_id);
  1952. if (dets != null) {
  1953. return "工单+序号不存在,不允许进行当前操作!行号:" + dets;
  1954. }
  1955. dets = baseDao
  1956. .getJdbcTemplate()
  1957. .queryForObject(
  1958. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and pd_piclass in ('生产领料单','生产补料单','生产退料单','委外领料单','委外退料单','委外补料单') and not exists (select 1 from make left join makematerial on ma_id=mm_maid where pd_ordercode=ma_code and pd_orderdetno=mm_detno and pd_prodcode=mm_prodcode) and "
  1959. + " not exists(select 1 from make inner join makematerial on ma_id= mm_maid inner join makematerialreplace on mm_id = mp_mmid where pd_ordercode=ma_code and pd_orderdetno=mm_detno and pd_prodcode=mp_prodcode)",
  1960. String.class, pi_id);
  1961. if (dets != null) {
  1962. return "工单+序号+物料编号不存在,不允许进行当前操作!行号:" + dets;
  1963. }
  1964. dets = baseDao
  1965. .getJdbcTemplate()
  1966. .queryForObject(
  1967. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode where "
  1968. + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(ma_vendcode,' ') and pd_piclass in ('委外退料单','委外验退单','委外领料单') "
  1969. + "and nvl(pd_ordercode,' ')<>' ' and not exists (select 1 from makecraft where mc_code=pd_jobcode and mc_tasktype='工序委外单')",
  1970. String.class, pi_id);
  1971. if (dets != null) {
  1972. return "明细委外单委外商与单据委外商不一致,不允许进行当前操作!行号:" + dets;
  1973. }
  1974. dets = baseDao
  1975. .getJdbcTemplate()
  1976. .queryForObject(
  1977. "select wm_concat(pd_pdno) from ProdIODetail where nvl(pd_jobcode,' ')<>' ' and not exists (select 1 from makecraft where pd_jobcode=mc_code "
  1978. + "and mc_tasktype='工序委外单') and pd_piclass in ('委外退料单','委外验退单','委外领料单') and pd_piid=?", String.class,
  1979. pi_id);
  1980. if (dets != null) {
  1981. return "明细工序委外单不存在,不允许进行当前操作!行号:" + dets;
  1982. }
  1983. dets = baseDao
  1984. .getJdbcTemplate()
  1985. .queryForObject(
  1986. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join makecraft on mc_code=pd_jobcode where "
  1987. + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(mc_vendcode,' ') and pd_piclass in ('委外退料单','委外验退单','委外领料单') "
  1988. + "and nvl(pd_ordercode,' ')<>' ' and exists (select 1 from makecraft where mc_code=pd_jobcode and mc_tasktype='工序委外单') ",
  1989. String.class, pi_id);
  1990. if (dets != null) {
  1991. return "委外商与工序委外单委外商不一致,不允许进行当前操作!行号:" + dets;
  1992. }
  1993. dets = baseDao
  1994. .getJdbcTemplate()
  1995. .queryForObject(
  1996. "select wm_concat('工单:'||pd_ordercode||'序号:'||pd_orderdetno) from (select pd_ordercode,pd_orderdetno,sum(pd_inqty) pd_inqty,max(mm_yqty)mm_yqty,max(mm_gqty)mm_gqty from ProdIODetail left join make on ma_code=pd_ordercode left join makematerial on ma_id=mm_maid and mm_detno=pd_orderdetno where pd_piid=? and pd_piclass='拆件入库单' group by pd_ordercode,pd_orderdetno)A where mm_yqty+pd_inqty>mm_gqty and mm_gqty>0 ",
  1997. String.class, pi_id);
  1998. if (dets != null) {
  1999. return "拆件入库数不能大于工单允许可拆件入库数!" + dets;
  2000. }
  2001. dets = baseDao
  2002. .getJdbcTemplate()
  2003. .queryForObject(
  2004. "select wm_concat('行号:'||pd_pdno||'工单:'||pd_ordercode) from ProdIODetail left join make on ma_code=pd_ordercode left join makekind ON mk_name=ma_kind where pd_piid=? and pd_piclass='拆件入库单' and mk_type='S'",
  2005. String.class, pi_id);
  2006. if (dets != null) {
  2007. return "拆件单明细中存在制造单的类型是标准!" + dets;
  2008. }
  2009. boolean allowBackAfterFinish = false;
  2010. if ("ProdInOut!Make!Return".equals(caller)) { // @add xst 20180830
  2011. // 反馈:2018080651
  2012. // ,制造单已结案允许退料
  2013. allowBackAfterFinish = baseDao.isDBSetting("Make!Base", "allowBackAfterFinish");
  2014. }
  2015. dets = baseDao
  2016. .getJdbcTemplate()
  2017. .queryForObject(
  2018. "select wm_concat(pd_pdno) from prodinout left join ProdIODetail on pd_piid=pi_id left join make on ma_code=pd_ordercode where pd_piid=? and (NVL(ma_statuscode,' ')<>'AUDITED' AND ('"
  2019. + allowBackAfterFinish
  2020. + "'='false' or (pd_piclass='生产退料单' and ma_statuscode<>'FINISH'))) and pi_statuscode='UNPOST' and pd_piclass in ('完工入库单','拆件入库单','委外验收单','生产领料单','生产补料单','生产退料单','委外领料单','委外退料单','委外补料单') and nvl(pd_ordercode,' ')<>' ' ",
  2021. String.class, pi_id);
  2022. if (dets != null) {
  2023. return "工单不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
  2024. }
  2025. dets = baseDao
  2026. .getJdbcTemplate()
  2027. .queryForObject(
  2028. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join MakeKind on mk_name=ma_kind "
  2029. + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(mk_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(mk_whcodes,'#'))) "
  2030. + "and pd_piclass in ('完工入库单','委外验收单') and nvl(pd_ordercode,' ')<>' ' and nvl(ProdIODetail.pd_status,0)=0",
  2031. String.class, pi_id);
  2032. if (dets != null) {
  2033. return "明细仓库与工单类型允许入库仓库不一致,不允许进行当前操作!行号:" + dets;
  2034. }
  2035. }
  2036. if ("ProdInOut!OutesideCheckReturn".equals(caller)) {
  2037. dets = baseDao
  2038. .getJdbcTemplate()
  2039. .queryForObject(
  2040. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and pd_piclass in ('委外验退单') and not exists (select 1 from make where pd_ordercode=ma_code and pd_prodcode=ma_prodcode) "
  2041. + "and not exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单' and pd_prodcode=mc_prodcode)",
  2042. String.class, pi_id);
  2043. if (dets != null) {
  2044. return "委外单+物料编号不存在,不允许进行当前操作!行号:" + dets;
  2045. }
  2046. dets = baseDao
  2047. .getJdbcTemplate()
  2048. .queryForObject(
  2049. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Make on ma_code=pd_ordercode where pd_piid=? and nvl(pi_currency,' ')<>nvl(ma_currency,' ')"
  2050. + " and not exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单')"
  2051. + " and pd_piclass in ('委外验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2052. if (dets != null) {
  2053. return "明细委外单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2054. }
  2055. dets = baseDao.getJdbcTemplate().queryForObject(
  2056. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join MakeCraft on mc_makecode=pd_ordercode "
  2057. + " and mc_code =pd_jobcode where pd_piid=? and nvl(pi_currency,' ')<>nvl(mc_currency,' ')"
  2058. + " and exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单')"
  2059. + " and pd_piclass in ('委外验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2060. if (dets != null) {
  2061. return "明细委外单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2062. }
  2063. }
  2064. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller) || "ProdInOut!DefectIn".equals(caller)
  2065. || "ProdInOut!DefectOut".equals(caller)) {
  2066. dets = baseDao
  2067. .getJdbcTemplate()
  2068. .queryForObject(
  2069. "select wm_concat(pi_inoutno) from ProdInOut where pi_id=? and pi_class in ('采购验收单','采购验退单') and (pi_cardcode,pi_title) not in (select ve_code,ve_name from vendor)",
  2070. String.class, pi_id);
  2071. if (dets != null) {
  2072. return "单据中供应商编号,供应商名称在供应商资料中不存在!";
  2073. }
  2074. dets = baseDao
  2075. .getJdbcTemplate()
  2076. .queryForObject(
  2077. "select wm_concat(pi_inoutno) from ProdInOut where pi_id=? and pi_class in ('采购验收单','采购验退单') and (pi_receivecode,pi_receivename) not in (select ve_code,ve_name from vendor)",
  2078. String.class, pi_id);
  2079. if (dets != null) {
  2080. return "单据中应付供应商编号,应付供应商名称在供应商资料中不存在!";
  2081. }
  2082. dets = baseDao
  2083. .getJdbcTemplate()
  2084. .queryForObject(
  2085. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=?"
  2086. + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' ' and not exists (select pd_code,pd_detno from purchasedetail where pd_code=ProdIODetail.pd_ordercode and pd_detno=ProdIODetail.pd_orderdetno)",
  2087. String.class, pi_id);
  2088. if (dets != null) {
  2089. return "采购单号+采购序号不存在,不允许进行当前操作!行号:" + dets;
  2090. }
  2091. dets = baseDao
  2092. .getJdbcTemplate()
  2093. .queryForObject(
  2094. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=?"
  2095. + " and not exists(select pd_code,pd_detno from purchasedetail p where p.pd_prodcode=ProdIODetail.pd_prodcode and p.pd_code=ProdIODetail.pd_ordercode and p.pd_detno=ProdIODetail.pd_orderdetno ) and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' ' ",
  2096. String.class, pi_id);
  2097. if (dets != null) {
  2098. Boolean bo = baseDao.isDBSetting("VerifyApply", "verifyApplyAllowPre"); // 允许收替代料
  2099. if (bo) {
  2100. SqlRowList rsReq = baseDao
  2101. .queryForRowSet(
  2102. "select pd_repprodcode,pd_detno,pd_code from purchasedetail A where exists(select 1 from prodiodetail B where B.pd_piid=? and A.pd_code=B.pd_ordercode and A.pd_detno=B.pd_orderdetno )",
  2103. pi_id);
  2104. if (!rsReq.hasNext()) {
  2105. return "采购单号+采购序号不存在!";
  2106. }
  2107. while (rsReq.next()) {
  2108. if (rsReq.getString("pd_repprodcode") != null && !("").equals(rsReq.getString("pd_repprodcode"))) {
  2109. StringBuffer codes = new StringBuffer();
  2110. String[] arr = rsReq.getString("pd_repprodcode").split(",");
  2111. codes.append("'");
  2112. for (int i = 0; i < arr.length; i++) {
  2113. if (i < arr.length - 1) {
  2114. codes.append(arr[i] + "','");
  2115. } else {
  2116. codes.append(arr[i] + "'");
  2117. }
  2118. }
  2119. dets = baseDao
  2120. .getJdbcTemplate()
  2121. .queryForObject(
  2122. " select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and pd_ordercode ='"
  2123. + rsReq.getString("pd_code")
  2124. + "' and pd_orderdetno="
  2125. + rsReq.getInt("pd_detno")
  2126. + " and not exists(select pd_code,pd_detno from purchasedetail p where p.pd_code=ProdIODetail.pd_ordercode and p.pd_detno=ProdIODetail.pd_orderdetno and (p.pd_prodcode=ProdIODetail.pd_prodcode or ProdIODetail.pd_prodcode in ("
  2127. + codes + ")) ) and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' ' ",
  2128. String.class, pi_id);
  2129. if (dets != null) {
  2130. return "采购单号+采购序号+物料不存在,不允许进行当前操作!行号:" + dets;
  2131. }
  2132. }
  2133. }
  2134. }
  2135. if (dets != null) {
  2136. return "采购单号+采购序号+物料不存在,不允许进行当前操作!行号:" + dets;
  2137. }
  2138. }
  2139. dets = baseDao.getJdbcTemplate().queryForObject(
  2140. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on pd_ordercode=pd_code and pd_orderdetno=pd_detno where "
  2141. + "pd_piid=? and nvl(pd_mrpstatuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('采购验收单','采购验退单') "
  2142. + "and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2143. if (dets != null) {
  2144. return "采购单明细已冻结或者已结案,不允许进行当前操作!行号:" + dets;
  2145. }
  2146. dets = baseDao.getJdbcTemplate().queryForObject(
  2147. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on pd_ordercode=pd_code and pd_orderdetno=pd_detno where "
  2148. + "pd_piid=? and nvl(pd_mrpstatuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('不良品入库单','不良品出库单') "
  2149. + "and nvl(pd_ordercode,' ')<>' ' and nvl(pd_qctype,' ')='采购检验单'", String.class, pi_id);
  2150. if (dets != null) {
  2151. return "采购单明细已冻结或者已结案,不允许进行当前操作!行号:" + dets;
  2152. }
  2153. dets = baseDao.getJdbcTemplate().queryForObject(
  2154. "select wm_concat(pd_pdno) from ProdIODetail left join Make on pd_ordercode=ma_code where "
  2155. + "pd_piid=? and nvl(ma_statuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('不良品入库单','不良品出库单') "
  2156. + "and nvl(pd_ordercode,' ')<>' ' and nvl(pd_qctype,' ')='委外检验单'", String.class, pi_id);
  2157. if (dets != null) {
  2158. return "明细行委外单已冻结或者已结案,不允许进行当前操作!行号:" + dets;
  2159. }
  2160. if (!baseDao.isDBSetting(caller, "noLimitVendor")) {
  2161. dets = baseDao.getJdbcTemplate().queryForObject(
  2162. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Purchase on pu_code=pd_ordercode where "
  2163. + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(pu_vendcode,' ') and pd_piclass in ('采购验收单','采购验退单') "
  2164. + "and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2165. if (dets != null) {
  2166. return "明细采购单与单据供应商不一致,不允许进行当前操作!行号:" + dets;
  2167. }
  2168. }
  2169. if (!baseDao.isDBSetting(caller, "allowARCust")) {
  2170. dets = baseDao
  2171. .getJdbcTemplate()
  2172. .queryForObject(
  2173. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Purchase on pu_code=pd_ordercode where "
  2174. + "pd_piid=? and nvl(pi_receivecode,' ')<>nvl(pu_receivecode,' ') and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '",
  2175. String.class, pi_id);
  2176. if (dets != null) {
  2177. return "明细采购单与单据应付供应商不一致,不允许进行当前操作!行号:" + dets;
  2178. }
  2179. dets = baseDao
  2180. .getJdbcTemplate()
  2181. .queryForObject(
  2182. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Purchase on pu_code=pd_ordercode where pd_piid=? and nvl(pi_currency,' ')<>nvl(pu_currency,' ')"
  2183. + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2184. if (dets != null) {
  2185. return "明细采购单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2186. }
  2187. }
  2188. dets = baseDao
  2189. .getJdbcTemplate()
  2190. .queryForObject(
  2191. "select wm_concat('行号:'||pd_pdno||'收料合格数量:'||ved_okqty) from ProdIODetail left join QUA_VerifyApplyDetailDet on pd_qcid=ved_id where pd_piid=? and nvl(pd_qcid,0)<>0 and nvl(pd_inqty,0)>nvl(ved_okqty,0) and pd_piclass in ('采购验收单')",
  2192. String.class, pi_id);
  2193. if (dets != null) {
  2194. return "明细行入库数量大于收料合格数量!" + dets;
  2195. }
  2196. dets = baseDao
  2197. .getJdbcTemplate()
  2198. .queryForObject(
  2199. "select wm_concat('行号:'||pd_pdno||'收料不合格数量:'||ved_ngqty) from ProdIODetail left join QUA_VerifyApplyDetailDet on pd_qcid=ved_id where pd_piid=? and nvl(pd_qcid,0)<>0 and nvl(pd_inqty,0)>nvl(ved_ngqty,0) and pd_piclass in ('不良品入库单')",
  2200. String.class, pi_id);
  2201. if (dets != null) {
  2202. return "明细行入库数量大于收料不合格数量!" + dets;
  2203. }
  2204. dets = baseDao
  2205. .getJdbcTemplate()
  2206. .queryForObject(
  2207. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Purchase on pu_code=pd_ordercode left join purchasekind on pk_name=pu_kind "
  2208. + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(pk_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(pk_whcodes,'#'))) "
  2209. + "and pd_piclass in ('采购验收单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2210. if (dets != null) {
  2211. return "明细仓库与采购单类型允许入仓库不一致,不允许进行当前操作!行号:" + dets;
  2212. }
  2213. if ("ProdInOut!PurcCheckin".equals(caller)) {
  2214. dets = baseDao
  2215. .getJdbcTemplate()
  2216. .queryForObject(
  2217. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on PurchaseDetail.pd_code=ProdIODetail.pd_ordercode and PurchaseDetail.pd_detno=ProdIODetail.pd_orderdetno "
  2218. + "where pd_piid=? and nvl(PurchaseDetail.pd_yqty,0)>nvl(PurchaseDetail.pd_qty,0)-nvl(PurchaseDetail.pd_frozenqty,0) "
  2219. + "and pd_piclass in ('采购验收单') and nvl(ProdIODetail.pd_ordercode,' ')<>' '", String.class, pi_id);
  2220. if (dets != null) {
  2221. return "明细采购订单已转数大于采购订单数量-已冻结数量,不允许进行当前操作!行号:" + dets;
  2222. }
  2223. }
  2224. }
  2225. if ("ProdInOut!SaleBorrow".equals(caller) || "ProdInOut!OtherPurcIn".equals(caller)) {
  2226. dets = baseDao
  2227. .getJdbcTemplate()
  2228. .queryForObject(
  2229. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join Prodinout on pd_piid=pi_id left join BorrowCargoType on bt_name=pi_outtype "
  2230. + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(bt_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(bt_whcodes,'#'))) "
  2231. + "and pd_piclass in ('借货出货单','其它采购入库单')", String.class, pi_id);
  2232. if (dets != null) {
  2233. return "明细仓库与借货类型允许出入仓库不一致,不允许进行当前操作!" + dets;
  2234. }
  2235. }
  2236. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller) || "ProdInOut!OtherOut".equals(caller)
  2237. || "ProdInOut!ExchangeOut".equals(caller) || "ProdInOut!SaleAppropriationOut".equals(caller)) {
  2238. if (baseDao.isDBSetting(caller, "allowDifProd")) {
  2239. dets = baseDao
  2240. .getJdbcTemplate()
  2241. .queryForObject(
  2242. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and not exists(select sd_code,sd_detno from saledetail where sd_code=pd_ordercode and sd_detno=pd_orderdetno and sd_statuscode='AUDITED')"
  2243. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  2244. String.class, pi_id);
  2245. if (dets != null) {
  2246. return "销售单号+销售序号不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
  2247. }
  2248. } else if (baseDao.isDBSetting(caller, "SaleWithProdRelation")) {
  2249. dets = baseDao
  2250. .getJdbcTemplate()
  2251. .queryForObject(
  2252. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and "
  2253. + "not exists (select sd_code,sd_detno from saledetail left join ProdRelation on (sd_prodcode=prr_soncode or (nvl(prr_ifonewa,0)=0 and sd_prodcode=prr_repcode)) "
  2254. + "where sd_code=pd_ordercode and sd_detno=pd_orderdetno and (nvl(sd_prodcode,' ')=nvl(pd_prodcode,' ') or nvl(prr_repcode ,' ')=nvl(pd_prodcode,' ') or nvl(prr_soncode ,' ')=nvl(pd_prodcode,' ')))"
  2255. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  2256. String.class, pi_id);
  2257. if (dets != null) {
  2258. return "销售单号+销售序号+物料编号不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
  2259. }
  2260. } else {
  2261. dets = baseDao
  2262. .getJdbcTemplate()
  2263. .queryForObject(
  2264. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and not exists(select sd_code,sd_detno from saledetail where sd_prodcode=pd_prodcode and sd_code=pd_ordercode and sd_detno=pd_orderdetno )"
  2265. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  2266. String.class, pi_id);
  2267. if (dets != null) {
  2268. return "销售单号+销售序号+物料编号不存在,不允许进行当前操作!行号:" + dets;
  2269. }
  2270. }
  2271. if (baseDao.isDBSetting("sys","useMachineNo")) {
  2272. dets = baseDao
  2273. .getJdbcTemplate()
  2274. .queryForObject(
  2275. "select wm_concat('物料'||pd_prodcode||'总数量'||qty||'已采集数'||yqty) from (SELECT pd_piid, pd_prodcode, pd_inoutno, nvl(sum(nvl(pd_inqty,0)+nvl(pd_outqty,0)),0) qty from prodiodetail where pd_piid=? group by pd_piid,pd_inoutno,pd_prodcode) left join (select pim_piid,pim_prodcode,count(1) yqty from prodiomac group by pim_piid,pim_prodcode) on pim_piid=pd_piid and pim_prodcode=pd_prodcode where nvl(qty,0)<>nvl(yqty,0) and nvl(yqty,0)<>0",
  2276. String.class, pi_id);
  2277. if (dets != null) {
  2278. return "单据+物料数量跟机器号数量不一致,不允许进行当前操作!行号:" + dets;
  2279. }
  2280. }
  2281. if (!(baseDao.isDBSetting("ProdInOut!Sale", "custatus"))) {
  2282. if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {// 客户挂起时,订单单价为0不限制出货
  2283. dets = baseDao
  2284. .getJdbcTemplate()
  2285. .queryForObject(
  2286. "select wm_concat(pi_cardcode) from ProdInOut left join customer on pi_cardcode=cu_code where pi_id = ? and pi_class in ('出货单') "
  2287. + "and cu_status='挂起' and not exists (select 1 from prodiodetail left join saledetail on pd_ordercode=sd_code and pd_orderdetno=sd_detno"
  2288. + " where pd_piid=pi_id and nvl(pd_ordercode,' ')<>' ' and nvl(sd_price,0)=0)", String.class,
  2289. pi_id);
  2290. if (dets != null) {
  2291. return "客户资料状态为挂起,且订单单价不为0,不允许进行当前操作!客户号:" + dets;
  2292. }
  2293. } else {
  2294. dets = baseDao
  2295. .getJdbcTemplate()
  2296. .queryForObject(
  2297. "select wm_concat(pi_cardcode) from ProdInOut left join customer on pi_cardcode=cu_code where pi_id = ? and pi_class in ('出货单','其它出库单','换货出库单','销售拨出单') and cu_status='挂起'",
  2298. String.class, pi_id);
  2299. if (dets != null) {
  2300. return "客户资料状态为挂起,不允许进行当前操作!客户号:" + dets;
  2301. }
  2302. }
  2303. }
  2304. if (!baseDao.isDBSetting(caller, "allowARCust")) {
  2305. dets = baseDao
  2306. .getJdbcTemplate()
  2307. .queryForObject(
  2308. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Sale on sa_code=pd_ordercode where pd_piid=? and nvl(pi_cardcode,' ')<>nvl(sa_custcode,' ')"
  2309. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  2310. String.class, pi_id);
  2311. if (dets != null) {
  2312. return "明细销售单与单据客户不一致,不允许进行当前操作!行号:" + dets;
  2313. }
  2314. dets = baseDao
  2315. .getJdbcTemplate()
  2316. .queryForObject(
  2317. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Sale on sa_code=pd_ordercode where pd_piid=? and nvl(pi_arcode,' ')<>nvl(sa_apcustcode,' ')"
  2318. + " and pd_piclass in ('出货单','销售退货单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2319. if (dets != null) {
  2320. return "明细销售单与单据应收客户不一致,不允许进行当前操作!行号:" + dets;
  2321. }
  2322. dets = baseDao
  2323. .getJdbcTemplate()
  2324. .queryForObject(
  2325. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Sale on sa_code=pd_ordercode where pd_piid=? and nvl(pi_currency,' ')<>nvl(sa_currency,' ')"
  2326. + " and pd_piclass in ('出货单','销售退货单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2327. if (dets != null) {
  2328. return "明细销售单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2329. }
  2330. }
  2331. dets = baseDao
  2332. .getJdbcTemplate()
  2333. .queryForObject(
  2334. "select wm_concat(pi_inoutno) from ProdInOut where pi_id=? and pi_class in ('出货单','销售退货单') and (pi_cardcode,pi_title) not in (select cu_code,cu_name from customer)",
  2335. String.class, pi_id);
  2336. if (dets != null) {
  2337. return "单据中客户编号,客户名称在客户资料中不存在!";
  2338. }
  2339. dets = baseDao
  2340. .getJdbcTemplate()
  2341. .queryForObject(
  2342. "select wm_concat(pi_inoutno) from ProdInOut where pi_id=? and pi_class in ('出货单','销售退货单') and (pi_arcode,pi_arname) not in (select cu_code,cu_name from customer)",
  2343. String.class, pi_id);
  2344. if (dets != null) {
  2345. return "单据中应收客户编号,应收客户名称在客户资料中不存在!";
  2346. }
  2347. // 销售退货单:退货数量,如退货数量+其它未过账的退货单数量大于销售订单出货数
  2348. /**
  2349. * 需考虑状态
  2350. */
  2351. dets = baseDao
  2352. .getJdbcTemplate()
  2353. .queryForObject(
  2354. "select wm_concat(pd_pdno) from ProdIODetail b left join SaleDetail on sd_code=pd_ordercode and sd_detno=pd_orderdetno where pd_piid=? and pd_status<99 and pd_piclass='销售退货单' and nvl(pd_ordercode,' ')<>' ' and nvl(pd_inqty,0) + (select nvl(sum(nvl(a.pd_inqty,0)),0) from ProdIODetail a where a.pd_piclass='销售退货单' and a.pd_status<99 and a.pd_ordercode=b.pd_ordercode and a.pd_orderdetno=b.pd_orderdetno and a.pd_id <> b.pd_id) > nvl(sd_sendqty,0)",
  2355. String.class, pi_id);
  2356. if (dets != null) {
  2357. return "本次退货数+其它退货数合计大于订单的已发货数量,不允许进行当前操作!行号:" + dets;
  2358. }
  2359. if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!OtherOut".equals(caller)) {
  2360. dets = baseDao
  2361. .getJdbcTemplate()
  2362. .queryForObject(
  2363. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail where pd_piid=? and (pd_plancode,pd_forecastdetno) not in (select sd_code, sd_detno from saleforecastdetail,saleforecast where sf_id=sd_sfid and sf_code=pd_plancode and sd_detno=pd_forecastdetno and sd_statuscode='AUDITED') and nvl(pd_plancode,' ')<>' '",
  2364. String.class, pi_id);
  2365. if (dets != null) {
  2366. return "明细行预测单号+预测序号不存在或者状态不等于已审核,不允许进行当前操作!!" + dets;
  2367. }
  2368. dets = baseDao
  2369. .getJdbcTemplate()
  2370. .queryForObject(
  2371. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail where pd_piid=? and (pd_plancode,pd_forecastdetno) in (select sd_code, sd_detno from saleforecastdetail where nvl(sd_qty,0)=0) and nvl(pd_plancode,' ')<>' '",
  2372. String.class, pi_id);
  2373. if (dets != null) {
  2374. return "明细行预测单号+预测序号预测数量等于0,不允许进行当前操作!" + dets;
  2375. }
  2376. dets = baseDao
  2377. .getJdbcTemplate()
  2378. .queryForObject(
  2379. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join SaleDetail on pd_ordercode=sd_code and pd_orderdetno=sd_detno where pd_piid=? and pd_piclass in ('销售拨出单','其它出库单') and nvl(pd_outqty+pd_inqty,0)>nvl(sd_qty,0)-nvl(sd_yqty,0) and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0 and nvl(pd_snid,0)=0",
  2380. String.class, pi_id);
  2381. if (dets != null) {
  2382. return "明细行销售单号+销售序号数量大于订单未发货数,不允许进行当前操作!" + dets;
  2383. }
  2384. dets = baseDao
  2385. .getJdbcTemplate()
  2386. .queryForObject(
  2387. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail where pd_piid=? and pd_piclass='销售拨出单' and pd_plancode not in (select a.sf_code from saleforecast a left join saleforecastkind b on (a.sf_kind=b.sf_name or a.sf_kind=b.sf_code) where a.sf_code=pd_plancode and sf_clashoption in ('SEND','发货冲销')) and nvl(pd_plancode,' ')<>' '",
  2388. String.class, pi_id);
  2389. if (dets != null) {
  2390. return "预测单录入错误,该预测类型不属于发货冲销!" + dets;
  2391. }
  2392. }
  2393. }
  2394. // if ("ProdInOut!AppropriationOut".equals(caller) || "ProdInOut!AppropriationIn".equals(caller)
  2395. // || "ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!SaleAppropriationIn".equals(caller)) {
  2396. // dets = baseDao
  2397. // .getJdbcTemplate()
  2398. // .queryForObject(
  2399. // "select wm_concat(pd_pdno) from ProdIODetail,warehouse w1,warehouse w2 where pd_piid=? and pd_whcode=w1.wh_code and pd_inwhcode=w2.wh_code and nvl(w1.wh_nocost,0)<>nvl(w2.wh_nocost,0)",
  2400. // String.class, pi_id);
  2401. // if (dets != null) {
  2402. // return "有值和无值仓之间不能相互调拨!行号:" + dets);
  2403. // }
  2404. // }
  2405. SqlRowList rs = baseDao.queryForRowSet("select * from prodiodetail where pd_piid=?", pi_id);
  2406. StringBuffer sb = new StringBuffer();
  2407. while (rs.next()) {
  2408. int pdid = rs.getInt("pd_id");
  2409. int ioid = rs.getGeneralInt("pd_ioid");
  2410. double tqty = rs.getGeneralDouble("pd_inqty") + rs.getGeneralDouble("pd_outqty");
  2411. double yqty = 0.0;
  2412. if (ioid > 0) {
  2413. yqty = baseDao.getSummaryByField("Prodiodetail", "nvl(pd_outqty,0) + nvl(pd_inqty,0)", "pd_ioid=" + ioid + " and pd_id<>"
  2414. + pdid);
  2415. Object[] source = baseDao.getFieldsDataByCondition("Prodiodetail", new String[] { "nvl(pd_outqty,0)", "nvl(pd_inqty,0)",
  2416. "pd_piclass", "pd_inoutno" }, "pd_id=" + ioid);
  2417. if (source != null) {
  2418. if (yqty + tqty > Double.parseDouble(source[0].toString()) + Double.parseDouble(source[1].toString())) {
  2419. sb.append("行号:" + rs.getInt("pd_pdno") + ",数量:" + tqty + ",无法转出." + source[2] + "[" + source[3] + "]已转数量:" + yqty
  2420. + ",本次数量:" + tqty + "<hr/>");
  2421. }
  2422. }
  2423. }
  2424. }
  2425. if (sb.length() > 0) {
  2426. return sb.toString();
  2427. }
  2428. // 保税信息判断
  2429. if (baseDao.isDBSetting("sys","ioWHBondedCheck")) {
  2430. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)) {
  2431. dets = baseDao
  2432. .getJdbcTemplate()
  2433. .queryForObject(
  2434. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join PurchaseDetail on pd_code=pd_ordercode and pd_detno=pd_orderdetno left join warehouse on ProdIODetail.pd_whcode=wh_code where pd_piid=? and nvl(PurchaseDetail.pd_bonded,0)<>nvl(wh_bonded,0)"
  2435. + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2436. if (dets != null) {
  2437. return "采购单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
  2438. }
  2439. }
  2440. if ("ProdInOut!OutesideCheckReturn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  2441. dets = baseDao
  2442. .getJdbcTemplate()
  2443. .queryForObject(
  2444. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Make on ma_code=pd_ordercode left join warehouse on pd_whcode=wh_code where pd_piid=? and nvl(ma_bonded,0)<>nvl(wh_bonded,0)"
  2445. + " and pd_piclass in ('委外验退单','委外验收单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2446. if (dets != null) {
  2447. return "委外单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
  2448. }
  2449. }
  2450. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!PartitionStockIn".equals(caller)) {
  2451. dets = baseDao
  2452. .getJdbcTemplate()
  2453. .queryForObject(
  2454. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Make on ma_code=pd_ordercode left join warehouse on pd_whcode=wh_code where pd_piid=? and nvl(ma_bonded,0)<>nvl(wh_bonded,0)"
  2455. + " and pd_piclass in ('完工入库单','拆件入库单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2456. if (dets != null) {
  2457. return "工单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
  2458. }
  2459. }
  2460. if ("ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller) || "ProdInOut!Picking".equals(caller)
  2461. || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
  2462. || "ProdInOut!OutsidePicking".equals(caller)) {
  2463. dets = baseDao
  2464. .getJdbcTemplate()
  2465. .queryForObject(
  2466. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join Prodinout on pd_piid=pi_id left join Make on ma_code=pd_ordercode left join warehouse on pd_whcode=wh_code where pd_piid=? and nvl(ma_bonded,0)=0 and nvl(wh_bonded,0)<>0"
  2467. + " and pd_piclass in ('委外补料单','委外退料单','委外领料单') and nvl(pd_ordercode,' ')<>' '", String.class,
  2468. pi_id);
  2469. if (dets != null) {
  2470. return "委外单保税属性是非保税,不能发生仓库保税属性是保税的单据!" + dets;
  2471. }
  2472. dets = baseDao
  2473. .getJdbcTemplate()
  2474. .queryForObject(
  2475. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join Prodinout on pd_piid=pi_id left join Make on ma_code=pd_ordercode left join warehouse on pd_whcode=wh_code where pd_piid=? and nvl(ma_bonded,0)=0 and nvl(wh_bonded,0)<>0"
  2476. + " and pd_piclass in ('生产补料单','生产退料单','生产领料单') and nvl(pd_ordercode,' ')<>' '", String.class,
  2477. pi_id);
  2478. if (dets != null) {
  2479. return "工单保税属性是非保税,不能发生仓库保税属性是保税的单据!" + dets;
  2480. }
  2481. }
  2482. if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!AppropriationOut".equals(caller)) {
  2483. dets = baseDao
  2484. .getJdbcTemplate()
  2485. .queryForObject(
  2486. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail left join Prodinout on pd_piid=pi_id left join warehouse a on a.wh_code=pd_whcode left join warehouse b on b.wh_code=pd_inwhcode where pd_piid=? and nvl(a.wh_bonded,0)<>nvl(b.wh_bonded,0)"
  2487. + " and pd_piclass in ('拨出单','销售拨出单') and nvl(pd_whcode,' ')<>' ' and nvl(pd_inwhcode,' ')<>' '",
  2488. String.class, pi_id);
  2489. if (dets != null) {
  2490. return "拨出仓库与拨入仓库仓库的保税属性不一致,不能进行当前操作!" + dets;
  2491. }
  2492. }
  2493. }
  2494. // @add20180605 Q:2018050126 最后一张完工入库单或者委外验收单,提交、审核、过账之前限制,不允许存在未过账
  2495. // 领、退、补单据,未审核的报废单,未过账的委外验退单
  2496. if (("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!Make!In".equals(caller))
  2497. && baseDao.isDBSetting(caller, "checkRelBillsStatus")) {
  2498. // 判断哪些工单是最后一张完工入库单
  2499. rs = baseDao
  2500. .queryForRowSet(
  2501. "select pd_ordercode,pd_pdno from (select pd_ordercode,sum(pd_inqty)inqty,wm_concat(pd_pdno)pd_pdno from prodiodetail where "
  2502. + "pd_piid=? and pd_piclass in('完工入库单','委外验收单') group by pd_ordercode) A left join make on ma_code=A.pd_ordercode "
  2503. + "where nvl(ma_madeqty,0)+inqty>=ma_qty", pi_id);
  2504. String errors = null;
  2505. while (rs.next()) {
  2506. dets = baseDao
  2507. .getJdbcTemplate()
  2508. .queryForObject(
  2509. "select wm_concat(pi_class||':'||pi_inoutno) from prodiodetail,ProdInOut WHERE pd_piid=pi_id AND pi_id<>? and pd_ordercode = ? AND pi_statuscode = 'UNPOST' AND pd_status=0 AND (pd_piclass LIKE '生产%' OR pd_piclass LIKE '委外%' OR pd_piclass LIKE '完工%') and rownum<15",
  2510. String.class, pi_id, rs.getString("pd_ordercode"));
  2511. if (dets != null) {
  2512. errors = "行号:" + rs.getString("pd_pdno") + ",工单:" + rs.getString("pd_ordercode") + "存在关联未过账单据!" + dets;
  2513. }
  2514. dets = baseDao
  2515. .getJdbcTemplate()
  2516. .queryForObject(
  2517. "SELECT wm_concat(ms_code) FROM MakeScrapdetail,MakeScrap WHERE md_msid=ms_id AND md_mmcode=? AND ms_statuscode in ('ENTERING','COMMITED') AND nvl(md_status,0)=0",
  2518. String.class, rs.getString("pd_ordercode"));
  2519. if (dets != null) {
  2520. if (errors != null) {
  2521. errors += "<br>未审核的报废单:" + dets;
  2522. } else {
  2523. errors = "行号:" + rs.getString("pd_pdno") + ",工单:" + rs.getString("pd_ordercode") + "存在关联未审核的报废单:" + dets;
  2524. }
  2525. }
  2526. if (errors != null && !"".equals(errors)) {
  2527. return errors;
  2528. }
  2529. }
  2530. }
  2531. if (baseDao.isOut(caller)) {
  2532. dets = baseDao
  2533. .getJdbcTemplate()
  2534. .queryForObject(
  2535. "select wm_concat(pd_pdno) from (select pd_pdno from ProdIODetail where pd_piid=? and nvl(pd_outqty,0)>0 and nvl(pd_prodcode,' ')<>' ' and nvl(pd_whcode,' ')<>' ' and nvl(pd_batchcode,' ')<>' '"
  2536. + "and not exists(select 1 from batch where pd_prodcode=ba_prodcode and pd_whcode=ba_whcode and pd_batchcode=ba_code) order by pd_pdno)",
  2537. String.class, pi_id);
  2538. if (dets != null) {
  2539. return "物料编号+仓库编号+批号不存在,不允许进行当前操作!行号:" + dets;
  2540. }
  2541. }
  2542. return null;
  2543. }
  2544. /**
  2545. * 校验批次是否重复
  2546. *
  2547. * @param caller
  2548. * @param pi_id
  2549. */
  2550. private String checkBatch(String caller, Object pi_id) {
  2551. if (baseDao.isIn(caller)) {
  2552. // 入库单据,同一物料同仓库不能同时入两次相同的批号
  2553. SqlRowList rs = baseDao
  2554. .queryForRowSet("select count(1)n, wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']')detno from (select pd_batchcode,pd_whcode,pd_prodcode,min(pd_pdno)pd_pdno,min(pd_inoutno)pd_inoutno,min(pd_piclass)pd_piclass,count(1)c from ProdIODetail where pd_piid="
  2555. + pi_id + " and pd_batchcode<>' ' group by pd_batchcode,pd_whcode,pd_prodcode ) where c> 1");
  2556. if (rs.next()) {
  2557. if (rs.getInt("n") > 0) {
  2558. return "同一物料同仓库不能同时入两次相同的批号!" + rs.getString("detno");
  2559. }
  2560. }
  2561. rs = baseDao
  2562. .queryForRowSet("select count(1) n,wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']')detno "
  2563. + "from (select pd_piclass,pd_inoutno,pd_pdno from ProdIODetail where pd_piid="
  2564. + pi_id
  2565. + " and pd_batchcode is not null and exists (select 1 from batch where ba_code=pd_batchcode and ba_prodcode=pd_prodcode "
  2566. + "and ba_whcode=pd_whcode and (nvl(ba_remain,0)<>0 or nvl(ba_inqty,0)<>0))) where rownum<30");
  2567. if (rs.next()) {
  2568. if (rs.getInt("n") > 0) {
  2569. return "批号已存在,不能重复入库!" + rs.getString("detno");
  2570. }
  2571. }
  2572. }
  2573. return null;
  2574. }
  2575. private String copcheck(int pi_id, String caller) {
  2576. if (baseDao.isDBSetting("sys","CopCheck")) {
  2577. // 出入库单:明细行采购单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  2578. String dets = baseDao
  2579. .getJdbcTemplate()
  2580. .queryForObject(
  2581. "select wm_concat(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id left join Purchase on pd_ordercode=pu_code where pi_id=? and nvl(pu_cop,' ')<>nvl(pi_cop,' ') and nvl(pd_ordercode,' ')<>' ' "
  2582. + " and pd_piclass in ('采购验收单','采购验退单')", String.class, pi_id);
  2583. if (dets != null) {
  2584. return "明细行采购单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  2585. }
  2586. // 出入库单:明细行销售单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  2587. dets = baseDao
  2588. .getJdbcTemplate()
  2589. .queryForObject(
  2590. "select wm_concat(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id left join Sale on pd_ordercode=sa_code where pi_id=? and nvl(sa_cop,' ')<>nvl(pi_cop,' ') and nvl(pd_ordercode,' ')<>' ' "
  2591. + "and pd_piclass in ('出货单','销售退货单','销售拨出单','销售拨入单')", String.class, pi_id);
  2592. if (dets != null) {
  2593. return "明细行销售单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  2594. }
  2595. // 出货单:来源单所属公司与当前单所属公司不一致,不允许进行当前操作
  2596. dets = baseDao
  2597. .getJdbcTemplate()
  2598. .queryForObject(
  2599. "select wm_concat(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id left join Sendnotify on pd_snid=sn_id where pi_id=? and nvl(sn_cop,' ')<>nvl(pi_cop,' ') and nvl(pd_snid,0)<>0 ",
  2600. String.class, pi_id);
  2601. if (dets != null) {
  2602. return "明细来源通知单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  2603. }
  2604. // 出入库单:明细行制造单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  2605. dets = baseDao
  2606. .getJdbcTemplate()
  2607. .queryForObject(
  2608. "select wm_concat(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id left join Make on pd_ordercode=ma_code where pi_id=? and nvl(ma_cop,' ')<>nvl(pi_cop,' ') and nvl(pd_ordercode,' ')<>' ' "
  2609. + "and pd_piclass in ('生产领料单','生产退料单','生产补料单','完工入库单','拆件入库单')", String.class, pi_id);
  2610. if (dets != null) {
  2611. return "明细行制造单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  2612. }
  2613. // 出入库单:明细行委外单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  2614. dets = baseDao
  2615. .getJdbcTemplate()
  2616. .queryForObject(
  2617. "select wm_concat(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id left join Make on pd_ordercode=ma_code where pi_id=? and nvl(ma_cop,' ')<>nvl(pi_cop,' ') and nvl(pd_ordercode,' ')<>' ' "
  2618. + "and pd_piclass in ('委外验收单','委外验退单','委外领料单','委外退料单','委外补料单')", String.class, pi_id);
  2619. if (dets != null) {
  2620. return "明细行委外单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  2621. }
  2622. if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!OtherOut".equals(caller)
  2623. || "ProdInOut!AppropriationOut".equals(caller)) {
  2624. dets = baseDao
  2625. .getJdbcTemplate()
  2626. .queryForObject(
  2627. "select wm_concat(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id left join SaleForecast on pd_plancode=sf_code where pi_id=? and nvl(sf_cop,' ')<>nvl(pi_cop,' ') and nvl(pd_plancode,' ')<>' ' "
  2628. + "and pd_piclass in ('销售拨出单','其它出库单')", String.class, pi_id);
  2629. if (dets != null) {
  2630. return "明细行销售预测单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  2631. }
  2632. dets = baseDao
  2633. .getJdbcTemplate()
  2634. .queryForObject(
  2635. "select wm_concat(pd_pdno) from ProdIODetail left join prodinout on pd_piid=pi_id left join Warehouse on pd_inwhcode=wh_code where pi_id=? and pi_class in ('销售拨出单','拨出单') and nvl(pi_cop,' ')<>nvl(wh_cop,' ')",
  2636. String.class, pi_id);
  2637. if (dets != null) {
  2638. return "单据所属公司和明细行拨入仓库的所属公司不一致,不允许进行当前操作!行号:" + dets;
  2639. }
  2640. }
  2641. // 出入库单限制界面的所属公司和仓库的所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  2642. dets = baseDao
  2643. .getJdbcTemplate()
  2644. .queryForObject(
  2645. "select wm_concat(pd_pdno) from ProdIODetail left join prodinout on pd_piid=pi_id left join Warehouse on pd_whcode=wh_code where nvl(pi_cop,' ')<>nvl(wh_cop,' ') and pi_id=? and pi_class not in ('成本调整单')",
  2646. String.class, pi_id);
  2647. if (dets != null) {
  2648. return "单据所属公司和明细行仓库的所属公司不一致,不允许进行当前操作!行号:" + dets;
  2649. }
  2650. }
  2651. return null;
  2652. }
  2653. private String factorycheck(int pi_id, String caller) {
  2654. if (baseDao.isDBSetting("MpsDesk", "mrpSeparateFactory")) {
  2655. // 采购验收单、采购验退单:明细行采购单所属工厂与仓库的所属工厂不一致,,不允许进行当前操作
  2656. String dets = baseDao
  2657. .getJdbcTemplate()
  2658. .queryForObject(
  2659. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on ProdIODetail.pd_ordercode=PurchaseDetail.pd_code and ProdIODetail.pd_orderdetno=PurchaseDetail.pd_detno left join Warehouse on ProdIODetail.pd_whcode=wh_code left join product on ProdIODetail.pd_prodcode=pr_code where pd_piid=? and nvl(PR_ISGROUPPURC,0)=0 and nvl(PurchaseDetail.pd_factory,' ')<>nvl(wh_factory,' ') and nvl(ProdIODetail.pd_ordercode,' ')<>' ' "
  2660. + " and PurchaseDetail.pd_factory is not null and pd_piclass in ('采购验收单','采购验退单')", String.class,
  2661. pi_id);
  2662. if (dets != null) {
  2663. return "明细行采购单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
  2664. }
  2665. // 生产领料单、退料单、补料单:明细行制造单所属工厂与仓库的所属工厂不一致,不允许进行当前操作
  2666. dets = baseDao
  2667. .getJdbcTemplate()
  2668. .queryForObject(
  2669. "select wm_concat(pd_pdno) from ProdIODetail left join Make on pd_ordercode=ma_code left join Warehouse on pd_whcode=wh_code left join product on ProdIODetail.pd_prodcode=pr_code where pd_piid=? and nvl(PR_ISGROUPPURC,0)=0 and nvl(ma_factory,' ')<>nvl(wh_factory,' ') and nvl(pd_ordercode,' ')<>' ' "
  2670. + "and pd_piclass in ('生产领料单','生产退料单','生产补料单')", String.class, pi_id);
  2671. if (dets != null) {
  2672. return "明细行制造单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
  2673. }
  2674. // 委外领料单、退料单、补料单:明细行委外单所属工厂与仓库的所属工厂不一致,不允许进行当前操作
  2675. dets = baseDao
  2676. .getJdbcTemplate()
  2677. .queryForObject(
  2678. "select wm_concat(pd_pdno) from ProdIODetail left join Make on pd_ordercode=ma_code left join Warehouse on pd_whcode=wh_code left join product on ProdIODetail.pd_prodcode=pr_code where pd_piid=? and nvl(PR_ISGROUPPURC,0)=0 and nvl(ma_factory,' ')<>nvl(wh_factory,' ') and nvl(pd_ordercode,' ')<>' ' "
  2679. + "and pd_piclass in ('委外领料单','委外退料单','委外补料单')", String.class, pi_id);
  2680. if (dets != null) {
  2681. return "明细行委外单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
  2682. }
  2683. }
  2684. return null;
  2685. }
  2686. private String checkIOMaPick(String caller, Object pi_id) {
  2687. String[] checkCallers={"ProdInOut!AppropriationOut","ProdInOut!Picking", "ProdInOut!OutsidePicking","ProdInOut!Make!Give","ProdInOut!OSMake!Give"
  2688. ,"ProdInOut!OtherOut","ProdInOut!SaleBorrow"};
  2689. if(Arrays.asList(checkCallers).contains(caller)){
  2690. String gridStore = "[]";
  2691. String formStore = null;
  2692. SqlRowList fromP = baseDao.queryForRowSet("select pi_id,pi_class,TO_CHAR(pi_date,'YYYYMM') pi_date from prodinout where pi_id = "+pi_id+" ");
  2693. if(fromP.next()){
  2694. formStore = BaseUtil.parseMap2Str(baseDao.changeKeyToLowerCase(fromP.getCurrentMap()));
  2695. SqlRowList checkDetail = baseDao.queryForRowSet("select pd_ordercode macode, pd_prodcode prodcode,pd_outqty outqty,pd_whcode outwhcode,pd_inwhcode inwhcode" +
  2696. " from prodiodetail where pd_piid = "+pi_id+" order by pd_pdno");
  2697. if(checkDetail.hasNext()){
  2698. gridStore = BaseUtil.parseGridStore2Str(baseDao.changeKeyToLowerCase(checkDetail.getResultList()));
  2699. }
  2700. String res = baseDao.callProcedure("USER_CHECKOUTSTOCK", new Object[] {formStore,gridStore});
  2701. if (res != null && res.length() > 0) {
  2702. return res;
  2703. }
  2704. }
  2705. }
  2706. return null;
  2707. }
  2708. /**
  2709. * 新增生产退料和委外退料判断,替代料退料数量不能大于替代料已领数量,主料退料不能大于主料已领数,工单外退料的情况不限制
  2710. *
  2711. * @date 2016年10月17日 下午12:30:58
  2712. * @param pi_id
  2713. * 单据id
  2714. */
  2715. private String checkRepQty(int pi_id) {
  2716. SqlRowList rs = baseDao
  2717. .queryForRowSet(
  2718. "select wm_concat(T.pdno) no from (select nvl(sum(pd_inqty),0) inqty,pd_ordercode,pd_orderdetno,pd_prodcode,max(pd_pdno)pdno "
  2719. + " from prodiodetail where pd_piid=? group by pd_ordercode,pd_orderdetno,pd_prodcode )T "
  2720. + " left join makematerial on mm_code=T.pd_ordercode and mm_detno=T.pd_orderdetno "
  2721. + " where T.pd_prodcode=mm_prodcode and mm_havegetqty-nvl(mm_haverepqty,0)<T.inqty and (nvl(mm_qty,0)>0 or (nvl(mm_qty,0)=0 and nvl(mm_updatetype,' ')<>'R')) and rownum<25",
  2722. pi_id);
  2723. if (rs.next() && rs.getObject("no") != null) {
  2724. return "主料退料数不允许大于主料已领数,行号:" + rs.getString(1);
  2725. }
  2726. rs = baseDao
  2727. .queryForRowSet(
  2728. "select wm_concat(T.pdno) no from (select nvl(sum(pd_inqty),0) inqty,pd_ordercode,pd_orderdetno,pd_prodcode,max(pd_pdno)pdno "
  2729. + " from prodiodetail where pd_piid=? group by pd_ordercode,pd_orderdetno,pd_prodcode )T "
  2730. + " left join MakeMaterialreplace on mp_mmcode=T.pd_ordercode and mp_mmdetno=T.pd_orderdetno left join makematerial on mm_code=mp_mmcode and mm_detno=mp_mmdetno"
  2731. + " where T.pd_prodcode=mp_prodcode and T.inqty>nvl(mp_haverepqty,0) and (nvl(mm_qty,0)>0 or (nvl(mm_qty,0)=0 and nvl(mm_updatetype,' ')<>'R')) and rownum<25",
  2732. pi_id);
  2733. if (rs.next() && rs.getObject("no") != null) {
  2734. return "替代料退料数不允许大于替代已领数,行号:" + rs.getString(1);
  2735. }
  2736. return null;
  2737. }
  2738. private String checkMmBackOver(String caller, int pi_id) {
  2739. //截止到退料单单据日期月份的 本单的退料不允许大于 已过账的 领料出库-退料数+补料数-(完工-验退数)*单位用量
  2740. String data = baseDao.getJdbcTemplate().queryForObject("select wm_concat('工单:'||pd_ordercode||',序号:'||pd_orderdetno ||'<br>') " +
  2741. " from (select pd_ordercode,pd_orderdetno,sum(pd_inqty)inqty,to_char(max(pi_date),'yyyymm')pidate from prodinout left join prodiodetail on pd_piid=pi_id where pd_piid=? group by pd_ordercode,pd_orderdetno)a LEFT JOIN MAKE ON MA_CODE=PD_ORDERCODE " +
  2742. " LEFT JOIN MAKEMATERIAL ON MM_MAID=MA_ID and pd_orderdetno=mm_detno where " +
  2743. " inqty > nvl((select sum(nvl(pd_outqty,0)-nvl(pd_inqty,0)) from prodiodetail b left join prodinout on pd_piid=pi_id where pd_status=99 and pidate>= to_char(pi_date,'yyyymm') and " +
  2744. " a.pd_ordercode=b.pd_ordercode and a.pd_orderdetno=b.pd_orderdetno and pi_class in('生产领料单','委外领料单','生产退料单','委外退料单','生产补料单','委外补料单')),0) " +
  2745. " - NVL((select SUM(MD_QTY) from makescrap left join makescrapdetail on md_msid=ms_id WHERE ms_statuscode='AUDITED' AND pidate>=to_char(MS_AUDITDATE,'yyyymm') AND MD_mmcode = pd_ordercode AND MD_mmdetno = pd_orderdetno),0) " +
  2746. " -NVL((SELECT sum(nvl(pd_inqty,0)-nvl(pd_outqty,0)) FROM prodiodetail b left join prodinout on pd_piid=pi_id where pd_status=99 and pidate>=to_char(pi_date,'yyyymm') and " +
  2747. " a.pd_ordercode=b.pd_ordercode AND pi_class in('完工入库单','委外验退单','委外验收单')),0)*nvl(mm_oneuseqty,0) and rownum<10",String.class,pi_id);
  2748. if(data != null){
  2749. return "退料数大于截止到单据月份剩余的结存数,"+data;
  2750. }
  2751. return null;
  2752. }
  2753. /**
  2754. * 计算pi_total
  2755. */
  2756. private void getTotal(Object pi_id, String caller) {
  2757. baseDao.execute("update prodiodetail set pd_purcinqty=nvl(pd_inqty,0) where pd_piid=" + pi_id
  2758. + " and exists (select 1 from product where pd_prodcode=pr_code and nvl(pr_purcunit,pr_unit)=pr_unit) ");
  2759. baseDao.execute("update prodiodetail set pd_purcoutqty=nvl(pd_outqty,0) where pd_piid=" + pi_id
  2760. + " and exists (select 1 from product where pd_prodcode=pr_code and nvl(pr_purcunit,pr_unit)=pr_unit)");
  2761. baseDao.execute("update prodiodetail set pd_purcinqty=pd_inqty/(select case when nvl(pr_purcrate,0)<>0 then pr_purcrate else 1 end from product where pr_code=pd_prodcode) where pd_piid="
  2762. + pi_id + " and nvl(pd_purcinqty,0)=0");
  2763. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
  2764. || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  2765. if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {// 委外
  2766. baseDao.updateByCondition("ProdIODetail", "pd_orderprice=(select ma_price from make where ma_code=pd_ordercode)",
  2767. "pd_piid=" + pi_id + " and nvl(pd_orderprice,0)=0");
  2768. // 强制取委外单主表中的税率
  2769. baseDao.execute(
  2770. "update ProdIODetail set pd_taxrate=(select nvl(ma_taxrate,0) from make where ma_code=pd_ordercode) where pd_ordercode is not null and pd_piid=?",
  2771. pi_id);
  2772. } else {// 采购
  2773. baseDao.updateByCondition("ProdIODetail",
  2774. "pd_orderprice=nvl((select pd_price from PurchaseDetail where pd_code=pd_ordercode and pd_detno=pd_orderdetno),0)",
  2775. "pd_piid=" + pi_id + " and nvl(pd_orderprice,0)=0 and nvl(pd_status,0)<>99");
  2776. // 强制取采购单明细表中的对应的税率
  2777. baseDao.execute(
  2778. "update ProdIODetail set pd_taxrate=(select nvl(pd_rate,0) from PurchaseDetail where pd_code=pd_ordercode and pd_detno=pd_orderdetno) where pd_ordercode is not null and nvl(pd_status,0)<>99 and pd_piid=?",
  2779. pi_id);
  2780. }
  2781. baseDao.execute("update ProdIODetail set pd_ordertotal=round(pd_orderprice*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end),2) where pd_piid="
  2782. + pi_id);
  2783. baseDao.execute("update ProdIODetail set pd_taxtotal=round(pd_orderprice*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end)*nvl(pd_taxrate,0)/(100+nvl(pd_taxrate,0)),2),pd_nettotal=round(pd_orderprice*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end)/(1+nvl(pd_taxrate,0)/100),2) where pd_piid="
  2784. + pi_id);
  2785. baseDao.updateByCondition("ProdIODetail", " pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)", "pd_piid="
  2786. + pi_id);
  2787. baseDao.updateByCondition("ProdInOut",
  2788. "pi_total = round(nvl((SELECT sum(round(pd_ordertotal,2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
  2789. + pi_id);
  2790. baseDao.updateByCondition(
  2791. "ProdIODetail",
  2792. "pd_netprice=round(pd_orderprice/(1+pd_taxrate/100),8),pd_nettotal=round(pd_orderprice*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end)/(1+nvl(pd_taxrate,0)/100),2)",
  2793. "pd_piid=" + pi_id);
  2794. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  2795. } else if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller)) {
  2796. baseDao.updateByCondition(
  2797. "ProdIODetail",
  2798. "pd_ordertotal=round(nvl(pd_sendprice,0)*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end),2),pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)",
  2799. "pd_piid=" + pi_id);
  2800. baseDao.updateByCondition(
  2801. "ProdIODetail",
  2802. "pd_netprice=round(pd_sendprice/(1+pd_taxrate/100),8),pd_nettotal=round(pd_sendprice*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end)/(1+nvl(pd_taxrate,0)/100),2)",
  2803. "pd_piid=" + pi_id);
  2804. baseDao.updateByCondition("ProdInOut",
  2805. "pi_total=round(nvl((SELECT sum(round(pd_ordertotal,2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id=" + pi_id);
  2806. baseDao.execute("update prodiodetail set pd_customprice=pd_sendprice, pd_taxamount=pd_ordertotal "
  2807. + "where pd_piclass in ('出货单','销售退货单') and pd_piid=? and nvl(pd_customprice,0)=0", pi_id);
  2808. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  2809. // 成品标准成本,用于报价毛利润统计
  2810. baseDao.execute("UPDATE product set pr_cost=nvl((select price from ( select qd_prodcode,round(qd_factprice*qu_rate,2) price,"
  2811. + " row_number() over(partition by qd_prodcode order by qu_auditdate desc) rn from quotation,quotationdetail "
  2812. + "where qu_id=qd_quid and qu_statuscode='AUDITED') t1 where rn=1 and qd_prodcode=pr_code),0) "
  2813. + "where nvl(pr_cost,0)=0 and pr_code in (select pd_prodcode from prodiodetail where pd_piid=?)", pi_id);
  2814. baseDao.execute("UPDATE prodiodetail SET pd_showprice=nvl((select pr_cost from product where pd_prodcode=pr_code),0)"
  2815. + "WHERE pd_piid=?", pi_id);
  2816. } else {
  2817. baseDao.updateByCondition("ProdIODetail", "pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)", "pd_piid="
  2818. + pi_id);
  2819. baseDao.updateByCondition(
  2820. "ProdInOut",
  2821. "pi_total=(SELECT sum(round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)) FROM ProdIODetail WHERE pd_piid=pi_id)",
  2822. "pi_id=" + pi_id);
  2823. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  2824. }
  2825. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller) || "ProdInOut!AppropriationOut".equals(caller)
  2826. || "ProdInOut!OtherOut".equals(caller) || "ProdInOut!ExchangeOut".equals(caller)) {
  2827. Object cardcode = baseDao.getFieldDataByCondition("ProdInOut", "pi_cardcode", "pi_id=" + pi_id);
  2828. baseDao.execute("update prodiodetail set (PD_CUSTPRODCODE,PD_CUSTPRODSPEC,pd_custproddetail)=(select max(pc_custprodcode),max(pc_custprodspec),max(pc_custproddetail) from ProductCustomer left join Product on pc_prodid=pr_id left join customer on pc_custid=cu_id where cu_code='"
  2829. + cardcode
  2830. + "' and pd_prodcode=pr_code) where pd_piid="
  2831. + pi_id
  2832. + " and nvl(pd_custprodcode,' ')=' ' and nvl(pd_custprodspec,' ')=' ' and pd_piclass in ('销售退货单', '出货单', '其它出库单', '拨出单', '换货出库单')");
  2833. baseDao.execute("update ProdIODetail set pd_taxtotal=round(pd_sendprice*(case when nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0)=0 then nvl(pd_inqty,0)+nvl(pd_outqty,0) else nvl(pd_purcinqty,0)+nvl(pd_purcoutqty,0) end)*nvl(pd_taxrate,0)/(100+nvl(pd_taxrate,0)),2) where pd_piid="
  2834. + pi_id);
  2835. }
  2836. if ("ProdInOut!CostChange".equals(caller)) {
  2837. baseDao.execute(
  2838. "update prodiodetail set pd_total=round((nvl(pd_price,0)-nvl(pd_orderprice,0))*nvl(pd_orderqty,0),2) where pd_piclass ='成本调整单' and pd_piid=?",
  2839. pi_id);
  2840. }
  2841. // 入库类单据:如果pd_location为空,默认等于物料资料里的仓位pr_location
  2842. if (baseDao.isIn(caller)) {
  2843. baseDao.execute(
  2844. "update prodiodetail set pd_location=(select pr_location from product where pr_code=pd_prodcode) where pd_piid=? and nvl(pd_location,' ')=' '",
  2845. pi_id);
  2846. }
  2847. baseDao.updateByCondition("ProdInOut",
  2848. "pi_total = round(nvl((SELECT sum(round(nvl(pd_ordertotal,0),2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
  2849. + pi_id);
  2850. baseDao.updateByCondition("ProdInOut",
  2851. "pi_nettotal = round(nvl((SELECT sum(round(nvl(pd_nettotal,0),2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
  2852. + pi_id);
  2853. }
  2854. /**
  2855. * 计算pi_qtytotal
  2856. */
  2857. private void getQtyTotal(Object pi_id, String caller) {
  2858. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!OtherOut".equals(caller)) {
  2859. baseDao.execute("update ProdInOut set pi_qtytotal=nvl((select sum(nvl(pd_outqty,0)+nvl(pd_inqty,0)) from ProdIODetail where "
  2860. + "ProdIODetail.pd_piid = ProdInOut.pi_id),0) where pi_id=" + pi_id);
  2861. }
  2862. }
  2863. // @add 20170524 出库类型的单据,保存,更新,获取批号之后更新备料状态
  2864. private void updatePdaStatus(String caller, Object pi_id) {
  2865. Boolean bo = baseDao.isDBSetting("BarCodeSetting", "BarRelevancyBatch");
  2866. Boolean AutoPickBarcode = baseDao.isDBSetting("BarCodeSetting", "autoPickBarcode");
  2867. if (!AutoPickBarcode) {
  2868. if (!bo) {
  2869. if (baseDao.isOut(caller)) { // 出库类型
  2870. // 如果所有的明细都没有条码则更新为空
  2871. SqlRowList rs = baseDao.queryForRowSet(
  2872. "select count(1)cn from prodiodetail where pd_piid=? and nvl(pd_batchcode,' ')<>' '", pi_id);
  2873. if (rs.next() && rs.getInt("cn") == 0) {
  2874. baseDao.execute("update prodinout set pi_pdastatus='' where pi_id=? and nvl(pi_pdastatus,' ')<>' '", pi_id);
  2875. } else {
  2876. rs = baseDao.queryForRowSet("select count(1)cn from barcodeio where bi_piid=? and bi_outqty>0", pi_id);
  2877. if (rs.next() && rs.getInt("cn") > 0) { // 有一行以上备料记录则是备料中
  2878. baseDao.execute("update prodinout set pi_pdastatus ='备料中' where pi_id=?", pi_id);
  2879. rs = baseDao
  2880. .queryForRowSet(
  2881. "select count(1) cn from (select pd_prodcode,pd_whcode,sum(pd_outqty)qty from prodiodetail left join batch on pd_batchid=ba_id "
  2882. + " where pd_piid=? and ba_hasbarcode<>0 group by pd_prodcode,pd_whcode)A left join (select bi_prodcode,bi_whcode,sum(bi_outqty)qty "
  2883. + " from barcodeio where bi_piid=? group by bi_prodcode,bi_whcode)B on (pd_prodcode=bi_prodcode and pd_whcode=bi_whcode) where A.qty>NVL(B.qty,0)",
  2884. pi_id, pi_id);
  2885. if (rs.next() && rs.getInt("cn") == 0) {
  2886. baseDao.execute("update prodinout set pi_pdastatus ='已备料' where pi_id=?", pi_id);
  2887. }
  2888. } else {
  2889. // --存在有条码的批号则更新成未备料
  2890. baseDao.execute(
  2891. "update prodinout set pi_pdastatus ='未备料' where pi_id=? and exists(select 1 from prodiodetail,batch where pd_piid=? and pd_batchid=ba_id and ba_hasbarcode<>0)",
  2892. pi_id, pi_id);
  2893. // --所有批号都无条码则更新成无条码
  2894. baseDao.execute(
  2895. "update prodinout set pi_pdastatus ='无条码' where pi_id=? and not exists(select 1 from prodiodetail left join batch on ba_id=pd_batchid where pd_piid=? and ba_hasbarcode=-1)",
  2896. pi_id, pi_id);
  2897. }
  2898. }
  2899. }
  2900. }
  2901. }
  2902. }
  2903. /**
  2904. * 检查批号是否存在,批号数量是否足够
  2905. */
  2906. private String checkBatchRemain(Object pi_id) {
  2907. int count = baseDao.getCount("select count(1) from documentsetup where ds_name=(select pi_class from prodinout " + "where pi_id="
  2908. + pi_id + ") and (ds_inorout = '-IN' or ds_inorout = 'OUT')");
  2909. if (count > 0) {
  2910. String pdnos1 = baseDao.getJdbcTemplate().queryForObject(
  2911. "select WMSYS.WM_CONCAT(pd_pdno) from (select pd_pdno from prodiodetail left join batch on"
  2912. + " pd_batchcode=ba_code and ba_whcode = pd_whcode and ba_prodcode = pd_prodcode "
  2913. + "where pd_piid=? and ba_code is null order by pd_pdno) where rownum<20", String.class, pi_id);
  2914. String pdnos2 = baseDao
  2915. .getJdbcTemplate()
  2916. .queryForObject(
  2917. "select WMSYS.WM_CONCAT(pd_pdno) from (select WMSYS.WM_CONCAT(pd_pdno) pd_pdno,max(pd_batchcode),"
  2918. + "sum(pd_outqty),max(ba_remain),max(ba_code) from prodiodetail left join batch on pd_batchcode=ba_code and "
  2919. + "ba_whcode = pd_whcode and ba_prodcode = pd_prodcode where pd_piid=? group by pd_batchcode,pd_prodcode,pd_whcode"
  2920. + " having sum(pd_outqty)>max(ba_remain) ) where rownum<20", String.class, pi_id);
  2921. if (pdnos1 != null || pdnos2 != null) {
  2922. String error1 = pdnos1 == null ? "" : "找不到您所指的批号,请修改批号或点击【重置批号】再过账!行号是:" + pdnos1 + "<br>";
  2923. String error2 = pdnos2 == null ? "" : "批号的库存数小于出库数量,请修改批号或点击【重置批号】再过账!行号是:" + pdnos2 + "<br>";
  2924. return error1 + error2;
  2925. }
  2926. }
  2927. return null;
  2928. }
  2929. /**
  2930. * 产生冲销单并审核 发货单过账/销售单审核 scm->prodinout->post->after scm->sale->audit->after
  2931. *
  2932. * @author ZhongYL
  2933. */
  2934. @Transactional
  2935. public void createSaleClash(Integer fromid, String fromcaller,Employee employee) {
  2936. String SqlStr = "", clashcode = "", canclash = "", othercondition = "";
  2937. double thisqty = 0, needclashqty = 0, clashedqty = 0;
  2938. int csid = 0, detno = 0;
  2939. String prodcode = "", ordercode = "", fromcode = "", fromwhere = "";
  2940. String clashoption = "", saleclashkind = "";
  2941. SqlRowList rs0;
  2942. if (fromcaller.equalsIgnoreCase("ProdInOut")) {
  2943. fromwhere = baseDao.getFieldDataByCondition("ProdInOut", "pi_class", "pi_id=" + fromid).toString();
  2944. } else if (fromcaller.equalsIgnoreCase("Sale") || fromcaller.equals("销售单")) {
  2945. fromwhere = "销售单";
  2946. } else {
  2947. return;
  2948. }
  2949. // 先更新呆冲销的明细已冲销数为0
  2950. SqlStr = "update saleforecastDetail set sd_stepqty=0 where sd_id in (select sd_id from saleforecastDetail ,saleforecast where sd_sfid=sf_id and sf_statuscode='AUDITED' and NVL(sd_statuscode,' ')<>'FINISH' and sd_qty>0) ";
  2951. baseDao.execute(SqlStr);
  2952. // 获取冲销来源单据
  2953. if (fromwhere.equals("出货单")) {
  2954. SqlStr = "select pd_id as sourcedetid,pd_inoutno as fromcode,pd_outqty+nvl(pd_beipinoutqty,0) as qty,pd_prodcode as prodcode,pd_ordercode as ordercode,pd_pdno as pdno,sd_forecastcode as sfcode,sd_forecastdetno as sfdetno from Prodiodetail left join saledetail on sd_code=pd_ordercode and sd_detno=pd_orderdetno where pd_piid='"
  2955. + fromid + "' ";
  2956. } else if (fromwhere.equals("销售单")) {
  2957. SqlStr = "select sd_id as sourcedetid,sd_code as fromcode,sd_qty as qty,sd_prodcode as prodcode,sa_code as ordercode,sd_detno as pdno,sd_forecastcode as sfcode,sd_forecastdetno as sfdetno,sa_custcode,sa_sellercode from saledetail,sale where sa_id=sd_said and sd_said='"
  2958. + fromid + "' ";
  2959. } else if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单")) {
  2960. SqlStr = "select pd_id as sourcedetid,pd_inoutno as fromcode,NVL(pd_inqty,0)+NVL(pd_outqty,0) as qty,pd_prodcode as prodcode,pd_ordercode as ordercode,pd_pdno as pdno,ma_salecode,ma_saledetno from Prodiodetail,warehouse,make,makekind where pd_piid='"
  2961. + fromid
  2962. + "' and pd_whcode=wh_code and NVL(wh_ifclash,0)<>0 and ma_code=pd_ordercode and ma_kind=mk_name and NVL(mk_clashsale,0)<>0 ";
  2963. // 判断是否存在需要完工入库冲销的预测
  2964. rs0 = baseDao.queryForRowSet("select sf_code from saleforecastkind where sf_clashoption='完工冲销' or sf_clashoption='FINISH' ");
  2965. if (!rs0.hasNext()) {
  2966. // 不需要完工冲销
  2967. return;
  2968. }
  2969. } else if (fromwhere.equals("销售拨出单")) {
  2970. SqlStr = "select pd_id as sourcedetid,pd_inoutno as fromcode,pd_outqty+nvl(pd_beipinoutqty,0) as qty,pd_prodcode as prodcode,pd_plancode as ordercode,pd_pdno as pdno,pd_plancode as sfcode,pd_forecastdetno as sfdetno from Prodiodetail where pd_piid='"
  2971. + fromid + "' and NVL(pd_plancode,' ')<>' ' and pd_forecastdetno>0 ";
  2972. } else if (fromwhere.equals("其它出库单")) {
  2973. SqlStr = "select pd_id as sourcedetid,pd_inoutno as fromcode,pd_outqty+nvl(pd_beipinoutqty,0) as qty,pd_prodcode as prodcode,pd_plancode as ordercode,pd_pdno as pdno,pd_plancode as sfcode,pd_forecastdetno as sfdetno from Prodiodetail where pd_piid='"
  2974. + fromid + "' and NVL(pd_plancode,' ')<>' ' and pd_forecastdetno>0 ";
  2975. } else {
  2976. return;
  2977. }
  2978. detno = 1;
  2979. SqlRowList rs = baseDao.queryForRowSet(SqlStr);
  2980. while (rs.next()) {
  2981. fromcode = rs.getString("fromcode");
  2982. clashoption = "";
  2983. saleclashkind = "";
  2984. othercondition = "";
  2985. clashedqty = 0;
  2986. needclashqty = rs.getDouble("qty");
  2987. prodcode = rs.getString("prodcode");
  2988. ordercode = rs.getString("ordercode");
  2989. // 判断此行记录是否需要冲销
  2990. canclash = "N";
  2991. if (fromwhere.equals("销售单") || fromwhere.equals("出货单")) {
  2992. if(fromwhere.equals("出货单") && baseDao.isDBSetting("ProdInOut!Sale", "clashSaleForecastByProduct")){
  2993. saleclashkind="PRODUCT";
  2994. clashoption = "SEND";
  2995. }else{
  2996. SqlStr = "SELECT * from sale left join salekind on (sa_kind=sk_name or sa_kind=sk_code) where sa_code='" + ordercode + "' ";
  2997. SqlRowList rs2 = baseDao.queryForRowSet(SqlStr);
  2998. if (rs2.next()) {
  2999. saleclashkind = rs2.getString("sk_clashfor");
  3000. clashoption = rs2.getString("sk_clashoption");
  3001. othercondition = rs2.getString("sk_clashkind");
  3002. } else {
  3003. // 未设置类型,不冲销
  3004. continue;
  3005. }
  3006. }
  3007. } else if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单")) {
  3008. saleclashkind = "PRODUCT";
  3009. clashoption = "FINISH";
  3010. } else if (fromwhere.equals("销售拨出单") || fromwhere.equals("其它出库单")) {
  3011. saleclashkind = "单号冲销";
  3012. clashoption = "SEND";
  3013. }
  3014. if (saleclashkind == null || clashoption == null) {
  3015. // 未设置类型,不冲销
  3016. continue;
  3017. }
  3018. if (fromwhere.equals("销售单")) {
  3019. if (clashoption.equals("订单冲销") || clashoption.equalsIgnoreCase("SALE")) {
  3020. canclash = "Y";
  3021. }
  3022. } else if (fromwhere.equals("出货单")) {
  3023. if (clashoption.equals("发货冲销") || clashoption.equalsIgnoreCase("SEND")) {
  3024. canclash = "Y";
  3025. }
  3026. }
  3027. if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单") || fromwhere.equals("销售拨出单")
  3028. || fromwhere.equals("其它出库单")) {
  3029. canclash = "Y";
  3030. }
  3031. if (canclash.equals("N")) {
  3032. // 不冲销
  3033. continue;
  3034. }
  3035. SqlStr = "";
  3036. if (saleclashkind.equalsIgnoreCase("sale") || saleclashkind.equals("单号冲销")) {
  3037. SqlStr = "SELECT saleforecastDetail.*,saleforecast.* from saleforecastDetail left join saleforecast on sd_sfid=sf_id left join saleforecastkind on (saleforecast.sf_kind=saleforecastkind.sf_name or saleforecast.sf_kind=saleforecastkind.sf_code) where saleforecast.sf_code='"
  3038. + rs.getString("sfcode") + "' and sd_detno=" + rs.getInt("sfdetno");
  3039. } else if (saleclashkind.equalsIgnoreCase("product") || saleclashkind.equals("料号冲销")) {
  3040. // 按物料号冲销
  3041. SqlStr = "SELECT saleforecastDetail.*,saleforecast.* from saleforecastDetail left join saleforecast on sd_sfid=sf_id left join saleforecastkind on (saleforecast.sf_kind=saleforecastkind.sf_name or saleforecast.sf_kind=saleforecastkind.sf_code) where sd_prodcode='"
  3042. + prodcode + "' ";
  3043. if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单")) {
  3044. SqlStr = "SELECT case when saleforecast.sf_code='"
  3045. + rs.getString("ma_salecode")
  3046. + "' and sd_detno="
  3047. + rs.getInt("ma_saledetno")
  3048. + " then 1 else 2 end sortid,saleforecastDetail.*,saleforecast.* from saleforecastDetail left join saleforecast on sd_sfid=sf_id left join saleforecastkind on (saleforecast.sf_kind=saleforecastkind.sf_name or saleforecast.sf_kind=saleforecastkind.sf_code) where sd_prodcode='"
  3049. + prodcode + "' ";
  3050. }
  3051. if (fromwhere.equals("销售单") && othercondition != null && othercondition.equals("客户匹配")) {
  3052. SqlStr = SqlStr + " and (case when NVL(saleforecastDetail.sd_custcode,' ')<>' ' then saleforecastDetail.sd_custcode else sf_custcode end)='" + rs.getString("sa_custcode") + "' ";
  3053. } else if (fromwhere.equals("销售单") && othercondition != null && othercondition.equals("业务员")){
  3054. SqlStr = SqlStr + " and (case when nvl(saleforecastDetail.sd_sellercode,' ')<>' ' then saleforecastDetail.sd_sellercode else sf_sellercode end)='"+ rs.getString("sa_sellercode")+"' ";
  3055. }
  3056. } else {
  3057. // 不冲销
  3058. continue;
  3059. }
  3060. if (clashoption.equals("订单冲销") || clashoption.equalsIgnoreCase("SALE")) {
  3061. SqlStr = SqlStr + " and sf_clashoption in ('SALE','订单冲销') ";
  3062. } else if (clashoption.equals("发货冲销") || clashoption.equalsIgnoreCase("SEND")) {
  3063. SqlStr = SqlStr + " and sf_clashoption in ('SEND','发货冲销') ";
  3064. } else if (clashoption.equals("完工冲销") || clashoption.equalsIgnoreCase("FINISH")) {
  3065. SqlStr = SqlStr + " and sf_clashoption in ('FINISH','完工冲销') ";
  3066. }
  3067. if (saleclashkind.equalsIgnoreCase("product") || saleclashkind.equals("料号冲销")) {
  3068. SqlStr = SqlStr + " and trunc(sd_enddate)>=trunc(sysdate) ";// 只冲销有效的预测,@update 20170224 截止日期等于今日的也可冲销,与存储过程中的计算一致
  3069. }
  3070. if (fromwhere.equals("委外验退单")) {
  3071. SqlStr = " SELECT saleforecastDetail.*,saleforecast.*,scd_id,NVL(scd_clashqty,0)scd_clashqty,NVL(scd_cancelqty,0)scd_cancelqty,scd_id from saleclashdetail left join saleclash on scd_scid=sc_id left join saleforecast on scd_ordercode=sf_code left join saleforecastdetail on sd_sfid=sf_id where sc_source='委外验收单' and scd_fromcode='"
  3072. + rs.getString("ordercode")
  3073. + "' and scd_clashqty>0 and scd_clashqty-NVL(scd_cancelqty,0)>0 and sc_statuscode='AUDITED' and sd_clashsaleqty>0 ";
  3074. }
  3075. if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单")) {
  3076. if (baseDao.isDBSetting("SaleForecast", "mappingSaleForecast")) {
  3077. SqlStr = SqlStr
  3078. + " and saleforecast.sf_code='"
  3079. + rs.getString("ma_salecode")
  3080. + "' and saleforecastdetail.sd_detno="
  3081. + rs.getInt("ma_saledetno")
  3082. + " and saleforecast.sf_statuscode='AUDITED' and sd_qty-nvl(sd_stepqty,0)>0 order by sortid,sd_needdate asc,sd_detno asc";
  3083. } else {
  3084. SqlStr = SqlStr
  3085. + " and saleforecast.sf_statuscode='AUDITED' and sd_qty-nvl(sd_stepqty,0)>0 order by sortid,sd_needdate asc,sd_detno asc";
  3086. }
  3087. } else if (fromwhere.equals("委外验退单")) {
  3088. // 委外验退条件特殊,上面已加
  3089. } else {
  3090. SqlStr = SqlStr
  3091. + " and saleforecast.sf_statuscode='AUDITED' and NVL(sd_statuscode,' ')<>'FINISH' and sd_qty-nvl(sd_stepqty,0)>0 order by sd_needdate asc,sd_detno asc";
  3092. }
  3093. if ("Y".equals(canclash) && !SqlStr.equals("")) {
  3094. SqlRowList rs2 = baseDao.queryForRowSet(SqlStr);
  3095. while (rs2.next() && clashedqty < needclashqty) {
  3096. double remain = rs2.getDouble("sd_qty") - rs2.getDouble("sd_stepqty");
  3097. int cancelsourceid = 0;
  3098. if (fromwhere.equals("委外验退单")) {
  3099. remain = (rs2.getDouble("scd_clashqty") - rs2.getDouble("scd_cancelqty"));// 拿冲销数反冲减预测
  3100. cancelsourceid = rs2.getInt("scd_id");
  3101. if (remain <= 0) {
  3102. continue;
  3103. }
  3104. }
  3105. thisqty = remain > needclashqty - clashedqty ? needclashqty - clashedqty : remain;
  3106. if (clashcode == "") {
  3107. clashcode = baseDao.sGetMaxNumber("SaleClash", 2);
  3108. csid = baseDao.getSeqId("SALECLASH_SEQ");
  3109. SqlStr = "insert into SaleClash(sc_id,sc_code,sc_date,sc_status,sc_statuscode,sc_recorder,sc_source,sc_sourceid,sc_sourcecode)values("
  3110. + csid
  3111. + ",'"
  3112. + clashcode
  3113. + "',sysdate,'已提交','COMMITED','"+employee.getEm_name()+"','" + fromwhere + "'," + fromid + ",'" + fromcode+ "') ";
  3114. baseDao.execute(SqlStr);
  3115. }
  3116. SqlStr = "insert into SaleClashDetail(scd_id,scd_scid,scd_detno,scd_prodcode,scd_clashqty,scd_ordercode,scd_orderdetno,scd_sourcedetid,scd_fromcode,scd_cancelid)values("
  3117. + "SALECLASHDETAIL_SEQ.NEXTVAL,"
  3118. + csid
  3119. + ",'"
  3120. + detno
  3121. + "','"
  3122. + prodcode
  3123. + "','"
  3124. + thisqty
  3125. + "','"
  3126. + rs2.getString("sf_code")
  3127. + "','"
  3128. + rs2.getInt("sd_detno")
  3129. + "',"
  3130. + rs.getInt("sourcedetid")
  3131. + ",'"
  3132. + rs.getString("ordercode") + "'," + cancelsourceid + ")";
  3133. baseDao.execute(SqlStr);
  3134. if (fromwhere.equals("委外验退单")) {
  3135. SqlStr = "UPDATE SaleClashDetail set scd_cancelqty=nvl(scd_cancelqty,0)+" + thisqty + " where scd_id="
  3136. + rs2.getInt("scd_id") + " ";
  3137. baseDao.execute(SqlStr);
  3138. }
  3139. SqlStr = "UPDATE saleforecastDetail set sd_stepqty=nvl(sd_stepqty,0)+(" + thisqty + ") where sd_id="
  3140. + rs2.getInt("sd_id") + " ";
  3141. baseDao.execute(SqlStr);
  3142. detno = detno + 1;
  3143. clashedqty = clashedqty + thisqty;
  3144. }
  3145. }
  3146. }
  3147. if (fromwhere.equals("委外验退单") && csid > 0) {
  3148. SqlStr = "UPDATE SaleClashDetail set scd_clashqty=0-scd_clashqty where scd_scid=" + csid + " ";
  3149. baseDao.execute(SqlStr);
  3150. }
  3151. if (!"".equals(clashcode)) {
  3152. // 审核冲销单
  3153. auditSaleClash(csid, "SaleClash",employee);
  3154. }
  3155. }
  3156. public String auditSaleClash(int sc_id, String caller,Employee employee) {
  3157. // 只能对状态为[已提交]的订单进行审核操作!
  3158. Object status = baseDao.getFieldDataByCondition("SaleClash", "sc_statuscode", "sc_id=" + sc_id);
  3159. if (!"AUDITED".equals(StringUtil.nvl(status, ""))){
  3160. return "只能对已提交的单据进行审核!";
  3161. }
  3162. String dets = baseDao
  3163. .getJdbcTemplate()
  3164. .queryForObject(
  3165. "select WM_CONCAT('预测单号:'||sf_code||',行号:'||sd_detno) from (select sf_code,sd_detno from SaleForecast left join SaleForecastDetail on sf_id=sd_sfid where (nvl(sd_statuscode,' ')<>'AUDITED' and not(sd_statuscode='COMMITED' and sf_statuscode='AUDITED')) and (sf_code,sd_detno) in (select scd_ordercode,scd_orderdetno from SaleClashDetail where scd_scid=?))",
  3166. String.class, sc_id);
  3167. if (dets != null) {
  3168. return "预测单号+预测行号状态不等于已审核,不允许已审核!" + dets;
  3169. }
  3170. // 执行审核操作
  3171. baseDao.audit("SaleClash", "sc_id=" + sc_id, "sc_status", "sc_statuscode", "sc_auditdate", "sc_auditman",employee);
  3172. Object source = baseDao.getFieldDataByCondition("SaleClash", "sc_source", "sc_id=" + sc_id);
  3173. // 冲销数量记录在预测单中
  3174. SqlRowList rs = baseDao
  3175. .queryForRowSet(
  3176. "select scd_ordercode,scd_orderdetno,sum(scd_clashqty) scd_clashqty from SaleClashDetail where scd_scid=? group by scd_ordercode,scd_orderdetno",
  3177. sc_id);
  3178. while (rs.next()) {
  3179. baseDao.updateByCondition("SaleForecastDetail", "sd_qty=sd_qty-(" + rs.getDouble("scd_clashqty")
  3180. + "),sd_clashsaleqty=nvl(sd_clashsaleqty,0)+" + rs.getDouble("scd_clashqty"), "sd_detno=" + rs.getInt("scd_orderdetno")
  3181. + " AND sd_sfid=(SELECT sf_id FROM SaleForecast WHERE sf_code='" + rs.getString("scd_ordercode") + "')");
  3182. if (source != null && source.equals("销售单") && rs.getGeneralDouble("scd_clashqty") > 0) {
  3183. baseDao.updateByCondition("SaleForecastDetail", "sd_yqty=(case when NVL(sd_yqty,0)-(" + rs.getDouble("scd_clashqty")
  3184. + ")<0 then 0 else sd_yqty-(" + rs.getDouble("scd_clashqty") + ") end)", "sd_detno=" + rs.getInt("scd_orderdetno")
  3185. + " AND sd_sfid=(SELECT sf_id FROM SaleForecast WHERE sf_code='" + rs.getString("scd_ordercode") + "')");
  3186. }
  3187. }
  3188. return null;
  3189. }
  3190. /*
  3191. * 拨出单过账后过账拨入单
  3192. */
  3193. public String turnProdIO(int id,Employee employee) {
  3194. String dets = null;
  3195. SqlRowList rs = baseDao.queryForRowSet("select pi_relativeplace,pi_class from prodinout where pi_id=?", id);
  3196. if (rs.next()) {
  3197. SqlRowList rs1 = baseDao.queryForRowSet(
  3198. "select pi_id from prodinout where pi_inoutno=? and pi_class in ('拨入单','销售拨入单') and nvl(PI_UNAUTOPOSTIN,0)=0",
  3199. rs.getString("pi_relativeplace"));
  3200. if (rs1.next()) {
  3201. if (baseDao.isDBSetting("sys","cgyCheck")) {
  3202. /**
  3203. * maz
  3204. * 出入库单判断过账人是否在明细行仓库的仓管员资料表中存在,人员资料中查找管理员一样限制如果为非仓库员不允许过账
  3205. * 虚拟账号不限制 2017080135
  3206. */
  3207. Object type = baseDao.getFieldDataByCondition("Employee", "em_code",
  3208. "em_code='"+employee.getEm_code()+"'");
  3209. if (type != null) {
  3210. dets = baseDao.getJdbcTemplate()
  3211. .queryForObject(
  3212. "select wm_concat(pd_pdno) from prodinout,prodiodetail where pi_id=pd_piid and pi_id=? and pd_id not in "
  3213. + "(select pd_id from prodinout,prodiodetail,warehouse,warehouseman where pi_id=pd_piid and pd_whcode=wh_code and wh_id=wm_whid "
  3214. + "and pi_id=? and wm_cgycode=?)", String.class, rs1.getInt("pi_id"),
  3215. rs1.getInt("pi_id"), employee.getEm_code());
  3216. }
  3217. }
  3218. if (dets == null) {
  3219. if ("拨出单".equals(rs.getString("pi_class"))) {
  3220. postProdInOut(rs1.getInt("pi_id"), "ProdInOut!AppropriationIn",employee);
  3221. } else if ("销售拨出单".equals(rs.getString("pi_class"))) {
  3222. postProdInOut(rs1.getInt("pi_id"), "ProdInOut!SaleAppropriationIn",employee);
  3223. }
  3224. }
  3225. }
  3226. }
  3227. return dets;
  3228. }
  3229. /**
  3230. * @author XiaoST 2016年8月25日 下午7:18:45 更新工单的完工状态,在完工入库,委外验收,验退过账,反过账时调用
  3231. */
  3232. public void updateMakeFinishStatus(Integer ma_id) {
  3233. baseDao.execute("update make set ma_madeqty=nvl((select sum(pd_inqty-pd_outqty) from prodiodetail where " +
  3234. "pd_ordercode=ma_code and pd_piclass in ('委外验收单','完工入库单','委外验退单') and pd_status>0),0) WHERE ma_id="
  3235. + ma_id);
  3236. baseDao.execute("update make set ma_finishstatuscode='COMPLETED',ma_finishstatus='已完工' where ma_id=" + ma_id + " and ma_madeqty>=ma_qty ");
  3237. baseDao.execute("update make set ma_finishstatuscode='PARTFI',ma_finishstatus='部分完工' where ma_id="
  3238. + ma_id + " and ma_madeqty>0 and ma_madeqty<ma_qty ");
  3239. baseDao.execute("update make set ma_finishstatuscode='UNCOMPLET',ma_finishstatus='未完工' where ma_id=" + ma_id + " and ma_madeqty=0 ");
  3240. }
  3241. private void changeMaStatus(int pi_id) {
  3242. String ids = baseDao
  3243. .getJdbcTemplate()
  3244. .queryForObject(
  3245. "select wm_concat(ma_id) from (select distinct ma_id from ProdIODetail left join make on ma_code=pd_ordercode where pd_piid=?)",
  3246. String.class, pi_id);
  3247. if (ids != null) {
  3248. updateMakeGetStatus(ids);
  3249. }
  3250. }
  3251. /**
  3252. * 修改工单领料状态
  3253. */
  3254. public void updateMakeGetStatus(String ids) {
  3255. baseDao.execute("update make set ma_turnstatuscode='UNGET',ma_turnstatus='未领料' where ma_id in ("
  3256. + ids + ") and not exists(select 1 from makematerial where mm_maid=ma_id and NVL(mm_havegetqty,0)+NVL(mm_totaluseqty,0)>0)");
  3257. baseDao.execute("update make set ma_turnstatuscode='PARTGET',ma_turnstatus='部分转领料' where ma_id in ("
  3258. + ids + ") and nvl(ma_turnstatuscode,' ')<>'PARTGET' and exists (select 1 from makematerial where mm_maid=ma_id "
  3259. + "and NVL(mm_havegetqty,0)+NVL(mm_totaluseqty,0)+NVL(mm_turnaddqty,0)>0 and NVL(mm_materialstatus,' ')=' ')");
  3260. baseDao.execute("update make set ma_turnstatuscode='TURNGET',ma_turnstatus='已转领料' where ma_id in ("
  3261. + ids + ") and nvl(ma_turnstatuscode,' ')<>'TURNGET' and not exists(select 1 from makematerial where mm_maid=ma_id "
  3262. + "and nvl(MM_QTY,0)-NVL(mm_havegetqty,0)-NVL(mm_totaluseqty,0)-NVL(mm_turnaddqty,0)>0 and NVL(mm_materialstatus,' ')=' ')");
  3263. }
  3264. private void refreshTurnQty(Integer ma_id, Integer mm_id) {
  3265. if (mm_id != null && mm_id > 0) {
  3266. // 已转领料数
  3267. baseDao.execute("update MakeMaterial set mm_totaluseqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout where pd_piid=pi_id and pd_status=0 and pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_piclass in ('生产领料单', '委外领料单')) WHERE mm_maid="
  3268. + ma_id + " and mm_id=" + mm_id);
  3269. // 转补料数
  3270. baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  3271. + "where pd_piid=pi_id and pi_statuscode<>'DELETE' and pd_status=0 and pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_piclass in ('生产补料单', '委外补料单')) where mm_maid ="
  3272. + ma_id + " and mm_id=" + mm_id);
  3273. // 更新替代已转数
  3274. baseDao.execute("update makematerialreplace set mp_repqty=(select NVL(sum(nvl(pd_outqty,0)),0) from prodiodetail,prodinout "
  3275. + "where pd_piid=pi_id and pd_status=0 and pd_prodcode=mp_prodcode and pd_ordercode=mp_mmcode and "
  3276. + "pd_orderdetno=mp_mmdetno and pd_piclass in ('生产领料单', '委外领料单')) where mp_maid=" + ma_id + " and mp_mmid=" + mm_id);
  3277. baseDao.execute("update makematerialreplace set mp_repqty=0 where mp_maid=" + ma_id + " AND MP_REPQTY<0");
  3278. // 更新替代总已转数
  3279. baseDao.execute("update MakeMaterial set mm_repqty=NVL((select sum(NVL(mp_repqty,0)) from MakeMaterialreplace where mp_mmid=mm_id),0) where mm_maid="
  3280. + ma_id + " and mm_id=" + mm_id);
  3281. // 更新替代总已领数
  3282. baseDao.execute("update MakeMaterial set mm_haverepqty=NVL((select sum(NVL(mp_haverepqty,0)) from MakeMaterialreplace where mp_mmid=mm_id),0) where mm_maid="
  3283. + ma_id + " and mm_id=" + mm_id);
  3284. } else {
  3285. // 已转领料数
  3286. baseDao.execute("update MakeMaterial set mm_totaluseqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  3287. + "where pd_piid=pi_id and pd_status=0 and pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_piclass in ('生产领料单', '委外领料单')) WHERE mm_maid="
  3288. + ma_id);
  3289. // 转补料数
  3290. baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  3291. + "where pd_piid=pi_id and pi_statuscode<>'DELETE' and pd_status=0 and pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_piclass in ('生产补料单', '委外补料单')) where mm_maid ="
  3292. + ma_id);
  3293. // 更新替代已转数
  3294. baseDao.execute("update makematerialreplace set mp_repqty=(select NVL(sum(nvl(pd_outqty,0)),0) from prodiodetail,prodinout "
  3295. + "where pd_piid=pi_id and pd_status=0 and pd_prodcode=mp_prodcode and pd_ordercode=mp_mmcode and "
  3296. + "pd_orderdetno=mp_mmdetno and pd_piclass in ('生产领料单', '委外领料单')) where mp_maid=" + ma_id);
  3297. baseDao.execute("update makematerialreplace set mp_repqty=0 where mp_maid=" + ma_id + " AND MP_REPQTY<0");
  3298. // 更新替代总已转数
  3299. baseDao.execute("update MakeMaterial set mm_repqty=NVL((select sum(NVL(mp_repqty,0)) from MakeMaterialreplace where mp_mmid=mm_id),0) where mm_maid="
  3300. + ma_id);
  3301. // 更新替代总已领数
  3302. baseDao.execute("update MakeMaterial set mm_haverepqty=NVL((select sum(NVL(mp_haverepqty,0)) from MakeMaterialreplace where mp_mmid=mm_id),0) where mm_maid="
  3303. + ma_id);
  3304. }
  3305. }
  3306. private void setBackQty(String maidstr, Integer mm_id) {
  3307. if (mm_id != null && mm_id > 0) {
  3308. baseDao.getJdbcTemplate()
  3309. .execute(
  3310. "update makematerial set mm_backqty=(select sum(pd_inqty) from prodiodetail where pd_piclass in ('生产退料单','委外退料单') and pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_status=0) WHERE mm_maid in ("
  3311. + maidstr + ") and mm_id=" + mm_id);
  3312. baseDao.getJdbcTemplate()
  3313. .execute(
  3314. "update MakeMaterialreplace set mp_backqty=(select sum(pd_inqty) from prodiodetail where pd_piclass in ('生产退料单','委外退料单') and pd_ordercode=mp_mmcode and pd_orderdetno=mp_mmdetno and pd_prodcode=mp_prodcode and pd_status=0) WHERE mp_maid in ("
  3315. + maidstr + ") and mp_mmid=" + mm_id);
  3316. baseDao.getJdbcTemplate()
  3317. .execute(
  3318. "update makematerial set mm_turnscrapqty=(select sum(md_qty) from makescrapdetail,makescrap where ms_id=md_msid and ms_statuscode<>'AUDITED' and md_mmcode=mm_code and md_mmdetno=mm_detno ) WHERE mm_maid in ("
  3319. + maidstr + ") and mm_id=" + mm_id);
  3320. baseDao.getJdbcTemplate()
  3321. .execute(
  3322. "update MakeMaterialreplace set mp_turnscrapqty=(select sum(md_qty) from makescrapdetail,makescrap where ms_id=md_msid and ms_statuscode<>'AUDITED' and md_mmcode=mp_mmcode and md_mmdetno=mp_mmdetno ) WHERE mp_maid in ("
  3323. + maidstr + ") and mp_mmid=" + mm_id);
  3324. } else {
  3325. baseDao.getJdbcTemplate()
  3326. .execute(
  3327. "update makematerial set mm_backqty=(select sum(pd_inqty) from prodiodetail where pd_piclass in ('生产退料单','委外退料单') and pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_status=0) WHERE mm_maid in ("
  3328. + maidstr + ")");
  3329. baseDao.getJdbcTemplate()
  3330. .execute(
  3331. "update MakeMaterialreplace set mp_backqty=(select sum(pd_inqty) from prodiodetail where pd_piclass in ('生产退料单','委外退料单') and pd_ordercode=mp_mmcode and pd_orderdetno=mp_mmdetno and pd_prodcode=mp_prodcode and pd_status=0) WHERE mp_maid in ("
  3332. + maidstr + ")");
  3333. baseDao.getJdbcTemplate()
  3334. .execute(
  3335. "update makematerial set mm_turnscrapqty=(select sum(md_qty) from makescrapdetail,makescrap where ms_id=md_msid and ms_statuscode<>'AUDITED' and md_mmcode=mm_code and md_mmdetno=mm_detno ) WHERE mm_maid in ("
  3336. + maidstr + ")");
  3337. baseDao.getJdbcTemplate()
  3338. .execute(
  3339. "update MakeMaterialreplace set mp_turnscrapqty=(select sum(md_qty) from makescrapdetail,makescrap where ms_id=md_msid and ms_statuscode<>'AUDITED' and md_mmcode=mp_mmcode and md_mmdetno=mp_mmdetno ) WHERE mp_maid in ("
  3340. + maidstr + ")");
  3341. }
  3342. }
  3343. }