@extends('layouts.worker')
@php
$userTranslations = \App\Helpers\TranslationHelper::getUserTranslations();
@endphp
@section('title', $userTranslations['translations']['invoices']['title'] ?? 'Mes Factures')
@push('styles')
@endpush
@section('content')
@php
// Extraire l'année et le mois
list($year, $month) = explode('-', $selectedMonth);
$year = (int)$year;
$month = (int)$month;
// Mois précédent
$prevMonth = $month > 1 ?
$year . '-' . str_pad($month - 1, 2, '0', STR_PAD_LEFT) :
($year - 1) . '-12';
// Mois suivant
$nextMonth = $month < 12 ?
$year . '-' . str_pad($month + 1, 2, '0', STR_PAD_LEFT) :
($year + 1) . '-01';
// Vérifier si le mois suivant est dans le futur
$currentYear = (int)date('Y');
$currentMonth = (int)date('m');
$isNextMonthDisabled = ($month == 12 && $year + 1 > $currentYear) ||
($year > $currentYear || ($year == $currentYear && $month + 1 > $currentMonth));
// Formater le mois pour l'affichage
$translations = \App\Helpers\TranslationHelper::getUserTranslations()['translations'];
$monthNames = [];
if (isset($translations['months'])) {
$monthNames = [
1 => $translations['months']['january'] ?? 'janvier',
2 => $translations['months']['february'] ?? 'février',
3 => $translations['months']['march'] ?? 'mars',
4 => $translations['months']['april'] ?? 'avril',
5 => $translations['months']['may'] ?? 'mai',
6 => $translations['months']['june'] ?? 'juin',
7 => $translations['months']['july'] ?? 'juillet',
8 => $translations['months']['august'] ?? 'août',
9 => $translations['months']['september'] ?? 'septembre',
10 => $translations['months']['october'] ?? 'octobre',
11 => $translations['months']['november'] ?? 'novembre',
12 => $translations['months']['december'] ?? 'décembre'
];
} else {
$monthNames = [
1 => 'janvier', 2 => 'février', 3 => 'mars', 4 => 'avril',
5 => 'mai', 6 => 'juin', 7 => 'juillet', 8 => 'août',
9 => 'septembre', 10 => 'octobre', 11 => 'novembre', 12 => 'décembre'
];
}
$monthYearFormat = $translations['schedules']['month_year_format'] ?? '{month} {year}';
$displayMonth = ucfirst($monthNames[$month]);
$displayMonth = str_replace('{month}', $displayMonth, $monthYearFormat);
$displayMonth = str_replace('{year}', $year, $displayMonth);
@endphp
{{ $displayMonth }}
@if($isNextMonthDisabled)
@else
@endif
@if($invoices->isEmpty())
{{ $userTranslations['translations']['invoices']['no_invoices_title'] ?? 'Aucune facture' }}
{{ $userTranslations['translations']['invoices']['no_invoices_text'] ?? 'Aucune facture générée pour ce mois.' }}
@else
@foreach($invoices as $invoice)
{{ \Carbon\Carbon::parse($invoice->invoice_date)->format('d/m/Y') }}
{{ number_format($invoice->total, 2, ',', ' ') }} €
@endforeach
@endif