Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0213c0a97d | ||
| 12def35dda | |||
| 2d1c1e6e22 | |||
|
|
f7568f2d09 | ||
| 9c164fe78e |
@@ -6,7 +6,8 @@
|
|||||||
"Bash(php:*)",
|
"Bash(php:*)",
|
||||||
"Bash(docker compose:*)",
|
"Bash(docker compose:*)",
|
||||||
"Bash(make test:*)",
|
"Bash(make test:*)",
|
||||||
"Bash(grep:*)"
|
"Bash(grep:*)",
|
||||||
|
"Bash(docker exec:*)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ services:
|
|||||||
App\:
|
App\:
|
||||||
resource: '../src/'
|
resource: '../src/'
|
||||||
|
|
||||||
|
App\Service\PublicHolidayService:
|
||||||
|
arguments:
|
||||||
|
$holidayUrl: '%env(HOLIDAY_URL)%'
|
||||||
|
|
||||||
App\Repository\Contract\AbsenceReadRepositoryInterface: '@App\Repository\AbsenceRepository'
|
App\Repository\Contract\AbsenceReadRepositoryInterface: '@App\Repository\AbsenceRepository'
|
||||||
App\Repository\Contract\EmployeeContractPeriodReadRepositoryInterface: '@App\Repository\EmployeeContractPeriodRepository'
|
App\Repository\Contract\EmployeeContractPeriodReadRepositoryInterface: '@App\Repository\EmployeeContractPeriodRepository'
|
||||||
App\Repository\Contract\EmployeeScopedRepositoryInterface: '@App\Repository\EmployeeRepository'
|
App\Repository\Contract\EmployeeScopedRepositoryInterface: '@App\Repository\EmployeeRepository'
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.19'
|
app.version: '0.1.21'
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
final class PublicHolidayService implements PublicHolidayServiceInterface
|
final readonly class PublicHolidayService implements PublicHolidayServiceInterface
|
||||||
{
|
{
|
||||||
private const string BASE_URL = 'https://calendrier.api.gouv.fr/jours-feries/';
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly HttpClientInterface $client,
|
private HttpClientInterface $client,
|
||||||
|
private string $holidayUrl
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +30,7 @@ final class PublicHolidayService implements PublicHolidayServiceInterface
|
|||||||
public function getHolidaysDay(string $zone): array
|
public function getHolidaysDay(string $zone): array
|
||||||
{
|
{
|
||||||
$zone = strtolower(trim($zone));
|
$zone = strtolower(trim($zone));
|
||||||
$url = self::BASE_URL."{$zone}.json";
|
$url = $this->holidayUrl."{$zone}.json";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->client->request(
|
$response = $this->client->request(
|
||||||
@@ -61,7 +60,7 @@ final class PublicHolidayService implements PublicHolidayServiceInterface
|
|||||||
{
|
{
|
||||||
$zone = strtolower(trim($zone));
|
$zone = strtolower(trim($zone));
|
||||||
$years = trim($years);
|
$years = trim($years);
|
||||||
$url = self::BASE_URL."{$zone}/{$years}.json";
|
$url = $this->holidayUrl."{$zone}/{$years}.json";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->client->request('GET', $url);
|
$response = $this->client->request('GET', $url);
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
$carrySaturdays = 0.0;
|
$carrySaturdays = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$calculationEnd = $this->resolveCalculationEndDate($leavePolicy['ruleCode'], $year, $to);
|
$calculationEnd = $this->resolveCalculationEndDate($leavePolicy['ruleCode'], $year, $to, $employee);
|
||||||
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
|
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
|
||||||
? $this->computeAccruedDaysFromStart(
|
? $this->computeAccruedDaysFromStart(
|
||||||
$leavePolicy['acquiredDays'],
|
$leavePolicy['acquiredDays'],
|
||||||
@@ -193,6 +193,13 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
$leavePolicy['countOnlyCp'],
|
$leavePolicy['countOnlyCp'],
|
||||||
$leavePolicy['splitSaturdays']
|
$leavePolicy['splitSaturdays']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Bootstrap support: if the opening balance has pre-filled taken days
|
||||||
|
// (e.g. manual data entry for production bootstrap), add them as an offset.
|
||||||
|
if (null !== $openingBalance) {
|
||||||
|
$takenDays += $openingBalance->getTakenDays();
|
||||||
|
$takenSaturdays += $openingBalance->getTakenSaturdays();
|
||||||
|
}
|
||||||
if (LeaveRuleCode::CDI_CDD_NON_FORFAIT->value === $leavePolicy['ruleCode']) {
|
if (LeaveRuleCode::CDI_CDD_NON_FORFAIT->value === $leavePolicy['ruleCode']) {
|
||||||
$availableAcquired = max(0.0, $carryDays);
|
$availableAcquired = max(0.0, $carryDays);
|
||||||
$takenFromAcquired = min($availableAcquired, $takenDays);
|
$takenFromAcquired = min($availableAcquired, $takenDays);
|
||||||
@@ -349,7 +356,8 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
private function resolveCalculationEndDate(
|
private function resolveCalculationEndDate(
|
||||||
string $ruleCode,
|
string $ruleCode,
|
||||||
int $year,
|
int $year,
|
||||||
DateTimeImmutable $periodEnd
|
DateTimeImmutable $periodEnd,
|
||||||
|
Employee $employee
|
||||||
): ?DateTimeImmutable {
|
): ?DateTimeImmutable {
|
||||||
$today = new DateTimeImmutable('today');
|
$today = new DateTimeImmutable('today');
|
||||||
$currentYear = LeaveRuleCode::FORFAIT_218->value === $ruleCode
|
$currentYear = LeaveRuleCode::FORFAIT_218->value === $ruleCode
|
||||||
@@ -357,18 +365,27 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
|||||||
: $this->resolveCurrentLeaveYear($today);
|
: $this->resolveCurrentLeaveYear($today);
|
||||||
|
|
||||||
if ($year < $currentYear) {
|
if ($year < $currentYear) {
|
||||||
return $periodEnd;
|
$end = $periodEnd;
|
||||||
}
|
} elseif ($year > $currentYear) {
|
||||||
if ($year > $currentYear) {
|
$end = null;
|
||||||
return null;
|
} else {
|
||||||
|
$lastDayPreviousMonth = $today
|
||||||
|
->modify('first day of this month')
|
||||||
|
->modify('-1 day')
|
||||||
|
;
|
||||||
|
$end = $lastDayPreviousMonth < $periodEnd ? $lastDayPreviousMonth : $periodEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastDayPreviousMonth = $today
|
// Cap at contract end date if the employee has left.
|
||||||
->modify('first day of this month')
|
$contractEndRaw = $employee->getCurrentContractEndDate();
|
||||||
->modify('-1 day')
|
if (null !== $end && null !== $contractEndRaw && '' !== trim($contractEndRaw)) {
|
||||||
;
|
$contractEnd = DateTimeImmutable::createFromFormat('Y-m-d', $contractEndRaw);
|
||||||
|
if ($contractEnd instanceof DateTimeImmutable && $contractEnd < $end) {
|
||||||
|
$end = $contractEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $lastDayPreviousMonth < $periodEnd ? $lastDayPreviousMonth : $periodEnd;
|
return $end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user