|
|
@@ -1759,6 +1759,157 @@ public class MESServiceImpl implements MESService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApiResult<String> confirmSendNotify(HttpServletRequest request) {
|
|
|
+ String requestId = request.getHeader("RequestId");
|
|
|
+ Map<String, JSONArray> data = getData(request);
|
|
|
+ if (data!=null&&!data.isEmpty()){
|
|
|
+ int snId=0;
|
|
|
+ JSONArray main = data.get("main");
|
|
|
+ if (main != null&&main.size()>0) {
|
|
|
+ JSONObject object = JSON.parseObject(StringUtil.nvl(main.get(0), "{}"));
|
|
|
+ snId = Integer.parseInt(StringUtil.nvl(object.get("snId"), "0"));
|
|
|
+ if (!baseDao.checkIf("SendNotify", "sn_id=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10071", requestId, "出货通知单不存在,无法确认!");
|
|
|
+ }
|
|
|
+ if (!baseDao.checkIf("SendNotify", "sn_statuscode='AUDITED' and sn_id=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10072", requestId, "出货通知单不是已审核状态,无法确认!");
|
|
|
+ }
|
|
|
+ if (baseDao.checkIf("SendNotify", "sn_sendstatus='已出库' and sn_id=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10073", requestId, "出货通知单已出货,无需重新确认生成!");
|
|
|
+ }
|
|
|
+ if (baseDao.checkIf("ProdIODetail", "pd_piclass='出货单' and pd_snid=" + snId)) {
|
|
|
+ return ApiResponse.failRsp("10074", requestId, "出货通知单已转出货单,无需重新确认生成!");
|
|
|
+ }
|
|
|
+ // 存在未审批变更单
|
|
|
+ String dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_snid=" + snId + " and exists (select 1 from SaleChangeDetail left join SaleChange on sc_id=scd_scid where scd_sacode=snd_ordercode and scd_sddetno=snd_orderdetno and sc_statuscode<>'AUDITED' )", String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10075", requestId, "存在待审批的销售变更单,不能进行转出操作!行号:" + dets);
|
|
|
+ }
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from sendnotifydetail where snd_snid=" + snId + " and exists (select 1 from SendNotifyChange left join SendNotifyChangeDetail on sc_id=scd_scid where sc_sncode=snd_code and scd_snddetno=snd_pdno and sc_statuscode<>'AUDITED')", String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10076", requestId, "存在待审批的通知变更单,不能进行转出操作!行号:" + dets);
|
|
|
+ }
|
|
|
+ if (baseDao.isDBSetting("Sale", "zeroOutWhenHung")) {
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_snid=" + snId + " and sn_custcode in (select cu_code from customer where cu_status='挂起') and not exists (select 1 from saledetail where sd_code=snd_ordercode and sd_detno=snd_orderdetno and nvl(sd_price,0)=0)", String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10077", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select distinct wm_concat('通知单号:'||sn_code||'客户:'||sn_custcode) from sendnotify left join SendNotifyDetail on snd_snid=sn_id where nvl(sn_custcode, ' ')<>' ' and snd_snid=" + snId + " and sn_custcode in (select cu_code from customer where cu_status='挂起')", String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10078", requestId, "通知单客户已挂起,不能进行转出操作!" + dets);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dets = baseDao.getJdbcTemplate().queryForObject("select wm_concat(snd_pdno) from SendNotifyDetail where nvl(snd_statuscode, ' ')<>'AUDITED' and snd_snid=" + snId, String.class);
|
|
|
+ if (dets != null) {
|
|
|
+ return ApiResponse.failRsp("10079", requestId, "明细行状态不等于已审核,不能进行转出操作!" + dets);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray detail = data.get("detail");
|
|
|
+ if (detail != null&&detail.size()>0&&snId>0) {
|
|
|
+ List<Map<Object, Object>> maps = new ArrayList<>();
|
|
|
+ for (int i = 0; i <detail.size(); i++) {
|
|
|
+ JSONObject parseObject = JSON.parseObject(StringUtil.nvl(detail.get(i), "{}"));
|
|
|
+ int sndId = Integer.parseInt(StringUtil.nvl(parseObject.get("sndId"), "0"));
|
|
|
+ double tqty = Double.parseDouble(StringUtil.nvl(parseObject.get("tqty"), "0"));
|
|
|
+ String prodCode = StringUtil.nvl(parseObject.get("prodCode"), "");
|
|
|
+ String whCode = StringUtil.nvl(parseObject.get("whCode"), "");
|
|
|
+ if (!baseDao.checkIf("SendNotifyDetail","snd_id="+sndId)){
|
|
|
+ return ApiResponse.failRsp("10079", requestId, "明细行不存在,请核对!");
|
|
|
+ }
|
|
|
+ if ("".equals(prodCode)){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"物料不能为空!");
|
|
|
+ }
|
|
|
+ if (!baseDao.checkIf("SendNotifyDetail","snd_prodcode='"+prodCode+"' and snd_id="+sndId)){
|
|
|
+ return ApiResponse.failRsp("10079", requestId, "明细行物料不存在,请核对!");
|
|
|
+ }
|
|
|
+ if ("".equals(whCode)){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"仓库不能为空!");
|
|
|
+ }
|
|
|
+ int count = baseDao.getCount("select count(1) from customtabledetail left join customtable on cd_ctid=ct_id where ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whCode + "'");
|
|
|
+ if (count<=0){
|
|
|
+ return ApiResponse.failRsp("10064",requestId,"MES仓库编号在ERP没有对应关系,请联系管理员新增!");
|
|
|
+ }
|
|
|
+ Object[] wh = baseDao.getFieldsDataByCondition("customtabledetail left join customtable on cd_ctid=ct_id left join Warehouse on cd_varchar50_3=wh_code", "cd_varchar50_3,wh_description", "ct_statuscode='AUDITED' and ct_caller='MESWarehouse' and cd_varchar50_1='" + whCode + "'");
|
|
|
+ if (tqty<=0){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"数量需要大于0!");
|
|
|
+ }
|
|
|
+ if (baseDao.checkIf("SendNotifyDetail","nvl(snd_yqty,0)+"+tqty+">nvl(snd_outqty,0) and snd_id="+sndId)){
|
|
|
+ return ApiResponse.failRsp("10063",requestId,"数量+已转出货数不能大于通知单数量!");
|
|
|
+ }
|
|
|
+ Map<Object, Object> map = new HashMap<>();
|
|
|
+ map.put("snd_id",sndId);
|
|
|
+ map.put("snd_tqty",tqty);
|
|
|
+ map.put("snd_warehousecode",wh[0]);
|
|
|
+ map.put("snd_warehouse",wh[1]);
|
|
|
+ maps.add(map);
|
|
|
+ }
|
|
|
+ Employee employee = baseDao.getJdbcTemplate().queryForObject("select * from employee where em_code=?", new BeanPropertyRowMapper<Employee>(Employee.class), "mes");
|
|
|
+ //生成出货单
|
|
|
+ Key key = transferRepository.transfer("ProdInOut!Sale", snId, employee);
|
|
|
+ if (key != null) {
|
|
|
+ int pi_id = key.getId();
|
|
|
+ // 转入出货单明细
|
|
|
+ transferRepository.transfer("ProdInOut!Sale", maps, key, employee);
|
|
|
+ // 地址
|
|
|
+ baseDao.execute(
|
|
|
+ "update ProdInOut set pi_address=(select cu_add1 from customer where pi_cardcode=cu_code) where pi_id=? and nvl(pi_address,' ')=' '",
|
|
|
+ pi_id);
|
|
|
+ baseDao.execute(
|
|
|
+ "update ProdIODetail set (pd_whcode,pd_whname)=(select pr_whcode,wh_description from product left join warehouse on pr_whcode=wh_code where pd_prodcode=pr_code) where pd_piid=? and nvl(pd_whcode,' ')=' '",
|
|
|
+ pi_id);
|
|
|
+ baseDao.execute(
|
|
|
+ "update prodinout set (pi_whcode,pi_whname)=(select pd_whcode,pd_whname from prodiodetail where pd_piid=pi_id and nvl(pd_whcode,' ')<>' ' and rownum<2) where nvl(pi_whcode,' ')=' ' and pi_id=?",
|
|
|
+ pi_id);
|
|
|
+ baseDao.execute("update prodinout set (pi_purposename,pi_expresscode,pi_fax)=(select max(ca_person),max(ca_phone),max(ca_fax) from CustomerAddress left join customer on ca_cuid=cu_id where cu_code=pi_cardcode and ca_address=pi_address) where pi_id="
|
|
|
+ + pi_id);
|
|
|
+ baseDao.execute(
|
|
|
+ "update ProdInOut set pi_rate=nvl((select cm_crrate from currencysmonth where cm_yearmonth=to_char(pi_date,'yyyymm') and cm_crname=pi_currency),1) where pi_id=? and nvl(pi_currency,' ')<>' '",
|
|
|
+ pi_id);
|
|
|
+ baseDao.execute(
|
|
|
+ "update ProdInOut set pi_total=(SELECT round(sum(nvl(pd_sendprice,0)*(nvl(pd_inqty,0)+nvl(pd_outqty,0))),2) FROM ProdIODetail WHERE pd_piid=pi_id) where pi_id=?",
|
|
|
+ pi_id);
|
|
|
+ baseDao.updateByCondition(
|
|
|
+ "ProdIODetail",
|
|
|
+ "pd_netprice=round(pd_sendprice/(1+pd_taxrate/100),8),pd_nettotal=round(pd_sendprice*pd_outqty/(1+nvl(pd_taxrate,0)/100),2)",
|
|
|
+ "pd_piid=" + pi_id);
|
|
|
+ baseDao.execute(
|
|
|
+ "update ProdIODetail set pd_taxtotal=round(pd_sendprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2), pd_nettotal=round(pd_netprice*(nvl(pd_inqty,0)+nvl(pd_outqty,0)),2) WHERE pd_piid=?",
|
|
|
+ pi_id);
|
|
|
+ baseDao.updateByCondition("ProdInOut", "pi_totalupper=L2U(nvl(pi_total,0))", "pi_id=" + pi_id);
|
|
|
+ // 修改出货通知单状态
|
|
|
+ String statuscode = null, status = null;
|
|
|
+ int count = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + snId);
|
|
|
+ int yCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + snId + " and nvl(snd_yqty,0)=nvl(snd_outqty,0) and nvl(snd_yqty,0)>=0");
|
|
|
+ int xCount = baseDao.getCountByCondition("SendNotifyDetail", "snd_snid=" + snId + " and nvl(snd_yqty,0)=0");
|
|
|
+ statuscode = "PARTOUT";
|
|
|
+ status = "部分出库";
|
|
|
+ if (xCount == count) {
|
|
|
+ statuscode = "";
|
|
|
+ status = "";
|
|
|
+ }
|
|
|
+ if (yCount == count) {
|
|
|
+ statuscode = "TURNOUT";
|
|
|
+ status = "已出库";
|
|
|
+ }
|
|
|
+ baseDao.updateByCondition("SendNotify", "SN_SENDSTATUSCODE='" + statuscode + "',SN_SENDSTATUS='" + status + "'", "sn_id=" + snId);
|
|
|
+ //过账出货单
|
|
|
+ String s = postProdInOut(pi_id, "ProdInOut!Sale", employee);
|
|
|
+ if (s!=null&&!"".equals(s)){
|
|
|
+ return ApiResponse.successRsp("0", requestId, "出货单:" + key.getCode() + ",过账失败,请在ERP重新过账!");
|
|
|
+ }
|
|
|
+ // 记录操作
|
|
|
+ baseDao.execute("INSERT INTO MessageLog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search) VALUES (MessageLog_seq.nextval,sysdate,'mes','确认操作','确认成功','SendNotify|sn_id=" + snId + "')");
|
|
|
+ return ApiResponse.successRsp("0", requestId, "出货单:" + key.getCode() + ",请在ERP查看!");
|
|
|
+ } else
|
|
|
+ return ApiResponse.failRsp("10080", requestId, "生成失败!");
|
|
|
+ }else
|
|
|
+ return ApiResponse.failRsp("10081",requestId,"参数异常!");
|
|
|
+ }else
|
|
|
+ return ApiResponse.failRsp("10081",requestId,"参数异常!");
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, JSONArray> getData(HttpServletRequest request){
|
|
|
Map<String, JSONArray> map = new HashMap<>();
|
|
|
try {
|