Updates for check data script

This commit is contained in:
David Bomba 2025-08-31 15:54:53 +10:00
parent 789a3d0ca7
commit c37318c2cc
22 changed files with 54 additions and 51 deletions

View File

@ -970,14 +970,14 @@ class CheckData extends Command
public function checkClientSettings()
{
if ($this->option('fix') == 'true') {
Client::query()->whereNull('country_id')->orWhere('country_id', 0)->cursor()->each(function ($client) {
Client::query()->withTrashed()->whereNull('country_id')->orWhere('country_id', 0)->cursor()->each(function ($client) {
$client->country_id = $client->company->settings->country_id;
$client->saveQuietly();
$this->logMessage("Fixing country for # {$client->id}");
});
Client::query()->whereNull("settings->currency_id")->orWhereJsonContains('settings', ['currency_id' => ''])->cursor()->each(function ($client) {
Client::query()->withTrashed()->whereNull("settings->currency_id")->orWhereJsonContains('settings', ['currency_id' => ''])->cursor()->each(function ($client) {
$settings = $client->settings;
$settings->currency_id = (string)$client->company->settings->currency_id;
$client->settings = $settings;
@ -987,7 +987,7 @@ class CheckData extends Command
});
Payment::withTrashed()->where('exchange_rate', 0)->cursor()->each(function ($payment) {
Payment::withTrashed()->withTrashed()->where('exchange_rate', 0)->cursor()->each(function ($payment) {
$payment->exchange_rate = 1;
$payment->saveQuietly();
@ -1000,11 +1000,11 @@ class CheckData extends Command
})
->cursor()
->each(function ($p) {
$p->currency_id = $p->client->settings->currency_id;
$p->currency_id = $p->client->settings->currency_id ?? $p->company->settings->currency_id;
$p->saveQuietly();
$this->logMessage("Fixing currency for # {$p->id}");
$this->logMessage("Fixing currency for # {$p->id} with new currency {$p->currency_id}");
});
@ -1015,7 +1015,7 @@ class CheckData extends Command
$c->subdomain = MultiDB::randomSubdomainGenerator();
$c->save();
$this->logMessage("Fixing subdomain for # {$c->id}");
$this->logMessage("Fixing subdomain for # {$c->id} with new subdomain {$c->subdomain}");
});
@ -1076,7 +1076,7 @@ class CheckData extends Command
public function checkVendorSettings()
{
if ($this->option('fix') == 'true') {
Vendor::query()->whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor) {
Vendor::query()->withTrashed()->whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor) {
$vendor->currency_id = $vendor->company->settings->currency_id;
$vendor->saveQuietly();
@ -1174,7 +1174,7 @@ class CheckData extends Command
$bt->invoice_ids = collect($bt->payment->invoices)->pluck('hashed_id')->implode(',');
$bt->save();
$this->logMessage("Fixing - {$bt->id}");
$this->logMessage("Fixing - {$bt->id} with new invoice IDs {$bt->invoice_ids}");
}
@ -1195,7 +1195,7 @@ class CheckData extends Command
$c->send_email = false;
$c->saveQuietly();
$this->logMessage("Fixing - {$c->id}");
$this->logMessage("Fixing - {$c->id} with new send email {$c->send_email}");
});
}
@ -1234,11 +1234,11 @@ class CheckData extends Command
if ($this->option('fix') == 'true') {
$p->cursor()->each(function ($c) {
$c->currency_id = $c->client->settings->currency_id ?? $c->company->settings->currency_id;
$c->saveQuietly();
$p->cursor()->each(function ($payment) {
$payment->currency_id = $payment->client->settings->currency_id ?? $payment->company->settings->currency_id;
$payment->saveQuietly();
$this->logMessage("Fixing - {$c->id}");
$this->logMessage("Fixing payment ID - {$payment->id} with new currency {$payment->currency_id}");
});
}

View File

@ -619,7 +619,7 @@ class ClientTest extends TestCase
$data = [
'name' => 'A loyal Client',
'contacts' => $this->faker->unique()->safeEmail(),
'contacts' => \Illuminate\Support\Str::random(32)."@example.com",
];
try {
@ -674,7 +674,7 @@ class ClientTest extends TestCase
$data = [
'name' => 'A loyal Client',
'contacts' => [
['email' => $this->faker->unique()->safeEmail()],
['email' => \Illuminate\Support\Str::random(32)."@example.com"],
],
];
@ -690,7 +690,7 @@ class ClientTest extends TestCase
'name' => 'A loyal Client',
'contacts' => [
[
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => '*****',
],
],
@ -706,7 +706,7 @@ class ClientTest extends TestCase
'name' => 'A loyal Client',
'contacts' => [
[
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => '1',
],
],
@ -728,7 +728,7 @@ class ClientTest extends TestCase
'name' => 'A loyal Client',
'contacts' => [
[
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => '1Qajsj...33',
],
],
@ -751,11 +751,11 @@ class ClientTest extends TestCase
'name' => 'A loyal Client',
'contacts' => [
[
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => '1Qajsj...33',
],
[
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => '1234AAAAAaaaaa',
],
],
@ -786,7 +786,7 @@ class ClientTest extends TestCase
$arr = $response->json();
$safe_email = $this->faker->unique()->safeEmail();
$safe_email = \Illuminate\Support\Str::random(32)."@example.com";
$data = [
'name' => 'A loyal Client',
@ -820,7 +820,7 @@ class ClientTest extends TestCase
$this->assertEquals(0, strlen($contact->password));
$safe_email = $this->faker->unique()->safeEmail();
$safe_email = \Illuminate\Support\Str::random(32)."@example.com";
$data = [
'name' => 'A loyal Client',

View File

@ -88,7 +88,7 @@ class ArDetailReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -85,7 +85,7 @@ class ArSummaryReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -85,7 +85,7 @@ class ClientBalanceReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -85,7 +85,7 @@ class ClientSalesReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -89,7 +89,7 @@ class ProductSalesReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -88,7 +88,7 @@ class ProfitAndLossReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -207,7 +207,7 @@ class ReportCsvGenerationTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -88,7 +88,7 @@ class UserSalesReportTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -45,6 +45,9 @@ class InventoryManagementTest extends TestCase
public function testInventoryMovements()
{
config(['queue.default' => 'sync']);
$product = Product::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,

View File

@ -56,7 +56,7 @@ class MultiPaymentDeleteTest extends TestCase
$user = User::factory()->create([
'account_id' => $account->id,
'confirmation_code' => '11',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$cu = CompanyUserFactory::create($user->id, $company->id, $account->id);

View File

@ -87,7 +87,7 @@ class QuoteReminderTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
if(!$settings) {

View File

@ -87,7 +87,7 @@ class ReminderTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
if(!$settings) {
@ -295,7 +295,7 @@ class ReminderTest extends TestCase
$user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -73,7 +73,7 @@ class UserTest extends TestCase
$user = User::factory()->create([
'account_id' => $account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$user->password = \Illuminate\Support\Facades\Hash::make('ALongAndBriliantPassword');
@ -204,7 +204,7 @@ class UserTest extends TestCase
$data = $user->toArray();
$data['email'] = $this->faker->unique()->safeEmail();
$data['email'] = \Illuminate\Support\Str::random(32)."@example.com";
unset($data['password']);
$response = $this->withHeaders([
@ -357,7 +357,7 @@ class UserTest extends TestCase
$user = User::factory()->create([
'account_id' => $account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => \Illuminate\Support\Facades\Hash::make('ALongAndBriliantPassword'),
]);

View File

@ -50,7 +50,7 @@ class StorecoveRouterTest extends TestCase
$user = User::factory()->create([
'account_id' => $account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
'password' => \Illuminate\Support\Facades\Hash::make('ALongAndBriliantPassword'),
]);

View File

@ -1018,7 +1018,7 @@ $this->assertTrue(in_array($item->tax_id, ['1','2']));
$settings->state = 'Lazio';
$settings->postal_code = '00187';
$settings->phone = '06 1234567';
$settings->email = $this->faker->unique()->safeEmail();
$settings->email = \Illuminate\Support\Str::random(32)."@example.com";
$settings->country_id = '380'; // Italy's ISO country code
$settings->vat_number = 'IT92443356490'; // Italian VAT number
$settings->id_number = 'RM 123456'; // Typical Italian company registration format
@ -1181,7 +1181,7 @@ $this->assertTrue(in_array($item->tax_id, ['1','2']));
$settings->state = 'Berlin';
$settings->postal_code = '10115';
$settings->phone = '030 1234567';
$settings->email = $this->faker->unique()->safeEmail();
$settings->email = \Illuminate\Support\Str::random(32)."@example.com";
$settings->country_id = '276'; // Germany's ISO country code
$settings->vat_number = 'DE123456789';
$settings->id_number = 'HRB 98765';
@ -1289,7 +1289,7 @@ $this->assertTrue(in_array($item->tax_id, ['1','2']));
$settings->state = 'Madrid';
$settings->postal_code = '28013';
$settings->phone = '030 1234567';
$settings->email = $this->faker->unique()->safeEmail();
$settings->email = \Illuminate\Support\Str::random(32)."@example.com";
$settings->country_id = '724'; // Germany's ISO country code
$settings->vat_number = 'ESB16645678';
$settings->id_number = 'HRB 12345';
@ -1397,7 +1397,7 @@ $this->assertTrue(in_array($item->tax_id, ['1','2']));
$settings->state = 'Île-de-France';
$settings->postal_code = '75002';
$settings->phone = '01 23456789';
$settings->email = $this->faker->unique()->safeEmail();
$settings->email = \Illuminate\Support\Str::random(32)."@example.com";
$settings->country_id = '250'; // France's ISO country code
$settings->vat_number = 'FR82345678911';
$settings->id_number = '12345678900010';
@ -1508,7 +1508,7 @@ $this->assertTrue(in_array($item->tax_id, ['1','2']));
$settings->state = 'Vienna';
$settings->postal_code = '1010';
$settings->phone = '+43 1 23456789';
$settings->email = $this->faker->unique()->safeEmail();
$settings->email = \Illuminate\Support\Str::random(32)."@example.com";
$settings->country_id = '40'; // Austria's ISO country code
$settings->vat_number = 'ATU92335648';
$settings->id_number = 'FN 123456x';
@ -1617,7 +1617,7 @@ $this->assertTrue(in_array($item->tax_id, ['1','2']));
$settings->state = 'Bucharest';
$settings->postal_code = '010101';
$settings->phone = '021 1234567';
$settings->email = $this->faker->unique()->safeEmail();
$settings->email = \Illuminate\Support\Str::random(32)."@example.com";
$settings->country_id = '642'; // Romania's ISO country code
$settings->vat_number = 'RO92443356490'; // Romanian VAT number format
$settings->id_number = 'B12345678'; // Typical Romanian company registration format

View File

@ -56,7 +56,7 @@ trait MockUnitData
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$this->company = Company::factory()->create([

View File

@ -68,7 +68,7 @@ class CheckDataTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();
@ -182,12 +182,12 @@ class CheckDataTest extends TestCase
User::factory()->create([
'account_id' => $this->account->id,
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
User::factory()->create([
'account_id' => $this->account->id,
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$user_hash = 'a';

View File

@ -79,7 +79,7 @@ class InvoiceMarkPaidTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$settings = CompanySettings::defaults();

View File

@ -70,7 +70,7 @@ class LateFeeTest extends TestCase
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'confirmation_code' => 'xyz123',
'email' => $this->faker->unique()->safeEmail(),
'email' => \Illuminate\Support\Str::random(32)."@example.com",
]);
$this->company = Company::factory()->create([

View File

@ -43,7 +43,7 @@ class RecurringExpenseCloneTest extends TestCase
public function testBadBase64String()
{
$account = Account::factory()->create();
$user = User::factory()->create(['account_id' => $account->id, 'email' => $this->faker->unique()->safeEmail()]);
$user = User::factory()->create(['account_id' => $account->id, 'email' => \Illuminate\Support\Str::random(32)."@example.com"]);
$company = Company::factory()->create(['account_id' => $account->id]);
$client = Client::factory()->create([