MESServiceImpl.java 312 KB

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