unit CalcData;

interface

type
  TCalcData = class
  private
    FQuantity: Double;
    FTotalPrice: Double;
  public
    constructor Create; virtual;

    procedure AddQuantity(AValue: Double);
    procedure AddTotalPrice(AValue: Double);

    property Quantity: Double read FQuantity write FQuantity;
    property TotalPrice: Double read FTotalPrice write FTotalPrice;
  end;

  TReCalcData = class(TCalcData)
  private
    FTotalPrice_Rc: Double;
  public
    constructor Create; override;

    property TotalPrice_Rc: Double read FTotalPrice_Rc write FTotalPrice_Rc;
  end;

  TCompileCalc = class
  private
    FOrg: TReCalcData;
    FMis: TReCalcData;
    FOth: TReCalcData;
    FSubTotal: TReCalcData;
  public
    constructor Create;
    destructor Destroy; override;

    procedure InitTotalPrice_Rc;
    procedure UpdateTotalPrice_Rc(ACalc: TCompileCalc);
    procedure CalcTotalPrice_Rc(APrice: Double);

    procedure InitCalcData;
    procedure AddCalcData(ACalc: TCompileCalc);
    procedure MinusCalcData(ACalc: TCompileCalc);

    property Org: TReCalcData read FOrg write FOrg;
    property Mis: TReCalcData read FMis write FMis;
    property Oth: TReCalcData read FOth write FOth;
    property SubTotal: TReCalcData read FSubTotal write FSubTotal;
  end;

  TMeasureCalc = class
  private
    FDeal: TReCalcData;
    FQc: TReCalcData;
    FGather: TReCalcData;
  public
    constructor Create;
    destructor Destroy; override;

    procedure InitTotalPrice_Rc;
    procedure UpdateTotalPrice_Rc(ACalc: TMeasureCalc);
    procedure CalcTotalPrice_Rc(APrice: Double);

    procedure InitCalcData;
    procedure AddCalcData(ACalc: TMeasureCalc);
    procedure MinusCalcData(ACalc: TMeasureCalc);

    property Deal: TReCalcData read FDeal write FDeal;
    property Qc: TReCalcData read FQc write FQc;
    property Gather: TReCalcData read FGather write FGather;
  end;

  TProjCalc = class
  private
    FCompile: TCompileCalc;
    FAddMeasure: TMeasureCalc;
    FCurMeasure: TMeasureCalc;
    FPreMeasure: TMeasureCalc;
    FEndMeasure: TMeasureCalc;
    FZoneMeasure: TMeasureCalc;

    FDgnQuantity1: Double;
    FDgnQuantity2: Double;
    FDealDgnQuantity1: Double;
    FDealDgnQuantity2: Double;
    FCDgnQuantity1: Double;
    FCDgnQuantity2: Double;
  public
    constructor Create;
    destructor Destroy; override;

    procedure InitTotalPrice_Rc;
    procedure UpdateTotalPrice_Rc(AProjCalc: TProjCalc);
    procedure CalcTotalPrice_Rc(APrice: Double);

    procedure InitCalcData;
    procedure AddCalcData(AProjCalc: TProjCalc);
    procedure MinusCalcData(AProjCalc: TProjCalc);

    property Compile: TCompileCalc read FCompile;
    property AddMeasure: TMeasureCalc read FAddMeasure;
    property CurMeasure: TMeasureCalc read FCurMeasure;
    property PreMeasure: TMeasureCalc read FPreMeasure;
    property EndMeasure: TMeasureCalc read FEndMeasure;
    property ZoneMeasure: TMeasureCalc read FZoneMeasure;

    property DgnQuantity1: Double read FDgnQuantity1 write FDgnQuantity1;
    property DgnQuantity2: Double read FDgnQuantity2 write FDgnQuantity2;
    property DealDgnQuantity1: Double read FDealDgnQuantity1 write FDealDgnQuantity1;
    property DealDgnQuantity2: Double read FDealDgnQuantity2 write FDealDgnQuantity2;
    property CDgnQuantity1: Double read FCDgnQuantity1 write FCDgnQuantity1;
    property CDgnQuantity2: Double read FCDgnQuantity2 write FCDgnQuantity2;
  end;

implementation

{ TCompileCalc }

procedure TCompileCalc.AddCalcData(ACalc: TCompileCalc);
begin
  Org.TotalPrice := Org.TotalPrice + ACalc.Org.TotalPrice;
  Mis.TotalPrice := Mis.TotalPrice + ACalc.Mis.TotalPrice;
  Oth.TotalPrice := Oth.TotalPrice + ACalc.Oth.TotalPrice;
  SubTotal.TotalPrice := SubTotal.TotalPrice + ACalc.SubTotal.TotalPrice;
  Org.TotalPrice_Rc := Org.TotalPrice_Rc + ACalc.Org.TotalPrice_Rc;
  Mis.TotalPrice_Rc := Mis.TotalPrice_Rc + ACalc.Mis.TotalPrice_Rc;
  Oth.TotalPrice_Rc := Oth.TotalPrice_Rc + ACalc.Oth.TotalPrice_Rc;
  SubTotal.TotalPrice_Rc := SubTotal.TotalPrice_Rc + ACalc.SubTotal.TotalPrice_Rc;
end;

procedure TCompileCalc.CalcTotalPrice_Rc(APrice: Double);
begin
  Org.TotalPrice_Rc := Org.Quantity * APrice;
  Mis.TotalPrice_Rc := Mis.Quantity * APrice;
  Oth.TotalPrice_Rc := Oth.Quantity * APrice;
  SubTotal.TotalPrice_Rc := SubTotal.Quantity * APrice;
end;

constructor TCompileCalc.Create;
begin
  FOrg := TReCalcData.Create;
  FMis := TReCalcData.Create;
  FOth := TReCalcData.Create;
  FSubTotal := TReCalcData.Create;
end;

destructor TCompileCalc.Destroy;
begin
  FOrg.Free;
  FMis.Free;
  FOth.Free;
  FSubTotal.Free;
  inherited;
end;

procedure TCompileCalc.InitCalcData;
begin
  Org.TotalPrice := 0;
  Mis.TotalPrice := 0;
  Oth.TotalPrice := 0;
  SubTotal.TotalPrice := 0;
  InitTotalPrice_Rc;
end;

procedure TCompileCalc.InitTotalPrice_Rc;
begin
  Org.TotalPrice_Rc := 0;
  Mis.TotalPrice_Rc := 0;
  Oth.TotalPrice_Rc := 0;
  SubTotal.TotalPrice_Rc := 0;
end;

procedure TCompileCalc.MinusCalcData(ACalc: TCompileCalc);
begin
  Org.TotalPrice := Org.TotalPrice - ACalc.Org.TotalPrice;
  Mis.TotalPrice := Mis.TotalPrice - ACalc.Mis.TotalPrice;
  Oth.TotalPrice := Oth.TotalPrice - ACalc.Oth.TotalPrice;
  SubTotal.TotalPrice := SubTotal.TotalPrice - ACalc.SubTotal.TotalPrice;
  Org.TotalPrice_Rc := Org.TotalPrice_Rc - ACalc.Org.TotalPrice_Rc;
  Mis.TotalPrice_Rc := Mis.TotalPrice_Rc - ACalc.Mis.TotalPrice_Rc;
  Oth.TotalPrice_Rc := Oth.TotalPrice_Rc - ACalc.Oth.TotalPrice_Rc;
  SubTotal.TotalPrice_Rc := SubTotal.TotalPrice_Rc - ACalc.SubTotal.TotalPrice_Rc;
end;

procedure TCompileCalc.UpdateTotalPrice_Rc(ACalc: TCompileCalc);
begin
  Org.TotalPrice_Rc := Org.TotalPrice_Rc + ACalc.Org.TotalPrice_Rc;
  Mis.TotalPrice_Rc := Mis.TotalPrice_Rc + ACalc.Mis.TotalPrice_Rc;
  Oth.TotalPrice_Rc := Oth.TotalPrice_Rc + ACalc.Oth.TotalPrice_Rc;
  SubTotal.TotalPrice_Rc := SubTotal.TotalPrice_Rc + ACalc.SubTotal.TotalPrice_Rc;
end;

{ TMeasureCalc }

procedure TMeasureCalc.AddCalcData(ACalc: TMeasureCalc);
begin
  Deal.TotalPrice := Deal.TotalPrice + ACalc.Deal.TotalPrice;
  Qc.TotalPrice := Qc.TotalPrice + ACalc.Qc.TotalPrice;
  Gather.TotalPrice := Gather.TotalPrice + ACalc.Gather.TotalPrice;
  Deal.TotalPrice_Rc := Deal.TotalPrice_Rc + ACalc.Deal.TotalPrice_Rc;
  Qc.TotalPrice_Rc := Qc.TotalPrice_Rc + ACalc.Qc.TotalPrice_Rc;
  Gather.TotalPrice_Rc := Gather.TotalPrice_Rc + ACalc.Gather.TotalPrice_Rc;
end;

procedure TMeasureCalc.CalcTotalPrice_Rc(APrice: Double);
begin
  Deal.TotalPrice_Rc := Deal.Quantity * APrice;
  Qc.TotalPrice_Rc := Qc.Quantity * APrice;
  Gather.TotalPrice_Rc := Gather.Quantity * APrice;
end;

constructor TMeasureCalc.Create;
begin
  FDeal := TReCalcData.Create;
  FQc := TReCalcData.Create;
  FGather := TReCalcData.Create;
end;

destructor TMeasureCalc.Destroy;
begin
  FDeal.Free;
  FQc.Free;
  FGather.Free;
  inherited;
end;

procedure TMeasureCalc.InitCalcData;
begin
  Deal.TotalPrice := 0;
  Qc.TotalPrice := 0;
  Gather.TotalPrice := 0;
  InitTotalPrice_Rc;
end;

procedure TMeasureCalc.InitTotalPrice_Rc;
begin
  Deal.TotalPrice_Rc := 0;
  Qc.TotalPrice_Rc := 0;
  Gather.TotalPrice_Rc := 0;
end;

procedure TMeasureCalc.MinusCalcData(ACalc: TMeasureCalc);
begin
  Deal.TotalPrice := Deal.TotalPrice - ACalc.Deal.TotalPrice;
  Qc.TotalPrice := Qc.TotalPrice - ACalc.Qc.TotalPrice;
  Gather.TotalPrice := Gather.TotalPrice - ACalc.Gather.TotalPrice;
  Deal.TotalPrice_Rc := Deal.TotalPrice_Rc - ACalc.Deal.TotalPrice_Rc;
  Qc.TotalPrice_Rc := Qc.TotalPrice_Rc - ACalc.Qc.TotalPrice_Rc;
  Gather.TotalPrice_Rc := Gather.TotalPrice_Rc - ACalc.Gather.TotalPrice_Rc;
end;

procedure TMeasureCalc.UpdateTotalPrice_Rc(ACalc: TMeasureCalc);
begin
  Deal.TotalPrice_Rc := Deal.TotalPrice_Rc + ACalc.Deal.TotalPrice_Rc;
  Qc.TotalPrice_Rc := Qc.TotalPrice_Rc + ACalc.Qc.TotalPrice_Rc;
  Gather.TotalPrice_Rc := Gather.TotalPrice_Rc + ACalc.Gather.TotalPrice_Rc;
end;

{ TProjCalc }

procedure TProjCalc.AddCalcData(AProjCalc: TProjCalc);
begin
  Compile.AddCalcData(AProjCalc.Compile);
  AddMeasure.AddCalcData(AProjCalc.AddMeasure);
  CurMeasure.AddCalcData(AProjCalc.CurMeasure);
  PreMeasure.AddCalcData(AProjCalc.PreMeasure);
  EndMeasure.AddCalcData(AProjCalc.EndMeasure);
  ZoneMeasure.AddCalcData(AProjCalc.ZoneMeasure);
end;

procedure TProjCalc.CalcTotalPrice_Rc(APrice: Double);
begin
  Compile.CalcTotalPrice_Rc(APrice);
  AddMeasure.CalcTotalPrice_Rc(APrice);
  CurMeasure.CalcTotalPrice_Rc(APrice);
  PreMeasure.CalcTotalPrice_Rc(APrice);
  EndMeasure.CalcTotalPrice_Rc(APrice);
  ZoneMeasure.CalcTotalPrice_Rc(APrice);
end;

constructor TProjCalc.Create;
begin
  FCompile := TCompileCalc.Create;
  FAddMeasure := TMeasureCalc.Create;
  FCurMeasure := TMeasureCalc.Create;
  FPreMeasure := TMeasureCalc.Create;
  FEndMeasure := TMeasureCalc.Create;
  FZoneMeasure := TMeasureCalc.Create;

  FDgnQuantity1 := 0;
  FDgnQuantity2 := 0;
  FDealDgnQuantity1 := 0;
  FDealDgnQuantity2 := 0;
  FCDgnQuantity1 := 0;
  FCDgnQuantity2 := 0;
end;

destructor TProjCalc.Destroy;
begin
  FCompile.Free;
  FAddMeasure.Free;
  FCurMeasure.Free;
  FPreMeasure.Free;
  FEndMeasure.Free;
  FZoneMeasure.Free;
  inherited;
end;

procedure TProjCalc.InitCalcData;
begin
  Compile.InitCalcData;
  AddMeasure.InitCalcData;
  CurMeasure.InitCalcData;
  PreMeasure.InitCalcData;
  EndMeasure.InitCalcData;
  ZoneMeasure.InitCalcData;
end;

procedure TProjCalc.InitTotalPrice_Rc;
begin
  Compile.InitTotalPrice_Rc;
  AddMeasure.InitTotalPrice_Rc;
  CurMeasure.InitTotalPrice_Rc;
  PreMeasure.InitTotalPrice_Rc;
  EndMeasure.InitTotalPrice_Rc;
  ZoneMeasure.InitTotalPrice_Rc;
end;

procedure TProjCalc.MinusCalcData(AProjCalc: TProjCalc);
begin
  Compile.MinusCalcData(AProjCalc.Compile);
  AddMeasure.MinusCalcData(AProjCalc.AddMeasure);
  CurMeasure.MinusCalcData(AProjCalc.CurMeasure);
  PreMeasure.MinusCalcData(AProjCalc.PreMeasure);
  EndMeasure.MinusCalcData(AProjCalc.EndMeasure);
  ZoneMeasure.MinusCalcData(AProjCalc.ZoneMeasure);
end;

procedure TProjCalc.UpdateTotalPrice_Rc(AProjCalc: TProjCalc);
begin
  Compile.UpdateTotalPrice_Rc(AProjCalc.Compile);
  AddMeasure.UpdateTotalPrice_Rc(AProjCalc.AddMeasure);
  CurMeasure.UpdateTotalPrice_Rc(AProjCalc.CurMeasure);
  PreMeasure.UpdateTotalPrice_Rc(AProjCalc.PreMeasure);
  EndMeasure.UpdateTotalPrice_Rc(AProjCalc.EndMeasure);
  ZoneMeasure.UpdateTotalPrice_Rc(AProjCalc.ZoneMeasure);
end;

{ TCalcData }

procedure TCalcData.AddQuantity(AValue: Double);
begin
  FQuantity := FQuantity + AValue;
end;

procedure TCalcData.AddTotalPrice(AValue: Double);
begin
  FTotalPrice := FTotalPrice + AValue;
end;

constructor TCalcData.Create;
begin
  FQuantity := 0;
  FTotalPrice := 0;
end;

{ TReCalcData }

constructor TReCalcData.Create;
begin
  inherited;
  FTotalPrice_Rc := 0;
end;

end.
