trait CommonSubtotal (View source)

Trait CommonSubtotal

Add subtotals lines

Properties

static int $PRODUCT_TYPE
static string[] $TITLE_OPTIONS
static string[] $SUBTOTAL_OPTIONS
static string[] $ALLOWED_TYPES

Methods

int
addSubtotalLine(Translate $langs, string $desc, int $depth, array<string, string>|string $options = array(), int $parent_line = 0)

Adds a subtotals line to a document.

int
deleteSubtotalLine(Translate $langs, int $id, bool $correspondingstline = false, User $user = null)

Deletes a subtotal or a title line from a document.

int
updateSubtotalLine(Translate $langs, int $lineid, string $desc, int $depth, array<string, string>|string $options)

Updates a subtotal line of a document.

int
updateSubtotalLineBlockLines(Translate $langs, int $linerang, string $mode, int $value)

Updates a block of lines of a document.

string
getSubtotalLineAmount(object $line)

Return the total_ht of lines that are above the current line (excluded) and that are not a subtotal line until a title line of the same level is found

string
getSubtotalLineMulticurrencyAmount(object $line)

Return the multicurrency_total_ht of lines that are above the current line (excluded) and that are not a subtotal line until a title line of the same level is found

string|null
getSubtotalColors(int|float $level)

Retrieve the background color associated with a specific subtotal level.

array<string, string>
getPossibleTitles()

Retrieve current object possible titles to choose from

array<int, string>
getPossibleLevels(Translate $langs)

Retrieve the current object possible levels (defined in admin page)

int[]
getDisabledShippmentSubtotalLines()

Returns an array with the IDs of the line that we don't need to show to avoid empty blocks

Details

int addSubtotalLine(Translate $langs, string $desc, int $depth, array<string, string>|string $options = array(), int $parent_line = 0)

Adds a subtotals line to a document.

This function inserts a subtotal line based on the given parameters.

Parameters

Translate $langs Translation.
string $desc

Description of the line.

int $depth

Level of the line (>0 for title lines, <0 for subtotal lines)

array<string, string>|string $options

Subtotal options for pdf view

int $parent_line

ID of the parent line for shipments

Return Value

int

ID of the added line if successful, 0 on warning, -1 on error

int deleteSubtotalLine(Translate $langs, int $id, bool $correspondingstline = false, User $user = null)

Deletes a subtotal or a title line from a document.

If the corresponding subtotal line exists and second parameter true, it will also be deleted.

Parameters

Translate $langs Translation.
int $id

ID of the line to delete

bool $correspondingstline

If true, also deletes the corresponding subtotal line

User $user

performing the deletion (used for permissions in some modules)

Return Value

int

ID of deleted line if successful, -1 on error

int updateSubtotalLine(Translate $langs, int $lineid, string $desc, int $depth, array<string, string>|string $options)

Updates a subtotal line of a document.

This function updates a subtotals line based on its id and the given parameters. Updating a title line updates the corresponding subtotal line except options.

Parameters

Translate $langs Translation.
int $lineid

ID of the line to update.

string $desc

Description of the line.

int $depth

Level of the line (>0 for title lines, <0 for subtotal lines)

array<string, string>|string $options

Subtotal options for pdf view

Return Value

int

ID of the added line if successful, 0 on warning, -1 on error

int updateSubtotalLineBlockLines(Translate $langs, int $linerang, string $mode, int $value)

Updates a block of lines of a document.

Parameters

Translate $langs Translation.
int $linerang

Rang of the line to start from.

string $mode

Column to change (discount or vat).

int $value

Value of the change.

Return Value

int

Return integer < 0 if KO, 1 if OK

string getSubtotalLineAmount(object $line)

Return the total_ht of lines that are above the current line (excluded) and that are not a subtotal line until a title line of the same level is found

Parameters

object $line

Line that needs the subtotal amount.

Return Value

string $total_ht

string getSubtotalLineMulticurrencyAmount(object $line)

Return the multicurrency_total_ht of lines that are above the current line (excluded) and that are not a subtotal line until a title line of the same level is found

Parameters

object $line

Line that needs the subtotal amount with multicurrency mod activated.

Return Value

string $total_ht

string|null getSubtotalColors(int|float $level)

Retrieve the background color associated with a specific subtotal level.

Parameters

int|float $level

The level of the subtotal for which the color is requested.

Return Value

string|null

The background color in hexadecimal format or null if not set.

array<string, string> getPossibleTitles()

Retrieve current object possible titles to choose from

Return Value

array<string, string>

The set of titles, empty if no title line set.

array<int, string> getPossibleLevels(Translate $langs)

Retrieve the current object possible levels (defined in admin page)

Parameters

Translate $langs Translations.

Return Value

array<int, string>

The set of possible levels, empty if not defined correctly.

int[] getDisabledShippmentSubtotalLines()

Returns an array with the IDs of the line that we don't need to show to avoid empty blocks

Return Value

int[] $total_ht