'admin']); Role::create(['name' => 'manager']); Role::create(['name' => 'staff']); $admin = User::create([ 'name' => 'Admin', 'email' => 'admin@minicrm.local', 'password' => bcrypt('password'), 'role' => 'admin', ]); $admin->assignRole('admin'); $manager = User::create([ 'name' => 'Manager', 'email' => 'manager@minicrm.local', 'password' => bcrypt('password'), 'role' => 'manager', ]); $manager->assignRole('manager'); $staff = User::create([ 'name' => 'Staff', 'email' => 'staff@minicrm.local', 'password' => bcrypt('password'), 'role' => 'staff', ]); $staff->assignRole('staff'); $depCskh = Department::create(['name' => 'Phòng CSKH', 'manager_id' => $manager->id]); $depKythuat = Department::create(['name' => 'Phòng Kỹ thuật', 'manager_id' => $admin->id]); $depKetoan = Department::create(['name' => 'Phòng Kế toán', 'manager_id' => null]); $depPhaply = Department::create(['name' => 'Phòng Pháp lý', 'manager_id' => null]); $channels = [ ['name' => 'Email', 'slug' => 'email', 'icon' => 'heroicon-o-envelope'], ['name' => 'Zalo', 'slug' => 'zalo', 'icon' => 'heroicon-o-chat-bubble-left'], ['name' => 'Phone', 'slug' => 'phone', 'icon' => 'heroicon-o-phone'], ['name' => 'Document', 'slug' => 'document', 'icon' => 'heroicon-o-document-text'], ['name' => 'In Person', 'slug' => 'in-person', 'icon' => 'heroicon-o-user'], ]; foreach ($channels as $channel) { FeedbackChannel::create($channel); } $products = [ ['name' => 'Sunrise Apartment A1', 'description' => 'Luxury apartment in District 1, 3 bedrooms, river view', 'status' => 'active'], ['name' => 'Sunrise Apartment A2', 'description' => 'Premium apartment in District 1, 2 bedrooms, city view', 'status' => 'active'], ['name' => 'Green Valley Villa', 'description' => 'Standalone villa with private garden and pool', 'status' => 'active'], ['name' => 'Ocean Tower Office', 'description' => 'High-end office space in central business district', 'status' => 'sold_out'], ['name' => 'Park Hill Townhouse', 'description' => 'Modern townhouse near the park, 4 bedrooms', 'status' => 'inactive'], ]; foreach ($products as $product) { Product::create($product); } $customers = [ ['name' => 'Nguyen Van A', 'email' => 'nguyenvana@example.com', 'phone' => '0909123456', 'address' => 'Hanoi'], ['name' => 'Tran Thi B', 'email' => 'tranthib@example.com', 'phone' => '0918234567', 'address' => 'Ho Chi Minh City'], ['name' => 'Le Van C', 'email' => 'levanc@example.com', 'phone' => '0927345678', 'address' => 'Da Nang'], ['name' => 'Pham Thi D', 'email' => 'phamthid@example.com', 'phone' => '0936456789', 'address' => 'Can Tho'], ]; foreach ($customers as $customerData) { Customer::create($customerData); } $customers = Customer::all(); $products = Product::where('status', 'active')->get(); $channels = FeedbackChannel::all(); $customers[0]->products()->attach($products[0]->id, ['purchase_date' => '2024-01-15']); $customers[0]->products()->attach($products[1]->id, ['purchase_date' => '2024-06-01']); $customers[1]->products()->attach($products[0]->id, ['purchase_date' => '2024-03-20']); $customers[2]->products()->attach($products[2]->id, ['purchase_date' => '2024-09-10']); $customers[3]->products()->attach($products[1]->id, ['purchase_date' => '2025-01-05']); $customers[3]->products()->attach($products[2]->id, ['purchase_date' => '2025-02-15']); $customerProduct1 = \App\Models\CustomerProduct::where('customer_id', $customers[0]->id)->where('product_id', $products[0]->id)->first(); $customerProduct2 = \App\Models\CustomerProduct::where('customer_id', $customers[0]->id)->where('product_id', $products[1]->id)->first(); $customerProduct3 = \App\Models\CustomerProduct::where('customer_id', $customers[1]->id)->where('product_id', $products[0]->id)->first(); $feedbacks = [ [ 'customer_id' => $customers[0]->id, 'customer_product_id' => $customerProduct1->id, 'feedback_channel_id' => $channels->firstWhere('slug', 'email')->id, 'title' => 'Leaking ceiling in living room', 'content' => 'I noticed water stains on the ceiling of the living room after heavy rain. Please send someone to inspect and fix.', 'status' => 'pending', 'assigned_to' => $staff->id, 'current_department_id' => $depCskh->id, ], [ 'customer_id' => $customers[0]->id, 'customer_product_id' => $customerProduct2->id, 'feedback_channel_id' => $channels->firstWhere('slug', 'phone')->id, 'title' => 'Request for parking slot upgrade', 'content' => 'I would like to upgrade from one parking slot to two. Please advise on availability and pricing.', 'status' => 'processing', 'assigned_to' => $manager->id, 'current_department_id' => $depCskh->id, ], [ 'customer_id' => $customers[1]->id, 'customer_product_id' => $customerProduct3->id, 'feedback_channel_id' => $channels->firstWhere('slug', 'zalo')->id, 'title' => 'AC not cooling properly', 'content' => 'The air conditioner in the master bedroom is making loud noises and not cooling effectively.', 'status' => 'resolved', 'assigned_to' => $staff->id, 'current_department_id' => $depKythuat->id, ], [ 'customer_id' => $customers[2]->id, 'customer_product_id' => null, 'feedback_channel_id' => $channels->firstWhere('slug', 'document')->id, 'title' => 'General feedback on community services', 'content' => 'I suggest improving the garbage collection schedule to twice a day instead of once. Also, the security guard shift changes could be more organized.', 'status' => 'pending', 'assigned_to' => null, 'current_department_id' => $depCskh->id, ], [ 'customer_id' => $customers[3]->id, 'customer_product_id' => \App\Models\CustomerProduct::where('customer_id', $customers[3]->id)->where('product_id', $products[1]->id)->first()->id, 'feedback_channel_id' => $channels->firstWhere('slug', 'email')->id, 'title' => 'Kitchen cabinet hinge broken', 'content' => 'One of the kitchen cabinet hinges is broken. It is still under warranty, please arrange replacement.', 'status' => 'closed', 'assigned_to' => $staff->id, 'current_department_id' => $depKythuat->id, ], ]; foreach ($feedbacks as $feedback) { Feedback::create($feedback); } $tags = [ ['name' => 'Leaking', 'slug' => 'leaking', 'color' => '#3b82f6'], ['name' => 'Electrical', 'slug' => 'electrical', 'color' => '#f59e0b'], ['name' => 'Warranty', 'slug' => 'warranty', 'color' => '#10b981'], ['name' => 'Maintenance', 'slug' => 'maintenance', 'color' => '#8b5cf6'], ['name' => 'Service Request', 'slug' => 'service-request', 'color' => '#ec4899'], ]; foreach ($tags as $tag) { \App\Models\FeedbackTag::create($tag); } $allFeedback = Feedback::all(); $allTags = \App\Models\FeedbackTag::all(); $allFeedback[0]->tags()->attach([$allTags[0]->id, $allTags[3]->id]); $allFeedback[1]->tags()->attach([$allTags[4]->id]); $allFeedback[2]->tags()->attach([$allTags[1]->id, $allTags[2]->id]); $allFeedback[3]->tags()->attach([$allTags[3]->id]); $allFeedback[4]->tags()->attach([$allTags[2]->id, $allTags[3]->id]); \App\Models\FeedbackInteraction::create([ 'feedback_id' => $allFeedback[0]->id, 'user_id' => $admin->id, 'type' => 'note', 'content' => 'Feedback received via Email. Assigned to Staff for initial handling.', 'changes' => ['status' => ['old' => null, 'new' => 'pending']], ]); \App\Models\FeedbackInteraction::create([ 'feedback_id' => $allFeedback[0]->id, 'user_id' => $staff->id, 'type' => 'note', 'content' => 'Contacted customer via phone. Scheduled inspection for next Tuesday. Customer agreed.', ]); \App\Models\FeedbackInteraction::create([ 'feedback_id' => $allFeedback[2]->id, 'user_id' => $staff->id, 'type' => 'status_change', 'content' => 'Technician visited site on 2024-06-10. AC repaired. Customer confirmed cooling is now normal.', 'changes' => ['status' => ['old' => 'processing', 'new' => 'resolved']], ]); \App\Models\FeedbackInteraction::create([ 'feedback_id' => $allFeedback[1]->id, 'user_id' => $manager->id, 'type' => 'note', 'content' => 'Parking upgrade available. Sent quotation via email. Waiting for customer confirmation.', ]); \App\Models\FeedbackInteraction::create([ 'feedback_id' => $allFeedback[4]->id, 'user_id' => $staff->id, 'type' => 'status_change', 'content' => 'Replacement hinge installed on 2025-03-01. All kitchen cabinets now working properly.', 'changes' => ['status' => ['old' => 'processing', 'new' => 'closed']], ]); \App\Models\TicketTransferLog::create([ 'feedback_id' => $allFeedback[2]->id, 'from_department_id' => $depCskh->id, 'to_department_id' => $depKythuat->id, 'sender_id' => $manager->id, 'reason' => 'Vấn đề kỹ thuật về điều hòa, cần Phòng Kỹ thuật kiểm tra và xử lý.', ]); \App\Models\FeedbackAttachment::create([ 'uuid' => \Illuminate\Support\Str::uuid(), 'feedback_id' => $allFeedback[2]->id, 'user_id' => $staff->id, 'name' => 'ac_repair_report.pdf', 'path' => 'feedback-attachments/ac_repair_report.pdf', 'disk' => 'local', 'collection' => 'proof_of_resolution', 'mime_type' => 'application/pdf', 'size' => 204800, ]); \App\Models\FeedbackAttachment::create([ 'uuid' => \Illuminate\Support\Str::uuid(), 'feedback_id' => $allFeedback[0]->id, 'user_id' => $staff->id, 'name' => 'ceiling_photo.jpg', 'path' => 'feedback-attachments/ceiling_photo.jpg', 'disk' => 'local', 'collection' => 'customer_evidence', 'mime_type' => 'image/jpeg', 'size' => 512000, ]); \App\Models\FeedbackAttachment::create([ 'uuid' => \Illuminate\Support\Str::uuid(), 'feedback_id' => $allFeedback[4]->id, 'user_id' => $staff->id, 'name' => 'replaced_hinge_photo.png', 'path' => 'feedback-attachments/replaced_hinge_photo.png', 'disk' => 'local', 'collection' => 'proof_of_resolution', 'mime_type' => 'image/png', 'size' => 307200, ]); } }