Add initial Code
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ContactFactory extends Factory
|
||||
{
|
||||
protected $model = \App\Models\Contact::class;
|
||||
|
||||
public function definition()
|
||||
{
|
||||
// 30% chance of having an avatar, 70% chance of having null
|
||||
$hasAvatar = $this->faker->boolean(30);
|
||||
|
||||
$avatar = null;
|
||||
if ($hasAvatar) {
|
||||
// Generate a random image ID between 1 and 70 (pravatar.cc has 70 default images)
|
||||
$randomImageId = $this->faker->numberBetween(1, 70);
|
||||
$avatar = "https://i.pravatar.cc/128?img={$randomImageId}";
|
||||
}
|
||||
|
||||
return [
|
||||
'first_name' => $this->faker->firstName(),
|
||||
'last_name' => $this->faker->lastName(),
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'position' => $this->faker->jobTitle(),
|
||||
'is_primary' => $this->faker->boolean(30),
|
||||
'avatar' => $avatar,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
use App\Models\PaymentTerms;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class CustomerFactory extends Factory
|
||||
{
|
||||
protected $model = \App\Models\Customer::class;
|
||||
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'type' => $this->faker->randomElement(['private', 'business']),
|
||||
'company_name' => $this->faker->company(),
|
||||
'vat_id' => $this->faker->numerify('DE##########'),
|
||||
'tax_id' => $this->faker->numerify('DE##########'),
|
||||
'global_id' => $this->faker->numerify('############'),
|
||||
'legal_registration_id' => $this->faker->numerify('##########'),
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'phone' => $this->faker->phoneNumber(),
|
||||
'billing_address' => [
|
||||
'line_one' => $this->faker->streetAddress(),
|
||||
'line_two' => '',
|
||||
'city' => $this->faker->city(),
|
||||
'postal_code' => $this->faker->postcode(),
|
||||
'country_code' => 'DE',
|
||||
],
|
||||
'payment_terms_id' => PaymentTerms::where('name', 'daysAfterInvoice')->first()->id,
|
||||
'logo' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\LineItem;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Invoice>
|
||||
*/
|
||||
class InvoiceFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$payment_status = $this->faker->randomElement(['draft', 'issued', 'paid', 'due', 'reminded']);
|
||||
|
||||
return [
|
||||
'nr' => ($payment_status == 'draft') ? null : $this->faker->unique()->numerify('RE-###'),
|
||||
'invoice_date' => $this->faker->date(),
|
||||
'due_date' => $this->faker->date(),
|
||||
'service_start_date' => $this->faker->date(),
|
||||
'service_end_date' => $this->faker->date(),
|
||||
'is_recurring' => $this->faker->boolean(30),
|
||||
'is_partial_service' => $this->faker->boolean(30),
|
||||
'customer_id' => Customer::factory(),
|
||||
'payment_status' => $payment_status,
|
||||
'total_amount' => $this->faker->randomFloat(2, 100, 1000),
|
||||
'title' => $this->faker->text(50),
|
||||
'text' => $this->faker->paragraph(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the factory to create related line items after creating an invoice.
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
return $this->afterCreating(function ($invoice) {
|
||||
LineItem::factory(rand(2, 5))->create([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class LineItemFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'position' => $this->faker->numberBetween(1, 10),
|
||||
'title' => $this->faker->words(3, true),
|
||||
'description' => $this->faker->sentence(),
|
||||
'quantity' => $this->faker->numberBetween(1, 10),
|
||||
'unit' => $this->faker->randomElement(['Stück', 'Stunden', 'Tage', 'pauschal']),
|
||||
'price' => $this->faker->randomFloat(2, 10, 500),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class PaymentTermsFactory extends Factory
|
||||
{
|
||||
protected $model = \App\Models\PaymentTerms::class;
|
||||
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->word(),
|
||||
'description' => $this->faker->sentence(),
|
||||
'is_fixed' => $this->faker->boolean(),
|
||||
'days' => $this->faker->numberBetween(7, 60),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'avatar' => null,
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user