MESServiceImpl.java 281 KB

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