Commit b4b594db authored by Bastien Ho's avatar Bastien Ho :alien:
Browse files

Resolve "Prendre en compte la pause estivale de SEPA"

Merge branch '102-summer-break' into 'main'

See merge request sudeducation/cartable!385
Showing with 81 additions and 18 deletions
+81 -18
......@@ -310,25 +310,14 @@ function cartable_civicrm_alter_next_collection_date(&$return_date, $rcontributi
}
}
// Now, get all dates
$legacy_date = $return_date;
$date = strtotime($return_date);
$last_end_date = mktime(0, 0, 0, $syndicate['ParametresAdhesion.ContributionEndMonth'], $syndicate['ParametresAdhesion.ContributionEndDay'], date('Y', $date));
$next_start_date = mktime(0, 0, 0, $syndicate['ParametresAdhesion.ContributionStartMonth'], $syndicate['ParametresAdhesion.ContributionStartDay'], date('Y', $date));
// Ensure that the next start date after the contribution date
if($next_start_date < $date){
$next_start_date = strtotime('+1 year', $next_start_date);
}
// Ensure that the last end date is before the next start date
if($next_start_date < $last_end_date){
$last_end_date = strtotime('-1 year', $last_end_date);
}
$return_date = cartable_compute_next_contribution_date(
$return_date,
$syndicate['ParametresAdhesion.ContributionStartMonth'],
$syndicate['ParametresAdhesion.ContributionStartDay'],
$syndicate['ParametresAdhesion.ContributionEndMonth'],
$syndicate['ParametresAdhesion.ContributionEndDay']
);
if($date > $last_end_date && $date < $next_start_date){
// Inhibate this behaviour. see https://git.avecnous.eu/sudeducation/cartable/-/issues/101
// $return_date = date('Y-m-d', $next_start_date);
}
\WPReporting()->stop();
}
......
......@@ -1039,3 +1039,40 @@ function cartable_generateRrule(string $effet_date, string $frequency, int $inte
}
return $rrule;
}
/**
* Get the next payment date for a given date and a given break-range
*
* @param string $return_date The current contribution date
* @param int $month_start The start month of the contribution range
* @param int $day_start The start day of the contribution range
* @param int $month_end The end month of the contribution range
* @param int $day_end The end day of the contribution range
*
* @return string
*/
function cartable_compute_next_contribution_date(string $return_date, int $month_start, int $day_start, int $month_end, int $day_end): string{
$date = strtotime($return_date);
$monthday_current = (int) date('md', $date);
$monthday_period_start = (int) ($month_start.str_pad($day_start, 2, '0', STR_PAD_LEFT));
$monthday_period_end = (int) ($month_end.str_pad($day_end, 2, '0', STR_PAD_LEFT));
// Between january 1rst & range end
if($monthday_current >= 101 && $monthday_current <= $monthday_period_end) {
// $next_start_date = mktime(0, 0, 0, $month_start, $day_start, date('Y', $date));
// Do not alter the date
}
// Out of range
elseif($monthday_current > $monthday_period_end && $monthday_current < $monthday_period_start) {
$next_start_date = mktime(0, 0, 0, $month_start, $day_start, date('Y', $date));
$return_date = date('Y-m-d', $next_start_date);
}
// Between range start & december 31rst
elseif($monthday_current > $monthday_period_end) {
// $next_start_date = mktime(0, 0, 0, $month_start, $day_start, date('Y', $date)+1);
// Do not alter the date
}
return $return_date;
}
\ No newline at end of file
<?php
namespace Tests\Unit;
use Tests\Support\UnitTester;
require 'cartable/inc/utils.php';
class SummerBreakTest extends \Codeception\Test\Unit
{
protected UnitTester $tester;
public function testBetweenJanuaryAndEnd()
{
$nextcollection = \cartable_compute_next_contribution_date('2024-04-01', 10, 9, 6, 10);
return $this->assertEquals('2024-04-01', $nextcollection);
}
public function testJustBeforeEnd()
{
$nextcollection = \cartable_compute_next_contribution_date('2024-06-09', 10, 9, 6, 10);
return $this->assertEquals('2024-06-09', $nextcollection);
}
public function testDuringBreak()
{
$nextcollection = \cartable_compute_next_contribution_date('2024-08-12', 10, 9, 6, 10);
return $this->assertEquals('2024-10-09', $nextcollection);
}
public function testBetweenStartAndDecember()
{
$nextcollection = \cartable_compute_next_contribution_date('2024-11-05', 10, 9, 6, 10);
return $this->assertEquals('2024-11-05', $nextcollection);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment