MESServiceImpl.java 306 KB

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