diff --git a/app/Models/AdminModel.php b/app/Models/Administrator.php similarity index 87% rename from app/Models/AdminModel.php rename to app/Models/Administrator.php index 0e37d73..108513d 100644 --- a/app/Models/AdminModel.php +++ b/app/Models/Administrator.php @@ -2,14 +2,13 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -class AdminModel extends Authenticatable +class Administrator extends Authenticatable { - protected $table = 'admins'; - - use Notifiable; + use HasFactory, Notifiable; /** * The attributes that are mass assignable. diff --git a/app/Models/ClientsModel.php b/app/Models/Client.php similarity index 68% rename from app/Models/ClientsModel.php rename to app/Models/Client.php index 3f31220..a4d1eb2 100644 --- a/app/Models/ClientsModel.php +++ b/app/Models/Client.php @@ -4,15 +4,13 @@ use App\Relations\Has\HasManyCompanies; use App\Relations\Has\HasManyEmployees; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -class ClientsModel extends Model +class Client extends Model { - use SoftDeletes, HasManyEmployees, HasManyCompanies; - - protected $table = 'clients'; - protected $dates = ['deleted_at']; + use HasFactory, SoftDeletes, HasManyEmployees, HasManyCompanies; protected $fillable = [ 'full_name', 'phone', 'email', 'section', 'budget', 'location', 'zip', 'city', 'country', 'is_active', 'admin_id' diff --git a/app/Models/CompaniesModel.php b/app/Models/CompaniesModel.php deleted file mode 100644 index 29fe9c2..0000000 --- a/app/Models/CompaniesModel.php +++ /dev/null @@ -1,35 +0,0 @@ - 'datetime', + ]; +} diff --git a/app/Models/FinancesModel.php b/app/Models/FinancesModel.php deleted file mode 100644 index e35e4c3..0000000 --- a/app/Models/FinancesModel.php +++ /dev/null @@ -1,32 +0,0 @@ - 'datetime', - ]; - - protected $dates = ['deleted_at']; - - protected $table = 'finances'; -} diff --git a/app/Models/ProductsModel.php b/app/Models/Product.php similarity index 63% rename from app/Models/ProductsModel.php rename to app/Models/Product.php index 47947ba..002b4b6 100644 --- a/app/Models/ProductsModel.php +++ b/app/Models/Product.php @@ -3,15 +3,13 @@ namespace App\Models; use App\Relations\Has\HasManySales; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -class ProductsModel extends Model +class Product extends Model { - use SoftDeletes, HasManySales; - - protected $table = 'products'; - protected $dates = ['deleted_at']; + use HasFactory, SoftDeletes, HasManySales; protected $fillable = ['name', 'category', 'count', 'price', 'is_active', 'admin_id']; } diff --git a/app/Models/Sale.php b/app/Models/Sale.php new file mode 100644 index 0000000..600855e --- /dev/null +++ b/app/Models/Sale.php @@ -0,0 +1,19 @@ + 'datetime' + ]; +} diff --git a/app/Models/SalesModel.php b/app/Models/SalesModel.php deleted file mode 100644 index 1816df4..0000000 --- a/app/Models/SalesModel.php +++ /dev/null @@ -1,21 +0,0 @@ - 'datetime' - ]; - - protected $table = 'sales'; - protected $dates = ['deleted_at']; -} diff --git a/app/Models/Setting.php b/app/Models/Setting.php new file mode 100644 index 0000000..0fe60af --- /dev/null +++ b/app/Models/Setting.php @@ -0,0 +1,11 @@ + + */ +class AdministratorFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'password' => Hash::make('password'), + 'role_type' => RoleType::USER_TYPE->value + ]; + } +} diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php new file mode 100644 index 0000000..52850b0 --- /dev/null +++ b/database/factories/ClientFactory.php @@ -0,0 +1,33 @@ + + */ +class ClientFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'full_name' => $this->faker->name, + 'phone' => $this->faker->phoneNumber, + 'email' => $this->faker->unique()->safeEmail, + 'section' => $this->faker->word, + 'budget' => $this->faker->randomFloat(2, 1000, 100000), + 'location' => $this->faker->word, + 'zip' => $this->faker->postcode, + 'city' => $this->faker->city, + 'country' => $this->faker->country, + 'is_active' => $this->faker->boolean, + 'admin_id' => 1 + ]; + } +} diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php new file mode 100644 index 0000000..9480414 --- /dev/null +++ b/database/factories/CompanyFactory.php @@ -0,0 +1,37 @@ + + */ +class CompanyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'tax_number' => $this->faker->randomNumber(8), + 'phone' => $this->faker->phoneNumber, + 'city' => $this->faker->city, + 'billing_address' => $this->faker->address, + 'country' => $this->faker->country, + 'postal_code' => $this->faker->postcode, + 'employees_size' => $this->faker->randomNumber(3), + 'fax' => $this->faker->phoneNumber, + 'description' => $this->faker->text, + 'client_id' => Client::get()->random()->id, + 'admin_id' => 1, + 'created_at' => $this->faker->dateTime, + 'is_active' => $this->faker->boolean, + ]; + } +} diff --git a/database/factories/DealFactory.php b/database/factories/DealFactory.php new file mode 100644 index 0000000..01788f0 --- /dev/null +++ b/database/factories/DealFactory.php @@ -0,0 +1,29 @@ + + */ +class DealFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'start_time' => $this->faker->dateTime, + 'end_time' => $this->faker->dateTime, + 'company_id' => Company::get()->random()->id, + 'is_active' => $this->faker->boolean, + 'admin_id' => 1, + ]; + } +} diff --git a/database/factories/DealTermFactory.php b/database/factories/DealTermFactory.php new file mode 100644 index 0000000..e0a1033 --- /dev/null +++ b/database/factories/DealTermFactory.php @@ -0,0 +1,25 @@ + + */ +class DealTermFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'body' => $this->faker->text, + 'deal_id' => Deal::get()->random()->id, + ]; + } +} diff --git a/database/factories/EmployeeFactory.php b/database/factories/EmployeeFactory.php new file mode 100644 index 0000000..705aa8e --- /dev/null +++ b/database/factories/EmployeeFactory.php @@ -0,0 +1,31 @@ + + */ +class EmployeeFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'full_name' => $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'phone' => $this->faker->phoneNumber, + 'job' => $this->faker->jobTitle, + 'note' => $this->faker->text, + 'client_id' => Client::get()->random()->id, + 'admin_id' => 1, + 'is_active' => $this->faker->boolean, + ]; + } +} diff --git a/database/factories/FinanceFactory.php b/database/factories/FinanceFactory.php new file mode 100644 index 0000000..e2f9b15 --- /dev/null +++ b/database/factories/FinanceFactory.php @@ -0,0 +1,34 @@ + + */ +class FinanceFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'company_id' => Company::get()->random()->id, + 'category' => $this->faker->word, + 'type' => $this->faker->word, + 'date' => $this->faker->date(), + 'gross' => $this->faker->randomFloat(), + 'net' => $this->faker->randomFloat(), + 'vat' => $this->faker->randomFloat(), + 'description' => $this->faker->text, + 'is_active' => $this->faker->boolean, + 'admin_id' => 1 + ]; + } +} diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php deleted file mode 100644 index 2539199..0000000 --- a/database/factories/ModelFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -define(App\UserModel::class, function (Faker\Generator $faker) { - static $password; - - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'password' => $password ?: $password = bcrypt('secret'), - 'remember_token' => str_random(10), - ]; -}); diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php new file mode 100644 index 0000000..b4b59ac --- /dev/null +++ b/database/factories/ProductFactory.php @@ -0,0 +1,28 @@ + + */ +class ProductFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'category' => $this->faker->name, + 'count' => $this->faker->randomNumber(3), + 'price' => $this->faker->randomNumber(3), + 'is_active' => $this->faker->boolean, + 'admin_id' => 1, + ]; + } +} diff --git a/database/factories/SaleFactory.php b/database/factories/SaleFactory.php new file mode 100644 index 0000000..1eab985 --- /dev/null +++ b/database/factories/SaleFactory.php @@ -0,0 +1,29 @@ + + */ +class SaleFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'quantity' => $this->faker->randomNumber(2), + 'price' => $this->faker->randomFloat(2, 0, 1000), + 'date_of_payment' => $this->faker->dateTimeThisYear(), + 'product_id' => Product::get()->random()->id, + 'admin_id' => 1, + ]; + } +} diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php new file mode 100644 index 0000000..d02f781 --- /dev/null +++ b/database/factories/TaskFactory.php @@ -0,0 +1,29 @@ + + */ +class TaskFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => $this->faker->name, + 'employee_id' => Employee::get()->random()->id, + 'duration' => $this->faker->randomNumber(2), + 'is_active' => $this->faker->boolean, + 'completed' => $this->faker->boolean, + 'admin_id' => 1, + ]; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php deleted file mode 100644 index 1559853..0000000 --- a/database/factories/UserFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -define(AdminModel::class, function (Faker $faker) { - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; -}); diff --git a/database/migrations/2024_11_26_104225_rename_tables.php b/database/migrations/2024_11_26_104225_rename_tables.php new file mode 100644 index 0000000..cbcd02d --- /dev/null +++ b/database/migrations/2024_11_26_104225_rename_tables.php @@ -0,0 +1,28 @@ +create([ 'name' => 'admin', 'email' => 'admin@admin.com', 'password' => Hash::make('admin'), - 'role_type' => 2 // admin - ]; - - DB::table('admins')->insert($admin); + 'role_type' => RoleType::ADMIN_TYPE + ]); } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php similarity index 95% rename from database/seeds/DatabaseSeeder.php rename to database/seeders/DatabaseSeeder.php index 6636b9e..e21ac6d 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -1,5 +1,7 @@ create(); + } +} diff --git a/database/seeders/FakerCompaniesSeeder.php b/database/seeders/FakerCompaniesSeeder.php new file mode 100644 index 0000000..c3d97ed --- /dev/null +++ b/database/seeders/FakerCompaniesSeeder.php @@ -0,0 +1,25 @@ +pluck('id')->toArray(); + + Company::factory(10)->create([ + 'client_id' => function() use ($userIds) { + return $userIds[array_rand($userIds)]; + } + ]); + } +} diff --git a/database/seeders/FakerDealsSeeder.php b/database/seeders/FakerDealsSeeder.php new file mode 100644 index 0000000..478ee42 --- /dev/null +++ b/database/seeders/FakerDealsSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/FakerEmployeesSeeder.php b/database/seeders/FakerEmployeesSeeder.php new file mode 100644 index 0000000..2a7a2a5 --- /dev/null +++ b/database/seeders/FakerEmployeesSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/FakerFinancesSeeder.php b/database/seeders/FakerFinancesSeeder.php new file mode 100644 index 0000000..08be2c2 --- /dev/null +++ b/database/seeders/FakerFinancesSeeder.php @@ -0,0 +1,20 @@ +count(10)->create(); + } +} diff --git a/database/seeders/FakerProductsSeeder.php b/database/seeders/FakerProductsSeeder.php new file mode 100644 index 0000000..542896b --- /dev/null +++ b/database/seeders/FakerProductsSeeder.php @@ -0,0 +1,18 @@ +create(); + } +} diff --git a/database/seeders/FakerSalesSeeder.php b/database/seeders/FakerSalesSeeder.php new file mode 100644 index 0000000..1276912 --- /dev/null +++ b/database/seeders/FakerSalesSeeder.php @@ -0,0 +1,19 @@ +count(10)->create(); + } +} diff --git a/database/seeders/FakerTasksSeeder.php b/database/seeders/FakerTasksSeeder.php new file mode 100644 index 0000000..5016020 --- /dev/null +++ b/database/seeders/FakerTasksSeeder.php @@ -0,0 +1,19 @@ +count(10)->create(); + } +} diff --git a/database/seeds/SettingsSeeder.php b/database/seeders/SettingsSeeder.php similarity index 98% rename from database/seeds/SettingsSeeder.php rename to database/seeders/SettingsSeeder.php index a389b18..b5bbaa5 100644 --- a/database/seeds/SettingsSeeder.php +++ b/database/seeders/SettingsSeeder.php @@ -1,5 +1,6 @@ $faker->name, - 'phone' => $faker->phoneNumber, - 'email' => $faker->companyEmail, - 'section' => Arr::random($section), - 'budget' => rand(100, 1000), - 'location' => $faker->country, - 'zip' => $faker->postcode, - 'city' => $faker->city, - 'country' => $faker->country, - 'created_at' => $faker->dateTimeBetween($startDate = '-30 days', $endDate = 'now'), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('clients')->insert($client); - } - } -} diff --git a/database/seeds/FakerCompaniesSeeder.php b/database/seeds/FakerCompaniesSeeder.php deleted file mode 100644 index e39d04b..0000000 --- a/database/seeds/FakerCompaniesSeeder.php +++ /dev/null @@ -1,39 +0,0 @@ -pluck('id')->toArray(); - $rowRand = rand(30,100); - - for ($i = 0; $i<$rowRand; $i++) { - $companies = [ - 'name' => $faker->company, - 'tax_number' => $faker->unixTime($max = 'now'), - 'phone' => $faker->phoneNumber, - 'city' => $faker->city, - 'billing_address' => $faker->streetAddress, - 'country' => $faker->country, - 'postal_code' => $faker->postcode, - 'employees_size' => rand(100,1000), - 'fax' => $faker->phoneNumber, - 'description' => 'test description', - 'client_id' => $userIds[array_rand($userIds)], - 'created_at' => \Carbon\Carbon::now()->subDays(rand(1, 33)), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('companies')->insert($companies); - } - } -} diff --git a/database/seeds/FakerDealsSeeder.php b/database/seeds/FakerDealsSeeder.php deleted file mode 100644 index 2ed4489..0000000 --- a/database/seeds/FakerDealsSeeder.php +++ /dev/null @@ -1,32 +0,0 @@ -pluck('id')->toArray(); - $rowRand = rand(30,100); - - for ($i = 0; $i<$rowRand; $i++) { - $deals = [ - 'name' => $faker->company, - 'start_time' => $faker->date, - 'end_time' => $faker->date, - 'companies_id' => $faker->randomElement($companiesIds), - 'created_at' => $faker->dateTimeBetween($startDate = '-30 days', $endDate = 'now'), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('deals')->insert($deals); - } - } -} diff --git a/database/seeds/FakerEmployeesSeeder.php b/database/seeds/FakerEmployeesSeeder.php deleted file mode 100644 index 65c1269..0000000 --- a/database/seeds/FakerEmployeesSeeder.php +++ /dev/null @@ -1,34 +0,0 @@ -pluck('id')->toArray(); - $rowRand = rand(30,100); - - for ($i = 0; $i<$rowRand; $i++) { - $employees = [ - 'full_name' => $faker->name, - 'phone' => $faker->phoneNumber, - 'email' => $faker->email, - 'job' => 'engineer', - 'note' => 'test note', - 'client_id' => $faker->randomElement($userIds), - 'created_at' => $faker->dateTimeBetween($startDate = '-30 days', $endDate = 'now'), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('employees')->insert($employees); - } - } -} diff --git a/database/seeds/FakerFinancesSeeder.php b/database/seeds/FakerFinancesSeeder.php deleted file mode 100644 index 9fe3f6a..0000000 --- a/database/seeds/FakerFinancesSeeder.php +++ /dev/null @@ -1,45 +0,0 @@ -pluck('id')->toArray(); - $rowRand = rand(30,70); - $category = ['steady income', 'large order', 'small order', 'one-off order']; - $type = ['Invoice', 'proforma invoice', 'advance', 'simple transfer']; - - for ($i = 0; $i<$rowRand; $i++) { - $rand = rand(800,2000); - $calculateFromFakeRand = new \App\Services\FinancesService(); - - $data = $calculateFromFakeRand->loadCalculateNetAndVatByGivenGross($rand); - - $finances = [ - 'name' => $faker->name, - 'description' => 'test_desc', - 'category' => Arr::random($category), - 'type' => Arr::random($type), - 'gross' => $rand, - 'vat' => $data['vat'], - 'net' => $data['net'], - 'date' => $faker->dateTimeBetween($startDate = '-30 days', $endDate = 'now'), - 'companies_id' => $faker->randomElement($companiesIds), - 'created_at' => \Carbon\Carbon::now()->subDays(rand(1, 33)), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('finances')->insert($finances); - } - } -} diff --git a/database/seeds/FakerProductsSeeder.php b/database/seeds/FakerProductsSeeder.php deleted file mode 100644 index b7589c0..0000000 --- a/database/seeds/FakerProductsSeeder.php +++ /dev/null @@ -1,34 +0,0 @@ - $names[$i], - 'category' => $faker->lastName, - 'count' => rand(50,500), - 'price' => rand(10,1000), - 'created_at' => $faker->dateTimeBetween($startDate = '-'.$i.' days', $endDate = 'now'), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('products')->insert($products); - } - } -} diff --git a/database/seeds/FakerSalesSeeder.php b/database/seeds/FakerSalesSeeder.php deleted file mode 100644 index 8e7aa72..0000000 --- a/database/seeds/FakerSalesSeeder.php +++ /dev/null @@ -1,33 +0,0 @@ -get(); - $productDetails = \App\Models\ProductsModel::all(); - - foreach($productDetails as $detail) { - $sales = [ - 'name' => $faker->name, - 'quantity' => rand(10,20), - 'product_id' => $detail->id, - 'date_of_payment' => $faker->dateTimeThisMonth(), - 'price' => $detail->price, //update this manual - 'created_at' => $faker->dateTimeBetween($startDate = '-30 days', $endDate = 'now'), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('sales')->insert($sales); - } - } -} diff --git a/database/seeds/FakerTasksSeeder.php b/database/seeds/FakerTasksSeeder.php deleted file mode 100644 index 2f08d2a..0000000 --- a/database/seeds/FakerTasksSeeder.php +++ /dev/null @@ -1,32 +0,0 @@ -pluck('id')->toArray(); - $rowRand = rand(30,100); - - for ($i = 0; $i<$rowRand; $i++) { - $tasks = [ - 'name' => 'test_task', - 'employee_id' => $faker->randomElement($employeeIds), - 'duration' => rand(1,30), - 'completed' => rand(0,1), - 'created_at' => \Carbon\Carbon::today()->subDays(rand(0, 365)), - 'updated_at' => \Carbon\Carbon::now(), - 'admin_id' => 1 - ]; - - DB::table('tasks')->insert($tasks); - } - } -}