MESServiceImpl.java 292 KB

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