Last updated: 2025-03-31

Syntax - HTML-reports

The text in XML reports can be formatted using standard HTML tags, for example <p>text</p> for paragraphs and <b>text</b> for bold. For more information, see https://www.w3schools.com/asp/razor_syntax.asp and https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-8.0.

The tags in reports of type HTML come from the Delivery class. Tags from other classes need the prefix

in the Class/prefix column of the tables in Förteckning över taggar. The prefix is separated from the tag by a dot, for example Customer.CUS_Name.

Syntax: @Model.prefix.tagg

In this example, which retrieves the order number, no prefix is needed because DEL_Id is in the Delivery class.

@Model.DEL_Id

In the example below, which retrieves the telephone number for the transport company from the office settings, OFF_PhoneNo is in the Office class, which must therefore be used as a prefix.

@Model.Office.OFF_PhoneNo

If you add a tag to a HTML report with the wrong prefix, or misspell the tag, the notification will not work and an error message stating that there is no report will be displayed when the notification is generated.

Lists

There may be many instances of some items in an order, such as packages and shipments. In order to be able to display information about such objects in the report, the tag has to be combined with a list tag so that all the instances of the item are counted. The result is a list with one or more entries.

The list in the report can be structured in various ways. A heading can be entered for the whole list, or a description can be written that repeats on each line. It is also possible to combine several tags belonging to the same list, thus creating a list with, for example, the package ID and the weight of each package in an order.

The entries in the list do not have to be numbers, but can also be text, for example PAC_Text, which returns the free text field for parcels on an order.

Syntax:

Optional text

@foreach(var item in Model.list tag.ActiveItems)

{

<text>Text of your choice: @item.tag</text><br/>

}

Example 1

List of parcel numbers and a description for each line.

@foreach(var item in Model.Packages.ActiveItems)
{
   <text>Kollinr: @item.PAC_PackageId</text><br/>
}

Returns the list in the following format.

Package ID: 123456

Package ID: 356789

Package ID: 986554

Example 2

List of parcel numbers and a header for the whole list.

<b>Kollin</b><br>
@foreach(var item in Model.Packages.ActiveItems)
{
   <text>@item.PAC_PackageId</text><br/>
}

Returns the list in the following format.

Packages

123456

356789

986554

Example 3

List with parcel number, weight and goods text.

<b>Kollin</b><br>
@foreach(var item in Model.Packages.ActiveItems)
{
   <text>@item.PAC_PackageId: @item.PAC_Weight kg (@item.PAC_Text)</text><br/>
}

Returns the list in the following format. If one of the packages does not have any goods text, an empty bracket is displayed.

Packages

123456: 1.200000 kg (Folder with documents)

356789: 3.400000 kg (Fragile)

986554: 5.600000 kg (Accessories)

Images in lists

See below.

Figures

Numbers are stored with six decimal places in the Opter database. If you want to round to fewer than six decimal places, type a format tag and the number of decimal places to display according to the pattern 0.00 in the tag that returns the number. The number of zeros entered after the decimal point defines the number of decimal places.

To exclude unnecessary zeros at the end of numbers (2.7 instead of 2.70), but print the decimal if it is not a zero (2.73), enter # signs for the number of decimal places that are to be shown.

Syntax: @Model.prefix.tagg för numeriskt värde.ToString("0.######")

Example 1

Always two decimal places whether they have a value or not.

<b>Vikt</b><br>
@foreach(var item in Model.Packages.ActiveItems)
{
   <text>@item.PAC_Weight.ToString("0.00") kg </text><br/>
}

Returns a list in the following format.

Weight

2.00 kg

2.70 kg

12.74 kg

Example 2

Displays up to three decimal places if they have a value.

<i>Vikt</i><br>
@foreach(var item in Model.Packages.ActiveItems)
{
   <text>@item.PAC_Weight.ToString("0.###") kg </text><br/>
}

Returns a list in the following format.

Weight

2 kg

2.7 kg

12.738 kg

Example 3

Always two-digit whole numbers and two decimal places.

<u>Vikt</u><br>
@foreach(var item in Model.Packages.ActiveItems)
{
   <text>@item.PAC_Weight.ToString("00.00") kg</text><br/>
}

Returns a list in the following format.

Weight

02.00 kg

02.70 kg

12.74 kg

Images

You can add images to reports, such as logos specified in the office settings.

Syntax: <img src="data:image/png;base64,@(Convert.ToBase64String(Model.prefix.tagg))">

The following retrieves the big picture from the office settings.

<p>Hej!</p>
<p>Din order från @Model.StartAddress.ADR_AddrLine1 är på väg.</p>
<p>Mvh</p>
<p>
@if (Model.Image != null)
 {
  <p>
   <img src="data:image/png;base64,@(Convert.ToBase64String(Model.Office.OFF_LargeImage))" width="128" height="128"/>
  </p>
 }
</p>
</body>
</html>

Returns the following.

Hello,

Your order from Opter is on its way.

Best wishes,

 

Images in lists

If you want to add images from, for example, deviations or pods, of which there may be several instances on an order (see the "Lists" section above), you must first retrieve the list and then check if there is an image in order to be able to send the notification even if there is no image.

Syntax:

Optional text

@foreach(var item in Model.list tag.ActiveItems)

{

<text>Text of your choice: @item.tag</text><br/>

@if (item.Image != null)

{

<p>

<img src="data:image/png;base64,@(Convert.ToBase64String(Model.Image))">

</p>

}

}

@if (item.Image != null) (line 14) checks if there is an image of the deviation (not equal to "null") and inserts it in the email if there is one.

<html>
<body>

<p>Hej @Model.CRE_Name!</p>

<p>Det har registrerats en avvikelse på order @Model.DEL_Id från @Model.ADR_AddrLine1From till @Model.ADR_AddrLine1To.</p>

<p>
Kommentar:<br/>
@foreach(var item in Model.Damages.ActiveItems)
    {
     <text>@item.DAM_Comment</text><br/>
     
         @if (item.Image != null)
          {
           <p>
                <img  src="data:image/png;base64,@(Convert.ToBase64String(item.Image))" />
          </p>
          }    
     
    }
</p>

<p>Med vänlig hälsning</p>
<p>@Model.Office.OFF_Name</p>

</body>
</html>

Returns the following.

Dear Anton Larsson,

A deviation has been registered on order 159 from Opter AB to H&M.

Comment.

Fell off the loading bay platform.

With best wishes,

Opter

See also