| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341 |
- package com.uas.eis.service.Impl;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.uas.eis.dao.BaseDao;
- import com.uas.eis.dao.SqlRowList;
- import com.uas.eis.dto.Key;
- import com.uas.eis.entity.Employee;
- import com.uas.eis.entity.VerifyApply;
- import com.uas.eis.entity.VerifyApplyDetail;
- import com.uas.eis.sdk.entity.ApiResult;
- import com.uas.eis.sdk.resp.ApiResponse;
- import com.uas.eis.service.MESService;
- import com.uas.eis.utils.*;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.jdbc.core.BeanPropertyRowMapper;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.servlet.http.HttpServletRequest;
- import java.io.IOException;
- import java.util.*;
- /**
- * @author koul
- * @email koul@usoftchina.com
- * @date 2021-12-08 9:32
- */
- @Service
- public class MESServiceImpl implements MESService {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
- @Autowired
- private BaseDao baseDao;
- @Autowired
- private TransferRepository transferRepository;
- @Override
- public ApiResult<String> checkVerifyApply(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject jsonData = getJsonData(request);
- String mesCode = StringUtil.nvl(jsonData.get("mesCode"), "");
- if ("".equals(mesCode)){
- return ApiResponse.failRsp("10011",requestId,"MES编号不能为空!");
- }
- VerifyApply verifyApply = baseDao.getJdbcTemplate().queryForObject("select va_id,va_mescode,va_code,to_char(va_date,'yyyy-MM-dd HH24:mi:ss') va_date,va_vendcode,va_vendname,va_currency,va_rate,va_paymentscode,va_payments,va_transport,va_sendcode,va_emcode,va_emname,va_departmentcode,va_department,va_recorder,case when nvl(va_cop,' ')=' ' then 'HS' else va_cop end va_cop,va_remark,va_ancode,va_factory,0 version,va_type,va_pucode,case when nvl(va_pucode,' ')=' ' then 0 else (select pu_id from purchase where pu_code=va_pucode) end pu_id,va_status,1 posted,to_char(va_auditdate,'yyyy-MM-dd HH24:mi:ss') va_auditdate,va_auditman,va_custcode,va_custname from VerifyApply where va_statuscode='AUDITED' and va_mescode=?",
- new BeanPropertyRowMapper<VerifyApply>(VerifyApply.class), mesCode);
- if (verifyApply==null) {
- return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
- }
- SqlRowList rs = baseDao.queryForRowSet("select case when va_custcode='AR214' or nvl(va_custcode,' ')=' ' then 'HS' else nvl(cu_mescode,cu_code) end cu_code,cu_name from verifyapply left join customer on va_custcode=cu_code where va_statuscode='AUDITED' and va_mescode='"+mesCode+"'");
- if (rs.next()){
- verifyApply.setVa_custcode(rs.getString("cu_code"));
- }
- List<VerifyApplyDetail> verifyApplyDetails = baseDao.query("select vad_code,vad_prodcode,pr_detail,replace(PR_SPEC,'''','''''') pr_spec,pr_unit,va_recorder,va_date,pr_kh_user,cu_name,sum(nvl(vad_qty,0)) vad_qty,vad_salecode from ( select vad_code,vad_prodcode,pr_detail,pr_spec,pr_unit,vad_qty,va_recorder,to_char(va_date,'yyyy-MM-dd HH24:mi:ss') va_date,case when pr_kh_user='柏英特' or nvl(pr_kh_user,' ')=' ' then 'HS' else nvl(cu_mescode,cu_code) end pr_kh_user,cu_name,vad_salecode from verifyapplydetail left join VerifyApply on va_id=vad_vaid left join product on vad_prodcode=pr_code left join customer on cu_shortname=pr_kh_user where nvl(vad_qty,0)>0 and vad_vaid="+verifyApply.getVa_id()+") group by vad_code,vad_prodcode,pr_detail,pr_spec,pr_unit,va_recorder,va_date,pr_kh_user,cu_name,vad_salecode", VerifyApplyDetail.class);
- verifyApply.setDetail(verifyApplyDetails);
- String s = JSON.toJSONString(verifyApply, SerializerFeature.WriteMapNullValue);
- return ApiResponse.successRsp("0","获取成功!",requestId,s);
- }
- @Override
- public ApiResult<String> purcCheckin(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- Object vaid=0;
- String caller="VerifyApply!ToOtherIn";
- String type="其它入库单";
- String djcaller="ProdInOut!OtherIn";
- String sellerName="";
- String whcode="";
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- String mesCode = StringUtil.nvl(jsonObject.get("mesCode"),"");
- whcode= StringUtil.nvl(jsonObject.get("whNo"), "");
- if ("".equals(mesCode)){
- return ApiResponse.failRsp("10011",requestId,"ERP单据编号不能为空!");
- }
- int count = baseDao.getCountByCondition("verifyApply", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
- if (count<1){
- return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
- }
- vaid = baseDao.getFieldDataByCondition("verifyApply", "va_id", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
- String vaClass = StringUtil.nvl(baseDao.getFieldDataByCondition("VerifyApply", "va_class", "va_id=" + vaid), "");
- if ("委外收料单".equals(vaClass)) {
- caller = "VerifyApply!ToOutsideCheckIn";
- type = "委外验收单";
- djcaller = "ProdInOut!OutsideCheckIn";
- }else if("采购收料单".equals(vaClass)){
- int count1 = baseDao.getCount("select count(1) from VerifyApplyDetail where nvl(vad_pucode,' ')<>' ' and vad_vaid=" + vaid);
- if (count1 > 0) {
- caller = "VerifyApply!ToPurcIn";
- type = "采购验收单";
- djcaller = "ProdInOut!PurcCheckin";
- }
- }
- //判断已转数
- 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);
- if(chekQty !=null){
- return ApiResponse.failRsp("10013",requestId,"检测到" + chekQty + ",本次数量超出可转数量!");
- }
- if ("VerifyApply!ToPurcIn".equals(caller)) {
- // 判断该收料单是否已经转入过采购验收单
- Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
- code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and " + "PI_REFNO='采购收料单' and pi_class='采购验收单'");
- if (code != null && !code.equals("")) {
- return ApiResponse.failRsp("10014", requestId, "该收料单已转入过采购验收单,验收单号[" + code + "]");
- }
- }
- if ("VerifyApply!ToOtherIn".equals(caller)) {
- // 判断该收料单是否已经转入过其它入库单
- Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
- code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='其它入库单'");
- if (code != null && !code.equals("")) {
- return ApiResponse.failRsp("10014", requestId, "该收料单已转入过其它入库单,单号[" + code + "]");
- }
- }
- if ("VerifyApply!ToOutsideCheckIn".equals(caller)) {
- // 判断该收料单是否已经转入过委外验收单
- Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
- code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='委外验收单'");
- if (code != null && !code.equals("")) {
- return ApiResponse.failRsp("10014", requestId, "该收料单已转入过委外验收单,单号[" + code + "]");
- }
- }
- sellerName = StringUtil.nvl(jsonObject.get("sellerName"), "mes");
- }
- JSONArray array = data.get("detail");
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
- String itemNo = StringUtil.nvl(json.get("itemNo"), "");
- Double qty = Double.parseDouble(StringUtil.nvl(json.get("qty"), "0"));
- Double vadQty = baseDao.getSummaryByField("verifyapplydetail", "vad_qty", "vad_prodcode='" + itemNo + "' and vad_vaid=" + vaid);
- int compare = qty.compareTo(vadQty);
- if (compare>0){
- return ApiResponse.failRsp("10017",requestId, "物料:"+itemNo+",收料数量:"+qty+"超出ERP收料单数量:"+vadQty+ ",不允许入库!");
- }
- if (compare<0){
- return ApiResponse.failRsp("10018",requestId,"物料:"+itemNo+",收料数量:"+qty+"少于ERP收料单数量:"+vadQty+",不允许入库!");
- }
- }
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10015",requestId,"MES仓库编号不能为空!");
- }
- 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 + "'");
- if (coun<=0){
- return ApiResponse.failRsp("10016",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- int piid =0;
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_name=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), sellerName);
- // 转采购验收单
- Key key = transferRepository.transfer(caller, vaid,employee);
- piid = key.getId();
- // 转入明细
- transferRepository.transferDetail(caller, vaid, key,employee);
- if (piid != 0) {
- baseDao.execute("delete from prodiodetail where nvl(pd_inqty,0)<=0 and pd_piid="+piid);
- baseDao.updateByCondition("prodiodetail", "pd_whcode='"+warehouses[0]+"',pd_whname='"+warehouses[1]+"'", "pd_piid=" + piid);
- baseDao.updateByCondition("prodinout", "pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"'", "pi_id=" + piid);
- baseDao.execute("update prodiodetail set pd_prodid=(select pr_id from product where pd_prodcode=pr_code) where pd_piid=" + piid
- + " and nvl(pd_prodcode,' ')<>' '");
- baseDao.execute("update prodiodetail set pd_whid=(select wh_id from warehouse where wh_code=pd_whcode) where pd_piid=" + piid
- + " and nvl(pd_whcode,' ')<>' '");
- baseDao.updateByCondition("ProdInOut",
- "pi_total=(SELECT round(sum(nvl(pd_orderprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid="
- + piid + ")", "pi_id=" + piid);
- baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + piid);
- if ("VerifyApply!ToPurcIn".equals(caller)) {
- baseDao.execute("Insert into ProdChargeDetail(pd_id,pd_piid,pd_detno,pd_type,pd_amount,pd_currency,pd_rate) "
- + "select ProdChargeDetail_seq.nextval, " + piid + ", pd_detno, pd_type,pd_amount,pd_currency,pd_rate "
- + "from ProdChargeDetailAN where PD_ANID=" + vaid);
- SqlRowList rs = baseDao.queryForRowSet("select vad_pucode,vad_pudetno,vad_qty from VerifyApplyDetail where vad_vaid=" + vaid);
- String pCode = null;
- int pDetno = 0;
- double yq = 0;
- Set<String> pCodes = new HashSet<String>();
- while (rs.next()) {
- pCode = rs.getString("vad_pucode");
- if (!pCodes.contains(pCode)) {
- pCodes.add(pCode);
- }
- pDetno = rs.getInt("vad_pudetno");
- yq = rs.getDouble("vad_qty");
- baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno);
- baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno
- + " and pd_qty=" + yq);
- }
- Iterator<String> iter = pCodes.iterator();
- while (iter.hasNext()) {
- pCode = iter.next();
- int total = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "'");
- int aud = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "' AND nvl(pd_acceptqty,0)=0");
- int turn = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode
- + "' AND nvl(pd_acceptqty,0)=nvl(pd_qty,0)");
- String statuscode = aud == total ? "" : (turn == total ? "TURNIN" : "PART2IN");
- String status = aud == total ? "" : (turn == total ? "已入库" : "部分入库");
- baseDao.updateByCondition("Purchase",
- "pu_turnstatuscode='" + statuscode + "',pu_turnstatus='" + status + "'", "pu_code='" + pCode + "'");
- }
- }
- // 修改收料状态
- baseDao.updateByCondition("VerifyApplyDetail", "vad_yqty=vad_qty", "vad_vaid=" + vaid);
- baseDao.updateByCondition("VerifyApply", "va_turnstatuscode='TURNIN',va_turnstatus='已入库'", "va_id=" + vaid);
- String s = postProdInOut(piid, djcaller, employee);
- logger.info("收料单入库=="+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",请在ERP查看!");
- }
- return ApiResponse.failRsp("10019",requestId,"ERP生成单据失败!");
- }
- @Override
- public ApiResult<String> prodInOutMakeIn(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- String ma_tasktype="";
- int piid=0;
- String picode="";
- String piclass="完工入库单";
- String picaller="ProdInOut!Make!In";
- int ma_id=0;
- List<String> sqls = new ArrayList<>();
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- JSONArray array = data.get("detail");
- if(array!=null&&array.size()>0) {
- for (int i = 0; i < array.size(); i++) {
- JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
- String macode = StringUtil.nvl(json.get("FICMOBillNo"),"");
- Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
- if (data1 != null && data1.length > 0) {
- ma_tasktype = StringUtil.nvl(data1[0], "");
- ma_id = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- } else {
- return ApiResponse.failRsp("10077", requestId, "工单在ERP不存在,请核对!");
- }
- /*float fauxqty = json.get("Fauxqty") == null ? 0 : Float.parseFloat(json.get("Fauxqty").toString());
- String msg = baseDao.callProcedure("USER_WGRKCHECK", new Object[]{ma_id, fauxqty});
- if (msg != null && !msg.trim().equals("")){
- return ApiResponse.failRsp("10078",requestId,msg);
- }*/
- }
- }
- if ("OS".equals(ma_tasktype)) {
- picaller = "ProdInOut!OutsideCheckIn";
- piclass = "委外验收单";
- }
- for (int i = 0; i <jsonArray.size() ; i++) {
- Object obj = jsonArray.get(i);
- JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(obj, ""));
- String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
- if (result!=null){
- return result;
- }
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDCStockID")));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
- Map<Object, Object> map6 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
- Map<Object, Object> map7 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
- Map<Object, Object> map8 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
- String whcode = StringUtil.nvl(map4.get("FNumber"), "");
- if ("".equals(whcode)) {
- return ApiResponse.failRsp("10073", requestId, "MES仓库编号不能为空!");
- }
- 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 + "'");
- if (count <= 0) {
- return ApiResponse.failRsp("10074", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- if ("OS".equals(ma_tasktype)) {
- // 转入委外验收单主记录
- piid = baseDao.getSeqId("PRODINOUT_SEQ");
- picode = baseDao.sGetMaxNumber(picaller, 2);
- 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) " +
- "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+"')");
- sqls.add("update prodinout set (pi_cardcode,pi_title,pi_currency,pi_rate,pi_receivecode," +
- "pi_receivename,pi_cardid,pi_paymentcode,pi_payment,pi_cop,pi_belongs," +
- "pi_sourcecode,pi_sellercode)=(select ma_vendcode,ma_vendname,ma_currency,ma_rate,ve_apvendcode," +
- "ve_apvendname,ve_id,ma_paymentscode,ma_payments,ma_cop,ve_buyername,ma_code,em_code from make left " +
- "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);
- sqls.add("update ProdinOut set pi_sellername=pi_belongs where pi_class='"+piclass+"' and pi_id=" + piid);
- 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");
- } else {
- piid = baseDao.getSeqId("PRODINOUT_SEQ");
- picode = baseDao.sGetMaxNumber(picaller, 2);
- 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) " +
- "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+"')");
- }
- }
- int detno=1;
- for (int i = 0; i <array.size(); i++) {
- Object obj = array.get(i);
- JSONObject jsonObject3 = JSON.parseObject(StringUtil.nvl(obj, ""));
- Map<Object, Object> map11 = JSONUtil.toMap(StringUtil.valueOf(jsonObject3.get("FItemID")));
- Map<Object, Object> map12 = JSONUtil.toMap(StringUtil.valueOf(jsonObject3.get("FDCStockID1")));
- String whcode = StringUtil.nvl(map12.get("FNumber"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10075",requestId,"MES仓库编号不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10076",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- String fBatchNo = StringUtil.nvl(jsonObject3.get("FBatchNo"), "");
- float fauxqty = jsonObject3.get("Fauxqty") == null ? 0 : Float.parseFloat(jsonObject3.get("Fauxqty").toString());
- String fSecUnitID = StringUtil.nvl(jsonObject3.get("FSecUnitID"), "");
- float fSecCoefficient = jsonObject3.get("FSecCoefficient") == null ? 0 : Float.parseFloat(jsonObject3.get("FSecCoefficient").toString());
- float fSecQty = jsonObject3.get("FSecQty") == null ? 0 : Float.parseFloat(jsonObject3.get("FSecQty").toString());
- float fAuxPlanPrice = jsonObject3.get("FAuxPlanPrice") == null ? 0 : Float.parseFloat(jsonObject3.get("FAuxPlanPrice").toString());
- float fPlanAmount = jsonObject3.get("FPlanAmount") == null ? 0 : Float.parseFloat(jsonObject3.get("FPlanAmount").toString());
- float fauxprice = jsonObject3.get("Fauxprice") == null ? 0 : Float.parseFloat(jsonObject3.get("Fauxprice").toString());
- float famount = jsonObject3.get("Famount") == null ? 0 : Float.parseFloat(jsonObject3.get("Famount").toString());
- String fnote = StringUtil.nvl(jsonObject3.get("Fnote"), "");
- String fKFDate = StringUtil.nvl(jsonObject3.get("FKFDate"), "");
- String fPeriodDate = StringUtil.nvl(jsonObject3.get("FPeriodDate"), "");
- int fDCSPID = jsonObject3.get("FDCSPID") == null ? 0 : Integer.parseInt(jsonObject3.get("FDCSPID").toString());
- Object location="";
- if (fDCSPID>0){
- location = baseDao.getFieldDataByCondition("ProductLocation", "pl_name", "pl_id=" + fDCSPID);
- }
- String fSourceBillNo = StringUtil.nvl(jsonObject3.get("FSourceBillNo"), "");
- String fICMOBillNo = StringUtil.nvl(jsonObject3.get("FICMOBillNo"), "");
- String fEntrySelfA0248 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0248"), "");
- String fEntrySelfA0245 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0245"), "");
- String fEntrySelfA0246 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0246"), "");
- String fEntrySelfA0247 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0247"), "0");
- String fEntrySelfA0242 = StringUtil.nvl(jsonObject3.get("FEntrySelfA0242"), "0");
- if ("OS".equals(ma_tasktype)) {
- sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_ordercode,pd_prodcode," +
- "pd_batchcode,pd_inqty,pd_nxlh,pd_purcrate,pd_notinqty,pd_orderprice,pd_ordertotal,pd_price," +
- "pd_total,pd_whcode,pd_whname,pd_remark,pd_prodmadedate,pd_replydate,pd_location,pd_macode,pd_xb," +
- "pd_bz,pd_dbds,pd_zds,pd_status) values (PRODIODETAIL_SEQ.nextval," + piid + ",'" + picode + "','"+piclass+
- "'," + detno + ",'" + fSourceBillNo +
- "','" + map11.get("FNumber") + "','" + fBatchNo + "'," + fauxqty + ",'" + fSecUnitID + "'," + fSecCoefficient + "," + fSecQty + "," + fAuxPlanPrice + "," + fPlanAmount + "," + fauxprice + "," +
- "" + famount + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + fnote + "',to_date('" + fEntrySelfA0248 + "'," +
- "'yyyy-MM-dd HH24:mi:ss'),to_date('" + fPeriodDate + "','yyyy-MM-dd HH24:mi:ss'),'" + location + "','" + fICMOBillNo + "','" + fEntrySelfA0246 + "','" + fEntrySelfA0245 + "'," + fEntrySelfA0247 + "," + fEntrySelfA0242 + ",0)");
- detno++;
- }else {
- sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_ordercode,pd_prodcode," +
- "pd_batchcode,pd_inqty,pd_nxlh,pd_purcrate,pd_notinqty,pd_orderprice,pd_ordertotal,pd_price," +
- "pd_total,pd_whcode,pd_whname,pd_remark,pd_prodmadedate,pd_replydate,pd_location,pd_macode,pd_xb," +
- "pd_bz,pd_dbds,pd_zds,pd_status) values (PRODIODETAIL_SEQ.nextval," + piid + ",'" + picode + "','"+piclass+
- "'," + detno + ",'" + fSourceBillNo +
- "','" + map11.get("FNumber") + "','" + fBatchNo + "'," + fauxqty + ",'" + fSecUnitID + "'," + fSecCoefficient + "," + fSecQty + "," + fAuxPlanPrice + "," + fPlanAmount + "," + fauxprice + "," +
- "" + famount + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + fnote + "',to_date('" + fEntrySelfA0248 + "'," +
- "'yyyy-MM-dd HH24:mi:ss'),to_date('" + fPeriodDate + "','yyyy-MM-dd HH24:mi:ss'),'" + location + "','" + fICMOBillNo + "','" + fEntrySelfA0246 + "','" + fEntrySelfA0245 + "'," + fEntrySelfA0247 + "," + fEntrySelfA0242 + ",0)");
- detno++;
- }
- }
- if ("OS".equals(ma_tasktype)) {
- sqls.add("update prodiodetail set (pd_location,pd_orderprice,pd_taxrate,pd_prodid,pd_orderid,pd_wccode)=" +
- "(select pr_location,ma_price,ma_taxrate,pr_id,ma_id,ma_wccode from make left join Product on " +
- "ma_prodcode=pr_code where ma_id="+ma_id+") where pd_piid="+piid);
- sqls.add("update Prodiodetail set pd_whname=(select wh_description from warehouse where pd_whcode=wh_code) where pd_piid="
- + piid);
- sqls.add("update Prodiodetail set pd_total=round(pd_inqty*pd_orderprice,2) where pd_piid=" + piid);
- }
- //更新已转完工数
- 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);
- sqls.add("update make set ma_tomadeqty=ma_madeqty where ma_id=" + ma_id + " and nvl(ma_madeqty,0)>nvl(ma_tomadeqty,0)");
- //更新最大套料数
- 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 + ") ");
- sqls.add("update make set ma_canmadeqty=ma_qty where ma_id in (" + ma_id
- + ") and ma_id not in (select ma_id from make left join makematerial on ma_id=mm_maid where ma_id in (" + ma_id
- + ") and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0 and mm_oneuseqty*ma_qty<=mm_qty+0.1)");
- sqls.add("update make set ma_canmadeqty=0 where ma_id in (" + ma_id + ") and NVL(ma_canmadeqty,0)<=0");
- baseDao.execute(sqls);
- if(!baseDao.isDBSetting(picaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,piclass+":"+picode+",请在ERP查看并手工过账!");
- }
- String s = postProdInOut(piid, picaller, employee);
- logger.info("完工过账信息=="+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,piclass+":"+picode+",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,piclass+":"+picode+",请在ERP查看!");
- }
- @Override
- public ApiResult<String> makeDeleteCheck(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject jsonData = getJsonData(request);
- Object maId = jsonData.get("finterid");
- // 只能删除在录入的单据!
- SqlRowList status =
- baseDao.queryForRowSet("select ma_statuscode,ma_checkstatuscode from make where ma_code='"+maId+"'");
- if (status.next()) {
- if (!status.getString("ma_statuscode").equals("ENTERING") && (status.getString("ma_checkstatuscode").equals("APPROVE") || status.getString("ma_checkstatuscode").equals("COMMITED"))) {
- return ApiResponse.failRsp("10015",requestId,"只能删除在录入且批准状态不等于已批准或已提交的工单");
- }
- }
- // 启用工厂模式 有对应的作业单 制造单不能删除
- if (baseDao.isDBSetting("sys","usingMakeCraft")) {
- int count = baseDao.getCount("Select count(1) from makecraft left join make on mc_makecode=ma_code where ma_code='"+maId+"'");
- if (count > 0) {
- return ApiResponse.failRsp("10016",requestId,"当前工单存在作业单,不能删除");
- }
- }
- return ApiResponse.successRsp("0",requestId,"校验通过!");
- }
- @Override
- public ApiResult<String> initMakeScrap(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- int id=0;
- String code="";
- String msclass="生产报废单";
- String caller="MakeScrap";
- String sourcetype="制造单";
- List<String> sqls = new ArrayList<>();
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- String fSelBillNo = StringUtil.nvl(jsonObject.get("FSelBillNo"), "");
- if ("".equals(fSelBillNo)){
- return ApiResponse.failRsp("10029", requestId, "MES单号不能为空!");
- }
- String prodNo = StringUtil.nvl(jsonObject.get("prodNo"), "");
- if ("".equals(prodNo)){
- return ApiResponse.failRsp("10023",requestId,"工单单号不能为空!");
- }
- String ma_tasktype = StringUtil.nvl(baseDao.getFieldDataByCondition("make", "ma_tasktype", "ma_code='" + prodNo + "'"), "");
- if ("OS".equals(ma_tasktype)) {
- msclass = "委外报废单";
- caller = "MakeScrap!Make";
- sourcetype="委外加工单";
- }
- int count = baseDao.getCount("select count(1) from MakeScrap where ms_class='" + msclass + "' and ms_mescode='" + fSelBillNo + "'");
- if (count>0){
- Object co = baseDao.getFieldDataByCondition("MakeScrap", "ms_code", "ms_class='" + msclass + "' and ms_mescode='" + fSelBillNo + "'");
- return ApiResponse.failRsp("10024",requestId,"MES单号:"+fSelBillNo+"已存在,请在ERP查看"+msclass+",单据编号:"+co);
- }
- //临时逻辑 工单结案直接返回成功
- if (baseDao.isDBSetting("MakeScrap","overSuccess")) {
- int condition = baseDao.getCountByCondition("make", "ma_statuscode='FINISH' and ma_code='" + prodNo + "'");
- if (condition > 0) {
- return ApiResponse.successRsp("0", requestId, "工单【" + prodNo + "】已结案,请在ERP查看!");
- }
- }
- id = baseDao.getSeqId("MAKESCRAP_SEQ");
- code = baseDao.sGetMaxNumber(caller, 2);
- String fdateTime = StringUtil.nvl(jsonObject.get("FdateTime"), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
- String fwcCode = StringUtil.nvl(jsonObject.get("FwcCode"), "");
- if ("".equals(fwcCode)) {
- return ApiResponse.failRsp("10021", requestId, "工作中心不能为空!");
- }
- String createdUser = StringUtil.nvl(jsonObject.get("createdUser"), employee.getEm_name());
- String createdDateTime = StringUtil.nvl(jsonObject.get("createdDateTime"), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
- String companyNo = StringUtil.nvl(jsonObject.get("companyNo"), "BYT");
- String fremark = StringUtil.nvl(jsonObject.get("Fremark"), "");
- 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+"')");
- }
- JSONArray array = data.get("detail");
- int detno=1;
- String fDeptID=null;
- String fDept=null;
- for (int i = 0; i <array.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
- String lineId = StringUtil.nvl(object.get("lineId"), "");
- if ("".equals(lineId)){
- return ApiResponse.failRsp("10022",requestId,"工单明细ID不能为空!");
- }
- Object mmdetno = baseDao.getFieldDataByCondition("MakeMaterial", "mm_detno", "mm_id in (" + lineId+")");
- String prodNo = StringUtil.nvl(object.get("prodNo"), "");
- if ("".equals(prodNo)){
- return ApiResponse.failRsp("10023",requestId,"工单单号不能为空!");
- }
- String itemNo = StringUtil.nvl(object.get("itemNo"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10024",requestId,"物料不能为空!");
- }
- double qty = Double.parseDouble(StringUtil.nvl(object.get("qty"), "0"));
- if (qty==0){
- return ApiResponse.failRsp("10025",requestId,"报废数量不能为空!");
- }
- //临时逻辑 重新计算报废数量
- //int coun = baseDao.getCountByCondition("make", "ma_code='" + prodNo + "' and to_char(ma_date,'yyyyMM')<'202212'");
- if (baseDao.isDBSetting("MakeScrap","overQtySuccess")) {
- 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"));
- if (mmqty < qty) {
- qty = mmqty;
- }
- }
- String reason = StringUtil.nvl(object.get("reason"), "");
- if ("".equals(reason)){
- return ApiResponse.failRsp("10026",requestId,"报废原因不能为空!");
- }
- fDeptID = StringUtil.nvl(object.get("FDeptID"), "");
- if ("".equals(fDeptID)){
- return ApiResponse.failRsp("10027",requestId,"责任部门编号不能为空!");
- }
- fDept = StringUtil.nvl(object.get("FDept"), "");
- if ("".equals(fDept)){
- return ApiResponse.failRsp("10028",requestId,"责任部门不能为空!");
- }
- String allScrapQty = StringUtil.nvl(object.get("AllScrapQty"), "0");
- String remark = StringUtil.nvl(object.get("remark"), "");
- if (qty>0) {
- 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 " +
- "(MAKESCRAPDETAIL_SEQ.nextval," + id + "," + detno + "," + lineId + ",'" + prodNo + "'," + mmdetno + ",'" + itemNo + "'," + qty + ",'" + reason + "','" + fDeptID + "','" + fDept + "'," + allScrapQty + ",'" + remark + "',0,'"+code+"')");
- detno++;
- }
- }
- if (detno==1) {
- return ApiResponse.failRsp("10030",requestId,"没有可报废的用料!");
- }
- baseDao.execute(sqls);
- Object[] status = baseDao.getFieldsDataByCondition("MakeScrap", new String[] { "ms_statuscode", "ms_indate","ms_date" }, "ms_id=" + id);
- //审核
- String s = checkFreezeMonth(status[2]);
- // 账期和工单状态检查
- String s1 = ScrapCheckAll(id, caller);
- String s2 = ScrapCheck_scrapqty(id);
- String s3 = copcheck(id);
- String s4 = checkMakeMaterial(id);
- if (s!=null||s1!=null||s2!=null||s3!=null||s4!=null){
- baseDao.deleteById("MakeScrapdetail","md_msid",id);
- baseDao.deleteById("MakeScrap","ms_id",id);
- return ApiResponse.failRsp("10029",requestId,(s==null?"":s)+(s1==null?"":s1)+(s2==null?"":s2)+(s3==null?"":s3)+(s4==null?"":s4));
- }
- baseDao.updateByCondition("MakeScrapdetail", "md_status=99", "md_msid=" + id);
- List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode ", new String[] {
- "ma_id", "md_mmdetno", "md_qty", "md_prodcode" }, " md_msid=" + id);
- for (Object[] object : objects) {
- baseDao.updateByCondition("Makematerial ", "mm_scrapqty =nvl(mm_scrapqty,0)+" + object[2], "mm_detno=" + object[1]
- + " and mm_maid=" + object[0]);
- baseDao.updateByCondition("Makematerial ", "mm_repscrapqty =nvl(mm_repscrapqty,0)+" + object[2], "mm_detno=" + object[1]
- + " and mm_maid=" + object[0] + " and mm_prodcode<>'" + object[3] + "'");
- baseDao.updateByCondition("Makematerialreplace ", "mp_scrapqty =nvl(mp_scrapqty,0)+" + object[2], " mp_maid=" + object[0]
- + " and mp_mmdetno=" + object[1] + " and mp_prodcode='" + object[3] + "'");
- }
- // 执行审核操作
- baseDao.updateByCondition("MakeScrap", "ms_status='已审核',ms_statuscode='AUDITED',ms_auditdate=sysdate,ms_auditman='"+employee.getEm_name()+"'","ms_id="+ id);
- // 记录操作
- 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+"')");
- //生成超损请购
- int apId = baseDao.getSeqId("APPLICATION_SEQ");
- String apCode = baseDao.sGetMaxNumber("Application", 2);
- 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 " +
- "("+apId+",'"+apCode+"','超损请购',sysdate,'ENTERING','在录入','"+employee.getEm_name()+"',"+employee.getEm_id()+",'"+employee.getEm_name()+"',"+employee.getEm_id()+",sysdate,'"+fDeptID+"','"+fDept+"','"+msclass+"',"+id+",'UNPRINT','未打印','MES生产报废单审核生成','"+code+"')");
- 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) " +
- "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);
- 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);
- return ApiResponse.successRsp("0",requestId,msclass+":"+code+",请在ERP查看!");
- }
- @Override
- public ApiResult<String> deleteMakeScrap(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject jsonData = getJsonData(request);
- String msclass="生产报废单";
- String caller="MakeScrap";
- if (jsonData==null){
- return ApiResponse.failRsp("10096",requestId,"参数异常!");
- }
- String fSelBillNo = StringUtil.nvl(jsonData.get("FSelBillNo"), "");
- if ("".equals(fSelBillNo)) {
- return ApiResponse.failRsp("10031", requestId, "MES单号不能为空!");
- }
- int count = baseDao.getCount("select count(1) from MakeScrap where ms_mescode='" + fSelBillNo + "'");
- if (count <= 0) {
- return ApiResponse.failRsp("10032", requestId, "MES单号对应报废单不存在,请核查!");
- }
- Object[] scraps = baseDao.getFieldsDataByCondition("MakeScrap","ms_id,ms_sourcecode,ms_sourcetype,ms_indate,ms_date,ms_code", "ms_mescode='" + fSelBillNo + "'");
- if ("委外加工单".equals(StringUtil.nvl(scraps[2],""))){
- msclass = "委外报废单";
- caller = "MakeScrap!Make";
- }
- int msId = Integer.parseInt(StringUtil.nvl(scraps[0], "0"));
- //判断请购单
- int count1 = baseDao.getCount("select count(1) from application where nvl(ap_statuscode,'ENTERING')<>'ENTERING' and ap_source='" + msclass + "' and ap_sourceid=" + msId);
- if(count1>0){
- return ApiResponse.failRsp("10033", requestId, "请购单不是在录入状态,不允许反审核!");
- }
- //反审核报废单
- String s = checkFreezeMonth(scraps[4]);
- baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
- + "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_code in (select md_mmcode from MakeScrapDetail where md_msid="
- + msId + ")");
- SqlRowList rs = baseDao
- .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='"
- + msId
- + "' 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 ");
- if (rs.next()) {
- return ApiResponse.failRsp("10033", requestId, "序号【" + rs.getString("md_detno") + "】报废数已生成补料单,不能反审核报废单!");
- }
- // 账期和工单状态检查
- String s1 = ScrapCheckAll(msId, caller);
- if (s!=null||s1!=null){
- return ApiResponse.failRsp("10029",requestId,(s==null?"":s)+(s1==null?"":s1));
- }
- baseDao.deleteByCondition("applicationdetail","ad_apid in (select ap_id from application where ap_source='" + msclass + "' and ap_sourceid=" + msId+")");
- baseDao.deleteByCondition("Application","ap_source='" + msclass + "' and ap_sourceid=" + msId);
- baseDao.updateByCondition("MakeScrapdetail", "md_status=0", "md_msid=" + msId);
- List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode", new String[] {
- "ma_id", "md_mmdetno", "md_qty", "md_prodcode" }, " md_msid=" + msId);
- for (Object[] obj : objects) {
- baseDao.updateByCondition("Makematerial ", "mm_scrapqty =nvl(mm_scrapqty,0)-" + obj[2], "mm_detno=" + obj[1] + " and mm_maid=" + obj[0]);
- 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] + "'");
- 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] + "'");
- }
- // 执行反审核操作
- baseDao.updateByCondition("MakeScrap", "ms_statuscode='ENTERING',ms_status='在录入'", "ms_id=" + msId);
- // 记录操作
- 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+"')");
- // 删除主表
- baseDao.deleteById("MakeScrap", "ms_id", msId);
- // 删除明细表
- baseDao.deleteById("MakeScrapdetail", "md_msid", msId);
- // 记录操作
- 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+"')");
- return ApiResponse.successRsp("0",requestId,msclass+":"+scraps[5]+"删除成功!");
- }
- @Override
- public ApiResult<String> prodInOutOtherOut(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- int id=0;
- String code="";
- String caller="ProdInOut!OtherOut";
- String piclass="其它出库单";
- List<String> sqls = new ArrayList<>();
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
- if (result!=null){
- return result;
- }
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillTypeID")));
- Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
- //客户编号 客户单号
- String fCustCode = StringUtil.nvl(jsonObject2.get("FCustCode"), "");
- String fCustNo = StringUtil.nvl(jsonObject2.get("FCustNo"), "");
- Object cuname="";
- if (!"".equals(fCustCode)){
- cuname = baseDao.getFieldDataByCondition("Customer", "cu_name", "cu_code='" + fCustCode + "'");
- }
- id = baseDao.getSeqId("PRODINOUT_SEQ");
- code = baseDao.sGetMaxNumber(caller, 2);
- 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) " +
- "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+"')");
- }
- JSONArray array = data.get("detail");
- int detno=1;
- for (int i = 0; i <array.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10031",requestId,"物料不能为空!");
- }
- String qty = StringUtil.nvl(object.get("FAuxQtyMust"), "");
- if ("".equals(qty)){
- return ApiResponse.failRsp("10032",requestId,"实出数量不能为空!");
- }
- String fnote = StringUtil.nvl(object.get("Fnote"), "");
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDCStockID1")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- String whname = StringUtil.nvl(map1.get("FName"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10034",requestId,"MES仓库编号不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10035",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- 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) " +
- "values (PRODIODETAIL_SEQ.nextval,"+id+",'"+code+"','其它出库单',"+detno+",'"+itemNo+ "',"+qty+",'"+warehouses[0]+"','"+warehouses[1]+"','"+fnote+"')");
- detno++;
- }
- baseDao.execute(sqls);
- /*Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- String s = postProdInOut(id, caller, employee);
- logger.info("其它出库单过账信息=="+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,"其它出库单:"+code+",过账失败,请在ERP重新过账!");
- }*/
- return ApiResponse.successRsp("0",requestId,"其它出库单:"+code+",请在ERP查看!");
- }
- @Override
- public ApiResult<String> prodInOutPicking(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- String bccode = null;
- int bcpiid = 0;
- String llcode = null;
- int llpiid=0;
- String ma_tasktype=null;
- int maid=0;
- String llpiclass = "生产领料单", llcaller = "ProdInOut!Picking", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
- // 是否生成调拨单,勾选不生成,不勾选默认生成
- Boolean notCreateAppropriation = baseDao.isDBSetting("MultiMakeSendLS", "notCreateAppropriation");
- List<String> sqls = new ArrayList<>();
- JSONArray array = data.get("detail");
- if(array!=null&&array.size()>0){
- String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "{}")).get("FICMOBillNo"));
- Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id,ma_status", "ma_code in ('" + macode + "')");
- if (data1!=null&&data1.length>0) {
- if ("已结案".equals(StringUtil.nvl(data1[2], ""))){
- return ApiResponse.failRsp("10045", requestId, "工单:"+macode+"在ERP已结案,不允许领料!");
- }
- ma_tasktype = StringUtil.nvl(data1[0], "");
- maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- }else {
- return ApiResponse.failRsp("10046", requestId, "工单在ERP不存在,请核对!");
- }
- }
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FPurposeID")));
- Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
- if ("OS".equals(ma_tasktype)) {
- llpiclass = "委外领料单";
- llcaller = "ProdInOut!OutsidePicking";
- }
- String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, llpiclass);
- if (result!=null){
- return result;
- }
- ApiResult<String> result1 = checkMESCode(requestId, fSelBillNo, bcpiclass);
- if (result1!=null){
- return result1;
- }
- if(!notCreateAppropriation){
- //生成拨出单
- bcpiid = baseDao.getSeqId("PRODINOUT_SEQ");
- bccode = baseDao.sGetMaxNumber(bccaller, 2);
- 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) " +
- "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+"')");
- }
- //生成领料单
- llpiid = baseDao.getSeqId("PRODINOUT_SEQ");
- llcode = baseDao.sGetMaxNumber(llcaller, 2);
- 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) " +
- "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+"')");
- // 标示领料单的拨出单号
- sqls.add("update ProdInOut set pi_fromcode='" + bccode + "' where pi_id=" + llpiid);
- }
- Object[] warehouses=null;
- Object[] warehouses2=null;
- int detno=1;
- int det=1;
- for (int i = 0; i <array.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10041",requestId,"物料不能为空!");
- }
- String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
- if ("0".equals(fAuxQty)){
- return ApiResponse.failRsp("10042",requestId,"实发数量不能为空!");
- }
- Double qty = Double.parseDouble(fAuxQty);
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10043",requestId,"发料仓库不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10044",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- String fSourceInterId = StringUtil.nvl(object.get("FSourceInterId"), "");
- String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
- String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
- if ("".equals(whcode2)){
- return ApiResponse.failRsp("10043",requestId,"物料所在仓库不能为空!");
- }
- 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 + "'");
- if (count2<=0){
- return ApiResponse.failRsp("10044",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
- int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
- if (count4<=0){
- return ApiResponse.failRsp("10046",requestId,"工单BOM在ERP中不存在,物料编号:"+itemNo+",请联系管理员!");
- }
- int count5 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ") and nvl(mm_qty,0)>0");
- if (count5<=0){
- return ApiResponse.failRsp("10047",requestId,"工单BOM在ERP中需求数为0,物料编号:"+itemNo+",请联系管理员!");
- }
- Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial", "mm_detno,mm_maid","mm_id in (" + lineId + ")");
- maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- if(bccode!=null) {
- 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]+")");
- detno++;
- }
- int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_prodcode='" + itemNo + "' and mm_id in (" + lineId + ")");
- if (count1>0) {
- 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 + ")");
- if (sqlRowList.next()) {
- Double mmqty = sqlRowList.getGeneralDouble("mmqty");
- qty = qty.compareTo(mmqty) > 0 ? mmqty : qty;
- }
- }else {
- int count3 = baseDao.getCount("select count(1) from MakeMaterialreplace where mp_prodcode='" + itemNo + "' and mp_mmid in (" + lineId + ")");
- if (count3>0){
- 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 + ")");
- if (sqlRowList1.next()){
- Double mpqty = sqlRowList1.getGeneralDouble("mpqty");
- qty = qty.compareTo(mpqty) > 0 ? mpqty : qty;
- }
- }
- }
- if (qty>0) {
- 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)");
- det++;
- }
- }
- if ("OS".equals(ma_tasktype)) {
- 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);
- }
- if (warehouses2!=null){
- sqls.add("update prodinout set pi_whcode='"+warehouses2[0]+"',pi_whname='"+warehouses2[1]+"' where " + "pi_id="+bcpiid);
- }
- if (warehouses!=null){
- sqls.add("update prodinout set pi_purpose='"+warehouses[0]+"',pi_purposename='"+warehouses[1]+"' where pi_id="+bcpiid);
- sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+llpiid);
- }
- baseDao.execute(sqls);
- refreshTurnQty(maid,0);
- setBackQty(String.valueOf(maid),0);
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- int count = baseDao.getCount("select count(1) from prodiodetail where pd_piid=" + llpiid);
- if (count<=0){
- baseDao.deleteById("prodinout","pi_id",llpiid);
- if(!baseDao.isDBSetting(llcaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+ ",请在ERP查看并过账!");
- }
- String s = postProdInOut(bcpiid, bccaller, employee);
- logger.info("旧拨出单过账信息:"+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+",过账失败,请在ERP重新过账!");
- }else {
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+ ",请在ERP查看!");
- }
- }else {
- if(!baseDao.isDBSetting(llcaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,llpiclass+":"+llcode+","+bcpiclass+":"+bccode+ ",请在ERP查看并手工过账!");
- }
- String s = postProdInOut(bcpiid, bccaller, employee);
- logger.info("旧拨出单过账信息:"+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+bccode+",过账失败,请在ERP重新过账!");
- }
- String s1 = postProdInOut(llpiid, llcaller, employee);
- logger.info("旧生产领料单过账信息:"+s1);
- refreshTurnQty(maid,0);
- setBackQty(String.valueOf(maid),0);
- if (s1 != null) {
- return ApiResponse.successRsp("0", requestId, llpiclass+":" + llcode + ",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,llpiclass+":"+llcode+","+bcpiclass+":"+bccode+ ",请在ERP查看!");
- }
- }
- @Override
- public ApiResult<String> prodInOutMakeReturn(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- int id=0;
- String code="";
- int tlid=0;
- String tlcode = "";
- String macode="";
- String ma_tasktype=null;
- //良品退仓、来料不良、制程不良
- String taskType="制程不良";
- int maid=0;
- String tlpiclass = "生产退料单", tlcaller = "ProdInOut!Make!Return", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
- List<String> sqls = new ArrayList<>();
- int frob=99;
- JSONArray array = data.get("detail");
- Object[] warehouses=null;
- Object[] warehouses2=null;
- if(array!=null&&array.size()>0) {
- macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "")).get("FICMOBillNo"));
- Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
- if (data1 != null && data1.length > 0) {
- ma_tasktype = StringUtil.nvl(data1[0], "");
- maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- } else {
- return ApiResponse.failRsp("10057", requestId, "工单在ERP不存在,请核对!");
- }
- for (int i = 0; i <array.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
- Object lineId = object.get("lineId");
- //线边仓
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- if ("".equals(whcode)) {
- return ApiResponse.failRsp("10053", requestId, "仓库编号不能为空!");
- }
- 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 + "'");
- if (count <= 0) {
- return ApiResponse.failRsp("10054", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- //大仓
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
- String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
- if ("".equals(whcode2)) {
- return ApiResponse.failRsp("10055", requestId, "物料退回仓库不能为空!");
- }
- 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 + "'");
- if (count2 <= 0) {
- return ApiResponse.failRsp("10056", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- }
- }
- for (int i = 0; i <jsonArray.size() ; i++) {
- Object obj = jsonArray.get(i);
- JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(obj, ""));
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FDeptID"),"{}"));
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FPurposeID"),"{}"));
- Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FFManagerID"),"{}"));
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FSManagerID"),"{}"));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.nvl(jsonObject2.get("FBillerID"),"{}"));
- frob = Integer.parseInt(StringUtil.nvl(jsonObject2.get("FROB"), "99"));
- taskType = StringUtil.nvl(jsonObject2.get("TaskType"), "");
- if ("OS".equals(ma_tasktype)) {
- tlpiclass = "委外退料单";
- tlcaller = "ProdInOut!OutsideReturn";
- }
- String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, tlpiclass);
- if (result!=null){
- return result;
- }
- ApiResult<String> result1 = checkMESCode(requestId, fSelBillNo, bcpiclass);
- if (result1!=null){
- return result1;
- }
- if (frob==0||"制程不良".equals(taskType)){
- tlid = baseDao.getSeqId("PRODINOUT_SEQ");
- tlcode = baseDao.sGetMaxNumber(tlcaller, 2);
- 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+"')");
- }
- id = baseDao.getSeqId("PRODINOUT_SEQ");
- code = baseDao.sGetMaxNumber(bccaller, 2);
- 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+"')");
- }
- int detno=1;
- int det=1;
- for (int i = 0; i <array.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10051",requestId,"物料不能为空!");
- }
- Double qty =Double.parseDouble(StringUtil.nvl(object.get("FAuxQty"), ""));
- if ("".equals(qty)){
- return ApiResponse.failRsp("10052",requestId,"实发数量不能为空!");
- }
- String fnote = StringUtil.nvl(object.get("Fnote"), "");
- Object lineId = object.get("lineId");
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- 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 + "'");
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
- String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
- 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 + "'");
- String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
- String fBatchNo = StringUtil.nvl(object.get("FBatchNo"), "");
- int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
- if (count1<=0){
- return ApiResponse.failRsp("10075",requestId,"工单BOM不存在或ID不一致,请联系管理员处理!");
- }
- 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+")");
- 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]+")");
- if (frob==0||"制程不良".equals(taskType)) {
- Object prid = baseDao.getFieldDataByCondition("Product", "pr_id", "pr_code='" + itemNo + "'");
- Double remain = baseDao.getSummaryByField("batch", "ba_remain", "ba_prodcode='" + itemNo + "' and ba_macode='" + macode + "' and ba_whcode='" + warehouses[0] + "'");
- /*Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial left join Make on ma_id=mm_maid",
- "mm_totaluseqty,mm_havegetqty,ma_tomadeqty,mm_oneuseqty,ma_qty", "mm_id=" + objs[0]);*/
- if (qty.compareTo(remain) > 0){
- double sub = DoubleUtils.sub(qty, remain);
- 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+ ",'良品退仓')");
- det++;
- }
- }
- detno++;
- }
- if (frob==0){
- 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="
- + tlid);
- 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="
- + tlid);
- }
- if ("OS".equals(ma_tasktype)) {
- 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);
- }
- if (warehouses!=null){
- sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+id);
- sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+tlid);
- }
- if (warehouses2!=null){
- sqls.add("update prodinout set pi_purpose='"+warehouses2[0]+"',pi_purposename='"+warehouses2[1]+"' where pi_id="+id);
- }
- baseDao.execute(sqls);
- baseDao.execute("delete from prodiodetail where pd_inqty=0 and pd_piclass='"+tlpiclass+"' and pd_piid="+tlid);
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- int count = baseDao.getCount("select count(1) from prodiodetail where pd_piid=" + tlid);
- if (count<=0){
- baseDao.deleteById("prodinout","pi_id",tlid);
- if(!baseDao.isDBSetting(tlcaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+ ",请在ERP查看并手工过账!");
- }
- String s = postProdInOut(id, bccaller, employee);
- logger.info("S=="+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,bcpiclass+":"+code+",请在ERP查看!");
- }else {
- if(!baseDao.isDBSetting(tlcaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",请在ERP查看并手工过账!");
- }
- String s1 = postProdInOut(tlid, tlcaller, employee);
- logger.info("S1==" + s1);
- if (s1 != null){
- return ApiResponse.successRsp("0", requestId, tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
- }
- String s = postProdInOut(id, bccaller, employee);
- logger.info("S=="+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+","+bcpiclass+":"+code+",请在ERP查看!");
- }
- }
- @Override
- public ApiResult<String> prodInOutAppropriationOut(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- int id=0;
- String code="";
- String picaller="ProdInOut!AppropriationOut";
- String piclass="拨出单";
- List<String> sqls = new ArrayList<>();
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject2 = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FDeptID")));
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FRefType")));
- Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FFManagerID")));
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FSManagerID")));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(jsonObject2.get("FBillerID")));
- String fSelBillNo = StringUtil.nvl(jsonObject2.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, piclass);
- if (result!=null){
- return result;
- }
- id = baseDao.getSeqId("PRODINOUT_SEQ");
- code = baseDao.sGetMaxNumber(picaller, 2);
- 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+"')");
- }
- JSONArray array = data.get("detail");
- Object[] warehouses=null;
- Object[] warehouses2=null;
- int detno=1;
- for (int i = 0; i <array.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(array.get(i), "{}"));
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10061",requestId,"物料不能为空!");
- }
- String qty = StringUtil.nvl(object.get("Fauxqty"), "");
- if ("".equals(qty)){
- return ApiResponse.failRsp("10062",requestId,"实转数量不能为空!");
- }
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID1")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- String whname = StringUtil.nvl(map1.get("FName"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10063",requestId,"发货仓库不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDCStockID1")));
- String whcode2 = StringUtil.nvl(map2.get("FNumber"), "");
- String whname2 = StringUtil.nvl(map2.get("FName"), "");
- if ("".equals(whcode2)){
- return ApiResponse.failRsp("10065",requestId,"收货仓库不能为空!");
- }
- 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 + "'");
- if (count2<=0){
- return ApiResponse.failRsp("10066",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- 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]+"')");
- detno++;
- }
- if (warehouses!=null){
- sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where " + "pi_id="+id);
- }
- if (warehouses2!=null){
- sqls.add("update prodinout set pi_purpose='"+warehouses2[0]+"',pi_purposename='"+warehouses2[1]+"' where pi_id="+id);
- }
- baseDao.execute(sqls);
- return ApiResponse.successRsp("0",requestId,"拨出单:"+code+",请在ERP查看!");
- }
- @Override
- public ApiResult<String> makeCheckOutStock(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- try {
- String data = PSHttpUtils.readRaw(request.getInputStream());
- JSONArray jsonArray = JSON.parseArray(data);
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- String whcode = StringUtil.nvl(jsonObject.getString("outwhcode"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10081",requestId,"拨出仓库不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10082",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- jsonObject.put("outwhcode",outwhcode);
- String whcode1 = StringUtil.nvl(jsonObject.getString("inwhcode"), "");
- if ("".equals(whcode1)){
- return ApiResponse.failRsp("10083",requestId,"拨入仓库不能为空!");
- }
- 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 + "'");
- if (count1<=0){
- return ApiResponse.failRsp("10084",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- jsonObject.put("inwhcode",inwhcode);
- }
- String msg = baseDao.callProcedure("USER_CHECKOUTSTOCK", new Object[] {null,JSON.toJSONString(jsonArray)});
- if (msg != null && !msg.trim().equals("")){
- return ApiResponse.failRsp("10085",requestId,msg);
- }
- return ApiResponse.successRsp("0",requestId,"校验通过!");
- } catch (IOException e) {
- logger.error("makeCheckOutStock==="+e.getMessage());
- return ApiResponse.failRsp("10086",requestId,e.getMessage());
- }
- }
- @Override
- public ApiResult<String> makeECNCheck(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject jsonData = getJsonData(request);
- if (jsonData!=null){
- String makeCode = StringUtil.nvl(jsonData.get("MakeCode"), "");
- Object mcCode = baseDao.getFieldDataByCondition("makematerialchange", "wm_concat(mc_code)",
- "mc_id in (select md_mcid from makematerialchangedet where md_makecode='"+makeCode+"' and nvl(md_didstatus,' ')<>'执行成功')");
- if (mcCode!=null){
- return ApiResponse.failRsp("10091",requestId,"ERP有未执行的制造单ECN:"+mcCode);
- }
- Object ecnCode = baseDao.getFieldDataByCondition("ecn", "wm_concat(ecn_code)",
- "nvl(ecn_didstatus,' ')<>'已执行' and ecn_id in (select ed_ecnid from ecndetail left join make on ed_boid=ma_bomid where ma_code='"+makeCode+"')");
- if (ecnCode!=null){
- return ApiResponse.failRsp("10092",requestId,"ERP有未执行的ECN:"+ecnCode);
- }
- return ApiResponse.successRsp("0",requestId,"校验通过!");
- }else {
- return ApiResponse.failRsp("10093",requestId,"参数异常!");
- }
- }
- @Override
- public ApiResult<String> canMadeQty(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject jsonData = getJsonData(request);
- if (jsonData!=null){
- String makeCode = StringUtil.nvl(jsonData.get("MakeCode"), "");
- int count = baseDao.getCount("select count(1) from make where ma_code ='" + makeCode + "'");
- if (count<=0){
- return ApiResponse.failRsp("10094",requestId,"工单:"+makeCode+"在ERP不存在,请核对!");
- }
- Object[] data = baseDao.getFieldsDataByCondition("make", "ma_canmadeqty,ma_code,ma_qty,ma_madeqty,ma_tomadeqty,ma_id", "ma_code='" + makeCode + "'");
- if (data!=null&&data.length>0) {
- Map<String, Object> map = new HashMap<>();
- map.put("code",data[1]);
- if (baseDao.checkIf("makematerial","nvl(mm_cp_user,0)=0 and nvl(mm_qty,0)>0 and mm_maid="+data[5])){
- 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 + "'");
- //备料齐套数量
- map.put("canmadeqty",Double.parseDouble(StringUtil.nvl(canmadeqty,"0")));
- }else {
- map.put("canmadeqty",Double.parseDouble(StringUtil.nvl(data[0],"0")));
- }
- //工单数量
- map.put("qty",data[2]);
- //完工数量
- map.put("madeqty",data[3]);
- //已转完工数
- map.put("tomadeqty",data[4]);
- return ApiResponse.successRsp("0", "获取成功!",requestId, JSON.toJSONString(map));
- }else {
- return ApiResponse.failRsp("10095",requestId,"未找到数据!");
- }
- }else {
- return ApiResponse.failRsp("10096",requestId,"参数异常!");
- }
- }
- @Override
- public ApiResult<String> prodInOutMakeGive(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- String piCaller="ProdInOut!Make!Give";
- String piClass="生产补料单";
- Object piid=null;
- String inoutno="";
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- inoutno = StringUtil.nvl(jsonObject.get("FSelBillNo"), "");
- if ("".equals(inoutno)){
- return ApiResponse.failRsp("10019",requestId,"生产补料单号不能为空!");
- }
- int count = baseDao.getCount("select count(1) from prodinout where pi_inoutno='" + inoutno + "' and pi_invostatuscode='AUDITED' and pi_statuscode='UNPOST' and pi_class='生产补料单'");
- if (count>0) {
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- piid = baseDao.getFieldDataByCondition("prodinout", "pi_id", "pi_inoutno='" + inoutno + "'");
- String s = postProdInOut(Integer.parseInt(StringUtil.nvl(piid,"0")), piCaller, employee);
- logger.info("s==" + s);
- if (s != null) {
- return ApiResponse.successRsp("108", requestId, piClass+":" + inoutno + ",过账失败,请在ERP重新过账!");
- }
- }else {
- return ApiResponse.successRsp("107", requestId, piClass+":" + inoutno + ",不存在或未审核,或已过帐!");
- }
- }
- return ApiResponse.successRsp("0",requestId,piClass+":"+inoutno+"自动过账,请在ERP查看!");
- }
- @Override
- public ApiResult<String> purcCheckinDetail(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- JSONArray jsonArray = data.get("main");
- Object vaid=0;
- String caller="VerifyApply!ToOtherIn";
- String type="其它入库单";
- String djcaller="ProdInOut!OtherIn";
- String sellerName="";
- for (int i = 0; i <jsonArray.size() ; i++) {
- JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
- String mesCode = StringUtil.nvl(jsonObject.get("mesCode"),"");
- if ("".equals(mesCode)){
- return ApiResponse.failRsp("10011",requestId,"ERP单据编号不能为空!");
- }
- int count = baseDao.getCountByCondition("verifyApply", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
- if (count<1){
- return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
- }
- vaid = baseDao.getFieldDataByCondition("verifyApply", "va_id", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
- String vaClass = StringUtil.nvl(baseDao.getFieldDataByCondition("VerifyApply", "va_class", "va_id=" + vaid), "");
- if ("委外收料单".equals(vaClass)) {
- caller = "VerifyApply!ToOutsideCheckIn";
- type = "委外验收单";
- djcaller = "ProdInOut!OutsideCheckIn";
- }else if("采购收料单".equals(vaClass)){
- int count1 = baseDao.getCount("select count(1) from VerifyApplyDetail where nvl(vad_pucode,' ')<>' ' and vad_vaid=" + vaid);
- if (count1 > 0) {
- caller = "VerifyApply!ToPurcIn";
- type = "采购验收单";
- djcaller = "ProdInOut!PurcCheckin";
- }
- }
- //判断已转数
- 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);
- if(chekQty !=null){
- return ApiResponse.failRsp("10013",requestId,"检测到" + chekQty + ",本次数量超出可转数量!");
- }
- if ("VerifyApply!ToPurcIn".equals(caller)) {
- // 判断该收料单是否已经转入过采购验收单
- Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
- code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and " + "PI_REFNO='采购收料单' and pi_class='采购验收单'");
- if (code != null && !code.equals("")) {
- return ApiResponse.failRsp("10014", requestId, "该收料单已转入过采购验收单,验收单号[" + code + "]");
- }
- }
- if ("VerifyApply!ToOtherIn".equals(caller)) {
- // 判断该收料单是否已经转入过其它入库单
- Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
- code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='其它入库单'");
- if (code != null && !code.equals("")) {
- return ApiResponse.failRsp("10014", requestId, "该收料单已转入过其它入库单,单号[" + code + "]");
- }
- }
- if ("VerifyApply!ToOutsideCheckIn".equals(caller)) {
- // 判断该收料单是否已经转入过委外验收单
- Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
- code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='委外验收单'");
- if (code != null && !code.equals("")) {
- return ApiResponse.failRsp("10014", requestId, "该收料单已转入过委外验收单,单号[" + code + "]");
- }
- }
- sellerName = StringUtil.nvl(jsonObject.get("sellerName"), "mes");
- }
- JSONArray array = data.get("detail");
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
- String itemNo = StringUtil.nvl(json.get("itemNo"), "");
- Double qty = Double.parseDouble(StringUtil.nvl(json.get("qty"), "0"));
- Double vadQty = baseDao.getSummaryByField("verifyapplydetail", "vad_qty", "vad_prodcode='" + itemNo + "' and vad_vaid=" + vaid);
- int compare = qty.compareTo(vadQty);
- if (compare>0){
- return ApiResponse.failRsp("10017",requestId, "物料:"+itemNo+",收料数量:"+qty+"超出ERP收料单数量:"+vadQty+ ",不允许入库!");
- }
- if (compare<0){
- return ApiResponse.failRsp("10018",requestId,"物料:"+itemNo+",收料数量:"+qty+"少于ERP收料单数量:"+vadQty+",不允许入库!");
- }
- String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10015",requestId,"MES仓库编号不能为空!");
- }
- 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 + "'");
- if (coun<=0){
- return ApiResponse.failRsp("10016",requestId,"MES仓库编号:"+whcode+"在ERP没有对应关系,请联系管理员新增!");
- }
- }
- int piid =0;
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_name=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), sellerName);
- // 转采购验收单
- Key key = transferRepository.transfer(caller, vaid,employee);
- piid = key.getId();
- // 转入明细
- transferRepository.transferDetail(caller, vaid, key,employee);
- if (piid != 0) {
- baseDao.execute("delete from prodiodetail where nvl(pd_inqty,0)<=0 and pd_piid="+piid);
- //更新仓库
- for (int i = 0; i <array.size() ; i++) {
- JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
- String itemNo = StringUtil.nvl(json.get("itemNo"), "");
- String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
- 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 + "'");
- baseDao.updateByCondition("prodiodetail", "pd_whcode='"+warehouses[0]+"',pd_whname='"+warehouses[1]+"'", "pd_prodcode='"+itemNo+"' and pd_piid=" + piid);
- }
- //baseDao.updateByCondition("prodinout", "pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"'","pi_id=" + piid);
- baseDao.execute("update prodiodetail set pd_prodid=(select pr_id from product where pd_prodcode=pr_code) where pd_piid=" + piid
- + " and nvl(pd_prodcode,' ')<>' '");
- baseDao.execute("update prodiodetail set pd_whid=(select wh_id from warehouse where wh_code=pd_whcode) where pd_piid=" + piid
- + " and nvl(pd_whcode,' ')<>' '");
- baseDao.updateByCondition("ProdInOut",
- "pi_total=(SELECT round(sum(nvl(pd_orderprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid="
- + piid + ")", "pi_id=" + piid);
- baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + piid);
- if ("VerifyApply!ToPurcIn".equals(caller)) {
- baseDao.execute("Insert into ProdChargeDetail(pd_id,pd_piid,pd_detno,pd_type,pd_amount,pd_currency,pd_rate) "
- + "select ProdChargeDetail_seq.nextval, " + piid + ", pd_detno, pd_type,pd_amount,pd_currency,pd_rate "
- + "from ProdChargeDetailAN where PD_ANID=" + vaid);
- SqlRowList rs = baseDao.queryForRowSet("select vad_pucode,vad_pudetno,vad_qty from VerifyApplyDetail where vad_vaid=" + vaid);
- String pCode = null;
- int pDetno = 0;
- double yq = 0;
- Set<String> pCodes = new HashSet<String>();
- while (rs.next()) {
- pCode = rs.getString("vad_pucode");
- if (!pCodes.contains(pCode)) {
- pCodes.add(pCode);
- }
- pDetno = rs.getInt("vad_pudetno");
- yq = rs.getDouble("vad_qty");
- baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno);
- baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno
- + " and pd_qty=" + yq);
- }
- Iterator<String> iter = pCodes.iterator();
- while (iter.hasNext()) {
- pCode = iter.next();
- int total = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "'");
- int aud = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "' AND nvl(pd_acceptqty,0)=0");
- int turn = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode
- + "' AND nvl(pd_acceptqty,0)=nvl(pd_qty,0)");
- String statuscode = aud == total ? "" : (turn == total ? "TURNIN" : "PART2IN");
- String status = aud == total ? "" : (turn == total ? "已入库" : "部分入库");
- baseDao.updateByCondition("Purchase",
- "pu_turnstatuscode='" + statuscode + "',pu_turnstatus='" + status + "'", "pu_code='" + pCode + "'");
- }
- }
- // 修改收料状态
- baseDao.updateByCondition("VerifyApplyDetail", "vad_yqty=vad_qty", "vad_vaid=" + vaid);
- baseDao.updateByCondition("VerifyApply", "va_turnstatuscode='TURNIN',va_turnstatus='已入库'", "va_id=" + vaid);
- String s = postProdInOut(piid, djcaller, employee);
- logger.info("收料单入库=="+s);
- if (s!=null){
- return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",请在ERP查看!");
- }
- return ApiResponse.failRsp("10019",requestId,"ERP生成单据失败!");
- }
- @Override
- public ApiResult<String> multiMakeSendPicking(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- String llcode = null,ma_tasktype=null,llpiclass = "生产领料单", llcaller = "ProdInOut!Picking";
- int llpiid=0,maid=0,detno=1;
- Object[] warehouses=null;
- List<String> sqls = new ArrayList<>();
- JSONArray detail = data.get("detail");
- if(detail!=null&&detail.size()>0){
- String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(detail.get(0), "{}")).get("FICMOBillNo"));
- Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id,ma_status,ma_finishstatus", "ma_code in ('" + macode + "')");
- if (data1!=null&&data1.length>0) {
- if ("已结案".equals(StringUtil.nvl(data1[2], ""))){
- return ApiResponse.failRsp("10041", requestId, "工单:"+macode+"在ERP已结案,不允许领料!");
- }
- if ("已完工".equals(StringUtil.nvl(data1[3], ""))){
- return ApiResponse.failRsp("10041", requestId, "工单:"+macode+"在ERP已完工,不允许领料!");
- }
- ma_tasktype = StringUtil.nvl(data1[0], "");
- maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- }else {
- return ApiResponse.failRsp("10042", requestId, "工单在ERP不存在,请核对!");
- }
- for (int i = 0; i <detail.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10043",requestId,"物料不能为空!");
- }
- String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
- if ("0".equals(fAuxQty)){
- return ApiResponse.failRsp("10044",requestId,"实发数量不能为空!");
- }
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID2")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- if ("".equals(whcode)){
- return ApiResponse.failRsp("10045",requestId,"发料仓库不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10046",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
- int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
- if (count4<=0){
- return ApiResponse.failRsp("10047",requestId,"工单BOM在ERP中不存在,物料编号:"+itemNo+",请联系管理员!");
- }
- int count5 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ") and nvl(mm_qty,0)>0");
- if (count5<=0){
- return ApiResponse.failRsp("10047",requestId,"工单BOM在ERP中需求数为0,物料编号:"+itemNo+",请联系管理员!");
- }
- }
- }
- JSONArray main = data.get("main");
- for (int i = 0; i <main.size() ; i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(main.get(i), "{}"));
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FDeptID")));
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.valueOf(object.get("FPurposeID")));
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSManagerID")));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.valueOf(object.get("FBillerID")));
- if ("OS".equals(ma_tasktype)) {
- llpiclass = "委外领料单";
- llcaller = "ProdInOut!OutsidePicking";
- }
- String fSelBillNo = StringUtil.nvl(object.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, llpiclass);
- if (result!=null){
- return result;
- }
- //生成领料单
- llpiid = baseDao.getSeqId("PRODINOUT_SEQ");
- llcode = baseDao.sGetMaxNumber(llcaller, 2);
- 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) " +
- "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+"')");
- }
- for (int i = 0; i <detail.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- String fAuxQty = StringUtil.nvl(object.get("FAuxQty"), "0");
- Double qty = Double.parseDouble(fAuxQty);
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.valueOf(object.get("FSCStockID2")));
- String whcode = StringUtil.nvl(map1.get("FNumber"), "");
- 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 + "'");
- 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 + "'");
- String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
- int lineId = Integer.parseInt(StringUtil.nvl(object.get("lineId"), "0"));
- int count4 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
- Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial", "mm_detno,mm_maid","mm_id in (" + lineId + ")");
- maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- 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 + "'," + detno + ",'" + itemNo + "'," + qty + ",'" + warehouses[0] + "','" + warehouses[1] + "','" + ficmoBillNo + "'," + data1[0] + ",'" + ficmoBillNo + "'," + data1[0] + ",0)");
- detno++;
- }
- if ("OS".equals(ma_tasktype)) {
- 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);
- }
- if (warehouses!=null){
- sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+llpiid);
- }
- baseDao.execute(sqls);
- refreshTurnQty(maid,0);
- setBackQty(String.valueOf(maid),0);
- if(!baseDao.isDBSetting(llcaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,llpiclass + ":" + llcode + ",请在ERP查看并手工过账!");
- }
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?",
- new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- String s = postProdInOut(llpiid, llcaller, employee);
- logger.info("新生产领料单过账信息:"+s);
- if (s!=null){
- return ApiResponse.successRsp("0", requestId, llpiclass + ":" + llcode + ",过账失败,请在ERP重新过账!");
- }
- refreshTurnQty(maid,0);
- setBackQty(String.valueOf(maid),0);
- return ApiResponse.successRsp("0", requestId, llpiclass + ":" + llcode + ",请在ERP查看!");
- }
- @Override
- public ApiResult<String> multiMakeReturn(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- Map<String, JSONArray> data = getData(request);
- int tlid=0,maid=0,frob=99;
- String tlcode = "",ma_tasktype=null,taskType="良品退仓",tlpiclass = "生产退料单", tlcaller = "ProdInOut!Make!Return", piclass="'生产领料单','生产退料单'";
- //良品退仓、来料不良、制程不良
- List<String> sqls = new ArrayList<>();
- JSONArray main = data.get("main");
- JSONArray detail = data.get("detail");
- String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(detail.get(0), "")).get("FICMOBillNo"));
- Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
- if (data1 != null && data1.length > 0) {
- ma_tasktype = StringUtil.nvl(data1[0], "");
- maid = Integer.parseInt(StringUtil.nvl(data1[1], "0"));
- } else {
- return ApiResponse.failRsp("10051", requestId, "工单在ERP不存在,请核对!");
- }
- for (int i = 0; i <main.size() ; i++) {
- Object obj = main.get(i);
- JSONObject object = JSON.parseObject(StringUtil.nvl(obj, ""));
- Map<Object, Object> map1 = JSONUtil.toMap(StringUtil.nvl(object.get("FDeptID"),"{}"));
- Map<Object, Object> map3 = JSONUtil.toMap(StringUtil.nvl(object.get("FFManagerID"),"{}"));
- Map<Object, Object> map4 = JSONUtil.toMap(StringUtil.nvl(object.get("FSManagerID"),"{}"));
- Map<Object, Object> map5 = JSONUtil.toMap(StringUtil.nvl(object.get("FBillerID"),"{}"));
- frob = Integer.parseInt(StringUtil.nvl(object.get("FROB"), "99"));
- taskType = StringUtil.nvl(object.get("TaskType"), "");
- if ("OS".equals(ma_tasktype)) {
- tlpiclass = "委外退料单";
- tlcaller = "ProdInOut!OutsideReturn";
- piclass="'委外领料单','委外退料单'";
- }
- String fSelBillNo = StringUtil.nvl(object.get("FSelBillNo"), "");
- ApiResult<String> result = checkMESCode(requestId, fSelBillNo, tlpiclass);
- if (result!=null){
- return result;
- }
- tlid = baseDao.getSeqId("PRODINOUT_SEQ");
- tlcode = baseDao.sGetMaxNumber(tlcaller, 2);
- 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+"')");
- }
- Object[] warehouses =null;
- if(detail!=null&&detail.size()>0) {
- int detno=1;
- for (int i = 0; i < detail.size(); i++) {
- JSONObject object = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
- Object lineId = object.get("lineId");
- //物料资料
- Map<Object, Object> map = JSONUtil.toMap(StringUtil.valueOf(object.get("FItemID")));
- String itemNo = StringUtil.nvl(map.get("FNumber"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10052",requestId,"物料不能为空!");
- }
- //退料数量
- Double qty =Double.parseDouble(StringUtil.nvl(object.get("FAuxQty"), "0"));
- if (qty==0){
- return ApiResponse.failRsp("10053",requestId,"实发数量不能为空!");
- }
- //退回仓库
- Map<Object, Object> map2 = JSONUtil.toMap(StringUtil.nvl(object.get("FSCStockID2"), "{}"));
- String whcode = StringUtil.nvl(map2.get("FNumber"), "");
- if ("".equals(whcode)) {
- return ApiResponse.failRsp("10055", requestId, "物料退回仓库不能为空!");
- }
- 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 + "'");
- if (count <= 0) {
- return ApiResponse.failRsp("10056", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- 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"));
- if (qty.compareTo(outqty) > 0) {
- return ApiResponse.failRsp("10058", requestId, "退料数量不允许超过对应的发料数,请确定仓库属性和领料数量!");
- }
- String ficmoBillNo = StringUtil.nvl(object.get("FICMOBillNo"), "");
- int count1 = baseDao.getCount("select count(1) from MakeMaterial where mm_id in (" + lineId + ")");
- if (count1<=0){
- return ApiResponse.failRsp("10075",requestId,"工单BOM不存在或ID不一致,请联系管理员处理!");
- }
- 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+")");
- Object prid = baseDao.getFieldDataByCondition("Product", "pr_id", "pr_code='" + itemNo + "'");
- 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+"')");
- detno++;
- }
- 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="
- + tlid);
- 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="
- + tlid);
- if ("OS".equals(ma_tasktype)) {
- 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);
- }
- if (warehouses!=null){
- sqls.add("update prodinout set pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"' where pi_id="+tlid);
- }
- }
- baseDao.execute(sqls);
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- if(!baseDao.isDBSetting(tlcaller,"AllowPost")){
- return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+",请在ERP查看并手工过账!");
- }
- String s = postProdInOut(tlid, tlcaller, employee);
- logger.info("新生产退料单过账信息:"+s);
- if (s!=null) {
- return ApiResponse.successRsp("0", requestId, tlpiclass + ":" + tlcode + ",过账失败,请在ERP重新过账!");
- }
- return ApiResponse.successRsp("0",requestId,tlpiclass+":"+tlcode+",请在ERP查看!");
- }
- @Override
- public ApiResult<String> productWhQty(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject data = getJsonData(request);
- if (data!=null){
- List<Map<String, Object>> maps = new ArrayList<>();
- //物料
- String itemNo = StringUtil.nvl(data.get("ItemNo"), "");
- if ("".equals(itemNo)){
- return ApiResponse.failRsp("10071",requestId,"物料不能为空!");
- }
- //仓库
- String whCode = StringUtil.nvl(data.get("WhCode"), "");
- if ("".equals(whCode)) {
- SqlRowList rs = baseDao.queryForRowSet("select pw_whcode,sum(nvl(pw_onhand,0)) qty from productwh where pw_prodcode='" + itemNo + "' group by pw_whcode");
- while (rs.next()){
- 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");
- if (rowSet.next()){
- Map<String, Object> map = new HashMap<>();
- map.put("whCode",rowSet.getString("cd_varchar50_1"));
- map.put("qty",rs.getGeneralDouble("qty"));
- maps.add(map);
- }
- }
- }else {
- 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 + "'");
- if (count <= 0) {
- return ApiResponse.failRsp("10072", requestId, "MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- Double qty = baseDao.getSummaryByField("productwh", "pw_onhand", "pw_prodcode='" + itemNo + "' and pw_whcode='" + warehouses[0] + "'");
- Map<String, Object> map = new HashMap<>();
- map.put("whCode", whCode);
- map.put("qty", qty);
- maps.add(map);
- }
- if (maps==null){
- return ApiResponse.failRsp("10073",requestId,"未找到数据!");
- }else {
- return ApiResponse.successRsp("0", "获取成功!",requestId, JSON.toJSONString(maps));
- }
- }else {
- return ApiResponse.failRsp("10074",requestId,"参数异常!");
- }
- }
- @Override
- public ApiResult<String> confirmMakeScrap(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject data = getJsonData(request);
- if (data != null) {
- String apCode = null;
- String msclass = "生产报废单";
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- String msId = StringUtil.nvl(data.get("scrapid"), "");
- if (baseDao.checkIf("MakeScrap","ms_statuscode='CONFIRMED' and ms_id="+msId)){
- return ApiResponse.failRsp("10075",requestId,"生产报废单已确认!");
- }
- baseDao.updateByCondition("MakeScrapdetail", "md_status=99", "md_msid=" + msId);
- List<Object[]> objects = baseDao.getFieldsDatasByCondition("MakeScrapdetail left join make on ma_code=md_mmcode ", new String[]{
- "ma_id", "md_mmdetno", "md_qty", "md_prodcode"}, " md_msid=" + msId);
- for (Object[] object : objects) {
- baseDao.updateByCondition("Makematerial ", "mm_scrapqty =nvl(mm_scrapqty,0)+" + object[2], "mm_detno=" + object[1]
- + " and mm_maid=" + object[0]);
- baseDao.updateByCondition("Makematerial ", "mm_repscrapqty =nvl(mm_repscrapqty,0)+" + object[2], "mm_detno=" + object[1]
- + " and mm_maid=" + object[0] + " and mm_prodcode<>'" + object[3] + "'");
- baseDao.updateByCondition("Makematerialreplace ", "mp_scrapqty =nvl(mp_scrapqty,0)+" + object[2], " mp_maid=" + object[0]
- + " and mp_mmdetno=" + object[1] + " and mp_prodcode='" + object[3] + "'");
- }
- // 执行审核操作
- baseDao.updateByCondition("MakeScrap", "ms_status='已确认',ms_statuscode='CONFIRMED'", "ms_id=" + msId);
- // 记录操作
- 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 + "')");
- //生成超损请购
- int apId = baseDao.getSeqId("APPLICATION_SEQ");
- apCode = baseDao.sGetMaxNumber("Application", 2);
- Object dpcode = baseDao.getFieldDataByCondition("MakeScrapDetail", "min(md_department)", "md_msid=" + msId);
- 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) " +
- " 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);
- 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) " +
- "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);
- 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);
- return ApiResponse.successRsp("0", requestId, "请购单:" + apCode + ",请在ERP查看!");
- }else {
- return ApiResponse.failRsp("10074",requestId,"参数异常!");
- }
- }
- @Override
- public ApiResult<String> confirmSendNotify(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- List<Map<Object, Object>> maps = getJsonsData(request);
- if (maps!=null&&!maps.isEmpty()){
- List<Map<String, Object>> hashMaps = new ArrayList<>();
- List<Key> keys = new ArrayList<>();
- for (Map<Object, Object> map:maps) {
- int sndId = Integer.parseInt(StringUtil.nvl(map.get("sndId"), "0"));
- if (sndId>0){
- int snId = Integer.parseInt(StringUtil.nvl(baseDao.getFieldDataByCondition("SendNotifyDetail", "snd_snid", "snd_id=" + sndId), "0"));
- if (!baseDao.checkIf("SendNotifyDetail","snd_id="+sndId)){
- return ApiResponse.failRsp("10079", requestId, "明细行不存在,请核对!");
- }
- if (!baseDao.checkIf("SendNotify", "sn_id=" + snId)) {
- return ApiResponse.failRsp("10071", requestId, "出货通知单不存在,无法确认!");
- }
- if (!baseDao.checkIf("SendNotify", "sn_statuscode='AUDITED' and sn_id=" + snId)) {
- return ApiResponse.failRsp("10072", requestId, "出货通知单不是已审核状态,无法确认!");
- }
- if (baseDao.checkIf("SendNotify", "sn_sendstatus='已出库' and sn_id=" + snId)) {
- String inoutno = StringUtil.nvl(baseDao.getFieldDataByCondition("prodiodetail", "pd_inoutno", "pd_piclass='出货单' and pd_orderid=" + sndId), "");
- return ApiResponse.successRsp("0", requestId, "出货单:" + inoutno + ",请在ERP查看!");
- //return ApiResponse.failRsp("10073", requestId, "出货通知单已出货,无需重新确认生成!");
- }
- if (baseDao.checkIf("ProdIODetail", "pd_piclass='出货单' and pd_orderid=" + sndId)) {
- return ApiResponse.failRsp("10074", requestId, "出货通知单已转出货单,无需重新确认生成!");
- }
- // 存在未审批变更单
- 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);
- if (dets != null) {
- return ApiResponse.failRsp("10075", requestId, "存在待审批的销售变更单,不能进行转出操作!行号:" + dets);
- }
- 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);
- if (dets != null) {
- return ApiResponse.failRsp("10076", requestId, "存在待审批的通知变更单,不能进行转出操作!行号:" + dets);
- }
- if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {
- 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);
- if (dets != null) {
- return ApiResponse.failRsp("10077", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
- }
- } else {
- 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);
- if (dets != null) {
- return ApiResponse.failRsp("10078", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
- }
- }
- dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from SendNotifyDetail where nvl(snd_statuscode, ' ')<>'AUDITED' and snd_id=" + sndId, String.class);
- if (dets != null) {
- return ApiResponse.failRsp("10079", requestId, "明细行状态不等于已审核,不能进行转出操作!" + dets);
- }
- double tqty = Double.parseDouble(StringUtil.nvl(map.get("tqty"), "0"));
- String prodCode = StringUtil.nvl(map.get("prodCode"), "");
- String whCode = StringUtil.nvl(map.get("whCode"), "");
- if ("".equals(prodCode)){
- return ApiResponse.failRsp("10063",requestId,"物料不能为空!");
- }
- if (!baseDao.checkIf("SendNotifyDetail","snd_prodcode='"+prodCode+"' and snd_id="+sndId)){
- return ApiResponse.failRsp("10079", requestId, "明细行物料不存在,请核对!");
- }
- if ("".equals(whCode)){
- return ApiResponse.failRsp("10063",requestId,"仓库不能为空!");
- }
- 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 + "'");
- if (count<=0){
- return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
- }
- 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 + "'");
- if (tqty<=0){
- return ApiResponse.failRsp("10063",requestId,"数量需要大于0!");
- }
- if (baseDao.checkIf("SendNotifyDetail","nvl(snd_yqty,0)+"+tqty+">nvl(snd_outqty,0) and snd_id="+sndId)){
- return ApiResponse.failRsp("10063",requestId,"数量+已转出货数不能大于通知单数量!");
- }
- 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);
- hashMaps.addAll(mapList);
- }
- }
- List<Map<Object, Object>> mapList = BaseUtil.parseGridStoreToMaps(StringUtil.nvl(baseDao.changeKeyToLowerCase(hashMaps), "[{}]"));
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- Map<Object, List<Map<Object, Object>>> groups = BaseUtil.groupsMap(mapList, new Object[] {"sn_custcode","sn_shcustcode","sn_currency","sn_arcustcode","sn_paymentscode"});
- // 按客户分组的转入操作
- Set<Object> mapSet = groups.keySet();
- List<Map<Object, Object>> items;
- for (Object s : mapSet) {
- items = groups.get(s);
- // 转入通知单主记录
- Integer sn_id = baseDao.getFieldValue("SendNotifyDetail", "snd_snid", "snd_id=" + items.get(0).get("snd_id"),
- Integer.class);
- Key key = transferRepository.transfer("ProdInOut!Sale", sn_id, employee);
- if (key != null) {
- keys.add(key);
- int pi_id = key.getId();
- // 转入明细
- transferRepository.transfer("ProdInOut!Sale", items, key, employee);
- // 地址
- baseDao.execute(
- "update ProdInOut set pi_address=(select cu_add1 from customer where pi_cardcode=cu_code) where pi_id=? and nvl(pi_address,' ')=' '",
- pi_id);
- 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="
- + pi_id);
- 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 nvl(pi_whcode,' ')=' ' and pi_id=?",
- pi_id);
- baseDao.execute(
- "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=?",
- pi_id);
- baseDao.execute("update ProdIODetail set pd_ordertotal=round(pd_outqty*pd_sendprice,2) where pd_piid=?", pi_id);
- baseDao.updateByCondition(
- "ProdIODetail",
- "pd_netprice=round(pd_sendprice/(1+pd_taxrate/100),8),pd_nettotal=round(pd_sendprice*pd_outqty/(1+nvl(pd_taxrate,0)/100),2)",
- "pd_piid=" + pi_id);
- baseDao.execute(
- "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=?",
- pi_id);
- baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
- return ApiResponse.successRsp("0", requestId, "出货单:" + key.getCode() + ",请在ERP查看!");
- } else
- return ApiResponse.failRsp("10080", requestId, "生成失败!");
- }
- // 修改出货通知单状态
- Map<Object, List<Map<Object, Object>>> listMap = BaseUtil.groupsMap(mapList, new Object[]{"sn_id"});
- // 按客户分组的转入操作
- Set<Object> mSet = listMap.keySet();
- for (Object obj : mSet) {
- String statuscode = null, status = null;
- int count = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj);
- int yCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj + " and nvl(snd_yqty,0)=nvl(snd_outqty,0) and nvl(snd_yqty,0)>=0");
- int xCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + obj + " and nvl(snd_yqty,0)=0");
- statuscode = "PARTOUT";
- status = "部分出库";
- if (xCount == count) {
- statuscode = "";
- status = "";
- }
- if (yCount == count) {
- statuscode = "TURNOUT";
- status = "已出库";
- }
- baseDao.updateByCondition("SendNotify", "SN_SENDSTATUSCODE='" + statuscode + "',SN_SENDSTATUS='" + status + "'", "sn_id=" + obj);
- }
- if (keys!=null&&!keys.isEmpty()) {
- String code="";
- for (Key key:keys) {
- //过账出货单
- String s = postProdInOut(key.getId(), "ProdInOut!Sale", employee);
- code=code+key.getCode()+",";
- }
- return ApiResponse.successRsp("0", requestId, "出货单:" + code + ",请在ERP查看!");
- }else
- return ApiResponse.failRsp("10082",requestId,"生成失败!");
- } else
- return ApiResponse.failRsp("10081",requestId,"参数异常!");
- }
- @Override
- public ApiResult<String> confirmProdInOutMakeGive(HttpServletRequest request) {
- String requestId = request.getHeader("RequestId");
- JSONObject jsonData = getJsonData(request);
- if (jsonData!=null&&jsonData.size()>0){
- int erpId = Integer.parseInt(StringUtil.nvl(jsonData.get("erpId"), "0"));
- if (erpId>0){
- if (baseDao.checkIf("prodinout","pi_id="+erpId)){
- Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
- String s = postProdInOut(erpId, "ProdInOut!Make!Give", employee);
- Object data = baseDao.getFieldDataByCondition("prodinout", "pi_inoutno", "pi_id=" + erpId);
- if (s!=null) {
- return ApiResponse.failRsp("10094", requestId, "生产补料单:" +data+",过账失败!异常信息:"+s);
- }else
- return ApiResponse.successRsp("0", requestId, "生产补料单:" +data+ "已过账,请在ERP查看!");
- }else
- return ApiResponse.failRsp("10093",requestId,"生产领料单不存在,请核对!");
- }else
- return ApiResponse.failRsp("10092",requestId,"参数异常!");
- }else
- return ApiResponse.failRsp("10091",requestId,"参数异常!");
- }
- private Map<String, JSONArray> getData(HttpServletRequest request){
- Map<String, JSONArray> map = new HashMap<>();
- try {
- String data = PSHttpUtils.readRaw(request.getInputStream());
- JSONObject jsonObject = JSON.parseObject(data);
- Object data1 = jsonObject.get("Data");
- JSONObject jsonObject1 = JSON.parseObject(StringUtil.nvl(data1,""));
- Object page1 = jsonObject1.get("Page1");
- Object page2 = jsonObject1.get("Page2");
- JSONArray jsonArray = JSON.parseArray(StringUtil.nvl(page1, ""));
- map.put("main",jsonArray);
- JSONArray jsonArray1 = JSON.parseArray(StringUtil.nvl(page2, ""));
- map.put("detail",jsonArray1);
- } catch (IOException e) {
- logger.info("参数解析异常信息:"+e.getMessage());
- e.printStackTrace();
- }
- return map;
- }
- private JSONObject getJsonData(HttpServletRequest request){
- JSONObject jsonObject=null;
- try {
- String data = PSHttpUtils.readRaw(request.getInputStream());
- jsonObject = JSON.parseObject(data);
- } catch (IOException e) {
- logger.info("参数解析异常信息:"+e.getMessage());
- e.printStackTrace();
- }
- return jsonObject;
- }
- private List<Map<Object, Object>> getJsonsData(HttpServletRequest request){
- try {
- String data = PSHttpUtils.readRaw(request.getInputStream());
- return BaseUtil.parseGridStoreToMaps(data);
- } catch (IOException e) {
- logger.info("参数解析异常信息:"+e.getMessage());
- e.printStackTrace();
- }
- return null;
- }
- private ApiResult<String> checkMESCode(String requestId,String mesNo,String piclass){
- if ("".equals(mesNo)){
- return ApiResponse.failRsp("10100", requestId, "MES单号不能为空!");
- }
- int count = baseDao.getCount("select count(1) from prodinout where pi_class='" + piclass + "' and pi_mescode='" + mesNo + "'");
- if (count>0){
- Object code = baseDao.getFieldDataByCondition("prodinout", "pi_inoutno", "pi_class='" + piclass + "' and pi_mescode='" + mesNo + "'");
- return ApiResponse.successRsp("0",requestId,"MES单号:"+mesNo+"已存在,请在ERP查看"+piclass+",单据编号:"+code);
- }
- return null;
- }
- private synchronized String postProdInOut(int pi_id, String caller,Employee employee) {
- // 增加系统参数 出入库日期小于等于当前日期才允许过账 maz 2018020006
- if (baseDao.isDBSetting("sys", "limitPostAfter")) {
- Object pi_date = baseDao.getFieldDataByCondition("ProdInOut", "pi_date", "pi_id=" + pi_id);
- String sysdate = DateUtil.getCurrentDate();
- int sign = 0;
- sign = DateUtil.compare(pi_date.toString(), sysdate);
- if (sign == 1) {
- return "单据日期大于当前日期,不能过账";
- }
- }
- // 只能对状态为[未过账]的单据进行过账操作!
- Object[] status = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_statuscode", "pi_invostatuscode", "pi_date", "pi_class", "pi_recordman", "pi_inoutno" }, "pi_id=" + pi_id);
- if (status[0].equals("POSTED")) {
- return "只能对未过账的" + status[3] + "[" + status[5] + "]进行过账操作!";
- }
- // 2018030244 maz 送货单号不一致不允许提交
- if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!DefectIn".equals(caller)) {
- if (baseDao.isDBSetting("VerifyApplyDetail!Deal", "turnByDeliver")) {
- SqlRowList rs = baseDao
- .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="
- + pi_id + " and nvl(pi_sendcode,' ')<>nvl(va_sendcode,' ')");
- if (rs.next()) {
- return "行号:" + rs.getInt("pd_pdno") + "送货单号不一致,不允许操作";
- }
- }
- }
- // 明细中如果有属于物料等级属于库存不可用的,就提示这些物料当前等级库存不可用
- SqlRowList rowList = baseDao
- .queryForRowSet(
- "select wm_concat(pd_prodcode) prodcode from (select distinct pd_prodcode from prodiodetail "
- + "left join product on pd_prodcode=pr_code left join productlevel on pr_level=pl_levcode where pd_piid=? and pl_id>0 "
- + "and pl_isuseable=0 ) where rownum<=20", pi_id);
- if (rowList.next()) {
- if (rowList.getString("prodcode") != null) {
- return "这些物料当前等级库存不可用,物料编号:" + rowList.getString("prodcode");
- }
- }
- 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="
- + pi_id + " and nvl(pi_whcode,' ')= ' '");
- // 判断已审核才允许过账
- if (baseDao.isDBSetting(caller, "postNeedAudit")) {
- if (!status[1].equals("AUDITED")) {
- return status[3] + "[" + status[5] + "]未审核,不允许过账!";
- }
- }
- String dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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'",
- String.class, pi_id);
- if (dets != null) {
- return "来源的" + dets + "未过账,本单据不允许过账!";
- }
- // 无来源订单不能直接过账
- if (baseDao.isDBSetting(caller, "isWuPO")) {
- int count = baseDao
- .getCount("select count(*) from ProdIODetail where (pd_ordercode is null or pd_orderdetno is null) and pd_piid="
- + pi_id);
- if (!status[1].equals("AUDITED") && count != 0) {
- return "无来源订单审核后才能过账";
- }
- }
- boolean isProdIn=baseDao.isProdIn(caller);
- if (isProdIn) {
- // 检测入库单明细生产日期是否大于系统时间
- if (baseDao.isDBSetting("sys","inOverNow")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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') ",
- String.class, pi_id);
- if (dets != null) {
- return "行:" + dets + ",明细生产日期不能大于系统日期所在年月!";
- }
- }
- SqlRowList rs = null;
- // 入库类单据:如果pd_location为空,默认等于物料资料里的仓位pr_location
- baseDao.execute(
- "update prodiodetail set pd_location=(select pr_location from product where pr_code=pd_prodcode) where pd_piid=? and nvl(pd_location,' ')=' '",
- pi_id);
- rs = baseDao.queryForRowSet("SELECT pd_id FROM ProdioDetail where pd_piid=? and nvl(pd_batchcode,' ')=' '", pi_id);
- while (rs.next()) {
- baseDao.execute("update prodiodetail set pd_batchcode=? where pd_id=?", baseDao.getBatchcode(caller), rs.getInt("pd_id"));
- }
- // 入库单有生成条码但条码对应的物料或数量或批次号与明细行不一致则不允许过账
- rs = baseDao.queryForRowSet(
- "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"
- + " where bi_piid=? group by bi_pdno) on bi_pdno=pd_pdno where pd_piid=? and pd_inqty>0 and inqty>0 "
- + " and (nvl(inqty,0)<>pd_inqty or bi_prodcode<>pd_prodcode or bi_batchcode<>pd_batchcode) and rownum<30",
- pi_id, pi_id);
- if (rs.next() && rs.getInt("cn") > 0) {
- return "条码与明细行中的物料或数量或批次号不一致,不允许过账,请先清除不一致条码!行号:" + rs.getString("no");
- }
- } else {
- SqlRowList rs = null;
- rs = baseDao
- .queryForRowSet(
- "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",
- pi_id);
- while (rs.next()) {
- if (rs.getGeneralDouble("ba_purcrate") != 0) {
- baseDao.execute("update prodiodetail set pd_purcoutqty=round(nvl(pd_outqty,0)/" + rs.getGeneralDouble("ba_purcrate")
- + ",8) where pd_id=" + rs.getObject("pd_id"));
- } else {
- baseDao.execute("update prodiodetail set pd_purcoutqty=nvl(pd_outqty,0) where pd_id=" + rs.getObject("pd_id"));
- }
- }
- }
- useDefaultTax(caller, pi_id);
- String s = allowZeroTax(caller, pi_id);
- if (s!=null){
- return s;
- }
- String s1 = checkFreezeMonth(caller, status[2]);
- if (s1!=null){
- return s1;
- }
- String s2 = checkCloseMonth(status[2]);
- if (s2!=null){
- return s2;
- }
- String s3 = checkFirstMonth(caller, status[2]);
- if (s3!=null){
- return s3;
- }
- String s4 = checkCommit(caller, pi_id);
- if (s4!=null){
- return s4;
- }
- String s5 = checkBatch(caller, pi_id);
- if (s5!=null){
- return s5;
- }
- String copcheck = copcheck(pi_id, caller);
- if (copcheck!=null){
- return copcheck;
- }
- String factorycheck = factorycheck(pi_id, caller);
- if (factorycheck!=null){
- return factorycheck;
- }
- // 制造工单加工类型
- if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
- String s6 = checkMakeKindType(caller, pi_id);
- if (s6!=null){
- return s6;
- }
- }
- // 暂时不启用平台 销售仓模式checkWhIsB2C(caller, pi_id);
- /**
- * 委外验收单,委外验退单 过账限制,判断明细行中的应付供应商或币别与主表是否一致,不一致则不允许过账;
- */
- if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
- SqlRowList rs = baseDao
- .queryForRowSet(
- "select wm_concat(pd_pdno) c from (select nvl(nvl(ma_apvendcode,ve_apvendcode),ve_code) apvendcode, pi_receivecode,pd_pdno "
- + "from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join vendor "
- + "on ma_vendcode=ve_code where pi_id=?) t where t.apvendcode <> t.pi_receivecode and rownum<30", pi_id);
- if (rs.next()) {
- if (rs.getObject("c") != null) {
- return "明细行中委外加工单的应付供应商与主表中的应付供应商不一致!";
- }
- }
- SqlRowList rs2 = baseDao.queryForRowSet("select wm_concat(pd_pdno) x from (select ma_currency,pi_currency,pd_pdno"
- + " from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode"
- + " where pi_id=?) t where t.ma_currency <> t.pi_currency and rownum<30", pi_id);
- if (rs2.next()) {
- if (rs2.getObject("x") != null) {
- return "明细行中委外加工单的币别与主表中的币别不一致!";
- }
- }
- }
- // 完工入库,委外验收限制,入库数量不允许大于到当前pi_date的月份为止的(制造单生产的总数数量-已入库总数)
- if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
- // 存在pi_date 年月之后的 出入库单
- int ym = DateUtil.getYearmonth(status[2].toString());
- SqlRowList rs = baseDao
- .queryForRowSet(
- "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"
- + " 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 "
- + " where A.pd_ordercode=B.pd_ordercode and to_char(pi_date,'yyyyMM')>? and "
- + " pi_class in('生产领料单','生产退料单','生产补料单','委外补料单','委外领料单','委外退料单') and B.pd_status=99) group by A.pd_ordercode",
- pi_id, ym);
- while (rs.next()) {
- Object[] obs = baseDao
- .getFieldsDataByCondition(
- "make left join makematerial on mm_maid=ma_id",
- new String[] {
- " 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 "
- + " where to_char(pi_date,'yyyyMM')>'"
- + ym
- + "' and pd_ordercode=ma_code and pd_orderdetno=mm_detno and pi_class in('生产领料单','生产退料单','生产补料单','委外补料单','委外领料单','委外退料单'))"
- + " -nvl(mm_scrapqty,0))*1.0/mm_oneuseqty)end),0) as canmadeqty",
- "nvl(max(ma_madeqty),0) -"
- + "nvl(max((select SUM(NVL(pd_inqty,0)-NVL(pd_outqty,0)) from prodinout LEFT JOIN prodiodetail ON pd_piid=pi_id "
- + " WHERE TO_CHAR(pi_date,'yyyyMM')>'" + ym + "' and pd_ordercode='"
- + rs.getString("pd_ordercode")
- + "' and pi_class in('完工入库单','委外验收单','委外验退单'))),0) as madeqty" },
- " mm_code='" + rs.getString("pd_ordercode") + "' and nvl(mm_materialstatus,' ')=' ' and mm_oneuseqty>0");
- if (obs != null) {// 比较
- if (rs.getDouble("inqty") > (Double.valueOf(obs[0].toString()).doubleValue() - Double.valueOf(obs[1].toString())
- .doubleValue())) {
- return "工单[" + rs.getString("pd_ordercode") + "]当前月份领料套数(" + obs[0] + ")不足完工数";
- }
- }
- }
- }
- /**
- * 采购验收单、委外验收单 从表单位pr_unit与采购单位pr_purcunit不一致的时候,
- * 数量pd_inqty与采购单位入库数量pd_purcinqty不能一致,否则无法提交、过账
- */
- if (baseDao.isDBSetting("sys","usePurcUnit") && ("ProdInOut!PurcCheckin".equals(caller) || ("ProdInOut" +
- "!OutsideCheckIn").equals(caller))) {
- String dets1 = baseDao.getJdbcTemplate().queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join Product on pd_prodcode=pr_code where pd_piid=? "
- + "and PR_UNIT is not null and pr_purcunit is not null "
- + "and (nvl(pd_inqty,0)>0) and (nvl(pd_purcinqty,0)>0) "
- + "and nvl(PR_UNIT,'')<>nvl(pr_purcunit,'') and nvl(pd_inqty,0)=nvl(pd_purcinqty,0)", String.class, pi_id);
- if (dets1 != null) {
- return "行" + dets1 + ",明细入库数量和采购单位入库数量需不一致,否则无法过账!";
- }
- }
- /**
- * 新增生产退料和委外退料判断,替代料退料数量不能大于替代料已领数量,禁用物料判断mm_updatetype='R',
- *
- * @date 2016年10月17日 下午12:30:58
- */
- if (("ProdInOut!Make!Return").equals(caller) || ("ProdInOut!OutsideReturn").equals(caller)) {
- checkRepQty(pi_id);
- /**
- * 生产退料单,委外退料单 校验退料数量不能大于截止到单据日期月份 已过账的领料-退料-报废+补料-完工数*单位用量
- */
- checkMmBackOver(caller,pi_id);
- }
- /**
- * 新增限制,拆件类型制造单不允许走完工入库单
- *
- * @author XiaoST 2016年12月9日 下午4:26:34
- */
- if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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",
- String.class, pi_id);
- if (dets != null) {
- return "拆件工单必须走拆件入库单!" + dets;
- }
- }
- baseDao.getEndDate(caller, pi_id);
- String res = null;
- // 平台生成的销售订单转出货单过账必须等于销售订单明细序号和数量
- if ("ProdInOut!Sale".equals(caller)) {
- SqlRowList rs = baseDao
- .queryForRowSet(
- "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",
- pi_id);
- while (rs.next()) {
- rs = baseDao
- .queryForRowSet(
- "select distinct pd_ordercode pd_ordercode from prodiodetail where pd_piid=? and (pd_orderdetno not in (select sd_detno from saledetail where sd_code=?))"
- + " OR "
- + rs.getDouble("out_qty")
- + " <>(select sd_qty from saledetail where sd_code=? and sd_detno=?) and pd_ordercode =?", pi_id,
- rs.getString("sa_code"), rs.getString("sa_code"), rs.getString("pd_orderdetno"), rs.getString("sa_code"));
- if (rs.next()) {
- return "通过优软商城平台生成的发货单必须一次性发货,销售单号[" + rs.getString("pd_ordercode") + "]";
- }
- // 维护物流公司和物流单号
- Object[] obs = baseDao.getFieldsDataByCondition("prodinout", new String[] { "pi_logisticscompany", "pi_logisticscode" },
- "pi_id=" + pi_id);
- if (obs[0] == null || obs[1] == null) {
- return "请维护出货单的物流公司和物料单号信息!";
- }
- }
- }
- // 委外领、退、补单过账前
- if ("ProdInOut!OutsidePicking".equals(caller) || "ProdInOut!OutsideReturn".equals(caller) || "ProdInOut!OSMake!Give".equals(caller)) {
- // 更新:如果主表的应付供应商空,则取第一个工单的应付供应商ma_apvendcode,空则取工单供应商ma_vendcode
- baseDao.execute("update prodinout set (pi_receivecode,pi_receivename)=(select code,ve_name from "
- + "(select nvl(ma_apvendcode,ma_vendcode)code,ve_name from prodiodetail left join make on "
- + "pd_ordercode=ma_code left join vendor on nvl(ma_apvendcode,ma_vendcode)=ve_code "
- + "where pd_piid=? order by pd_pdno) where rownum=1 )" + "where nvl(pi_receivecode,' ')=' ' and pi_id=?", pi_id, pi_id);
- // 判断主表应付供应商与从表工单应付供应商是否一致
- SqlRowList pdnos = baseDao
- .queryForRowSet(
- "select wm_concat(pd_pdno) c from (select nvl(nvl(ma_apvendcode,ve_apvendcode),ve_code) apvendcode, pi_receivecode,pd_pdno "
- + "from prodiodetail left join prodinout on pd_piid=pi_id left join make on ma_code=pd_ordercode left join vendor "
- + "on ma_vendcode=ve_code where pi_id=?) t where t.apvendcode <> t.pi_receivecode and rownum<30", pi_id);
- if (pdnos.next()) {
- if (pdnos.getObject("c") != null) {
- return "行" + pdnos.getObject("c") + "工单应付供应商与主表应付供应商不一致,不能过账";
- }
- }
- }
- // @add20171103
- if ("ProdInOut!PurcCheckin".equals(caller)) {// 采购验收单根据采购单号、序号,更新入库销售单号、序号
- baseDao.execute(
- "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 "
- + " pd_ordercode=pu_code and pd_orderdetno=pd_detno) where pd_piid=?", pi_id);
- }
- // 生产退料单、委外退料单、拆件入库单、完工入库单、委外验收单,根据工单的订单号、订单序号能匹配到销售单号和序号(如果是预测单则不锁批记录)则更新到入库单明细的销售单号、序号
- if ("ProdInOut!OutsideReturn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!Make!In".equals(caller)
- || "ProdInOut!PartitionStockIn".equals(caller) || "ProdInOut!Make!Return".equals(caller)) {
- baseDao.execute(
- "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)"
- + " 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)",
- pi_id);
- }
- // 销售退货明细客户为空时=主表客户
- if ("ProdInOut!SaleReturn".equals(caller)) {
- baseDao.execute(
- "update prodiodetail set (pd_custcode,pd_custname)=(select pi_cardcode,pi_title from prodinout where pd_piid=pi_id)"
- + " where pd_piid=? and nvl(pd_custcode,' ')=' '", pi_id);
- }
- /*
- * 退料数量不能大于维护的可退数量 String SQLStr_s = ""; SqlRowList rs_s; SQLStr_s=
- * "select * from ProdIODetail left join make on ma_code=pd_ordercode"
- * +" left join IO_MAKEMATERIAL_DETNO_VIEW on pd_orderdetno = mm_detno"
- * +" where ma_id=mm_maid and pd_piid= '"+pi_id+"'"; rs_s =
- * baseDao.queryForRowSet(SQLStr_s); if(rs_s.next()){ if
- * (rs_s.getInt("pd_inqty")>rs_s.getInt("mm_havegetqty")) {
- * BaseUtil.showError("工单序号[" + rs_s.getString("pd_orderdetno") +
- * "]的退料数量不能大于维护的可退数量!'"); } }
- */
- // 过账前的其它逻辑
- getTotal(pi_id, caller);// 调用过账存储过程前后都掉用一次gettotal方法,解决出入库单税率与发票不一致
- getQtyTotal(pi_id, caller);
- // 执行过账操作
- Object[] objs = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_class", "pi_inoutno" }, "pi_id=" + pi_id);
- if ("ProdInOut!CostChange".equals(caller)) {
- res = baseDao.callProcedure("SP_PRODUCTCOSTADJUST", new Object[] { objs[0].toString(), objs[1].toString(), "" });
- if (res != null && !res.trim().equals("")) {
- return res;
- }
- } else {
- baseDao.procedure("SP_GetCostPrice", new Object[] { objs[0].toString(), objs[1].toString() });
- if (baseDao.isDBSetting("sys","SplitprodoutByseller")) {// 出单过账前取批号按照业务员pi_sellercode获取
- res = baseDao.callProcedure("Sp_Splitprodout_Byseller",
- new Object[] { objs[0].toString(), objs[1].toString(),employee.getEm_name()});
- } else {
- res = baseDao.callProcedure("Sp_SplitProdOut",
- new Object[] { objs[0].toString(), objs[1].toString(),employee.getEm_name()});
- }
- if (res != null && !res.trim().equals("")) {
- // 重新添加提示限制信息
- return res + " " + objs[0].toString() + objs[1].toString() + ",过账失败";
- // BaseUtil.showError(res);
- }
- // @add 20170614 抓取批次号成功之后更新出库单据的备料状态
- updatePdaStatus(caller, pi_id);
- if (baseDao.isDBSetting(caller, "ifBatchCodeNotChange") && baseDao.isDBSetting(caller, "autoPostIn")) {
- // 拨出单过账后产生的拨入单批号不变,同一物料同仓库不能同时入两次相同的批号
- SqlRowList rs1 = baseDao
- .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="
- + pi_id + " and pd_batchcode<>' ' group by pd_batchcode,pd_inwhcode,pd_prodcode ) where c> 1");
- if (rs1.next()) {
- if (rs1.getInt("n") > 0) {
- return "拨出单过账后产生的拨入单批号不变,同一物料同拨入仓库批号不能相同!行号:" + rs1.getString("detno");
- }
- }
- }
- String s7 = checkBatchRemain(pi_id);
- if (s7!=null){
- return s7;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wmsys.wm_concat(a2.pd_pdno) from prodinout a1 left join prodiodetail a2 on a1.pi_id=a2.pd_piid " +
- "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 " +
- "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 " +
- "and to_char(a1.pi_date,'yyyymm')<to_char(b1.pi_date,'yyyymm') and rownum<20",
- String.class, pi_id);
- if (dets != null) {
- return "出库单据日期所在期间小于批次入库日期所在期间,不能过账!行号:" + dets;
- }
- // 存储过程
- res = baseDao.callProcedure("Sp_CommitProdInout",
- new Object[] { objs[0].toString(), objs[1].toString(), employee.getEm_name()});
- if (res != null && !res.trim().equals("")) {
- return res;
- }
- if (baseDao.isDBSetting("sys","autoCreateApBill")) {
- if ("采购验收单".equals(status[3]) || "采购验退单".equals(status[3]) || "委外验收单".equals(status[3]) || "委外验退单".equals(status[3])
- || "用品验收单".equals(status[3]) || "用品验退单".equals(status[3])) {
- dets = baseDao.queryForObject("select wm_concat(ab_code) from apbill where ab_source=? and ab_statuscode<>'POSTED'",
- String.class, status[5]);
- if (dets != null) {
- return "发票" + dets + "未过账成功,请手工过账!";
- }
- }
- }
- if (baseDao.isDBSetting("sys","autoCreateArBill")) {
- if ("出货单".equals(status[3]) || "销售退货单".equals(status[3])) {
- dets = baseDao.queryForObject(
- "select wm_concat(ab_code) from arbill where AB_SOURCECODE=? and ab_statuscode<>'POSTED'", String.class,
- status[5]);
- if (dets != null) {
- return "发票" + dets + "未过账成功,请手工过账!";
- }
- }
- }
- }
- getTotal(pi_id, caller);
- getQtyTotal(pi_id, caller);
- baseDao.updateByCondition("ProdInOut", "pi_statuscode='POSTED',pi_status='已过账',pi_inoutman='"+employee.getEm_name()+"'," + "pi_date1=sysdate,pi_sendstatus='待上传'", "pi_id=" + pi_id);
- if (!baseDao.isIn(caller)) {// 出库类单据过账时,根据批号抓取batch.ba_vendorrate到prodiodetail.pd_vendorrate
- baseDao.execute("update prodiodetail set pd_vendorrate=(select ba_vendorrate from batch where ba_code=pd_batchcode"
- + " and ba_whcode =pd_whcode and ba_prodcode=pd_prodcode ) where pd_piid=" + pi_id + " and nvl(pd_vendorrate,0)=0");
- }
- if (baseDao.isDBSetting("sys","updateBusinessChance") && !"ProdInOut!GoodsIn".equals(caller)) {// 更新当前商机阶段
- Object bsname = baseDao.getFieldDataByCondition("BusinessChanceStage", "bs_name", "bs_relativeitem='Shipment'");
- Object date = baseDao.getFieldDataByCondition("ProdInOut", "to_char(pi_recorddate,'yyyy-MM-dd')", "pi_id=" + pi_id);
- List<Object[]> data = baseDao.getFieldsDatasByCondition("prodiodetail left join ProdInOut on pd_piid=pi_id", new String[] {
- "pd_bcid", "pd_prodcode", "pd_pdno" }, "pd_piid=" + pi_id);
- for (Object[] os : data) {
- if (os[0] == null || os[0].equals("") || os[0].equals("0") || Integer.parseInt(os[0].toString()) == 0) {
- String sql = "update Prodiodetail set pd_bcid=nvl((select sd_bcid from saledetail "
- + "where pd_ordercode=sd_code and pd_orderdetno=sd_detno),0) where pd_piid=" + pi_id + " and nvl(pd_bcid,0)=0";
- baseDao.execute(sql);
- }
- Object pd_bcid = baseDao.getFieldDataByCondition("Prodiodetail", "pd_bcid", " pd_prodcode='" + os[1] + "' and pd_piid="
- + pi_id);
- if (pd_bcid == null || pd_bcid.equals("") || pd_bcid.equals("0") || Integer.parseInt(pd_bcid.toString()) == 0) {
- String sql = "update prodiodetail set pd_bcid=nvl((select max(bc_id) from prodinout,businesschance "
- + "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="
- + pi_id + " and nvl(pd_bcid,0)=0";
- baseDao.execute(sql);
- }
- Object bc_id = baseDao.getFieldDataByCondition("Prodiodetail", "pd_bcid", " pd_prodcode='" + os[1] + "' and pd_piid="
- + pi_id);
- Integer bs_detno = baseDao.getFieldValue("businesschancestage", "bs_detno", "bs_name='" + bsname + "'", Integer.class);
- Integer bs_detno1 = baseDao.getFieldValue("businesschance left join businesschancestage on bs_name=bc_currentprocess",
- "nvl(bs_detno,0)", "bc_id=" + bc_id, Integer.class);
- if (bs_detno != null && bs_detno1 != null) {
- if (bs_detno >= bs_detno1) {
- baseDao.updateByCondition("BusinessChance", "bc_currentprocess='" + bsname + "',bc_desc" + bs_detno + "='" + bsname
- + "',bc_date" + bs_detno + "=to_date('" + date.toString() + "','yyyy-MM-dd')", "bc_id=" + bc_id);
- if (bsname != null && Integer.parseInt(pd_bcid.toString()) != 0) {
- Object bscode = baseDao.getFieldDataByCondition("BusinessChanceStage", "bs_code", "bs_name='" + bsname + "'");
- // 插入一条记录到商机动态表
- int bcd_id = baseDao.getSeqId("BusinessChanceData_seq");
- String link = "jsps/scm/reserve/prodInOut.jsp?whoami=ProdInOut!Sale&formCondition=pi_idIS" + pi_id
- + "&gridCondition=pd_piidIS" + pi_id;
- 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 ("
- + bcd_id
- + ","
- + bc_id
- + ",'"
- + baseDao.sGetMaxNumber("BusinessChanceData", 2)
- + "','"
- + bscode
- + "','"
- + bsname
- + "',"
- + "to_date('"
- + date.toString()
- + "','yyyy-MM-dd')"
- + ",'"
- + status[4]
- + "','"
- + "ENTERING" + "','在录入','" + status[5] + "','" + link + "')";
- baseDao.execute(contactSql);
- }
- }
- }
- }
- }
- // 调用冲销
- createSaleClash(pi_id, "ProdInOut",employee);
- if ("ProdInOut!AppropriationOut".equals(caller) || "ProdInOut!SaleAppropriationOut".equals(caller)) {
- dets = null;
- if (baseDao.isDBSetting(caller, "autoPostIn")) {
- // 过账销售拨入单
- dets = turnProdIO(pi_id,employee);
- // 过账失败提醒
- boolean showTurnProdIOError = baseDao.checkIf("ProdInOut",
- "pi_class='拨入单' and pi_statuscode='UNPOST' and pi_inoutno=(select pi_relativeplace from ProdInOut where pi_class='拨出单' and pi_id="
- + pi_id + ")");
- if (showTurnProdIOError) {
- return "自动过账失败";
- }
- }
- if (dets != null) {
- return "拨入单明细行仓库对应的仓管员与当前过账人不一致,不允许进行当前操作!行号:" + dets;
- }
- if (baseDao.isDBSetting(caller, "autoPostMakeLSSend")) {// MakeSendLS
- // 拉式发料
- // 拨出单过账,拨入也过账时自动过账领料单
- String SQLStr = "";
- String Outpiclass = "";
- SQLStr = "select pi_inoutno from prodinout where pi_id=" + pi_id + " and pi_statuscode='POSTED'";
- SqlRowList rs0 = baseDao.queryForRowSet(SQLStr);
- if (rs0.next()) {
- SQLStr = "select pi_id,pi_class,pi_inoutno from prodinout where pi_fromcode='" + rs0.getString("pi_inoutno")
- + "' and pi_statuscode='UNPOST' ";
- SqlRowList rs = baseDao.queryForRowSet(SQLStr);
- if (rs.next()) {
- Outpiclass = rs.getObject("pi_class").toString();
- if (Outpiclass.equals("生产领料单")) {
- postProdInOut(rs.getInt("pi_id"), "ProdInOut!Picking",employee);
- } else if (Outpiclass.equals("委外领料单")) {
- postProdInOut(rs.getInt("pi_id"), "ProdInOut!OutsidePicking",employee);
- }
- SQLStr = "select pi_statuscode from prodinout where pi_id=" + rs.getInt("pi_id") + " and pi_statuscode='POSTED' ";
- rs0 = baseDao.queryForRowSet(SQLStr);
- if (rs0.next()) {
- return null;
- } else {
- return Outpiclass + ":" + rs.getString("pi_inoutno") + "过账不成功!";
- }
- }
- }
- }
- }
- // 委外验收,验退,完工入库单,过账更新完工状态
- if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
- || "ProdInOut!OutesideCheckReturn".equals(caller)) {
- SqlRowList rs = baseDao.queryForRowSet(
- "select distinct ma_id from prodiodetail left join make on ma_code=pd_ordercode where pd_piid=?", pi_id);
- while (rs.next()) {// 更新完工状态
- updateMakeFinishStatus(rs.getInt("ma_id"));
- }
- }
- /*if ("ProdInOut!AppropriationOut".equals(caller)) {
- SqlRowList rs3 = baseDao
- .queryForRowSet(
- "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='拨入单'",
- pi_id);
- if (rs3.next()) {
- return "拨出单过账成功!系统产生的拨入单号 "+ rs3.getString("pi_relativeplace");
- }
- }*/
- if ("ProdInOut!PurcCheckin".equals(caller)) {// 采购验收单过账根据采购单+采购单序号更新pd_vendorrate
- // ba_vendorrate
- SqlRowList pdRowList = baseDao
- .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="
- + pi_id);
- while (pdRowList.next()) {
- baseDao.execute("update prodiodetail set pd_vendorrate=(select pd_vendorrate from purchasedetail where pd_code='"
- + pdRowList.getObject("pd_ordercode") + "' and pd_detno='" + pdRowList.getObject("pd_orderdetno")
- + "') where pd_id=" + pdRowList.getObject("pd_id"));
- baseDao.execute("update batch set ba_vendorrate=(select pd_vendorrate from purchasedetail where pd_code='"
- + pdRowList.getObject("pd_ordercode") + "' and pd_detno='" + pdRowList.getObject("pd_orderdetno")
- + "') where ba_id=" + pdRowList.getObject("pd_batchid"));
- }
- }
- if ("ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller) || "ProdInOut!Picking".equals(caller)
- || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
- || "ProdInOut!OutsidePicking".equals(caller)) {
- changeMaStatus(pi_id);
- }
- // 2017-08-30 重新根据pdno更新批号仓库属性
- if (isProdIn) {
- baseDao.execute(
- "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",
- pi_id);
- baseDao.execute(
- "update batch set ba_hasbarcode=-1 where ba_id in (select pd_batchid from prodiodetail "
- + " 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) ",
- pi_id);
- }
- /**
- * @author wsy
- * 其它入库单:如果选择了采购单号、采购序号后,提交、审核的时候要判断采购单号+采购序号+物料编号是否一致,不一致限制提交
- * 、审核
- */
- if ("ProdInOut!OtherIn".equals(caller)) {
- 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="
- + pi_id + " and pd_piclass='其它入库单')");
- }
- prodinout_post_updatesourceqty(pi_id);
- return null;
- }
- /**
- * 过账后扣除待检数量、收料数量 scm->prodinout->post->after
- *
- * @author madan
- */
- public void prodinout_post_updatesourceqty(Integer id) {
- Object[] piclass = baseDao.getFieldsDataByCondition("ProdInOut", new String[] { "pi_class", "pi_type" }, "pi_id=" + id);
- if (!(piclass[0].toString().equals("采购验收单") || piclass[0].toString().equals("委外验收单") || piclass[0].toString().equals("不良品入库单"))) {
- return;
- }
- List<Object[]> objs = baseDao.getFieldsDatasByCondition("prodioDetail", new String[] { "pd_orderdetno", "pd_ordercode",
- "sum(pd_inqty)", "pd_prodcode" }, "pd_piid=" + id + " and pd_qcid>0 group by pd_ordercode, pd_orderdetno, pd_prodcode");
- for (Object[] obj : objs) {
- if ("采购验收单".equals(piclass[0].toString())) {
- baseDao.updateByCondition("PurchaseDetail", "pd_reconhand = nvl(pd_reconhand,0)-" + obj[2]
- + ",pd_totested=NVL(pd_totested,0)-" + obj[2], "pd_code='" + obj[1] + "' and pd_detno = " + obj[0]);
- } else if ("委外验收单".equals(piclass[0].toString()) || "完工入库单".equals(piclass[0].toString())) {
- baseDao.updateByCondition("Make", "ma_reconhand = nvl(ma_reconhand,0)-" + obj[2] + ",ma_totested=NVL(ma_totested,0)-"
- + obj[2], "ma_code='" + obj[1] + "'");
- } else if ("不良品入库单".equals(piclass[0].toString())) {
- if ("PURC".equals(piclass[1].toString()) || "采购不良品入库".equals(piclass[1].toString())) {
- baseDao.updateByCondition("PurchaseDetail", "pd_reconhand = nvl(pd_reconhand,0)-" + obj[2]
- + ",pd_totested=NVL(pd_totested,0)-" + obj[2], "pd_code='" + obj[1] + "' and pd_detno = " + obj[0]);
- } else {
- baseDao.updateByCondition("Make", "ma_reconhand = nvl(ma_reconhand,0)-" + obj[2] + ",ma_totested=NVL(ma_totested,0)-"
- + obj[2], "ma_code='" + obj[1] + "'");
- }
- }
- baseDao.updateByCondition("Product", "pr_reconhand = nvl(pr_reconhand,0)-" + obj[2] + ",pr_totested=NVL(pr_totested,0)-"
- + obj[2], "pr_code='" + obj[3] + "'");
- }
- }
- // 税率强制等于币别表的默认税率
- private void useDefaultTax(String caller, Object pi_id) {
- if (baseDao.isDBSetting(caller, "useDefaultTax")) {
- 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)"
- + " where pd_piid=" + pi_id);
- }
- String defaultTax = baseDao.getDBSetting(caller, "defaultTax");
- if (defaultTax != null) {
- // 税率强制等于币别表的默认税率
- if ("1".equals(defaultTax)) {
- 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)"
- + " where pd_piid=" + pi_id);
- }
- // 税率强制等于供应商资料的默认税率
- if ("2".equals(defaultTax)) {
- if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)
- || "ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
- 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)"
- + " where pd_piid=" + pi_id);
- }
- if ("ProdInOut!SaleReturn".equals(caller) || "ProdInOut!Sale".equals(caller)) {
- 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)"
- + " where pd_piid=" + pi_id);
- }
- }
- }
- }
- // 本位币允许税率为0
- private String allowZeroTax(String caller, Object pi_id) {
- String currency = baseDao.getDBSetting("sys","defaultCurrency");
- boolean allowZeroTax = baseDao.isDBSetting(caller, "allowZeroTax");
- if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller)) {
- allowZeroTax = baseDao.isDBSetting("Sale", "allowZeroTax");
- }
- if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)) {
- allowZeroTax = baseDao.isDBSetting("Purchase", "allowZeroTax");
- }
- if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {
- allowZeroTax = baseDao.isDBSetting("Make", "allowZeroTax");
- }
- if (!allowZeroTax) {
- String dets = baseDao.getJdbcTemplate().queryForObject(
- "select WM_CONCAT(pd_pdno) from ProdIODetail left join ProdInOut on pd_piid=pi_id where nvl(pd_taxrate,0)=0 and pi_currency='"
- + currency + "' and pi_id=?", String.class, pi_id);
- if (dets != null) {
- return "本位币税率为0,不允许进行当前操作!行号:" + dets;
- }
- }
- return null;
- }
- String checkCloseMonth(Object pidate) {
- boolean bool = baseDao.checkIf("PeriodsDetail", "pd_code='MONTH-P' and pd_status=99 and pd_detno=to_char(to_date('" + pidate
- + "','yyyy-mm-dd hh24:mi:ss'), 'yyyymm')");
- if (bool) {
- return "单据日期所属期间已结账,不允许进行当前操作!";
- }
- return null;
- }
- String checkMakeKindType(String caller, Object pi_id) {
- if (baseDao.isDBSetting(caller, "makeKindType")) {
- String sql = "select count(1)cn from (select count(1) cn, mk_type from make left join makekind on mk_name =ma_kind"
- + " left join prodiodetail on pd_ordercode = ma_code where pd_piid=? group by mk_type) ";
- SqlRowList sqlRowList = baseDao.queryForRowSet(sql, pi_id);
- if (sqlRowList.next()) {
- if (sqlRowList.getInt("cn") > 1) {
- return "明细行制造单加工类型不同,不能使用同一张完工入库单";
- }
- }
- }
- return null;
- }
- String checkFreezeMonth(String caller, Object pidate) {
- if (!"ProdInOut!CostChange".equals(caller)) {
- String freeze = baseDao.getDBSetting("sys","freezeMonth");
- if (freeze != null && !freeze.equals("")) {
- if (Integer.parseInt(freeze) == DateUtil.getYearmonth(pidate.toString())) {
- return "单据日期所属期间已冻结,不允许进行当前操作!";
- }
- }
- }
- return null;
- }
- String checkFirstMonth(String caller, Object pidate) {
- if ("ProdInOut!ReserveInitialize".equals(caller)) {
- Object first = baseDao.getFieldDataByCondition("periods", "nvl(PE_FIRSTDAY,0)", "PE_CODE='MONTH-P'");
- if ("0".equals(first.toString())) {
- return "请前往【初始化期间设置】确认开账期间!";
- } else {
- if (Integer.parseInt(first.toString()) != DateUtil.getYearmonth(pidate.toString())) {
- return "库存初始化单据只能发生在库存模块的开账期间!当前库存模块开账期间为[" + first + "],请前往【初始化期间设置】确认开账期间!";
- }
- }
- }
- return null;
- }
- /*
- * 提交,审核,过账之前的限制
- */
- private String checkCommit(String caller, Object pi_id) {
- checkIOMaPick(caller,pi_id);
- if (!caller.equals("ProdInOut!AppropriationOut") && !caller.equals("ProdInOut!AppropriationIn")) {
- baseDao.execute("update prodiodetail set pd_whcode=(select pi_whcode from prodinout where pd_piid=pi_id) where pd_piid="
- + pi_id + " and NVL(pd_whcode,' ')=' '");
- }
- if (caller.equals("ProdInOut!Make!Return") || caller.equals("ProdInOut!OutsideReturn")) {
- 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="
- + pi_id + " and pd_prodmadedate is null");
- }
- baseDao.execute("update prodiodetail set pd_prodmadedate=(select pi_date from prodinout where pd_piid=pi_id) where pd_piid="
- + pi_id + " and pd_prodmadedate is null");
- if ("ProdInOut!CostChange".equals(caller)) {
- baseDao.execute(
- "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=?",
- pi_id);
- baseDao.execute(
- "update prodiodetail set pd_total=round(nvl(pd_orderqty,0)*(nvl(pd_price,0)-nvl(pd_orderprice,0)),2) where pd_piid=?",
- pi_id);
- }
- 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="
- + pi_id + " and nvl(pd_qcid,0)<>0");
- String dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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'",
- String.class, pi_id);
- if (dets != null) {
- return "明细行物料不存在或者状态不等于已审核,不允许进行当前操作!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']') from ProdIODetail where pd_piid=? and nvl(pd_whcode,' ')=' '",
- String.class, pi_id);
- if (dets != null) {
- return "明细行仓库为空,不允许进行当前操作!" + dets;
- }
- /**
- * 限制当仓库编号不为空时,明细行仓库至少有一行与主记录一致;为空则不判断
- */
- /*
- * 暂不启用该逻辑限制 int c = baseDao.getCountByCondition(
- * "ProdInOut left join ProdIODetail on pi_id=pd_piid", "pi_id=" + pi_id
- * +
- * " and ((NVL(pd_whcode,' ')=nvl(pi_whcode,' ') AND pi_whcode IS NOT NULL) or pi_whcode is null )"
- * ); if (c < 1) { BaseUtil.showError("无一明细仓库与主表仓库一致,不允许进行当前操作!"); }
- */
- if (!caller.equals("ProdInOut!StockProfit") && !caller.equals("ProdInOut!StockLoss")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail inner join Prodinout on pd_piid=pi_id left join product on pr_code=pd_prodcode where "
- + "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,' ')<>'用品' ",
- String.class, pi_id);
- if (dets != null) {
- return "计算精度是0的物料不能以小数出入库!行号:" + dets;
- }
- }
- if (baseDao.isDBSetting("sys","warehouseCheck") || baseDao.isDBSetting(caller, "warehouseCheck")) {
- // 出入库单主记录与明细行仓库必须一致
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' '))",
- String.class, pi_id);
- if (dets != null) {
- return "明细行仓库与当前单主表仓库不一致,不允许进行当前操作!" + dets;
- }
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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'",
- String.class, pi_id);
- if (dets != null) {
- return "仓库已禁用,不允许进行当前操作!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "仓库不存在,不允许进行当前操作!" + dets;
- }
- String maxprice = baseDao.getDBSetting(caller, "maxPrice");
- if (maxprice != null) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wmsys.wm_concat(pd_piclass||':'||pd_inoutno||',行:'||pd_pdno||',单价:'||pd_price) from prodiodetail where pd_piid=? and nvl(pd_price,0)>?",
- String.class, pi_id, maxprice);
- if (dets != null) {
- return "单价超过设置上限,不允许进行当前操作!" + dets;
- }
- }
- if ("ProdInOut!Picking".equals(caller) || "ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller)
- || "ProdInOut!OutsidePicking".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
- || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!Make!In".equals(caller)
- || "ProdInOut!PartitionStockIn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
- || "ProdInOut!OutesideCheckReturn".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "工单+序号不存在,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 "
- + " 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)",
- String.class, pi_id);
- if (dets != null) {
- return "工单+序号+物料编号不存在,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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_cardcode,' ')<>nvl(ma_vendcode,' ') and pd_piclass in ('委外退料单','委外验退单','委外领料单') "
- + "and nvl(pd_ordercode,' ')<>' ' and not exists (select 1 from makecraft where mc_code=pd_jobcode and mc_tasktype='工序委外单')",
- String.class, pi_id);
- if (dets != null) {
- return "明细委外单委外商与单据委外商不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail where nvl(pd_jobcode,' ')<>' ' and not exists (select 1 from makecraft where pd_jobcode=mc_code "
- + "and mc_tasktype='工序委外单') and pd_piclass in ('委外退料单','委外验退单','委外领料单') and pd_piid=?", String.class,
- pi_id);
- if (dets != null) {
- return "明细工序委外单不存在,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join makecraft on mc_code=pd_jobcode where "
- + "pd_piid=? and nvl(pi_cardcode,' ')<>nvl(mc_vendcode,' ') and pd_piclass in ('委外退料单','委外验退单','委外领料单') "
- + "and nvl(pd_ordercode,' ')<>' ' and exists (select 1 from makecraft where mc_code=pd_jobcode and mc_tasktype='工序委外单') ",
- String.class, pi_id);
- if (dets != null) {
- return "委外商与工序委外单委外商不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 ",
- String.class, pi_id);
- if (dets != null) {
- return "拆件入库数不能大于工单允许可拆件入库数!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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'",
- String.class, pi_id);
- if (dets != null) {
- return "拆件单明细中存在制造单的类型是标准!" + dets;
- }
- boolean allowBackAfterFinish = false;
- if ("ProdInOut!Make!Return".equals(caller)) { // @add xst 20180830
- // 反馈:2018080651
- // ,制造单已结案允许退料
- allowBackAfterFinish = baseDao.isDBSetting("Make!Base", "allowBackAfterFinish");
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 "
- + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(mk_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(mk_whcodes,'#'))) "
- + "and pd_piclass in ('完工入库单','委外验收单') and nvl(pd_ordercode,' ')<>' ' and nvl(ProdIODetail.pd_status,0)=0",
- String.class, pi_id);
- if (dets != null) {
- return "明细仓库与工单类型允许入库仓库不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if ("ProdInOut!OutesideCheckReturn".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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) "
- + "and not exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单' and pd_prodcode=mc_prodcode)",
- String.class, pi_id);
- if (dets != null) {
- return "委外单+物料编号不存在,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')"
- + " and not exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单')"
- + " and pd_piclass in ('委外验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细委外单与单据币别不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao.getJdbcTemplate().queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join Prodinout on pd_piid=pi_id left join MakeCraft on mc_makecode=pd_ordercode "
- + " and mc_code =pd_jobcode where pd_piid=? and nvl(pi_currency,' ')<>nvl(mc_currency,' ')"
- + " and exists (select 1 from makecraft where pd_jobcode=mc_code and mc_tasktype='工序委外单')"
- + " and pd_piclass in ('委外验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细委外单与单据币别不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller) || "ProdInOut!DefectIn".equals(caller)
- || "ProdInOut!DefectOut".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "单据中供应商编号,供应商名称在供应商资料中不存在!";
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "单据中应付供应商编号,应付供应商名称在供应商资料中不存在!";
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=?"
- + " 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)",
- String.class, pi_id);
- if (dets != null) {
- return "采购单号+采购序号不存在,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=?"
- + " 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,' ')<>' ' ",
- String.class, pi_id);
- if (dets != null) {
- Boolean bo = baseDao.isDBSetting("VerifyApply", "verifyApplyAllowPre"); // 允许收替代料
- if (bo) {
- SqlRowList rsReq = baseDao
- .queryForRowSet(
- "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 )",
- pi_id);
- if (!rsReq.hasNext()) {
- return "采购单号+采购序号不存在!";
- }
- while (rsReq.next()) {
- if (rsReq.getString("pd_repprodcode") != null && !("").equals(rsReq.getString("pd_repprodcode"))) {
- StringBuffer codes = new StringBuffer();
- String[] arr = rsReq.getString("pd_repprodcode").split(",");
- codes.append("'");
- for (int i = 0; i < arr.length; i++) {
- if (i < arr.length - 1) {
- codes.append(arr[i] + "','");
- } else {
- codes.append(arr[i] + "'");
- }
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- " select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and pd_ordercode ='"
- + rsReq.getString("pd_code")
- + "' and pd_orderdetno="
- + rsReq.getInt("pd_detno")
- + " 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 ("
- + codes + ")) ) and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' ' ",
- String.class, pi_id);
- if (dets != null) {
- return "采购单号+采购序号+物料不存在,不允许进行当前操作!行号:" + dets;
- }
- }
- }
- }
- if (dets != null) {
- return "采购单号+采购序号+物料不存在,不允许进行当前操作!行号:" + dets;
- }
- }
- dets = baseDao.getJdbcTemplate().queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on pd_ordercode=pd_code and pd_orderdetno=pd_detno where "
- + "pd_piid=? and nvl(pd_mrpstatuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('采购验收单','采购验退单') "
- + "and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "采购单明细已冻结或者已结案,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao.getJdbcTemplate().queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on pd_ordercode=pd_code and pd_orderdetno=pd_detno where "
- + "pd_piid=? and nvl(pd_mrpstatuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('不良品入库单','不良品出库单') "
- + "and nvl(pd_ordercode,' ')<>' ' and nvl(pd_qctype,' ')='采购检验单'", String.class, pi_id);
- if (dets != null) {
- return "采购单明细已冻结或者已结案,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao.getJdbcTemplate().queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join Make on pd_ordercode=ma_code where "
- + "pd_piid=? and nvl(ma_statuscode,' ') in ('FREEZE','FINISH') and pd_piclass in ('不良品入库单','不良品出库单') "
- + "and nvl(pd_ordercode,' ')<>' ' and nvl(pd_qctype,' ')='委外检验单'", String.class, pi_id);
- if (dets != null) {
- return "明细行委外单已冻结或者已结案,不允许进行当前操作!行号:" + dets;
- }
- if (!baseDao.isDBSetting(caller, "noLimitVendor")) {
- dets = baseDao.getJdbcTemplate().queryForObject(
- "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_cardcode,' ')<>nvl(pu_vendcode,' ') and pd_piclass in ('采购验收单','采购验退单') "
- + "and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细采购单与单据供应商不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if (!baseDao.isDBSetting(caller, "allowARCust")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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_receivecode,' ')<>nvl(pu_receivecode,' ') and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '",
- String.class, pi_id);
- if (dets != null) {
- return "明细采购单与单据应付供应商不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')"
- + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细采购单与单据币别不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 ('采购验收单')",
- String.class, pi_id);
- if (dets != null) {
- return "明细行入库数量大于收料合格数量!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 ('不良品入库单')",
- String.class, pi_id);
- if (dets != null) {
- return "明细行入库数量大于收料不合格数量!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 "
- + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(pk_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(pk_whcodes,'#'))) "
- + "and pd_piclass in ('采购验收单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细仓库与采购单类型允许入仓库不一致,不允许进行当前操作!行号:" + dets;
- }
- if ("ProdInOut!PurcCheckin".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail left join PurchaseDetail on PurchaseDetail.pd_code=ProdIODetail.pd_ordercode and PurchaseDetail.pd_detno=ProdIODetail.pd_orderdetno "
- + "where pd_piid=? and nvl(PurchaseDetail.pd_yqty,0)>nvl(PurchaseDetail.pd_qty,0)-nvl(PurchaseDetail.pd_frozenqty,0) "
- + "and pd_piclass in ('采购验收单') and nvl(ProdIODetail.pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细采购订单已转数大于采购订单数量-已冻结数量,不允许进行当前操作!行号:" + dets;
- }
- }
- }
- if ("ProdInOut!SaleBorrow".equals(caller) || "ProdInOut!OtherPurcIn".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 "
- + "where pd_piid=? and nvl(pd_whcode,' ')<>' ' and nvl(bt_whcodes,' ')<>' ' and pd_whcode not in (select column_value from table(parsestring(bt_whcodes,'#'))) "
- + "and pd_piclass in ('借货出货单','其它采购入库单')", String.class, pi_id);
- if (dets != null) {
- return "明细仓库与借货类型允许出入仓库不一致,不允许进行当前操作!" + dets;
- }
- }
- if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller) || "ProdInOut!OtherOut".equals(caller)
- || "ProdInOut!ExchangeOut".equals(caller) || "ProdInOut!SaleAppropriationOut".equals(caller)) {
- if (baseDao.isDBSetting(caller, "allowDifProd")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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')"
- + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
- String.class, pi_id);
- if (dets != null) {
- return "销售单号+销售序号不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
- }
- } else if (baseDao.isDBSetting(caller, "SaleWithProdRelation")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from ProdIODetail where pd_piid=? and "
- + "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)) "
- + "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,' ')))"
- + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
- String.class, pi_id);
- if (dets != null) {
- return "销售单号+销售序号+物料编号不存在或者状态不等于已审核,不允许进行当前操作!行号:" + dets;
- }
- } else {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 )"
- + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
- String.class, pi_id);
- if (dets != null) {
- return "销售单号+销售序号+物料编号不存在,不允许进行当前操作!行号:" + dets;
- }
- }
- if (baseDao.isDBSetting("sys","useMachineNo")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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",
- String.class, pi_id);
- if (dets != null) {
- return "单据+物料数量跟机器号数量不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if (!(baseDao.isDBSetting("ProdInOut!Sale", "custatus"))) {
- if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {// 客户挂起时,订单单价为0不限制出货
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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='挂起' and not exists (select 1 from prodiodetail left join saledetail on pd_ordercode=sd_code and pd_orderdetno=sd_detno"
- + " where pd_piid=pi_id and nvl(pd_ordercode,' ')<>' ' and nvl(sd_price,0)=0)", String.class,
- pi_id);
- if (dets != null) {
- return "客户资料状态为挂起,且订单单价不为0,不允许进行当前操作!客户号:" + dets;
- }
- } else {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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='挂起'",
- String.class, pi_id);
- if (dets != null) {
- return "客户资料状态为挂起,不允许进行当前操作!客户号:" + dets;
- }
- }
- }
- if (!baseDao.isDBSetting(caller, "allowARCust")) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')"
- + " and pd_piclass in ('出货单','销售退货单','其它出库单','换货出库单','销售拨出单') and nvl(pd_ordercode,' ')<>' ' and nvl(pd_ioid,0)=0",
- String.class, pi_id);
- if (dets != null) {
- return "明细销售单与单据客户不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')"
- + " and pd_piclass in ('出货单','销售退货单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细销售单与单据应收客户不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')"
- + " and pd_piclass in ('出货单','销售退货单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "明细销售单与单据币别不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "单据中客户编号,客户名称在客户资料中不存在!";
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "单据中应收客户编号,应收客户名称在客户资料中不存在!";
- }
- // 销售退货单:退货数量,如退货数量+其它未过账的退货单数量大于销售订单出货数
- /**
- * 需考虑状态
- */
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, pi_id);
- if (dets != null) {
- return "本次退货数+其它退货数合计大于订单的已发货数量,不允许进行当前操作!行号:" + dets;
- }
- if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!OtherOut".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' '",
- String.class, pi_id);
- if (dets != null) {
- return "明细行预测单号+预测序号不存在或者状态不等于已审核,不允许进行当前操作!!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' '",
- String.class, pi_id);
- if (dets != null) {
- return "明细行预测单号+预测序号预测数量等于0,不允许进行当前操作!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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",
- String.class, pi_id);
- if (dets != null) {
- return "明细行销售单号+销售序号数量大于订单未发货数,不允许进行当前操作!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' '",
- String.class, pi_id);
- if (dets != null) {
- return "预测单录入错误,该预测类型不属于发货冲销!" + dets;
- }
- }
- }
- // if ("ProdInOut!AppropriationOut".equals(caller) || "ProdInOut!AppropriationIn".equals(caller)
- // || "ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!SaleAppropriationIn".equals(caller)) {
- // dets = baseDao
- // .getJdbcTemplate()
- // .queryForObject(
- // "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)",
- // String.class, pi_id);
- // if (dets != null) {
- // return "有值和无值仓之间不能相互调拨!行号:" + dets);
- // }
- // }
- SqlRowList rs = baseDao.queryForRowSet("select * from prodiodetail where pd_piid=?", pi_id);
- StringBuffer sb = new StringBuffer();
- while (rs.next()) {
- int pdid = rs.getInt("pd_id");
- int ioid = rs.getGeneralInt("pd_ioid");
- double tqty = rs.getGeneralDouble("pd_inqty") + rs.getGeneralDouble("pd_outqty");
- double yqty = 0.0;
- if (ioid > 0) {
- yqty = baseDao.getSummaryByField("Prodiodetail", "nvl(pd_outqty,0) + nvl(pd_inqty,0)", "pd_ioid=" + ioid + " and pd_id<>"
- + pdid);
- Object[] source = baseDao.getFieldsDataByCondition("Prodiodetail", new String[] { "nvl(pd_outqty,0)", "nvl(pd_inqty,0)",
- "pd_piclass", "pd_inoutno" }, "pd_id=" + ioid);
- if (source != null) {
- if (yqty + tqty > Double.parseDouble(source[0].toString()) + Double.parseDouble(source[1].toString())) {
- sb.append("行号:" + rs.getInt("pd_pdno") + ",数量:" + tqty + ",无法转出." + source[2] + "[" + source[3] + "]已转数量:" + yqty
- + ",本次数量:" + tqty + "<hr/>");
- }
- }
- }
- }
- if (sb.length() > 0) {
- return sb.toString();
- }
- // 保税信息判断
- if (baseDao.isDBSetting("sys","ioWHBondedCheck")) {
- if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)"
- + " and pd_piclass in ('采购验收单','采购验退单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "采购单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if ("ProdInOut!OutesideCheckReturn".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)"
- + " and pd_piclass in ('委外验退单','委外验收单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "委外单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if ("ProdInOut!Make!In".equals(caller) || "ProdInOut!PartitionStockIn".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)"
- + " and pd_piclass in ('完工入库单','拆件入库单') and nvl(pd_ordercode,' ')<>' '", String.class, pi_id);
- if (dets != null) {
- return "工单的保税属性与仓库的保税属性不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- if ("ProdInOut!Make!Give".equals(caller) || "ProdInOut!Make!Return".equals(caller) || "ProdInOut!Picking".equals(caller)
- || "ProdInOut!OSMake!Give".equals(caller) || "ProdInOut!OutsideReturn".equals(caller)
- || "ProdInOut!OutsidePicking".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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"
- + " and pd_piclass in ('委外补料单','委外退料单','委外领料单') and nvl(pd_ordercode,' ')<>' '", String.class,
- pi_id);
- if (dets != null) {
- return "委外单保税属性是非保税,不能发生仓库保税属性是保税的单据!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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"
- + " and pd_piclass in ('生产补料单','生产退料单','生产领料单') and nvl(pd_ordercode,' ')<>' '", String.class,
- pi_id);
- if (dets != null) {
- return "工单保税属性是非保税,不能发生仓库保税属性是保税的单据!" + dets;
- }
- }
- if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!AppropriationOut".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)"
- + " and pd_piclass in ('拨出单','销售拨出单') and nvl(pd_whcode,' ')<>' ' and nvl(pd_inwhcode,' ')<>' '",
- String.class, pi_id);
- if (dets != null) {
- return "拨出仓库与拨入仓库仓库的保税属性不一致,不能进行当前操作!" + dets;
- }
- }
- }
- // @add20180605 Q:2018050126 最后一张完工入库单或者委外验收单,提交、审核、过账之前限制,不允许存在未过账
- // 领、退、补单据,未审核的报废单,未过账的委外验退单
- if (("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!Make!In".equals(caller))
- && baseDao.isDBSetting(caller, "checkRelBillsStatus")) {
- // 判断哪些工单是最后一张完工入库单
- rs = baseDao
- .queryForRowSet(
- "select pd_ordercode,pd_pdno from (select pd_ordercode,sum(pd_inqty)inqty,wm_concat(pd_pdno)pd_pdno from prodiodetail where "
- + "pd_piid=? and pd_piclass in('完工入库单','委外验收单') group by pd_ordercode) A left join make on ma_code=A.pd_ordercode "
- + "where nvl(ma_madeqty,0)+inqty>=ma_qty", pi_id);
- String errors = null;
- while (rs.next()) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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",
- String.class, pi_id, rs.getString("pd_ordercode"));
- if (dets != null) {
- errors = "行号:" + rs.getString("pd_pdno") + ",工单:" + rs.getString("pd_ordercode") + "存在关联未过账单据!" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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",
- String.class, rs.getString("pd_ordercode"));
- if (dets != null) {
- if (errors != null) {
- errors += "<br>未审核的报废单:" + dets;
- } else {
- errors = "行号:" + rs.getString("pd_pdno") + ",工单:" + rs.getString("pd_ordercode") + "存在关联未审核的报废单:" + dets;
- }
- }
- if (errors != null && !"".equals(errors)) {
- return errors;
- }
- }
- }
- if (baseDao.isOut(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' '"
- + "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)",
- String.class, pi_id);
- if (dets != null) {
- return "物料编号+仓库编号+批号不存在,不允许进行当前操作!行号:" + dets;
- }
- }
- return null;
- }
- /**
- * 校验批次是否重复
- *
- * @param caller
- * @param pi_id
- */
- private String checkBatch(String caller, Object pi_id) {
- if (baseDao.isIn(caller)) {
- // 入库单据,同一物料同仓库不能同时入两次相同的批号
- SqlRowList rs = baseDao
- .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="
- + pi_id + " and pd_batchcode<>' ' group by pd_batchcode,pd_whcode,pd_prodcode ) where c> 1");
- if (rs.next()) {
- if (rs.getInt("n") > 0) {
- return "同一物料同仓库不能同时入两次相同的批号!" + rs.getString("detno");
- }
- }
- rs = baseDao
- .queryForRowSet("select count(1) n,wm_concat(pd_piclass||'['||pd_inoutno||']行号['||pd_pdno||']')detno "
- + "from (select pd_piclass,pd_inoutno,pd_pdno from ProdIODetail where pd_piid="
- + pi_id
- + " and pd_batchcode is not null and exists (select 1 from batch where ba_code=pd_batchcode and ba_prodcode=pd_prodcode "
- + "and ba_whcode=pd_whcode and (nvl(ba_remain,0)<>0 or nvl(ba_inqty,0)<>0))) where rownum<30");
- if (rs.next()) {
- if (rs.getInt("n") > 0) {
- return "批号已存在,不能重复入库!" + rs.getString("detno");
- }
- }
- }
- return null;
- }
- private String copcheck(int pi_id, String caller) {
- if (baseDao.isDBSetting("sys","CopCheck")) {
- // 出入库单:明细行采购单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
- String dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + " and pd_piclass in ('采购验收单','采购验退单')", String.class, pi_id);
- if (dets != null) {
- return "明细行采购单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- // 出入库单:明细行销售单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + "and pd_piclass in ('出货单','销售退货单','销售拨出单','销售拨入单')", String.class, pi_id);
- if (dets != null) {
- return "明细行销售单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- // 出货单:来源单所属公司与当前单所属公司不一致,不允许进行当前操作
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 ",
- String.class, pi_id);
- if (dets != null) {
- return "明细来源通知单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- // 出入库单:明细行制造单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + "and pd_piclass in ('生产领料单','生产退料单','生产补料单','完工入库单','拆件入库单')", String.class, pi_id);
- if (dets != null) {
- return "明细行制造单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- // 出入库单:明细行委外单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + "and pd_piclass in ('委外验收单','委外验退单','委外领料单','委外退料单','委外补料单')", String.class, pi_id);
- if (dets != null) {
- return "明细行委外单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- if ("ProdInOut!SaleAppropriationOut".equals(caller) || "ProdInOut!OtherOut".equals(caller)
- || "ProdInOut!AppropriationOut".equals(caller)) {
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + "and pd_piclass in ('销售拨出单','其它出库单')", String.class, pi_id);
- if (dets != null) {
- return "明细行销售预测单所属公司与当前单所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')",
- String.class, pi_id);
- if (dets != null) {
- return "单据所属公司和明细行拨入仓库的所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- // 出入库单限制界面的所属公司和仓库的所属公司必须一致,可在提交、打印、审核、过账等操作前配置
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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 ('成本调整单')",
- String.class, pi_id);
- if (dets != null) {
- return "单据所属公司和明细行仓库的所属公司不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- return null;
- }
- private String factorycheck(int pi_id, String caller) {
- if (baseDao.isDBSetting("MpsDesk", "mrpSeparateFactory")) {
- // 采购验收单、采购验退单:明细行采购单所属工厂与仓库的所属工厂不一致,,不允许进行当前操作
- String dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + " and PurchaseDetail.pd_factory is not null and pd_piclass in ('采购验收单','采购验退单')", String.class,
- pi_id);
- if (dets != null) {
- return "明细行采购单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
- }
- // 生产领料单、退料单、补料单:明细行制造单所属工厂与仓库的所属工厂不一致,不允许进行当前操作
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + "and pd_piclass in ('生产领料单','生产退料单','生产补料单')", String.class, pi_id);
- if (dets != null) {
- return "明细行制造单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
- }
- // 委外领料单、退料单、补料单:明细行委外单所属工厂与仓库的所属工厂不一致,不允许进行当前操作
- dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ')<>' ' "
- + "and pd_piclass in ('委外领料单','委外退料单','委外补料单')", String.class, pi_id);
- if (dets != null) {
- return "明细行委外单所属工厂与仓库的所属工厂不一致,不允许进行当前操作!行号:" + dets;
- }
- }
- return null;
- }
- private String checkIOMaPick(String caller, Object pi_id) {
- String[] checkCallers={"ProdInOut!AppropriationOut","ProdInOut!Picking", "ProdInOut!OutsidePicking","ProdInOut!Make!Give","ProdInOut!OSMake!Give"
- ,"ProdInOut!OtherOut","ProdInOut!SaleBorrow"};
- if(Arrays.asList(checkCallers).contains(caller)){
- String gridStore = "[]";
- String formStore = null;
- SqlRowList fromP = baseDao.queryForRowSet("select pi_id,pi_class,TO_CHAR(pi_date,'YYYYMM') pi_date from prodinout where pi_id = "+pi_id+" ");
- if(fromP.next()){
- formStore = BaseUtil.parseMap2Str(baseDao.changeKeyToLowerCase(fromP.getCurrentMap()));
- SqlRowList checkDetail = baseDao.queryForRowSet("select pd_ordercode macode, pd_prodcode prodcode,pd_outqty outqty,pd_whcode outwhcode,pd_inwhcode inwhcode" +
- " from prodiodetail where pd_piid = "+pi_id+" order by pd_pdno");
- if(checkDetail.hasNext()){
- gridStore = BaseUtil.parseGridStore2Str(baseDao.changeKeyToLowerCase(checkDetail.getResultList()));
- }
- String res = baseDao.callProcedure("USER_CHECKOUTSTOCK", new Object[] {formStore,gridStore});
- if (res != null && res.length() > 0) {
- return res;
- }
- }
- }
- return null;
- }
- /**
- * 新增生产退料和委外退料判断,替代料退料数量不能大于替代料已领数量,主料退料不能大于主料已领数,工单外退料的情况不限制
- *
- * @date 2016年10月17日 下午12:30:58
- * @param pi_id
- * 单据id
- */
- private String checkRepQty(int pi_id) {
- SqlRowList rs = baseDao
- .queryForRowSet(
- "select wm_concat(T.pdno) no from (select nvl(sum(pd_inqty),0) inqty,pd_ordercode,pd_orderdetno,pd_prodcode,max(pd_pdno)pdno "
- + " from prodiodetail where pd_piid=? group by pd_ordercode,pd_orderdetno,pd_prodcode )T "
- + " left join makematerial on mm_code=T.pd_ordercode and mm_detno=T.pd_orderdetno "
- + " 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",
- pi_id);
- if (rs.next() && rs.getObject("no") != null) {
- return "主料退料数不允许大于主料已领数,行号:" + rs.getString(1);
- }
- rs = baseDao
- .queryForRowSet(
- "select wm_concat(T.pdno) no from (select nvl(sum(pd_inqty),0) inqty,pd_ordercode,pd_orderdetno,pd_prodcode,max(pd_pdno)pdno "
- + " from prodiodetail where pd_piid=? group by pd_ordercode,pd_orderdetno,pd_prodcode )T "
- + " 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"
- + " 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",
- pi_id);
- if (rs.next() && rs.getObject("no") != null) {
- return "替代料退料数不允许大于替代已领数,行号:" + rs.getString(1);
- }
- return null;
- }
- private String checkMmBackOver(String caller, int pi_id) {
- //截止到退料单单据日期月份的 本单的退料不允许大于 已过账的 领料出库-退料数+补料数-(完工-验退数)*单位用量
- String data = baseDao.getJdbcTemplate().queryForObject("select wm_concat('工单:'||pd_ordercode||',序号:'||pd_orderdetno ||'<br>') " +
- " 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 " +
- " LEFT JOIN MAKEMATERIAL ON MM_MAID=MA_ID and pd_orderdetno=mm_detno where " +
- " 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 " +
- " a.pd_ordercode=b.pd_ordercode and a.pd_orderdetno=b.pd_orderdetno and pi_class in('生产领料单','委外领料单','生产退料单','委外退料单','生产补料单','委外补料单')),0) " +
- " - 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) " +
- " -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 " +
- " a.pd_ordercode=b.pd_ordercode AND pi_class in('完工入库单','委外验退单','委外验收单')),0)*nvl(mm_oneuseqty,0) and rownum<10",String.class,pi_id);
- if(data != null){
- return "退料数大于截止到单据月份剩余的结存数,"+data;
- }
- return null;
- }
- /**
- * 计算pi_total
- */
- private void getTotal(Object pi_id, String caller) {
- baseDao.execute("update prodiodetail set pd_purcinqty=nvl(pd_inqty,0) where pd_piid=" + pi_id
- + " and exists (select 1 from product where pd_prodcode=pr_code and nvl(pr_purcunit,pr_unit)=pr_unit) ");
- baseDao.execute("update prodiodetail set pd_purcoutqty=nvl(pd_outqty,0) where pd_piid=" + pi_id
- + " and exists (select 1 from product where pd_prodcode=pr_code and nvl(pr_purcunit,pr_unit)=pr_unit)");
- 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="
- + pi_id + " and nvl(pd_purcinqty,0)=0");
- if ("ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!PurcCheckout".equals(caller) || "ProdInOut!OutsideCheckIn".equals(caller)
- || "ProdInOut!OutesideCheckReturn".equals(caller)) {
- if ("ProdInOut!OutsideCheckIn".equals(caller) || "ProdInOut!OutesideCheckReturn".equals(caller)) {// 委外
- baseDao.updateByCondition("ProdIODetail", "pd_orderprice=(select ma_price from make where ma_code=pd_ordercode)",
- "pd_piid=" + pi_id + " and nvl(pd_orderprice,0)=0");
- // 强制取委外单主表中的税率
- baseDao.execute(
- "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=?",
- pi_id);
- } else {// 采购
- baseDao.updateByCondition("ProdIODetail",
- "pd_orderprice=nvl((select pd_price from PurchaseDetail where pd_code=pd_ordercode and pd_detno=pd_orderdetno),0)",
- "pd_piid=" + pi_id + " and nvl(pd_orderprice,0)=0 and nvl(pd_status,0)<>99");
- // 强制取采购单明细表中的对应的税率
- baseDao.execute(
- "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=?",
- pi_id);
- }
- 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="
- + pi_id);
- 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="
- + pi_id);
- baseDao.updateByCondition("ProdIODetail", " pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)", "pd_piid="
- + pi_id);
- baseDao.updateByCondition("ProdInOut",
- "pi_total = round(nvl((SELECT sum(round(pd_ordertotal,2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
- + pi_id);
- baseDao.updateByCondition(
- "ProdIODetail",
- "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)",
- "pd_piid=" + pi_id);
- baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
- } else if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller)) {
- baseDao.updateByCondition(
- "ProdIODetail",
- "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)",
- "pd_piid=" + pi_id);
- baseDao.updateByCondition(
- "ProdIODetail",
- "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)",
- "pd_piid=" + pi_id);
- baseDao.updateByCondition("ProdInOut",
- "pi_total=round(nvl((SELECT sum(round(pd_ordertotal,2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id=" + pi_id);
- baseDao.execute("update prodiodetail set pd_customprice=pd_sendprice, pd_taxamount=pd_ordertotal "
- + "where pd_piclass in ('出货单','销售退货单') and pd_piid=? and nvl(pd_customprice,0)=0", pi_id);
- baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
- // 成品标准成本,用于报价毛利润统计
- baseDao.execute("UPDATE product set pr_cost=nvl((select price from ( select qd_prodcode,round(qd_factprice*qu_rate,2) price,"
- + " row_number() over(partition by qd_prodcode order by qu_auditdate desc) rn from quotation,quotationdetail "
- + "where qu_id=qd_quid and qu_statuscode='AUDITED') t1 where rn=1 and qd_prodcode=pr_code),0) "
- + "where nvl(pr_cost,0)=0 and pr_code in (select pd_prodcode from prodiodetail where pd_piid=?)", pi_id);
- baseDao.execute("UPDATE prodiodetail SET pd_showprice=nvl((select pr_cost from product where pd_prodcode=pr_code),0)"
- + "WHERE pd_piid=?", pi_id);
- } else {
- baseDao.updateByCondition("ProdIODetail", "pd_total=round(nvl(pd_price,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2)", "pd_piid="
- + pi_id);
- baseDao.updateByCondition(
- "ProdInOut",
- "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)",
- "pi_id=" + pi_id);
- baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
- }
- if ("ProdInOut!Sale".equals(caller) || "ProdInOut!SaleReturn".equals(caller) || "ProdInOut!AppropriationOut".equals(caller)
- || "ProdInOut!OtherOut".equals(caller) || "ProdInOut!ExchangeOut".equals(caller)) {
- Object cardcode = baseDao.getFieldDataByCondition("ProdInOut", "pi_cardcode", "pi_id=" + pi_id);
- 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='"
- + cardcode
- + "' and pd_prodcode=pr_code) where pd_piid="
- + pi_id
- + " and nvl(pd_custprodcode,' ')=' ' and nvl(pd_custprodspec,' ')=' ' and pd_piclass in ('销售退货单', '出货单', '其它出库单', '拨出单', '换货出库单')");
- 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="
- + pi_id);
- }
- if ("ProdInOut!CostChange".equals(caller)) {
- baseDao.execute(
- "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=?",
- pi_id);
- }
- // 入库类单据:如果pd_location为空,默认等于物料资料里的仓位pr_location
- if (baseDao.isIn(caller)) {
- baseDao.execute(
- "update prodiodetail set pd_location=(select pr_location from product where pr_code=pd_prodcode) where pd_piid=? and nvl(pd_location,' ')=' '",
- pi_id);
- }
- baseDao.updateByCondition("ProdInOut",
- "pi_total = round(nvl((SELECT sum(round(nvl(pd_ordertotal,0),2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
- + pi_id);
- baseDao.updateByCondition("ProdInOut",
- "pi_nettotal = round(nvl((SELECT sum(round(nvl(pd_nettotal,0),2)) FROM ProdIODetail WHERE pd_piid=pi_id),0),2)", "pi_id="
- + pi_id);
- }
- /**
- * 计算pi_qtytotal
- */
- private void getQtyTotal(Object pi_id, String caller) {
- if ("ProdInOut!Sale".equals(caller) || "ProdInOut!PurcCheckin".equals(caller) || "ProdInOut!OtherOut".equals(caller)) {
- baseDao.execute("update ProdInOut set pi_qtytotal=nvl((select sum(nvl(pd_outqty,0)+nvl(pd_inqty,0)) from ProdIODetail where "
- + "ProdIODetail.pd_piid = ProdInOut.pi_id),0) where pi_id=" + pi_id);
- }
- }
- // @add 20170524 出库类型的单据,保存,更新,获取批号之后更新备料状态
- private void updatePdaStatus(String caller, Object pi_id) {
- Boolean bo = baseDao.isDBSetting("BarCodeSetting", "BarRelevancyBatch");
- Boolean AutoPickBarcode = baseDao.isDBSetting("BarCodeSetting", "autoPickBarcode");
- if (!AutoPickBarcode) {
- if (!bo) {
- if (baseDao.isOut(caller)) { // 出库类型
- // 如果所有的明细都没有条码则更新为空
- SqlRowList rs = baseDao.queryForRowSet(
- "select count(1)cn from prodiodetail where pd_piid=? and nvl(pd_batchcode,' ')<>' '", pi_id);
- if (rs.next() && rs.getInt("cn") == 0) {
- baseDao.execute("update prodinout set pi_pdastatus='' where pi_id=? and nvl(pi_pdastatus,' ')<>' '", pi_id);
- } else {
- rs = baseDao.queryForRowSet("select count(1)cn from barcodeio where bi_piid=? and bi_outqty>0", pi_id);
- if (rs.next() && rs.getInt("cn") > 0) { // 有一行以上备料记录则是备料中
- baseDao.execute("update prodinout set pi_pdastatus ='备料中' where pi_id=?", pi_id);
- rs = baseDao
- .queryForRowSet(
- "select count(1) cn from (select pd_prodcode,pd_whcode,sum(pd_outqty)qty from prodiodetail left join batch on pd_batchid=ba_id "
- + " 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 "
- + " 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)",
- pi_id, pi_id);
- if (rs.next() && rs.getInt("cn") == 0) {
- baseDao.execute("update prodinout set pi_pdastatus ='已备料' where pi_id=?", pi_id);
- }
- } else {
- // --存在有条码的批号则更新成未备料
- baseDao.execute(
- "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)",
- pi_id, pi_id);
- // --所有批号都无条码则更新成无条码
- baseDao.execute(
- "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)",
- pi_id, pi_id);
- }
- }
- }
- }
- }
- }
- /**
- * 检查批号是否存在,批号数量是否足够
- */
- private String checkBatchRemain(Object pi_id) {
- int count = baseDao.getCount("select count(1) from documentsetup where ds_name=(select pi_class from prodinout " + "where pi_id="
- + pi_id + ") and (ds_inorout = '-IN' or ds_inorout = 'OUT')");
- if (count > 0) {
- String pdnos1 = baseDao.getJdbcTemplate().queryForObject(
- "select WMSYS.WM_CONCAT(pd_pdno) from (select pd_pdno from prodiodetail left join batch on"
- + " pd_batchcode=ba_code and ba_whcode = pd_whcode and ba_prodcode = pd_prodcode "
- + "where pd_piid=? and ba_code is null order by pd_pdno) where rownum<20", String.class, pi_id);
- String pdnos2 = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select WMSYS.WM_CONCAT(pd_pdno) from (select WMSYS.WM_CONCAT(pd_pdno) pd_pdno,max(pd_batchcode),"
- + "sum(pd_outqty),max(ba_remain),max(ba_code) from prodiodetail left join batch on pd_batchcode=ba_code and "
- + "ba_whcode = pd_whcode and ba_prodcode = pd_prodcode where pd_piid=? group by pd_batchcode,pd_prodcode,pd_whcode"
- + " having sum(pd_outqty)>max(ba_remain) ) where rownum<20", String.class, pi_id);
- if (pdnos1 != null || pdnos2 != null) {
- String error1 = pdnos1 == null ? "" : "找不到您所指的批号,请修改批号或点击【重置批号】再过账!行号是:" + pdnos1 + "<br>";
- String error2 = pdnos2 == null ? "" : "批号的库存数小于出库数量,请修改批号或点击【重置批号】再过账!行号是:" + pdnos2 + "<br>";
- return error1 + error2;
- }
- }
- return null;
- }
- /**
- * 产生冲销单并审核 发货单过账/销售单审核 scm->prodinout->post->after scm->sale->audit->after
- *
- * @author ZhongYL
- */
- @Transactional
- public void createSaleClash(Integer fromid, String fromcaller,Employee employee) {
- String SqlStr = "", clashcode = "", canclash = "", othercondition = "";
- double thisqty = 0, needclashqty = 0, clashedqty = 0;
- int csid = 0, detno = 0;
- String prodcode = "", ordercode = "", fromcode = "", fromwhere = "";
- String clashoption = "", saleclashkind = "";
- SqlRowList rs0;
- if (fromcaller.equalsIgnoreCase("ProdInOut")) {
- fromwhere = baseDao.getFieldDataByCondition("ProdInOut", "pi_class", "pi_id=" + fromid).toString();
- } else if (fromcaller.equalsIgnoreCase("Sale") || fromcaller.equals("销售单")) {
- fromwhere = "销售单";
- } else {
- return;
- }
- // 先更新呆冲销的明细已冲销数为0
- 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) ";
- baseDao.execute(SqlStr);
- // 获取冲销来源单据
- if (fromwhere.equals("出货单")) {
- 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='"
- + fromid + "' ";
- } else if (fromwhere.equals("销售单")) {
- 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='"
- + fromid + "' ";
- } else if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单")) {
- 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='"
- + fromid
- + "' 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 ";
- // 判断是否存在需要完工入库冲销的预测
- rs0 = baseDao.queryForRowSet("select sf_code from saleforecastkind where sf_clashoption='完工冲销' or sf_clashoption='FINISH' ");
- if (!rs0.hasNext()) {
- // 不需要完工冲销
- return;
- }
- } else if (fromwhere.equals("销售拨出单")) {
- 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='"
- + fromid + "' and NVL(pd_plancode,' ')<>' ' and pd_forecastdetno>0 ";
- } else if (fromwhere.equals("其它出库单")) {
- 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='"
- + fromid + "' and NVL(pd_plancode,' ')<>' ' and pd_forecastdetno>0 ";
- } else {
- return;
- }
- detno = 1;
- SqlRowList rs = baseDao.queryForRowSet(SqlStr);
- while (rs.next()) {
- fromcode = rs.getString("fromcode");
- clashoption = "";
- saleclashkind = "";
- othercondition = "";
- clashedqty = 0;
- needclashqty = rs.getDouble("qty");
- prodcode = rs.getString("prodcode");
- ordercode = rs.getString("ordercode");
- // 判断此行记录是否需要冲销
- canclash = "N";
- if (fromwhere.equals("销售单") || fromwhere.equals("出货单")) {
- if(fromwhere.equals("出货单") && baseDao.isDBSetting("ProdInOut!Sale", "clashSaleForecastByProduct")){
- saleclashkind="PRODUCT";
- clashoption = "SEND";
- }else{
- SqlStr = "SELECT * from sale left join salekind on (sa_kind=sk_name or sa_kind=sk_code) where sa_code='" + ordercode + "' ";
- SqlRowList rs2 = baseDao.queryForRowSet(SqlStr);
- if (rs2.next()) {
- saleclashkind = rs2.getString("sk_clashfor");
- clashoption = rs2.getString("sk_clashoption");
- othercondition = rs2.getString("sk_clashkind");
- } else {
- // 未设置类型,不冲销
- continue;
- }
- }
- } else if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单")) {
- saleclashkind = "PRODUCT";
- clashoption = "FINISH";
- } else if (fromwhere.equals("销售拨出单") || fromwhere.equals("其它出库单")) {
- saleclashkind = "单号冲销";
- clashoption = "SEND";
- }
- if (saleclashkind == null || clashoption == null) {
- // 未设置类型,不冲销
- continue;
- }
- if (fromwhere.equals("销售单")) {
- if (clashoption.equals("订单冲销") || clashoption.equalsIgnoreCase("SALE")) {
- canclash = "Y";
- }
- } else if (fromwhere.equals("出货单")) {
- if (clashoption.equals("发货冲销") || clashoption.equalsIgnoreCase("SEND")) {
- canclash = "Y";
- }
- }
- if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单") || fromwhere.equals("委外验退单") || fromwhere.equals("销售拨出单")
- || fromwhere.equals("其它出库单")) {
- canclash = "Y";
- }
- if (canclash.equals("N")) {
- // 不冲销
- continue;
- }
- SqlStr = "";
- if (saleclashkind.equalsIgnoreCase("sale") || saleclashkind.equals("单号冲销")) {
- 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='"
- + rs.getString("sfcode") + "' and sd_detno=" + rs.getInt("sfdetno");
- } else if (saleclashkind.equalsIgnoreCase("product") || saleclashkind.equals("料号冲销")) {
- // 按物料号冲销
- 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='"
- + prodcode + "' ";
- if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单")) {
- SqlStr = "SELECT case when saleforecast.sf_code='"
- + rs.getString("ma_salecode")
- + "' and sd_detno="
- + rs.getInt("ma_saledetno")
- + " 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='"
- + prodcode + "' ";
- }
- if (fromwhere.equals("销售单") && othercondition != null && othercondition.equals("客户匹配")) {
- SqlStr = SqlStr + " and (case when NVL(saleforecastDetail.sd_custcode,' ')<>' ' then saleforecastDetail.sd_custcode else sf_custcode end)='" + rs.getString("sa_custcode") + "' ";
- } else if (fromwhere.equals("销售单") && othercondition != null && othercondition.equals("业务员")){
- SqlStr = SqlStr + " and (case when nvl(saleforecastDetail.sd_sellercode,' ')<>' ' then saleforecastDetail.sd_sellercode else sf_sellercode end)='"+ rs.getString("sa_sellercode")+"' ";
- }
- } else {
- // 不冲销
- continue;
- }
- if (clashoption.equals("订单冲销") || clashoption.equalsIgnoreCase("SALE")) {
- SqlStr = SqlStr + " and sf_clashoption in ('SALE','订单冲销') ";
- } else if (clashoption.equals("发货冲销") || clashoption.equalsIgnoreCase("SEND")) {
- SqlStr = SqlStr + " and sf_clashoption in ('SEND','发货冲销') ";
- } else if (clashoption.equals("完工冲销") || clashoption.equalsIgnoreCase("FINISH")) {
- SqlStr = SqlStr + " and sf_clashoption in ('FINISH','完工冲销') ";
- }
- if (saleclashkind.equalsIgnoreCase("product") || saleclashkind.equals("料号冲销")) {
- SqlStr = SqlStr + " and trunc(sd_enddate)>=trunc(sysdate) ";// 只冲销有效的预测,@update 20170224 截止日期等于今日的也可冲销,与存储过程中的计算一致
- }
- if (fromwhere.equals("委外验退单")) {
- 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='"
- + rs.getString("ordercode")
- + "' and scd_clashqty>0 and scd_clashqty-NVL(scd_cancelqty,0)>0 and sc_statuscode='AUDITED' and sd_clashsaleqty>0 ";
- }
- if (fromwhere.equals("完工入库单") || fromwhere.equals("委外验收单")) {
- if (baseDao.isDBSetting("SaleForecast", "mappingSaleForecast")) {
- SqlStr = SqlStr
- + " and saleforecast.sf_code='"
- + rs.getString("ma_salecode")
- + "' and saleforecastdetail.sd_detno="
- + rs.getInt("ma_saledetno")
- + " and saleforecast.sf_statuscode='AUDITED' and sd_qty-nvl(sd_stepqty,0)>0 order by sortid,sd_needdate asc,sd_detno asc";
- } else {
- SqlStr = SqlStr
- + " and saleforecast.sf_statuscode='AUDITED' and sd_qty-nvl(sd_stepqty,0)>0 order by sortid,sd_needdate asc,sd_detno asc";
- }
- } else if (fromwhere.equals("委外验退单")) {
- // 委外验退条件特殊,上面已加
- } else {
- SqlStr = SqlStr
- + " 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";
- }
- if ("Y".equals(canclash) && !SqlStr.equals("")) {
- SqlRowList rs2 = baseDao.queryForRowSet(SqlStr);
- while (rs2.next() && clashedqty < needclashqty) {
- double remain = rs2.getDouble("sd_qty") - rs2.getDouble("sd_stepqty");
- int cancelsourceid = 0;
- if (fromwhere.equals("委外验退单")) {
- remain = (rs2.getDouble("scd_clashqty") - rs2.getDouble("scd_cancelqty"));// 拿冲销数反冲减预测
- cancelsourceid = rs2.getInt("scd_id");
- if (remain <= 0) {
- continue;
- }
- }
- thisqty = remain > needclashqty - clashedqty ? needclashqty - clashedqty : remain;
- if (clashcode == "") {
- clashcode = baseDao.sGetMaxNumber("SaleClash", 2);
- csid = baseDao.getSeqId("SALECLASH_SEQ");
- SqlStr = "insert into SaleClash(sc_id,sc_code,sc_date,sc_status,sc_statuscode,sc_recorder,sc_source,sc_sourceid,sc_sourcecode)values("
- + csid
- + ",'"
- + clashcode
- + "',sysdate,'已提交','COMMITED','"+employee.getEm_name()+"','" + fromwhere + "'," + fromid + ",'" + fromcode+ "') ";
- baseDao.execute(SqlStr);
- }
- 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("
- + "SALECLASHDETAIL_SEQ.NEXTVAL,"
- + csid
- + ",'"
- + detno
- + "','"
- + prodcode
- + "','"
- + thisqty
- + "','"
- + rs2.getString("sf_code")
- + "','"
- + rs2.getInt("sd_detno")
- + "',"
- + rs.getInt("sourcedetid")
- + ",'"
- + rs.getString("ordercode") + "'," + cancelsourceid + ")";
- baseDao.execute(SqlStr);
- if (fromwhere.equals("委外验退单")) {
- SqlStr = "UPDATE SaleClashDetail set scd_cancelqty=nvl(scd_cancelqty,0)+" + thisqty + " where scd_id="
- + rs2.getInt("scd_id") + " ";
- baseDao.execute(SqlStr);
- }
- SqlStr = "UPDATE saleforecastDetail set sd_stepqty=nvl(sd_stepqty,0)+(" + thisqty + ") where sd_id="
- + rs2.getInt("sd_id") + " ";
- baseDao.execute(SqlStr);
- detno = detno + 1;
- clashedqty = clashedqty + thisqty;
- }
- }
- }
- if (fromwhere.equals("委外验退单") && csid > 0) {
- SqlStr = "UPDATE SaleClashDetail set scd_clashqty=0-scd_clashqty where scd_scid=" + csid + " ";
- baseDao.execute(SqlStr);
- }
- if (!"".equals(clashcode)) {
- // 审核冲销单
- auditSaleClash(csid, "SaleClash",employee);
- }
- }
- public String auditSaleClash(int sc_id, String caller,Employee employee) {
- // 只能对状态为[已提交]的订单进行审核操作!
- Object status = baseDao.getFieldDataByCondition("SaleClash", "sc_statuscode", "sc_id=" + sc_id);
- if (!"AUDITED".equals(StringUtil.nvl(status, ""))){
- return "只能对已提交的单据进行审核!";
- }
- String dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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=?))",
- String.class, sc_id);
- if (dets != null) {
- return "预测单号+预测行号状态不等于已审核,不允许已审核!" + dets;
- }
- // 执行审核操作
- baseDao.audit("SaleClash", "sc_id=" + sc_id, "sc_status", "sc_statuscode", "sc_auditdate", "sc_auditman",employee);
- Object source = baseDao.getFieldDataByCondition("SaleClash", "sc_source", "sc_id=" + sc_id);
- // 冲销数量记录在预测单中
- SqlRowList rs = baseDao
- .queryForRowSet(
- "select scd_ordercode,scd_orderdetno,sum(scd_clashqty) scd_clashqty from SaleClashDetail where scd_scid=? group by scd_ordercode,scd_orderdetno",
- sc_id);
- while (rs.next()) {
- baseDao.updateByCondition("SaleForecastDetail", "sd_qty=sd_qty-(" + rs.getDouble("scd_clashqty")
- + "),sd_clashsaleqty=nvl(sd_clashsaleqty,0)+" + rs.getDouble("scd_clashqty"), "sd_detno=" + rs.getInt("scd_orderdetno")
- + " AND sd_sfid=(SELECT sf_id FROM SaleForecast WHERE sf_code='" + rs.getString("scd_ordercode") + "')");
- if (source != null && source.equals("销售单") && rs.getGeneralDouble("scd_clashqty") > 0) {
- baseDao.updateByCondition("SaleForecastDetail", "sd_yqty=(case when NVL(sd_yqty,0)-(" + rs.getDouble("scd_clashqty")
- + ")<0 then 0 else sd_yqty-(" + rs.getDouble("scd_clashqty") + ") end)", "sd_detno=" + rs.getInt("scd_orderdetno")
- + " AND sd_sfid=(SELECT sf_id FROM SaleForecast WHERE sf_code='" + rs.getString("scd_ordercode") + "')");
- }
- }
- return null;
- }
- /*
- * 拨出单过账后过账拨入单
- */
- public String turnProdIO(int id,Employee employee) {
- String dets = null;
- SqlRowList rs = baseDao.queryForRowSet("select pi_relativeplace,pi_class from prodinout where pi_id=?", id);
- if (rs.next()) {
- SqlRowList rs1 = baseDao.queryForRowSet(
- "select pi_id from prodinout where pi_inoutno=? and pi_class in ('拨入单','销售拨入单') and nvl(PI_UNAUTOPOSTIN,0)=0",
- rs.getString("pi_relativeplace"));
- if (rs1.next()) {
- if (baseDao.isDBSetting("sys","cgyCheck")) {
- /**
- * maz
- * 出入库单判断过账人是否在明细行仓库的仓管员资料表中存在,人员资料中查找管理员一样限制如果为非仓库员不允许过账
- * 虚拟账号不限制 2017080135
- */
- Object type = baseDao.getFieldDataByCondition("Employee", "em_code",
- "em_code='"+employee.getEm_code()+"'");
- if (type != null) {
- dets = baseDao.getJdbcTemplate()
- .queryForObject(
- "select wm_concat(pd_pdno) from prodinout,prodiodetail where pi_id=pd_piid and pi_id=? and pd_id not in "
- + "(select pd_id from prodinout,prodiodetail,warehouse,warehouseman where pi_id=pd_piid and pd_whcode=wh_code and wh_id=wm_whid "
- + "and pi_id=? and wm_cgycode=?)", String.class, rs1.getInt("pi_id"),
- rs1.getInt("pi_id"), employee.getEm_code());
- }
- }
- if (dets == null) {
- if ("拨出单".equals(rs.getString("pi_class"))) {
- postProdInOut(rs1.getInt("pi_id"), "ProdInOut!AppropriationIn",employee);
- } else if ("销售拨出单".equals(rs.getString("pi_class"))) {
- postProdInOut(rs1.getInt("pi_id"), "ProdInOut!SaleAppropriationIn",employee);
- }
- }
- }
- }
- return dets;
- }
- /**
- * @author XiaoST 2016年8月25日 下午7:18:45 更新工单的完工状态,在完工入库,委外验收,验退过账,反过账时调用
- */
- public void updateMakeFinishStatus(Integer ma_id) {
- baseDao.execute("update make set ma_madeqty=nvl((select sum(pd_inqty-pd_outqty) from prodiodetail where " +
- "pd_ordercode=ma_code and pd_piclass in ('委外验收单','完工入库单','委外验退单') and pd_status>0),0) WHERE ma_id="
- + ma_id);
- baseDao.execute("update make set ma_finishstatuscode='COMPLETED',ma_finishstatus='已完工' where ma_id=" + ma_id + " and ma_madeqty>=ma_qty ");
- baseDao.execute("update make set ma_finishstatuscode='PARTFI',ma_finishstatus='部分完工' where ma_id="
- + ma_id + " and ma_madeqty>0 and ma_madeqty<ma_qty ");
- baseDao.execute("update make set ma_finishstatuscode='UNCOMPLET',ma_finishstatus='未完工' where ma_id=" + ma_id + " and ma_madeqty=0 ");
- }
- private void changeMaStatus(int pi_id) {
- String ids = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "select wm_concat(ma_id) from (select distinct ma_id from ProdIODetail left join make on ma_code=pd_ordercode where pd_piid=?)",
- String.class, pi_id);
- if (ids != null) {
- updateMakeGetStatus(ids);
- }
- }
- /**
- * 修改工单领料状态
- */
- public void updateMakeGetStatus(String ids) {
- baseDao.execute("update make set ma_turnstatuscode='UNGET',ma_turnstatus='未领料' where ma_id in ("
- + ids + ") and not exists(select 1 from makematerial where mm_maid=ma_id and NVL(mm_havegetqty,0)+NVL(mm_totaluseqty,0)>0)");
- baseDao.execute("update make set ma_turnstatuscode='PARTGET',ma_turnstatus='部分转领料' where ma_id in ("
- + ids + ") and nvl(ma_turnstatuscode,' ')<>'PARTGET' and exists (select 1 from makematerial where mm_maid=ma_id "
- + "and NVL(mm_havegetqty,0)+NVL(mm_totaluseqty,0)+NVL(mm_turnaddqty,0)>0 and NVL(mm_materialstatus,' ')=' ')");
- baseDao.execute("update make set ma_turnstatuscode='TURNGET',ma_turnstatus='已转领料' where ma_id in ("
- + ids + ") and nvl(ma_turnstatuscode,' ')<>'TURNGET' and not exists(select 1 from makematerial where mm_maid=ma_id "
- + "and nvl(MM_QTY,0)-NVL(mm_havegetqty,0)-NVL(mm_totaluseqty,0)-NVL(mm_turnaddqty,0)>0 and NVL(mm_materialstatus,' ')=' ')");
- }
- private void refreshTurnQty(Integer ma_id, Integer mm_id) {
- if (mm_id != null && mm_id > 0) {
- // 已转领料数
- 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="
- + ma_id + " and mm_id=" + mm_id);
- // 转补料数
- baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
- + "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 ="
- + ma_id + " and mm_id=" + mm_id);
- // 更新替代已转数
- baseDao.execute("update makematerialreplace set mp_repqty=(select NVL(sum(nvl(pd_outqty,0)),0) from prodiodetail,prodinout "
- + "where pd_piid=pi_id and pd_status=0 and pd_prodcode=mp_prodcode and pd_ordercode=mp_mmcode and "
- + "pd_orderdetno=mp_mmdetno and pd_piclass in ('生产领料单', '委外领料单')) where mp_maid=" + ma_id + " and mp_mmid=" + mm_id);
- baseDao.execute("update makematerialreplace set mp_repqty=0 where mp_maid=" + ma_id + " AND MP_REPQTY<0");
- // 更新替代总已转数
- 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="
- + ma_id + " and mm_id=" + mm_id);
- // 更新替代总已领数
- 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="
- + ma_id + " and mm_id=" + mm_id);
- } else {
- // 已转领料数
- 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="
- + ma_id);
- // 转补料数
- baseDao.execute("update MakeMaterial set mm_turnaddqty=(select sum(nvl(pd_outqty,0)) from prodiodetail,prodinout "
- + "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 ="
- + ma_id);
- // 更新替代已转数
- baseDao.execute("update makematerialreplace set mp_repqty=(select NVL(sum(nvl(pd_outqty,0)),0) from prodiodetail,prodinout "
- + "where pd_piid=pi_id and pd_status=0 and pd_prodcode=mp_prodcode and pd_ordercode=mp_mmcode and "
- + "pd_orderdetno=mp_mmdetno and pd_piclass in ('生产领料单', '委外领料单')) where mp_maid=" + ma_id);
- baseDao.execute("update makematerialreplace set mp_repqty=0 where mp_maid=" + ma_id + " AND MP_REPQTY<0");
- // 更新替代总已转数
- 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="
- + ma_id);
- // 更新替代总已领数
- 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="
- + ma_id);
- }
- }
- private void setBackQty(String maidstr, Integer mm_id) {
- if (mm_id != null && mm_id > 0) {
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ") and mm_id=" + mm_id);
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ") and mp_mmid=" + mm_id);
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ") and mm_id=" + mm_id);
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ") and mp_mmid=" + mm_id);
- } else {
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ")");
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ")");
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ")");
- baseDao.getJdbcTemplate()
- .execute(
- "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 ("
- + maidstr + ")");
- }
- }
- private String checkFreezeMonth(Object pidate) {
- boolean bool = baseDao.checkIf("PeriodsDetail", "pd_code='MONTH-P' and pd_status=99 and pd_detno=to_char(to_date('" + pidate
- + "','yyyy-mm-dd hh24:mi:ss'), 'yyyymm')");
- if (bool) {
- return "单据日期所属期间已结账,不允许进行当前操作!";
- }
- String freeze = baseDao.getDBSetting("sys","freezeMonth");
- if (freeze != null && !freeze.equals("")) {
- if (Integer.parseInt(freeze) == DateUtil.getYearmonth(pidate.toString())) {
- return "单据日期所属期间已冻结,不允许进行当前操作!";
- }
- }
- return null;
- }
- private String ScrapCheckAll(int ms_id, String caller) {
- // 判断工单状态是否已审核
- SqlRowList rs = baseDao.queryForRowSet("select md_detno,md_mmcode,ma_status from makescrapdetail,make where md_msid=" + ms_id
- + " and md_mmcode=ma_code and ma_statuscode<>'AUDITED' ");
- if (rs.next()) {
- return "制造单" + rs.getString("md_mmcode") + "状态[" + rs.getString("ma_status") + "],只能操作已审核状态的制造单!";
- }
- return null;
- }
- /**
- * 判断报废数是否大于结存可报废数
- *
- * @param
- */
- private String ScrapCheck_scrapqty(Integer ms_id) {
- String sql = "";
- String err = "";
- 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='"
- + ms_id
- + "') and mm_code=md_mmcode and md_mmdetno=mm_detno),0) "
- + " WHERE (mm_code,mm_detno) in (select md_mmcode as mm_code,md_mmdetno as mm_detno from MakeScrapDetail where md_msid='"
- + ms_id + "')";
- baseDao.execute(sql);
- if(baseDao.isDBSetting("sys","usingMakeCraft")){
- 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="
- + 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) ";
- }else{
- 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="
- + ms_id ;
- if(baseDao.isDBSetting("Make!Base", "allowChangeAfterCom")){
- sql = sql+ " and round(nvl(mm_allscrapqty,0),4) > round(nvl(mm_havegetqty,0)-nvl(mm_backqty,0),4) ";
- }else{
- sql += " and round(nvl(mm_allscrapqty,0),4)>round(nvl(mm_havegetqty,0)-mm_oneuseqty*ma_madeqty,4) ";
- }
- }
- SqlRowList rs = baseDao.queryForRowSet(sql);
- while (rs.next()) {
- err = err + "," + rs.getString("md_detno");
- }
- if (!err.equals("")) {
- return "序号:" + err.substring(1) + "报废数大于结存数!";
- }
- sql = "SELECT count(1) detno ,wm_concat(md_detno) as detnostr FROM MakeScrapDetail WHERE md_msid='" + ms_id + "' and md_qty<=0 ";
- rs = baseDao.queryForRowSet(sql);
- if (rs.next()) {
- if (rs.getInt("detno") > 0) {
- return "序号:" + rs.getString("detnostr") + "报废数小于或等于0,不能审核!";
- }
- }
- return null;
- }
- private String copcheck(int ms_id) {
- if (baseDao.isDBSetting("sys","CopCheck")) {
- // 生产报废单:明细行制造单所属公司与当前单所属公司必须一致,可在提交、打印、审核、过账等操作前配置
- String dets = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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,' ') ",
- String.class, ms_id);
- if (dets != null) {
- return "行号:" + dets+"制造单所属公司与当前单所属公司不一致,不允许进行当前操作!";
- }
- }
- return null;
- }
- // 验证从表中的工单的序号是否有效
- private String checkMakeMaterial(int ms_id) {
- String err = baseDao
- .getJdbcTemplate()
- .queryForObject(
- "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)",
- String.class, ms_id);
- if (err != null) {
- return "序号:" + err.toString() + " 无对应工单和序号,不允许进行当前操作!";
- }
- return null;
- }
- }
|