Booking Activity Tracking & Management System

๐Ÿ“„ General
โ† Back to Documentation
# Booking Activity Tracking & Management System ## Overview Complete activity logging, client contact management, room status tracking, and invoice/receipt management for bookings. --- ## ๐ŸŽฏ Features Implemented ### 1. Activity Timeline Logger ๐Ÿ“‹ - **Complete audit trail** of all booking actions - **Before/after change tracking** for important fields - **User attribution** - who made each change - **IP address logging** for security - **Formatted action display** with emojis - **Timestamp tracking** with human-readable dates ### 2. Client Contact Widget ๐Ÿ“ž - **Prominent display** at top of edit page - **Quick action buttons:** - ๐Ÿ“ž Call (tel: link) - โœ‰๏ธ Email (mailto: link) - ๐Ÿ’ฌ WhatsApp (direct message link) - **Client information:** - Name with avatar - Client ID - Address/City/Country - Total guests and nights - **Beautiful gradient design** for visibility ### 3. Room Status Tracker ๐Ÿ  - **Real-time room status** for all assigned rooms - **Housekeeping status dropdown:** - โœ… Clean - ๐Ÿงน Dirty - ๐Ÿ”„ In Progress - ๐Ÿ‘€ Inspected - **Room information:** - Room name and number - Type (Standard, Suite, etc.) - Capacity - Price per night - **Status badges:** - Room status (Available/Occupied/Maintenance) - Maintenance alerts - **Live updates** - changes reflected immediately ### 4. Invoice Management ๐Ÿ“„ - **Relation manager** for invoices - **Create/Edit/Delete** invoices - **Download PDF** functionality - **Status tracking:** - Draft - Sent - Paid - Cancelled - **Searchable** by invoice number - **Sortable** by date, amount, status ### 5. Fiscal Receipt Management ๐Ÿงพ - **Relation manager** for fiscal receipts - **Print new receipt** button - **Reprint** functionality - **Status tracking:** - Pending - Printed - Sent - Failed - **Fiscal number** tracking - **Print timestamp** recording --- ## ๐Ÿ“Š Database Schema ### booking_activity_logs Table ```sql CREATE TABLE booking_activity_logs ( id BIGINT PRIMARY KEY, booking_id BIGINT (FK to bookings), user_id BIGINT (FK to users, nullable), action VARCHAR(255), -- created, updated, checked_in, etc. description TEXT, changes JSON, -- Before/after values ip_address VARCHAR(45), user_agent TEXT, created_at TIMESTAMP, updated_at TIMESTAMP, INDEX(booking_id), INDEX(user_id), INDEX(action), INDEX(created_at) ); ``` ### venue_objects Table (Added Fields) ```sql ALTER TABLE venue_objects ADD COLUMN housekeeping_status VARCHAR(255) DEFAULT 'clean', maintenance_status VARCHAR(255) DEFAULT 'ok'; ``` ### invoices Table (Added Field) ```sql ALTER TABLE invoices ADD COLUMN booking_id BIGINT (FK to bookings, nullable); ``` ### fiscal_receipts Table (Added Field) ```sql ALTER TABLE fiscal_receipts ADD COLUMN booking_id BIGINT (FK to bookings, nullable); ``` --- ## ๐Ÿ”„ Activity Logging ### Automatic Logging **On Booking Creation:** ```php BookingActivityLog::logActivity( $booking->id, 'created', "Booking {$booking->booking_number} created", [ 'booking_number' => $booking->booking_number, 'client' => $client->name, 'venue' => $venue->name, 'check_in' => $checkIn, 'check_out' => $checkOut, 'guests' => $totalGuests, 'total_amount' => $totalAmount, ] ); ``` **On Booking Update:** ```php // Tracks changes to important fields $changes = [ 'status' => ['old' => 'pending', 'new' => 'confirmed'], 'total_amount' => ['old' => 100.00, 'new' => 150.00], ]; BookingActivityLog::logActivity( $booking->id, 'updated', 'Booking details updated', $changes ); ``` **On Status Change:** ```php // Automatically logs specific status changes - confirmed โ†’ "Booking confirmed" - checked_in โ†’ "Guest checked in" - checked_out โ†’ "Guest checked out" - cancelled โ†’ "Booking cancelled" ``` **On Room Status Update:** ```php BookingActivityLog::logActivity( $booking->id, 'room_status_updated', "Room {$room->name} status changed to: clean" ); ``` ### Manual Logging ```php use App\Models\BookingActivityLog; BookingActivityLog::logActivity( bookingId: 123, action: 'payment_received', description: 'Payment of โ‚ฌ500 received via MyPos', changes: [ 'paid_amount' => ['old' => 0, 'new' => 500], 'payment_status' => ['old' => 'pending', 'new' => 'paid'], ], userId: auth()->id() // Optional, defaults to current user ); ``` --- ## ๐ŸŽจ Widget Layout on Edit Page ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ“ž CLIENT CONTACT WIDGET (Gradient Blue) โ”‚ โ”‚ Name, Phone, Email, WhatsApp, Address โ”‚ โ”‚ Quick action buttons for communication โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ  ROOM STATUS WIDGET โ”‚ โ”‚ All assigned rooms with status dropdowns โ”‚ โ”‚ Housekeeping: Clean/Dirty/In Progress/Inspected โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ“ BOOKING FORM (Tabs) โ”‚ โ”‚ Basic Info | Rooms | Services | Guests | Spots โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ“„ INVOICES TAB โ”‚ โ”‚ List of all invoices with actions โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿงพ FISCAL RECEIPTS TAB โ”‚ โ”‚ List of all fiscal receipts with print button โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ“‹ ACTIVITY TIMELINE (Bottom) โ”‚ โ”‚ Complete history of all actions โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` --- ## ๐Ÿš€ Usage Examples ### 1. Receptionist Workflow **Guest Arrives:** 1. Open booking in edit view 2. **See client contact** at top (call if needed) 3. **Check room status** - is it clean? 4. If dirty, change to "In Progress" 5. Click "Check In" in Quick Actions 6. **Activity logged:** "Guest checked in" **Housekeeping Updates:** 1. Housekeeper cleans room 2. Change status from "Dirty" to "Clean" 3. **Activity logged:** "Room 101 status changed to: clean" **Guest Checks Out:** 1. Click "Check Out" button 2. Generate invoice if needed 3. Print fiscal receipt 4. **Activity logged:** "Guest checked out" ### 2. Manager Workflow **Review Booking History:** 1. Open booking edit page 2. Scroll to **Activity Timeline** at bottom 3. See complete history: - When created - Who made changes - What changed (before/after) - When checked in/out - All payments received **Contact Client:** 1. See **Client Contact Widget** at top 2. Click phone number to call 3. Click email to send message 4. Click WhatsApp for instant message **Check Room Readiness:** 1. View **Room Status Widget** 2. See all assigned rooms 3. Check housekeeping status 4. Verify room is ready for guest ### 3. Accounting Workflow **Generate Invoice:** 1. Go to **Invoices** tab 2. Click "New Invoice" 3. Fill in details 4. Download PDF 5. **Activity logged:** "Invoice #INV-001 created" **Print Fiscal Receipt:** 1. Go to **Fiscal Receipts** tab 2. Click "Print New Receipt" 3. Receipt prints to fiscal printer 4. **Activity logged:** "Fiscal receipt printed" --- ## ๐Ÿ” Activity Log Actions ### Standard Actions: - โœจ **created** - Booking created - ๐Ÿ“ **updated** - Booking details updated - โœ… **confirmed** - Booking confirmed - ๐Ÿ”‘ **checked_in** - Guest checked in - ๐Ÿšช **checked_out** - Guest checked out - โŒ **cancelled** - Booking cancelled - ๐Ÿ’ฐ **payment_received** - Payment received - ๐Ÿ  **room_assigned** - Room assigned - ๐Ÿงน **room_status_updated** - Room status changed - โž• **service_added** - Service added - ๐Ÿ‘ค **guest_added** - Guest added - ๐Ÿ“„ **invoice_created** - Invoice created - ๐Ÿงพ **receipt_printed** - Fiscal receipt printed ### Custom Actions: You can log any custom action: ```php BookingActivityLog::logActivity( $booking->id, 'custom_action', 'Your custom description', ['any' => 'data'] ); ``` --- ## ๐ŸŽจ Housekeeping Status Options ```php 'clean' => 'โœ… Clean' // Room is ready 'dirty' => '๐Ÿงน Dirty' // Needs cleaning 'in_progress' => '๐Ÿ”„ In Progress' // Being cleaned 'inspected' => '๐Ÿ‘€ Inspected' // Quality checked ``` ### Status Colors: - **Clean:** Green - **Dirty:** Red - **In Progress:** Yellow - **Inspected:** Blue --- ## ๐Ÿ” Security Features ### Activity Log Security: - โœ… IP address recorded for each action - โœ… User agent tracked - โœ… User attribution (who made the change) - โœ… Timestamp with timezone - โœ… Immutable log (no editing) - โœ… Cascade delete protection ### Access Control: - โœ… Only admins see IP addresses - โœ… Activity log visible to authorized users - โœ… Room status changes logged - โœ… All modifications tracked --- ## ๐Ÿ“ฑ Responsive Design All widgets are fully responsive: - **Desktop:** Full layout with all widgets - **Tablet:** Stacked widgets, readable - **Mobile:** Optimized for small screens --- ## ๐Ÿงช Testing ### Test Activity Logging: ```bash # Create a booking php artisan tinker >>> $booking = Booking::first(); >>> BookingActivityLog::logActivity($booking->id, 'test', 'Test activity'); >>> $booking->activityLogs; // Should show the log ``` ### Test Room Status: ```bash # Update room status >>> $room = VenueObject::first(); >>> $room->update(['housekeeping_status' => 'clean']); ``` ### Test Widgets: 1. Open any booking in edit mode 2. Verify client contact widget appears at top 3. Verify room status widget shows assigned rooms 4. Verify activity timeline at bottom 5. Check Invoices and Fiscal Receipts tabs --- ## ๐Ÿ”ง Configuration ### Customize Activity Log Display: Edit `BookingActivityLog` model: ```php public function getFormattedActionAttribute(): string { return match($this->action) { 'created' => 'โœจ Created', 'your_action' => '๐ŸŽฏ Your Label', default => '๐Ÿ“Œ ' . ucfirst($this->action), }; } ``` ### Customize Room Status Options: Edit `RoomStatusWidget`: ```php <option value="your_status">๐Ÿท๏ธ Your Status</option> ``` ### Customize Client Contact Widget: Edit `client-contact-widget.blade.php` to add more contact methods or information. --- ## ๐Ÿ“Š Reports & Analytics ### Activity Summary: ```php // Get all activities for a booking $activities = $booking->activityLogs; // Get activities by action $checkIns = $booking->activityLogs() ->where('action', 'checked_in') ->get(); // Get activities by user $userActivities = $booking->activityLogs() ->where('user_id', $userId) ->get(); // Get activities in date range $activities = $booking->activityLogs() ->whereBetween('created_at', [$start, $end]) ->get(); ``` --- ## ๐Ÿš€ Next Steps ### Enhancements: 1. โœ… Activity logging - DONE 2. โœ… Client contact widget - DONE 3. โœ… Room status tracking - DONE 4. โœ… Invoice management - DONE 5. โœ… Fiscal receipt management - DONE 6. โณ Email notifications on status changes 7. โณ SMS notifications for check-in/out 8. โณ Export activity log to PDF 9. โณ Activity statistics dashboard 10. โณ Automated room status updates --- ## ๐Ÿ“ Migration Commands ```bash # Run all migrations php artisan migrate # Specific migrations php artisan migrate --path=/database/migrations/2025_10_16_070500_create_booking_activity_logs_table.php php artisan migrate --path=/database/migrations/2025_10_16_071000_add_status_fields_to_venue_objects_table.php php artisan migrate --path=/database/migrations/2025_10_16_071500_add_booking_id_to_invoices_table.php php artisan migrate --path=/database/migrations/2025_10_16_071600_add_booking_id_to_fiscal_receipts_table.php ``` --- ## โœ… Summary **Complete booking management system with:** - โœ… Full activity audit trail - โœ… Client contact information (prominent display) - โœ… Real-time room status tracking - โœ… Invoice management (relation manager) - โœ… Fiscal receipt management (relation manager) - โœ… Automatic activity logging - โœ… User attribution and IP tracking - โœ… Beautiful, responsive UI - โœ… Quick action buttons - โœ… Complete change history **Everything a receptionist or manager needs to efficiently manage bookings!** ๐ŸŽฏ