Changeset 10 for trunk/Ean.pas


Ignore:
Timestamp:
Apr 15, 2026, 9:35:17 AM (2 weeks ago)
Author:
chronos
Message:
  • Added: Show spot total price above zero for EANs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ean.pas

    r9 r10  
    4747    function GetSharedPercent(TimeFrom, TimeTo: TDateTime): Double;
    4848    function GetSavings(TimeFrom, TimeTo: TDateTime; SpotPrices: TSpotPrices): Currency;
    49     function GetPrice(TimeFrom, TimeTo: TDateTime; SpotPrices: TSpotPrices): Currency;
     49    function GetPrice(TimeFrom, TimeTo: TDateTime; SpotPrices: TSpotPrices; MinPrice: Currency): Currency;
    5050    procedure LoadFromXmlNode(Node: TDOMNode);
    5151    procedure SaveToXmlNode(Node: TDOMNode);
     
    198198  I: Integer;
    199199  SpotPrice: TSpotPrice;
     200  SpotPriceIndex: Integer;
    200201begin
    201202    if PriceLow = 0 then begin
     
    203204    for I := 0 to Values.Count - 1 do
    204205      if (Values[I].Time >= TimeFrom) and (Values[I].Time < TimeTo) then begin
    205         SpotPrice := SpotPrices.SearchByTime(Values[I].Time);
    206         if SpotPrice.Value <> 0 then
    207           Result := Result + (Values[I].ValueIn - Values[I].ValueOut) * (SpotPrice.Value - PriceSpot);
     206        SpotPriceIndex := SpotPrices.SearchByTime(Values[I].Time);
     207        if SpotPriceIndex <> -1 then
     208          Result := Result + (Values[I].ValueIn - Values[I].ValueOut) * (SpotPrices[SpotPriceIndex].Value - PriceSpot);
    208209      end;
    209210  end else begin
     
    214215end;
    215216
    216 function TEan.GetPrice(TimeFrom, TimeTo: TDateTime; SpotPrices: TSpotPrices): Currency;
    217 var
    218   I: Integer;
    219   SpotPrice: TSpotPrice;
     217function TEan.GetPrice(TimeFrom, TimeTo: TDateTime; SpotPrices: TSpotPrices; MinPrice: Currency): Currency;
     218var
     219  I: Integer;
     220  SpotPriceIndex: Integer;
     221  SpotPrice: Currency;
    220222begin
    221223  if PriceLow = 0 then begin
     
    223225    for I := 0 to Values.Count - 1 do
    224226      if (Values[I].Time >= TimeFrom) and (Values[I].Time < TimeTo) then begin
    225         SpotPrice := SpotPrices.SearchByTime(Values[I].Time);
    226         if SpotPrice.Value <> 0 then
    227           Result := Result + Values[I].ValueIn * (SpotPrice.Value - PriceSpot);
     227        SpotPriceIndex := SpotPrices.SearchByTime(Values[I].Time);
     228        if (SpotPriceIndex <> -1) then begin
     229          SpotPrice := SpotPrices[SpotPriceIndex].Value - PriceSpot;
     230          if SpotPrice > MinPrice then
     231            Result := Result + Values[I].ValueIn * SpotPrice;
     232        end;
    228233      end;
    229234  end else Result := GetTotalIn(TimeFrom, TimeTo) * PriceLow;
Note: See TracChangeset for help on using the changeset viewer.