Skip to content

Commit

Permalink
Fix(Contract): Expiration date (#17725)
Browse files Browse the repository at this point in the history
* Fix(Contract): Expiration date

* add tooltip
  • Loading branch information
Rom1-B authored Aug 28, 2024
1 parent 53a22e7 commit b14fbab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
28 changes: 22 additions & 6 deletions phpunit/functional/ContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public static function getSpecificValueToDisplayProvider()
'values' => [
'begin_date' => '2020-01-01',
'duration' => 6,
'renewal' => \Contract::RENEWAL_NEVER
'renewal' => \Contract::RENEWAL_NEVER,
'periodicity' => 0
],
'expected' => "<span class='red'>2020-07-01</span>"
],
Expand All @@ -119,7 +120,8 @@ public static function getSpecificValueToDisplayProvider()
'values' => [
'begin_date' => '2020-01-01',
'duration' => 6,
'renewal' => \Contract::RENEWAL_TACIT
'renewal' => \Contract::RENEWAL_TACIT,
'periodicity' => 0
],
'expected' => "2024-07-01"
],
Expand All @@ -128,7 +130,8 @@ public static function getSpecificValueToDisplayProvider()
'values' => [
'begin_date' => '2020-01-01',
'duration' => 6,
'renewal' => \Contract::RENEWAL_EXPRESS
'renewal' => \Contract::RENEWAL_EXPRESS,
'periodicity' => 0
],
'expected' => "<span class='red'>2020-07-01</span>"
],
Expand All @@ -137,7 +140,8 @@ public static function getSpecificValueToDisplayProvider()
'values' => [
'begin_date' => '2025-01-01',
'duration' => 6,
'renewal' => \Contract::RENEWAL_NEVER
'renewal' => \Contract::RENEWAL_NEVER,
'periodicity' => 0
],
'expected' => '2025-07-01'
],
Expand All @@ -146,7 +150,8 @@ public static function getSpecificValueToDisplayProvider()
'values' => [
'begin_date' => '2025-01-01',
'duration' => 6,
'renewal' => \Contract::RENEWAL_TACIT
'renewal' => \Contract::RENEWAL_TACIT,
'periodicity' => 0
],
'expected' => '2025-07-01'
],
Expand All @@ -155,10 +160,21 @@ public static function getSpecificValueToDisplayProvider()
'values' => [
'begin_date' => '2025-01-01',
'duration' => 6,
'renewal' => \Contract::RENEWAL_EXPRESS
'renewal' => \Contract::RENEWAL_EXPRESS,
'periodicity' => 0
],
'expected' => '2025-07-01'
],
[
'field' => '_virtual_expiration',
'values' => [
'begin_date' => '2019-01-01',
'duration' => 60,
'renewal' => \Contract::RENEWAL_TACIT,
'periodicity' => 12
],
'expected' => '2025-01-01'
],
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ public static function getSpecificValueToDisplay($field, $values, array $options
$values['duration'],
0,
true,
($values['renewal'] == self::RENEWAL_TACIT)
($values['renewal'] == self::RENEWAL_TACIT),
$values['periodicity']
);
}
return parent::getSpecificValueToDisplay($field, $values, $options);
Expand Down Expand Up @@ -667,7 +668,8 @@ public function rawSearchOptions()
'additionalfields' => [
'begin_date',
'duration',
'renewal'
'renewal',
'periodicity'
],
'name' => __('Expiration'),
'datatype' => 'specific',
Expand Down
11 changes: 7 additions & 4 deletions src/Infocom.php
Original file line number Diff line number Diff line change
Expand Up @@ -1763,13 +1763,14 @@ public function showDebug()
* @param integer $deletenotice period in months of notice (default 0)
* @param boolean $color if show expire date in red color (false by default)
* @param boolean $auto_renew
* @param integer $periodicity renewal periodicity in month if different from addwarranty
*
* @return string expiration date
**/
public static function getWarrantyExpir($from, $addwarranty, $deletenotice = 0, $color = false, $auto_renew = false)
public static function getWarrantyExpir($from, $addwarranty, $deletenotice = 0, $color = false, $auto_renew = false, $periodicity = 0)
{

// Life warranty
// Life warranty
if (
($addwarranty == -1)
&& ($deletenotice == 0)
Expand All @@ -1783,11 +1784,13 @@ public static function getWarrantyExpir($from, $addwarranty, $deletenotice = 0,

$timestamp = strtotime("$from+$addwarranty month -$deletenotice month");

if ($auto_renew && $addwarranty > 0) {
$periodicity = ($periodicity > 0) ? $periodicity : $addwarranty;

if ($auto_renew && $periodicity > 0) {
while ($timestamp < strtotime($_SESSION['glpi_currenttime'])) {
$datetime = new DateTime();
$datetime->setTimestamp($timestamp);
$timestamp = strtotime($datetime->format("Y-m-d H:i:s") . "+$addwarranty month");
$timestamp = strtotime($datetime->format("Y-m-d H:i:s") . "+$periodicity month");
}
}

Expand Down
26 changes: 17 additions & 9 deletions templates/pages/management/contract.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,22 @@
) }}

{% if item.fields['begin_date'] is not empty and item.fields['duration'] is not empty %}
{% set end_title = __('End date') %}
{% if item.fields['renewal'] == constant('Contract::RENEWAL_TACIT') %}
{% set end_title = __('Next renewal date') %}
{% endif %}
{% set warranty_expiration %}
<i class="fas fa-arrow-right"></i>
{{ call('Infocom::getWarrantyExpir', [
item.fields['begin_date'],
item.fields['duration'],
0,
true,
item.fields['renewal'] == constant('Contract::RENEWAL_TACIT')
])|raw }}
<span title="{{ end_title|default('') }}" data-bs-toggle="tooltip">
<i class="fas fa-arrow-right"></i>
{{ call('Infocom::getWarrantyExpir', [
item.fields['begin_date'],
item.fields['duration'],
0,
true,
item.fields['renewal'] == constant('Contract::RENEWAL_TACIT'),
item.fields['periodicity']
])|raw }}
</span>
{% endset %}
{% endif %}
{{ fields.dropdownNumberField('duration', item.fields['duration'], __('Initial contract period'), {
Expand All @@ -72,7 +79,8 @@
item.fields['begin_date'],
item.fields['duration'],
item.fields['notice'],
true
true,
item.fields['periodicity']
])|raw }}
{% endset %}
{% endif %}
Expand Down

0 comments on commit b14fbab

Please sign in to comment.