Add products module #46

This commit is contained in:
2025-11-26 10:05:43 +01:00
parent 155f0d3525
commit 83dd8e9ecb
21 changed files with 607 additions and 50 deletions
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Unit;
class LineItemFactory extends Factory
{
@@ -16,7 +17,7 @@ public function definition(): array
'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']),
'unit_id' => Unit::factory(),
'price' => $this->faker->randomFloat(2, 10, 500),
];
}
@@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\ProductCategory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ProductCategory>
*/
class ProductCategoryFactory extends Factory
{
protected $model = ProductCategory::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->unique()->word()
];
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Product;
use App\Models\ProductCategory;
use App\Models\Unit;
class ProductFactory extends Factory
{
protected $model = Product::class;
public function definition()
{
return [
'title' => $this->faker->words(3, true),
'description' => $this->faker->optional()->paragraph(),
'notes' => $this->faker->optional()->sentence(),
'vendor_url' => $this->faker->optional()->url(),
'category_id' => ProductCategory::factory(),
'unit_id' => Unit::factory(), // Neue Einheit
'price' => $this->faker->optional()->randomFloat(2, 10, 1000),
'margin' => $this->faker->randomFloat(2, 0.1, 0.5),
'image' => $this->faker->optional()->imageUrl(640, 480, 'products', true)
];
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class UnitFactory extends Factory
{
public function definition(): array
{
return [
'name' => $this->faker->unique()->randomElement([
'Stück',
'Stunden',
'Tage',
'pauschal'
]),
'symbol' => $this->faker->lexify('??'),
];
}
}
-37
View File
@@ -1,37 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->enum('type', ['private', 'business']);
$table->string('company_name', 100)->nullable();
$table->string('vat_id', 50)->nullable();
$table->string('tax_id', 50)->nullable(); // Tax identification number
$table->string('global_id', 50)->nullable(); // Global Location Number (GLN)
$table->string('legal_registration_id', 50)->nullable(); // Legal registration ID
$table->string('email', 100)->unique();
$table->string('phone', 20)->nullable();
$table->json('billing_address'); // Structured as per ZUGFeRD standard
$table->integer('payment_terms')->default(14);
$table->enum('status', ['active', 'inactive', 'prospect'])->default('active');
$table->text('notes')->nullable();
$table->timestamps();
// $table->index('email');
});
}
public function down()
{
Schema::dropIfExists('customers');
}
};
@@ -19,7 +19,7 @@ public function up(): void
$table->string('title')->nullable();
$table->string('description')->nullable();
$table->integer('quantity')->default(1);
$table->string('unit')->default('Stunden');
$table->foreignId('unit_id')->nullable()->constrained()->nullOnDelete();
$table->decimal('price', 10, 2)->nullable();
$table->timestamps();
});
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('title', 64);
$table->text('description')->nullable();
$table->text('notes')->nullable();
$table->string('vendor_url', 100)->nullable();
$table->foreignId('category_id')->constrained()->nullOnDelete()->nullable();
$table->decimal('price', 10, 2)->nullable();
$table->decimal('margin', 2, 2)->default(0.2);
$table->foreignId('unit_id')->nullable()->constrained()->nullOnDelete();
$table->string('image')->nullable();
$table->timestamps();
$table->index(['title', 'description']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('products');
}
};
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('product_categories', function (Blueprint $table) {
$table->id();
$table->string('name', 64);
$table->timestamps();
$table->index(['name']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('product_categories');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
Schema::create('units', function (Blueprint $table) {
$table->id();
$table->string('name', 50)->unique();
$table->string('symbol', 10)->nullable();
$table->timestamps();
});
// Füge Standard-Einheiten hinzu
DB::table('units')->insert([
['name' => 'Stück', 'symbol' => 'Stk'],
['name' => 'Stunden', 'symbol' => 'h'],
['name' => 'Tage', 'symbol' => 'd'],
['name' => 'pauschal', 'symbol' => 'p'],
]);
}
public function down(): void
{
Schema::dropIfExists('units');
}
};