<html>

<script type="text/dlbscript">// Inline script gets removed after build

function GetWarnHintHTMLColor: String;
var 
  BackColor: TColor;
  id: Int64;
begin
  id := Document.RealValue('adr', 'warnhinttypeid');
    
  if id > 0 then
  begin    
    if not AddressModule.Get_UIColorByWarnHintTypeID(id, BackColor) then
	    BackColor := clNone;	 
  end else 
    BackColor := clNone;
  
  if BackColor = clNone then    
    Result := 'transparent'
  else
    Result := ColorToHTML(BackColor);   
end;

function GetChipColor: TColor;
var 
  BackColor: TColor;  
begin  
  {$IFDEF AddressModule}	
  BackColor := AddressModule.Get_UIColorByPersonStateID(Document.RealValue('adr', 'isactive')); 
  {$ELSE AddressModule}
   BackColor := clNone;
  {$ENDIF AddressModule}
  
  if BackColor = clNone then
    Result := $F2D390
  else
    Result := BackColor;
end;

function GetChipHTMLColor: String;
begin
  Result := ColorToHTML(GetChipColor);
end;

function GetChipHTMLTextColor: String;
begin
  Result := ColorToHTML(GetContrastingColor(GetChipColor));
end;

function GetChipText: String;
begin 
  {$IFDEF AddressModule}
  Result := AddressModule.Get_ChipTextByName(<adr."shortcut">, <adr."companyname">, <adr."name">, <adr."surname">, 2);  
  {$ELSE AddressModule}
  Result := '';
  {$ENDIF AddressModule}  
end;

function GetDisplayText: String;
begin 
  Result := Trim(<adr."companyname"> + ' ' + <adr."name"> + ' ' + <adr."surname">);
end;

function GetBDAgeText: String;
var
  BirthYear, BirthMonth, BirthDay, CurrentYear, CurrentMonth, CurrentDay: Word;
  BDay: TDateTime;  
begin
  BDay := VarToDateDef(<adr."birthday">, 0);
  
  if BDay > 0 then
  begin    
    DecodeDate(BDay, BirthYear, BirthMonth, BirthDay);
    DecodeDate(Date, CurrentYear, CurrentMonth, CurrentDay);
    BDay := EncodeDate(CurrentYear, BirthMonth, BirthDay);
   
    if (BirthMonth = CurrentMonth) and (BirthDay = CurrentDay) then
      Result := 'wird Heute'
    else
    if (BirthMonth > CurrentMonth) or ((BirthMonth = CurrentMonth) and (BirthDay > CurrentDay)) then
    begin 
      if DaySpan(Date, BDay) < 8 then
      begin
        if WeekOfTheYear(Date) = WeekOfTheYear(BDay) then            
          Result := 'wird diesen ' + FormatDateTime('dddd', BDay)
        else
          Result := 'wird nächste Woche am ' + FormatDateTime('dddd', BDay)
      end else
        Result := 'wird';
    end else
      Result := 'wurde';
      
    Result := Result + ' <b>' + IntToStr(YearOf(Date) - BirthYear) + '</b>';
  end else
    Result := '';
end;


//</script>

<report-objects>
  <object name="adr" sql="select id, birthday, isactive, warnhinttypeid, talkto, shortcut, name, surname, companyname, zip, city, countryid FROM recordset WHERE id = :EditValue" type=""></object>
</report-objects>

<body style="background-color: transparent; min-height: 1.3em;">

<div class="delight-dynamicblock dlb-s-brad" style="display: flex; background-color:{{#script}}GetWarnHintHTMLColor{{/script}};">

{{#adr}}

<div class="dlb-record-chip" style="color:{{#script}}GetChipHTMLTextColor{{/script}}; background-color:{{#script}}GetChipHTMLColor{{/script}};">  
  {{#script}}GetChipText{{/script}}
</div>  


<div style="padding-left: 0.5em">
  <b>{{NAME}}&nbsp;{{SURNAME}}</b> {{#script}}GetBDAgeText{{/script}}
</div>

{{/adr}}

</div>

</body>

</html>
