Browse Source

结算单

chenc 3 năm trước cách đây
mục cha
commit
daaa6fc889

+ 41 - 28
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/controller/PurchaseWarehousingController.java

@@ -171,35 +171,48 @@ public class PurchaseWarehousingController extends JeecgController<PurchaseWareh
   public Result saveBath(@RequestBody JSONArray json){
   	Result result=new Result();
 
-	if(json!=null&&json.size()>0){
-		//账套1
-		List<Map<String,Object>> mapListOne=new ArrayList<>();
-		//账套2
-		List<Map<String,Object>> mapListTwo=new ArrayList<>();
-		//账套3
-		List<Map<String,Object>> mapListThree=new ArrayList<>();
-		for(int i=0;i<json.size();i++){
-			//获取对象
-			JSONObject jsonObject=json.getJSONObject(i);
-			//获取账套
-			String cAccId=jsonObject.get("cAccId").toString();
-			//转map
-			Map<String,Object> map=updateMap(jsonObject);
-			if(cAccId.equals("101")){
-				mapListOne.add(map);
-			}else if(cAccId.equals("102")){
-				mapListTwo.add(map);
-			}else if(cAccId.equals("103")){
-				mapListThree.add(map);
-			}
-		}
-//		purchaseWarehousingService.aa();
-//		purchaseWarehousingService.bb();
-		purchaseWarehousingService.savaOne(mapListOne);
-//		result.setResult(mapList);
-	}
+	  try {
+		  if(json!=null&&json.size()>0){
+              //账套1
+              List<Map<String,Object>> mapListOne=new ArrayList<>();
+              //账套2
+              List<Map<String,Object>> mapListTwo=new ArrayList<>();
+              //账套3
+              List<Map<String,Object>> mapListThree=new ArrayList<>();
+              for(int i=0;i<json.size();i++){
+                  //获取对象
+                  JSONObject jsonObject=json.getJSONObject(i);
+                  //获取账套
+                  String cAccId=jsonObject.get("cAccId").toString();
+                  //转map
+                  Map<String,Object> map=updateMap(jsonObject);
+                  if(cAccId.equals("101")){
+                      mapListOne.add(map);
+                  }else if(cAccId.equals("102")){
+                      mapListTwo.add(map);
+                  }else if(cAccId.equals("103")){
+                      mapListThree.add(map);
+                  }
+              }
+              if(mapListOne.size()>0){
+                  purchaseWarehousingService.savaOne(mapListOne);
+              }
+              if(mapListTwo.size()>0){
+                  purchaseWarehousingService.savaTwo(mapListTwo);
+              }
+              if(mapListThree.size()>0){
+                  purchaseWarehousingService.savaThree(mapListThree);
+              }
+              result.success("操作成功");
+          }else{
+		  	result.error500("为获取到正确的json");
+		  }
+	  } catch (Exception e) {
+		  e.printStackTrace();
+		  result.error500("操作失败:"+e.getMessage());
+	  }
 
-  	return result;
+	  return result;
   }
 
   public Map<String,Object> updateMap(JSONObject jsonObject){

+ 39 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/mapper/PurchaseWarehousingMapper.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.openApi.mapper;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -22,9 +23,9 @@ public interface PurchaseWarehousingMapper extends BaseMapper<PurchaseWarehousin
     * @Param [table]
     * @return java.lang.String
     */
-    Integer getMaxId(@Param("id")String id,@Param("tableName")String tableName);
+    String getMaxId(@Param("id")String id,@Param("tableName")String tableName);
 
-    Integer getMaxCode(@Param("code")String code,@Param("tableName")String tableName);
+    String getMaxCode(@Param("code")String code,@Param("tableName")String tableName);
 
     /**
     * @Author chenchuang
@@ -79,4 +80,40 @@ public interface PurchaseWarehousingMapper extends BaseMapper<PurchaseWarehousin
     * @return void
     */
     void saveTransVouch(@Param("map")Map<String,Object> map);
+
+    /**
+    * @Author chenchuang
+    * @Description //TODO 根据红字获取对应采购订单行的蓝字根据入库数量与发票数量判断是否需要做结算单的数量
+    * @Date 2022/4/26 14:14
+    * @Param [rowmId]
+    * @return java.math.BigDecimal
+    */
+    BigDecimal getRdrecords01WriteQuantity(@Param("rowmId")String rowmId);
+
+    /**
+    * @Author chenchuang
+    * @Description //TODO 根据采购订单行id获取相关数据
+    * @Date 2022/4/26 15:12
+    * @Param [rowmId]
+    * @return java.math.BigDecimal
+    */
+    Map<String,Object> getPOPodetailsINatUnitPrice(@Param("rowmId")String rowmId);
+
+    /**
+    * @Author chenchuang
+    * @Description //TODO 新增结算单主表
+    * @Date 2022/4/26 17:40
+    * @Param [map]
+    * @return void
+    */
+    void savePurSettleVouch(@Param("map")Map<String,Object> map);
+
+    /**
+    * @Author chenchuang
+    * @Description //TODO 新增结算单子表
+    * @Date 2022/4/26 18:43
+    * @Param [map]
+    * @return void
+    */
+    void savePurSettleVouchs(@Param("map")Map<String,Object> map);
 }

+ 83 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/mapper/xml/PurchaseWarehousingMapper.xml

@@ -2,11 +2,11 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.openApi.mapper.PurchaseWarehousingMapper">
 
-    <select id="getMaxId" resultType="java.lang.Integer">
+    <select id="getMaxId" resultType="java.lang.String">
         select max(${id}) from ${tableName}
     </select>
 
-    <select id="getMaxCode" resultType="java.lang.Integer">
+    <select id="getMaxCode" resultType="java.lang.String">
         select top 1 ${code} from ${tableName} ORDER BY dDate desc
     </select>
 
@@ -116,12 +116,91 @@
         </foreach>
     </insert>
 
+    <insert id="savePurSettleVouch">
+        INSERT INTO PurSettleVouch (
+        cSVCode,
+        dSVDate,
+        cBusType,
+        cVenCode,
+        cDepCode,
+        cPersonCode,
+        cPTCode,
+        iTaxRate,<!--税率-->
+        bFirst,
+        cMaker,
+        cSettleType,
+        iPrintCount,
+        bMerger,
+        PSVID<!--主键-->
+        )
+        VALUES (
+        #{map.cSVCode},
+        CONVERT(varchar,GETDATE(),20),
+        #{map.cBusType},
+        #{map.cVenCode},
+        #{map.cDepCode},
+        #{map.cPersonCode},
+        #{map.cPTCode},
+        #{map.iTaxRate},
+        0,
+        '陈创',
+        '01',
+        0,
+        0,
+        #{map.PSVID}
+        )
+    </insert>
+
+    <insert id="savePurSettleVouchs">
+        INSERT INTO PurSettleVouchs(
+        cPIVCode,
+        cInvCode,
+        iSVQuantity,<!--结算数量-->
+        iSVCost,<!--结算单价-->
+        iSVPrice,<!--结算金额-->
+        iSVACost,<!--暂估单价-->
+        iSVAPrice,<!--暂估金额-->
+        ID,
+        PSVID,
+        iRdsID,<!--蓝字入库单子表id-->
+        bAccount,
+        crdcvencode,<!--入库单供应商编码-->
+        cUpSoType,<!--入库单单据类型-->
+        )
+        VALUES(
+        #{map.cPIVCode},
+        #{map.cInvCode},
+        #{map.iSVQuantity},
+        #{map.iSVCost},
+        #{map.iSVPrice},
+        #{map.iSVACost},
+        #{map.iSVAPrice},
+        #{map.ID},
+        #{map.PSVID},
+        #{map.iRdsID},
+        0,
+        #{map.crdcvencode},
+        '01',
+        )
+    </insert>
+
     <select id="getWhCodeByVenCode" parameterType="java.lang.String" resultType="java.util.HashMap">
         select cVenCode,cVenDefine1,cVenDefine2 from Vendor where cVenCode=#{cVenCode}
     </select>
 
-    <select id="get">
-      select sum(iQuantity)-sum(iSumBillQuantity) from rdrecords01 where iPOsID='1000000051'
+    <select id="getRdrecords01WriteQuantity" resultType="java.util.HashMap" parameterType="java.lang.String">
+      SELECT SUM
+            ( rs.iQuantity ) - SUM ( rs.iSumBillQuantity )
+        FROM
+            rdrecords01 rs
+            LEFT JOIN RdRecord01 r ON rs.ID= r.ID
+        WHERE
+            r.bredvouch= 0
+            AND rs.iPOsID= #{rowmId}
+    </select>
+
+    <select id="getPOPodetailsINatUnitPrice" parameterType="java.lang.String" resultType="java.util.HashMap">
+        select iNatUnitPrice,iPerTaxRate from PO_Podetails where ID=#{rowmId}
     </select>
 
     <insert id="saveTransVouch">

+ 6 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/IPurchaseWarehousingService.java

@@ -16,8 +16,13 @@ public interface IPurchaseWarehousingService extends IService<PurchaseWarehousin
 
     void savaOne(List<Map<String,Object>> mapList);
 
+    void savaTwo(List<Map<String,Object>> mapList);
+
+    void savaThree(List<Map<String,Object>> mapList);
+
+
+    String getMaxId(String id,String tableName);
 
-    Integer getMaxId(String id,String tableName);
 
 
 }

+ 105 - 11
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/impl/PurchaseWarehousingServiceImpl.java

@@ -7,12 +7,14 @@ import org.jeecg.modules.openApi.mapper.PurchaseWarehousingMapper;
 import org.jeecg.modules.openApi.service.IPurchaseWarehousingService;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.service.ISysUserService;
+import org.jeecg.modules.system.util.oConvertUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
@@ -38,16 +40,32 @@ public class PurchaseWarehousingServiceImpl extends ServiceImpl<PurchaseWarehous
     @DS("multi-one")
     @Override
     public void savaOne(List<Map<String, Object>> mapList) {
+        save(mapList);
+    }
+
+    @DS("multi-two")
+    @Override
+    public void savaTwo(List<Map<String, Object>> mapList) {
+        save(mapList);
+    }
+
+    @DS("multi-three")
+    @Override
+    public void savaThree(List<Map<String, Object>> mapList) {
+        save(mapList);
+    }
+
+    public void save(List<Map<String, Object>> mapList){
         if(mapList!=null&&mapList.size()>0){
 
             for(Map<String,Object> map:mapList){
                 //获取主表最大编码
-                map.put("ID",getMaxId("ID","RdRecord01"));
+                map.put("ID", oConvertUtils.addOne(getMaxId("ID","RdRecord01")));
                 System.out.println(map.get("ID"));
                 //获取最大code
-                Integer cCode=this.baseMapper.getMaxCode("cCode","RdRecord01");
+                String cCode=oConvertUtils.addOne(this.baseMapper.getMaxCode("cCode","RdRecord01"));
                 if(cCode!=null){
-                    map.put("cCode",cCode+1);
+                    map.put("cCode",cCode);
                 }else{
                     throw new RuntimeException("获取入库单号失败");
                 }
@@ -105,18 +123,21 @@ public class PurchaseWarehousingServiceImpl extends ServiceImpl<PurchaseWarehous
                     Integer rowId=1;
                     String message="";
                     for(Map<String,Object> itemMap:itemList){
-                        //获取子表最大编码
-                        itemMap.put("AutoID",getMaxId("AutoID","rdrecords01"));
+                        //获取子表最大id
+                        itemMap.put("AutoID",oConvertUtils.addOne(getMaxId("AutoID","rdrecords01")));
                         //主表id
                         itemMap.put("ID",map.get("ID"));
                         //行号
                         itemMap.put("irowno",rowId);
                         //订单号
                         itemMap.put("cPOID",String.valueOf(map.get("cOrderCode")));
+                        String rowmId="";
                         //订单子表id
                         if(map.get("cRdCode").toString().equals("11")){
                             itemMap.put("iPOsID",itemMap.get("moDetailId"));//采购订单行id
                             itemMap.put("iOMoDID","");//委外订单行id
+                            rowmId=String.valueOf(itemMap.get("moDetailId"));
+
                         }else{//委外入库
                             itemMap.put("iPOsID","");//采购订单行id
                             itemMap.put("iOMoDID",itemMap.get("moDetailId"));//委外订单行id
@@ -128,7 +149,14 @@ public class PurchaseWarehousingServiceImpl extends ServiceImpl<PurchaseWarehous
                             }else{
                                 message=message+"缺少委外订单行id;";
                             }
+                            rowmId=String.valueOf(itemMap.get("moDetailId"));
+                        }
+                        //如果是红字入库则处理是否需要做结算单
+                        if(map.get("cVouchType").toString().equals("1")){
+                            //保存结算单
+//                            savePurSettleVouch(map,itemMap,rowmId);
                         }
+
                         rowId++;
                     }
                     if(StringUtils.isNotBlank(message)){
@@ -140,13 +168,79 @@ public class PurchaseWarehousingServiceImpl extends ServiceImpl<PurchaseWarehous
         }
     }
 
+    public void savePurSettleVouch(Map<String,Object> map,Map<String,Object> itemMap,String rowmId){
+        BigDecimal rdiQuantity=getDecimalNew(String.valueOf(itemMap.get("iQuantity")));
+        BigDecimal decimal=this.baseMapper.getRdrecords01WriteQuantity(rowmId);
+        //根据红字查询对应的蓝字入库的未做发票的数量判断是否有且是否大于红字入库数量
+        if(decimal!=null&&decimal.doubleValue()>0.0&&decimal.doubleValue()>rdiQuantity.doubleValue()){
+            Map<String,Object> mapPurSettleVouch=new HashMap<>();
+            Map<String,Object> mapPurSettleVouchs=new HashMap<>();
+            //主表
+            mapPurSettleVouch.put("PSVID",oConvertUtils.addOne(getMaxId("PSVID","PurSettleVouch")));
+            mapPurSettleVouch.put("cSVCode",oConvertUtils.addOne(getMaxId("cSVCode","PurSettleVouch")));
+            mapPurSettleVouch.put("cVenCode",map.get("cVenCode"));
+            mapPurSettleVouch.put("cDepCode",map.get("cDepCode"));
+            mapPurSettleVouch.put("cPersonCode",map.get("cPersonCode"));
+            mapPurSettleVouch.put("cPTCode",map.get("cPTCode"));
+            //子表
+            mapPurSettleVouchs.put("cPIVCode",map.get("cCode"));//入库单号
+            mapPurSettleVouchs.put("cInvCode",itemMap.get("cInvCode"));//存货编码
+            mapPurSettleVouchs.put("iSVQuantity",itemMap.get("iQuantity"));//结算数量
+
+            BigDecimal money=new BigDecimal("0.0");//金额
+            BigDecimal iNatUnitPrice=new BigDecimal("0.0");//单价
+            BigDecimal iPerTaxRate=new BigDecimal("0.0");//税率
+            //根据业务类型取不同的值
+            if(map.get("cRdCode").toString().equals("11")){//采购入库
+                mapPurSettleVouch.put("cBusType","普通采购");
+                //获取采购订单行的本币单价
+                Map<String,Object> mappoPoDetails=this.baseMapper.getPOPodetailsINatUnitPrice(rowmId);
+
+                if(mappoPoDetails!=null){
+                    if(mappoPoDetails.get("iNatUnitPrice")!=null){
+                        iNatUnitPrice=getDecimalNew(String.valueOf(mappoPoDetails.get("iNatUnitPrice")));//单价
+                        money=rdiQuantity.multiply(iNatUnitPrice);//单价*数量获取金额
+                    }
+                    if(mappoPoDetails.get("iPerTaxRate")!=null){
+                        iPerTaxRate=getDecimalNew(String.valueOf(mappoPoDetails.get("iPerTaxRate")));
+                    }
+
+                }
+
+            }else{//委外入库
+                mapPurSettleVouch.put("cBusType","委外加工");
+            }
+            //主
+            mapPurSettleVouch.put("iTaxRate",iPerTaxRate.doubleValue());
+            //子
+            mapPurSettleVouchs.put("iSVCost",iNatUnitPrice.doubleValue());//结算单价
+            mapPurSettleVouchs.put("iSVPrice",money.doubleValue());//结算金额
+            mapPurSettleVouchs.put("iSVACost",iNatUnitPrice.doubleValue());//暂估单价
+            mapPurSettleVouchs.put("iSVAPrice",money.doubleValue());//暂估金额
+            mapPurSettleVouchs.put("ID",oConvertUtils.addOne(getMaxId("ID","PurSettleVouchs")));//ID
+            mapPurSettleVouchs.put("PSVID",mapPurSettleVouch.get("PSVID"));//主表id
+            mapPurSettleVouchs.put("iRdsID",mapPurSettleVouch.get("PSVID"));//蓝字入库单id ???
+            mapPurSettleVouchs.put("crdcvencode",map.get("cVenCode"));//入库单单据类型
+            this.baseMapper.savePurSettleVouch(mapPurSettleVouch);
+            this.baseMapper.savePurSettleVouchs(mapPurSettleVouchs);
+        }
+    }
+
+    public BigDecimal getDecimalNew(String d){
+        if(StringUtils.isEmpty(d)){
+            d="0.0";
+        }
+        BigDecimal decimal= new BigDecimal(d);
+        return decimal;
+    }
+
     //保存调拨单
     public void saveTransVouch(Map<String,Object> rdRecord01Map){
         Map<String,Object> transVouchMao=new HashMap<>();
         //获取主表最大ID
-        transVouchMao.put("ID",getMaxId("ID","TransVouch"));
+        transVouchMao.put("ID",oConvertUtils.addOne(getMaxId("ID","TransVouch")));
         //获取最大编码
-        transVouchMao.put("cTVCode",getMaxId("cTVCode","TransVouch"));
+        transVouchMao.put("cTVCode",oConvertUtils.addOne(getMaxId("cTVCode","TransVouch")));
         //单据日期
         Date date=new Date();
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -188,12 +282,12 @@ public class PurchaseWarehousingServiceImpl extends ServiceImpl<PurchaseWarehous
     }
 
     @Override
-    public Integer getMaxId(String id, String tableName) {
-        Integer maxId=purchaseWarehousingMapper.getMaxId(id,tableName);
+    public String getMaxId(String id, String tableName) {
+        String maxId=purchaseWarehousingMapper.getMaxId(id,tableName);
         if(maxId!=null){
-            maxId=maxId+1;
+//            maxId=maxId+1;
         }else{
-            maxId=0;
+            maxId="0";
         }
         return maxId;
     }