dolibarr 25.0.0-alpha
asset.lib.php File Reference

Library files with common functions for Assets. More...

Go to the source code of this file.

Functions

 assetAdminPrepareHead ()
 Prepare admin pages header.
 
 assetPrepareHead (Asset $object)
 Prepare array of tabs for Asset.
 
 assetModelPrepareHead ($object)
 Prepare array of tabs for AssetModel.
 
 getAssetDepreciationDayCountConventions ()
 Return the list of the day count conventions available to compute the prorata temporis of a depreciation, with their translation key.
 
 getAssetDepreciationDayCountConvention ()
 Return the day count convention to use to compute the prorata temporis of a depreciation.
 
 getAssetDepreciationPeriodFraction ($timestampStart, $timestampEnd, $convention='', $forcetimezone='')
 Return the fraction of a year (the prorata temporis) between two dates, for a given day count convention.
 
 getAssetDepreciationMonthFraction ($timestampStart, $timestampEnd, $convention='', $forcetimezone='')
 Return the fraction of a month covered by a period, for the given day count convention.
 

Detailed Description

Library files with common functions for Assets.

Definition in file asset.lib.php.

Function Documentation

◆ assetAdminPrepareHead()

assetAdminPrepareHead ( )

Prepare admin pages header.

Returns
array<array{0:string,1:string,2:string}> head array with tabs

Definition at line 32 of file asset.lib.php.

References $conf, complete_head_from_modules(), and dolBuildUrl().

◆ assetModelPrepareHead()

assetModelPrepareHead ( $object)

Prepare array of tabs for AssetModel.

Parameters
AssetModel$objectAssetModel
Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 184 of file asset.lib.php.

References $conf, $object, complete_head_from_modules(), dolBuildUrl(), and getDolGlobalString().

◆ assetPrepareHead()

assetPrepareHead ( Asset $object)

Prepare array of tabs for Asset.

Parameters
Asset$objectAsset
Returns
array<array{0:string,1:string,2:string}> Array of tabs

Definition at line 88 of file asset.lib.php.

References $conf, $object, complete_head_from_modules(), Link\count(), dol_dir_list(), dol_sanitizeFileName(), and getDolGlobalString().

◆ getAssetDepreciationDayCountConvention()

getAssetDepreciationDayCountConvention ( )

Return the day count convention to use to compute the prorata temporis of a depreciation.

When the new setup ASSET_DEPRECIATION_DAY_COUNT_CONVENTION is not set, the convention is deduced from the deprecated setup ASSET_DEPRECIATION_DURATION_PER_YEAR so that existing installations keep the divisor they were configured with (360 => THIRTY_360, 365 or more => ACT_365).

Returns
string 'THIRTY_360', 'ACT_365' or 'ACT_ACT'

Definition at line 264 of file asset.lib.php.

References $mysoc, getAssetDepreciationDayCountConventions(), getDolGlobalInt(), and getDolGlobalString().

Referenced by Asset\calculationDepreciation(), getAssetDepreciationMonthFraction(), and getAssetDepreciationPeriodFraction().

◆ getAssetDepreciationDayCountConventions()

getAssetDepreciationDayCountConventions ( )

Return the list of the day count conventions available to compute the prorata temporis of a depreciation, with their translation key.

A convention defines both how the days of a partial period are counted and by how many days a full year is divided. Mixing the two (counting real calendar days then dividing by 360) is not a convention, it is a calculation error: it overestimates every partial period by about 1.39%.

Returns
array<string,string> Array of convention code => translation key

Definition at line 246 of file asset.lib.php.

Referenced by getAssetDepreciationDayCountConvention(), getAssetDepreciationMonthFraction(), and getAssetDepreciationPeriodFraction().

◆ getAssetDepreciationMonthFraction()

getAssetDepreciationMonthFraction ( $timestampStart,
$timestampEnd,
$convention = '',
$forcetimezone = '' )

Return the fraction of a month covered by a period, for the given day count convention.

The monthly depreciation used to count the real calendar days of the period then divide them by ASSET_DEPRECIATION_DURATION_PER_MONTH, a conventional month of 30 days. Numerator and denominator came from two different systems, so the depreciation of a partial month depended on the length of that month: placed in service on the 3rd, a 31 day month gave 29/30 of the monthly amount while a 30 day month gave 28/30.

Parameters
int$timestampStartStart of the period
int$timestampEndEnd of the period
string$convention'THIRTY_360', 'ACT_365' or 'ACT_ACT'. Empty to use the setup.
string$forcetimezone'' to use the server timezone, 'gmt' to read the dates in GMT
Returns
float Fraction of a month, between 0 and 1

Definition at line 356 of file asset.lib.php.

References dol_get_last_day(), dol_getdate(), getAssetDepreciationDayCountConvention(), getAssetDepreciationDayCountConventions(), and num_between_day().

Referenced by Asset\calculationDepreciation().

◆ getAssetDepreciationPeriodFraction()

getAssetDepreciationPeriodFraction ( $timestampStart,
$timestampEnd,
$convention = '',
$forcetimezone = '' )

Return the fraction of a year (the prorata temporis) between two dates, for a given day count convention.

Both bounds are included, so a period covering a whole standard year returns a value very close to 1 (exactly 1 with THIRTY_360).

WARNING: this function uses the PHP server timezone by default because THIRTY_360 and ACT_ACT work on the calendar representation of the dates. Force $forcetimezone to 'gmt' for UTC timestamps.

Parameters
int$timestampStartTimestamp of the first day of the period
int$timestampEndTimestamp of the last day of the period
string$conventionDay count convention ('' to read the current setup)
string$forcetimezone'' to use the PHP server timezone, or 'gmt', 'Europe/Paris', ...
Returns
float Fraction of year

Definition at line 300 of file asset.lib.php.

References dol_getdate(), getAssetDepreciationDayCountConvention(), getAssetDepreciationDayCountConventions(), num_between_day(), num_between_day_30_360(), and num_days_in_year().

Referenced by Asset\calculationDepreciation().