Various fixes for DB seeding
This commit is contained in:
@@ -40,28 +40,32 @@ ### Prerequisites
|
|||||||
### Steps
|
### Steps
|
||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
```bash
|
```bash
|
||||||
git lfs clone https://code.tooloop.de/Tooloop/Caramel-CRM.git
|
git clone http://code.tooloop.de/Tooloop/Caramel-CRM.git
|
||||||
cd Caramel-CRM
|
cd Caramel-CRM
|
||||||
````
|
```
|
||||||
2. Install dependencies:
|
2. Create empty database:
|
||||||
|
```bash
|
||||||
|
touch database/database.sqlite
|
||||||
|
```
|
||||||
|
3. Install dependencies:
|
||||||
```bash
|
```bash
|
||||||
composer install
|
composer install
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
3. Set up the environment:
|
4. Set up the environment:
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
php artisan key\:generate
|
php artisan key\:generate
|
||||||
```
|
```
|
||||||
4. Run migrations and seeders:
|
5. Run migrations and seeders:
|
||||||
```bash
|
```bash
|
||||||
php artisan migrate --seed
|
php artisan migrate --seed
|
||||||
```
|
```
|
||||||
5. Build frontend assets:
|
6. Build frontend assets:
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
6. Start the development server:
|
7. Start the development server:
|
||||||
```bash
|
```bash
|
||||||
php artisan serve
|
php artisan serve
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public static function generateCustomerNumber()
|
|||||||
// DATEV standard
|
// DATEV standard
|
||||||
$randomNumber = rand(10000, 69999);
|
$randomNumber = rand(10000, 69999);
|
||||||
$customer = Customer::firstWhere('customer_nr', $randomNumber);
|
$customer = Customer::firstWhere('customer_nr', $randomNumber);
|
||||||
if ($customer) {
|
if ($customer || Customer::count() === 0) {
|
||||||
return $randomNumber;
|
return $randomNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Schedule;
|
use Illuminate\Support\Facades\Schedule;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Routing\Events\RouteMatched;
|
use Illuminate\Routing\Events\RouteMatched;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Listeners\ScheduleListener;
|
use App\Listeners\ScheduleListener;
|
||||||
@@ -22,10 +22,12 @@ public function boot(): void
|
|||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
|
if (Schema::hasTable('settings')) {
|
||||||
$method = Setting::where('key', 'app.schedule_method')->value('value') ?? 'internal';
|
$method = Setting::where('key', 'app.schedule_method')->value('value') ?? 'internal';
|
||||||
if ($method === 'internal') {
|
if ($method === 'internal') {
|
||||||
Event::listen(RouteMatched::class, [ScheduleListener::class, 'handle']);
|
Event::listen(RouteMatched::class, [ScheduleListener::class, 'handle']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: read where to put these
|
// TODO: read where to put these
|
||||||
// it seems to work here, but where is the apropriate place?
|
// it seems to work here, but where is the apropriate place?
|
||||||
|
|||||||
@@ -26,7 +26,31 @@ public function definition()
|
|||||||
$hasMatrix = rand(0, 9) >= 7;
|
$hasMatrix = rand(0, 9) >= 7;
|
||||||
$hasGithub = rand(0, 9) >= 7;
|
$hasGithub = rand(0, 9) >= 7;
|
||||||
|
|
||||||
$contact = [
|
$onlineAccounts = [];
|
||||||
|
|
||||||
|
if ($hasLinkedIn) {
|
||||||
|
$onlineAccounts[] = [
|
||||||
|
'platform' => 'linkedin',
|
||||||
|
'user_name' => $userName,
|
||||||
|
'url' => 'https://www.linkedin.com/in/' . $userName
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if ($hasMatrix) {
|
||||||
|
$onlineAccounts[] = [
|
||||||
|
'platform' => 'matrix',
|
||||||
|
'user_name' => $userName,
|
||||||
|
'url' => '@' . $userName . ':matrix.org'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if ($hasGithub) {
|
||||||
|
$onlineAccounts[] = [
|
||||||
|
'platform' => 'github',
|
||||||
|
'user_name' => $userName,
|
||||||
|
'url' => 'https://www.github.com/' . $userName
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
'is_primary' => $this->faker->boolean(30),
|
'is_primary' => $this->faker->boolean(30),
|
||||||
'salutation' => $this->faker->title($gender),
|
'salutation' => $this->faker->title($gender),
|
||||||
'first_name' => $this->faker->firstName($gender),
|
'first_name' => $this->faker->firstName($gender),
|
||||||
@@ -36,25 +60,7 @@ public function definition()
|
|||||||
'phone' => $this->faker->phoneNumber(),
|
'phone' => $this->faker->phoneNumber(),
|
||||||
'mobile_phone' => $this->faker->phoneNumber(),
|
'mobile_phone' => $this->faker->phoneNumber(),
|
||||||
'avatar' => $avatar,
|
'avatar' => $avatar,
|
||||||
'online_accounts' => []
|
'online_accounts' => $onlineAccounts
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($hasLinkedIn) $contact[] = [
|
|
||||||
'platform' => 'linkedin',
|
|
||||||
'user_name' => $userName,
|
|
||||||
'url' => 'https://www.linkedin.com/in/' . $userName
|
|
||||||
];
|
|
||||||
if ($hasMatrix) $contact[] = [
|
|
||||||
'platform' => 'matrix',
|
|
||||||
'user_name' => $userName,
|
|
||||||
'url' => '@' . $userName . ':matrix.org'
|
|
||||||
];
|
|
||||||
if ($hasGithub) $contact[] = [
|
|
||||||
'platform' => 'github',
|
|
||||||
'user_name' => $userName,
|
|
||||||
'url' => 'https://www.github.com/' . $userName
|
|
||||||
];
|
|
||||||
|
|
||||||
return $contact;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,13 +11,15 @@ public function definition(): array
|
|||||||
{
|
{
|
||||||
|
|
||||||
$isSection = rand(0, 10) > 7;
|
$isSection = rand(0, 10) > 7;
|
||||||
|
$unit = Unit::where('name', $this->faker->randomElement(['Stück', 'Stunden', 'Tage', 'pauschal']))->first();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'position' => $this->faker->numberBetween(1, 10) + ($isSection ? 0.5 : 0),
|
'position' => $this->faker->numberBetween(1, 10) + ($isSection ? 0.5 : 0),
|
||||||
'is_section' => $isSection,
|
'is_section' => $isSection,
|
||||||
'title' => $this->faker->words(3, true),
|
'title' => $this->faker->words(3, true),
|
||||||
'description' => $this->faker->sentence(),
|
'description' => $this->faker->sentence(),
|
||||||
'quantity' => $this->faker->numberBetween(1, 10),
|
'quantity' => $this->faker->numberBetween(1, 10),
|
||||||
'unit_id' => Unit::factory(),
|
'unit_id' => $unit ? $unit->id : null,
|
||||||
'price' => $this->faker->randomFloat(2, 10, 500),
|
'price' => $this->faker->randomFloat(2, 10, 500),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,34 +15,6 @@ public function up()
|
|||||||
$table->integer('days')->nullable();
|
$table->integer('days')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fügen Sie Standard-Zahlungsziele hinzu
|
|
||||||
DB::table('payment_terms')->insert([
|
|
||||||
[
|
|
||||||
'name' => 'prepaid',
|
|
||||||
'description' => 'Vorkasse',
|
|
||||||
'is_fixed' => true,
|
|
||||||
'days' => null,
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now()
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'onReceipt',
|
|
||||||
'description' => 'Bei Rechnungserhalt',
|
|
||||||
'is_fixed' => true,
|
|
||||||
'days' => null,
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now()
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'daysAfterInvoice',
|
|
||||||
'description' => 'Zahlungsziel in Tagen',
|
|
||||||
'is_fixed' => false,
|
|
||||||
'days' => 14,
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now()
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down()
|
public function down()
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ public function up(): void
|
|||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('user_id')->constrained()->nullOnDelete();
|
$table->foreignId('user_id')->constrained()->nullOnDelete();
|
||||||
$table->text('text');
|
$table->text('text');
|
||||||
|
|
||||||
// Polymorphische Beziehung
|
|
||||||
$table->unsignedBigInteger('notable_id');
|
$table->unsignedBigInteger('notable_id');
|
||||||
$table->string('notable_type');
|
$table->string('notable_type');
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,6 @@ public function up(): void
|
|||||||
$table->string('symbol', 10)->nullable();
|
$table->string('symbol', 10)->nullable();
|
||||||
$table->timestamps();
|
$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
|
public function down(): void
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public function run(): void
|
|||||||
PaymentTermsSeeder::class,
|
PaymentTermsSeeder::class,
|
||||||
SettingsTableSeeder::class,
|
SettingsTableSeeder::class,
|
||||||
TodoTypeSeeder::class,
|
TodoTypeSeeder::class,
|
||||||
|
UnitSeeder::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = User::factory()->create([
|
$user = User::factory()->create([
|
||||||
@@ -46,7 +47,8 @@ public function run(): void
|
|||||||
// Create some notes for each customer
|
// Create some notes for each customer
|
||||||
Note::factory(rand(0, 5))->create([
|
Note::factory(rand(0, 5))->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'customer_id' => $customer->id,
|
'notable_id' => $customer->id,
|
||||||
|
'notable_type' => Customer::class,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public function run(): void
|
|||||||
|
|
||||||
PaymentTerms::create([
|
PaymentTerms::create([
|
||||||
'name' => 'onReceipt',
|
'name' => 'onReceipt',
|
||||||
|
'description' => 'Bei Rechnungserhalt',
|
||||||
'is_fixed' => true,
|
'is_fixed' => true,
|
||||||
'days' => null
|
'days' => null
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Unit;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class UnitSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
Unit::create(['name' => 'Stück', 'symbol' => 'Stk']);
|
||||||
|
Unit::create(['name' => 'Stunden', 'symbol' => 'h']);
|
||||||
|
Unit::create(['name' => 'Tage', 'symbol' => 'd']);
|
||||||
|
Unit::create(['name' => 'pauschal', 'symbol' => 'p']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "Software",
|
"name": "Caramel-CRM",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
Reference in New Issue
Block a user