| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159 |
- 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 'BYT' else va_cop end va_cop,va_remark,va_ancode,va_factory,0 version,va_type,va_pucode,case when nvl(va_pucode,' ')=' ' then 0 else (select pu_id from purchase where pu_code=va_pucode) end pu_id,va_status,1 posted,to_char(va_auditdate,'yyyy-MM-dd HH24:mi:ss') va_auditdate,va_auditman,va_custcode,va_custname from VerifyApply where va_statuscode='AUDITED' and va_mescode=?",
- 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 'BYT' else nvl(cu_mescode,cu_code) end cu_code,cu_name from verifyapply left join customer on va_custcode=cu_code where va_statuscode='AUDITED' and va_mescode='"+mesCode+"'");
- 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 'BYT' else nvl(cu_mescode,cu_code) end pr_kh_user,cu_name,vad_salecode from verifyapplydetail left join VerifyApply on va_id=vad_vaid left join product on vad_prodcode=pr_code left join customer on cu_shortname=pr_kh_user where nvl(vad_qty,0)>0 and vad_vaid="+verifyApply.getVa_id()+") group by vad_code,vad_prodcode,pr_detail,pr_spec,pr_unit,va_recorder,va_date,pr_kh_user,cu_name,vad_salecode", VerifyApplyDetail.class);
- 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 mm_oneuseqty>0 and mm_oneuseqty*ma_qty<=mm_qty+0.1 and nvl(mm_cp_user,0)=0)","ma_code='" + makeCode + "'");
- //备料齐套数量
- map.put("canmadeqty",canmadeqty);
- }else {
- map.put("canmadeqty",data[2]);
- }
- //工单数量
- 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"), "");
- 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) values " +
- " 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,"参数异常!");
- }
- }
- 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 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 prodinout left join ProdIODetail on pd_piid=pi_id left join make on ma_code=pd_ordercode where pd_piid=? and (NVL(ma_statuscode,' ')<>'AUDITED' AND ('"
- + allowBackAfterFinish
- + "'='false' or (pd_piclass='生产退料单' and ma_statuscode<>'FINISH'))) and pi_statuscode='UNPOST' 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 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;
- }
- }
|