MESServiceImpl.java 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341
  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.Employee;
  10. import com.uas.eis.entity.VerifyApply;
  11. import com.uas.eis.entity.VerifyApplyDetail;
  12. import com.uas.eis.sdk.entity.ApiResult;
  13. import com.uas.eis.sdk.resp.ApiResponse;
  14. import com.uas.eis.service.MESService;
  15. import com.uas.eis.utils.*;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import javax.servlet.http.HttpServletRequest;
  23. import java.io.IOException;
  24. import java.util.*;
  25. /**
  26. * @author koul
  27. * @email koul@usoftchina.com
  28. * @date 2021-12-08 9:32
  29. */
  30. @Service
  31. public class MESServiceImpl implements MESService {
  32. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  33. @Autowired
  34. private BaseDao baseDao;
  35. @Autowired
  36. private TransferRepository transferRepository;
  37. @Override
  38. public ApiResult<String> checkVerifyApply(HttpServletRequest request) {
  39. String requestId = request.getHeader("RequestId");
  40. JSONObject jsonData = getJsonData(request);
  41. String mesCode = StringUtil.nvl(jsonData.get("mesCode"), "");
  42. if ("".equals(mesCode)){
  43. return ApiResponse.failRsp("10011",requestId,"MES编号不能为空!");
  44. }
  45. 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 'HS' 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=?",
  46. new BeanPropertyRowMapper<VerifyApply>(VerifyApply.class), mesCode);
  47. if (verifyApply==null) {
  48. return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
  49. }
  50. SqlRowList rs = baseDao.queryForRowSet("select case when va_custcode='AR214' or nvl(va_custcode,' ')=' ' then 'HS' 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+"'");
  51. if (rs.next()){
  52. verifyApply.setVa_custcode(rs.getString("cu_code"));
  53. }
  54. 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 'HS' 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);
  55. verifyApply.setDetail(verifyApplyDetails);
  56. String s = JSON.toJSONString(verifyApply, SerializerFeature.WriteMapNullValue);
  57. return ApiResponse.successRsp("0","获取成功!",requestId,s);
  58. }
  59. @Override
  60. public ApiResult<String> purcCheckin(HttpServletRequest request) {
  61. String requestId = request.getHeader("RequestId");
  62. Map<String, JSONArray> data = getData(request);
  63. JSONArray jsonArray = data.get("main");
  64. Object vaid=0;
  65. String caller="VerifyApply!ToOtherIn";
  66. String type="其它入库单";
  67. String djcaller="ProdInOut!OtherIn";
  68. String sellerName="";
  69. String whcode="";
  70. for (int i = 0; i <jsonArray.size() ; i++) {
  71. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  72. String mesCode = StringUtil.nvl(jsonObject.get("mesCode"),"");
  73. whcode= StringUtil.nvl(jsonObject.get("whNo"), "");
  74. if ("".equals(mesCode)){
  75. return ApiResponse.failRsp("10011",requestId,"ERP单据编号不能为空!");
  76. }
  77. int count = baseDao.getCountByCondition("verifyApply", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
  78. if (count<1){
  79. return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
  80. }
  81. vaid = baseDao.getFieldDataByCondition("verifyApply", "va_id", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
  82. String vaClass = StringUtil.nvl(baseDao.getFieldDataByCondition("VerifyApply", "va_class", "va_id=" + vaid), "");
  83. if ("委外收料单".equals(vaClass)) {
  84. caller = "VerifyApply!ToOutsideCheckIn";
  85. type = "委外验收单";
  86. djcaller = "ProdInOut!OutsideCheckIn";
  87. }else if("采购收料单".equals(vaClass)){
  88. int count1 = baseDao.getCount("select count(1) from VerifyApplyDetail where nvl(vad_pucode,' ')<>' ' and vad_vaid=" + vaid);
  89. if (count1 > 0) {
  90. caller = "VerifyApply!ToPurcIn";
  91. type = "采购验收单";
  92. djcaller = "ProdInOut!PurcCheckin";
  93. }
  94. }
  95. //判断已转数
  96. 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);
  97. if(chekQty !=null){
  98. return ApiResponse.failRsp("10013",requestId,"检测到" + chekQty + ",本次数量超出可转数量!");
  99. }
  100. if ("VerifyApply!ToPurcIn".equals(caller)) {
  101. // 判断该收料单是否已经转入过采购验收单
  102. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  103. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and " + "PI_REFNO='采购收料单' and pi_class='采购验收单'");
  104. if (code != null && !code.equals("")) {
  105. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过采购验收单,验收单号[" + code + "]");
  106. }
  107. }
  108. if ("VerifyApply!ToOtherIn".equals(caller)) {
  109. // 判断该收料单是否已经转入过其它入库单
  110. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  111. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='其它入库单'");
  112. if (code != null && !code.equals("")) {
  113. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过其它入库单,单号[" + code + "]");
  114. }
  115. }
  116. if ("VerifyApply!ToOutsideCheckIn".equals(caller)) {
  117. // 判断该收料单是否已经转入过委外验收单
  118. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  119. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='委外验收单'");
  120. if (code != null && !code.equals("")) {
  121. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过委外验收单,单号[" + code + "]");
  122. }
  123. }
  124. sellerName = StringUtil.nvl(jsonObject.get("sellerName"), "mes");
  125. }
  126. JSONArray array = data.get("detail");
  127. for (int i = 0; i <array.size() ; i++) {
  128. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  129. String itemNo = StringUtil.nvl(json.get("itemNo"), "");
  130. Double qty = Double.parseDouble(StringUtil.nvl(json.get("qty"), "0"));
  131. Double vadQty = baseDao.getSummaryByField("verifyapplydetail", "vad_qty", "vad_prodcode='" + itemNo + "' and vad_vaid=" + vaid);
  132. int compare = qty.compareTo(vadQty);
  133. if (compare>0){
  134. return ApiResponse.failRsp("10017",requestId, "物料:"+itemNo+",收料数量:"+qty+"超出ERP收料单数量:"+vadQty+ ",不允许入库!");
  135. }
  136. if (compare<0){
  137. return ApiResponse.failRsp("10018",requestId,"物料:"+itemNo+",收料数量:"+qty+"少于ERP收料单数量:"+vadQty+",不允许入库!");
  138. }
  139. }
  140. if ("".equals(whcode)){
  141. return ApiResponse.failRsp("10015",requestId,"MES仓库编号不能为空!");
  142. }
  143. 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 + "'");
  144. if (coun<=0){
  145. return ApiResponse.failRsp("10016",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  146. }
  147. 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 + "'");
  148. int piid =0;
  149. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_name=?",
  150. new BeanPropertyRowMapper<Employee>(Employee.class), sellerName);
  151. // 转采购验收单
  152. Key key = transferRepository.transfer(caller, vaid,employee);
  153. piid = key.getId();
  154. // 转入明细
  155. transferRepository.transferDetail(caller, vaid, key,employee);
  156. if (piid != 0) {
  157. baseDao.execute("delete from prodiodetail where nvl(pd_inqty,0)<=0 and pd_piid="+piid);
  158. baseDao.updateByCondition("prodiodetail", "pd_whcode='"+warehouses[0]+"',pd_whname='"+warehouses[1]+"'", "pd_piid=" + piid);
  159. baseDao.updateByCondition("prodinout", "pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"'", "pi_id=" + piid);
  160. baseDao.execute("update prodiodetail set pd_prodid=(select pr_id from product where pd_prodcode=pr_code) where pd_piid=" + piid
  161. + " and nvl(pd_prodcode,' ')<>' '");
  162. baseDao.execute("update prodiodetail set pd_whid=(select wh_id from warehouse where wh_code=pd_whcode) where pd_piid=" + piid
  163. + " and nvl(pd_whcode,' ')<>' '");
  164. baseDao.updateByCondition("ProdInOut",
  165. "pi_total=(SELECT round(sum(nvl(pd_orderprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid="
  166. + piid + ")", "pi_id=" + piid);
  167. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + piid);
  168. if ("VerifyApply!ToPurcIn".equals(caller)) {
  169. baseDao.execute("Insert into ProdChargeDetail(pd_id,pd_piid,pd_detno,pd_type,pd_amount,pd_currency,pd_rate) "
  170. + "select ProdChargeDetail_seq.nextval, " + piid + ", pd_detno, pd_type,pd_amount,pd_currency,pd_rate "
  171. + "from ProdChargeDetailAN where PD_ANID=" + vaid);
  172. SqlRowList rs = baseDao.queryForRowSet("select vad_pucode,vad_pudetno,vad_qty from VerifyApplyDetail where vad_vaid=" + vaid);
  173. String pCode = null;
  174. int pDetno = 0;
  175. double yq = 0;
  176. Set<String> pCodes = new HashSet<String>();
  177. while (rs.next()) {
  178. pCode = rs.getString("vad_pucode");
  179. if (!pCodes.contains(pCode)) {
  180. pCodes.add(pCode);
  181. }
  182. pDetno = rs.getInt("vad_pudetno");
  183. yq = rs.getDouble("vad_qty");
  184. baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno);
  185. baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno
  186. + " and pd_qty=" + yq);
  187. }
  188. Iterator<String> iter = pCodes.iterator();
  189. while (iter.hasNext()) {
  190. pCode = iter.next();
  191. int total = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "'");
  192. int aud = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "' AND nvl(pd_acceptqty,0)=0");
  193. int turn = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode
  194. + "' AND nvl(pd_acceptqty,0)=nvl(pd_qty,0)");
  195. String statuscode = aud == total ? "" : (turn == total ? "TURNIN" : "PART2IN");
  196. String status = aud == total ? "" : (turn == total ? "已入库" : "部分入库");
  197. baseDao.updateByCondition("Purchase",
  198. "pu_turnstatuscode='" + statuscode + "',pu_turnstatus='" + status + "'", "pu_code='" + pCode + "'");
  199. }
  200. }
  201. // 修改收料状态
  202. baseDao.updateByCondition("VerifyApplyDetail", "vad_yqty=vad_qty", "vad_vaid=" + vaid);
  203. baseDao.updateByCondition("VerifyApply", "va_turnstatuscode='TURNIN',va_turnstatus='已入库'", "va_id=" + vaid);
  204. String s = postProdInOut(piid, djcaller, employee);
  205. logger.info("收料单入库=="+s);
  206. if (s!=null){
  207. return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",过账失败,请在ERP重新过账!");
  208. }
  209. return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",请在ERP查看!");
  210. }
  211. return ApiResponse.failRsp("10019",requestId,"ERP生成单据失败!");
  212. }
  213. @Override
  214. public ApiResult<String> prodInOutMakeIn(HttpServletRequest request) {
  215. String requestId = request.getHeader("RequestId");
  216. Map<String, JSONArray> data = getData(request);
  217. JSONArray jsonArray = data.get("main");
  218. String ma_tasktype="";
  219. int piid=0;
  220. String picode="";
  221. String piclass="完工入库单";
  222. String picaller="ProdInOut!Make!In";
  223. int ma_id=0;
  224. List<String> sqls = new ArrayList<>();
  225. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  226. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  227. JSONArray array = data.get("detail");
  228. if(array!=null&&array.size()>0) {
  229. for (int i = 0; i < array.size(); i++) {
  230. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  231. String macode = StringUtil.nvl(json.get("FICMOBillNo"),"");
  232. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
  233. if (data1 != null && data1.length > 0) {
  234. ma_tasktype = StringUtil.nvl(data1[0], "");
  235. ma_id = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  236. } else {
  237. return ApiResponse.failRsp("10077", requestId, "工单在ERP不存在,请核对!");
  238. }
  239. /*float fauxqty = json.get("Fauxqty") == null ? 0 : Float.parseFloat(json.get("Fauxqty").toString());
  240. String msg = baseDao.callProcedure("USER_WGRKCHECK", new Object[]{ma_id, fauxqty});
  241. if (msg != null && !msg.trim().equals("")){
  242. return ApiResponse.failRsp("10078",requestId,msg);
  243. }*/
  244. }
  245. }
  246. if ("OS".equals(ma_tasktype)) {
  247. picaller = "ProdInOut!OutsideCheckIn";
  248. piclass = "委外验收单";
  249. }
  250. for (int i = 0; i <jsonArray.size() ; i++) {
  251. Object obj = jsonArray.get(i);
  252. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(obj, ""));
  253. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  254. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
  255. if (result!=null){
  256. return result;
  257. }
  258. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDCStockID")));
  259. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  260. Map<Object, Object> map6 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  261. Map<Object, Object> map7 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  262. Map<Object, Object> map8 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  263. String whcode = StringUtil.nvl(map4.get("FNumber"), "");
  264. if ("".equals(whcode)) {
  265. return ApiResponse.failRsp("10073", requestId, "MES仓库编号不能为空!");
  266. }
  267. 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 + "'");
  268. if (count <= 0) {
  269. return ApiResponse.failRsp("10074", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  270. }
  271. 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 + "'");
  272. if ("OS".equals(ma_tasktype)) {
  273. // 转入委外验收单主记录
  274. piid = baseDao.getSeqId("PRODINOUT_SEQ");
  275. picode = baseDao.sGetMaxNumber(picaller, 2);
  276. 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) " +
  277. "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+"')");
  278. sqls.add("update prodinout set (pi_cardcode,pi_title,pi_currency,pi_rate,pi_receivecode," +
  279. "pi_receivename,pi_cardid,pi_paymentcode,pi_payment,pi_cop,pi_belongs," +
  280. "pi_sourcecode,pi_sellercode)=(select ma_vendcode,ma_vendname,ma_currency,ma_rate,ve_apvendcode," +
  281. "ve_apvendname,ve_id,ma_paymentscode,ma_payments,ma_cop,ve_buyername,ma_code,em_code from make left " +
  282. "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);
  283. sqls.add("update ProdinOut set pi_sellername=pi_belongs where pi_class='"+piclass+"' and pi_id=" + piid);
  284. 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");
  285. } else {
  286. piid = baseDao.getSeqId("PRODINOUT_SEQ");
  287. picode = baseDao.sGetMaxNumber(picaller, 2);
  288. 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) " +
  289. "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+"')");
  290. }
  291. }
  292. int detno=1;
  293. for (int i = 0; i <array.size(); i++) {
  294. Object obj = array.get(i);
  295. JSONObject jsonObject3 = JSON.parseObject(StringUtil.nvl(obj, ""));
  296. Map<Object, Object> map11 = JSONUtil.toMap(StringUtil.valueOf(jsonObject3.get("FItemID")));
  297. Map<Object, Object> map12 = JSONUtil.toMap(StringUtil.valueOf(jsonObject3.get("FDCStockID1")));
  298. String whcode = StringUtil.nvl(map12.get("FNumber"), "");
  299. if ("".equals(whcode)){
  300. return ApiResponse.failRsp("10075",requestId,"MES仓库编号不能为空!");
  301. }
  302. 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 + "'");
  303. if (count<=0){
  304. return ApiResponse.failRsp("10076",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  305. }
  306. 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 + "'");
  307. String fBatchNo = StringUtil.nvl(jsonObject3.get("FBatchNo"), "");
  308. float fauxqty = jsonObject3.get("Fauxqty") == null ? 0 : Float.parseFloat(jsonObject3.get("Fauxqty").toString());
  309. String fSecUnitID = StringUtil.nvl(jsonObject3.get("FSecUnitID"), "");
  310. float fSecCoefficient = jsonObject3.get("FSecCoefficient") == null ? 0 : Float.parseFloat(jsonObject3.get("FSecCoefficient").toString());
  311. float fSecQty = jsonObject3.get("FSecQty") == null ? 0 : Float.parseFloat(jsonObject3.get("FSecQty").toString());
  312. float fAuxPlanPrice = jsonObject3.get("FAuxPlanPrice") == null ? 0 : Float.parseFloat(jsonObject3.get("FAuxPlanPrice").toString());
  313. float fPlanAmount = jsonObject3.get("FPlanAmount") == null ? 0 : Float.parseFloat(jsonObject3.get("FPlanAmount").toString());
  314. float fauxprice = jsonObject3.get("Fauxprice") == null ? 0 : Float.parseFloat(jsonObject3.get("Fauxprice").toString());
  315. float famount = jsonObject3.get("Famount") == null ? 0 : Float.parseFloat(jsonObject3.get("Famount").toString());
  316. String fnote = StringUtil.nvl(jsonObject3.get("Fnote"), "");
  317. String fKFDate = StringUtil.nvl(jsonObject3.get("FKFDate"), "");
  318. String fPeriodDate = StringUtil.nvl(jsonObject3.get("FPeriodDate"), "");
  319. int fDCSPID = jsonObject3.get("FDCSPID") == null ? 0 : Integer.parseInt(jsonObject3.get("FDCSPID").toString());
  320. Object location="";
  321. if (fDCSPID>0){
  322. location = baseDao.getFieldDataByCondition("ProductLocation", "pl_name", "pl_id=" + fDCSPID);
  323. }
  324. String fSourceBillNo = StringUtil.nvl(jsonObject3.get("FSourceBillNo"), "");
  325. String fICMOBillNo = StringUtil.nvl(jsonObject3.get("FICMOBillNo"), "");
  326. String fEntrySelfA0248 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0248"), "");
  327. String fEntrySelfA0245 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0245"), "");
  328. String fEntrySelfA0246 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0246"), "");
  329. String fEntrySelfA0247 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0247"), "0");
  330. String fEntrySelfA0242 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0242"), "0");
  331. if ("OS".equals(ma_tasktype)) {
  332. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_ordercode,pd_prodcode," +
  333. "pd_batchcode,pd_inqty,pd_nxlh,pd_purcrate,pd_notinqty,pd_orderprice,pd_ordertotal,pd_price," +
  334. "pd_total,pd_whcode,pd_whname,pd_remark,pd_prodmadedate,pd_replydate,pd_location,pd_macode,pd_xb," +
  335. "pd_bz,pd_dbds,pd_zds,pd_status) values (PRODIODETAIL_SEQ.nextval," + piid + ",'" + picode + "','"+piclass+
  336. "'," + detno + ",'" + fSourceBillNo +
  337. "','" + map11.get("FNumber") + "','" + fBatchNo + "'," + fauxqty + ",'" + fSecUnitID + "'," + fSecCoefficient + "," + fSecQty + "," + fAuxPlanPrice + "," + fPlanAmount + "," + fauxprice + "," +
  338. "" + famount + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + fnote + "',to_date('" + fEntrySelfA0248 + "'," +
  339. "'yyyy-MM-dd HH24:mi:ss'),to_date('" + fPeriodDate + "','yyyy-MM-dd HH24:mi:ss'),'" + location + "','" + fICMOBillNo + "','" + fEntrySelfA0246 + "','" + fEntrySelfA0245 + "'," + fEntrySelfA0247 + "," + fEntrySelfA0242 + ",0)");
  340. detno++;
  341. }else {
  342. sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_ordercode,pd_prodcode," +
  343. "pd_batchcode,pd_inqty,pd_nxlh,pd_purcrate,pd_notinqty,pd_orderprice,pd_ordertotal,pd_price," +
  344. "pd_total,pd_whcode,pd_whname,pd_remark,pd_prodmadedate,pd_replydate,pd_location,pd_macode,pd_xb," +
  345. "pd_bz,pd_dbds,pd_zds,pd_status) values (PRODIODETAIL_SEQ.nextval," + piid + ",'" + picode + "','"+piclass+
  346. "'," + detno + ",'" + fSourceBillNo +
  347. "','" + map11.get("FNumber") + "','" + fBatchNo + "'," + fauxqty + ",'" + fSecUnitID + "'," + fSecCoefficient + "," + fSecQty + "," + fAuxPlanPrice + "," + fPlanAmount + "," + fauxprice + "," +
  348. "" + famount + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + fnote + "',to_date('" + fEntrySelfA0248 + "'," +
  349. "'yyyy-MM-dd HH24:mi:ss'),to_date('" + fPeriodDate + "','yyyy-MM-dd HH24:mi:ss'),'" + location + "','" + fICMOBillNo + "','" + fEntrySelfA0246 + "','" + fEntrySelfA0245 + "'," + fEntrySelfA0247 + "," + fEntrySelfA0242 + ",0)");
  350. detno++;
  351. }
  352. }
  353. if ("OS".equals(ma_tasktype)) {
  354. sqls.add("update prodiodetail set (pd_location,pd_orderprice,pd_taxrate,pd_prodid,pd_orderid,pd_wccode)=" +
  355. "(select pr_location,ma_price,ma_taxrate,pr_id,ma_id,ma_wccode from make left join Product on " +
  356. "ma_prodcode=pr_code where ma_id="+ma_id+") where pd_piid="+piid);
  357. sqls.add("update Prodiodetail set pd_whname=(select wh_description from warehouse where pd_whcode=wh_code) where pd_piid="
  358. + piid);
  359. sqls.add("update Prodiodetail set pd_total=round(pd_inqty*pd_orderprice,2) where pd_piid=" + piid);
  360. }
  361. //更新已转完工数
  362. 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);
  363. sqls.add("update make set ma_tomadeqty=ma_madeqty where ma_id=" + ma_id + " and nvl(ma_madeqty,0)>nvl(ma_tomadeqty,0)");
  364. //更新最大套料数
  365. 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 + ") ");
  366. sqls.add("update make set ma_canmadeqty=ma_qty where ma_id in (" + ma_id
  367. + ") and ma_id not in (select ma_id from make left join makematerial on ma_id=mm_maid where ma_id in (" + ma_id
  368. + ") and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0 and mm_oneuseqty*ma_qty<=mm_qty+0.1)");
  369. sqls.add("update make set ma_canmadeqty=0 where ma_id in (" + ma_id + ") and NVL(ma_canmadeqty,0)<=0");
  370. baseDao.execute(sqls);
  371. if(!baseDao.isDBSetting(picaller,"AllowPost")){
  372. return ApiResponse.successRsp("0",requestId,piclass+":"+picode+",请在ERP查看并手工过账!");
  373. }
  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. String sourcetype="制造单";
  413. List<String> sqls = new ArrayList<>();
  414. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  415. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  416. for (int i = 0; i <jsonArray.size() ; i++) {
  417. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  418. String fSelBillNo = StringUtil.nvl(jsonObject.get("FSelBillNo"), "");
  419. if ("".equals(fSelBillNo)){
  420. return ApiResponse.failRsp("10029", requestId, "MES单号不能为空!");
  421. }
  422. String prodNo = StringUtil.nvl(jsonObject.get("prodNo"), "");
  423. if ("".equals(prodNo)){
  424. return ApiResponse.failRsp("10023",requestId,"工单单号不能为空!");
  425. }
  426. String ma_tasktype = StringUtil.nvl(baseDao.getFieldDataByCondition("make", "ma_tasktype", "ma_code='" + prodNo + "'"), "");
  427. if ("OS".equals(ma_tasktype)) {
  428. msclass = "委外报废单";
  429. caller = "MakeScrap!Make";
  430. sourcetype="委外加工单";
  431. }
  432. int count = baseDao.getCount("select count(1) from MakeScrap where ms_class='" + msclass + "' and ms_mescode='" + fSelBillNo + "'");
  433. if (count>0){
  434. Object co = baseDao.getFieldDataByCondition("MakeScrap", "ms_code", "ms_class='" + msclass + "' and ms_mescode='" + fSelBillNo + "'");
  435. return ApiResponse.failRsp("10024",requestId,"MES单号:"+fSelBillNo+"已存在,请在ERP查看"+msclass+",单据编号:"+co);
  436. }
  437. //临时逻辑 工单结案直接返回成功
  438. if (baseDao.isDBSetting("MakeScrap","overSuccess")) {
  439. int condition = baseDao.getCountByCondition("make", "ma_statuscode='FINISH' and ma_code='" + prodNo + "'");
  440. if (condition > 0) {
  441. return ApiResponse.successRsp("0", requestId, "工单【" + prodNo + "】已结案,请在ERP查看!");
  442. }
  443. }
  444. id = baseDao.getSeqId("MAKESCRAP_SEQ");
  445. code = baseDao.sGetMaxNumber(caller, 2);
  446. String fdateTime = StringUtil.nvl(jsonObject.get("FdateTime"), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
  447. String fwcCode = StringUtil.nvl(jsonObject.get("FwcCode"), "");
  448. if ("".equals(fwcCode)) {
  449. return ApiResponse.failRsp("10021", requestId, "工作中心不能为空!");
  450. }
  451. String createdUser = StringUtil.nvl(jsonObject.get("createdUser"), employee.getEm_name());
  452. String createdDateTime = StringUtil.nvl(jsonObject.get("createdDateTime"), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
  453. String companyNo = StringUtil.nvl(jsonObject.get("companyNo"), "BYT");
  454. String fremark = StringUtil.nvl(jsonObject.get("Fremark"), "");
  455. 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,ms_sourcetype,ms_sourcecode) values (" + id + ",'" + code + "','"+msclass+ "','COMMITED','已提交','UNPRINT','未打印',to_date('" + fdateTime + "','yyyy-MM-dd HH24:mi:ss'),'" + fwcCode + "','" + createdUser + "',to_date('" + createdDateTime + "','yyyy-MM-dd HH24:mi:ss'),'" + companyNo + "','" + fremark + "','"+fSelBillNo+"','"+sourcetype+"','"+prodNo+"')");
  456. }
  457. JSONArray array = data.get("detail");
  458. int detno=1;
  459. String fDeptID=null;
  460. String fDept=null;
  461. for (int i = 0; i <array.size(); i++) {
  462. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  463. String lineId = StringUtil.nvl(object.get("lineId"), "");
  464. if ("".equals(lineId)){
  465. return ApiResponse.failRsp("10022",requestId,"工单明细ID不能为空!");
  466. }
  467. Object mmdetno = baseDao.getFieldDataByCondition("MakeMaterial", "mm_detno", "mm_id in (" + lineId+")");
  468. String prodNo = StringUtil.nvl(object.get("prodNo"), "");
  469. if ("".equals(prodNo)){
  470. return ApiResponse.failRsp("10023",requestId,"工单单号不能为空!");
  471. }
  472. String itemNo = StringUtil.nvl(object.get("itemNo"), "");
  473. if ("".equals(itemNo)){
  474. return ApiResponse.failRsp("10024",requestId,"物料不能为空!");
  475. }
  476. double qty = Double.parseDouble(StringUtil.nvl(object.get("qty"), "0"));
  477. if (qty==0){
  478. return ApiResponse.failRsp("10025",requestId,"报废数量不能为空!");
  479. }
  480. //临时逻辑 重新计算报废数量
  481. //int coun = baseDao.getCountByCondition("make", "ma_code='" + prodNo + "' and to_char(ma_date,'yyyyMM')<'202212'");
  482. if (baseDao.isDBSetting("MakeScrap","overQtySuccess")) {
  483. double mmqty = Double.parseDouble(StringUtil.nvl(baseDao.getFieldDataByCondition("makematerial left join make on mm_maid=ma_id", "nvl(mm_havegetqty,0)-nvl(mm_returnmqty,0)+nvl(mm_addqty,0)+nvl(mm_scrapqty,0)-nvl(mm_oneuseqty,0)*nvl(ma_madeqty,0)", "mm_id=" + lineId), "0"));
  484. if (mmqty < qty) {
  485. qty = mmqty;
  486. }
  487. }
  488. String reason = StringUtil.nvl(object.get("reason"), "");
  489. if ("".equals(reason)){
  490. return ApiResponse.failRsp("10026",requestId,"报废原因不能为空!");
  491. }
  492. fDeptID = StringUtil.nvl(object.get("FDeptID"), "");
  493. if ("".equals(fDeptID)){
  494. return ApiResponse.failRsp("10027",requestId,"责任部门编号不能为空!");
  495. }
  496. fDept = StringUtil.nvl(object.get("FDept"), "");
  497. if ("".equals(fDept)){
  498. return ApiResponse.failRsp("10028",requestId,"责任部门不能为空!");
  499. }
  500. String allScrapQty = StringUtil.nvl(object.get("AllScrapQty"), "0");
  501. String remark = StringUtil.nvl(object.get("remark"), "");
  502. if (qty>0) {
  503. 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,md_status,md_code) values " +
  504. "(MAKESCRAPDETAIL_SEQ.nextval," + id + "," + detno + "," + lineId + ",'" + prodNo + "'," + mmdetno + ",'" + itemNo + "'," + qty + ",'" + reason + "','" + fDeptID + "','" + fDept + "'," + allScrapQty + ",'" + remark + "',0,'"+code+"')");
  505. detno++;
  506. }
  507. }
  508. if (detno==1) {
  509. return ApiResponse.failRsp("10030",requestId,"没有可报废的用料!");
  510. }
  511. baseDao.execute(sqls);
  512. Object[] status = baseDao.getFieldsDataByCondition("MakeScrap", new String[] { "ms_statuscode", "ms_indate","ms_date" }, "ms_id=" + id);
  513. //审核
  514. String s = checkFreezeMonth(status[2]);
  515. // 账期和工单状态检查
  516. String s1 = ScrapCheckAll(id, caller);
  517. String s2 = ScrapCheck_scrapqty(id);
  518. String s3 = copcheck(id);
  519. String s4 = checkMakeMaterial(id);
  520. if (s!=null||s1!=null||s2!=null||s3!=null||s4!=null){
  521. baseDao.deleteById("MakeScrapdetail","md_msid",id);
  522. baseDao.deleteById("MakeScrap","ms_id",id);
  523. return ApiResponse.failRsp("10029",requestId,(s==null?"":s)+(s1==null?"":s1)+(s2==null?"":s2)+(s3==null?"":s3)+(s4==null?"":s4));
  524. }
  525. baseDao.updateByCondition("MakeScrapdetail", "md_status=99", "md_msid=" + id);
  526. List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode ", new String[] {
  527. "ma_id", "md_mmdetno", "md_qty", "md_prodcode" }, " md_msid=" + id);
  528. for (Object[] object : objects) {
  529. baseDao.updateByCondition("Makematerial ", "mm_scrapqty =nvl(mm_scrapqty,0)+" + object[2], "mm_detno=" + object[1]
  530. + " and mm_maid=" + object[0]);
  531. baseDao.updateByCondition("Makematerial ", "mm_repscrapqty =nvl(mm_repscrapqty,0)+" + object[2], "mm_detno=" + object[1]
  532. + " and mm_maid=" + object[0] + " and mm_prodcode<>'" + object[3] + "'");
  533. baseDao.updateByCondition("Makematerialreplace ", "mp_scrapqty =nvl(mp_scrapqty,0)+" + object[2], " mp_maid=" + object[0]
  534. + " and mp_mmdetno=" + object[1] + " and mp_prodcode='" + object[3] + "'");
  535. }
  536. // 执行审核操作
  537. baseDao.updateByCondition("MakeScrap", "ms_status='已审核',ms_statuscode='AUDITED',ms_auditdate=sysdate,ms_auditman='"+employee.getEm_name()+"'","ms_id="+ id);
  538. // 记录操作
  539. baseDao.execute("INSERT INTO MessageLog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search) VALUES (MessageLog_seq.nextval,sysdate,'mes','审核操作','审核成功','MakeScrap|ms_id="+id+"')");
  540. //生成超损请购
  541. int apId = baseDao.getSeqId("APPLICATION_SEQ");
  542. String apCode = baseDao.sGetMaxNumber("Application", 2);
  543. baseDao.execute("insert into Application (ap_id,ap_code,ap_kind,ap_date,ap_statuscode,ap_status,ap_pleamanname,ap_pleamanid,ap_recorder,ap_recorderid,ap_recorddate,ap_departcode,ap_departname,ap_source,ap_sourceid,ap_printstatuscode,ap_printstatus,ap_remark,ap_bfcode_user) values " +
  544. "("+apId+",'"+apCode+"','超损请购',sysdate,'ENTERING','在录入','"+employee.getEm_name()+"',"+employee.getEm_id()+",'"+employee.getEm_name()+"',"+employee.getEm_id()+",sysdate,'"+fDeptID+"','"+fDept+"','"+msclass+"',"+id+",'UNPRINT','未打印','MES生产报废单审核生成','"+code+"')");
  545. baseDao.execute("insert into applicationdetail (ad_id,ad_apid,ad_code,ad_detno,ad_prodcode,ad_qty,ad_use,ad_statuscode,ad_status,ad_source,ad_sourcecode,ad_remark,ad_zzcode_user,ad_zzxh_user,ad_sacode,ad_sadetno) " +
  546. "select APPLICATIONDETAIL_SEQ.nextval,"+apId+",'"+apCode+"',md_detno,md_prodcode,md_qty,md_reason,'ENTERING','在录入','"+msclass+"','"+code+"','MES生产报废单审核生成',md_mmcode,md_mmdetno,ma_salecode,ma_saledetno from MakeScrapdetail left join make on md_mmcode=ma_code where md_msid=" + id);
  547. baseDao.execute("update applicationdetail set ad_kcqty=(select ad_qty/(case when nvl(pr_purcrate,0)=0 then 1 else pr_purcrate end) from product where pr_code=ad_prodcode) where ad_apid="+apId);
  548. return ApiResponse.successRsp("0",requestId,msclass+":"+code+",请在ERP查看!");
  549. }
  550. @Override
  551. public ApiResult<String> deleteMakeScrap(HttpServletRequest request) {
  552. String requestId = request.getHeader("RequestId");
  553. JSONObject jsonData = getJsonData(request);
  554. String msclass="生产报废单";
  555. String caller="MakeScrap";
  556. if (jsonData==null){
  557. return ApiResponse.failRsp("10096",requestId,"参数异常!");
  558. }
  559. String fSelBillNo = StringUtil.nvl(jsonData.get("FSelBillNo"), "");
  560. if ("".equals(fSelBillNo)) {
  561. return ApiResponse.failRsp("10031", requestId, "MES单号不能为空!");
  562. }
  563. int count = baseDao.getCount("select count(1) from MakeScrap where ms_mescode='" + fSelBillNo + "'");
  564. if (count <= 0) {
  565. return ApiResponse.failRsp("10032", requestId, "MES单号对应报废单不存在,请核查!");
  566. }
  567. Object[] scraps = baseDao.getFieldsDataByCondition("MakeScrap","ms_id,ms_sourcecode,ms_sourcetype,ms_indate,ms_date,ms_code", "ms_mescode='" + fSelBillNo + "'");
  568. if ("委外加工单".equals(StringUtil.nvl(scraps[2],""))){
  569. msclass = "委外报废单";
  570. caller = "MakeScrap!Make";
  571. }
  572. int msId = Integer.parseInt(StringUtil.nvl(scraps[0], "0"));
  573. //判断请购单
  574. int count1 = baseDao.getCount("select count(1) from application where nvl(ap_statuscode,'ENTERING')<>'ENTERING' and ap_source='" + msclass + "' and ap_sourceid=" + msId);
  575. if(count1>0){
  576. return ApiResponse.failRsp("10033", requestId, "请购单不是在录入状态,不允许反审核!");
  577. }
  578. //反审核报废单
  579. String s = checkFreezeMonth(scraps[4]);
  580. baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  581. + "where pd_piid=pi_id and pi_statuscode<>'DELETE' and pd_status=0 and "
  582. + "pd_ordercode=mm_code and pd_orderdetno=mm_detno and pd_piclass in ('生产补料单', '委外补料单')) where mm_code in (select md_mmcode from MakeScrapDetail where md_msid="
  583. + msId + ")");
  584. SqlRowList rs = baseDao
  585. .queryForRowSet("select md_detno from MakeScrapDetail left join makematerial on mm_code=md_mmcode and md_mmdetno=mm_detno left join make on mm_maid=ma_id where md_msid='"
  586. + msId
  587. + "' and mm_addqty+NVL(mm_turnaddqty,0)>nvl(mm_scrapqty,0)+nvl(mm_returnmqty,0)-md_qty-nvl(mm_balance,0) and nvl(mm_scrapqty,0)+nvl(mm_returnmqty,0)-md_qty-nvl(mm_balance,0)>0 ");
  588. if (rs.next()) {
  589. return ApiResponse.failRsp("10033", requestId, "序号【" + rs.getString("md_detno") + "】报废数已生成补料单,不能反审核报废单!");
  590. }
  591. // 账期和工单状态检查
  592. String s1 = ScrapCheckAll(msId, caller);
  593. if (s!=null||s1!=null){
  594. return ApiResponse.failRsp("10029",requestId,(s==null?"":s)+(s1==null?"":s1));
  595. }
  596. baseDao.deleteByCondition("applicationdetail","ad_apid in (select ap_id from application where ap_source='" + msclass + "' and ap_sourceid=" + msId+")");
  597. baseDao.deleteByCondition("Application","ap_source='" + msclass + "' and ap_sourceid=" + msId);
  598. baseDao.updateByCondition("MakeScrapdetail", "md_status=0", "md_msid=" + msId);
  599. List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode", new String[] {
  600. "ma_id", "md_mmdetno", "md_qty", "md_prodcode" }, " md_msid=" + msId);
  601. for (Object[] obj : objects) {
  602. baseDao.updateByCondition("Makematerial ", "mm_scrapqty =nvl(mm_scrapqty,0)-" + obj[2], "mm_detno=" + obj[1] + " and mm_maid=" + obj[0]);
  603. baseDao.updateByCondition("Makematerial ", "mm_repscrapqty =nvl(mm_repscrapqty,0)-" + obj[2], "mm_detno=" + obj[1] + " and mm_maid=" + obj[0] + " and mm_prodcode<>'" + obj[3] + "'");
  604. baseDao.updateByCondition("Makematerialreplace ", "mp_scrapqty =nvl(mp_scrapqty,0)-" + obj[2], " mp_maid=" + obj[0] + " and mp_mmdetno=" + obj[1] + " and mp_prodcode='" + obj[3] + "'");
  605. }
  606. // 执行反审核操作
  607. baseDao.updateByCondition("MakeScrap", "ms_statuscode='ENTERING',ms_status='在录入'", "ms_id=" + msId);
  608. // 记录操作
  609. baseDao.execute("INSERT INTO MessageLog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search) VALUES " +
  610. "(MessageLog_seq.nextval,sysdate,'mes','反审核操作','反审核成功','MakeScrap|ms_id="+msId+"')");
  611. // 删除主表
  612. baseDao.deleteById("MakeScrap", "ms_id", msId);
  613. // 删除明细表
  614. baseDao.deleteById("MakeScrapdetail", "md_msid", msId);
  615. // 记录操作
  616. baseDao.execute("INSERT INTO MessageLog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search) VALUES " +
  617. "(MessageLog_seq.nextval,sysdate,'mes','删除操作','删除成功','MakeScrap|ms_id="+msId+"')");
  618. return ApiResponse.successRsp("0",requestId,msclass+":"+scraps[5]+"删除成功!");
  619. }
  620. @Override
  621. public ApiResult<String> prodInOutOtherOut(HttpServletRequest request) {
  622. String requestId = request.getHeader("RequestId");
  623. Map<String, JSONArray> data = getData(request);
  624. JSONArray jsonArray = data.get("main");
  625. int id=0;
  626. String code="";
  627. String caller="ProdInOut!OtherOut";
  628. String piclass="其它出库单";
  629. List<String> sqls = new ArrayList<>();
  630. for (int i = 0; i <jsonArray.size() ; i++) {
  631. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  632. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  633. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
  634. if (result!=null){
  635. return result;
  636. }
  637. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  638. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillTypeID")));
  639. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  640. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  641. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  642. //客户编号 客户单号
  643. String fCustCode = StringUtil.nvl(jsonObject2.get("FCustCode"), "");
  644. String fCustNo = StringUtil.nvl(jsonObject2.get("FCustNo"), "");
  645. Object cuname="";
  646. if (!"".equals(fCustCode)){
  647. cuname = baseDao.getFieldDataByCondition("Customer", "cu_name", "cu_code='" + fCustCode + "'");
  648. }
  649. id = baseDao.getSeqId("PRODINOUT_SEQ");
  650. code = baseDao.sGetMaxNumber(caller, 2);
  651. 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) " +
  652. "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")+"','ENTERING','在录入','"+map5.get("FName")+"',to_date('"+jsonObject2.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+map2.get("FName")+"','"+fSelBillNo+"','"+fCustCode+"','"+cuname+"','"+fCustNo+"')");
  653. }
  654. JSONArray array = data.get("detail");
  655. int detno=1;
  656. for (int i = 0; i <array.size(); i++) {
  657. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  658. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  659. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  660. if ("".equals(itemNo)){
  661. return ApiResponse.failRsp("10031",requestId,"物料不能为空!");
  662. }
  663. String qty = StringUtil.nvl(object.get("FAuxQtyMust"), "");
  664. if ("".equals(qty)){
  665. return ApiResponse.failRsp("10032",requestId,"实出数量不能为空!");
  666. }
  667. String fnote = StringUtil.nvl(object.get("Fnote"), "");
  668. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDCStockID1")));
  669. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  670. String whname = StringUtil.nvl(map1.get("FName"), "");
  671. if ("".equals(whcode)){
  672. return ApiResponse.failRsp("10034",requestId,"MES仓库编号不能为空!");
  673. }
  674. 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 + "'");
  675. if (count<=0){
  676. return ApiResponse.failRsp("10035",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  677. }
  678. 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 + "'");
  679. 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) " +
  680. "values (PRODIODETAIL_SEQ.nextval,"+id+",'"+code+"','其它出库单',"+detno+",'"+itemNo+ "',"+qty+",'"+warehouses[0]+"','"+warehouses[1]+"','"+fnote+"')");
  681. detno++;
  682. }
  683. baseDao.execute(sqls);
  684. /*Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  685. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  686. String s = postProdInOut(id, caller, employee);
  687. logger.info("其它出库单过账信息=="+s);
  688. if (s!=null){
  689. return ApiResponse.successRsp("0",requestId,"其它出库单:"+code+",过账失败,请在ERP重新过账!");
  690. }*/
  691. return ApiResponse.successRsp("0",requestId,"其它出库单:"+code+",请在ERP查看!");
  692. }
  693. @Override
  694. public ApiResult<String> prodInOutPicking(HttpServletRequest request) {
  695. String requestId = request.getHeader("RequestId");
  696. Map<String, JSONArray> data = getData(request);
  697. JSONArray jsonArray = data.get("main");
  698. String bccode = null;
  699. int bcpiid = 0;
  700. String llcode = null;
  701. int llpiid=0;
  702. String ma_tasktype=null;
  703. int maid=0;
  704. String llpiclass = "生产领料单", llcaller = "ProdInOut!Picking", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
  705. // 是否生成调拨单,勾选不生成,不勾选默认生成
  706. Boolean notCreateAppropriation = baseDao.isDBSetting("MultiMakeSendLS", "notCreateAppropriation");
  707. List<String> sqls = new ArrayList<>();
  708. JSONArray array = data.get("detail");
  709. if(array!=null&&array.size()>0){
  710. String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "{}")).get("FICMOBillNo"));
  711. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id,ma_status", "ma_code in ('" + macode + "')");
  712. if (data1!=null&&data1.length>0) {
  713. if ("已结案".equals(StringUtil.nvl(data1[2], ""))){
  714. return ApiResponse.failRsp("10045", requestId, "工单:"+macode+"在ERP已结案,不允许领料!");
  715. }
  716. ma_tasktype = StringUtil.nvl(data1[0], "");
  717. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  718. }else {
  719. return ApiResponse.failRsp("10046", requestId, "工单在ERP不存在,请核对!");
  720. }
  721. }
  722. for (int i = 0; i <jsonArray.size() ; i++) {
  723. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  724. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  725. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FPurposeID")));
  726. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  727. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  728. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  729. if ("OS".equals(ma_tasktype)) {
  730. llpiclass = "委外领料单";
  731. llcaller = "ProdInOut!OutsidePicking";
  732. }
  733. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  734. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, llpiclass);
  735. if (result!=null){
  736. return result;
  737. }
  738. ApiResult<String> result1 = checkMESCode(requestId, fSelBillNo, bcpiclass);
  739. if (result1!=null){
  740. return result1;
  741. }
  742. if(!notCreateAppropriation){
  743. //生成拨出单
  744. bcpiid = baseDao.getSeqId("PRODINOUT_SEQ");
  745. bccode = baseDao.sGetMaxNumber(bccaller, 2);
  746. 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) " +
  747. "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+"')");
  748. }
  749. //生成领料单
  750. llpiid = baseDao.getSeqId("PRODINOUT_SEQ");
  751. llcode = baseDao.sGetMaxNumber(llcaller, 2);
  752. 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) " +
  753. "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+"')");
  754. // 标示领料单的拨出单号
  755. sqls.add("update ProdInOut set pi_fromcode='" + bccode + "' where pi_id=" + llpiid);
  756. }
  757. Object[] warehouses=null;
  758. Object[] warehouses2=null;
  759. int detno=1;
  760. int det=1;
  761. for (int i = 0; i <array.size(); i++) {
  762. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  763. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  764. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  765. if ("".equals(itemNo)){
  766. return ApiResponse.failRsp("10041",requestId,"物料不能为空!");
  767. }
  768. String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
  769. if ("0".equals(fAuxQty)){
  770. return ApiResponse.failRsp("10042",requestId,"实发数量不能为空!");
  771. }
  772. Double qty = Double.parseDouble(fAuxQty);
  773. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  774. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  775. if ("".equals(whcode)){
  776. return ApiResponse.failRsp("10043",requestId,"发料仓库不能为空!");
  777. }
  778. 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 + "'");
  779. if (count<=0){
  780. return ApiResponse.failRsp("10044",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  781. }
  782. 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 + "'");
  783. String fSourceInterId = StringUtil.nvl(object.get("FSourceInterId"), "");
  784. String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
  785. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  786. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  787. if ("".equals(whcode2)){
  788. return ApiResponse.failRsp("10043",requestId,"物料所在仓库不能为空!");
  789. }
  790. 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 + "'");
  791. if (count2<=0){
  792. return ApiResponse.failRsp("10044",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  793. }
  794. 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 + "'");
  795. int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
  796. int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  797. if (count4<=0){
  798. return ApiResponse.failRsp("10046",requestId,"工单BOM在ERP中不存在,物料编号:"+itemNo+",请联系管理员!");
  799. }
  800. int count5 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ") and nvl(mm_qty,0)>0");
  801. if (count5<=0){
  802. return ApiResponse.failRsp("10047",requestId,"工单BOM在ERP中需求数为0,物料编号:"+itemNo+",请联系管理员!");
  803. }
  804. Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial", "mm_detno,mm_maid","mm_id in (" + lineId + ")");
  805. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  806. if(bccode!=null) {
  807. 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]+")");
  808. detno++;
  809. }
  810. int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_prodcode='" + itemNo + "' and mm_id in (" + lineId + ")");
  811. if (count1>0) {
  812. 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 + ")");
  813. if (sqlRowList.next()) {
  814. Double mmqty = sqlRowList.getGeneralDouble("mmqty");
  815. qty = qty.compareTo(mmqty) > 0 ? mmqty : qty;
  816. }
  817. }else {
  818. int count3 = baseDao.getCount("select count(1) from MakeMaterialreplace where mp_prodcode='" + itemNo + "' and mp_mmid in (" + lineId + ")");
  819. if (count3>0){
  820. 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 + ")");
  821. if (sqlRowList1.next()){
  822. Double mpqty = sqlRowList1.getGeneralDouble("mpqty");
  823. qty = qty.compareTo(mpqty) > 0 ? mpqty : qty;
  824. }
  825. }
  826. }
  827. if (qty>0) {
  828. 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)");
  829. det++;
  830. }
  831. }
  832. if ("OS".equals(ma_tasktype)) {
  833. 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);
  834. }
  835. if (warehouses2!=null){
  836. sqls.add("update prodinout set pi_whcode='"+warehouses2[0]+"',pi_whname='"+warehouses2[1]+"' where " + "pi_id="+bcpiid);
  837. }
  838. if (warehouses!=null){
  839. sqls.add("update prodinout set pi_purpose='"+warehouses[0]+"',pi_purposename='"+warehouses[1]+"' where pi_id="+bcpiid);
  840. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+llpiid);
  841. }
  842. baseDao.execute(sqls);
  843. refreshTurnQty(maid,0);
  844. setBackQty(String.valueOf(maid),0);
  845. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  846. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  847. int count = baseDao.getCount("select count(1) from prodiodetail where pd_piid=" + llpiid);
  848. if (count<=0){
  849. baseDao.deleteById("prodinout","pi_id",llpiid);
  850. if(!baseDao.isDBSetting(llcaller,"AllowPost")){
  851. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+ ",请在ERP查看并过账!");
  852. }
  853. String s = postProdInOut(bcpiid, bccaller, employee);
  854. logger.info("旧拨出单过账信息:"+s);
  855. if (s!=null){
  856. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+",过账失败,请在ERP重新过账!");
  857. }else {
  858. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+ ",请在ERP查看!");
  859. }
  860. }else {
  861. if(!baseDao.isDBSetting(llcaller,"AllowPost")){
  862. return ApiResponse.successRsp("0",requestId,llpiclass+":"+llcode+","+bcpiclass+":"+bccode+ ",请在ERP查看并手工过账!");
  863. }
  864. String s = postProdInOut(bcpiid, bccaller, employee);
  865. logger.info("旧拨出单过账信息:"+s);
  866. if (s!=null){
  867. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+",过账失败,请在ERP重新过账!");
  868. }
  869. String s1 = postProdInOut(llpiid, llcaller, employee);
  870. logger.info("旧生产领料单过账信息:"+s1);
  871. refreshTurnQty(maid,0);
  872. setBackQty(String.valueOf(maid),0);
  873. if (s1 != null) {
  874. return ApiResponse.successRsp("0", requestId, llpiclass+":" + llcode + ",过账失败,请在ERP重新过账!");
  875. }
  876. return ApiResponse.successRsp("0",requestId,llpiclass+":"+llcode+","+bcpiclass+":"+bccode+ ",请在ERP查看!");
  877. }
  878. }
  879. @Override
  880. public ApiResult<String> prodInOutMakeReturn(HttpServletRequest request) {
  881. String requestId = request.getHeader("RequestId");
  882. Map<String, JSONArray> data = getData(request);
  883. JSONArray jsonArray = data.get("main");
  884. int id=0;
  885. String code="";
  886. int tlid=0;
  887. String tlcode = "";
  888. String macode="";
  889. String ma_tasktype=null;
  890. //良品退仓、来料不良、制程不良
  891. String taskType="制程不良";
  892. int maid=0;
  893. String tlpiclass = "生产退料单", tlcaller = "ProdInOut!Make!Return", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
  894. List<String> sqls = new ArrayList<>();
  895. int frob=99;
  896. JSONArray array = data.get("detail");
  897. Object[] warehouses=null;
  898. Object[] warehouses2=null;
  899. if(array!=null&&array.size()>0) {
  900. macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "")).get("FICMOBillNo"));
  901. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
  902. if (data1 != null && data1.length > 0) {
  903. ma_tasktype = StringUtil.nvl(data1[0], "");
  904. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  905. } else {
  906. return ApiResponse.failRsp("10057", requestId, "工单在ERP不存在,请核对!");
  907. }
  908. for (int i = 0; i <array.size(); i++) {
  909. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  910. Object lineId = object.get("lineId");
  911. //线边仓
  912. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  913. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  914. if ("".equals(whcode)) {
  915. return ApiResponse.failRsp("10053", requestId, "仓库编号不能为空!");
  916. }
  917. 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 + "'");
  918. if (count <= 0) {
  919. return ApiResponse.failRsp("10054", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  920. }
  921. //大仓
  922. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  923. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  924. if ("".equals(whcode2)) {
  925. return ApiResponse.failRsp("10055", requestId, "物料退回仓库不能为空!");
  926. }
  927. 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 + "'");
  928. if (count2 <= 0) {
  929. return ApiResponse.failRsp("10056", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  930. }
  931. }
  932. }
  933. for (int i = 0; i <jsonArray.size() ; i++) {
  934. Object obj = jsonArray.get(i);
  935. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(obj, ""));
  936. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FDeptID"),"{}"));
  937. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FPurposeID"),"{}"));
  938. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FFManagerID"),"{}"));
  939. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FSManagerID"),"{}"));
  940. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FBillerID"),"{}"));
  941. frob = Integer.parseInt(StringUtil.nvl(jsonObject2.get("FROB"), "99"));
  942. taskType = StringUtil.nvl(jsonObject2.get("TaskType"), "");
  943. if ("OS".equals(ma_tasktype)) {
  944. tlpiclass = "委外退料单";
  945. tlcaller = "ProdInOut!OutsideReturn";
  946. }
  947. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  948. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, tlpiclass);
  949. if (result!=null){
  950. return result;
  951. }
  952. ApiResult<String> result1 = checkMESCode(requestId, fSelBillNo, bcpiclass);
  953. if (result1!=null){
  954. return result1;
  955. }
  956. if (frob==0||"制程不良".equals(taskType)){
  957. tlid = baseDao.getSeqId("PRODINOUT_SEQ");
  958. tlcode = baseDao.sGetMaxNumber(tlcaller, 2);
  959. 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+"')");
  960. }
  961. id = baseDao.getSeqId("PRODINOUT_SEQ");
  962. code = baseDao.sGetMaxNumber(bccaller, 2);
  963. 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+"')");
  964. }
  965. int detno=1;
  966. int det=1;
  967. for (int i = 0; i <array.size(); i++) {
  968. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  969. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  970. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  971. if ("".equals(itemNo)){
  972. return ApiResponse.failRsp("10051",requestId,"物料不能为空!");
  973. }
  974. Double qty =Double.parseDouble(StringUtil.nvl(object.get("FAuxQty"), ""));
  975. if ("".equals(qty)){
  976. return ApiResponse.failRsp("10052",requestId,"实发数量不能为空!");
  977. }
  978. String fnote = StringUtil.nvl(object.get("Fnote"), "");
  979. Object lineId = object.get("lineId");
  980. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  981. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  982. 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 + "'");
  983. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  984. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  985. 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 + "'");
  986. String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
  987. String fBatchNo = StringUtil.nvl(object.get("FBatchNo"), "");
  988. int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  989. if (count1<=0){
  990. return ApiResponse.failRsp("10075",requestId,"工单BOM不存在或ID不一致,请联系管理员处理!");
  991. }
  992. 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+")");
  993. 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]+")");
  994. if (frob==0||"制程不良".equals(taskType)) {
  995. Object prid = baseDao.getFieldDataByCondition("Product", "pr_id", "pr_code='" + itemNo + "'");
  996. Double remain = baseDao.getSummaryByField("batch", "ba_remain", "ba_prodcode='" + itemNo + "' and ba_macode='" + macode + "' and ba_whcode='" + warehouses[0] + "'");
  997. /*Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial left join Make on ma_id=mm_maid",
  998. "mm_totaluseqty,mm_havegetqty,ma_tomadeqty,mm_oneuseqty,ma_qty", "mm_id=" + objs[0]);*/
  999. if (qty.compareTo(remain) > 0){
  1000. double sub = DoubleUtils.sub(qty, remain);
  1001. 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+ ",'良品退仓')");
  1002. det++;
  1003. }
  1004. }
  1005. detno++;
  1006. }
  1007. if (frob==0){
  1008. 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="
  1009. + tlid);
  1010. 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="
  1011. + tlid);
  1012. }
  1013. if ("OS".equals(ma_tasktype)) {
  1014. 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);
  1015. }
  1016. if (warehouses!=null){
  1017. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+id);
  1018. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+tlid);
  1019. }
  1020. if (warehouses2!=null){
  1021. sqls.add("update prodinout set pi_purpose='"+warehouses2[0]+"',pi_purposename='"+warehouses2[1]+"' where pi_id="+id);
  1022. }
  1023. baseDao.execute(sqls);
  1024. baseDao.execute("delete from prodiodetail where pd_inqty=0 and pd_piclass='"+tlpiclass+"' and pd_piid="+tlid);
  1025. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1026. int count = baseDao.getCount("select count(1) from prodiodetail where pd_piid=" + tlid);
  1027. if (count<=0){
  1028. baseDao.deleteById("prodinout","pi_id",tlid);
  1029. if(!baseDao.isDBSetting(tlcaller,"AllowPost")){
  1030. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+ ",请在ERP查看并手工过账!");
  1031. }
  1032. String s = postProdInOut(id, bccaller, employee);
  1033. logger.info("S=="+s);
  1034. if (s!=null){
  1035. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
  1036. }
  1037. return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+",请在ERP查看!");
  1038. }else {
  1039. if(!baseDao.isDBSetting(tlcaller,"AllowPost")){
  1040. return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",请在ERP查看并手工过账!");
  1041. }
  1042. String s1 = postProdInOut(tlid, tlcaller, employee);
  1043. logger.info("S1==" + s1);
  1044. if (s1 != null){
  1045. return ApiResponse.successRsp("0", requestId, tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
  1046. }
  1047. String s = postProdInOut(id, bccaller, employee);
  1048. logger.info("S=="+s);
  1049. if (s!=null){
  1050. return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
  1051. }
  1052. return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",请在ERP查看!");
  1053. }
  1054. }
  1055. @Override
  1056. public ApiResult<String> prodInOutAppropriationOut(HttpServletRequest request) {
  1057. String requestId = request.getHeader("RequestId");
  1058. Map<String, JSONArray> data = getData(request);
  1059. JSONArray jsonArray = data.get("main");
  1060. int id=0;
  1061. String code="";
  1062. String picaller="ProdInOut!AppropriationOut";
  1063. String piclass="拨出单";
  1064. List<String> sqls = new ArrayList<>();
  1065. for (int i = 0; i <jsonArray.size() ; i++) {
  1066. JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  1067. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
  1068. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FRefType")));
  1069. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
  1070. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
  1071. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
  1072. String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
  1073. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
  1074. if (result!=null){
  1075. return result;
  1076. }
  1077. id = baseDao.getSeqId("PRODINOUT_SEQ");
  1078. code = baseDao.sGetMaxNumber(picaller, 2);
  1079. 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+"')");
  1080. }
  1081. JSONArray array = data.get("detail");
  1082. Object[] warehouses=null;
  1083. Object[] warehouses2=null;
  1084. int detno=1;
  1085. for (int i = 0; i <array.size(); i++) {
  1086. JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
  1087. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  1088. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  1089. if ("".equals(itemNo)){
  1090. return ApiResponse.failRsp("10061",requestId,"物料不能为空!");
  1091. }
  1092. String qty = StringUtil.nvl(object.get("Fauxqty"), "");
  1093. if ("".equals(qty)){
  1094. return ApiResponse.failRsp("10062",requestId,"实转数量不能为空!");
  1095. }
  1096. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
  1097. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  1098. String whname = StringUtil.nvl(map1.get("FName"), "");
  1099. if ("".equals(whcode)){
  1100. return ApiResponse.failRsp("10063",requestId,"发货仓库不能为空!");
  1101. }
  1102. 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 + "'");
  1103. if (count<=0){
  1104. return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1105. }
  1106. 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 + "'");
  1107. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDCStockID1")));
  1108. String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
  1109. String whname2 = StringUtil.nvl(map2.get("FName"), "");
  1110. if ("".equals(whcode2)){
  1111. return ApiResponse.failRsp("10065",requestId,"收货仓库不能为空!");
  1112. }
  1113. 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 + "'");
  1114. if (count2<=0){
  1115. return ApiResponse.failRsp("10066",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1116. }
  1117. 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 + "'");
  1118. 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]+"')");
  1119. detno++;
  1120. }
  1121. if (warehouses!=null){
  1122. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where " + "pi_id="+id);
  1123. }
  1124. if (warehouses2!=null){
  1125. sqls.add("update prodinout set pi_purpose='"+warehouses2[0]+"',pi_purposename='"+warehouses2[1]+"' where pi_id="+id);
  1126. }
  1127. baseDao.execute(sqls);
  1128. return ApiResponse.successRsp("0",requestId,"拨出单:"+code+",请在ERP查看!");
  1129. }
  1130. @Override
  1131. public ApiResult<String> makeCheckOutStock(HttpServletRequest request) {
  1132. String requestId = request.getHeader("RequestId");
  1133. try {
  1134. String data = PSHttpUtils.readRaw(request.getInputStream());
  1135. JSONArray jsonArray = JSON.parseArray(data);
  1136. for (int i = 0; i <jsonArray.size() ; i++) {
  1137. JSONObject jsonObject = jsonArray.getJSONObject(i);
  1138. String whcode = StringUtil.nvl(jsonObject.getString("outwhcode"), "");
  1139. if ("".equals(whcode)){
  1140. return ApiResponse.failRsp("10081",requestId,"拨出仓库不能为空!");
  1141. }
  1142. 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 + "'");
  1143. if (count<=0){
  1144. return ApiResponse.failRsp("10082",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1145. }
  1146. 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 + "'");
  1147. jsonObject.put("outwhcode",outwhcode);
  1148. String whcode1 = StringUtil.nvl(jsonObject.getString("inwhcode"), "");
  1149. if ("".equals(whcode1)){
  1150. return ApiResponse.failRsp("10083",requestId,"拨入仓库不能为空!");
  1151. }
  1152. 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 + "'");
  1153. if (count1<=0){
  1154. return ApiResponse.failRsp("10084",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1155. }
  1156. 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 + "'");
  1157. jsonObject.put("inwhcode",inwhcode);
  1158. }
  1159. String msg = baseDao.callProcedure("USER_CHECKOUTSTOCK", new Object[] {null,JSON.toJSONString(jsonArray)});
  1160. if (msg != null && !msg.trim().equals("")){
  1161. return ApiResponse.failRsp("10085",requestId,msg);
  1162. }
  1163. return ApiResponse.successRsp("0",requestId,"校验通过!");
  1164. } catch (IOException e) {
  1165. logger.error("makeCheckOutStock==="+e.getMessage());
  1166. return ApiResponse.failRsp("10086",requestId,e.getMessage());
  1167. }
  1168. }
  1169. @Override
  1170. public ApiResult<String> makeECNCheck(HttpServletRequest request) {
  1171. String requestId = request.getHeader("RequestId");
  1172. JSONObject jsonData = getJsonData(request);
  1173. if (jsonData!=null){
  1174. String makeCode = StringUtil.nvl(jsonData.get("MakeCode"), "");
  1175. Object mcCode = baseDao.getFieldDataByCondition("makematerialchange", "wm_concat(mc_code)",
  1176. "mc_id in (select md_mcid from makematerialchangedet where md_makecode='"+makeCode+"' and nvl(md_didstatus,' ')<>'执行成功')");
  1177. if (mcCode!=null){
  1178. return ApiResponse.failRsp("10091",requestId,"ERP有未执行的制造单ECN:"+mcCode);
  1179. }
  1180. Object ecnCode = baseDao.getFieldDataByCondition("ecn", "wm_concat(ecn_code)",
  1181. "nvl(ecn_didstatus,' ')<>'已执行' and ecn_id in (select ed_ecnid from ecndetail left join make on ed_boid=ma_bomid where ma_code='"+makeCode+"')");
  1182. if (ecnCode!=null){
  1183. return ApiResponse.failRsp("10092",requestId,"ERP有未执行的ECN:"+ecnCode);
  1184. }
  1185. return ApiResponse.successRsp("0",requestId,"校验通过!");
  1186. }else {
  1187. return ApiResponse.failRsp("10093",requestId,"参数异常!");
  1188. }
  1189. }
  1190. @Override
  1191. public ApiResult<String> canMadeQty(HttpServletRequest request) {
  1192. String requestId = request.getHeader("RequestId");
  1193. JSONObject jsonData = getJsonData(request);
  1194. if (jsonData!=null){
  1195. String makeCode = StringUtil.nvl(jsonData.get("MakeCode"), "");
  1196. int count = baseDao.getCount("select count(1) from make where ma_code ='" + makeCode + "'");
  1197. if (count<=0){
  1198. return ApiResponse.failRsp("10094",requestId,"工单:"+makeCode+"在ERP不存在,请核对!");
  1199. }
  1200. Object[] data = baseDao.getFieldsDataByCondition("make", "ma_canmadeqty,ma_code,ma_qty,ma_madeqty,ma_tomadeqty,ma_id", "ma_code='" + makeCode + "'");
  1201. if (data!=null&&data.length>0) {
  1202. Map<String, Object> map = new HashMap<>();
  1203. map.put("code",data[1]);
  1204. if (baseDao.checkIf("makematerial","nvl(mm_cp_user,0)=0 and nvl(mm_qty,0)>0 and mm_maid="+data[5])){
  1205. Object canmadeqty = baseDao.getFieldDataByCondition("make", "(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 nvl(mm_oneuseqty,0)>0 and nvl(mm_cp_user,0)=0)","ma_code='" + makeCode + "'");
  1206. //备料齐套数量
  1207. map.put("canmadeqty",Double.parseDouble(StringUtil.nvl(canmadeqty,"0")));
  1208. }else {
  1209. map.put("canmadeqty",Double.parseDouble(StringUtil.nvl(data[0],"0")));
  1210. }
  1211. //工单数量
  1212. map.put("qty",data[2]);
  1213. //完工数量
  1214. map.put("madeqty",data[3]);
  1215. //已转完工数
  1216. map.put("tomadeqty",data[4]);
  1217. return ApiResponse.successRsp("0", "获取成功!",requestId, JSON.toJSONString(map));
  1218. }else {
  1219. return ApiResponse.failRsp("10095",requestId,"未找到数据!");
  1220. }
  1221. }else {
  1222. return ApiResponse.failRsp("10096",requestId,"参数异常!");
  1223. }
  1224. }
  1225. @Override
  1226. public ApiResult<String> prodInOutMakeGive(HttpServletRequest request) {
  1227. String requestId = request.getHeader("RequestId");
  1228. Map<String, JSONArray> data = getData(request);
  1229. JSONArray jsonArray = data.get("main");
  1230. String piCaller="ProdInOut!Make!Give";
  1231. String piClass="生产补料单";
  1232. Object piid=null;
  1233. String inoutno="";
  1234. for (int i = 0; i <jsonArray.size() ; i++) {
  1235. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  1236. inoutno = StringUtil.nvl(jsonObject.get("FSelBillNo"), "");
  1237. if ("".equals(inoutno)){
  1238. return ApiResponse.failRsp("10019",requestId,"生产补料单号不能为空!");
  1239. }
  1240. int count = baseDao.getCount("select count(1) from prodinout where pi_inoutno='" + inoutno + "' and pi_invostatuscode='AUDITED' and pi_statuscode='UNPOST' and pi_class='生产补料单'");
  1241. if (count>0) {
  1242. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1243. piid = baseDao.getFieldDataByCondition("prodinout", "pi_id", "pi_inoutno='" + inoutno + "'");
  1244. String s = postProdInOut(Integer.parseInt(StringUtil.nvl(piid,"0")), piCaller, employee);
  1245. logger.info("s==" + s);
  1246. if (s != null) {
  1247. return ApiResponse.successRsp("108", requestId, piClass+":" + inoutno + ",过账失败,请在ERP重新过账!");
  1248. }
  1249. }else {
  1250. return ApiResponse.successRsp("107", requestId, piClass+":" + inoutno + ",不存在或未审核,或已过帐!");
  1251. }
  1252. }
  1253. return ApiResponse.successRsp("0",requestId,piClass+":"+inoutno+"自动过账,请在ERP查看!");
  1254. }
  1255. @Override
  1256. public ApiResult<String> purcCheckinDetail(HttpServletRequest request) {
  1257. String requestId = request.getHeader("RequestId");
  1258. Map<String, JSONArray> data = getData(request);
  1259. JSONArray jsonArray = data.get("main");
  1260. Object vaid=0;
  1261. String caller="VerifyApply!ToOtherIn";
  1262. String type="其它入库单";
  1263. String djcaller="ProdInOut!OtherIn";
  1264. String sellerName="";
  1265. for (int i = 0; i <jsonArray.size() ; i++) {
  1266. JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
  1267. String mesCode = StringUtil.nvl(jsonObject.get("mesCode"),"");
  1268. if ("".equals(mesCode)){
  1269. return ApiResponse.failRsp("10011",requestId,"ERP单据编号不能为空!");
  1270. }
  1271. int count = baseDao.getCountByCondition("verifyApply", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
  1272. if (count<1){
  1273. return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
  1274. }
  1275. vaid = baseDao.getFieldDataByCondition("verifyApply", "va_id", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
  1276. String vaClass = StringUtil.nvl(baseDao.getFieldDataByCondition("VerifyApply", "va_class", "va_id=" + vaid), "");
  1277. if ("委外收料单".equals(vaClass)) {
  1278. caller = "VerifyApply!ToOutsideCheckIn";
  1279. type = "委外验收单";
  1280. djcaller = "ProdInOut!OutsideCheckIn";
  1281. }else if("采购收料单".equals(vaClass)){
  1282. int count1 = baseDao.getCount("select count(1) from VerifyApplyDetail where nvl(vad_pucode,' ')<>' ' and vad_vaid=" + vaid);
  1283. if (count1 > 0) {
  1284. caller = "VerifyApply!ToPurcIn";
  1285. type = "采购验收单";
  1286. djcaller = "ProdInOut!PurcCheckin";
  1287. }
  1288. }
  1289. //判断已转数
  1290. 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);
  1291. if(chekQty !=null){
  1292. return ApiResponse.failRsp("10013",requestId,"检测到" + chekQty + ",本次数量超出可转数量!");
  1293. }
  1294. if ("VerifyApply!ToPurcIn".equals(caller)) {
  1295. // 判断该收料单是否已经转入过采购验收单
  1296. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  1297. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and " + "PI_REFNO='采购收料单' and pi_class='采购验收单'");
  1298. if (code != null && !code.equals("")) {
  1299. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过采购验收单,验收单号[" + code + "]");
  1300. }
  1301. }
  1302. if ("VerifyApply!ToOtherIn".equals(caller)) {
  1303. // 判断该收料单是否已经转入过其它入库单
  1304. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  1305. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='其它入库单'");
  1306. if (code != null && !code.equals("")) {
  1307. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过其它入库单,单号[" + code + "]");
  1308. }
  1309. }
  1310. if ("VerifyApply!ToOutsideCheckIn".equals(caller)) {
  1311. // 判断该收料单是否已经转入过委外验收单
  1312. Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
  1313. code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='委外验收单'");
  1314. if (code != null && !code.equals("")) {
  1315. return ApiResponse.failRsp("10014", requestId, "该收料单已转入过委外验收单,单号[" + code + "]");
  1316. }
  1317. }
  1318. sellerName = StringUtil.nvl(jsonObject.get("sellerName"), "mes");
  1319. }
  1320. JSONArray array = data.get("detail");
  1321. for (int i = 0; i <array.size() ; i++) {
  1322. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  1323. String itemNo = StringUtil.nvl(json.get("itemNo"), "");
  1324. Double qty = Double.parseDouble(StringUtil.nvl(json.get("qty"), "0"));
  1325. Double vadQty = baseDao.getSummaryByField("verifyapplydetail", "vad_qty", "vad_prodcode='" + itemNo + "' and vad_vaid=" + vaid);
  1326. int compare = qty.compareTo(vadQty);
  1327. if (compare>0){
  1328. return ApiResponse.failRsp("10017",requestId, "物料:"+itemNo+",收料数量:"+qty+"超出ERP收料单数量:"+vadQty+ ",不允许入库!");
  1329. }
  1330. if (compare<0){
  1331. return ApiResponse.failRsp("10018",requestId,"物料:"+itemNo+",收料数量:"+qty+"少于ERP收料单数量:"+vadQty+",不允许入库!");
  1332. }
  1333. String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
  1334. if ("".equals(whcode)){
  1335. return ApiResponse.failRsp("10015",requestId,"MES仓库编号不能为空!");
  1336. }
  1337. 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 + "'");
  1338. if (coun<=0){
  1339. return ApiResponse.failRsp("10016",requestId,"MES仓库编号:"+whcode+"在ERP没有对应关系,请联系管理员新增!");
  1340. }
  1341. }
  1342. int piid =0;
  1343. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_name=?",
  1344. new BeanPropertyRowMapper<Employee>(Employee.class), sellerName);
  1345. // 转采购验收单
  1346. Key key = transferRepository.transfer(caller, vaid,employee);
  1347. piid = key.getId();
  1348. // 转入明细
  1349. transferRepository.transferDetail(caller, vaid, key,employee);
  1350. if (piid != 0) {
  1351. baseDao.execute("delete from prodiodetail where nvl(pd_inqty,0)<=0 and pd_piid="+piid);
  1352. //更新仓库
  1353. for (int i = 0; i <array.size() ; i++) {
  1354. JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
  1355. String itemNo = StringUtil.nvl(json.get("itemNo"), "");
  1356. String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
  1357. 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 + "'");
  1358. baseDao.updateByCondition("prodiodetail", "pd_whcode='"+warehouses[0]+"',pd_whname='"+warehouses[1]+"'", "pd_prodcode='"+itemNo+"' and pd_piid=" + piid);
  1359. }
  1360. //baseDao.updateByCondition("prodinout", "pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"'","pi_id=" + piid);
  1361. baseDao.execute("update prodiodetail set pd_prodid=(select pr_id from product where pd_prodcode=pr_code) where pd_piid=" + piid
  1362. + " and nvl(pd_prodcode,' ')<>' '");
  1363. baseDao.execute("update prodiodetail set pd_whid=(select wh_id from warehouse where wh_code=pd_whcode) where pd_piid=" + piid
  1364. + " and nvl(pd_whcode,' ')<>' '");
  1365. baseDao.updateByCondition("ProdInOut",
  1366. "pi_total=(SELECT round(sum(nvl(pd_orderprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid="
  1367. + piid + ")", "pi_id=" + piid);
  1368. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + piid);
  1369. if ("VerifyApply!ToPurcIn".equals(caller)) {
  1370. baseDao.execute("Insert into ProdChargeDetail(pd_id,pd_piid,pd_detno,pd_type,pd_amount,pd_currency,pd_rate) "
  1371. + "select ProdChargeDetail_seq.nextval, " + piid + ", pd_detno, pd_type,pd_amount,pd_currency,pd_rate "
  1372. + "from ProdChargeDetailAN where PD_ANID=" + vaid);
  1373. SqlRowList rs = baseDao.queryForRowSet("select vad_pucode,vad_pudetno,vad_qty from VerifyApplyDetail where vad_vaid=" + vaid);
  1374. String pCode = null;
  1375. int pDetno = 0;
  1376. double yq = 0;
  1377. Set<String> pCodes = new HashSet<String>();
  1378. while (rs.next()) {
  1379. pCode = rs.getString("vad_pucode");
  1380. if (!pCodes.contains(pCode)) {
  1381. pCodes.add(pCode);
  1382. }
  1383. pDetno = rs.getInt("vad_pudetno");
  1384. yq = rs.getDouble("vad_qty");
  1385. baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno);
  1386. baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno
  1387. + " and pd_qty=" + yq);
  1388. }
  1389. Iterator<String> iter = pCodes.iterator();
  1390. while (iter.hasNext()) {
  1391. pCode = iter.next();
  1392. int total = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "'");
  1393. int aud = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "' AND nvl(pd_acceptqty,0)=0");
  1394. int turn = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode
  1395. + "' AND nvl(pd_acceptqty,0)=nvl(pd_qty,0)");
  1396. String statuscode = aud == total ? "" : (turn == total ? "TURNIN" : "PART2IN");
  1397. String status = aud == total ? "" : (turn == total ? "已入库" : "部分入库");
  1398. baseDao.updateByCondition("Purchase",
  1399. "pu_turnstatuscode='" + statuscode + "',pu_turnstatus='" + status + "'", "pu_code='" + pCode + "'");
  1400. }
  1401. }
  1402. // 修改收料状态
  1403. baseDao.updateByCondition("VerifyApplyDetail", "vad_yqty=vad_qty", "vad_vaid=" + vaid);
  1404. baseDao.updateByCondition("VerifyApply", "va_turnstatuscode='TURNIN',va_turnstatus='已入库'", "va_id=" + vaid);
  1405. String s = postProdInOut(piid, djcaller, employee);
  1406. logger.info("收料单入库=="+s);
  1407. if (s!=null){
  1408. return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",过账失败,请在ERP重新过账!");
  1409. }
  1410. return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",请在ERP查看!");
  1411. }
  1412. return ApiResponse.failRsp("10019",requestId,"ERP生成单据失败!");
  1413. }
  1414. @Override
  1415. public ApiResult<String> multiMakeSendPicking(HttpServletRequest request) {
  1416. String requestId = request.getHeader("RequestId");
  1417. Map<String, JSONArray> data = getData(request);
  1418. String llcode = null,ma_tasktype=null,llpiclass = "生产领料单", llcaller = "ProdInOut!Picking";
  1419. int llpiid=0,maid=0,detno=1;
  1420. Object[] warehouses=null;
  1421. List<String> sqls = new ArrayList<>();
  1422. JSONArray detail = data.get("detail");
  1423. if(detail!=null&&detail.size()>0){
  1424. String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(detail.get(0), "{}")).get("FICMOBillNo"));
  1425. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id,ma_status,ma_finishstatus", "ma_code in ('" + macode + "')");
  1426. if (data1!=null&&data1.length>0) {
  1427. if ("已结案".equals(StringUtil.nvl(data1[2], ""))){
  1428. return ApiResponse.failRsp("10041", requestId, "工单:"+macode+"在ERP已结案,不允许领料!");
  1429. }
  1430. if ("已完工".equals(StringUtil.nvl(data1[3], ""))){
  1431. return ApiResponse.failRsp("10041", requestId, "工单:"+macode+"在ERP已完工,不允许领料!");
  1432. }
  1433. ma_tasktype = StringUtil.nvl(data1[0], "");
  1434. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  1435. }else {
  1436. return ApiResponse.failRsp("10042", requestId, "工单在ERP不存在,请核对!");
  1437. }
  1438. for (int i = 0; i <detail.size(); i++) {
  1439. JSONObject object = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
  1440. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  1441. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  1442. if ("".equals(itemNo)){
  1443. return ApiResponse.failRsp("10043",requestId,"物料不能为空!");
  1444. }
  1445. String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
  1446. if ("0".equals(fAuxQty)){
  1447. return ApiResponse.failRsp("10044",requestId,"实发数量不能为空!");
  1448. }
  1449. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID2")));
  1450. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  1451. if ("".equals(whcode)){
  1452. return ApiResponse.failRsp("10045",requestId,"发料仓库不能为空!");
  1453. }
  1454. 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 + "'");
  1455. if (count<=0){
  1456. return ApiResponse.failRsp("10046",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1457. }
  1458. 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 + "'");
  1459. int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
  1460. int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  1461. if (count4<=0){
  1462. return ApiResponse.failRsp("10047",requestId,"工单BOM在ERP中不存在,物料编号:"+itemNo+",请联系管理员!");
  1463. }
  1464. int count5 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ") and nvl(mm_qty,0)>0");
  1465. if (count5<=0){
  1466. return ApiResponse.failRsp("10047",requestId,"工单BOM在ERP中需求数为0,物料编号:"+itemNo+",请联系管理员!");
  1467. }
  1468. }
  1469. }
  1470. JSONArray main = data.get("main");
  1471. for (int i = 0; i <main.size() ; i++) {
  1472. JSONObject object = JSON.parseObject(StringUtil.nvl(main.get(i), "{}"));
  1473. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDeptID")));
  1474. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(object.get("FPurposeID")));
  1475. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSManagerID")));
  1476. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(object.get("FBillerID")));
  1477. if ("OS".equals(ma_tasktype)) {
  1478. llpiclass = "委外领料单";
  1479. llcaller = "ProdInOut!OutsidePicking";
  1480. }
  1481. String fSelBillNo = StringUtil.nvl(object.get("FSelBillNo"), "");
  1482. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, llpiclass);
  1483. if (result!=null){
  1484. return result;
  1485. }
  1486. //生成领料单
  1487. llpiid = baseDao.getSeqId("PRODINOUT_SEQ");
  1488. llcode = baseDao.sGetMaxNumber(llcaller, 2);
  1489. 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) " +
  1490. "values ("+llpiid+",'"+llcode+"','"+llpiclass+"',to_date('"+object.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('"+object.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'UNPRINT','未打印','"+map2.get("FName")+"','"+fSelBillNo+"')");
  1491. }
  1492. for (int i = 0; i <detail.size(); i++) {
  1493. JSONObject object = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
  1494. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  1495. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  1496. String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
  1497. Double qty = Double.parseDouble(fAuxQty);
  1498. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID2")));
  1499. String whcode = StringUtil.nvl(map1.get("FNumber"), "");
  1500. 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 + "'");
  1501. 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 + "'");
  1502. String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
  1503. int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
  1504. int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  1505. Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial", "mm_detno,mm_maid","mm_id in (" + lineId + ")");
  1506. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  1507. 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) " +
  1508. "values (PRODIODETAIL_SEQ.nextval," + llpiid + ",'" + llcode + "','" + llpiclass + "'," + detno + ",'" + itemNo + "'," + qty + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + ficmoBillNo + "'," + data1[0] + ",'" + ficmoBillNo + "'," + data1[0] + ",0)");
  1509. detno++;
  1510. }
  1511. if ("OS".equals(ma_tasktype)) {
  1512. 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);
  1513. }
  1514. if (warehouses!=null){
  1515. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+llpiid);
  1516. }
  1517. baseDao.execute(sqls);
  1518. refreshTurnQty(maid,0);
  1519. setBackQty(String.valueOf(maid),0);
  1520. if(!baseDao.isDBSetting(llcaller,"AllowPost")){
  1521. return ApiResponse.successRsp("0",requestId,llpiclass + ":" + llcode + ",请在ERP查看并手工过账!");
  1522. }
  1523. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
  1524. new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1525. String s = postProdInOut(llpiid, llcaller, employee);
  1526. logger.info("新生产领料单过账信息:"+s);
  1527. if (s!=null){
  1528. return ApiResponse.successRsp("0", requestId, llpiclass + ":" + llcode + ",过账失败,请在ERP重新过账!");
  1529. }
  1530. refreshTurnQty(maid,0);
  1531. setBackQty(String.valueOf(maid),0);
  1532. return ApiResponse.successRsp("0", requestId, llpiclass + ":" + llcode + ",请在ERP查看!");
  1533. }
  1534. @Override
  1535. public ApiResult<String> multiMakeReturn(HttpServletRequest request) {
  1536. String requestId = request.getHeader("RequestId");
  1537. Map<String, JSONArray> data = getData(request);
  1538. int tlid=0,maid=0,frob=99;
  1539. String tlcode = "",ma_tasktype=null,taskType="良品退仓",tlpiclass = "生产退料单", tlcaller = "ProdInOut!Make!Return", piclass="'生产领料单','生产退料单'";
  1540. //良品退仓、来料不良、制程不良
  1541. List<String> sqls = new ArrayList<>();
  1542. JSONArray main = data.get("main");
  1543. JSONArray detail = data.get("detail");
  1544. String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(detail.get(0), "")).get("FICMOBillNo"));
  1545. Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
  1546. if (data1 != null && data1.length > 0) {
  1547. ma_tasktype = StringUtil.nvl(data1[0], "");
  1548. maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
  1549. } else {
  1550. return ApiResponse.failRsp("10051", requestId, "工单在ERP不存在,请核对!");
  1551. }
  1552. for (int i = 0; i <main.size() ; i++) {
  1553. Object obj = main.get(i);
  1554. JSONObject object = JSON.parseObject(StringUtil.nvl(obj, ""));
  1555. Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.nvl(object.get("FDeptID"),"{}"));
  1556. Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.nvl(object.get("FFManagerID"),"{}"));
  1557. Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.nvl(object.get("FSManagerID"),"{}"));
  1558. Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.nvl(object.get("FBillerID"),"{}"));
  1559. frob = Integer.parseInt(StringUtil.nvl(object.get("FROB"), "99"));
  1560. taskType = StringUtil.nvl(object.get("TaskType"), "");
  1561. if ("OS".equals(ma_tasktype)) {
  1562. tlpiclass = "委外退料单";
  1563. tlcaller = "ProdInOut!OutsideReturn";
  1564. piclass="'委外领料单','委外退料单'";
  1565. }
  1566. String fSelBillNo = StringUtil.nvl(object.get("FSelBillNo"), "");
  1567. ApiResult<String> result = checkMESCode(requestId, fSelBillNo, tlpiclass);
  1568. if (result!=null){
  1569. return result;
  1570. }
  1571. tlid = baseDao.getSeqId("PRODINOUT_SEQ");
  1572. tlcode = baseDao.sGetMaxNumber(tlcaller, 2);
  1573. 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('"+object.get("Fdate")+"','yyyy-MM-dd HH24:mi:ss'),'"+tlpiclass+"','已审核','AUDITED','"+map5.get("FName")+"',to_date('"+object.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+"')");
  1574. }
  1575. Object[] warehouses =null;
  1576. if(detail!=null&&detail.size()>0) {
  1577. int detno=1;
  1578. for (int i = 0; i < detail.size(); i++) {
  1579. JSONObject object = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
  1580. Object lineId = object.get("lineId");
  1581. //物料资料
  1582. Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
  1583. String itemNo = StringUtil.nvl(map.get("FNumber"), "");
  1584. if ("".equals(itemNo)){
  1585. return ApiResponse.failRsp("10052",requestId,"物料不能为空!");
  1586. }
  1587. //退料数量
  1588. Double qty =Double.parseDouble(StringUtil.nvl(object.get("FAuxQty"), "0"));
  1589. if (qty==0){
  1590. return ApiResponse.failRsp("10053",requestId,"实发数量不能为空!");
  1591. }
  1592. //退回仓库
  1593. Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
  1594. String whcode = StringUtil.nvl(map2.get("FNumber"), "");
  1595. if ("".equals(whcode)) {
  1596. return ApiResponse.failRsp("10055", requestId, "物料退回仓库不能为空!");
  1597. }
  1598. 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 + "'");
  1599. if (count <= 0) {
  1600. return ApiResponse.failRsp("10056", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1601. }
  1602. warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on " +
  1603. "cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description,wh_nocost", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
  1604. Double outqty = Double.parseDouble(StringUtil.nvl(baseDao.getFieldDataByCondition("prodiodetail left join Warehouse on pd_whcode=wh_code", "sum(nvl(pd_outqty,0)-nvl(pd_inqty,0))", "pd_piclass in ("+piclass+ ") and pd_ordercode='" + macode + "' and pd_prodcode='" + itemNo + "' and nvl(wh_nocost,0)=" + warehouses[2]),"0"));
  1605. if (qty.compareTo(outqty) > 0) {
  1606. return ApiResponse.failRsp("10058", requestId, "退料数量不允许超过对应的发料数,请确定仓库属性和领料数量!");
  1607. }
  1608. String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
  1609. int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
  1610. if (count1<=0){
  1611. return ApiResponse.failRsp("10075",requestId,"工单BOM不存在或ID不一致,请联系管理员处理!");
  1612. }
  1613. 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+")");
  1614. Object prid = baseDao.getFieldDataByCondition("Product", "pr_id", "pr_code='" + itemNo + "'");
  1615. 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+"',"+detno+ ",0,'ENTERING','在录入','"+itemNo+"','"+ficmoBillNo+"',"+objs[2]+",'"+ficmoBillNo+"',"+objs[2]+ ",'"+objs[3]+"','"+objs[5]+"',"+lineId+","+prid+",'"+warehouses[0]+"','"+warehouses[1]+"',"+qty+ ",'"+taskType+"')");
  1616. detno++;
  1617. }
  1618. 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="
  1619. + tlid);
  1620. 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="
  1621. + tlid);
  1622. if ("OS".equals(ma_tasktype)) {
  1623. 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);
  1624. }
  1625. if (warehouses!=null){
  1626. sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+tlid);
  1627. }
  1628. }
  1629. baseDao.execute(sqls);
  1630. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1631. if(!baseDao.isDBSetting(tlcaller,"AllowPost")){
  1632. return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+",请在ERP查看并手工过账!");
  1633. }
  1634. String s = postProdInOut(tlid, tlcaller, employee);
  1635. logger.info("新生产退料单过账信息:"+s);
  1636. if (s!=null) {
  1637. return ApiResponse.successRsp("0", requestId, tlpiclass + ":" + tlcode + ",过账失败,请在ERP重新过账!");
  1638. }
  1639. return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+",请在ERP查看!");
  1640. }
  1641. @Override
  1642. public ApiResult<String> productWhQty(HttpServletRequest request) {
  1643. String requestId = request.getHeader("RequestId");
  1644. JSONObject data = getJsonData(request);
  1645. if (data!=null){
  1646. List<Map<String, Object>> maps = new ArrayList<>();
  1647. //物料
  1648. String itemNo = StringUtil.nvl(data.get("ItemNo"), "");
  1649. if ("".equals(itemNo)){
  1650. return ApiResponse.failRsp("10071",requestId,"物料不能为空!");
  1651. }
  1652. //仓库
  1653. String whCode = StringUtil.nvl(data.get("WhCode"), "");
  1654. if ("".equals(whCode)) {
  1655. SqlRowList rs = baseDao.queryForRowSet("select pw_whcode,sum(nvl(pw_onhand,0)) qty from productwh where pw_prodcode='" + itemNo + "' group by pw_whcode");
  1656. while (rs.next()){
  1657. SqlRowList rowSet = baseDao.queryForRowSet("select cd_varchar50_3,cd_varchar50_1 from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and nvl(cd_varchar50_1,' ')<>' ' and cd_varchar50_3='" + rs.getGeneralString("pw_whcode") + "' order by ct_id desc,cd_id desc");
  1658. if (rowSet.next()){
  1659. Map<String, Object> map = new HashMap<>();
  1660. map.put("whCode",rowSet.getString("cd_varchar50_1"));
  1661. map.put("qty",rs.getGeneralDouble("qty"));
  1662. maps.add(map);
  1663. }
  1664. }
  1665. }else {
  1666. 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 + "'");
  1667. if (count <= 0) {
  1668. return ApiResponse.failRsp("10072", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1669. }
  1670. 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,wh_nocost", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whCode + "'");
  1671. Double qty = baseDao.getSummaryByField("productwh", "pw_onhand", "pw_prodcode='" + itemNo + "' and pw_whcode='" + warehouses[0] + "'");
  1672. Map<String, Object> map = new HashMap<>();
  1673. map.put("whCode", whCode);
  1674. map.put("qty", qty);
  1675. maps.add(map);
  1676. }
  1677. if (maps==null){
  1678. return ApiResponse.failRsp("10073",requestId,"未找到数据!");
  1679. }else {
  1680. return ApiResponse.successRsp("0", "获取成功!",requestId, JSON.toJSONString(maps));
  1681. }
  1682. }else {
  1683. return ApiResponse.failRsp("10074",requestId,"参数异常!");
  1684. }
  1685. }
  1686. @Override
  1687. public ApiResult<String> confirmMakeScrap(HttpServletRequest request) {
  1688. String requestId = request.getHeader("RequestId");
  1689. JSONObject data = getJsonData(request);
  1690. if (data != null) {
  1691. String apCode = null;
  1692. String msclass = "生产报废单";
  1693. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1694. String msId = StringUtil.nvl(data.get("scrapid"), "");
  1695. if (baseDao.checkIf("MakeScrap","ms_statuscode='CONFIRMED' and ms_id="+msId)){
  1696. return ApiResponse.failRsp("10075",requestId,"生产报废单已确认!");
  1697. }
  1698. baseDao.updateByCondition("MakeScrapdetail", "md_status=99", "md_msid=" + msId);
  1699. List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode ", new String[]{
  1700. "ma_id", "md_mmdetno", "md_qty", "md_prodcode"}, " md_msid=" + msId);
  1701. for (Object[] object : objects) {
  1702. baseDao.updateByCondition("Makematerial ", "mm_scrapqty =nvl(mm_scrapqty,0)+" + object[2], "mm_detno=" + object[1]
  1703. + " and mm_maid=" + object[0]);
  1704. baseDao.updateByCondition("Makematerial ", "mm_repscrapqty =nvl(mm_repscrapqty,0)+" + object[2], "mm_detno=" + object[1]
  1705. + " and mm_maid=" + object[0] + " and mm_prodcode<>'" + object[3] + "'");
  1706. baseDao.updateByCondition("Makematerialreplace ", "mp_scrapqty =nvl(mp_scrapqty,0)+" + object[2], " mp_maid=" + object[0]
  1707. + " and mp_mmdetno=" + object[1] + " and mp_prodcode='" + object[3] + "'");
  1708. }
  1709. // 执行审核操作
  1710. baseDao.updateByCondition("MakeScrap", "ms_status='已确认',ms_statuscode='CONFIRMED'", "ms_id=" + msId);
  1711. // 记录操作
  1712. baseDao.execute("INSERT INTO MessageLog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search) VALUES (MessageLog_seq.nextval,sysdate,'mes','确认操作','确认成功','MakeScrap|ms_id=" + msId + "')");
  1713. //生成超损请购
  1714. int apId = baseDao.getSeqId("APPLICATION_SEQ");
  1715. apCode = baseDao.sGetMaxNumber("Application", 2);
  1716. Object dpcode = baseDao.getFieldDataByCondition("MakeScrapDetail", "min(md_department)", "md_msid=" + msId);
  1717. baseDao.execute("insert into Application (ap_id,ap_code,ap_kind,ap_date,ap_statuscode,ap_status,ap_pleamanname,ap_pleamanid,ap_recorder,ap_recorderid,ap_recorddate,ap_departcode,ap_departname,ap_source,ap_sourceid,ap_printstatuscode,ap_printstatus,ap_remark,ap_bfcode_user) " +
  1718. " select " + apId + ",'" + apCode + "','超损请购',sysdate,'ENTERING','在录入','" + employee.getEm_name() + "'," + employee.getEm_id() + ",'" + employee.getEm_name() + "'," + employee.getEm_id() + ",sysdate,'" + dpcode + "',dp_name,'" + msclass + "',ms_id,'UNPRINT','未打印','MES生产报废单确认生成',ms_code from MakeScrap,department where dp_code='" + dpcode + "' and ms_id=" + msId);
  1719. baseDao.execute("insert into applicationdetail (ad_id,ad_apid,ad_code,ad_detno,ad_prodcode,ad_qty,ad_use,ad_statuscode,ad_status,ad_source,ad_sourcecode,ad_remark,ad_zzcode_user,ad_zzxh_user,ad_sacode,ad_sadetno) " +
  1720. "select APPLICATIONDETAIL_SEQ.nextval," + apId + ",'" + apCode + "',md_detno,md_prodcode,md_qty,md_reason,'ENTERING','在录入','" + msclass + "',md_code,'MES生产报废单审核生成',md_mmcode,md_mmdetno,ma_salecode,ma_saledetno from MakeScrapdetail left join make on md_mmcode=ma_code where md_msid=" + msId);
  1721. baseDao.execute("update applicationdetail set ad_kcqty=(select ad_qty/(case when nvl(pr_purcrate,0)=0 then 1 else pr_purcrate end) from product where pr_code=ad_prodcode) where ad_apid=" + apId);
  1722. return ApiResponse.successRsp("0", requestId, "请购单:" + apCode + ",请在ERP查看!");
  1723. }else {
  1724. return ApiResponse.failRsp("10074",requestId,"参数异常!");
  1725. }
  1726. }
  1727. @Override
  1728. public ApiResult<String> confirmSendNotify(HttpServletRequest request) {
  1729. String requestId = request.getHeader("RequestId");
  1730. List<Map<Object, Object>> maps = getJsonsData(request);
  1731. if (maps!=null&&!maps.isEmpty()){
  1732. List<Map<String, Object>> hashMaps = new ArrayList<>();
  1733. List<Key> keys = new ArrayList<>();
  1734. for (Map<Object, Object> map:maps) {
  1735. int sndId = Integer.parseInt(StringUtil.nvl(map.get("sndId"), "0"));
  1736. if (sndId>0){
  1737. int snId = Integer.parseInt(StringUtil.nvl(baseDao.getFieldDataByCondition("SendNotifyDetail", "snd_snid", "snd_id=" + sndId), "0"));
  1738. if (!baseDao.checkIf("SendNotifyDetail","snd_id="+sndId)){
  1739. return ApiResponse.failRsp("10079", requestId, "明细行不存在,请核对!");
  1740. }
  1741. if (!baseDao.checkIf("SendNotify", "sn_id=" + snId)) {
  1742. return ApiResponse.failRsp("10071", requestId, "出货通知单不存在,无法确认!");
  1743. }
  1744. if (!baseDao.checkIf("SendNotify", "sn_statuscode='AUDITED' and sn_id=" + snId)) {
  1745. return ApiResponse.failRsp("10072", requestId, "出货通知单不是已审核状态,无法确认!");
  1746. }
  1747. if (baseDao.checkIf("SendNotify", "sn_sendstatus='已出库' and sn_id=" + snId)) {
  1748. String inoutno = StringUtil.nvl(baseDao.getFieldDataByCondition("prodiodetail", "pd_inoutno", "pd_piclass='出货单' and pd_orderid=" + sndId), "");
  1749. return ApiResponse.successRsp("0", requestId, "出货单:" + inoutno + ",请在ERP查看!");
  1750. //return ApiResponse.failRsp("10073", requestId, "出货通知单已出货,无需重新确认生成!");
  1751. }
  1752. if (baseDao.checkIf("ProdIODetail", "pd_piclass='出货单' and pd_orderid=" + sndId)) {
  1753. return ApiResponse.failRsp("10074", requestId, "出货通知单已转出货单,无需重新确认生成!");
  1754. }
  1755. // 存在未审批变更单
  1756. String dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_id=" + sndId + " and exists (select 1 from SaleChangeDetail left join SaleChange on sc_id=scd_scid where scd_sacode=snd_ordercode and scd_sddetno=snd_orderdetno and sc_statuscode<>'AUDITED' )", String.class);
  1757. if (dets != null) {
  1758. return ApiResponse.failRsp("10075", requestId, "存在待审批的销售变更单,不能进行转出操作!行号:" + dets);
  1759. }
  1760. dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_id=" + sndId + " and exists (select 1 from SendNotifyChange left join SendNotifyChangeDetail on sc_id=scd_scid where sc_sncode=snd_code and scd_snddetno=snd_pdno and sc_statuscode<>'AUDITED')", String.class);
  1761. if (dets != null) {
  1762. return ApiResponse.failRsp("10076", requestId, "存在待审批的通知变更单,不能进行转出操作!行号:" + dets);
  1763. }
  1764. if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {
  1765. dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_id=" + sndId + " and sn_custcode in (select cu_code from customer where cu_status='挂起') and not exists (select 1 from saledetail where sd_code=snd_ordercode and sd_detno=snd_orderdetno and nvl(sd_price,0)=0)", String.class);
  1766. if (dets != null) {
  1767. return ApiResponse.failRsp("10077", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
  1768. }
  1769. } else {
  1770. dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_id=" + sndId + " and sn_custcode in (select cu_code from customer where cu_status='挂起')", String.class);
  1771. if (dets != null) {
  1772. return ApiResponse.failRsp("10078", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
  1773. }
  1774. }
  1775. dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from SendNotifyDetail where nvl(snd_statuscode, ' ')<>'AUDITED' and snd_id=" + sndId, String.class);
  1776. if (dets != null) {
  1777. return ApiResponse.failRsp("10079", requestId, "明细行状态不等于已审核,不能进行转出操作!" + dets);
  1778. }
  1779. double tqty = Double.parseDouble(StringUtil.nvl(map.get("tqty"), "0"));
  1780. String prodCode = StringUtil.nvl(map.get("prodCode"), "");
  1781. String whCode = StringUtil.nvl(map.get("whCode"), "");
  1782. if ("".equals(prodCode)){
  1783. return ApiResponse.failRsp("10063",requestId,"物料不能为空!");
  1784. }
  1785. if (!baseDao.checkIf("SendNotifyDetail","snd_prodcode='"+prodCode+"' and snd_id="+sndId)){
  1786. return ApiResponse.failRsp("10079", requestId, "明细行物料不存在,请核对!");
  1787. }
  1788. if ("".equals(whCode)){
  1789. return ApiResponse.failRsp("10063",requestId,"仓库不能为空!");
  1790. }
  1791. 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 + "'");
  1792. if (count<=0){
  1793. return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
  1794. }
  1795. Object[] wh = 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 + "'");
  1796. if (tqty<=0){
  1797. return ApiResponse.failRsp("10063",requestId,"数量需要大于0!");
  1798. }
  1799. if (baseDao.checkIf("SendNotifyDetail","nvl(snd_yqty,0)+"+tqty+">nvl(snd_outqty,0) and snd_id="+sndId)){
  1800. return ApiResponse.failRsp("10063",requestId,"数量+已转出货数不能大于通知单数量!");
  1801. }
  1802. List<Map<String, Object>> mapList = baseDao.queryForList("select "+tqty+" snd_tqty,'"+wh[0]+"' snd_warehousecode,'"+wh[1]+"' snd_warehouse,sn_code,sn_custcode,snd_prodcode,sn_currency,sn_rate,sn_paymentscode,sn_shcustcode,sn_arcustcode,snd_id,sn_id from SendNotify left join SendNotifyDetail on sn_id=snd_snid left join Product on snd_prodcode=pr_code where snd_id=" + sndId);
  1803. hashMaps.addAll(mapList);
  1804. }
  1805. }
  1806. List<Map<Object, Object>> mapList = BaseUtil.parseGridStoreToMaps(StringUtil.nvl(baseDao.changeKeyToLowerCase(hashMaps), "[{}]"));
  1807. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1808. Map<Object, List<Map<Object, Object>>> groups = BaseUtil.groupsMap(mapList, new Object[] {"sn_custcode","sn_shcustcode","sn_currency","sn_arcustcode","sn_paymentscode"});
  1809. // 按客户分组的转入操作
  1810. Set<Object> mapSet = groups.keySet();
  1811. List<Map<Object, Object>> items;
  1812. for (Object s : mapSet) {
  1813. items = groups.get(s);
  1814. // 转入通知单主记录
  1815. Integer sn_id = baseDao.getFieldValue("SendNotifyDetail", "snd_snid", "snd_id=" + items.get(0).get("snd_id"),
  1816. Integer.class);
  1817. Key key = transferRepository.transfer("ProdInOut!Sale", sn_id, employee);
  1818. if (key != null) {
  1819. keys.add(key);
  1820. int pi_id = key.getId();
  1821. // 转入明细
  1822. transferRepository.transfer("ProdInOut!Sale", items, key, employee);
  1823. // 地址
  1824. baseDao.execute(
  1825. "update ProdInOut set pi_address=(select cu_add1 from customer where pi_cardcode=cu_code) where pi_id=? and nvl(pi_address,' ')=' '",
  1826. pi_id);
  1827. baseDao.execute("update prodinout set (pi_purposename,pi_expresscode,pi_fax)=(select max(ca_person),max(ca_phone),max(ca_fax) from CustomerAddress left join customer on ca_cuid=cu_id where cu_code=pi_cardcode and ca_address=pi_address) where pi_id="
  1828. + pi_id);
  1829. baseDao.execute(
  1830. "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 nvl(pi_whcode,' ')=' ' and pi_id=?",
  1831. pi_id);
  1832. baseDao.execute(
  1833. "update ProdIODetail set pd_taxtotal=round(pd_sendprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2), pd_nettotal=round(pd_netprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2) WHERE pd_piid=?",
  1834. pi_id);
  1835. baseDao.execute("update ProdIODetail set pd_ordertotal=round(pd_outqty*pd_sendprice,2) where pd_piid=?", pi_id);
  1836. baseDao.updateByCondition(
  1837. "ProdIODetail",
  1838. "pd_netprice=round(pd_sendprice/(1+pd_taxrate/100),8),pd_nettotal=round(pd_sendprice*pd_outqty/(1+nvl(pd_taxrate,0)/100),2)",
  1839. "pd_piid=" + pi_id);
  1840. baseDao.execute(
  1841. "update ProdInOut set pi_total=(SELECT round(sum(nvl(pd_sendprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid=pi_id) where pi_id=?",
  1842. pi_id);
  1843. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  1844. return ApiResponse.successRsp("0", requestId, "出货单:" + key.getCode() + ",请在ERP查看!");
  1845. } else
  1846. return ApiResponse.failRsp("10080", requestId, "生成失败!");
  1847. }
  1848. // 修改出货通知单状态
  1849. Map<Object, List<Map<Object, Object>>> listMap = BaseUtil.groupsMap(mapList, new Object[]{"sn_id"});
  1850. // 按客户分组的转入操作
  1851. Set<Object> mSet = listMap.keySet();
  1852. for (Object obj : mSet) {
  1853. String statuscode = null, status = null;
  1854. int count = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj);
  1855. int yCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj + " and nvl(snd_yqty,0)=nvl(snd_outqty,0) and nvl(snd_yqty,0)>=0");
  1856. int xCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj + " and nvl(snd_yqty,0)=0");
  1857. statuscode = "PARTOUT";
  1858. status = "部分出库";
  1859. if (xCount == count) {
  1860. statuscode = "";
  1861. status = "";
  1862. }
  1863. if (yCount == count) {
  1864. statuscode = "TURNOUT";
  1865. status = "已出库";
  1866. }
  1867. baseDao.updateByCondition("SendNotify", "SN_SENDSTATUSCODE='" + statuscode + "',SN_SENDSTATUS='" + status + "'", "sn_id=" + obj);
  1868. }
  1869. if (keys!=null&&!keys.isEmpty()) {
  1870. String code="";
  1871. for (Key key:keys) {
  1872. //过账出货单
  1873. String s = postProdInOut(key.getId(), "ProdInOut!Sale", employee);
  1874. code=code+key.getCode()+",";
  1875. }
  1876. return ApiResponse.successRsp("0", requestId, "出货单:" + code + ",请在ERP查看!");
  1877. }else
  1878. return ApiResponse.failRsp("10082",requestId,"生成失败!");
  1879. } else
  1880. return ApiResponse.failRsp("10081",requestId,"参数异常!");
  1881. }
  1882. @Override
  1883. public ApiResult<String> confirmProdInOutMakeGive(HttpServletRequest request) {
  1884. String requestId = request.getHeader("RequestId");
  1885. JSONObject jsonData = getJsonData(request);
  1886. if (jsonData!=null&&jsonData.size()>0){
  1887. int erpId = Integer.parseInt(StringUtil.nvl(jsonData.get("erpId"), "0"));
  1888. if (erpId>0){
  1889. if (baseDao.checkIf("prodinout","pi_id="+erpId)){
  1890. Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
  1891. String s = postProdInOut(erpId, "ProdInOut!Make!Give", employee);
  1892. Object data = baseDao.getFieldDataByCondition("prodinout", "pi_inoutno", "pi_id=" + erpId);
  1893. if (s!=null) {
  1894. return ApiResponse.failRsp("10094", requestId, "生产补料单:" +data+",过账失败!异常信息:"+s);
  1895. }else
  1896. return ApiResponse.successRsp("0", requestId, "生产补料单:" +data+ "已过账,请在ERP查看!");
  1897. }else
  1898. return ApiResponse.failRsp("10093",requestId,"生产领料单不存在,请核对!");
  1899. }else
  1900. return ApiResponse.failRsp("10092",requestId,"参数异常!");
  1901. }else
  1902. return ApiResponse.failRsp("10091",requestId,"参数异常!");
  1903. }
  1904. private Map<String, JSONArray> getData(HttpServletRequest request){
  1905. Map<String, JSONArray> map = new HashMap<>();
  1906. try {
  1907. String data = PSHttpUtils.readRaw(request.getInputStream());
  1908. JSONObject jsonObject = JSON.parseObject(data);
  1909. Object data1 = jsonObject.get("Data");
  1910. JSONObject jsonObject1 = JSON.parseObject(StringUtil.nvl(data1,""));
  1911. Object page1 = jsonObject1.get("Page1");
  1912. Object page2 = jsonObject1.get("Page2");
  1913. JSONArray jsonArray = JSON.parseArray(StringUtil.nvl(page1, ""));
  1914. map.put("main",jsonArray);
  1915. JSONArray jsonArray1 = JSON.parseArray(StringUtil.nvl(page2, ""));
  1916. map.put("detail",jsonArray1);
  1917. } catch (IOException e) {
  1918. logger.info("参数解析异常信息:"+e.getMessage());
  1919. e.printStackTrace();
  1920. }
  1921. return map;
  1922. }
  1923. private JSONObject getJsonData(HttpServletRequest request){
  1924. JSONObject jsonObject=null;
  1925. try {
  1926. String data = PSHttpUtils.readRaw(request.getInputStream());
  1927. jsonObject = JSON.parseObject(data);
  1928. } catch (IOException e) {
  1929. logger.info("参数解析异常信息:"+e.getMessage());
  1930. e.printStackTrace();
  1931. }
  1932. return jsonObject;
  1933. }
  1934. private List<Map<Object, Object>> getJsonsData(HttpServletRequest request){
  1935. try {
  1936. String data = PSHttpUtils.readRaw(request.getInputStream());
  1937. return BaseUtil.parseGridStoreToMaps(data);
  1938. } catch (IOException e) {
  1939. logger.info("参数解析异常信息:"+e.getMessage());
  1940. e.printStackTrace();
  1941. }
  1942. return null;
  1943. }
  1944. private ApiResult<String> checkMESCode(String requestId,String mesNo,String piclass){
  1945. if ("".equals(mesNo)){
  1946. return ApiResponse.failRsp("10100", requestId, "MES单号不能为空!");
  1947. }
  1948. int count = baseDao.getCount("select count(1) from prodinout where pi_class='" + piclass + "' and pi_mescode='" + mesNo + "'");
  1949. if (count>0){
  1950. Object code = baseDao.getFieldDataByCondition("prodinout", "pi_inoutno", "pi_class='" + piclass + "' and pi_mescode='" + mesNo + "'");
  1951. return ApiResponse.successRsp("0",requestId,"MES单号:"+mesNo+"已存在,请在ERP查看"+piclass+",单据编号:"+code);
  1952. }
  1953. return null;
  1954. }
  1955. private synchronized String postProdInOut(int pi_id, String caller,Employee employee) {
  1956. // 增加系统参数 出入库日期小于等于当前日期才允许过账 maz 2018020006
  1957. if (baseDao.isDBSetting("sys", "limitPostAfter")) {
  1958. Object pi_date = baseDao.getFieldDataByCondition("ProdInOut", "pi_date", "pi_id=" + pi_id);
  1959. String sysdate = DateUtil.getCurrentDate();
  1960. int sign = 0;
  1961. sign = DateUtil.compare(pi_date.toString(), sysdate);
  1962. if (sign == 1) {
  1963. return "单据日期大于当前日期,不能过账";
  1964. }
  1965. }
  1966. // 只能对状态为[未过账]的单据进行过账操作!
  1967. Object[] status = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_statuscode", "pi_invostatuscode", "pi_date", "pi_class", "pi_recordman", "pi_inoutno" }, "pi_id=" + pi_id);
  1968. if (status[0].equals("POSTED")) {
  1969. return "只能对未过账的" + status[3] + "[" + status[5] + "]进行过账操作!";
  1970. }
  1971. // 2018030244 maz 送货单号不一致不允许提交
  1972. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!DefectIn".equals(caller)) {
  1973. if (baseDao.isDBSetting("VerifyApplyDetail!Deal", "turnByDeliver")) {
  1974. SqlRowList rs = baseDao
  1975. .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="
  1976. + pi_id + " and nvl(pi_sendcode,' ')<>nvl(va_sendcode,' ')");
  1977. if (rs.next()) {
  1978. return "行号:" + rs.getInt("pd_pdno") + "送货单号不一致,不允许操作";
  1979. }
  1980. }
  1981. }
  1982. // 明细中如果有属于物料等级属于库存不可用的,就提示这些物料当前等级库存不可用
  1983. SqlRowList rowList = baseDao
  1984. .queryForRowSet(
  1985. "select wm_concat(pd_prodcode) prodcode from (select distinct pd_prodcode from prodiodetail "
  1986. + "left join product on pd_prodcode=pr_code left join productlevel on pr_level=pl_levcode where pd_piid=? and pl_id>0 "
  1987. + "and pl_isuseable=0 ) where rownum<=20", pi_id);
  1988. if (rowList.next()) {
  1989. if (rowList.getString("prodcode") != null) {
  1990. return "这些物料当前等级库存不可用,物料编号:" + rowList.getString("prodcode");
  1991. }
  1992. }
  1993. 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="
  1994. + pi_id + " and nvl(pi_whcode,' ')= ' '");
  1995. // 判断已审核才允许过账
  1996. if (baseDao.isDBSetting(caller, "postNeedAudit")) {
  1997. if (!status[1].equals("AUDITED")) {
  1998. return status[3] + "[" + status[5] + "]未审核,不允许过账!";
  1999. }
  2000. }
  2001. String dets = baseDao
  2002. .getJdbcTemplate()
  2003. .queryForObject(
  2004. "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'",
  2005. String.class, pi_id);
  2006. if (dets != null) {
  2007. return "来源的" + dets + "未过账,本单据不允许过账!";
  2008. }
  2009. // 无来源订单不能直接过账
  2010. if (baseDao.isDBSetting(caller, "isWuPO")) {
  2011. int count = baseDao
  2012. .getCount("select count(*) from ProdIODetail where (pd_ordercode is null or pd_orderdetno is null) and pd_piid="
  2013. + pi_id);
  2014. if (!status[1].equals("AUDITED") && count != 0) {
  2015. return "无来源订单审核后才能过账";
  2016. }
  2017. }
  2018. boolean isProdIn=baseDao.isProdIn(caller);
  2019. if (isProdIn) {
  2020. // 检测入库单明细生产日期是否大于系统时间
  2021. if (baseDao.isDBSetting("sys","inOverNow")) {
  2022. dets = baseDao
  2023. .getJdbcTemplate()
  2024. .queryForObject(
  2025. "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') ",
  2026. String.class, pi_id);
  2027. if (dets != null) {
  2028. return "行:" + dets + ",明细生产日期不能大于系统日期所在年月!";
  2029. }
  2030. }
  2031. SqlRowList rs = null;
  2032. // 入库类单据:如果pd_location为空,默认等于物料资料里的仓位pr_location
  2033. baseDao.execute(
  2034. "update prodiodetail set pd_location=(select pr_location from product where pr_code=pd_prodcode) where pd_piid=? and nvl(pd_location,' ')=' '",
  2035. pi_id);
  2036. rs = baseDao.queryForRowSet("SELECT pd_id FROM ProdioDetail where pd_piid=? and nvl(pd_batchcode,' ')=' '", pi_id);
  2037. while (rs.next()) {
  2038. baseDao.execute("update prodiodetail set pd_batchcode=? where pd_id=?", baseDao.getBatchcode(caller), rs.getInt("pd_id"));
  2039. }
  2040. // 入库单有生成条码但条码对应的物料或数量或批次号与明细行不一致则不允许过账
  2041. rs = baseDao.queryForRowSet(
  2042. "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"
  2043. + " where bi_piid=? group by bi_pdno) on bi_pdno=pd_pdno where pd_piid=? and pd_inqty>0 and inqty>0 "
  2044. + " and (nvl(inqty,0)<>pd_inqty or bi_prodcode<>pd_prodcode or bi_batchcode<>pd_batchcode) and rownum<30",
  2045. pi_id, pi_id);
  2046. if (rs.next() && rs.getInt("cn") > 0) {
  2047. return "条码与明细行中的物料或数量或批次号不一致,不允许过账,请先清除不一致条码!行号:" + rs.getString("no");
  2048. }
  2049. } else {
  2050. SqlRowList rs = null;
  2051. rs = baseDao
  2052. .queryForRowSet(
  2053. "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",
  2054. pi_id);
  2055. while (rs.next()) {
  2056. if (rs.getGeneralDouble("ba_purcrate") != 0) {
  2057. baseDao.execute("update prodiodetail set pd_purcoutqty=round(nvl(pd_outqty,0)/" + rs.getGeneralDouble("ba_purcrate")
  2058. + ",8) where pd_id=" + rs.getObject("pd_id"));
  2059. } else {
  2060. baseDao.execute("update prodiodetail set pd_purcoutqty=nvl(pd_outqty,0) where pd_id=" + rs.getObject("pd_id"));
  2061. }
  2062. }
  2063. }
  2064. useDefaultTax(caller, pi_id);
  2065. String s = allowZeroTax(caller, pi_id);
  2066. if (s!=null){
  2067. return s;
  2068. }
  2069. String s1 = checkFreezeMonth(caller, status[2]);
  2070. if (s1!=null){
  2071. return s1;
  2072. }
  2073. String s2 = checkCloseMonth(status[2]);
  2074. if (s2!=null){
  2075. return s2;
  2076. }
  2077. String s3 = checkFirstMonth(caller, status[2]);
  2078. if (s3!=null){
  2079. return s3;
  2080. }
  2081. String s4 = checkCommit(caller, pi_id);
  2082. if (s4!=null){
  2083. return s4;
  2084. }
  2085. String s5 = checkBatch(caller, pi_id);
  2086. if (s5!=null){
  2087. return s5;
  2088. }
  2089. String copcheck = copcheck(pi_id, caller);
  2090. if (copcheck!=null){
  2091. return copcheck;
  2092. }
  2093. String factorycheck = factorycheck(pi_id, caller);
  2094. if (factorycheck!=null){
  2095. return factorycheck;
  2096. }
  2097. // 制造工单加工类型
  2098. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  2099. String s6 = checkMakeKindType(caller, pi_id);
  2100. if (s6!=null){
  2101. return s6;
  2102. }
  2103. }
  2104. // 暂时不启用平台 销售仓模式checkWhIsB2C(caller, pi_id);
  2105. /**
  2106. * 委外验收单,委外验退单 过账限制,判断明细行中的应付供应商或币别与主表是否一致,不一致则不允许过账;
  2107. */
  2108. if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  2109. SqlRowList rs = baseDao
  2110. .queryForRowSet(
  2111. "select wm_concat(pd_pdno) c from (select nvl(nvl(ma_apvendcode,ve_apvendcode),ve_code) apvendcode, pi_receivecode,pd_pdno "
  2112. + "from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join vendor "
  2113. + "on ma_vendcode=ve_code where pi_id=?) t where t.apvendcode <> t.pi_receivecode and rownum<30", pi_id);
  2114. if (rs.next()) {
  2115. if (rs.getObject("c") != null) {
  2116. return "明细行中委外加工单的应付供应商与主表中的应付供应商不一致!";
  2117. }
  2118. }
  2119. SqlRowList rs2 = baseDao.queryForRowSet("select wm_concat(pd_pdno) x from (select ma_currency,pi_currency,pd_pdno"
  2120. + " from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode"
  2121. + " where pi_id=?) t where t.ma_currency <> t.pi_currency and rownum<30", pi_id);
  2122. if (rs2.next()) {
  2123. if (rs2.getObject("x") != null) {
  2124. return "明细行中委外加工单的币别与主表中的币别不一致!";
  2125. }
  2126. }
  2127. }
  2128. // 完工入库,委外验收限制,入库数量不允许大于到当前pi_date的月份为止的(制造单生产的总数数量-已入库总数)
  2129. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  2130. // 存在pi_date 年月之后的 出入库单
  2131. int ym = DateUtil.getYearmonth(status[2].toString());
  2132. SqlRowList rs = baseDao
  2133. .queryForRowSet(
  2134. "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"
  2135. + " 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 "
  2136. + " where A.pd_ordercode=B.pd_ordercode and to_char(pi_date,'yyyyMM')>? and "
  2137. + " pi_class in('生产领料单','生产退料单','生产补料单','委外补料单','委外领料单','委外退料单') and B.pd_status=99) group by A.pd_ordercode",
  2138. pi_id, ym);
  2139. while (rs.next()) {
  2140. Object[] obs = baseDao
  2141. .getFieldsDataByCondition(
  2142. "make left join makematerial on mm_maid=ma_id",
  2143. new String[] {
  2144. " 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 "
  2145. + " where to_char(pi_date,'yyyyMM')>'"
  2146. + ym
  2147. + "' and pd_ordercode=ma_code and pd_orderdetno=mm_detno and pi_class in('生产领料单','生产退料单','生产补料单','委外补料单','委外领料单','委外退料单'))"
  2148. + " -nvl(mm_scrapqty,0))*1.0/mm_oneuseqty)end),0) as canmadeqty",
  2149. "nvl(max(ma_madeqty),0) -"
  2150. + "nvl(max((select SUM(NVL(pd_inqty,0)-NVL(pd_outqty,0)) from prodinout LEFT JOIN prodiodetail ON pd_piid=pi_id "
  2151. + " WHERE TO_CHAR(pi_date,'yyyyMM')>'" + ym + "' and pd_ordercode='"
  2152. + rs.getString("pd_ordercode")
  2153. + "' and pi_class in('完工入库单','委外验收单','委外验退单'))),0) as madeqty" },
  2154. " mm_code='" + rs.getString("pd_ordercode") + "' and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0");
  2155. if (obs != null) {// 比较
  2156. if (rs.getDouble("inqty") > (Double.valueOf(obs[0].toString()).doubleValue() - Double.valueOf(obs[1].toString())
  2157. .doubleValue())) {
  2158. return "工单[" + rs.getString("pd_ordercode") + "]当前月份领料套数(" + obs[0] + ")不足完工数";
  2159. }
  2160. }
  2161. }
  2162. }
  2163. /**
  2164. * 采购验收单、委外验收单 从表单位pr_unit与采购单位pr_purcunit不一致的时候,
  2165. * 数量pd_inqty与采购单位入库数量pd_purcinqty不能一致,否则无法提交、过账
  2166. */
  2167. if (baseDao.isDBSetting("sys","usePurcUnit") && ("ProdInOut!PurcCheckin".equals(caller) || ("ProdInOut" +
  2168. "!OutsideCheckIn").equals(caller))) {
  2169. String dets1 = baseDao.getJdbcTemplate().queryForObject(
  2170. "select wm_concat(pd_pdno) from ProdIODetail left join Product on pd_prodcode=pr_code where pd_piid=? "
  2171. + "and PR_UNIT is not null and pr_purcunit is not null "
  2172. + "and (nvl(pd_inqty,0)>0) and (nvl(pd_purcinqty,0)>0) "
  2173. + "and nvl(PR_UNIT,'')<>nvl(pr_purcunit,'') and nvl(pd_inqty,0)=nvl(pd_purcinqty,0)", String.class, pi_id);
  2174. if (dets1 != null) {
  2175. return "行" + dets1 + ",明细入库数量和采购单位入库数量需不一致,否则无法过账!";
  2176. }
  2177. }
  2178. /**
  2179. * 新增生产退料和委外退料判断,替代料退料数量不能大于替代料已领数量,禁用物料判断mm_updatetype='R',
  2180. *
  2181. * @date 2016年10月17日 下午12:30:58
  2182. */
  2183. if (("ProdInOut!Make!Return").equals(caller) || ("ProdInOut!OutsideReturn").equals(caller)) {
  2184. checkRepQty(pi_id);
  2185. /**
  2186. * 生产退料单,委外退料单 校验退料数量不能大于截止到单据日期月份 已过账的领料-退料-报废+补料-完工数*单位用量
  2187. */
  2188. checkMmBackOver(caller,pi_id);
  2189. }
  2190. /**
  2191. * 新增限制,拆件类型制造单不允许走完工入库单
  2192. *
  2193. * @author XiaoST 2016年12月9日 下午4:26:34
  2194. */
  2195. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  2196. dets = baseDao
  2197. .getJdbcTemplate()
  2198. .queryForObject(
  2199. "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",
  2200. String.class, pi_id);
  2201. if (dets != null) {
  2202. return "拆件工单必须走拆件入库单!" + dets;
  2203. }
  2204. }
  2205. baseDao.getEndDate(caller, pi_id);
  2206. String res = null;
  2207. // 平台生成的销售订单转出货单过账必须等于销售订单明细序号和数量
  2208. if ("ProdInOut!Sale".equals(caller)) {
  2209. SqlRowList rs = baseDao
  2210. .queryForRowSet(
  2211. "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",
  2212. pi_id);
  2213. while (rs.next()) {
  2214. rs = baseDao
  2215. .queryForRowSet(
  2216. "select distinct pd_ordercode pd_ordercode from prodiodetail where pd_piid=? and (pd_orderdetno not in (select sd_detno from saledetail where sd_code=?))"
  2217. + " OR "
  2218. + rs.getDouble("out_qty")
  2219. + " <>(select sd_qty from saledetail where sd_code=? and sd_detno=?) and pd_ordercode =?", pi_id,
  2220. rs.getString("sa_code"), rs.getString("sa_code"), rs.getString("pd_orderdetno"), rs.getString("sa_code"));
  2221. if (rs.next()) {
  2222. return "通过优软商城平台生成的发货单必须一次性发货,销售单号[" + rs.getString("pd_ordercode") + "]";
  2223. }
  2224. // 维护物流公司和物流单号
  2225. Object[] obs = baseDao.getFieldsDataByCondition("prodinout", new String[] { "pi_logisticscompany", "pi_logisticscode" },
  2226. "pi_id=" + pi_id);
  2227. if (obs[0] == null || obs[1] == null) {
  2228. return "请维护出货单的物流公司和物料单号信息!";
  2229. }
  2230. }
  2231. }
  2232. // 委外领、退、补单过账前
  2233. if ("ProdInOut!OutsidePicking".equals(caller) || "ProdInOut!OutsideReturn".equals(caller) || "ProdInOut!OSMake!Give".equals(caller)) {
  2234. // 更新:如果主表的应付供应商空,则取第一个工单的应付供应商ma_apvendcode,空则取工单供应商ma_vendcode
  2235. baseDao.execute("update prodinout set (pi_receivecode,pi_receivename)=(select code,ve_name from "
  2236. + "(select nvl(ma_apvendcode,ma_vendcode)code,ve_name from prodiodetail left join make on "
  2237. + "pd_ordercode=ma_code left join vendor on nvl(ma_apvendcode,ma_vendcode)=ve_code "
  2238. + "where pd_piid=? order by pd_pdno) where rownum=1 )" + "where nvl(pi_receivecode,' ')=' ' and pi_id=?", pi_id, pi_id);
  2239. // 判断主表应付供应商与从表工单应付供应商是否一致
  2240. SqlRowList pdnos = baseDao
  2241. .queryForRowSet(
  2242. "select wm_concat(pd_pdno) c from (select nvl(nvl(ma_apvendcode,ve_apvendcode),ve_code) apvendcode, pi_receivecode,pd_pdno "
  2243. + "from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join vendor "
  2244. + "on ma_vendcode=ve_code where pi_id=?) t where t.apvendcode <> t.pi_receivecode and rownum<30", pi_id);
  2245. if (pdnos.next()) {
  2246. if (pdnos.getObject("c") != null) {
  2247. return "行" + pdnos.getObject("c") + "工单应付供应商与主表应付供应商不一致,不能过账";
  2248. }
  2249. }
  2250. }
  2251. // @add20171103
  2252. if ("ProdInOut!PurcCheckin".equals(caller)) {// 采购验收单根据采购单号、序号,更新入库销售单号、序号
  2253. baseDao.execute(
  2254. "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 "
  2255. + " pd_ordercode=pu_code and pd_orderdetno=pd_detno) where pd_piid=?", pi_id);
  2256. }
  2257. // 生产退料单、委外退料单、拆件入库单、完工入库单、委外验收单,根据工单的订单号、订单序号能匹配到销售单号和序号(如果是预测单则不锁批记录)则更新到入库单明细的销售单号、序号
  2258. if ("ProdInOut!OutsideReturn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!Make!In".equals(caller)
  2259. || "ProdInOut!PartitionStockIn".equals(caller) || "ProdInOut!Make!Return".equals(caller)) {
  2260. baseDao.execute(
  2261. "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)"
  2262. + " 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)",
  2263. pi_id);
  2264. }
  2265. // 销售退货明细客户为空时=主表客户
  2266. if ("ProdInOut!SaleReturn".equals(caller)) {
  2267. baseDao.execute(
  2268. "update prodiodetail set (pd_custcode,pd_custname)=(select pi_cardcode,pi_title from prodinout where pd_piid=pi_id)"
  2269. + " where pd_piid=? and nvl(pd_custcode,' ')=' '", pi_id);
  2270. }
  2271. /*
  2272. * 退料数量不能大于维护的可退数量 String SQLStr_s = ""; SqlRowList rs_s; SQLStr_s=
  2273. * "select * from ProdIODetail left join make on ma_code=pd_ordercode"
  2274. * +" left join IO_MAKEMATERIAL_DETNO_VIEW on pd_orderdetno = mm_detno"
  2275. * +" where ma_id=mm_maid and pd_piid= '"+pi_id+"'"; rs_s =
  2276. * baseDao.queryForRowSet(SQLStr_s); if(rs_s.next()){ if
  2277. * (rs_s.getInt("pd_inqty")>rs_s.getInt("mm_havegetqty")) {
  2278. * BaseUtil.showError("工单序号[" + rs_s.getString("pd_orderdetno") +
  2279. * "]的退料数量不能大于维护的可退数量!'"); } }
  2280. */
  2281. // 过账前的其它逻辑
  2282. getTotal(pi_id, caller);// 调用过账存储过程前后都掉用一次gettotal方法,解决出入库单税率与发票不一致
  2283. getQtyTotal(pi_id, caller);
  2284. // 执行过账操作
  2285. Object[] objs = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_class", "pi_inoutno" }, "pi_id=" + pi_id);
  2286. if ("ProdInOut!CostChange".equals(caller)) {
  2287. res = baseDao.callProcedure("SP_PRODUCTCOSTADJUST", new Object[] { objs[0].toString(), objs[1].toString(), "" });
  2288. if (res != null && !res.trim().equals("")) {
  2289. return res;
  2290. }
  2291. } else {
  2292. baseDao.procedure("SP_GetCostPrice", new Object[] { objs[0].toString(), objs[1].toString() });
  2293. if (baseDao.isDBSetting("sys","SplitprodoutByseller")) {// 出单过账前取批号按照业务员pi_sellercode获取
  2294. res = baseDao.callProcedure("Sp_Splitprodout_Byseller",
  2295. new Object[] { objs[0].toString(), objs[1].toString(),employee.getEm_name()});
  2296. } else {
  2297. res = baseDao.callProcedure("Sp_SplitProdOut",
  2298. new Object[] { objs[0].toString(), objs[1].toString(),employee.getEm_name()});
  2299. }
  2300. if (res != null && !res.trim().equals("")) {
  2301. // 重新添加提示限制信息
  2302. return res + " " + objs[0].toString() + objs[1].toString() + ",过账失败";
  2303. // BaseUtil.showError(res);
  2304. }
  2305. // @add 20170614 抓取批次号成功之后更新出库单据的备料状态
  2306. updatePdaStatus(caller, pi_id);
  2307. if (baseDao.isDBSetting(caller, "ifBatchCodeNotChange") && baseDao.isDBSetting(caller, "autoPostIn")) {
  2308. // 拨出单过账后产生的拨入单批号不变,同一物料同仓库不能同时入两次相同的批号
  2309. SqlRowList rs1 = baseDao
  2310. .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="
  2311. + pi_id + " and pd_batchcode<>' ' group by pd_batchcode,pd_inwhcode,pd_prodcode ) where c> 1");
  2312. if (rs1.next()) {
  2313. if (rs1.getInt("n") > 0) {
  2314. return "拨出单过账后产生的拨入单批号不变,同一物料同拨入仓库批号不能相同!行号:" + rs1.getString("detno");
  2315. }
  2316. }
  2317. }
  2318. String s7 = checkBatchRemain(pi_id);
  2319. if (s7!=null){
  2320. return s7;
  2321. }
  2322. dets = baseDao
  2323. .getJdbcTemplate()
  2324. .queryForObject(
  2325. "select wmsys.wm_concat(a2.pd_pdno) from prodinout a1 left join prodiodetail a2 on a1.pi_id=a2.pd_piid " +
  2326. "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 " +
  2327. "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 " +
  2328. "and to_char(a1.pi_date,'yyyymm')<to_char(b1.pi_date,'yyyymm') and rownum<20",
  2329. String.class, pi_id);
  2330. if (dets != null) {
  2331. return "出库单据日期所在期间小于批次入库日期所在期间,不能过账!行号:" + dets;
  2332. }
  2333. // 存储过程
  2334. res = baseDao.callProcedure("Sp_CommitProdInout",
  2335. new Object[] { objs[0].toString(), objs[1].toString(), employee.getEm_name()});
  2336. if (res != null && !res.trim().equals("")) {
  2337. return res;
  2338. }
  2339. if (baseDao.isDBSetting("sys","autoCreateApBill")) {
  2340. if ("采购验收单".equals(status[3]) || "采购验退单".equals(status[3]) || "委外验收单".equals(status[3]) || "委外验退单".equals(status[3])
  2341. || "用品验收单".equals(status[3]) || "用品验退单".equals(status[3])) {
  2342. dets = baseDao.queryForObject("select wm_concat(ab_code) from apbill where ab_source=? and ab_statuscode<>'POSTED'",
  2343. String.class, status[5]);
  2344. if (dets != null) {
  2345. return "发票" + dets + "未过账成功,请手工过账!";
  2346. }
  2347. }
  2348. }
  2349. if (baseDao.isDBSetting("sys","autoCreateArBill")) {
  2350. if ("出货单".equals(status[3]) || "销售退货单".equals(status[3])) {
  2351. dets = baseDao.queryForObject(
  2352. "select wm_concat(ab_code) from arbill where AB_SOURCECODE=? and ab_statuscode<>'POSTED'", String.class,
  2353. status[5]);
  2354. if (dets != null) {
  2355. return "发票" + dets + "未过账成功,请手工过账!";
  2356. }
  2357. }
  2358. }
  2359. }
  2360. getTotal(pi_id, caller);
  2361. getQtyTotal(pi_id, caller);
  2362. baseDao.updateByCondition("ProdInOut", "pi_statuscode='POSTED',pi_status='已过账',pi_inoutman='"+employee.getEm_name()+"'," + "pi_date1=sysdate,pi_sendstatus='待上传'", "pi_id=" + pi_id);
  2363. if (!baseDao.isIn(caller)) {// 出库类单据过账时,根据批号抓取batch.ba_vendorrate到prodiodetail.pd_vendorrate
  2364. baseDao.execute("update prodiodetail set pd_vendorrate=(select ba_vendorrate from batch where ba_code=pd_batchcode"
  2365. + " and ba_whcode =pd_whcode and ba_prodcode=pd_prodcode ) where pd_piid=" + pi_id + " and nvl(pd_vendorrate,0)=0");
  2366. }
  2367. if (baseDao.isDBSetting("sys","updateBusinessChance") && !"ProdInOut!GoodsIn".equals(caller)) {// 更新当前商机阶段
  2368. Object bsname = baseDao.getFieldDataByCondition("BusinessChanceStage", "bs_name", "bs_relativeitem='Shipment'");
  2369. Object date = baseDao.getFieldDataByCondition("ProdInOut", "to_char(pi_recorddate,'yyyy-MM-dd')", "pi_id=" + pi_id);
  2370. List<Object[]> data = baseDao.getFieldsDatasByCondition("prodiodetail left join ProdInOut on pd_piid=pi_id", new String[] {
  2371. "pd_bcid", "pd_prodcode", "pd_pdno" }, "pd_piid=" + pi_id);
  2372. for (Object[] os : data) {
  2373. if (os[0] == null || os[0].equals("") || os[0].equals("0") || Integer.parseInt(os[0].toString()) == 0) {
  2374. String sql = "update Prodiodetail set pd_bcid=nvl((select sd_bcid from saledetail "
  2375. + "where pd_ordercode=sd_code and pd_orderdetno=sd_detno),0) where pd_piid=" + pi_id + " and nvl(pd_bcid,0)=0";
  2376. baseDao.execute(sql);
  2377. }
  2378. Object pd_bcid = baseDao.getFieldDataByCondition("Prodiodetail", "pd_bcid", " pd_prodcode='" + os[1] + "' and pd_piid="
  2379. + pi_id);
  2380. if (pd_bcid == null || pd_bcid.equals("") || pd_bcid.equals("0") || Integer.parseInt(pd_bcid.toString()) == 0) {
  2381. String sql = "update prodiodetail set pd_bcid=nvl((select max(bc_id) from prodinout,businesschance "
  2382. + "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="
  2383. + pi_id + " and nvl(pd_bcid,0)=0";
  2384. baseDao.execute(sql);
  2385. }
  2386. Object bc_id = baseDao.getFieldDataByCondition("Prodiodetail", "pd_bcid", " pd_prodcode='" + os[1] + "' and pd_piid="
  2387. + pi_id);
  2388. Integer bs_detno = baseDao.getFieldValue("businesschancestage", "bs_detno", "bs_name='" + bsname + "'", Integer.class);
  2389. Integer bs_detno1 = baseDao.getFieldValue("businesschance left join businesschancestage on bs_name=bc_currentprocess",
  2390. "nvl(bs_detno,0)", "bc_id=" + bc_id, Integer.class);
  2391. if (bs_detno != null && bs_detno1 != null) {
  2392. if (bs_detno >= bs_detno1) {
  2393. baseDao.updateByCondition("BusinessChance", "bc_currentprocess='" + bsname + "',bc_desc" + bs_detno + "='" + bsname
  2394. + "',bc_date" + bs_detno + "=to_date('" + date.toString() + "','yyyy-MM-dd')", "bc_id=" + bc_id);
  2395. if (bsname != null && Integer.parseInt(pd_bcid.toString()) != 0) {
  2396. Object bscode = baseDao.getFieldDataByCondition("BusinessChanceStage", "bs_code", "bs_name='" + bsname + "'");
  2397. // 插入一条记录到商机动态表
  2398. int bcd_id = baseDao.getSeqId("BusinessChanceData_seq");
  2399. String link = "jsps/scm/reserve/prodInOut.jsp?whoami=ProdInOut!Sale&formCondition=pi_idIS" + pi_id
  2400. + "&gridCondition=pd_piidIS" + pi_id;
  2401. 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 ("
  2402. + bcd_id
  2403. + ","
  2404. + bc_id
  2405. + ",'"
  2406. + baseDao.sGetMaxNumber("BusinessChanceData", 2)
  2407. + "','"
  2408. + bscode
  2409. + "','"
  2410. + bsname
  2411. + "',"
  2412. + "to_date('"
  2413. + date.toString()
  2414. + "','yyyy-MM-dd')"
  2415. + ",'"
  2416. + status[4]
  2417. + "','"
  2418. + "ENTERING" + "','在录入','" + status[5] + "','" + link + "')";
  2419. baseDao.execute(contactSql);
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. // 调用冲销
  2426. createSaleClash(pi_id, "ProdInOut",employee);
  2427. if ("ProdInOut!AppropriationOut".equals(caller) || "ProdInOut!SaleAppropriationOut".equals(caller)) {
  2428. dets = null;
  2429. if (baseDao.isDBSetting(caller, "autoPostIn")) {
  2430. // 过账销售拨入单
  2431. dets = turnProdIO(pi_id,employee);
  2432. // 过账失败提醒
  2433. boolean showTurnProdIOError = baseDao.checkIf("ProdInOut",
  2434. "pi_class='拨入单' and pi_statuscode='UNPOST' and pi_inoutno=(select pi_relativeplace from ProdInOut where pi_class='拨出单' and pi_id="
  2435. + pi_id + ")");
  2436. if (showTurnProdIOError) {
  2437. return "自动过账失败";
  2438. }
  2439. }
  2440. if (dets != null) {
  2441. return "拨入单明细行仓库对应的仓管员与当前过账人不一致,不允许进行当前操作!行号:" + dets;
  2442. }
  2443. if (baseDao.isDBSetting(caller, "autoPostMakeLSSend")) {// MakeSendLS
  2444. // 拉式发料
  2445. // 拨出单过账,拨入也过账时自动过账领料单
  2446. String SQLStr = "";
  2447. String Outpiclass = "";
  2448. SQLStr = "select pi_inoutno from prodinout where pi_id=" + pi_id + " and pi_statuscode='POSTED'";
  2449. SqlRowList rs0 = baseDao.queryForRowSet(SQLStr);
  2450. if (rs0.next()) {
  2451. SQLStr = "select pi_id,pi_class,pi_inoutno from prodinout where pi_fromcode='" + rs0.getString("pi_inoutno")
  2452. + "' and pi_statuscode='UNPOST' ";
  2453. SqlRowList rs = baseDao.queryForRowSet(SQLStr);
  2454. if (rs.next()) {
  2455. Outpiclass = rs.getObject("pi_class").toString();
  2456. if (Outpiclass.equals("生产领料单")) {
  2457. postProdInOut(rs.getInt("pi_id"), "ProdInOut!Picking",employee);
  2458. } else if (Outpiclass.equals("委外领料单")) {
  2459. postProdInOut(rs.getInt("pi_id"), "ProdInOut!OutsidePicking",employee);
  2460. }
  2461. SQLStr = "select pi_statuscode from prodinout where pi_id=" + rs.getInt("pi_id") + " and pi_statuscode='POSTED' ";
  2462. rs0 = baseDao.queryForRowSet(SQLStr);
  2463. if (rs0.next()) {
  2464. return null;
  2465. } else {
  2466. return Outpiclass + ":" + rs.getString("pi_inoutno") + "过账不成功!";
  2467. }
  2468. }
  2469. }
  2470. }
  2471. }
  2472. // 委外验收,验退,完工入库单,过账更新完工状态
  2473. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
  2474. || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  2475. SqlRowList rs = baseDao.queryForRowSet(
  2476. "select distinct ma_id from prodiodetail left join make on ma_code=pd_ordercode where pd_piid=?", pi_id);
  2477. while (rs.next()) {// 更新完工状态
  2478. updateMakeFinishStatus(rs.getInt("ma_id"));
  2479. }
  2480. }
  2481. /*if ("ProdInOut!AppropriationOut".equals(caller)) {
  2482. SqlRowList rs3 = baseDao
  2483. .queryForRowSet(
  2484. "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='拨入单'",
  2485. pi_id);
  2486. if (rs3.next()) {
  2487. return "拨出单过账成功!系统产生的拨入单号 "+ rs3.getString("pi_relativeplace");
  2488. }
  2489. }*/
  2490. if ("ProdInOut!PurcCheckin".equals(caller)) {// 采购验收单过账根据采购单+采购单序号更新pd_vendorrate
  2491. // ba_vendorrate
  2492. SqlRowList pdRowList = baseDao
  2493. .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="
  2494. + pi_id);
  2495. while (pdRowList.next()) {
  2496. baseDao.execute("update prodiodetail set pd_vendorrate=(select pd_vendorrate from purchasedetail where pd_code='"
  2497. + pdRowList.getObject("pd_ordercode") + "' and pd_detno='" + pdRowList.getObject("pd_orderdetno")
  2498. + "') where pd_id=" + pdRowList.getObject("pd_id"));
  2499. baseDao.execute("update batch set ba_vendorrate=(select pd_vendorrate from purchasedetail where pd_code='"
  2500. + pdRowList.getObject("pd_ordercode") + "' and pd_detno='" + pdRowList.getObject("pd_orderdetno")
  2501. + "') where ba_id=" + pdRowList.getObject("pd_batchid"));
  2502. }
  2503. }
  2504. if ("ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller) || "ProdInOut!Picking".equals(caller)
  2505. || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
  2506. || "ProdInOut!OutsidePicking".equals(caller)) {
  2507. changeMaStatus(pi_id);
  2508. }
  2509. // 2017-08-30 重新根据pdno更新批号仓库属性
  2510. if (isProdIn) {
  2511. baseDao.execute(
  2512. "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",
  2513. pi_id);
  2514. baseDao.execute(
  2515. "update batch set ba_hasbarcode=-1 where ba_id in (select pd_batchid from prodiodetail "
  2516. + " 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) ",
  2517. pi_id);
  2518. }
  2519. /**
  2520. * @author wsy
  2521. * 其它入库单:如果选择了采购单号、采购序号后,提交、审核的时候要判断采购单号+采购序号+物料编号是否一致,不一致限制提交
  2522. * 、审核
  2523. */
  2524. if ("ProdInOut!OtherIn".equals(caller)) {
  2525. 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="
  2526. + pi_id + " and pd_piclass='其它入库单')");
  2527. }
  2528. prodinout_post_updatesourceqty(pi_id);
  2529. return null;
  2530. }
  2531. /**
  2532. * 过账后扣除待检数量、收料数量 scm->prodinout->post->after
  2533. *
  2534. * @author madan
  2535. */
  2536. public void prodinout_post_updatesourceqty(Integer id) {
  2537. Object[] piclass = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_class", "pi_type" }, "pi_id=" + id);
  2538. if (!(piclass[0].toString().equals("采购验收单") || piclass[0].toString().equals("委外验收单") || piclass[0].toString().equals("不良品入库单"))) {
  2539. return;
  2540. }
  2541. List<Object[]> objs = baseDao.getFieldsDatasByCondition("prodioDetail", new String[] { "pd_orderdetno", "pd_ordercode",
  2542. "sum(pd_inqty)", "pd_prodcode" }, "pd_piid=" + id + " and pd_qcid>0 group by pd_ordercode, pd_orderdetno, pd_prodcode");
  2543. for (Object[] obj : objs) {
  2544. if ("采购验收单".equals(piclass[0].toString())) {
  2545. baseDao.updateByCondition("PurchaseDetail", "pd_reconhand = nvl(pd_reconhand,0)-" + obj[2]
  2546. + ",pd_totested=NVL(pd_totested,0)-" + obj[2], "pd_code='" + obj[1] + "' and pd_detno = " + obj[0]);
  2547. } else if ("委外验收单".equals(piclass[0].toString()) || "完工入库单".equals(piclass[0].toString())) {
  2548. baseDao.updateByCondition("Make", "ma_reconhand = nvl(ma_reconhand,0)-" + obj[2] + ",ma_totested=NVL(ma_totested,0)-"
  2549. + obj[2], "ma_code='" + obj[1] + "'");
  2550. } else if ("不良品入库单".equals(piclass[0].toString())) {
  2551. if ("PURC".equals(piclass[1].toString()) || "采购不良品入库".equals(piclass[1].toString())) {
  2552. baseDao.updateByCondition("PurchaseDetail", "pd_reconhand = nvl(pd_reconhand,0)-" + obj[2]
  2553. + ",pd_totested=NVL(pd_totested,0)-" + obj[2], "pd_code='" + obj[1] + "' and pd_detno = " + obj[0]);
  2554. } else {
  2555. baseDao.updateByCondition("Make", "ma_reconhand = nvl(ma_reconhand,0)-" + obj[2] + ",ma_totested=NVL(ma_totested,0)-"
  2556. + obj[2], "ma_code='" + obj[1] + "'");
  2557. }
  2558. }
  2559. baseDao.updateByCondition("Product", "pr_reconhand = nvl(pr_reconhand,0)-" + obj[2] + ",pr_totested=NVL(pr_totested,0)-"
  2560. + obj[2], "pr_code='" + obj[3] + "'");
  2561. }
  2562. }
  2563. // 税率强制等于币别表的默认税率
  2564. private void useDefaultTax(String caller, Object pi_id) {
  2565. if (baseDao.isDBSetting(caller, "useDefaultTax")) {
  2566. 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)"
  2567. + " where pd_piid=" + pi_id);
  2568. }
  2569. String defaultTax = baseDao.getDBSetting(caller, "defaultTax");
  2570. if (defaultTax != null) {
  2571. // 税率强制等于币别表的默认税率
  2572. if ("1".equals(defaultTax)) {
  2573. 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)"
  2574. + " where pd_piid=" + pi_id);
  2575. }
  2576. // 税率强制等于供应商资料的默认税率
  2577. if ("2".equals(defaultTax)) {
  2578. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)
  2579. || "ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  2580. 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)"
  2581. + " where pd_piid=" + pi_id);
  2582. }
  2583. if ("ProdInOut!SaleReturn".equals(caller) || "ProdInOut!Sale".equals(caller)) {
  2584. 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)"
  2585. + " where pd_piid=" + pi_id);
  2586. }
  2587. }
  2588. }
  2589. }
  2590. // 本位币允许税率为0
  2591. private String allowZeroTax(String caller, Object pi_id) {
  2592. String currency = baseDao.getDBSetting("sys","defaultCurrency");
  2593. boolean allowZeroTax = baseDao.isDBSetting(caller, "allowZeroTax");
  2594. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller)) {
  2595. allowZeroTax = baseDao.isDBSetting("Sale", "allowZeroTax");
  2596. }
  2597. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)) {
  2598. allowZeroTax = baseDao.isDBSetting("Purchase", "allowZeroTax");
  2599. }
  2600. if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  2601. allowZeroTax = baseDao.isDBSetting("Make", "allowZeroTax");
  2602. }
  2603. if (!allowZeroTax) {
  2604. String dets = baseDao.getJdbcTemplate().queryForObject(
  2605. "select WM_CONCAT(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id where nvl(pd_taxrate,0)=0 and pi_currency='"
  2606. + currency + "' and pi_id=?", String.class, pi_id);
  2607. if (dets != null) {
  2608. return "本位币税率为0,不允许进行当前操作!行号:" + dets;
  2609. }
  2610. }
  2611. return null;
  2612. }
  2613. String checkCloseMonth(Object pidate) {
  2614. boolean bool = baseDao.checkIf("PeriodsDetail", "pd_code='MONTH-P' and pd_status=99 and pd_detno=to_char(to_date('" + pidate
  2615. + "','yyyy-mm-dd hh24:mi:ss'), 'yyyymm')");
  2616. if (bool) {
  2617. return "单据日期所属期间已结账,不允许进行当前操作!";
  2618. }
  2619. return null;
  2620. }
  2621. String checkMakeKindType(String caller, Object pi_id) {
  2622. if (baseDao.isDBSetting(caller, "makeKindType")) {
  2623. String sql = "select count(1)cn from (select count(1) cn, mk_type from make left join makekind on mk_name =ma_kind"
  2624. + " left join prodiodetail on pd_ordercode = ma_code where pd_piid=? group by mk_type) ";
  2625. SqlRowList sqlRowList = baseDao.queryForRowSet(sql, pi_id);
  2626. if (sqlRowList.next()) {
  2627. if (sqlRowList.getInt("cn") > 1) {
  2628. return "明细行制造单加工类型不同,不能使用同一张完工入库单";
  2629. }
  2630. }
  2631. }
  2632. return null;
  2633. }
  2634. String checkFreezeMonth(String caller, Object pidate) {
  2635. if (!"ProdInOut!CostChange".equals(caller)) {
  2636. String freeze = baseDao.getDBSetting("sys","freezeMonth");
  2637. if (freeze != null && !freeze.equals("")) {
  2638. if (Integer.parseInt(freeze) == DateUtil.getYearmonth(pidate.toString())) {
  2639. return "单据日期所属期间已冻结,不允许进行当前操作!";
  2640. }
  2641. }
  2642. }
  2643. return null;
  2644. }
  2645. String checkFirstMonth(String caller, Object pidate) {
  2646. if ("ProdInOut!ReserveInitialize".equals(caller)) {
  2647. Object first = baseDao.getFieldDataByCondition("periods", "nvl(PE_FIRSTDAY,0)", "PE_CODE='MONTH-P'");
  2648. if ("0".equals(first.toString())) {
  2649. return "请前往【初始化期间设置】确认开账期间!";
  2650. } else {
  2651. if (Integer.parseInt(first.toString()) != DateUtil.getYearmonth(pidate.toString())) {
  2652. return "库存初始化单据只能发生在库存模块的开账期间!当前库存模块开账期间为[" + first + "],请前往【初始化期间设置】确认开账期间!";
  2653. }
  2654. }
  2655. }
  2656. return null;
  2657. }
  2658. /*
  2659. * 提交,审核,过账之前的限制
  2660. */
  2661. private String checkCommit(String caller, Object pi_id) {
  2662. checkIOMaPick(caller,pi_id);
  2663. if (!caller.equals("ProdInOut!AppropriationOut") && !caller.equals("ProdInOut!AppropriationIn")) {
  2664. baseDao.execute("update prodiodetail set pd_whcode=(select pi_whcode from prodinout where pd_piid=pi_id) where pd_piid="
  2665. + pi_id + " and NVL(pd_whcode,' ')=' '");
  2666. }
  2667. if (caller.equals("ProdInOut!Make!Return") || caller.equals("ProdInOut!OutsideReturn")) {
  2668. 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="
  2669. + pi_id + " and pd_prodmadedate is null");
  2670. }
  2671. baseDao.execute("update prodiodetail set pd_prodmadedate=(select pi_date from prodinout where pd_piid=pi_id) where pd_piid="
  2672. + pi_id + " and pd_prodmadedate is null");
  2673. if ("ProdInOut!CostChange".equals(caller)) {
  2674. baseDao.execute(
  2675. "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=?",
  2676. pi_id);
  2677. baseDao.execute(
  2678. "update prodiodetail set pd_total=round(nvl(pd_orderqty,0)*(nvl(pd_price,0)-nvl(pd_orderprice,0)),2) where pd_piid=?",
  2679. pi_id);
  2680. }
  2681. 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="
  2682. + pi_id + " and nvl(pd_qcid,0)<>0");
  2683. String dets = baseDao
  2684. .getJdbcTemplate()
  2685. .queryForObject(
  2686. "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'",
  2687. String.class, pi_id);
  2688. if (dets != null) {
  2689. return "明细行物料不存在或者状态不等于已审核,不允许进行当前操作!" + dets;
  2690. }
  2691. dets = baseDao
  2692. .getJdbcTemplate()
  2693. .queryForObject(
  2694. "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail where pd_piid=? and nvl(pd_whcode,' ')=' '",
  2695. String.class, pi_id);
  2696. if (dets != null) {
  2697. return "明细行仓库为空,不允许进行当前操作!" + dets;
  2698. }
  2699. /**
  2700. * 限制当仓库编号不为空时,明细行仓库至少有一行与主记录一致;为空则不判断
  2701. */
  2702. /*
  2703. * 暂不启用该逻辑限制 int c = baseDao.getCountByCondition(
  2704. * "ProdInOut left join ProdIODetail on pi_id=pd_piid", "pi_id=" + pi_id
  2705. * +
  2706. * " and ((NVL(pd_whcode,' ')=nvl(pi_whcode,' ') AND pi_whcode IS NOT NULL) or pi_whcode is null )"
  2707. * ); if (c < 1) { BaseUtil.showError("无一明细仓库与主表仓库一致,不允许进行当前操作!"); }
  2708. */
  2709. if (!caller.equals("ProdInOut!StockProfit") && !caller.equals("ProdInOut!StockLoss")) {
  2710. dets = baseDao
  2711. .getJdbcTemplate()
  2712. .queryForObject(
  2713. "select wm_concat(pd_pdno) from ProdIODetail inner join Prodinout on pd_piid=pi_id left join product on pr_code=pd_prodcode where "
  2714. + "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,' ')<>'用品' ",
  2715. String.class, pi_id);
  2716. if (dets != null) {
  2717. return "计算精度是0的物料不能以小数出入库!行号:" + dets;
  2718. }
  2719. }
  2720. if (baseDao.isDBSetting("sys","warehouseCheck") || baseDao.isDBSetting(caller, "warehouseCheck")) {
  2721. // 出入库单主记录与明细行仓库必须一致
  2722. dets = baseDao
  2723. .getJdbcTemplate()
  2724. .queryForObject(
  2725. "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,' '))",
  2726. String.class, pi_id);
  2727. if (dets != null) {
  2728. return "明细行仓库与当前单主表仓库不一致,不允许进行当前操作!" + dets;
  2729. }
  2730. }
  2731. dets = baseDao
  2732. .getJdbcTemplate()
  2733. .queryForObject(
  2734. "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'",
  2735. String.class, pi_id);
  2736. if (dets != null) {
  2737. return "仓库已禁用,不允许进行当前操作!" + dets;
  2738. }
  2739. dets = baseDao
  2740. .getJdbcTemplate()
  2741. .queryForObject(
  2742. "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)",
  2743. String.class, pi_id);
  2744. if (dets != null) {
  2745. return "仓库不存在,不允许进行当前操作!" + dets;
  2746. }
  2747. String maxprice = baseDao.getDBSetting(caller, "maxPrice");
  2748. if (maxprice != null) {
  2749. dets = baseDao
  2750. .getJdbcTemplate()
  2751. .queryForObject(
  2752. "select wmsys.wm_concat(pd_piclass||':'||pd_inoutno||',行:'||pd_pdno||',单价:'||pd_price) from prodiodetail where pd_piid=? and nvl(pd_price,0)>?",
  2753. String.class, pi_id, maxprice);
  2754. if (dets != null) {
  2755. return "单价超过设置上限,不允许进行当前操作!" + dets;
  2756. }
  2757. }
  2758. if ("ProdInOut!Picking".equals(caller) || "ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller)
  2759. || "ProdInOut!OutsidePicking".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
  2760. || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!Make!In".equals(caller)
  2761. || "ProdInOut!PartitionStockIn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
  2762. || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  2763. dets = baseDao
  2764. .getJdbcTemplate()
  2765. .queryForObject(
  2766. "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)",
  2767. String.class, pi_id);
  2768. if (dets != null) {
  2769. return "工单+序号不存在,不允许进行当前操作!行号:" + dets;
  2770. }
  2771. dets = baseDao
  2772. .getJdbcTemplate()
  2773. .queryForObject(
  2774. "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 "
  2775. + " 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)",
  2776. String.class, pi_id);
  2777. if (dets != null) {
  2778. return "工单+序号+物料编号不存在,不允许进行当前操作!行号:" + dets;
  2779. }
  2780. dets = baseDao
  2781. .getJdbcTemplate()
  2782. .queryForObject(
  2783. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode where "
  2784. + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(ma_vendcode,' ') and pd_piclass in ('委外退料单','委外验退单','委外领料单') "
  2785. + "and nvl(pd_ordercode,' ')<>' ' and not exists (select 1 from makecraft where mc_code=pd_jobcode and mc_tasktype='工序委外单')",
  2786. String.class, pi_id);
  2787. if (dets != null) {
  2788. return "明细委外单委外商与单据委外商不一致,不允许进行当前操作!行号:" + dets;
  2789. }
  2790. dets = baseDao
  2791. .getJdbcTemplate()
  2792. .queryForObject(
  2793. "select wm_concat(pd_pdno) from ProdIODetail where nvl(pd_jobcode,' ')<>' ' and not exists (select 1 from makecraft where pd_jobcode=mc_code "
  2794. + "and mc_tasktype='工序委外单') and pd_piclass in ('委外退料单','委外验退单','委外领料单') and pd_piid=?", String.class,
  2795. pi_id);
  2796. if (dets != null) {
  2797. return "明细工序委外单不存在,不允许进行当前操作!行号:" + dets;
  2798. }
  2799. dets = baseDao
  2800. .getJdbcTemplate()
  2801. .queryForObject(
  2802. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join makecraft on mc_code=pd_jobcode where "
  2803. + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(mc_vendcode,' ') and pd_piclass in ('委外退料单','委外验退单','委外领料单') "
  2804. + "and nvl(pd_ordercode,' ')<>' ' and exists (select 1 from makecraft where mc_code=pd_jobcode and mc_tasktype='工序委外单') ",
  2805. String.class, pi_id);
  2806. if (dets != null) {
  2807. return "委外商与工序委外单委外商不一致,不允许进行当前操作!行号:" + dets;
  2808. }
  2809. dets = baseDao
  2810. .getJdbcTemplate()
  2811. .queryForObject(
  2812. "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 ",
  2813. String.class, pi_id);
  2814. if (dets != null) {
  2815. return "拆件入库数不能大于工单允许可拆件入库数!" + dets;
  2816. }
  2817. dets = baseDao
  2818. .getJdbcTemplate()
  2819. .queryForObject(
  2820. "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'",
  2821. String.class, pi_id);
  2822. if (dets != null) {
  2823. return "拆件单明细中存在制造单的类型是标准!" + dets;
  2824. }
  2825. boolean allowBackAfterFinish = false;
  2826. if ("ProdInOut!Make!Return".equals(caller)) { // @add xst 20180830
  2827. // 反馈:2018080651
  2828. // ,制造单已结案允许退料
  2829. allowBackAfterFinish = baseDao.isDBSetting("Make!Base", "allowBackAfterFinish");
  2830. }
  2831. dets = baseDao
  2832. .getJdbcTemplate()
  2833. .queryForObject(
  2834. "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 "
  2835. + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(mk_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(mk_whcodes,'#'))) "
  2836. + "and pd_piclass in ('完工入库单','委外验收单') and nvl(pd_ordercode,' ')<>' ' and nvl(ProdIODetail.pd_status,0)=0",
  2837. String.class, pi_id);
  2838. if (dets != null) {
  2839. return "明细仓库与工单类型允许入库仓库不一致,不允许进行当前操作!行号:" + dets;
  2840. }
  2841. }
  2842. if ("ProdInOut!OutesideCheckReturn".equals(caller)) {
  2843. dets = baseDao
  2844. .getJdbcTemplate()
  2845. .queryForObject(
  2846. "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) "
  2847. + "and not exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单' and pd_prodcode=mc_prodcode)",
  2848. String.class, pi_id);
  2849. if (dets != null) {
  2850. return "委外单+物料编号不存在,不允许进行当前操作!行号:" + dets;
  2851. }
  2852. dets = baseDao
  2853. .getJdbcTemplate()
  2854. .queryForObject(
  2855. "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,' ')"
  2856. + " and not exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单')"
  2857. + " and pd_piclass in ('委外验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2858. if (dets != null) {
  2859. return "明细委外单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2860. }
  2861. dets = baseDao.getJdbcTemplate().queryForObject(
  2862. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join MakeCraft on mc_makecode=pd_ordercode "
  2863. + " and mc_code =pd_jobcode where pd_piid=? and nvl(pi_currency,' ')<>nvl(mc_currency,' ')"
  2864. + " and exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单')"
  2865. + " and pd_piclass in ('委外验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2866. if (dets != null) {
  2867. return "明细委外单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2868. }
  2869. }
  2870. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller) || "ProdInOut!DefectIn".equals(caller)
  2871. || "ProdInOut!DefectOut".equals(caller)) {
  2872. dets = baseDao
  2873. .getJdbcTemplate()
  2874. .queryForObject(
  2875. "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)",
  2876. String.class, pi_id);
  2877. if (dets != null) {
  2878. return "单据中供应商编号,供应商名称在供应商资料中不存在!";
  2879. }
  2880. dets = baseDao
  2881. .getJdbcTemplate()
  2882. .queryForObject(
  2883. "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)",
  2884. String.class, pi_id);
  2885. if (dets != null) {
  2886. return "单据中应付供应商编号,应付供应商名称在供应商资料中不存在!";
  2887. }
  2888. dets = baseDao
  2889. .getJdbcTemplate()
  2890. .queryForObject(
  2891. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=?"
  2892. + " 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)",
  2893. String.class, pi_id);
  2894. if (dets != null) {
  2895. return "采购单号+采购序号不存在,不允许进行当前操作!行号:" + dets;
  2896. }
  2897. dets = baseDao
  2898. .getJdbcTemplate()
  2899. .queryForObject(
  2900. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=?"
  2901. + " 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,' ')<>' ' ",
  2902. String.class, pi_id);
  2903. if (dets != null) {
  2904. Boolean bo = baseDao.isDBSetting("VerifyApply", "verifyApplyAllowPre"); // 允许收替代料
  2905. if (bo) {
  2906. SqlRowList rsReq = baseDao
  2907. .queryForRowSet(
  2908. "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 )",
  2909. pi_id);
  2910. if (!rsReq.hasNext()) {
  2911. return "采购单号+采购序号不存在!";
  2912. }
  2913. while (rsReq.next()) {
  2914. if (rsReq.getString("pd_repprodcode") != null && !("").equals(rsReq.getString("pd_repprodcode"))) {
  2915. StringBuffer codes = new StringBuffer();
  2916. String[] arr = rsReq.getString("pd_repprodcode").split(",");
  2917. codes.append("'");
  2918. for (int i = 0; i < arr.length; i++) {
  2919. if (i < arr.length - 1) {
  2920. codes.append(arr[i] + "','");
  2921. } else {
  2922. codes.append(arr[i] + "'");
  2923. }
  2924. }
  2925. dets = baseDao
  2926. .getJdbcTemplate()
  2927. .queryForObject(
  2928. " select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and pd_ordercode ='"
  2929. + rsReq.getString("pd_code")
  2930. + "' and pd_orderdetno="
  2931. + rsReq.getInt("pd_detno")
  2932. + " 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 ("
  2933. + codes + ")) ) and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' ' ",
  2934. String.class, pi_id);
  2935. if (dets != null) {
  2936. return "采购单号+采购序号+物料不存在,不允许进行当前操作!行号:" + dets;
  2937. }
  2938. }
  2939. }
  2940. }
  2941. if (dets != null) {
  2942. return "采购单号+采购序号+物料不存在,不允许进行当前操作!行号:" + dets;
  2943. }
  2944. }
  2945. dets = baseDao.getJdbcTemplate().queryForObject(
  2946. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on pd_ordercode=pd_code and pd_orderdetno=pd_detno where "
  2947. + "pd_piid=? and nvl(pd_mrpstatuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('采购验收单','采购验退单') "
  2948. + "and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2949. if (dets != null) {
  2950. return "采购单明细已冻结或者已结案,不允许进行当前操作!行号:" + dets;
  2951. }
  2952. dets = baseDao.getJdbcTemplate().queryForObject(
  2953. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on pd_ordercode=pd_code and pd_orderdetno=pd_detno where "
  2954. + "pd_piid=? and nvl(pd_mrpstatuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('不良品入库单','不良品出库单') "
  2955. + "and nvl(pd_ordercode,' ')<>' ' and nvl(pd_qctype,' ')='采购检验单'", String.class, pi_id);
  2956. if (dets != null) {
  2957. return "采购单明细已冻结或者已结案,不允许进行当前操作!行号:" + dets;
  2958. }
  2959. dets = baseDao.getJdbcTemplate().queryForObject(
  2960. "select wm_concat(pd_pdno) from ProdIODetail left join Make on pd_ordercode=ma_code where "
  2961. + "pd_piid=? and nvl(ma_statuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('不良品入库单','不良品出库单') "
  2962. + "and nvl(pd_ordercode,' ')<>' ' and nvl(pd_qctype,' ')='委外检验单'", String.class, pi_id);
  2963. if (dets != null) {
  2964. return "明细行委外单已冻结或者已结案,不允许进行当前操作!行号:" + dets;
  2965. }
  2966. if (!baseDao.isDBSetting(caller, "noLimitVendor")) {
  2967. dets = baseDao.getJdbcTemplate().queryForObject(
  2968. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Purchase on pu_code=pd_ordercode where "
  2969. + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(pu_vendcode,' ') and pd_piclass in ('采购验收单','采购验退单') "
  2970. + "and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2971. if (dets != null) {
  2972. return "明细采购单与单据供应商不一致,不允许进行当前操作!行号:" + dets;
  2973. }
  2974. }
  2975. if (!baseDao.isDBSetting(caller, "allowARCust")) {
  2976. dets = baseDao
  2977. .getJdbcTemplate()
  2978. .queryForObject(
  2979. "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join Purchase on pu_code=pd_ordercode where "
  2980. + "pd_piid=? and nvl(pi_receivecode,' ')<>nvl(pu_receivecode,' ') and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '",
  2981. String.class, pi_id);
  2982. if (dets != null) {
  2983. return "明细采购单与单据应付供应商不一致,不允许进行当前操作!行号:" + dets;
  2984. }
  2985. dets = baseDao
  2986. .getJdbcTemplate()
  2987. .queryForObject(
  2988. "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,' ')"
  2989. + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  2990. if (dets != null) {
  2991. return "明细采购单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  2992. }
  2993. }
  2994. dets = baseDao
  2995. .getJdbcTemplate()
  2996. .queryForObject(
  2997. "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 ('采购验收单')",
  2998. String.class, pi_id);
  2999. if (dets != null) {
  3000. return "明细行入库数量大于收料合格数量!" + dets;
  3001. }
  3002. dets = baseDao
  3003. .getJdbcTemplate()
  3004. .queryForObject(
  3005. "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 ('不良品入库单')",
  3006. String.class, pi_id);
  3007. if (dets != null) {
  3008. return "明细行入库数量大于收料不合格数量!" + dets;
  3009. }
  3010. dets = baseDao
  3011. .getJdbcTemplate()
  3012. .queryForObject(
  3013. "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 "
  3014. + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(pk_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(pk_whcodes,'#'))) "
  3015. + "and pd_piclass in ('采购验收单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  3016. if (dets != null) {
  3017. return "明细仓库与采购单类型允许入仓库不一致,不允许进行当前操作!行号:" + dets;
  3018. }
  3019. if ("ProdInOut!PurcCheckin".equals(caller)) {
  3020. dets = baseDao
  3021. .getJdbcTemplate()
  3022. .queryForObject(
  3023. "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on PurchaseDetail.pd_code=ProdIODetail.pd_ordercode and PurchaseDetail.pd_detno=ProdIODetail.pd_orderdetno "
  3024. + "where pd_piid=? and nvl(PurchaseDetail.pd_yqty,0)>nvl(PurchaseDetail.pd_qty,0)-nvl(PurchaseDetail.pd_frozenqty,0) "
  3025. + "and pd_piclass in ('采购验收单') and nvl(ProdIODetail.pd_ordercode,' ')<>' '", String.class, pi_id);
  3026. if (dets != null) {
  3027. return "明细采购订单已转数大于采购订单数量-已冻结数量,不允许进行当前操作!行号:" + dets;
  3028. }
  3029. }
  3030. }
  3031. if ("ProdInOut!SaleBorrow".equals(caller) || "ProdInOut!OtherPurcIn".equals(caller)) {
  3032. dets = baseDao
  3033. .getJdbcTemplate()
  3034. .queryForObject(
  3035. "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 "
  3036. + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(bt_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(bt_whcodes,'#'))) "
  3037. + "and pd_piclass in ('借货出货单','其它采购入库单')", String.class, pi_id);
  3038. if (dets != null) {
  3039. return "明细仓库与借货类型允许出入仓库不一致,不允许进行当前操作!" + dets;
  3040. }
  3041. }
  3042. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller) || "ProdInOut!OtherOut".equals(caller)
  3043. || "ProdInOut!ExchangeOut".equals(caller) || "ProdInOut!SaleAppropriationOut".equals(caller)) {
  3044. if (baseDao.isDBSetting(caller, "allowDifProd")) {
  3045. dets = baseDao
  3046. .getJdbcTemplate()
  3047. .queryForObject(
  3048. "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')"
  3049. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  3050. String.class, pi_id);
  3051. if (dets != null) {
  3052. return "销售单号+销售序号不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
  3053. }
  3054. } else if (baseDao.isDBSetting(caller, "SaleWithProdRelation")) {
  3055. dets = baseDao
  3056. .getJdbcTemplate()
  3057. .queryForObject(
  3058. "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and "
  3059. + "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)) "
  3060. + "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,' ')))"
  3061. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  3062. String.class, pi_id);
  3063. if (dets != null) {
  3064. return "销售单号+销售序号+物料编号不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
  3065. }
  3066. } else {
  3067. dets = baseDao
  3068. .getJdbcTemplate()
  3069. .queryForObject(
  3070. "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 )"
  3071. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  3072. String.class, pi_id);
  3073. if (dets != null) {
  3074. return "销售单号+销售序号+物料编号不存在,不允许进行当前操作!行号:" + dets;
  3075. }
  3076. }
  3077. if (baseDao.isDBSetting("sys","useMachineNo")) {
  3078. dets = baseDao
  3079. .getJdbcTemplate()
  3080. .queryForObject(
  3081. "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",
  3082. String.class, pi_id);
  3083. if (dets != null) {
  3084. return "单据+物料数量跟机器号数量不一致,不允许进行当前操作!行号:" + dets;
  3085. }
  3086. }
  3087. if (!(baseDao.isDBSetting("ProdInOut!Sale", "custatus"))) {
  3088. if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {// 客户挂起时,订单单价为0不限制出货
  3089. dets = baseDao
  3090. .getJdbcTemplate()
  3091. .queryForObject(
  3092. "select wm_concat(pi_cardcode) from ProdInOut left join customer on pi_cardcode=cu_code where pi_id = ? and pi_class in ('出货单') "
  3093. + "and cu_status='挂起' and not exists (select 1 from prodiodetail left join saledetail on pd_ordercode=sd_code and pd_orderdetno=sd_detno"
  3094. + " where pd_piid=pi_id and nvl(pd_ordercode,' ')<>' ' and nvl(sd_price,0)=0)", String.class,
  3095. pi_id);
  3096. if (dets != null) {
  3097. return "客户资料状态为挂起,且订单单价不为0,不允许进行当前操作!客户号:" + dets;
  3098. }
  3099. } else {
  3100. dets = baseDao
  3101. .getJdbcTemplate()
  3102. .queryForObject(
  3103. "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='挂起'",
  3104. String.class, pi_id);
  3105. if (dets != null) {
  3106. return "客户资料状态为挂起,不允许进行当前操作!客户号:" + dets;
  3107. }
  3108. }
  3109. }
  3110. if (!baseDao.isDBSetting(caller, "allowARCust")) {
  3111. dets = baseDao
  3112. .getJdbcTemplate()
  3113. .queryForObject(
  3114. "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,' ')"
  3115. + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
  3116. String.class, pi_id);
  3117. if (dets != null) {
  3118. return "明细销售单与单据客户不一致,不允许进行当前操作!行号:" + dets;
  3119. }
  3120. dets = baseDao
  3121. .getJdbcTemplate()
  3122. .queryForObject(
  3123. "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,' ')"
  3124. + " and pd_piclass in ('出货单','销售退货单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  3125. if (dets != null) {
  3126. return "明细销售单与单据应收客户不一致,不允许进行当前操作!行号:" + dets;
  3127. }
  3128. dets = baseDao
  3129. .getJdbcTemplate()
  3130. .queryForObject(
  3131. "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,' ')"
  3132. + " and pd_piclass in ('出货单','销售退货单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  3133. if (dets != null) {
  3134. return "明细销售单与单据币别不一致,不允许进行当前操作!行号:" + dets;
  3135. }
  3136. }
  3137. dets = baseDao
  3138. .getJdbcTemplate()
  3139. .queryForObject(
  3140. "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)",
  3141. String.class, pi_id);
  3142. if (dets != null) {
  3143. return "单据中客户编号,客户名称在客户资料中不存在!";
  3144. }
  3145. dets = baseDao
  3146. .getJdbcTemplate()
  3147. .queryForObject(
  3148. "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)",
  3149. String.class, pi_id);
  3150. if (dets != null) {
  3151. return "单据中应收客户编号,应收客户名称在客户资料中不存在!";
  3152. }
  3153. // 销售退货单:退货数量,如退货数量+其它未过账的退货单数量大于销售订单出货数
  3154. /**
  3155. * 需考虑状态
  3156. */
  3157. dets = baseDao
  3158. .getJdbcTemplate()
  3159. .queryForObject(
  3160. "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)",
  3161. String.class, pi_id);
  3162. if (dets != null) {
  3163. return "本次退货数+其它退货数合计大于订单的已发货数量,不允许进行当前操作!行号:" + dets;
  3164. }
  3165. if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!OtherOut".equals(caller)) {
  3166. dets = baseDao
  3167. .getJdbcTemplate()
  3168. .queryForObject(
  3169. "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,' ')<>' '",
  3170. String.class, pi_id);
  3171. if (dets != null) {
  3172. return "明细行预测单号+预测序号不存在或者状态不等于已审核,不允许进行当前操作!!" + dets;
  3173. }
  3174. dets = baseDao
  3175. .getJdbcTemplate()
  3176. .queryForObject(
  3177. "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,' ')<>' '",
  3178. String.class, pi_id);
  3179. if (dets != null) {
  3180. return "明细行预测单号+预测序号预测数量等于0,不允许进行当前操作!" + dets;
  3181. }
  3182. dets = baseDao
  3183. .getJdbcTemplate()
  3184. .queryForObject(
  3185. "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",
  3186. String.class, pi_id);
  3187. if (dets != null) {
  3188. return "明细行销售单号+销售序号数量大于订单未发货数,不允许进行当前操作!" + dets;
  3189. }
  3190. dets = baseDao
  3191. .getJdbcTemplate()
  3192. .queryForObject(
  3193. "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,' ')<>' '",
  3194. String.class, pi_id);
  3195. if (dets != null) {
  3196. return "预测单录入错误,该预测类型不属于发货冲销!" + dets;
  3197. }
  3198. }
  3199. }
  3200. // if ("ProdInOut!AppropriationOut".equals(caller) || "ProdInOut!AppropriationIn".equals(caller)
  3201. // || "ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!SaleAppropriationIn".equals(caller)) {
  3202. // dets = baseDao
  3203. // .getJdbcTemplate()
  3204. // .queryForObject(
  3205. // "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)",
  3206. // String.class, pi_id);
  3207. // if (dets != null) {
  3208. // return "有值和无值仓之间不能相互调拨!行号:" + dets);
  3209. // }
  3210. // }
  3211. SqlRowList rs = baseDao.queryForRowSet("select * from prodiodetail where pd_piid=?", pi_id);
  3212. StringBuffer sb = new StringBuffer();
  3213. while (rs.next()) {
  3214. int pdid = rs.getInt("pd_id");
  3215. int ioid = rs.getGeneralInt("pd_ioid");
  3216. double tqty = rs.getGeneralDouble("pd_inqty") + rs.getGeneralDouble("pd_outqty");
  3217. double yqty = 0.0;
  3218. if (ioid > 0) {
  3219. yqty = baseDao.getSummaryByField("Prodiodetail", "nvl(pd_outqty,0) + nvl(pd_inqty,0)", "pd_ioid=" + ioid + " and pd_id<>"
  3220. + pdid);
  3221. Object[] source = baseDao.getFieldsDataByCondition("Prodiodetail", new String[] { "nvl(pd_outqty,0)", "nvl(pd_inqty,0)",
  3222. "pd_piclass", "pd_inoutno" }, "pd_id=" + ioid);
  3223. if (source != null) {
  3224. if (yqty + tqty > Double.parseDouble(source[0].toString()) + Double.parseDouble(source[1].toString())) {
  3225. sb.append("行号:" + rs.getInt("pd_pdno") + ",数量:" + tqty + ",无法转出." + source[2] + "[" + source[3] + "]已转数量:" + yqty
  3226. + ",本次数量:" + tqty + "<hr/>");
  3227. }
  3228. }
  3229. }
  3230. }
  3231. if (sb.length() > 0) {
  3232. return sb.toString();
  3233. }
  3234. // 保税信息判断
  3235. if (baseDao.isDBSetting("sys","ioWHBondedCheck")) {
  3236. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)) {
  3237. dets = baseDao
  3238. .getJdbcTemplate()
  3239. .queryForObject(
  3240. "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)"
  3241. + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  3242. if (dets != null) {
  3243. return "采购单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
  3244. }
  3245. }
  3246. if ("ProdInOut!OutesideCheckReturn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
  3247. dets = baseDao
  3248. .getJdbcTemplate()
  3249. .queryForObject(
  3250. "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)"
  3251. + " and pd_piclass in ('委外验退单','委外验收单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  3252. if (dets != null) {
  3253. return "委外单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
  3254. }
  3255. }
  3256. if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!PartitionStockIn".equals(caller)) {
  3257. dets = baseDao
  3258. .getJdbcTemplate()
  3259. .queryForObject(
  3260. "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)"
  3261. + " and pd_piclass in ('完工入库单','拆件入库单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
  3262. if (dets != null) {
  3263. return "工单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
  3264. }
  3265. }
  3266. if ("ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller) || "ProdInOut!Picking".equals(caller)
  3267. || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
  3268. || "ProdInOut!OutsidePicking".equals(caller)) {
  3269. dets = baseDao
  3270. .getJdbcTemplate()
  3271. .queryForObject(
  3272. "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"
  3273. + " and pd_piclass in ('委外补料单','委外退料单','委外领料单') and nvl(pd_ordercode,' ')<>' '", String.class,
  3274. pi_id);
  3275. if (dets != null) {
  3276. return "委外单保税属性是非保税,不能发生仓库保税属性是保税的单据!" + dets;
  3277. }
  3278. dets = baseDao
  3279. .getJdbcTemplate()
  3280. .queryForObject(
  3281. "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"
  3282. + " and pd_piclass in ('生产补料单','生产退料单','生产领料单') and nvl(pd_ordercode,' ')<>' '", String.class,
  3283. pi_id);
  3284. if (dets != null) {
  3285. return "工单保税属性是非保税,不能发生仓库保税属性是保税的单据!" + dets;
  3286. }
  3287. }
  3288. if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!AppropriationOut".equals(caller)) {
  3289. dets = baseDao
  3290. .getJdbcTemplate()
  3291. .queryForObject(
  3292. "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)"
  3293. + " and pd_piclass in ('拨出单','销售拨出单') and nvl(pd_whcode,' ')<>' ' and nvl(pd_inwhcode,' ')<>' '",
  3294. String.class, pi_id);
  3295. if (dets != null) {
  3296. return "拨出仓库与拨入仓库仓库的保税属性不一致,不能进行当前操作!" + dets;
  3297. }
  3298. }
  3299. }
  3300. // @add20180605 Q:2018050126 最后一张完工入库单或者委外验收单,提交、审核、过账之前限制,不允许存在未过账
  3301. // 领、退、补单据,未审核的报废单,未过账的委外验退单
  3302. if (("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!Make!In".equals(caller))
  3303. && baseDao.isDBSetting(caller, "checkRelBillsStatus")) {
  3304. // 判断哪些工单是最后一张完工入库单
  3305. rs = baseDao
  3306. .queryForRowSet(
  3307. "select pd_ordercode,pd_pdno from (select pd_ordercode,sum(pd_inqty)inqty,wm_concat(pd_pdno)pd_pdno from prodiodetail where "
  3308. + "pd_piid=? and pd_piclass in('完工入库单','委外验收单') group by pd_ordercode) A left join make on ma_code=A.pd_ordercode "
  3309. + "where nvl(ma_madeqty,0)+inqty>=ma_qty", pi_id);
  3310. String errors = null;
  3311. while (rs.next()) {
  3312. dets = baseDao
  3313. .getJdbcTemplate()
  3314. .queryForObject(
  3315. "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",
  3316. String.class, pi_id, rs.getString("pd_ordercode"));
  3317. if (dets != null) {
  3318. errors = "行号:" + rs.getString("pd_pdno") + ",工单:" + rs.getString("pd_ordercode") + "存在关联未过账单据!" + dets;
  3319. }
  3320. dets = baseDao
  3321. .getJdbcTemplate()
  3322. .queryForObject(
  3323. "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",
  3324. String.class, rs.getString("pd_ordercode"));
  3325. if (dets != null) {
  3326. if (errors != null) {
  3327. errors += "<br>未审核的报废单:" + dets;
  3328. } else {
  3329. errors = "行号:" + rs.getString("pd_pdno") + ",工单:" + rs.getString("pd_ordercode") + "存在关联未审核的报废单:" + dets;
  3330. }
  3331. }
  3332. if (errors != null && !"".equals(errors)) {
  3333. return errors;
  3334. }
  3335. }
  3336. }
  3337. if (baseDao.isOut(caller)) {
  3338. dets = baseDao
  3339. .getJdbcTemplate()
  3340. .queryForObject(
  3341. "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,' ')<>' '"
  3342. + "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)",
  3343. String.class, pi_id);
  3344. if (dets != null) {
  3345. return "物料编号+仓库编号+批号不存在,不允许进行当前操作!行号:" + dets;
  3346. }
  3347. }
  3348. return null;
  3349. }
  3350. /**
  3351. * 校验批次是否重复
  3352. *
  3353. * @param caller
  3354. * @param pi_id
  3355. */
  3356. private String checkBatch(String caller, Object pi_id) {
  3357. if (baseDao.isIn(caller)) {
  3358. // 入库单据,同一物料同仓库不能同时入两次相同的批号
  3359. SqlRowList rs = baseDao
  3360. .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="
  3361. + pi_id + " and pd_batchcode<>' ' group by pd_batchcode,pd_whcode,pd_prodcode ) where c> 1");
  3362. if (rs.next()) {
  3363. if (rs.getInt("n") > 0) {
  3364. return "同一物料同仓库不能同时入两次相同的批号!" + rs.getString("detno");
  3365. }
  3366. }
  3367. rs = baseDao
  3368. .queryForRowSet("select count(1) n,wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']')detno "
  3369. + "from (select pd_piclass,pd_inoutno,pd_pdno from ProdIODetail where pd_piid="
  3370. + pi_id
  3371. + " and pd_batchcode is not null and exists (select 1 from batch where ba_code=pd_batchcode and ba_prodcode=pd_prodcode "
  3372. + "and ba_whcode=pd_whcode and (nvl(ba_remain,0)<>0 or nvl(ba_inqty,0)<>0))) where rownum<30");
  3373. if (rs.next()) {
  3374. if (rs.getInt("n") > 0) {
  3375. return "批号已存在,不能重复入库!" + rs.getString("detno");
  3376. }
  3377. }
  3378. }
  3379. return null;
  3380. }
  3381. private String copcheck(int pi_id, String caller) {
  3382. if (baseDao.isDBSetting("sys","CopCheck")) {
  3383. // 出入库单:明细行采购单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  3384. String dets = baseDao
  3385. .getJdbcTemplate()
  3386. .queryForObject(
  3387. "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,' ')<>' ' "
  3388. + " and pd_piclass in ('采购验收单','采购验退单')", String.class, pi_id);
  3389. if (dets != null) {
  3390. return "明细行采购单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  3391. }
  3392. // 出入库单:明细行销售单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  3393. dets = baseDao
  3394. .getJdbcTemplate()
  3395. .queryForObject(
  3396. "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,' ')<>' ' "
  3397. + "and pd_piclass in ('出货单','销售退货单','销售拨出单','销售拨入单')", String.class, pi_id);
  3398. if (dets != null) {
  3399. return "明细行销售单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  3400. }
  3401. // 出货单:来源单所属公司与当前单所属公司不一致,不允许进行当前操作
  3402. dets = baseDao
  3403. .getJdbcTemplate()
  3404. .queryForObject(
  3405. "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 ",
  3406. String.class, pi_id);
  3407. if (dets != null) {
  3408. return "明细来源通知单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  3409. }
  3410. // 出入库单:明细行制造单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  3411. dets = baseDao
  3412. .getJdbcTemplate()
  3413. .queryForObject(
  3414. "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,' ')<>' ' "
  3415. + "and pd_piclass in ('生产领料单','生产退料单','生产补料单','完工入库单','拆件入库单')", String.class, pi_id);
  3416. if (dets != null) {
  3417. return "明细行制造单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  3418. }
  3419. // 出入库单:明细行委外单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  3420. dets = baseDao
  3421. .getJdbcTemplate()
  3422. .queryForObject(
  3423. "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,' ')<>' ' "
  3424. + "and pd_piclass in ('委外验收单','委外验退单','委外领料单','委外退料单','委外补料单')", String.class, pi_id);
  3425. if (dets != null) {
  3426. return "明细行委外单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  3427. }
  3428. if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!OtherOut".equals(caller)
  3429. || "ProdInOut!AppropriationOut".equals(caller)) {
  3430. dets = baseDao
  3431. .getJdbcTemplate()
  3432. .queryForObject(
  3433. "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,' ')<>' ' "
  3434. + "and pd_piclass in ('销售拨出单','其它出库单')", String.class, pi_id);
  3435. if (dets != null) {
  3436. return "明细行销售预测单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
  3437. }
  3438. dets = baseDao
  3439. .getJdbcTemplate()
  3440. .queryForObject(
  3441. "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,' ')",
  3442. String.class, pi_id);
  3443. if (dets != null) {
  3444. return "单据所属公司和明细行拨入仓库的所属公司不一致,不允许进行当前操作!行号:" + dets;
  3445. }
  3446. }
  3447. // 出入库单限制界面的所属公司和仓库的所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  3448. dets = baseDao
  3449. .getJdbcTemplate()
  3450. .queryForObject(
  3451. "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 ('成本调整单')",
  3452. String.class, pi_id);
  3453. if (dets != null) {
  3454. return "单据所属公司和明细行仓库的所属公司不一致,不允许进行当前操作!行号:" + dets;
  3455. }
  3456. }
  3457. return null;
  3458. }
  3459. private String factorycheck(int pi_id, String caller) {
  3460. if (baseDao.isDBSetting("MpsDesk", "mrpSeparateFactory")) {
  3461. // 采购验收单、采购验退单:明细行采购单所属工厂与仓库的所属工厂不一致,,不允许进行当前操作
  3462. String dets = baseDao
  3463. .getJdbcTemplate()
  3464. .queryForObject(
  3465. "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,' ')<>' ' "
  3466. + " and PurchaseDetail.pd_factory is not null and pd_piclass in ('采购验收单','采购验退单')", String.class,
  3467. pi_id);
  3468. if (dets != null) {
  3469. return "明细行采购单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
  3470. }
  3471. // 生产领料单、退料单、补料单:明细行制造单所属工厂与仓库的所属工厂不一致,不允许进行当前操作
  3472. dets = baseDao
  3473. .getJdbcTemplate()
  3474. .queryForObject(
  3475. "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,' ')<>' ' "
  3476. + "and pd_piclass in ('生产领料单','生产退料单','生产补料单')", String.class, pi_id);
  3477. if (dets != null) {
  3478. return "明细行制造单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
  3479. }
  3480. // 委外领料单、退料单、补料单:明细行委外单所属工厂与仓库的所属工厂不一致,不允许进行当前操作
  3481. dets = baseDao
  3482. .getJdbcTemplate()
  3483. .queryForObject(
  3484. "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,' ')<>' ' "
  3485. + "and pd_piclass in ('委外领料单','委外退料单','委外补料单')", String.class, pi_id);
  3486. if (dets != null) {
  3487. return "明细行委外单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
  3488. }
  3489. }
  3490. return null;
  3491. }
  3492. private String checkIOMaPick(String caller, Object pi_id) {
  3493. String[] checkCallers={"ProdInOut!AppropriationOut","ProdInOut!Picking", "ProdInOut!OutsidePicking","ProdInOut!Make!Give","ProdInOut!OSMake!Give"
  3494. ,"ProdInOut!OtherOut","ProdInOut!SaleBorrow"};
  3495. if(Arrays.asList(checkCallers).contains(caller)){
  3496. String gridStore = "[]";
  3497. String formStore = null;
  3498. SqlRowList fromP = baseDao.queryForRowSet("select pi_id,pi_class,TO_CHAR(pi_date,'YYYYMM') pi_date from prodinout where pi_id = "+pi_id+" ");
  3499. if(fromP.next()){
  3500. formStore = BaseUtil.parseMap2Str(baseDao.changeKeyToLowerCase(fromP.getCurrentMap()));
  3501. SqlRowList checkDetail = baseDao.queryForRowSet("select pd_ordercode macode, pd_prodcode prodcode,pd_outqty outqty,pd_whcode outwhcode,pd_inwhcode inwhcode" +
  3502. " from prodiodetail where pd_piid = "+pi_id+" order by pd_pdno");
  3503. if(checkDetail.hasNext()){
  3504. gridStore = BaseUtil.parseGridStore2Str(baseDao.changeKeyToLowerCase(checkDetail.getResultList()));
  3505. }
  3506. String res = baseDao.callProcedure("USER_CHECKOUTSTOCK", new Object[] {formStore,gridStore});
  3507. if (res != null && res.length() > 0) {
  3508. return res;
  3509. }
  3510. }
  3511. }
  3512. return null;
  3513. }
  3514. /**
  3515. * 新增生产退料和委外退料判断,替代料退料数量不能大于替代料已领数量,主料退料不能大于主料已领数,工单外退料的情况不限制
  3516. *
  3517. * @date 2016年10月17日 下午12:30:58
  3518. * @param pi_id
  3519. * 单据id
  3520. */
  3521. private String checkRepQty(int pi_id) {
  3522. SqlRowList rs = baseDao
  3523. .queryForRowSet(
  3524. "select wm_concat(T.pdno) no from (select nvl(sum(pd_inqty),0) inqty,pd_ordercode,pd_orderdetno,pd_prodcode,max(pd_pdno)pdno "
  3525. + " from prodiodetail where pd_piid=? group by pd_ordercode,pd_orderdetno,pd_prodcode )T "
  3526. + " left join makematerial on mm_code=T.pd_ordercode and mm_detno=T.pd_orderdetno "
  3527. + " 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",
  3528. pi_id);
  3529. if (rs.next() && rs.getObject("no") != null) {
  3530. return "主料退料数不允许大于主料已领数,行号:" + rs.getString(1);
  3531. }
  3532. rs = baseDao
  3533. .queryForRowSet(
  3534. "select wm_concat(T.pdno) no from (select nvl(sum(pd_inqty),0) inqty,pd_ordercode,pd_orderdetno,pd_prodcode,max(pd_pdno)pdno "
  3535. + " from prodiodetail where pd_piid=? group by pd_ordercode,pd_orderdetno,pd_prodcode )T "
  3536. + " 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"
  3537. + " 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",
  3538. pi_id);
  3539. if (rs.next() && rs.getObject("no") != null) {
  3540. return "替代料退料数不允许大于替代已领数,行号:" + rs.getString(1);
  3541. }
  3542. return null;
  3543. }
  3544. private String checkMmBackOver(String caller, int pi_id) {
  3545. //截止到退料单单据日期月份的 本单的退料不允许大于 已过账的 领料出库-退料数+补料数-(完工-验退数)*单位用量
  3546. String data = baseDao.getJdbcTemplate().queryForObject("select wm_concat('工单:'||pd_ordercode||',序号:'||pd_orderdetno ||'<br>') " +
  3547. " 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 " +
  3548. " LEFT JOIN MAKEMATERIAL ON MM_MAID=MA_ID and pd_orderdetno=mm_detno where " +
  3549. " 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 " +
  3550. " a.pd_ordercode=b.pd_ordercode and a.pd_orderdetno=b.pd_orderdetno and pi_class in('生产领料单','委外领料单','生产退料单','委外退料单','生产补料单','委外补料单')),0) " +
  3551. " - 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) " +
  3552. " -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 " +
  3553. " a.pd_ordercode=b.pd_ordercode AND pi_class in('完工入库单','委外验退单','委外验收单')),0)*nvl(mm_oneuseqty,0) and rownum<10",String.class,pi_id);
  3554. if(data != null){
  3555. return "退料数大于截止到单据月份剩余的结存数,"+data;
  3556. }
  3557. return null;
  3558. }
  3559. /**
  3560. * 计算pi_total
  3561. */
  3562. private void getTotal(Object pi_id, String caller) {
  3563. baseDao.execute("update prodiodetail set pd_purcinqty=nvl(pd_inqty,0) where pd_piid=" + pi_id
  3564. + " and exists (select 1 from product where pd_prodcode=pr_code and nvl(pr_purcunit,pr_unit)=pr_unit) ");
  3565. baseDao.execute("update prodiodetail set pd_purcoutqty=nvl(pd_outqty,0) where pd_piid=" + pi_id
  3566. + " and exists (select 1 from product where pd_prodcode=pr_code and nvl(pr_purcunit,pr_unit)=pr_unit)");
  3567. 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="
  3568. + pi_id + " and nvl(pd_purcinqty,0)=0");
  3569. if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
  3570. || "ProdInOut!OutesideCheckReturn".equals(caller)) {
  3571. if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {// 委外
  3572. baseDao.updateByCondition("ProdIODetail", "pd_orderprice=(select ma_price from make where ma_code=pd_ordercode)",
  3573. "pd_piid=" + pi_id + " and nvl(pd_orderprice,0)=0");
  3574. // 强制取委外单主表中的税率
  3575. baseDao.execute(
  3576. "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=?",
  3577. pi_id);
  3578. } else {// 采购
  3579. baseDao.updateByCondition("ProdIODetail",
  3580. "pd_orderprice=nvl((select pd_price from PurchaseDetail where pd_code=pd_ordercode and pd_detno=pd_orderdetno),0)",
  3581. "pd_piid=" + pi_id + " and nvl(pd_orderprice,0)=0 and nvl(pd_status,0)<>99");
  3582. // 强制取采购单明细表中的对应的税率
  3583. baseDao.execute(
  3584. "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=?",
  3585. pi_id);
  3586. }
  3587. 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="
  3588. + pi_id);
  3589. 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="
  3590. + pi_id);
  3591. baseDao.updateByCondition("ProdIODetail", " pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)", "pd_piid="
  3592. + pi_id);
  3593. baseDao.updateByCondition("ProdInOut",
  3594. "pi_total = round(nvl((SELECT sum(round(pd_ordertotal,2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
  3595. + pi_id);
  3596. baseDao.updateByCondition(
  3597. "ProdIODetail",
  3598. "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)",
  3599. "pd_piid=" + pi_id);
  3600. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  3601. } else if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller)) {
  3602. baseDao.updateByCondition(
  3603. "ProdIODetail",
  3604. "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)",
  3605. "pd_piid=" + pi_id);
  3606. baseDao.updateByCondition(
  3607. "ProdIODetail",
  3608. "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)",
  3609. "pd_piid=" + pi_id);
  3610. baseDao.updateByCondition("ProdInOut",
  3611. "pi_total=round(nvl((SELECT sum(round(pd_ordertotal,2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id=" + pi_id);
  3612. baseDao.execute("update prodiodetail set pd_customprice=pd_sendprice, pd_taxamount=pd_ordertotal "
  3613. + "where pd_piclass in ('出货单','销售退货单') and pd_piid=? and nvl(pd_customprice,0)=0", pi_id);
  3614. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  3615. // 成品标准成本,用于报价毛利润统计
  3616. baseDao.execute("UPDATE product set pr_cost=nvl((select price from ( select qd_prodcode,round(qd_factprice*qu_rate,2) price,"
  3617. + " row_number() over(partition by qd_prodcode order by qu_auditdate desc) rn from quotation,quotationdetail "
  3618. + "where qu_id=qd_quid and qu_statuscode='AUDITED') t1 where rn=1 and qd_prodcode=pr_code),0) "
  3619. + "where nvl(pr_cost,0)=0 and pr_code in (select pd_prodcode from prodiodetail where pd_piid=?)", pi_id);
  3620. baseDao.execute("UPDATE prodiodetail SET pd_showprice=nvl((select pr_cost from product where pd_prodcode=pr_code),0)"
  3621. + "WHERE pd_piid=?", pi_id);
  3622. } else {
  3623. baseDao.updateByCondition("ProdIODetail", "pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)", "pd_piid="
  3624. + pi_id);
  3625. baseDao.updateByCondition(
  3626. "ProdInOut",
  3627. "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)",
  3628. "pi_id=" + pi_id);
  3629. baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
  3630. }
  3631. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller) || "ProdInOut!AppropriationOut".equals(caller)
  3632. || "ProdInOut!OtherOut".equals(caller) || "ProdInOut!ExchangeOut".equals(caller)) {
  3633. Object cardcode = baseDao.getFieldDataByCondition("ProdInOut", "pi_cardcode", "pi_id=" + pi_id);
  3634. 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='"
  3635. + cardcode
  3636. + "' and pd_prodcode=pr_code) where pd_piid="
  3637. + pi_id
  3638. + " and nvl(pd_custprodcode,' ')=' ' and nvl(pd_custprodspec,' ')=' ' and pd_piclass in ('销售退货单', '出货单', '其它出库单', '拨出单', '换货出库单')");
  3639. 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="
  3640. + pi_id);
  3641. }
  3642. if ("ProdInOut!CostChange".equals(caller)) {
  3643. baseDao.execute(
  3644. "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=?",
  3645. pi_id);
  3646. }
  3647. // 入库类单据:如果pd_location为空,默认等于物料资料里的仓位pr_location
  3648. if (baseDao.isIn(caller)) {
  3649. baseDao.execute(
  3650. "update prodiodetail set pd_location=(select pr_location from product where pr_code=pd_prodcode) where pd_piid=? and nvl(pd_location,' ')=' '",
  3651. pi_id);
  3652. }
  3653. baseDao.updateByCondition("ProdInOut",
  3654. "pi_total = round(nvl((SELECT sum(round(nvl(pd_ordertotal,0),2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
  3655. + pi_id);
  3656. baseDao.updateByCondition("ProdInOut",
  3657. "pi_nettotal = round(nvl((SELECT sum(round(nvl(pd_nettotal,0),2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
  3658. + pi_id);
  3659. }
  3660. /**
  3661. * 计算pi_qtytotal
  3662. */
  3663. private void getQtyTotal(Object pi_id, String caller) {
  3664. if ("ProdInOut!Sale".equals(caller) || "ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!OtherOut".equals(caller)) {
  3665. baseDao.execute("update ProdInOut set pi_qtytotal=nvl((select sum(nvl(pd_outqty,0)+nvl(pd_inqty,0)) from ProdIODetail where "
  3666. + "ProdIODetail.pd_piid = ProdInOut.pi_id),0) where pi_id=" + pi_id);
  3667. }
  3668. }
  3669. // @add 20170524 出库类型的单据,保存,更新,获取批号之后更新备料状态
  3670. private void updatePdaStatus(String caller, Object pi_id) {
  3671. Boolean bo = baseDao.isDBSetting("BarCodeSetting", "BarRelevancyBatch");
  3672. Boolean AutoPickBarcode = baseDao.isDBSetting("BarCodeSetting", "autoPickBarcode");
  3673. if (!AutoPickBarcode) {
  3674. if (!bo) {
  3675. if (baseDao.isOut(caller)) { // 出库类型
  3676. // 如果所有的明细都没有条码则更新为空
  3677. SqlRowList rs = baseDao.queryForRowSet(
  3678. "select count(1)cn from prodiodetail where pd_piid=? and nvl(pd_batchcode,' ')<>' '", pi_id);
  3679. if (rs.next() && rs.getInt("cn") == 0) {
  3680. baseDao.execute("update prodinout set pi_pdastatus='' where pi_id=? and nvl(pi_pdastatus,' ')<>' '", pi_id);
  3681. } else {
  3682. rs = baseDao.queryForRowSet("select count(1)cn from barcodeio where bi_piid=? and bi_outqty>0", pi_id);
  3683. if (rs.next() && rs.getInt("cn") > 0) { // 有一行以上备料记录则是备料中
  3684. baseDao.execute("update prodinout set pi_pdastatus ='备料中' where pi_id=?", pi_id);
  3685. rs = baseDao
  3686. .queryForRowSet(
  3687. "select count(1) cn from (select pd_prodcode,pd_whcode,sum(pd_outqty)qty from prodiodetail left join batch on pd_batchid=ba_id "
  3688. + " 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 "
  3689. + " 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)",
  3690. pi_id, pi_id);
  3691. if (rs.next() && rs.getInt("cn") == 0) {
  3692. baseDao.execute("update prodinout set pi_pdastatus ='已备料' where pi_id=?", pi_id);
  3693. }
  3694. } else {
  3695. // --存在有条码的批号则更新成未备料
  3696. baseDao.execute(
  3697. "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)",
  3698. pi_id, pi_id);
  3699. // --所有批号都无条码则更新成无条码
  3700. baseDao.execute(
  3701. "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)",
  3702. pi_id, pi_id);
  3703. }
  3704. }
  3705. }
  3706. }
  3707. }
  3708. }
  3709. /**
  3710. * 检查批号是否存在,批号数量是否足够
  3711. */
  3712. private String checkBatchRemain(Object pi_id) {
  3713. int count = baseDao.getCount("select count(1) from documentsetup where ds_name=(select pi_class from prodinout " + "where pi_id="
  3714. + pi_id + ") and (ds_inorout = '-IN' or ds_inorout = 'OUT')");
  3715. if (count > 0) {
  3716. String pdnos1 = baseDao.getJdbcTemplate().queryForObject(
  3717. "select WMSYS.WM_CONCAT(pd_pdno) from (select pd_pdno from prodiodetail left join batch on"
  3718. + " pd_batchcode=ba_code and ba_whcode = pd_whcode and ba_prodcode = pd_prodcode "
  3719. + "where pd_piid=? and ba_code is null order by pd_pdno) where rownum<20", String.class, pi_id);
  3720. String pdnos2 = baseDao
  3721. .getJdbcTemplate()
  3722. .queryForObject(
  3723. "select WMSYS.WM_CONCAT(pd_pdno) from (select WMSYS.WM_CONCAT(pd_pdno) pd_pdno,max(pd_batchcode),"
  3724. + "sum(pd_outqty),max(ba_remain),max(ba_code) from prodiodetail left join batch on pd_batchcode=ba_code and "
  3725. + "ba_whcode = pd_whcode and ba_prodcode = pd_prodcode where pd_piid=? group by pd_batchcode,pd_prodcode,pd_whcode"
  3726. + " having sum(pd_outqty)>max(ba_remain) ) where rownum<20", String.class, pi_id);
  3727. if (pdnos1 != null || pdnos2 != null) {
  3728. String error1 = pdnos1 == null ? "" : "找不到您所指的批号,请修改批号或点击【重置批号】再过账!行号是:" + pdnos1 + "<br>";
  3729. String error2 = pdnos2 == null ? "" : "批号的库存数小于出库数量,请修改批号或点击【重置批号】再过账!行号是:" + pdnos2 + "<br>";
  3730. return error1 + error2;
  3731. }
  3732. }
  3733. return null;
  3734. }
  3735. /**
  3736. * 产生冲销单并审核 发货单过账/销售单审核 scm->prodinout->post->after scm->sale->audit->after
  3737. *
  3738. * @author ZhongYL
  3739. */
  3740. @Transactional
  3741. public void createSaleClash(Integer fromid, String fromcaller,Employee employee) {
  3742. String SqlStr = "", clashcode = "", canclash = "", othercondition = "";
  3743. double thisqty = 0, needclashqty = 0, clashedqty = 0;
  3744. int csid = 0, detno = 0;
  3745. String prodcode = "", ordercode = "", fromcode = "", fromwhere = "";
  3746. String clashoption = "", saleclashkind = "";
  3747. SqlRowList rs0;
  3748. if (fromcaller.equalsIgnoreCase("ProdInOut")) {
  3749. fromwhere = baseDao.getFieldDataByCondition("ProdInOut", "pi_class", "pi_id=" + fromid).toString();
  3750. } else if (fromcaller.equalsIgnoreCase("Sale") || fromcaller.equals("销售单")) {
  3751. fromwhere = "销售单";
  3752. } else {
  3753. return;
  3754. }
  3755. // 先更新呆冲销的明细已冲销数为0
  3756. 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) ";
  3757. baseDao.execute(SqlStr);
  3758. // 获取冲销来源单据
  3759. if (fromwhere.equals("出货单")) {
  3760. 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='"
  3761. + fromid + "' ";
  3762. } else if (fromwhere.equals("销售单")) {
  3763. 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='"
  3764. + fromid + "' ";
  3765. } else if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单")) {
  3766. 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='"
  3767. + fromid
  3768. + "' 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 ";
  3769. // 判断是否存在需要完工入库冲销的预测
  3770. rs0 = baseDao.queryForRowSet("select sf_code from saleforecastkind where sf_clashoption='完工冲销' or sf_clashoption='FINISH' ");
  3771. if (!rs0.hasNext()) {
  3772. // 不需要完工冲销
  3773. return;
  3774. }
  3775. } else if (fromwhere.equals("销售拨出单")) {
  3776. 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='"
  3777. + fromid + "' and NVL(pd_plancode,' ')<>' ' and pd_forecastdetno>0 ";
  3778. } else if (fromwhere.equals("其它出库单")) {
  3779. 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='"
  3780. + fromid + "' and NVL(pd_plancode,' ')<>' ' and pd_forecastdetno>0 ";
  3781. } else {
  3782. return;
  3783. }
  3784. detno = 1;
  3785. SqlRowList rs = baseDao.queryForRowSet(SqlStr);
  3786. while (rs.next()) {
  3787. fromcode = rs.getString("fromcode");
  3788. clashoption = "";
  3789. saleclashkind = "";
  3790. othercondition = "";
  3791. clashedqty = 0;
  3792. needclashqty = rs.getDouble("qty");
  3793. prodcode = rs.getString("prodcode");
  3794. ordercode = rs.getString("ordercode");
  3795. // 判断此行记录是否需要冲销
  3796. canclash = "N";
  3797. if (fromwhere.equals("销售单") || fromwhere.equals("出货单")) {
  3798. if(fromwhere.equals("出货单") && baseDao.isDBSetting("ProdInOut!Sale", "clashSaleForecastByProduct")){
  3799. saleclashkind="PRODUCT";
  3800. clashoption = "SEND";
  3801. }else{
  3802. SqlStr = "SELECT * from sale left join salekind on (sa_kind=sk_name or sa_kind=sk_code) where sa_code='" + ordercode + "' ";
  3803. SqlRowList rs2 = baseDao.queryForRowSet(SqlStr);
  3804. if (rs2.next()) {
  3805. saleclashkind = rs2.getString("sk_clashfor");
  3806. clashoption = rs2.getString("sk_clashoption");
  3807. othercondition = rs2.getString("sk_clashkind");
  3808. } else {
  3809. // 未设置类型,不冲销
  3810. continue;
  3811. }
  3812. }
  3813. } else if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单")) {
  3814. saleclashkind = "PRODUCT";
  3815. clashoption = "FINISH";
  3816. } else if (fromwhere.equals("销售拨出单") || fromwhere.equals("其它出库单")) {
  3817. saleclashkind = "单号冲销";
  3818. clashoption = "SEND";
  3819. }
  3820. if (saleclashkind == null || clashoption == null) {
  3821. // 未设置类型,不冲销
  3822. continue;
  3823. }
  3824. if (fromwhere.equals("销售单")) {
  3825. if (clashoption.equals("订单冲销") || clashoption.equalsIgnoreCase("SALE")) {
  3826. canclash = "Y";
  3827. }
  3828. } else if (fromwhere.equals("出货单")) {
  3829. if (clashoption.equals("发货冲销") || clashoption.equalsIgnoreCase("SEND")) {
  3830. canclash = "Y";
  3831. }
  3832. }
  3833. if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单") || fromwhere.equals("销售拨出单")
  3834. || fromwhere.equals("其它出库单")) {
  3835. canclash = "Y";
  3836. }
  3837. if (canclash.equals("N")) {
  3838. // 不冲销
  3839. continue;
  3840. }
  3841. SqlStr = "";
  3842. if (saleclashkind.equalsIgnoreCase("sale") || saleclashkind.equals("单号冲销")) {
  3843. 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='"
  3844. + rs.getString("sfcode") + "' and sd_detno=" + rs.getInt("sfdetno");
  3845. } else if (saleclashkind.equalsIgnoreCase("product") || saleclashkind.equals("料号冲销")) {
  3846. // 按物料号冲销
  3847. 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='"
  3848. + prodcode + "' ";
  3849. if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单")) {
  3850. SqlStr = "SELECT case when saleforecast.sf_code='"
  3851. + rs.getString("ma_salecode")
  3852. + "' and sd_detno="
  3853. + rs.getInt("ma_saledetno")
  3854. + " 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='"
  3855. + prodcode + "' ";
  3856. }
  3857. if (fromwhere.equals("销售单") && othercondition != null && othercondition.equals("客户匹配")) {
  3858. SqlStr = SqlStr + " and (case when NVL(saleforecastDetail.sd_custcode,' ')<>' ' then saleforecastDetail.sd_custcode else sf_custcode end)='" + rs.getString("sa_custcode") + "' ";
  3859. } else if (fromwhere.equals("销售单") && othercondition != null && othercondition.equals("业务员")){
  3860. SqlStr = SqlStr + " and (case when nvl(saleforecastDetail.sd_sellercode,' ')<>' ' then saleforecastDetail.sd_sellercode else sf_sellercode end)='"+ rs.getString("sa_sellercode")+"' ";
  3861. }
  3862. } else {
  3863. // 不冲销
  3864. continue;
  3865. }
  3866. if (clashoption.equals("订单冲销") || clashoption.equalsIgnoreCase("SALE")) {
  3867. SqlStr = SqlStr + " and sf_clashoption in ('SALE','订单冲销') ";
  3868. } else if (clashoption.equals("发货冲销") || clashoption.equalsIgnoreCase("SEND")) {
  3869. SqlStr = SqlStr + " and sf_clashoption in ('SEND','发货冲销') ";
  3870. } else if (clashoption.equals("完工冲销") || clashoption.equalsIgnoreCase("FINISH")) {
  3871. SqlStr = SqlStr + " and sf_clashoption in ('FINISH','完工冲销') ";
  3872. }
  3873. if (saleclashkind.equalsIgnoreCase("product") || saleclashkind.equals("料号冲销")) {
  3874. SqlStr = SqlStr + " and trunc(sd_enddate)>=trunc(sysdate) ";// 只冲销有效的预测,@update 20170224 截止日期等于今日的也可冲销,与存储过程中的计算一致
  3875. }
  3876. if (fromwhere.equals("委外验退单")) {
  3877. 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='"
  3878. + rs.getString("ordercode")
  3879. + "' and scd_clashqty>0 and scd_clashqty-NVL(scd_cancelqty,0)>0 and sc_statuscode='AUDITED' and sd_clashsaleqty>0 ";
  3880. }
  3881. if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单")) {
  3882. if (baseDao.isDBSetting("SaleForecast", "mappingSaleForecast")) {
  3883. SqlStr = SqlStr
  3884. + " and saleforecast.sf_code='"
  3885. + rs.getString("ma_salecode")
  3886. + "' and saleforecastdetail.sd_detno="
  3887. + rs.getInt("ma_saledetno")
  3888. + " and saleforecast.sf_statuscode='AUDITED' and sd_qty-nvl(sd_stepqty,0)>0 order by sortid,sd_needdate asc,sd_detno asc";
  3889. } else {
  3890. SqlStr = SqlStr
  3891. + " and saleforecast.sf_statuscode='AUDITED' and sd_qty-nvl(sd_stepqty,0)>0 order by sortid,sd_needdate asc,sd_detno asc";
  3892. }
  3893. } else if (fromwhere.equals("委外验退单")) {
  3894. // 委外验退条件特殊,上面已加
  3895. } else {
  3896. SqlStr = SqlStr
  3897. + " 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";
  3898. }
  3899. if ("Y".equals(canclash) && !SqlStr.equals("")) {
  3900. SqlRowList rs2 = baseDao.queryForRowSet(SqlStr);
  3901. while (rs2.next() && clashedqty < needclashqty) {
  3902. double remain = rs2.getDouble("sd_qty") - rs2.getDouble("sd_stepqty");
  3903. int cancelsourceid = 0;
  3904. if (fromwhere.equals("委外验退单")) {
  3905. remain = (rs2.getDouble("scd_clashqty") - rs2.getDouble("scd_cancelqty"));// 拿冲销数反冲减预测
  3906. cancelsourceid = rs2.getInt("scd_id");
  3907. if (remain <= 0) {
  3908. continue;
  3909. }
  3910. }
  3911. thisqty = remain > needclashqty - clashedqty ? needclashqty - clashedqty : remain;
  3912. if (clashcode == "") {
  3913. clashcode = baseDao.sGetMaxNumber("SaleClash", 2);
  3914. csid = baseDao.getSeqId("SALECLASH_SEQ");
  3915. SqlStr = "insert into SaleClash(sc_id,sc_code,sc_date,sc_status,sc_statuscode,sc_recorder,sc_source,sc_sourceid,sc_sourcecode)values("
  3916. + csid
  3917. + ",'"
  3918. + clashcode
  3919. + "',sysdate,'已提交','COMMITED','"+employee.getEm_name()+"','" + fromwhere + "'," + fromid + ",'" + fromcode+ "') ";
  3920. baseDao.execute(SqlStr);
  3921. }
  3922. 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("
  3923. + "SALECLASHDETAIL_SEQ.NEXTVAL,"
  3924. + csid
  3925. + ",'"
  3926. + detno
  3927. + "','"
  3928. + prodcode
  3929. + "','"
  3930. + thisqty
  3931. + "','"
  3932. + rs2.getString("sf_code")
  3933. + "','"
  3934. + rs2.getInt("sd_detno")
  3935. + "',"
  3936. + rs.getInt("sourcedetid")
  3937. + ",'"
  3938. + rs.getString("ordercode") + "'," + cancelsourceid + ")";
  3939. baseDao.execute(SqlStr);
  3940. if (fromwhere.equals("委外验退单")) {
  3941. SqlStr = "UPDATE SaleClashDetail set scd_cancelqty=nvl(scd_cancelqty,0)+" + thisqty + " where scd_id="
  3942. + rs2.getInt("scd_id") + " ";
  3943. baseDao.execute(SqlStr);
  3944. }
  3945. SqlStr = "UPDATE saleforecastDetail set sd_stepqty=nvl(sd_stepqty,0)+(" + thisqty + ") where sd_id="
  3946. + rs2.getInt("sd_id") + " ";
  3947. baseDao.execute(SqlStr);
  3948. detno = detno + 1;
  3949. clashedqty = clashedqty + thisqty;
  3950. }
  3951. }
  3952. }
  3953. if (fromwhere.equals("委外验退单") && csid > 0) {
  3954. SqlStr = "UPDATE SaleClashDetail set scd_clashqty=0-scd_clashqty where scd_scid=" + csid + " ";
  3955. baseDao.execute(SqlStr);
  3956. }
  3957. if (!"".equals(clashcode)) {
  3958. // 审核冲销单
  3959. auditSaleClash(csid, "SaleClash",employee);
  3960. }
  3961. }
  3962. public String auditSaleClash(int sc_id, String caller,Employee employee) {
  3963. // 只能对状态为[已提交]的订单进行审核操作!
  3964. Object status = baseDao.getFieldDataByCondition("SaleClash", "sc_statuscode", "sc_id=" + sc_id);
  3965. if (!"AUDITED".equals(StringUtil.nvl(status, ""))){
  3966. return "只能对已提交的单据进行审核!";
  3967. }
  3968. String dets = baseDao
  3969. .getJdbcTemplate()
  3970. .queryForObject(
  3971. "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=?))",
  3972. String.class, sc_id);
  3973. if (dets != null) {
  3974. return "预测单号+预测行号状态不等于已审核,不允许已审核!" + dets;
  3975. }
  3976. // 执行审核操作
  3977. baseDao.audit("SaleClash", "sc_id=" + sc_id, "sc_status", "sc_statuscode", "sc_auditdate", "sc_auditman",employee);
  3978. Object source = baseDao.getFieldDataByCondition("SaleClash", "sc_source", "sc_id=" + sc_id);
  3979. // 冲销数量记录在预测单中
  3980. SqlRowList rs = baseDao
  3981. .queryForRowSet(
  3982. "select scd_ordercode,scd_orderdetno,sum(scd_clashqty) scd_clashqty from SaleClashDetail where scd_scid=? group by scd_ordercode,scd_orderdetno",
  3983. sc_id);
  3984. while (rs.next()) {
  3985. baseDao.updateByCondition("SaleForecastDetail", "sd_qty=sd_qty-(" + rs.getDouble("scd_clashqty")
  3986. + "),sd_clashsaleqty=nvl(sd_clashsaleqty,0)+" + rs.getDouble("scd_clashqty"), "sd_detno=" + rs.getInt("scd_orderdetno")
  3987. + " AND sd_sfid=(SELECT sf_id FROM SaleForecast WHERE sf_code='" + rs.getString("scd_ordercode") + "')");
  3988. if (source != null && source.equals("销售单") && rs.getGeneralDouble("scd_clashqty") > 0) {
  3989. baseDao.updateByCondition("SaleForecastDetail", "sd_yqty=(case when NVL(sd_yqty,0)-(" + rs.getDouble("scd_clashqty")
  3990. + ")<0 then 0 else sd_yqty-(" + rs.getDouble("scd_clashqty") + ") end)", "sd_detno=" + rs.getInt("scd_orderdetno")
  3991. + " AND sd_sfid=(SELECT sf_id FROM SaleForecast WHERE sf_code='" + rs.getString("scd_ordercode") + "')");
  3992. }
  3993. }
  3994. return null;
  3995. }
  3996. /*
  3997. * 拨出单过账后过账拨入单
  3998. */
  3999. public String turnProdIO(int id,Employee employee) {
  4000. String dets = null;
  4001. SqlRowList rs = baseDao.queryForRowSet("select pi_relativeplace,pi_class from prodinout where pi_id=?", id);
  4002. if (rs.next()) {
  4003. SqlRowList rs1 = baseDao.queryForRowSet(
  4004. "select pi_id from prodinout where pi_inoutno=? and pi_class in ('拨入单','销售拨入单') and nvl(PI_UNAUTOPOSTIN,0)=0",
  4005. rs.getString("pi_relativeplace"));
  4006. if (rs1.next()) {
  4007. if (baseDao.isDBSetting("sys","cgyCheck")) {
  4008. /**
  4009. * maz
  4010. * 出入库单判断过账人是否在明细行仓库的仓管员资料表中存在,人员资料中查找管理员一样限制如果为非仓库员不允许过账
  4011. * 虚拟账号不限制 2017080135
  4012. */
  4013. Object type = baseDao.getFieldDataByCondition("Employee", "em_code",
  4014. "em_code='"+employee.getEm_code()+"'");
  4015. if (type != null) {
  4016. dets = baseDao.getJdbcTemplate()
  4017. .queryForObject(
  4018. "select wm_concat(pd_pdno) from prodinout,prodiodetail where pi_id=pd_piid and pi_id=? and pd_id not in "
  4019. + "(select pd_id from prodinout,prodiodetail,warehouse,warehouseman where pi_id=pd_piid and pd_whcode=wh_code and wh_id=wm_whid "
  4020. + "and pi_id=? and wm_cgycode=?)", String.class, rs1.getInt("pi_id"),
  4021. rs1.getInt("pi_id"), employee.getEm_code());
  4022. }
  4023. }
  4024. if (dets == null) {
  4025. if ("拨出单".equals(rs.getString("pi_class"))) {
  4026. postProdInOut(rs1.getInt("pi_id"), "ProdInOut!AppropriationIn",employee);
  4027. } else if ("销售拨出单".equals(rs.getString("pi_class"))) {
  4028. postProdInOut(rs1.getInt("pi_id"), "ProdInOut!SaleAppropriationIn",employee);
  4029. }
  4030. }
  4031. }
  4032. }
  4033. return dets;
  4034. }
  4035. /**
  4036. * @author XiaoST 2016年8月25日 下午7:18:45 更新工单的完工状态,在完工入库,委外验收,验退过账,反过账时调用
  4037. */
  4038. public void updateMakeFinishStatus(Integer ma_id) {
  4039. baseDao.execute("update make set ma_madeqty=nvl((select sum(pd_inqty-pd_outqty) from prodiodetail where " +
  4040. "pd_ordercode=ma_code and pd_piclass in ('委外验收单','完工入库单','委外验退单') and pd_status>0),0) WHERE ma_id="
  4041. + ma_id);
  4042. baseDao.execute("update make set ma_finishstatuscode='COMPLETED',ma_finishstatus='已完工' where ma_id=" + ma_id + " and ma_madeqty>=ma_qty ");
  4043. baseDao.execute("update make set ma_finishstatuscode='PARTFI',ma_finishstatus='部分完工' where ma_id="
  4044. + ma_id + " and ma_madeqty>0 and ma_madeqty<ma_qty ");
  4045. baseDao.execute("update make set ma_finishstatuscode='UNCOMPLET',ma_finishstatus='未完工' where ma_id=" + ma_id + " and ma_madeqty=0 ");
  4046. }
  4047. private void changeMaStatus(int pi_id) {
  4048. String ids = baseDao
  4049. .getJdbcTemplate()
  4050. .queryForObject(
  4051. "select wm_concat(ma_id) from (select distinct ma_id from ProdIODetail left join make on ma_code=pd_ordercode where pd_piid=?)",
  4052. String.class, pi_id);
  4053. if (ids != null) {
  4054. updateMakeGetStatus(ids);
  4055. }
  4056. }
  4057. /**
  4058. * 修改工单领料状态
  4059. */
  4060. public void updateMakeGetStatus(String ids) {
  4061. baseDao.execute("update make set ma_turnstatuscode='UNGET',ma_turnstatus='未领料' where ma_id in ("
  4062. + ids + ") and not exists(select 1 from makematerial where mm_maid=ma_id and NVL(mm_havegetqty,0)+NVL(mm_totaluseqty,0)>0)");
  4063. baseDao.execute("update make set ma_turnstatuscode='PARTGET',ma_turnstatus='部分转领料' where ma_id in ("
  4064. + ids + ") and nvl(ma_turnstatuscode,' ')<>'PARTGET' and exists (select 1 from makematerial where mm_maid=ma_id "
  4065. + "and NVL(mm_havegetqty,0)+NVL(mm_totaluseqty,0)+NVL(mm_turnaddqty,0)>0 and NVL(mm_materialstatus,' ')=' ')");
  4066. baseDao.execute("update make set ma_turnstatuscode='TURNGET',ma_turnstatus='已转领料' where ma_id in ("
  4067. + ids + ") and nvl(ma_turnstatuscode,' ')<>'TURNGET' and not exists(select 1 from makematerial where mm_maid=ma_id "
  4068. + "and nvl(MM_QTY,0)-NVL(mm_havegetqty,0)-NVL(mm_totaluseqty,0)-NVL(mm_turnaddqty,0)>0 and NVL(mm_materialstatus,' ')=' ')");
  4069. }
  4070. private void refreshTurnQty(Integer ma_id, Integer mm_id) {
  4071. if (mm_id != null && mm_id > 0) {
  4072. // 已转领料数
  4073. 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="
  4074. + ma_id + " and mm_id=" + mm_id);
  4075. // 转补料数
  4076. baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  4077. + "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 ="
  4078. + ma_id + " and mm_id=" + mm_id);
  4079. // 更新替代已转数
  4080. baseDao.execute("update makematerialreplace set mp_repqty=(select NVL(sum(nvl(pd_outqty,0)),0) from prodiodetail,prodinout "
  4081. + "where pd_piid=pi_id and pd_status=0 and pd_prodcode=mp_prodcode and pd_ordercode=mp_mmcode and "
  4082. + "pd_orderdetno=mp_mmdetno and pd_piclass in ('生产领料单', '委外领料单')) where mp_maid=" + ma_id + " and mp_mmid=" + mm_id);
  4083. baseDao.execute("update makematerialreplace set mp_repqty=0 where mp_maid=" + ma_id + " AND MP_REPQTY<0");
  4084. // 更新替代总已转数
  4085. 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="
  4086. + ma_id + " and mm_id=" + mm_id);
  4087. // 更新替代总已领数
  4088. 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="
  4089. + ma_id + " and mm_id=" + mm_id);
  4090. } else {
  4091. // 已转领料数
  4092. baseDao.execute("update MakeMaterial set mm_totaluseqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  4093. + "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="
  4094. + ma_id);
  4095. // 转补料数
  4096. baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
  4097. + "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 ="
  4098. + ma_id);
  4099. // 更新替代已转数
  4100. baseDao.execute("update makematerialreplace set mp_repqty=(select NVL(sum(nvl(pd_outqty,0)),0) from prodiodetail,prodinout "
  4101. + "where pd_piid=pi_id and pd_status=0 and pd_prodcode=mp_prodcode and pd_ordercode=mp_mmcode and "
  4102. + "pd_orderdetno=mp_mmdetno and pd_piclass in ('生产领料单', '委外领料单')) where mp_maid=" + ma_id);
  4103. baseDao.execute("update makematerialreplace set mp_repqty=0 where mp_maid=" + ma_id + " AND MP_REPQTY<0");
  4104. // 更新替代总已转数
  4105. 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="
  4106. + ma_id);
  4107. // 更新替代总已领数
  4108. 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="
  4109. + ma_id);
  4110. }
  4111. }
  4112. private void setBackQty(String maidstr, Integer mm_id) {
  4113. if (mm_id != null && mm_id > 0) {
  4114. baseDao.getJdbcTemplate()
  4115. .execute(
  4116. "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 ("
  4117. + maidstr + ") and mm_id=" + mm_id);
  4118. baseDao.getJdbcTemplate()
  4119. .execute(
  4120. "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 ("
  4121. + maidstr + ") and mp_mmid=" + mm_id);
  4122. baseDao.getJdbcTemplate()
  4123. .execute(
  4124. "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 ("
  4125. + maidstr + ") and mm_id=" + mm_id);
  4126. baseDao.getJdbcTemplate()
  4127. .execute(
  4128. "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 ("
  4129. + maidstr + ") and mp_mmid=" + mm_id);
  4130. } else {
  4131. baseDao.getJdbcTemplate()
  4132. .execute(
  4133. "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 ("
  4134. + maidstr + ")");
  4135. baseDao.getJdbcTemplate()
  4136. .execute(
  4137. "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 ("
  4138. + maidstr + ")");
  4139. baseDao.getJdbcTemplate()
  4140. .execute(
  4141. "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 ("
  4142. + maidstr + ")");
  4143. baseDao.getJdbcTemplate()
  4144. .execute(
  4145. "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 ("
  4146. + maidstr + ")");
  4147. }
  4148. }
  4149. private String checkFreezeMonth(Object pidate) {
  4150. boolean bool = baseDao.checkIf("PeriodsDetail", "pd_code='MONTH-P' and pd_status=99 and pd_detno=to_char(to_date('" + pidate
  4151. + "','yyyy-mm-dd hh24:mi:ss'), 'yyyymm')");
  4152. if (bool) {
  4153. return "单据日期所属期间已结账,不允许进行当前操作!";
  4154. }
  4155. String freeze = baseDao.getDBSetting("sys","freezeMonth");
  4156. if (freeze != null && !freeze.equals("")) {
  4157. if (Integer.parseInt(freeze) == DateUtil.getYearmonth(pidate.toString())) {
  4158. return "单据日期所属期间已冻结,不允许进行当前操作!";
  4159. }
  4160. }
  4161. return null;
  4162. }
  4163. private String ScrapCheckAll(int ms_id, String caller) {
  4164. // 判断工单状态是否已审核
  4165. SqlRowList rs = baseDao.queryForRowSet("select md_detno,md_mmcode,ma_status from makescrapdetail,make where md_msid=" + ms_id
  4166. + " and md_mmcode=ma_code and ma_statuscode<>'AUDITED' ");
  4167. if (rs.next()) {
  4168. return "制造单" + rs.getString("md_mmcode") + "状态[" + rs.getString("ma_status") + "],只能操作已审核状态的制造单!";
  4169. }
  4170. return null;
  4171. }
  4172. /**
  4173. * 判断报废数是否大于结存可报废数
  4174. *
  4175. * @param
  4176. */
  4177. private String ScrapCheck_scrapqty(Integer ms_id) {
  4178. String sql = "";
  4179. String err = "";
  4180. sql = "UPDATE MakeMaterial set mm_allscrapqty=nvl(mm_scrapqty,0)+nvl((select sum(md_qty) from MakeScrapDetail,MakeScrap where ms_id=md_msid and (ms_statuscode='COMMITED' or ms_id='"
  4181. + ms_id
  4182. + "') and mm_code=md_mmcode and md_mmdetno=mm_detno),0) "
  4183. + " WHERE (mm_code,mm_detno) in (select md_mmcode as mm_code,md_mmdetno as mm_detno from MakeScrapDetail where md_msid='"
  4184. + ms_id + "')";
  4185. baseDao.execute(sql);
  4186. if(baseDao.isDBSetting("sys","usingMakeCraft")){
  4187. sql = "select md_detno,md_mmcode,md_prodcode from MakeScrapDetail left join makematerial on md_mmcode=mm_code and md_mmdetno=mm_detno left join make on mm_maid=ma_id where md_msid="
  4188. + ms_id + " and round(nvl(mm_allscrapqty,0),4)>round(nvl(mm_havegetqty,0)+nvl(mm_stepinqty,0)-nvl(mm_clashqty,0) -NVL(mm_scrapqty,0),4) ";
  4189. }else{
  4190. sql = "select md_detno,md_mmcode,md_prodcode from MakeScrapDetail left join makematerial on md_mmcode=mm_code and md_mmdetno=mm_detno left join make on mm_maid=ma_id where md_msid="
  4191. + ms_id ;
  4192. if(baseDao.isDBSetting("Make!Base", "allowChangeAfterCom")){
  4193. sql = sql+ " and round(nvl(mm_allscrapqty,0),4) > round(nvl(mm_havegetqty,0)-nvl(mm_backqty,0),4) ";
  4194. }else{
  4195. sql += " and round(nvl(mm_allscrapqty,0),4)>round(nvl(mm_havegetqty,0)-mm_oneuseqty*ma_madeqty,4) ";
  4196. }
  4197. }
  4198. SqlRowList rs = baseDao.queryForRowSet(sql);
  4199. while (rs.next()) {
  4200. err = err + "," + rs.getString("md_detno");
  4201. }
  4202. if (!err.equals("")) {
  4203. return "序号:" + err.substring(1) + "报废数大于结存数!";
  4204. }
  4205. sql = "SELECT count(1) detno ,wm_concat(md_detno) as detnostr FROM MakeScrapDetail WHERE md_msid='" + ms_id + "' and md_qty<=0 ";
  4206. rs = baseDao.queryForRowSet(sql);
  4207. if (rs.next()) {
  4208. if (rs.getInt("detno") > 0) {
  4209. return "序号:" + rs.getString("detnostr") + "报废数小于或等于0,不能审核!";
  4210. }
  4211. }
  4212. return null;
  4213. }
  4214. private String copcheck(int ms_id) {
  4215. if (baseDao.isDBSetting("sys","CopCheck")) {
  4216. // 生产报废单:明细行制造单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
  4217. String dets = baseDao
  4218. .getJdbcTemplate()
  4219. .queryForObject(
  4220. "select wm_concat(md_detno) from MakeScrapDetail left join MakeScrap on md_msid=ms_id left join Make on md_mmcode=ma_code where ms_id=? and nvl(ma_cop,' ')<>nvl(ms_cop,' ') ",
  4221. String.class, ms_id);
  4222. if (dets != null) {
  4223. return "行号:" + dets+"制造单所属公司与当前单所属公司不一致,不允许进行当前操作!";
  4224. }
  4225. }
  4226. return null;
  4227. }
  4228. // 验证从表中的工单的序号是否有效
  4229. private String checkMakeMaterial(int ms_id) {
  4230. String err = baseDao
  4231. .getJdbcTemplate()
  4232. .queryForObject(
  4233. "select wm_concat(md_detno) from MakeScrapdetail where md_msid=? and not exists (select 1 from make left join makematerial on ma_id=mm_maid where md_mmcode=ma_code and md_mmdetno=mm_detno)",
  4234. String.class, ms_id);
  4235. if (err != null) {
  4236. return "序号:" + err.toString() + " 无对应工单和序号,不允许进行当前操作!";
  4237. }
  4238. return null;
  4239. }
  4240. }