|
|
@@ -1116,6 +1116,166 @@ public class MESServiceImpl implements MESService {
|
|
|
return ApiResponse.successRsp("0",requestId,piClass+":"+inoutno+"自动过账,请在ERP查看!");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApiResult<String> purcCheckinDetail(HttpServletRequest request) {
|
|
|
+ String requestId = request.getHeader("RequestId");
|
|
|
+ Map<String, JSONArray> data = getData(request);
|
|
|
+ JSONArray jsonArray = data.get("main");
|
|
|
+ Object vaid=0;
|
|
|
+ String caller="VerifyApply!ToOtherIn";
|
|
|
+ String type="其它入库单";
|
|
|
+ String djcaller="ProdInOut!OtherIn";
|
|
|
+ String sellerName="";
|
|
|
+ for (int i = 0; i <jsonArray.size() ; i++) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(StringUtil.nvl(jsonArray.get(i), ""));
|
|
|
+ String mesCode = StringUtil.nvl(jsonObject.get("mesCode"),"");
|
|
|
+ if ("".equals(mesCode)){
|
|
|
+ return ApiResponse.failRsp("10011",requestId,"ERP单据编号不能为空!");
|
|
|
+ }
|
|
|
+ int count = baseDao.getCountByCondition("verifyApply", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
|
|
|
+ if (count<1){
|
|
|
+ return ApiResponse.failRsp("10012",requestId,"单据未审核或不存在,请确认!");
|
|
|
+ }
|
|
|
+ vaid = baseDao.getFieldDataByCondition("verifyApply", "va_id", "va_statuscode='AUDITED' and va_mescode='" + mesCode + "'");
|
|
|
+ String vaClass = StringUtil.nvl(baseDao.getFieldDataByCondition("VerifyApply", "va_class", "va_id=" + vaid), "");
|
|
|
+ if ("委外收料单".equals(vaClass)) {
|
|
|
+ caller = "VerifyApply!ToOutsideCheckIn";
|
|
|
+ type = "委外验收单";
|
|
|
+ djcaller = "ProdInOut!OutsideCheckIn";
|
|
|
+ }else if("采购收料单".equals(vaClass)){
|
|
|
+ int count1 = baseDao.getCount("select count(1) from VerifyApplyDetail where nvl(vad_pucode,' ')<>' ' and vad_vaid=" + vaid);
|
|
|
+ if (count1 > 0) {
|
|
|
+ caller = "VerifyApply!ToPurcIn";
|
|
|
+ type = "采购验收单";
|
|
|
+ djcaller = "ProdInOut!PurcCheckin";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断已转数
|
|
|
+ Object chekQty = baseDao.getJdbcTemplate().queryForObject("select wmsys.wm_concat('收料单:'||vad_code||'序号:'||vad_detno) from VerifyApplyDetail where vad_qty < vad_yqty and nvl(vad_qty,0)>0 and nvl(vad_prodcode,' ')<>' ' and vad_vaid = "+vaid, String.class);
|
|
|
+ if(chekQty !=null){
|
|
|
+ return ApiResponse.failRsp("10013",requestId,"检测到" + chekQty + ",本次数量超出可转数量!");
|
|
|
+ }
|
|
|
+ if ("VerifyApply!ToPurcIn".equals(caller)) {
|
|
|
+ // 判断该收料单是否已经转入过采购验收单
|
|
|
+ Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
|
|
|
+ code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and " + "PI_REFNO='采购收料单' and pi_class='采购验收单'");
|
|
|
+ if (code != null && !code.equals("")) {
|
|
|
+ return ApiResponse.failRsp("10014", requestId, "该收料单已转入过采购验收单,验收单号[" + code + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("VerifyApply!ToOtherIn".equals(caller)) {
|
|
|
+ // 判断该收料单是否已经转入过其它入库单
|
|
|
+ Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
|
|
|
+ code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='其它入库单'");
|
|
|
+ if (code != null && !code.equals("")) {
|
|
|
+ return ApiResponse.failRsp("10014", requestId, "该收料单已转入过其它入库单,单号[" + code + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("VerifyApply!ToOutsideCheckIn".equals(caller)) {
|
|
|
+ // 判断该收料单是否已经转入过委外验收单
|
|
|
+ Object code = baseDao.getFieldDataByCondition("VerifyApply", "va_code", "va_id=" + vaid);
|
|
|
+ code = baseDao.getFieldDataByCondition("ProdInOut", "pi_inoutno", "pi_sourcecode='" + code + "' and PI_REFNO='采购收料单' and pi_class='委外验收单'");
|
|
|
+ if (code != null && !code.equals("")) {
|
|
|
+ return ApiResponse.failRsp("10014", requestId, "该收料单已转入过委外验收单,单号[" + code + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sellerName = StringUtil.nvl(jsonObject.get("sellerName"), "mes");
|
|
|
+ }
|
|
|
+ JSONArray array = data.get("detail");
|
|
|
+ for (int i = 0; i <array.size() ; i++) {
|
|
|
+ JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
|
|
|
+ String itemNo = StringUtil.nvl(json.get("itemNo"), "");
|
|
|
+ Double qty = Double.parseDouble(StringUtil.nvl(json.get("qty"), "0"));
|
|
|
+ Double vadQty = baseDao.getSummaryByField("verifyapplydetail", "vad_qty", "vad_prodcode='" + itemNo + "' and vad_vaid=" + vaid);
|
|
|
+ int compare = qty.compareTo(vadQty);
|
|
|
+ if (compare>0){
|
|
|
+ return ApiResponse.failRsp("10017",requestId, "物料:"+itemNo+",收料数量:"+qty+"超出ERP收料单数量:"+vadQty+ ",不允许入库!");
|
|
|
+ }
|
|
|
+ if (compare<0){
|
|
|
+ return ApiResponse.failRsp("10018",requestId,"物料:"+itemNo+",收料数量:"+qty+"少于ERP收料单数量:"+vadQty+",不允许入库!");
|
|
|
+ }
|
|
|
+ String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
|
|
|
+ if ("".equals(whcode)){
|
|
|
+ return ApiResponse.failRsp("10015",requestId,"MES仓库编号不能为空!");
|
|
|
+ }
|
|
|
+ int coun = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
|
|
|
+ if (coun<=0){
|
|
|
+ return ApiResponse.failRsp("10016",requestId,"MES仓库编号:"+whcode+"在ERP没有对应关系,请联系管理员新增!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int piid =0;
|
|
|
+ Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_name=?",
|
|
|
+ new BeanPropertyRowMapper<Employee>(Employee.class), sellerName);
|
|
|
+ // 转采购验收单
|
|
|
+ Key key = transferRepository.transfer(caller, vaid,employee);
|
|
|
+ piid = key.getId();
|
|
|
+ // 转入明细
|
|
|
+ transferRepository.transferDetail(caller, vaid, key,employee);
|
|
|
+ if (piid != 0) {
|
|
|
+ baseDao.execute("delete from prodiodetail where nvl(pd_inqty,0)<=0 and pd_piid="+piid);
|
|
|
+ //更新仓库
|
|
|
+ for (int i = 0; i <array.size() ; i++) {
|
|
|
+ JSONObject json = JSON.parseObject(StringUtil.nvl(array.get(i), ""));
|
|
|
+ String itemNo = StringUtil.nvl(json.get("itemNo"), "");
|
|
|
+ String whcode= StringUtil.nvl(json.get("vad_whcode"), "");
|
|
|
+ Object[] warehouses = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whcode + "'");
|
|
|
+ baseDao.updateByCondition("prodiodetail", "pd_whcode='"+warehouses[0]+"',pd_whname='"+warehouses[1]+"'", "pd_prodcode='"+itemNo+"' and pd_piid=" + piid);
|
|
|
+ }
|
|
|
+ //baseDao.updateByCondition("prodinout", "pi_whcode='"+warehouses[0]+"',pi_whname='"+warehouses[1]+"'","pi_id=" + piid);
|
|
|
+ baseDao.execute("update prodiodetail set pd_prodid=(select pr_id from product where pd_prodcode=pr_code) where pd_piid=" + piid
|
|
|
+ + " and nvl(pd_prodcode,' ')<>' '");
|
|
|
+ baseDao.execute("update prodiodetail set pd_whid=(select wh_id from warehouse where wh_code=pd_whcode) where pd_piid=" + piid
|
|
|
+ + " and nvl(pd_whcode,' ')<>' '");
|
|
|
+ baseDao.updateByCondition("ProdInOut",
|
|
|
+ "pi_total=(SELECT round(sum(nvl(pd_orderprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid="
|
|
|
+ + piid + ")", "pi_id=" + piid);
|
|
|
+ baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + piid);
|
|
|
+ if ("VerifyApply!ToPurcIn".equals(caller)) {
|
|
|
+ baseDao.execute("Insert into ProdChargeDetail(pd_id,pd_piid,pd_detno,pd_type,pd_amount,pd_currency,pd_rate) "
|
|
|
+ + "select ProdChargeDetail_seq.nextval, " + piid + ", pd_detno, pd_type,pd_amount,pd_currency,pd_rate "
|
|
|
+ + "from ProdChargeDetailAN where PD_ANID=" + vaid);
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select vad_pucode,vad_pudetno,vad_qty from VerifyApplyDetail where vad_vaid=" + vaid);
|
|
|
+ String pCode = null;
|
|
|
+ int pDetno = 0;
|
|
|
+ double yq = 0;
|
|
|
+ Set<String> pCodes = new HashSet<String>();
|
|
|
+ while (rs.next()) {
|
|
|
+ pCode = rs.getString("vad_pucode");
|
|
|
+ if (!pCodes.contains(pCode)) {
|
|
|
+ pCodes.add(pCode);
|
|
|
+ }
|
|
|
+ pDetno = rs.getInt("vad_pudetno");
|
|
|
+ yq = rs.getDouble("vad_qty");
|
|
|
+ baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno);
|
|
|
+ baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'", "pd_code='" + pCode + "' and pd_detno=" + pDetno
|
|
|
+ + " and pd_qty=" + yq);
|
|
|
+ }
|
|
|
+ Iterator<String> iter = pCodes.iterator();
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ pCode = iter.next();
|
|
|
+ int total = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "'");
|
|
|
+ int aud = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode + "' AND nvl(pd_acceptqty,0)=0");
|
|
|
+ int turn = baseDao.getCountByCondition("PurchaseDetail", "pd_code='" + pCode
|
|
|
+ + "' AND nvl(pd_acceptqty,0)=nvl(pd_qty,0)");
|
|
|
+ String statuscode = aud == total ? "" : (turn == total ? "TURNIN" : "PART2IN");
|
|
|
+ String status = aud == total ? "" : (turn == total ? "已入库" : "部分入库");
|
|
|
+ baseDao.updateByCondition("Purchase",
|
|
|
+ "pu_turnstatuscode='" + statuscode + "',pu_turnstatus='" + status + "'", "pu_code='" + pCode + "'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 修改收料状态
|
|
|
+ baseDao.updateByCondition("VerifyApplyDetail", "vad_yqty=vad_qty", "vad_vaid=" + vaid);
|
|
|
+ baseDao.updateByCondition("VerifyApply", "va_turnstatuscode='TURNIN',va_turnstatus='已入库'", "va_id=" + vaid);
|
|
|
+ String s = postProdInOut(piid, djcaller, employee);
|
|
|
+ logger.info("收料单入库=="+s);
|
|
|
+ if (s!=null){
|
|
|
+ return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",过账失败,请在ERP重新过账!");
|
|
|
+ }
|
|
|
+ return ApiResponse.successRsp("0",requestId,type+":"+key.getCode()+",请在ERP查看!");
|
|
|
+ }
|
|
|
+ return ApiResponse.failRsp("10019",requestId,"ERP生成单据失败!");
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, JSONArray> getData(HttpServletRequest request){
|
|
|
Map<String, JSONArray> map = new HashMap<>();
|
|
|
try {
|