Commit 36762c5d by wuwenlong

产副品制造成本核算dev

parent 67c1e27a
...@@ -97,6 +97,8 @@ public class HGCB005 extends DaoEPBase { ...@@ -97,6 +97,8 @@ public class HGCB005 extends DaoEPBase {
public static final String INSERT = "HGCB005.insert"; public static final String INSERT = "HGCB005.insert";
public static final String UPDATE = "HGCB005.update"; public static final String UPDATE = "HGCB005.update";
public static final String DELETE = "HGCB005.delete"; public static final String DELETE = "HGCB005.delete";
public static final String DELETE_BY_CONDITION = "HGCB005.delete_by_condition";
private Long id = new Long(0); private Long id = new Long(0);
private String accountCode = " "; /* 企业编码*/ private String accountCode = " "; /* 企业编码*/
...@@ -133,6 +135,25 @@ public class HGCB005 extends DaoEPBase { ...@@ -133,6 +135,25 @@ public class HGCB005 extends DaoEPBase {
private String processName = " "; /* 工序名称*/ private String processName = " "; /* 工序名称*/
private Long processOrder = new Long(0); /* 加工顺序*/ private Long processOrder = new Long(0); /* 加工顺序*/
private BigDecimal costWeight = new BigDecimal(0);
private BigDecimal costWeightValue = new BigDecimal(0);
public BigDecimal getCostWeight() {
return costWeight;
}
public void setCostWeight(BigDecimal costWeight) {
this.costWeight = costWeight;
}
public BigDecimal getCostWeightValue() {
return costWeightValue;
}
public void setCostWeightValue(BigDecimal costWeightValue) {
this.costWeightValue = costWeightValue;
}
/** /**
* initialize the metadata. * initialize the metadata.
*/ */
......
...@@ -350,6 +350,13 @@ ...@@ -350,6 +350,13 @@
id = #id# id = #id#
</delete> </delete>
<delete id="delete_by_condition">
DELETE FROM ${hggpSchema}.HGCB005 WHERE
company_code = #companyCode#, <!-- 公司编码 -->
account_year = #accountYear#, <!-- 会计期(年) -->
account_month = #accountMonth# <!-- 会计期(月) -->
</delete>
<update id="update"> <update id="update">
UPDATE ${hggpSchema}.HGCB005 UPDATE ${hggpSchema}.HGCB005
SET SET
......
...@@ -15,14 +15,12 @@ import com.baosight.hggp.hg.cb.domain.HGCB005; ...@@ -15,14 +15,12 @@ import com.baosight.hggp.hg.cb.domain.HGCB005;
import com.baosight.hggp.hg.cg.domain.HGCG003; import com.baosight.hggp.hg.cg.domain.HGCG003;
import com.baosight.hggp.hg.constant.HGConstant; import com.baosight.hggp.hg.constant.HGConstant;
import com.baosight.hggp.hg.constant.HGSqlConstant; import com.baosight.hggp.hg.constant.HGSqlConstant;
import com.baosight.hggp.hg.cw.domain.HGCW001; import com.baosight.hggp.hg.cw.domain.*;
import com.baosight.hggp.hg.cw.domain.HGCW012;
import com.baosight.hggp.hg.cw.domain.HGCW012A;
import com.baosight.hggp.hg.cw.domain.HGCW013;
import com.baosight.hggp.hg.cw.tools.HGCWTools; import com.baosight.hggp.hg.cw.tools.HGCWTools;
import com.baosight.hggp.hg.kc.domain.*; import com.baosight.hggp.hg.kc.domain.*;
import com.baosight.hggp.hg.kc.tools.HGKCTools; import com.baosight.hggp.hg.kc.tools.HGKCTools;
import com.baosight.hggp.hg.pz.domain.HGPZ005; import com.baosight.hggp.hg.pz.domain.HGPZ005;
import com.baosight.hggp.hg.pz.domain.HGPZ005A;
import com.baosight.hggp.hg.pz.domain.HGPZ007; import com.baosight.hggp.hg.pz.domain.HGPZ007;
import com.baosight.hggp.hg.pz.tools.HGPZTools; import com.baosight.hggp.hg.pz.tools.HGPZTools;
import com.baosight.hggp.hg.sc.domain.HGSC005A; import com.baosight.hggp.hg.sc.domain.HGSC005A;
...@@ -620,6 +618,10 @@ public class HGCBTools { ...@@ -620,6 +618,10 @@ public class HGCBTools {
} }
public static class THGCB005 { public static class THGCB005 {
public static void deleteByCondition(Map params){
DaoBase.getInstance().delete(HGCB005.DELETE_BY_CONDITION, params);
}
/** /**
* 同步数据 * 同步数据
* *
...@@ -639,20 +641,71 @@ public class HGCBTools { ...@@ -639,20 +641,71 @@ public class HGCBTools {
//入库单按项目编码、产品编码、存货工序ID、规格、单重分组,分别取正向入库单数量、重量和退回数量 //入库单按项目编码、产品编码、存货工序ID、规格、单重分组,分别取正向入库单数量、重量和退回数量
//生成制造成本基础数据 //生成制造成本基础数据
List<HGCB005> hgcb005List = constractHGCB005(hgcw001,hgkc003List); List<HGCB005> hgcb005List = constractHGCB005(hgcw001,hgkc003List);
//设置权重
setingCostWeight(hgcb005List);
//计算项目总成本
Map<String,BigDecimal> totalAmoutMap = calculateProjAmout(hgcw001);
//计算产副品成本:权重值*项目总费用=产副品制造总成本;总成本/数量=单位成本
Optional.ofNullable(hgcb005List).orElse(new ArrayList<>()).stream().forEach( o -> {
BigDecimal totalAmout = totalAmoutMap.get(o.getProjCode());
o.setTotalCost(totalAmout.multiply(o.getCostWeightValue()).setScale(6,RoundingMode.HALF_UP));
o.setUnitCost(o.getTotalCost().divide(o.getQuantity(),6,RoundingMode.HALF_UP));
});
//按公司删除当前会计起的成本核算数据
Map cb005DeleteParam = new HashMap();
cb005DeleteParam.put(HGCB005.FIELD_company_code,hgcw001.getCompanyCode());
cb005DeleteParam.put(HGCB005.FIELD_account_year,hgcw001.getAccountYear());
cb005DeleteParam.put(HGCB005.FIELD_account_month,hgcw001.getAccountPeriod().substring(4));
deleteByCondition(cb005DeleteParam);
//保存新的成本核算数据
if(CollectionUtils.isNotEmpty(hgcb005List)){
DaoBase.getInstance().insertBatch(HGCB005.INSERT, hgcb005List);
}
}
}
private static Map<String,BigDecimal> calculateProjAmout(HGCW001 hgcw001){
//通过业务账期信息查询类型为分摊的费用归集数据,按项目分组金额求和
Map cw052ParamMap = new HashMap();
cw052ParamMap.put(HGCW052.FIELD_COMPANY_CODE,hgcw001.getCompanyCode());
cw052ParamMap.put(HGCW052.FIELD_YEAR,hgcw001.getAccountYear());
cw052ParamMap.put(HGCW052.FIELD_MONTH,hgcw001.getAccountPeriod().substring(4));
cw052ParamMap.put(HGCW052.FIELD_IS_SHARE, CommonConstant.YesNo.YES_1);
List<HGCW052> hgcw052List = HGCWTools.HgCw052.listByCondition(cw052ParamMap);
Map<String,BigDecimal> totalAmoutMap = Optional.ofNullable(hgcw052List).orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(
o->o.getItemCode(),
Collectors.reducing(
BigDecimal.ZERO,HGCW052::getAmount,BigDecimal::add))
);
return totalAmoutMap;
}
private static void setingCostWeight(List<HGCB005> hgcb005List){
//通过存货工序ID查询工序权重 //通过存货工序ID查询工序权重
List<Long> processIds = Optional.ofNullable(hgcb005List).orElse(new ArrayList<>()).stream().map(HGCB005::getInventProcessId).collect(Collectors.toList()); List<Long> processIds = Optional.ofNullable(hgcb005List).orElse(new ArrayList<>()).stream().map(HGCB005::getInventProcessId).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(processIds)){ List<HGPZ005A> hgpz005aList = HGPZTools.HgPz005A.queryByIds(processIds);
List<HGPZ005> hgpz005List = HGPZTools.HgPz005.getIds(processIds); Map<Long,HGPZ005A> hgpz005aMap = Optional.ofNullable(hgpz005aList).orElse(new ArrayList<>()).stream().collect(Collectors.toMap(
Map<Long,HGPZ005> hgpz005Map = Optional.ofNullable(hgpz005List).orElse(new ArrayList<>()).stream().collect(Collectors.toMap( HGPZ005A::getId,
HGPZ005::getId,
o->o, o->o,
(o1,o2)->o1 (o1,o2)->o1
)); ));
} //设置权重,入库重量*工序权重=产副品权重
//通过业务账期信息查询类型为分摊的费用归集数据,按项目分组金额求和 Optional.ofNullable(hgcb005List).orElse(new ArrayList<>()).stream().forEach(o -> {
HGPZ005A hgpz005a = hgpz005aMap.get(o.getInventProcessId());
//计算成本:入库重量*工序权重=产副品权重,SUM(产副品权重)=项目权重,产副品权重/项目权重*总费用=产副品制造总成本 AssertUtils.isNull(hgpz005a,String.format("产品[%s]%s工艺工序配置缺失",o.getProductCode(),o.getProductName()));
} o.setCostWeight(o.getTotalWeight().multiply(hgpz005a.getCostWeight()).setScale(6,RoundingMode.HALF_UP));
});
//按项目分组求总权重,SUM(产副品权重)=项目权重
Map<String,BigDecimal> totalCostWeightMap = Optional.ofNullable(hgcb005List).orElse(new ArrayList<>()).stream().collect(
Collectors.groupingBy(HGCB005::getProjCode,Collectors.reducing(
BigDecimal.ZERO,HGCB005::getCostWeight,BigDecimal::add)));
//设置权重值 = 产副品权重/项目权重
Optional.ofNullable(hgcb005List).orElse(new ArrayList<>()).stream().forEach(o -> {
BigDecimal projCostWeight = totalCostWeightMap.get(o.getProjCode());
AssertUtils.isTrue(Objects.isNull(projCostWeight)||BigDecimal.ZERO.compareTo(projCostWeight)>=0
,String.format("项目[%s]%s总权重等于或小于0",o.getProjCode(),o.getProjName()));
o.setCostWeightValue(o.getCostWeight().divide(projCostWeight,6,RoundingMode.HALF_UP));
});
} }
private static List<HGCB005> constractHGCB005(HGCW001 hgcw001, List<HGKC003> hgkc003List){ private static List<HGCB005> constractHGCB005(HGCW001 hgcw001, List<HGKC003> hgkc003List){
......
...@@ -784,7 +784,12 @@ public class HGCWTools { ...@@ -784,7 +784,12 @@ public class HGCWTools {
} }
} }
public static class HgCw052{
public static List<HGCW052> listByCondition(Map param) {
return DaoBase.getInstance().query(HGCW052.QUERY,param);
}
}
public static class HgCw055{ public static class HgCw055{
public static void save(List<Map> rows, UserVO userVO) { public static void save(List<Map> rows, UserVO userVO) {
// AssertUtils.isNull(contractNumber, "合同号不能为空!"); // AssertUtils.isNull(contractNumber, "合同号不能为空!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment