浏览代码

面辅料结算单和成本分配面料金额调整

huxy 9 小时之前
父节点
当前提交
8f7f57625b

+ 98 - 40
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/mapper/xml/SyCostAllocationMapper.xml

@@ -549,49 +549,107 @@
 
     </select>-->
 
-    <select id="queryPurBillVouchByFabric" resultType="org.jeecg.modules.cost.entity.SyCostAllocation">
-
+    <!--<select id="queryPurBillVouchByFabric" resultType="org.jeecg.modules.cost.entity.SyCostAllocation">
+        select t.cInvName,sum(t.iOriSum) as fabriccostIncludestax,sum(t.iNotOriMoney) as fabriccostNotincludestax, sum(t.cExchRate) as fabriccostIncludestaxUsd,sum(t.invoiceQuantity) as invoiceQuantity from (
+        select omi.cInvName as cInvName,sum(pbs.iOriSum) as iOriSum,sum(round(pbs.iOriSum/1.13,4)) as iNotOriMoney,CONVERT(DECIMAL(38,2),sum(pbs.iOriSum)/max(so.iExchRate)) as cExchRate,sum(pbs.iPBVQuantity) as invoiceQuantity
+        from UFDATA_101_2021.dbo.PO_Pomain pm
+        join UFDATA_101_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
+        join UFDATA_101_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
+        join UFDATA_101_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
+        join UFDATA_101_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
+        join UFDATA_101_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
+        where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
+        and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001','T030001')
+        group by omi.cInvName
+            UNION ALL
+        select omi.cInvName as cInvName,sum(pbs.iOriSum) as iOriSum,sum(round(pbs.iOriSum/1.13,2)) as iNotOriMoney,CONVERT(DECIMAL(38,2),sum(pbs.iOriSum)/max(so.iExchRate)) as cExchRate,sum(pbs.iPBVQuantity) as invoiceQuantity
+        from UFDATA_102_2021.dbo.PO_Pomain pm
+        join UFDATA_102_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
+        join UFDATA_102_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
+        join UFDATA_102_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
+        join UFDATA_102_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
+        join UFDATA_102_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
+        where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
+         and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001')
+        group by omi.cInvName
+            UNION ALL
+        select omi.cInvName as cInvName,sum(pbs.iOriSum) as iOriSum,sum(round(pbs.iOriSum/1.13,4)) as iNotOriMoney,CONVERT(DECIMAL(38,2),sum(pbs.iOriSum)/max(so.iExchRate)) as cExchRate,sum(pbs.iPBVQuantity) as invoiceQuantity
+        from UFDATA_103_2021.dbo.PO_Pomain pm
+        join UFDATA_103_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
+        join UFDATA_103_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
+        join UFDATA_103_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
+        join UFDATA_103_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
+        join UFDATA_103_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
+        where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
+        and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001')
+        group by omi.cInvName) t where t.iOriSum is not null group by t.cInvName
+	</select>-->
 
-	select t.cInvName,sum(t.iOriSum) as fabriccostIncludestax,sum(t.iNotOriMoney) as fabriccostNotincludestax, sum(t.cExchRate) as fabriccostIncludestaxUsd,sum(t.invoiceQuantity) as invoiceQuantity from (
-	select omi.cInvName as cInvName,sum(pbs.iOriSum) as iOriSum,sum(round(pbs.iOriSum/1.13,4)) as iNotOriMoney,CONVERT(DECIMAL(38,2),sum(pbs.iOriSum)/max(so.iExchRate)) as cExchRate,sum(pbs.iPBVQuantity) as invoiceQuantity
-	from UFDATA_101_2021.dbo.PO_Pomain pm
-	join UFDATA_101_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
-	join UFDATA_101_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
-	join UFDATA_101_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
-	join UFDATA_101_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
-		join UFDATA_101_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
-	where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
-	 and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001','T030001')
-   group by omi.cInvName
-	UNION ALL
-
-select omi.cInvName as cInvName,sum(pbs.iOriSum) as iOriSum,sum(round(pbs.iOriSum/1.13,2)) as iNotOriMoney,CONVERT(DECIMAL(38,2),sum(pbs.iOriSum)/max(so.iExchRate)) as cExchRate,sum(pbs.iPBVQuantity) as invoiceQuantity
- from UFDATA_102_2021.dbo.PO_Pomain pm
-	join UFDATA_102_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
-	join UFDATA_102_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
-	join UFDATA_102_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
-	join UFDATA_102_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
-		join UFDATA_102_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
-	where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
-	 and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001')
-group by omi.cInvName
-		UNION ALL
-
-
-select omi.cInvName as cInvName,sum(pbs.iOriSum) as iOriSum,sum(round(pbs.iOriSum/1.13,4)) as iNotOriMoney,CONVERT(DECIMAL(38,2),sum(pbs.iOriSum)/max(so.iExchRate)) as cExchRate,sum(pbs.iPBVQuantity) as invoiceQuantity
- from UFDATA_103_2021.dbo.PO_Pomain pm
-	join UFDATA_103_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
-	join UFDATA_103_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
-	join UFDATA_103_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
-	join UFDATA_103_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
-		join UFDATA_103_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
-	where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
-	and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001')
-	group by omi.cInvName
-		) t where t.iOriSum is not null group by t.cInvName
 
+    <select id="queryPurBillVouchByFabric" resultType="org.jeecg.modules.cost.entity.SyCostAllocation">
 
-	</select>
+        select t.cInvName,
+        sum(t.iOriSum) as fabriccostIncludestax,sum(t.iNotOriMoney) as fabriccostNotincludestax, sum(t.cExchRate) as fabriccostIncludestaxUsd,sum(t.invoiceQuantity) as invoiceQuantity from (
+        select omi.cInvName as cInvName,
+        /*人民币含税金额取本币含税金额*/
+        SUM(pbs.iSum) as iOriSum,
+        /*人民币不含税金额 美元税率设置为0*/
+        sum(case when pb.cexch_name='美元' then pbs.iSum else round(pbs.iSum/1.13,4) end ) as iNotOriMoney,
+        /*美元金额*/
+        sum(case when pb.cexch_name='美元' then pbs.iOriSum else 0 end)+
+        CONVERT(DECIMAL(38,2),SUM(case when pb.cexch_name!='美元' THEN pbs.iSum ELSE 0 END)/max(so.iExchRate)) as cExchRate,
+
+        sum(pbs.iPBVQuantity) as invoiceQuantity
+        from UFDATA_101_2021.dbo.PO_Pomain pm
+        join UFDATA_101_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
+        join UFDATA_101_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
+        join UFDATA_101_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
+        join UFDATA_101_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
+        join UFDATA_101_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
+        where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
+        and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001','T030001')
+        group by omi.cInvName
+        UNION ALL
+
+        select omi.cInvName as cInvName,
+        /*人民币含税金额*/
+        SUM(pbs.iSum) as iOriSum,
+        /*人民币不含税金额 美元税率设置为0*/
+        sum(case when pb.cexch_name='美元' then pbs.iSum else round(pbs.iSum/1.13,4) end ) as iNotOriMoney,
+        /*美元金额*/
+        sum(case when pb.cexch_name='美元' then pbs.iOriSum else 0 end)+
+        CONVERT(DECIMAL(38,2),SUM(case when pb.cexch_name!='美元' THEN pbs.iSum ELSE 0 END)/max(so.iExchRate)) as cExchRate
+        ,sum(pbs.iPBVQuantity) as invoiceQuantity
+        from UFDATA_102_2021.dbo.PO_Pomain pm
+        join UFDATA_102_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
+        join UFDATA_102_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
+        join UFDATA_102_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
+        join UFDATA_102_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
+        join UFDATA_102_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
+        where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
+        and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001')
+        group by omi.cInvName
+        UNION ALL
+        select omi.cInvName as cInvName,
+        /*人民币含税金额*/
+        SUM(pbs.iSum) as iOriSum,
+        /*人民币不含税金额 美元税率设置为0*/
+        sum(case when pb.cexch_name='美元' then pbs.iSum else round(pbs.iSum/1.13,4) end ) as iNotOriMoney,
+        /*美元金额*/
+        sum(case when pb.cexch_name='美元' then pbs.iOriSum else 0 end)+
+        CONVERT(DECIMAL(38,2),SUM(case when pb.cexch_name!='美元' THEN pbs.iSum ELSE 0 END)/max(so.iExchRate)) as cExchRate,
+        sum(pbs.iPBVQuantity) as invoiceQuantity
+        from UFDATA_103_2021.dbo.PO_Pomain pm
+        join UFDATA_103_2021.dbo.PO_Podetails pd on pm.POID = pd.POID
+        join UFDATA_103_2021.dbo.PurBillVouchs pbs on pd.ID = pbs.iPOsID
+        join UFDATA_103_2021.dbo.PurBillVouch pb on pb.PBVID  = pbs.PBVID
+        join UFDATA_103_2021.dbo.Inventory omi on omi.cInvCode=pbs.cInvCode
+        join UFDATA_103_2021.dbo.SO_SOMain so on pd.csoordercode = so.csocode
+        where pm.cPOID like CONCAT('%',#{code},'%') and (omi.cInvCcode like '03%' or omi.cInvCcode like '04%') and omi.cInvCCode != '0399' and omi.cInvCCode != '0499' and omi.cInvCCode != '0299'
+        and omi.cInvCCode != '07'and omi.cInvCCode != '06'and omi.cInvCCode != '05' and pb.cVenCode not in('T010001','T020001')
+        group by omi.cInvName
+        ) t where t.iOriSum is not null group by t.cInvName
+    </select>
 
     <select id="querySalerIauantity" resultType="org.jeecg.modules.cost.entity.SyCostAllocation">
 

+ 9 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/service/impl/SyCostAllocationServiceImpl.java

@@ -486,7 +486,9 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
         BigDecimal notincludestaxTotal = BigDecimal.ZERO;
         //合计面料成本美元
         BigDecimal includestaxTotal = BigDecimal.ZERO;
+//        System.out.println("getFabriccostIncludestax\t"+str.getFabriccostIncludestax());
         if(fabriccostIncludestax.size()!=0){
+//            syCostAllocation.setTaxrate(new BigDecimal(0));
             for(SyCostAllocation str : fabriccostIncludestax){
                 for(SyCostAllocationFabric li:list3){
                     String goodsName=li.getGoodsName();
@@ -498,6 +500,9 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
                         if (li.getFabrictransferQuantity()!=null){
                             quantity=li.getUsageQuantity().subtract(li.getFabrictransferQuantity());
                         }
+                        //-- fabriccostincludestax=面料含税成本 fabriccostNotincludestax=面料不含税成本
+//                        System.out.println("getFabriccostIncludestax "+str.getFabriccostIncludestax()+" getFabriccostNotincludestax "+str.getFabriccostNotincludestax()
+//                                +"getFabriccostIncludestaxUsd"+str.getFabriccostIncludestaxUsd()+" getInvoiceQuantity "+str.getInvoiceQuantity()+" quantity "+quantity);
                         if (str.getInvoiceQuantity().compareTo(quantity)!=0){
                             BigDecimal money = str.getFabriccostIncludestax().divide(str.getInvoiceQuantity(),2,BigDecimal.ROUND_HALF_UP);
                             BigDecimal num = money.multiply(quantity);
@@ -513,6 +518,7 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
                             notincludestaxTotal = notincludestaxTotal.add(str.getFabriccostNotincludestax());
                             includestaxTotal = includestaxTotal.add(str.getFabriccostIncludestaxUsd());
                         }
+                        System.out.println(" getInvoiceQuantity "+str.getInvoiceQuantity()+" quantity "+quantity);
 //                            BigDecimal money = str.getFabriccostIncludestax().divide(str.getInvoiceQuantity(),2,BigDecimal.ROUND_HALF_UP);
 //                            BigDecimal num = money.multiply(li.getUsageQuantity());
 //                            usageQuantityTotal = usageQuantityTotal.add(num);
@@ -541,6 +547,7 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
             }else{
                 syCostAllocation.setFabriccostNotincludestax(notincludestaxTotal);
             }
+            System.out.println("includestaxTotal\t"+includestaxTotal+"  getFabriccostIncludestaxUsd  "+syCostAllocation.getFabriccostIncludestaxUsd());
             if (syCostAllocation.getFabriccostIncludestaxUsd()!=null){
                 syCostAllocation.setFabriccostIncludestaxUsd(syCostAllocation.getFabriccostIncludestaxUsd().add(includestaxTotal));
             }else{
@@ -749,8 +756,8 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
                     syCostAllocation.setExcipiencostIncludestaxUsd(BigDecimal.ZERO);
                 }
                 //人民币金额 RmbAmount+ 辅料含税成本 ExcipiencostIncludestax
-                //System.out.println("getRmbAmount\t"+Ingredient.getRmbAmount()+"getExcipiencostIncludestax\t"+syCostAllocation.getExcipiencostIncludestax());
-                syCostAllocation.setExcipiencostIncludestax(Ingredient.getRmbAmount().add(syCostAllocation.getExcipiencostIncludestax()));
+                 //System.out.println("getRmbAmount\t"+Ingredient.getRmbAmount()+"getExcipiencostIncludestax\t"+syCostAllocation.getExcipiencostIncludestax());
+                  syCostAllocation.setExcipiencostIncludestax(Ingredient.getRmbAmount().add(syCostAllocation.getExcipiencostIncludestax()));
                 syCostAllocation.setExcipiencostIncludestaxUsd(Ingredient.getUsdAmount().add(syCostAllocation.getExcipiencostIncludestaxUsd()));
 
             }

+ 55 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/splfi/service/impl/SyPackingListFabricServiceImpl.java

@@ -3064,9 +3064,11 @@ public class SyPackingListFabricServiceImpl extends ServiceImpl<SyPackingListFab
 		List<String> codes=getList3(listFabrics);//获取入库单号
 //		System.out.println("面辅料查看入库单号  "+codes);
 		listFabrics.forEach(f->{
+			//这里用来推送结算单
 //			System.out.println("单据号   "+f.getDocumentNo()+"  Rdrecord32Code  "+f.getRdrecord32Code());
 		});
 		if(codes.size()==0){
+			getList4(listFabrics);//获取入库单号
 			return "无可推送数据!";
 		}
 		Map<String,List<String>> customers=getSuppliers(listFabrics);//key:供应商编码,value:入库单单据号
@@ -3211,7 +3213,7 @@ public class SyPackingListFabricServiceImpl extends ServiceImpl<SyPackingListFab
 		text(jsonArrays2,"测试合并推送面辅料结算单");
 		JSONArray resturnJsonArrays = InterfaceConnUtils.doPost(jsonArrays1,"purinvoice_import");//采购发-票单
 		Map<String,String> codeMaps2 = result(resturnJsonArrays,"采购发票",account);
-		JSONArray resturnJsonArrays2 = InterfaceConnUtils.doPost(jsonArrays1,"purchasesettle_import");//结算单
+		JSONArray resturnJsonArrays2 = InterfaceConnUtils.doPost(jsonArrays2,"purchasesettle_import");//结算单
 		Map<String,String> codeMaps3 = result(resturnJsonArrays2,"结算单",account);
 		for (String code1 : codeMaps.keySet()){
 			List<SyPackingListFabric> listFabricList=codeMaps.get(code1);
@@ -3461,6 +3463,58 @@ public class SyPackingListFabricServiceImpl extends ServiceImpl<SyPackingListFab
 		return ids;
 	}
 
+	public List<String> getList4(List<SyPackingListFabric> listFabrics){
+		List<String> ids=new ArrayList<>();//获取出库单号
+		JSONArray jsonArrays2=new JSONArray();
+		Map<String,List<SyPackingListFabric>> codeMaps=new HashMap<>();//key:传入销售发票单id,value:主表数据
+		for (SyPackingListFabric syPackingListFabric : listFabrics){
+			String code=syPackingListFabric.getSaleInvoiceCode();
+			if(code!=null&&code.indexOf("101采购发票")>-1&&code.indexOf("101结算单")==-1 ){
+				String documentNo=code.substring(code.indexOf("101采购发票单号")+9,code.indexOf("101采购发票单号")+20);
+				if (!ids.contains(documentNo)){
+					List<SyPackingListFabric> fabricList=new ArrayList<>();
+					fabricList.add(syPackingListFabric);
+					codeMaps.put(documentNo,fabricList);
+					ids.add(documentNo);
+					JSONObject  jsonObject1=new JSONObject();
+					jsonObject1.put("CACCID","101");
+					jsonObject1.put("CMAKER","进出口平台管理员");
+					jsonObject1.put("CVOUCHCODE_U8",documentNo);
+					jsonObject1.put("DDATE",syPackingListFabric.getTheFinalShippingDate().substring(0,10));
+					jsonArrays2.add(jsonObject1);
+				}else{
+					List<SyPackingListFabric> fabricList=codeMaps.get(documentNo);
+					fabricList.add(syPackingListFabric);
+					codeMaps.put(documentNo,fabricList);
+				}
+			}
+		}
+		if (jsonArrays2.size()>0){
+			JSONArray resturnJsonArrays2 = InterfaceConnUtils.doPost(jsonArrays2,"purchasesettle_import");//结算单
+			Map<String,String> codeMaps3 = result(resturnJsonArrays2,"结算单","101");
+
+			for (String code1 : codeMaps.keySet()){
+				List<SyPackingListFabric> listFabricList=codeMaps.get(code1);
+				for (SyPackingListFabric fabric : listFabricList){
+					if (codeMaps3.get(code1).indexOf("失败")>-1){
+						if(fabric.getSaleInvoiceError()==null){
+							fabric.setSaleInvoiceError(codeMaps3.get(code1));
+						}else{
+							fabric.setSaleInvoiceError(fabric.getSaleInvoiceError()+";"+codeMaps3.get(code1));
+						}
+					}else{
+						if(fabric.getSaleInvoiceCode()==null){
+							fabric.setSaleInvoiceCode(codeMaps3.get(code1));
+						}else{
+							fabric.setSaleInvoiceCode(fabric.getSaleInvoiceCode()+";"+codeMaps3.get(code1));
+						}
+					}
+				}
+			}
+		}
+		return ids;
+	}
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public RespUpdateVO saveSrmBill(SyPackingListFabric syPackingListFabric){