package com.zzsmart.qomo.kn.cost.manage.vo;


import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostStandardBom;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostStandardProductprocess;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostStandardResult;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class StandardMatnr {
    public String posnr; //加入序号，保证唯一
    public String matnr;
    //public String oldversion;
    public String version;
    public String layer;
    public String werks;
    public double dosage=1;
    //public double batch=1;//批量
    //public String oldgroup;
    //public double parentUse=1;
    //public double totalcost=0;
    //public double totalcost7525=0;
    //public String pricetype="";
    public StandardCalculate stage=new StandardCalculate();//本阶
    public StandardCalculate accu_stage=new StandardCalculate();//累计
    public StandardCalculate struct_stage=new StandardCalculate();//结构成本
    //public Material material;
    //public List<StandardBom> bomRelevancyList=new ArrayList<>();//bom结构
    public List<AppSceneCostStandardProductprocess> productProcessMaintenanceList=new ArrayList<>();
    public AppSceneCostStandardResult standardResult=AppSceneCostStandardResult.builder().build();
    public AppSceneCostStandardBom standardBom=AppSceneCostStandardBom.builder().build();

    public List<StandardMatnr> childs=new ArrayList<>();

    public void CalTotal(){
        double totalcost= stage.getTotal()+accu_stage.getTotal();
        //double totalcost7525= stage.getTotal7525()+accu_stage.getTotal7525();
        standardResult.setTotalStandardCost(new BigDecimal(totalcost));
        //standardResult.setTotalStandardCostInter(new BigDecimal(totalcost7525));
    }

    public void CalStruct(){
        struct_stage.price=dosage*(stage.price+accu_stage.price);
        //struct_stage.price7525=dosage*(stage.price7525+accu_stage.price7525);
        struct_stage.pricezm=dosage*(stage.pricezm+accu_stage.pricezm);
        struct_stage.labor=dosage*(stage.labor+accu_stage.labor);
        struct_stage.equip=dosage*(stage.equip+accu_stage.equip);
        struct_stage.burning=dosage*(stage.burning+accu_stage.burning);
        struct_stage.auxi=dosage*(stage.auxi+accu_stage.auxi);
        struct_stage.other=dosage*(stage.other+accu_stage.other);
    }

//    public void GenerateStandardBom(){
//        standardResult.setMaterialCostStage(new BigDecimal(stage.price));
//        standardResult.setMaterialCostStageMaterial(new BigDecimal(stage.price_material));
//        standardResult.setMaterialCostStageEdcu(new BigDecimal(stage.price_edcu));
//        standardResult.setMaterialCostStageEm(new BigDecimal(stage.price_em));
//        standardResult.setMaterialCostStageInter(new BigDecimal(stage.price7525));
//        standardResult.setMaterialCostStageInterMaterial(new BigDecimal(stage.price7525_material));
//        standardResult.setMaterialCostStageInterEdcu(new BigDecimal(stage.price7525_edcu));
//        standardResult.setMaterialCostStageInterEm(new BigDecimal(stage.price7525_em));
//        standardResult.setLaborCostStage(new BigDecimal(stage.labor));
//        standardResult.setAuxiliaryCostStage(new BigDecimal(stage.auxi));
//        standardResult.setEquipCostStage(new BigDecimal(stage.equip));
//        standardResult.setBurningCostStage(new BigDecimal(stage.burning));
//        standardResult.setOtherCostStage(new BigDecimal(stage.other));
//
//        standardResult.setMaterialCostAccumulated(new BigDecimal(accu_stage.price));
//        standardResult.setMaterialCostAccumulatedMaterial(new BigDecimal(accu_stage.price_material));
//        standardResult.setMaterialCostAccumulatedEdcu(new BigDecimal(accu_stage.price_edcu));
//        standardResult.setMaterialCostAccumulatedEm(new BigDecimal(accu_stage.price_em));
//        standardResult.setMaterialCostAccumulatedInter(new BigDecimal(accu_stage.price7525));
//        standardResult.setMaterialCostAccumulatedInterMaterial(new BigDecimal(accu_stage.price7525_material));
//        standardResult.setMaterialCostAccumulatedInterEdcu(new BigDecimal(accu_stage.price7525_edcu));
//        standardResult.setMaterialCostAccumulatedInterEm(new BigDecimal(accu_stage.price7525_em));
//        standardResult.setLaborCostAccumulated(new BigDecimal(accu_stage.labor));
//        standardResult.setAuxiliaryCostAccumulated(new BigDecimal(accu_stage.auxi));
//        standardResult.setEquipCostAccumulated(new BigDecimal(accu_stage.equip));
//        standardResult.setBurningCostAccumulated(new BigDecimal(accu_stage.burning));
//        standardResult.setOtherCostAccumulated(new BigDecimal(accu_stage.other));
//
//        standardResult.setMaterialCostTotal(new BigDecimal(stage.price+accu_stage.price));
//        standardResult.setMaterialCostTotalInter(new BigDecimal(stage.price7525+accu_stage.price7525));
//        standardResult.setLaborCostTotal(new BigDecimal(stage.labor+accu_stage.labor));
//        standardResult.setAuxiliaryCostTotal(new BigDecimal(stage.auxi+accu_stage.auxi));
//        standardResult.setEquipCostTotal(new BigDecimal(stage.equip+accu_stage.equip));
//        standardResult.setBurningCostTotal(new BigDecimal(stage.burning+accu_stage.burning));
//        standardResult.setOtherCostTotal(new BigDecimal(stage.other+accu_stage.other));
//
//        standardResult.setMaterialCostRelative(new BigDecimal(struct_stage.price));
//        standardResult.setMaterialCostRelativeInter(new BigDecimal(struct_stage.price7525));
//        standardResult.setLaborCostRelative(new BigDecimal(struct_stage.labor));
//        standardResult.setManufactureCostRelative(new BigDecimal(struct_stage.getproduct()));
//        standardResult.setTotalCostRelative(new BigDecimal(struct_stage.getTotal()));
//        standardResult.setTotalCostRelativeInter(new BigDecimal(struct_stage.getTotal7525()));
//
//        standardResult.setRelativeDosage(new BigDecimal(dosage));
//    }

    public void GenerateStandardCalculate(){
        stage.price=standardResult.getMaterialCost().doubleValue();
        //stage.price7525=standardResult.getMaterialCostStageInter().doubleValue();
        stage.labor=standardResult.getLaborCost().doubleValue();
        stage.auxi=standardResult.getAuxiliaryCost().doubleValue();
        stage.equip=standardResult.getEquipCost().doubleValue();
        stage.burning=standardResult.getFuelCost().doubleValue();
        stage.other=standardResult.getOtherCost().doubleValue();

        accu_stage.price=standardResult.getMaterialCostTotal().doubleValue()-stage.price;
        //accu_stage.price7525=standardResult.getMaterialCostAccumulatedInter().doubleValue();
        accu_stage.labor=standardResult.getLaborCostTotal().doubleValue()-stage.labor;
        accu_stage.auxi=standardResult.getAuxiliaryCostTotal().doubleValue()-stage.auxi;
        accu_stage.equip=standardResult.getEquipCostTotal().doubleValue()-stage.equip;
        accu_stage.burning=standardResult.getFuelCostTotal().doubleValue()-stage.burning;
        accu_stage.other=standardResult.getOtherCostTotal().doubleValue()-stage.other;
    }

    public double getParentUse(){
        if(standardBom.getMenge()!=null){
            return standardBom.getMenge().doubleValue();
        }else
            return 1;
    }

//    public double getBatch(){
//        if(standardBom.getBatch()!=null){
//            return standardBom.getBatch().doubleValue();
//        }else
//            return 1;
//    }

    //public void setBatch(double batch){
    //    standardBom.setBatch(new BigDecimal(batch));
    //}

    public class StandardCalculate{
        public boolean hasprice=false;
        public boolean has7525price=false;
        public double price=0;           //电子成本
        public double price_material=0;           //电子成本-材料
        public double price_edcu=0;           //电子成本-门控
        public double price_em=0;           //电子成本-电机
        //public double price7525=0;      //7525成本
        //public double price7525_material=0;           //7525成本-材料
        //public double price7525_edcu=0;           //7525成本-门控
        //public double price7525_em=0;           //7525成本-电机
        public double pricezm=0;                //账面成本
        public double pricezm_edcu=0;           //账面成本-门控
        public double labor;//人工
        public double equip;//设备
        public double burning;//燃动
        public double auxi;//辅料
        public double other;//其他
        public boolean bCNY=true;

        public double getTotal(){
            return price+labor+equip+burning+auxi+other;
        }

        //public double getTotal7525(){
        //    return price7525+labor+equip+burning+auxi+other;
        //}

        public double getTotalzm(){
            return pricezm+labor+equip+burning+auxi+other;
        }

        public double getproduct(){
            return equip+burning+auxi+other;
        }
    }
}
