Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0213c0a97d | ||
| 12def35dda | |||
| 2d1c1e6e22 |
@@ -6,7 +6,8 @@
|
||||
"Bash(php:*)",
|
||||
"Bash(docker compose:*)",
|
||||
"Bash(make test:*)",
|
||||
"Bash(grep:*)"
|
||||
"Bash(grep:*)",
|
||||
"Bash(docker exec:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ services:
|
||||
App\:
|
||||
resource: '../src/'
|
||||
|
||||
App\Service\PublicHolidayService:
|
||||
arguments:
|
||||
$holidayUrl: '%env(HOLIDAY_URL)%'
|
||||
|
||||
App\Repository\Contract\AbsenceReadRepositoryInterface: '@App\Repository\AbsenceRepository'
|
||||
App\Repository\Contract\EmployeeContractPeriodReadRepositoryInterface: '@App\Repository\EmployeeContractPeriodRepository'
|
||||
App\Repository\Contract\EmployeeScopedRepositoryInterface: '@App\Repository\EmployeeRepository'
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.20'
|
||||
app.version: '0.1.21'
|
||||
|
||||
@@ -13,12 +13,11 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
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(
|
||||
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
|
||||
{
|
||||
$zone = strtolower(trim($zone));
|
||||
$url = self::BASE_URL."{$zone}.json";
|
||||
$url = $this->holidayUrl."{$zone}.json";
|
||||
|
||||
try {
|
||||
$response = $this->client->request(
|
||||
@@ -61,7 +60,7 @@ final class PublicHolidayService implements PublicHolidayServiceInterface
|
||||
{
|
||||
$zone = strtolower(trim($zone));
|
||||
$years = trim($years);
|
||||
$url = self::BASE_URL."{$zone}/{$years}.json";
|
||||
$url = $this->holidayUrl."{$zone}/{$years}.json";
|
||||
|
||||
try {
|
||||
$response = $this->client->request('GET', $url);
|
||||
|
||||
@@ -168,7 +168,7 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
$carrySaturdays = 0.0;
|
||||
}
|
||||
|
||||
$calculationEnd = $this->resolveCalculationEndDate($leavePolicy['ruleCode'], $year, $to);
|
||||
$calculationEnd = $this->resolveCalculationEndDate($leavePolicy['ruleCode'], $year, $to, $employee);
|
||||
$generatedDays = $leavePolicy['accrualPerMonth'] > 0.0
|
||||
? $this->computeAccruedDaysFromStart(
|
||||
$leavePolicy['acquiredDays'],
|
||||
@@ -356,7 +356,8 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
private function resolveCalculationEndDate(
|
||||
string $ruleCode,
|
||||
int $year,
|
||||
DateTimeImmutable $periodEnd
|
||||
DateTimeImmutable $periodEnd,
|
||||
Employee $employee
|
||||
): ?DateTimeImmutable {
|
||||
$today = new DateTimeImmutable('today');
|
||||
$currentYear = LeaveRuleCode::FORFAIT_218->value === $ruleCode
|
||||
@@ -364,18 +365,27 @@ final readonly class EmployeeLeaveSummaryProvider implements ProviderInterface
|
||||
: $this->resolveCurrentLeaveYear($today);
|
||||
|
||||
if ($year < $currentYear) {
|
||||
return $periodEnd;
|
||||
}
|
||||
if ($year > $currentYear) {
|
||||
return null;
|
||||
$end = $periodEnd;
|
||||
} elseif ($year > $currentYear) {
|
||||
$end = null;
|
||||
} else {
|
||||
$lastDayPreviousMonth = $today
|
||||
->modify('first day of this month')
|
||||
->modify('-1 day')
|
||||
;
|
||||
$end = $lastDayPreviousMonth < $periodEnd ? $lastDayPreviousMonth : $periodEnd;
|
||||
}
|
||||
|
||||
$lastDayPreviousMonth = $today
|
||||
->modify('first day of this month')
|
||||
->modify('-1 day')
|
||||
;
|
||||
// Cap at contract end date if the employee has left.
|
||||
$contractEndRaw = $employee->getCurrentContractEndDate();
|
||||
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