where('user_type', 'SuperAdmin')->find_one(); $adminId = $admin ? $admin['id'] : 1; $successCount = 0; $errorCount = 0; for ($i = 1; $i <= 60; $i++) { try { // Generate random data $firstName = $firstNames[array_rand($firstNames)]; $lastName = $lastNames[array_rand($lastNames)]; $fullname = $firstName . ' ' . $lastName; $username = generatePhoneNumber(); $email = generateEmail($firstName, $lastName); $city = $cities[array_rand($cities)]; $district = $districts[array_rand($districts)]; $state = $states[array_rand($states)]; $serviceType = $serviceTypes[array_rand($serviceTypes)]; $accountType = $accountTypes[array_rand($accountTypes)]; $status = $statuses[array_rand($statuses)]; $balance = generateBalance(); $coordinates = generateCoordinates(); $address = generateAddress($city); $zip = generateZipCode(); $phonenumber = generatePhoneNumber(); // Generate passwords $password = 'client' . $i . 'pass'; $pppoePassword = 'pppoe' . $i . 'pass'; // Create customer record $customer = ORM::for_table('tbl_customers')->create(); $customer->username = $username; $customer->password = $password; $customer->pppoe_password = $pppoePassword; $customer->email = $email; $customer->account_type = $accountType; $customer->fullname = $fullname; $customer->address = $address; $customer->created_by = $adminId; $customer->phonenumber = $phonenumber; $customer->service_type = $serviceType; $customer->coordinates = $coordinates; $customer->city = $city; $customer->district = $district; $customer->state = $state; $customer->zip = $zip; $customer->balance = $balance; $customer->auto_renewal = rand(0, 1); $customer->status = $status; if ($customer->save()) { $successCount++; echo "Created client #$i: $fullname ($email) - $serviceType - $accountType - $status\n"; // Add some custom fields for variety if (rand(0, 1)) { // 50% chance of having custom fields $customFields = [ 'Company' => 'Company ' . $i, 'Department' => ['IT', 'Sales', 'Marketing', 'Finance', 'HR'][array_rand(['IT', 'Sales', 'Marketing', 'Finance', 'HR'])], 'Referral' => ['Website', 'Friend', 'Advertisement', 'Walk-in', 'Social Media'][array_rand(['Website', 'Friend', 'Advertisement', 'Walk-in', 'Social Media'])], 'Notes' => 'Customer notes for ' . $fullname ]; foreach ($customFields as $fieldName => $fieldValue) { $customField = ORM::for_table('tbl_customers_fields')->create(); $customField->customer_id = $customer->id(); $customField->field_name = $fieldName; $customField->field_value = $fieldValue; $customField->save(); } } } else { $errorCount++; echo "Failed to create client #$i\n"; } } catch (Exception $e) { $errorCount++; echo "Error creating client #$i: " . $e->getMessage() . "\n"; } } echo "\nSeeding completed!\n"; echo "Successfully created: $successCount clients\n"; echo "Errors: $errorCount\n"; echo "Total clients in database: " . ORM::for_table('tbl_customers')->count() . "\n"; } catch (Exception $e) { echo "Fatal error: " . $e->getMessage() . "\n"; } ?>