diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6df8428 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 + +[{compose,docker-compose}.{yml,yaml}] +indent_size = 4 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..50a5b8b --- /dev/null +++ b/.env.example @@ -0,0 +1,86 @@ +APP_NAME=Laverie +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost:8000 + +APP_LOCALE=fr +APP_FALLBACK_LOCALE=fr +APP_FAKER_LOCALE=fr_FR + +APP_MAINTENANCE_DRIVER=file +# APP_MAINTENANCE_STORE=database + +# PHP_CLI_SERVER_WORKERS=4 + +BCRYPT_ROUNDS=12 + +LOG_CHANNEL=stack +LOG_STACK=single +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +# Base de données MySQL (schéma laverie — voir docker-compose.yml) +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=laverie +DB_USERNAME=laverie +DB_PASSWORD=laverie + +SESSION_DRIVER=database +SESSION_LIFETIME=120 +SESSION_ENCRYPT=false +SESSION_PATH=/ +SESSION_DOMAIN=null + +BROADCAST_CONNECTION=log +FILESYSTEM_DISK=local +QUEUE_CONNECTION=redis + +CACHE_STORE=redis +# CACHE_PREFIX= + +MEMCACHED_HOST=127.0.0.1 + +REDIS_CLIENT=phpredis +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=log +MAIL_SCHEME=null +MAIL_HOST=127.0.0.1 +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_FROM_ADDRESS="noreply@laverie.local" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=eu-west-3 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +VITE_APP_NAME="${APP_NAME}" + +# --- Configuration Laverie --- + +# Clé API pour les webhooks / intégrations machines (header X-Machine-Api-Key) +LAVERIE_MACHINE_API_KEY=demo-machine-api-key-change-me + +# Simulation de cycle machine (démo sans matériel) +LAVERIE_SIM_CYCLE_SECONDS=30 + +# Réservations +LAVERIE_BOOKING_FEE=1.00 +LAVERIE_BOOKING_CANCEL_GRACE_HOURS=2 +LAVERIE_BOOKING_NO_SHOW_GRACE_MINUTES=15 +LAVERIE_BOOKING_PENALTY_AMOUNT=3.00 + +# Machines +LAVERIE_MACHINE_OFFLINE_THRESHOLD_MINUTES=10 + +# Paiements +LAVERIE_PAYMENT_PROVIDER=simulated diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcb21d3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +* text=auto eol=lf + +*.blade.php diff=html +*.css diff=css +*.html diff=html +*.md diff=markdown +*.php diff=php + +/.github export-ignore +CHANGELOG.md export-ignore +.styleci.yml export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7be55e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +*.log +.DS_Store +.env +.env.backup +.env.production +.phpactor.json +.phpunit.result.cache +/.codex +/.cursor/ +/.idea +/.nova +/.phpunit.cache +/.vscode +/.zed +/auth.json +/node_modules +/public/build +/public/fonts-manifest.dev.json +/public/hot +/public/storage +/storage/*.key +/storage/pail +/vendor +_ide_helper.php +Homestead.json +Homestead.yaml +Thumbs.db diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..495a6af --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +ignore-scripts=true +audit=true diff --git a/README.md b/README.md index d483ec4..5a68b5d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,63 @@ -# backend +
+ + +```cmd +/c/wamp64/bin/php/php8.3.28/php.exe artisan serve +vite +``` + +## About Laravel + +Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: + +- [Simple, fast routing engine](https://laravel.com/docs/routing). +- [Powerful dependency injection container](https://laravel.com/docs/container). +- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. +- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). +- Database agnostic [schema migrations](https://laravel.com/docs/migrations). +- [Robust background job processing](https://laravel.com/docs/queues). +- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). + +Laravel is accessible, powerful, and provides tools required for large, robust applications. + +## Learning Laravel + +Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. + +In addition, [Laracasts](https://laracasts.com) contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. + +You can also watch bite-sized lessons with real-world projects on [Laravel Learn](https://laravel.com/learn), where you will be guided through building a Laravel application from scratch while learning PHP fundamentals. + +## Agentic Development + +Laravel's predictable structure and conventions make it ideal for AI coding agents like Claude Code, Cursor, and GitHub Copilot. Install [Laravel Boost](https://laravel.com/docs/ai) to supercharge your AI workflow: + +```bash +composer require laravel/boost --dev + +php artisan boost:install +``` + +Boost provides your agent 15+ tools and skills that help agents build Laravel applications while following best practices. + +## Contributing + +Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). + +## Code of Conduct + +In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). + +## Security Vulnerabilities + +If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. + +## License + +The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/app/Domain/Integration/MachineCommandResult.php b/app/Domain/Integration/MachineCommandResult.php new file mode 100644 index 0000000..24b1cca --- /dev/null +++ b/app/Domain/Integration/MachineCommandResult.php @@ -0,0 +1,29 @@ + $metadata + */ + public function __construct( + public string $status, + public ?CarbonInterface $lastHeartbeat = null, + public array $metadata = [], + ) {} +} diff --git a/app/Domain/Integration/SimulatedMachineProvider.php b/app/Domain/Integration/SimulatedMachineProvider.php new file mode 100644 index 0000000..ae6dd6e --- /dev/null +++ b/app/Domain/Integration/SimulatedMachineProvider.php @@ -0,0 +1,219 @@ +addSeconds($durationSeconds); + + $command = MachineCommand::query()->create([ + 'uuid' => (string) Str::uuid(), + 'machine_id' => $machine->id, + 'provider' => $provider, + 'command_type' => 'start_cycle', + 'payload' => $payload, + 'status' => 'acknowledged', + 'external_reference' => $externalReference, + 'correlation_id' => $correlationId, + 'requested_by_user_id' => $payload['requested_by_user_id'] ?? null, + 'sent_at' => now(), + 'responded_at' => now(), + ]); + + $previousStatus = $machine->status; + + $machine->update([ + 'status' => 'running', + 'current_user_id' => $payload['requested_by_user_id'] ?? $machine->current_user_id, + 'cycle_started_at' => now(), + 'cycle_ends_at' => $cycleEndsAt, + 'last_heartbeat_at' => now(), + ]); + + $this->recordStatusChange($machine, $previousStatus, 'running', $provider, 'cycle_started'); + $this->recordEvent($machine, $provider, 'cycle_started', [ + 'command_uuid' => $command->uuid, + 'wash_uuid' => $payload['wash_uuid'] ?? null, + ]); + + SimulateCycleCompletion::dispatch( + $machine->id, + $command->id, + $payload['wash_id'] ?? null, + )->delay($cycleEndsAt); + + return MachineCommandResult::success('acknowledged', $externalReference, $correlationId); + } + + public function stopCycle(Machine $machine, array $payload = []): MachineCommandResult + { + $provider = config('laverie.simulation.provider_name', 'simulated'); + $correlationId = (string) Str::uuid(); + + MachineCommand::query()->create([ + 'uuid' => (string) Str::uuid(), + 'machine_id' => $machine->id, + 'provider' => $provider, + 'command_type' => 'stop_cycle', + 'payload' => $payload, + 'status' => 'acknowledged', + 'correlation_id' => $correlationId, + 'sent_at' => now(), + 'responded_at' => now(), + ]); + + $previousStatus = $machine->status; + + $machine->update([ + 'status' => 'available', + 'current_user_id' => null, + 'cycle_started_at' => null, + 'cycle_ends_at' => null, + 'last_heartbeat_at' => now(), + ]); + + $this->recordStatusChange($machine, $previousStatus, 'available', $provider, 'cycle_stopped'); + $this->recordEvent($machine, $provider, 'cycle_completed', ['reason' => 'manual_stop']); + + return MachineCommandResult::success('acknowledged', null, $correlationId); + } + + public function refreshStatus(Machine $machine): MachineStatusSnapshot + { + $machine->refresh(); + + return new MachineStatusSnapshot( + status: $machine->status, + lastHeartbeat: $machine->last_heartbeat_at, + metadata: [ + 'cycle_started_at' => $machine->cycle_started_at?->toIso8601String(), + 'cycle_ends_at' => $machine->cycle_ends_at?->toIso8601String(), + 'current_user_id' => $machine->current_user_id, + ], + ); + } + + public function handleInboundEvent(array $payload): void + { + $externalMachineId = $payload['external_machine_id'] ?? $payload['machine_id'] ?? null; + + if ($externalMachineId === null) { + return; + } + + $integration = \App\Models\MachineIntegration::query() + ->where('external_machine_id', (string) $externalMachineId) + ->where('is_active', true) + ->first(); + + if ($integration === null) { + return; + } + + $machine = $integration->machine; + $provider = $integration->provider; + $eventType = $payload['event_type'] ?? 'status_changed'; + + if ($eventType === 'heartbeat') { + $machine->update(['last_heartbeat_at' => now()]); + + if ($machine->status === 'offline') { + $previousStatus = $machine->status; + $machine->update(['status' => 'available']); + $this->recordStatusChange($machine, $previousStatus, 'available', $provider, 'heartbeat'); + } + } + + if ($eventType === 'machine_offline') { + $previousStatus = $machine->status; + $machine->update(['status' => 'offline']); + $this->recordStatusChange($machine, $previousStatus, 'offline', $provider, 'machine_offline'); + } + + if ($eventType === 'machine_online') { + $previousStatus = $machine->status; + $machine->update(['status' => 'available', 'last_heartbeat_at' => now()]); + $this->recordStatusChange($machine, $previousStatus, 'available', $provider, 'machine_online'); + } + + if ($eventType === 'cycle_completed') { + $previousStatus = $machine->status; + $machine->update([ + 'status' => 'available', + 'current_user_id' => null, + 'cycle_started_at' => null, + 'cycle_ends_at' => null, + 'last_heartbeat_at' => now(), + ]); + $this->recordStatusChange($machine, $previousStatus, 'available', $provider, 'cycle_completed'); + } + + if ($eventType === 'error_reported') { + $previousStatus = $machine->status; + $machine->update(['status' => 'error']); + $this->recordStatusChange($machine, $previousStatus, 'error', $provider, 'error_reported'); + } + + $this->recordEvent( + $machine, + $provider, + $eventType, + $payload, + $payload['external_event_id'] ?? null, + ); + } + + private function recordStatusChange( + Machine $machine, + ?string $previousStatus, + string $newStatus, + string $source, + string $reason, + ): void { + MachineStatusHistory::query()->create([ + 'machine_id' => $machine->id, + 'previous_status' => $previousStatus, + 'new_status' => $newStatus, + 'source' => $source, + 'reason' => $reason, + 'created_at' => Carbon::now(), + ]); + } + + /** + * @param array+ {{ message }} +
++ Once your account is deleted, all of its resources and data will + be permanently deleted. Before deleting your account, please + download any data or information that you wish to retain. +
++ Once your account is deleted, all of its resources and data + will be permanently deleted. Please enter your password to + confirm you would like to permanently delete your account. +
+ ++ Ensure your account is using a long, random password to stay + secure. +
++ Update your account's profile information and email address. +
+Connexion exploitant
+| Créneau | +Utilisateur | +Machine | +Statut | +Frais | +
|---|---|---|---|---|
| + Aucune réservation trouvée. + | +||||
|
+ {{ formatDate(booking.slot_start) }}
+ → {{ formatDate(booking.slot_end) }}
+ |
+
+ {{ booking.user?.name ?? '—' }}
+ {{ booking.user?.email }}
+ |
+
+
+ {{ booking.machine.name }}
+
+ —
+
+ {{ booking.machine.establishment_name }}
+
+ |
+ + + {{ booking.status_label }} + + | ++ {{ formatCurrency(booking.booking_fee) }} + | +
+ {{ bookings.from ?? 0 }}–{{ bookings.to ?? 0 }} sur {{ bookings.total }} +
+Chiffre d'affaires aujourd'hui
++ {{ formatCurrency(kpis.revenue_today) }} +
+Lavages aujourd'hui
+{{ kpis.washes_today }}
+Réservations aujourd'hui
+{{ kpis.bookings_today }}
+Machines hors ligne
++ {{ kpis.offline_machines }} + / {{ kpis.machines_total }} +
+{{ alert.message }}
+{{ formatDate(alert.occurred_at) }}
++ {{ machine.establishment_name }} · {{ machine.type_label }} +
+| + Machine + | ++ Établissement + | ++ Type + | ++ Statut + | ++ Dernier signal + | +
|---|---|---|---|---|
| + Aucune machine trouvée. + | +||||
| + + {{ machine.name }} + + | ++ {{ machine.establishment_name ?? '—' }} + | ++ {{ machine.type_label }} + | ++ + {{ machine.status_label }} + + | ++ {{ formatDate(machine.last_heartbeat_at) }} + | +
+ {{ machines.from ?? 0 }}–{{ machines.to ?? 0 }} sur {{ machines.total }} +
+{{ machine.establishment?.name }}
+{{ machine.establishment.address }}
++ {{ machine.establishment.city }} +
+{{ event.event_type_label }}
+{{ formatDate(event.occurred_at) }}
+| Établissement | +Créneau | +Type | +Prix | +Statut | +Actions | +
|---|---|---|---|---|---|
| + Aucune règle tarifaire configurée. + | +|||||
| {{ rule.establishment_name }} | ++ {{ rule.slot_start }} – {{ rule.slot_end }} + ({{ rule.day_type_label }}) + | ++ {{ rule.machine_type_label ?? 'Tous' }} + | ++ {{ formatCurrency(rule.price) }} + | ++ + {{ rule.is_active ? 'Active' : 'Inactive' }} + + | ++ + + | +
| Établissement | +Remise | +Période | +Machines | +Statut | +Actions | +
|---|---|---|---|---|---|
| + Aucune promotion configurée. + | +|||||
| {{ promotion.establishment_name }} | ++ {{ formatDiscount(promotion) }} + | +
+ {{ formatDate(promotion.starts_at) }}
+ → {{ formatDate(promotion.ends_at) }}
+ |
+ {{ promotion.machine_type_label }} | ++ + {{ + isCurrentlyActive(promotion) + ? 'En cours' + : promotion.is_active + ? 'Programmée' + : 'Inactive' + }} + + | ++ + + | +
| Début | +Utilisateur | +Machine | +Statut | +Durée | +Coût | +
|---|---|---|---|---|---|
| + Aucun lavage trouvé. + | +|||||
| + {{ formatDate(wash.started_at) }} + | +
+ {{ wash.user?.name ?? '—' }}
+ {{ wash.user?.email }}
+ |
+ + + {{ wash.machine.name }} + + — + | ++ + {{ wash.status_label }} + + | ++ {{ wash.duration_minutes ? `${wash.duration_minutes} min` : '—' }} + | ++ {{ formatCurrency(wash.cost) }} + | +
+ {{ washes.from ?? 0 }}–{{ washes.to ?? 0 }} sur {{ washes.total }} +
++ Laravel has wonderful documentation + covering every aspect of the + framework. Whether you are a + newcomer or have prior experience + with Laravel, we recommend reading + our documentation from beginning to + end. +
++ Laracasts offers thousands of video + tutorials on Laravel, PHP, and JavaScript + development. Check them out, see for + yourself, and massively level up your + development skills in the process. +
++ Laravel News is a community driven portal + and newsletter aggregating all of the latest + and most important news in the Laravel + ecosystem, including new package releases + and tutorials. +
++ Laravel's robust library of first-party + tools and libraries, such as + Forge, + Vapor, + Nova, + Envoyer, and + Herd + help you take your projects to the next + level. Pair them with powerful open source + libraries like + Cashier, + Dusk, + Echo, + Horizon, + Sanctum, + Telescope, and more. +
+