Skip to content

Commit 8b8d826

Browse files
committed
Intermediary commit
1 parent aa1da82 commit 8b8d826

31 files changed

+702
-553
lines changed

Modules/Clients/Database/Seeders/AddressesSeeder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Faker\Factory as Faker;
66
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Log;
78
use Modules\Clients\Models\Address;
89
use Modules\Clients\Models\Relation;
910
use Modules\Core\Models\Company;
@@ -47,17 +48,17 @@ public function run(?int $companyId = null): void
4748
$existingCount = Address::query()->where('company_id', $company->id)->count();
4849

4950
if ($existingCount > 0) {
50-
$this->command->info("Skipping addresses for company {$company->name} - already has {$existingCount} addresses.");
51+
Log::info("Skipping addresses for company {$company->name} - already has {$existingCount} addresses.");
5152

5253
return;
5354
}
5455

55-
$this->command->info("Creating addresses for company: {$company->name}");
56+
Log::info("Creating addresses for company: {$company->name}");
5657

5758
$customers = Relation::query()->where('company_id', $company->id)->get();
5859

5960
if ($customers->isEmpty()) {
60-
$this->command->warn("No customers found for company {$company->name}. Creating some...");
61+
Log::debug("No customers found for company {$company->name}. Creating some...");
6162
$this->call(CustomersSeeder::class, ['companyId' => $company->id]);
6263
$customers = Relation::query()->where('company_id', $company->id)->get();
6364
}
@@ -97,7 +98,7 @@ public function run(?int $companyId = null): void
9798
DB::table('addresses')->insert($chunk);
9899
}
99100

100-
$this->command->info(sprintf(
101+
Log::info(sprintf(
101102
'Created %d addresses for company: %s',
102103
count($addresses),
103104
$company->name

Modules/Clients/Database/Seeders/ContactsSeeder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Faker\Factory as Faker;
66
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Log;
78
use Modules\Clients\Models\Contact;
89
use Modules\Clients\Models\Relation;
910
use Modules\Core\Models\Company;
@@ -38,12 +39,12 @@ public function run(?int $companyId = null): void
3839
$existingCount = Contact::query()->where('company_id', $company->id)->count();
3940

4041
if ($existingCount > 0) {
41-
$this->command->info("Skipping contacts for company {$company->name} - already has {$existingCount} contacts.");
42+
Log::info("Skipping contacts for company {$company->name} - already has {$existingCount} contacts.");
4243

4344
return;
4445
}
4546

46-
$this->command->info("Creating contacts for company: {$company->name}");
47+
Log::info("Creating contacts for company: {$company->name}");
4748

4849
$customers = Relation::query()->where('company_id', $company->id)
4950
->whereIn('relation_type', ['customer', 'both'])
@@ -86,7 +87,7 @@ public function run(?int $companyId = null): void
8687
DB::table('contacts')->insert($chunk);
8788
}
8889

89-
$this->command->info(sprintf(
90+
Log::info(sprintf(
9091
'Created %d contacts for company: %s',
9192
count($contacts),
9293
$company->name

Modules/Clients/Database/Seeders/CustomersSeeder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Modules\Clients\Database\Seeders;
44

55
use Faker\Factory as Faker;
6+
use Illuminate\Support\Facades\Log;
67
use Illuminate\Support\Str;
78
use Modules\Clients\Enums\CommunicationType;
89
use Modules\Clients\Enums\Gender;
@@ -51,12 +52,12 @@ public function run(?int $companyId = null): void
5152
->count();
5253

5354
if ($existingCount > 0) {
54-
$this->command->info("Skipping customers for company {$company->name} - already has {$existingCount} customers.");
55+
Log::info("Skipping customers for company {$company->name} - already has {$existingCount} customers.");
5556

5657
return;
5758
}
5859

59-
$this->command->info("Creating customers for company: {$company->name}");
60+
Log::info("Creating customers for company: {$company->name}");
6061

6162
// Create 10-20 customers per company
6263
$customerCount = rand(10, 20);

Modules/Clients/Models/Address.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Modules\Clients\Models;
44

55
use Illuminate\Database\Eloquent\Collection;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
68
use Illuminate\Database\Eloquent\Model;
79
use Illuminate\Database\Eloquent\Relations\MorphTo;
10+
use Modules\Clients\Database\Factories\AddressFactory;
811
use Modules\Clients\Enums\AddressType;
912
use Modules\Core\Models\Company;
1013
use Modules\Core\Traits\BelongsToCompany;
@@ -26,6 +29,7 @@
2629
class Address extends Model
2730
{
2831
use BelongsToCompany;
32+
use HasFactory;
2933

3034
public $timestamps = false;
3135

@@ -55,4 +59,14 @@ public function addressable(): MorphTo
5559
{
5660
return $this->morphTo();
5761
}
62+
63+
/*
64+
|--------------------------------------------------------------------------
65+
| Factory
66+
|--------------------------------------------------------------------------
67+
*/
68+
protected static function newFactory(): Factory
69+
{
70+
return AddressFactory::new();
71+
}
5872
}

Modules/Core/Database/Seeders/AdminUserSeeder.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

Modules/Core/Database/Seeders/CompaniesSeeder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Modules\Core\Database\Seeders;
44

5+
use Illuminate\Support\Facades\Log;
56
use Modules\Core\Models\Company;
67

78
class CompaniesSeeder extends \Modules\Core\Database\Seeders\AbstractSeeder
@@ -28,6 +29,6 @@ public function run(int $count = 1): void
2829
->create();
2930
}
3031

31-
$this->command->info("Created {$count} companies");
32+
Log::info("Created {$count} companies");
3233
}
3334
}

Modules/Core/Database/Seeders/DocumentGroupsSeeder.php

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
namespace Modules\Core\Database\Seeders;
44

5+
use Illuminate\Support\Facades\Log;
6+
57
class DocumentGroupsSeeder extends \Modules\Core\Database\Seeders\AbstractSeeder
68
{
79
public function run(?int $companyId = null): void
810
{
911
$company = $companyId
10-
? \Modules\Core\Models\Company::find($companyId)
11-
: \Modules\Core\Models\Company::first();
12+
? \Modules\Core\Models\Company::query()->find($companyId)
13+
: \Modules\Core\Models\Company::where('is_active', true)->first();
1214

1315
if ( ! $company) {
14-
$this->command->warn('No company found. Please run CompaniesSeeder first.');
16+
Log::debug('No company found. Please run CompaniesSeeder first.');
1517

1618
return;
1719
}
@@ -24,28 +26,33 @@ public function run(?int $companyId = null): void
2426
$name = $this->getDefaultNameForType($type);
2527
$format = $this->getDefaultFormatForType($type);
2628

27-
\Modules\Core\Models\DocumentGroup::firstOrCreate(
28-
[
29-
'company_id' => $company->id,
30-
'name' => $name,
31-
],
32-
[
33-
'type' => $type->value,
34-
'group_identifier_format' => $format,
35-
'next_id' => 1,
36-
'left_pad' => 0,
37-
'format' => $format,
38-
'reset_number' => 0,
39-
'last_id' => 0,
40-
'last_year' => $now->year,
41-
'last_month' => $now->month,
42-
'last_week' => $now->weekOfYear,
43-
]
44-
);
45-
$created++;
46-
}
29+
$documentGroup = \Modules\Core\Models\DocumentGroup::where([
30+
'company_id' => $company->id,
31+
'name' => $name,
32+
])->first();
33+
34+
if ( ! $documentGroup) {
35+
\Modules\Core\Models\DocumentGroup::create(
36+
[
37+
'company_id' => $company->id,
38+
'name' => $name,
39+
'type' => $type->value,
40+
'group_identifier_format' => $format,
41+
'next_id' => 1,
42+
'left_pad' => 0,
43+
'format' => $format,
44+
'reset_number' => 0,
45+
'last_id' => 0,
46+
'last_year' => $now->year,
47+
'last_month' => $now->month,
48+
'last_week' => $now->weekOfYear,
49+
]
50+
);
51+
$created++;
52+
}
4753

48-
$this->command->info("Created {$created} document groups for company: {$company->name} (ID: {$company->id})");
54+
Log::info("Created {$created} document groups for company: {$company->name} (ID: {$company->id})");
55+
}
4956
}
5057

5158
private function getDefaultNameForType(\Modules\Core\Enums\DocumentGroupType $type): string
@@ -66,14 +73,14 @@ private function getDefaultNameForType(\Modules\Core\Enums\DocumentGroupType $ty
6673
private function getDefaultFormatForType(\Modules\Core\Enums\DocumentGroupType $type): string
6774
{
6875
return match($type) {
69-
\Modules\Core\Enums\DocumentGroupType::INVOICES => 'INV-{YEAR}-{ID}',
70-
\Modules\Core\Enums\DocumentGroupType::QUOTES => 'QUO-{YEAR}-{ID}',
71-
\Modules\Core\Enums\DocumentGroupType::PRO_FORMA_INVOICES => 'PFI-{YEAR}-{ID}',
7276
\Modules\Core\Enums\DocumentGroupType::CREDIT_NOTES => 'CN-{YEAR}-{ID}',
73-
\Modules\Core\Enums\DocumentGroupType::RECURRING_INVOICES => 'RINV-{YEAR}-{ID}',
74-
\Modules\Core\Enums\DocumentGroupType::DRAFTS => 'DRAFT-{YEAR}-{ID}',
7577
\Modules\Core\Enums\DocumentGroupType::CUSTOMERS => 'CUST-{YEAR}-{ID}',
78+
\Modules\Core\Enums\DocumentGroupType::DRAFTS => 'DRAFT-{YEAR}-{ID}',
79+
\Modules\Core\Enums\DocumentGroupType::INVOICES => 'INV-{YEAR}-{ID}',
7680
\Modules\Core\Enums\DocumentGroupType::PROSPECTS => 'PROS-{YEAR}-{ID}',
81+
\Modules\Core\Enums\DocumentGroupType::PRO_FORMA_INVOICES => 'PFI-{YEAR}-{ID}',
82+
\Modules\Core\Enums\DocumentGroupType::QUOTES => 'QUO-{YEAR}-{ID}',
83+
\Modules\Core\Enums\DocumentGroupType::RECURRING_INVOICES => 'RECUR-{YEAR}-{ID}',
7784
default => $type->prefix() . '-{YEAR}-{ID}',
7885
};
7986
}

Modules/Core/Database/Seeders/EmailTemplatesSeeder.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Modules\Core\Database\Seeders;
44

5+
use Illuminate\Support\Facades\Log;
56
use Modules\Core\Models\EmailTemplate;
67

78
class EmailTemplatesSeeder extends \Modules\Core\Database\Seeders\AbstractSeeder
@@ -10,34 +11,37 @@ public function run(?int $companyId = null): void
1011
{
1112
$templates = [
1213
[
13-
'title' => 'invoice_sent',
14-
'subject' => 'New Invoice: {{ invoice.number }}',
15-
'body' => "Dear {{ customer.name }},\n\nA new invoice #{{ invoice.number }} has been created for you.\n\nAmount Due: {{ invoice.total_formatted }}\nDue Date: {{ invoice.due_date_formatted }}\n\nYou can view and pay your invoice by clicking the link below:\n{{ invoice.public_url }}\n\nThank you for your business!\n\n{{ company.name }}",
14+
'title' => 'invoice_sent',
15+
'subject' => 'New Invoice: {{ invoice.number }}',
16+
'body' => "Dear {{ customer.name }},\n\nA new invoice #{{ invoice.number }} has been created for you.\n\nAmount Due: {{ invoice.total_formatted }}\nDue Date: {{ invoice.due_date_formatted }}\n\nYou can view and pay your invoice by clicking the link below:\n{{ invoice.public_url }}\n\nThank you for your business!\n\n{{ company.name }}",
17+
'company_id' => $companyId,
1618
],
1719
[
18-
'title' => 'payment_received',
19-
'subject' => 'Payment Received - Invoice #{{ invoice.number }}',
20-
'body' => "Dear {{ customer.name }},\n\nWe have received your payment of {{ payment.amount_formatted }}\nFor Invoice: {{ invoice.number }}\nPayment Date: {{ payment.paid_at_formatted }}\n\nThank you for your payment!\n\n{{ company.name }}",
20+
'title' => 'payment_received',
21+
'subject' => 'Payment Received - Invoice #{{ invoice.number }}',
22+
'body' => "Dear {{ customer.name }},\n\nWe have received your payment of {{ payment.amount_formatted }}\nFor Invoice: {{ invoice.number }}\nPayment Date: {{ payment.paid_at_formatted }}\n\nThank you for your payment!\n\n{{ company.name }}",
23+
'company_id' => $companyId,
2124
],
2225
[
23-
'title' => 'quote_sent',
24-
'subject' => 'New Quote: {{ quote.number }}',
25-
'body' => "Dear {{ customer.name }},\n\nA new quote #{{ quote.number }} has been prepared for you.\n\nAmount: {{ quote.total_formatted }}\nValid Until: {{ quote.valid_until_formatted }}\n\nYou can view the quote by clicking the link below:\n{{ quote.public_url }}\n\nPlease let us know if you have any questions.\n\nBest regards,\n{{ company.name }}",
26+
'title' => 'quote_sent',
27+
'subject' => 'New Quote: {{ quote.number }}',
28+
'body' => "Dear {{ customer.name }},\n\nA new quote #{{ quote.number }} has been prepared for you.\n\nAmount: {{ quote.total_formatted }}\nValid Until: {{ quote.valid_until_formatted }}\n\nYou can view the quote by clicking the link below:\n{{ quote.public_url }}\n\nPlease let us know if you have any questions.\n\nBest regards,\n{{ company.name }}",
29+
'company_id' => $companyId,
2630
],
2731
[
28-
'title' => 'user_invitation',
29-
'subject' => 'You have been invited to {{ company.name }}',
30-
'body' => "Hello,\n\nYou have been invited to join {{ company.name }}.\n\nPlease click the link below to set up your account:\n{{ invitation_link }}\n\nThis invitation will expire in 7 days.\n\nIf you did not expect this invitation, you can safely ignore this email.\n\nBest regards,\n{{ company.name }}",
32+
'title' => 'user_invitation',
33+
'subject' => 'You have been invited to {{ company.name }}',
34+
'body' => "Hello,\n\nYou have been invited to join {{ company.name }}.\n\nPlease click the link below to set up your account:\n{{ invitation_link }}\n\nThis invitation will expire in 7 days.\n\nIf you did not expect this invitation, you can safely ignore this email.\n\nBest regards,\n{{ company.name }}",
35+
'company_id' => $companyId,
3136
],
3237
];
3338

34-
foreach ($templates as $template) {
35-
EmailTemplate::query()->firstOrCreate(
36-
['title' => $template['title'], 'company_id' => $companyId],
37-
$template
38-
);
39-
}
39+
EmailTemplate::upsert(
40+
$templates,
41+
['company_id', 'title'],
42+
['subject', 'body']
43+
);
4044

41-
$this->command->info('Email templates seeded successfully.');
45+
Log::info('Email templates seeded successfully.');
4246
}
4347
}

0 commit comments

Comments
 (0)