Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/Clients/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @property int $id
* @property int $company_id
* @property string $type
* @property AddressType $type
* @property string|null $address_1
* @property string|null $address_2
* @property string|null $number
Expand Down
2 changes: 1 addition & 1 deletion Modules/Clients/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @property bool|null $default_to
* @property bool|null $default_cc
* @property bool|null $default_bcc
* @property string|null $gender
* @property Gender|null $gender
* @property Company $company
* @property Relation $relation
* @property Collection|Relation[] $relations
Expand Down
4 changes: 2 additions & 2 deletions Modules/Clients/Models/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* @property int $id
* @property int $company_id
* @property int|null $primary_contact_id
* @property string $relation_type
* @property string $relation_status
* @property RelationType $relation_type
* @property RelationStatus $relation_status
* @property string $relation_number
* @property string $company_name
* @property string|null $trading_name
Expand Down
28 changes: 27 additions & 1 deletion Modules/Core/Database/Seeders/AbstractSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ protected function company(): Company

protected function findOrCreateCustomer(int $companyId): Relation
{
/** @var Relation|null $customer */
$customer = Relation::query()->where('company_id', $companyId)
->where('relation_type', RelationType::CUSTOMER->value)
->inRandomOrder()
->first();

if ( ! $customer) {
/** @var Relation $customer */
$customer = Relation::factory()
->customer()
->state(['company_id' => $companyId])
Expand All @@ -75,11 +77,13 @@ protected function findOrCreateCustomer(int $companyId): Relation

protected function findOrCreateNumbering(?int $companyId): Numbering
{
/** @var Numbering|null $documentGroup */
$documentGroup = Numbering::query()->where('company_id', $this->companyId)
->inRandomOrder()
->first();

if ( ! $documentGroup) {
/** @var Numbering $documentGroup */
$documentGroup = Numbering::factory()->state([
'company_id' => $companyId,
])
Expand All @@ -91,11 +95,13 @@ protected function findOrCreateNumbering(?int $companyId): Numbering

protected function findOrCreateExpenseCategory(?int $companyId): ExpenseCategory
{
/** @var ExpenseCategory|null $category */
$category = ExpenseCategory::query()->where('company_id', $this->companyId)
->inRandomOrder()
->first();

if ( ! $category) {
/** @var ExpenseCategory $category */
$category = ExpenseCategory::factory()->state([
'company_id' => $companyId,
])
Expand All @@ -107,13 +113,15 @@ protected function findOrCreateExpenseCategory(?int $companyId): ExpenseCategory

protected function findOrCreateInvoice(?int $companyId): Invoice
{
/** @var Invoice|null $invoice */
$invoice = Invoice::query()->where('company_id', $this->companyId)
->inRandomOrder()
->first();

if ( ! $invoice) {
$documentGroup = $this->findOrCreateNumbering($companyId);

/** @var Invoice $invoice */
$invoice = Invoice::factory()->state([
'company_id' => $this->companyId,
'numbering_id' => $documentGroup->id,
Expand All @@ -126,8 +134,10 @@ protected function findOrCreateInvoice(?int $companyId): Invoice

protected function findOrCreateProduct(int $companyId): Product
{
/** @var Product|null $product */
$product = Product::query()->where('company_id', $companyId)->inRandomOrder()->first();
if ( ! $product) {
/** @var Product $product */
$product = Product::factory()->state(['company_id' => $companyId])->create();
}

Expand All @@ -136,10 +146,12 @@ protected function findOrCreateProduct(int $companyId): Product

protected function findOrCreateProductCategory(int $companyId): ProductCategory
{
/** @var ProductCategory|null $prodCat */
$prodCat = ProductCategory::query()->where('company_id', $this->companyId)
->inRandomOrder()->first();

if ( ! $prodCat) {
/** @var ProductCategory $prodCat */
$prodCat = ProductCategory::factory()->state(['company_id' => $companyId])->create();
}

Expand All @@ -148,10 +160,12 @@ protected function findOrCreateProductCategory(int $companyId): ProductCategory

protected function findOrCreateProductUnit(int $companyId): ProductUnit
{
/** @var ProductUnit|null $prodUnit */
$prodUnit = ProductUnit::query()->where('company_id', $this->companyId)
->inRandomOrder()->first();

if ( ! $prodUnit) {
/** @var ProductUnit $prodUnit */
$prodUnit = ProductUnit::factory()->state(['company_id' => $companyId])->create();
}

Expand All @@ -160,10 +174,12 @@ protected function findOrCreateProductUnit(int $companyId): ProductUnit

protected function findOrCreateProject(int $companyId): Project
{
/** @var Project|null $project */
$project = Project::query()->where('company_id', $this->companyId)
->inRandomOrder()->first();

if ( ! $project) {
/** @var Project $project */
$project = Project::factory()->state(['company_id' => $companyId])->create();
}

Expand All @@ -172,12 +188,14 @@ protected function findOrCreateProject(int $companyId): Project

protected function findOrCreateProspect(int $companyId): Relation
{
/** @var Relation|null $prospect */
$prospect = Relation::query()->where('company_id', $companyId)
->where('relation_type', RelationType::PROSPECT->value)
->inRandomOrder()
->first();

if ( ! $prospect) {
/** @var Relation $prospect */
$prospect = Relation::factory()
->prospect()
->state(['company_id' => $companyId])
Expand All @@ -189,6 +207,7 @@ protected function findOrCreateProspect(int $companyId): Relation

protected function findOrCreateRelationOfType(int $companyId, RelationType $type): Relation
{
/** @var Relation|null $relation */
$relation = Relation::query()
->where('company_id', $companyId)
->where('relation_type', $type->value)
Expand All @@ -207,15 +226,20 @@ protected function findOrCreateRelationOfType(int $companyId, RelationType $type
default => $factory,
};

return $factory->create();
/** @var Relation $relation */
$relation = $factory->create();

return $relation;
}

protected function findOrCreateTaxRate(?int $companyId): TaxRate
{
/** @var TaxRate|null $taxRate */
$taxRate = TaxRate::query()->where('company_id', $this->companyId)
->inRandomOrder()->first();

if ( ! $taxRate) {
/** @var TaxRate $taxRate */
$taxRate = TaxRate::factory()->state(['company_id' => $companyId])->create();
}

Expand All @@ -224,11 +248,13 @@ protected function findOrCreateTaxRate(?int $companyId): TaxRate

protected function findOrCreateUser(int $companyId): User
{
/** @var User|null $user */
$user = User::query()->whereHas('companies', fn ($q) => $q->where('companies.id', $companyId))
->inRandomOrder()
->first();

if ( ! $user) {
/** @var User $user */
$user = User::factory()->create();
$user->companies()->attach($companyId);
}
Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Models/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Modules\Core\Traits\BelongsToCompany;

/**
* @property int $id
* @property int $company_id
* @property string|null $title
* @property string|null $type
* @property string $body
* @property int $id
* @property int $company_id
* @property string|null $title
* @property EmailTemplateType|null $type
Comment thread
nielsdrost7 marked this conversation as resolved.
* @property string $body
* @property string|null $subject
* @property string|null $from_name
* @property string|null $from_email
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Models/TaxRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @property int $id
* @property int $company_id
* @property string $tax_rate_type
* @property TaxRateType $tax_rate_type
* @property bool $is_active
* @property string $code
* @property string $name
Expand Down
8 changes: 6 additions & 2 deletions Modules/Core/Tests/AbstractAdminPanelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ protected function setUp(): void

filament()->setCurrentPanel(filament()->getPanel('admin'));

$this->company = Company::factory()->create();
/** @var Company $company */
$company = Company::factory()->create();
$this->company = $company;

$this->superAdmin = User::factory()->create();
/** @var User $superAdmin */
$superAdmin = User::factory()->create();
$this->superAdmin = $superAdmin;

session(['current_company_id' => $this->company->id]);

Expand Down
8 changes: 6 additions & 2 deletions Modules/Core/Tests/AbstractCompanyPanelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ protected function setUp(): void
{
parent::setUp();

$this->user = User::factory()->withCompany([
/** @var User $user */
$user = User::factory()->withCompany([
'search_code' => 'IVPLV2',
'name' => 'InvoicePlane Corporation',
'slug' => 'invoiceplane-corporation',
])->create();
$this->user = $user;

$this->company = Company::query()->where('search_code', 'IVPLV2')->firstOrFail();
/** @var Company $company */
$company = Company::query()->where('search_code', 'IVPLV2')->firstOrFail();
$this->company = $company;

/*
* quietly set tenant so it won't wine about user not being set yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ protected function setUp(): void
{
parent::setUp();

$this->company = Company::factory()->create();
/** @var Company $company */
$company = Company::factory()->create();
$this->company = $company;
}

#[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class RecentExpensesWidget extends TableWidget

protected function getTableQuery(): Builder|Relation|null
{
return Expense::query()->latest()->limit(10);
/** @var Builder<Expense> $query */
$query = Expense::query()->latest()->limit(10);

return $query;
}

protected function getTableColumns(): array
Expand Down
4 changes: 2 additions & 2 deletions Modules/Expenses/Models/Expense.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* @property int|null $category_id
* @property int|null $user_id
* @property string $expense_number
* @property string $expense_status
* @property string $expense_type
* @property ExpenseStatus $expense_status
* @property ExpenseType $expense_type
* @property Carbon $expensed_at
* @property float $expense_amount
* @property string|null $description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public function getTableHeaderActions(): array

protected function getTableQuery(): Builder|Relation|null
{
return Invoice::query()->recent();
/** @var Builder<Invoice> $query */
$query = Invoice::query()->recent();

return $query;
}

protected function getTableColumns(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public function it_fails_when_cancellation_not_allowed(): void
*/
protected function createMockInvoice(string $status = 'sent'): Invoice
{
/** @var Relation $customer */
$customer = Relation::factory()->make([
'company_name' => 'Test Customer',
'customer_name' => 'Test Customer',
Expand All @@ -236,6 +237,7 @@ protected function createMockInvoice(string $status = 'sent'): Invoice
]),
]);

/** @var Invoice $invoice */
$invoice = Invoice::factory()->make([
'invoice_number' => 'INV-2024-001',
'invoice_status' => $status,
Expand All @@ -249,7 +251,6 @@ protected function createMockInvoice(string $status = 'sent'): Invoice
$invoice->setRelation('customer', $customer);
$invoice->setRelation('invoiceItems', $items);

/* @var Invoice $invoice */
return $invoice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public function it_handles_server_errors(): void
*/
protected function createMockInvoice(): Invoice
{
/** @var Relation $customer */
$customer = Relation::factory()->make([
'company_name' => 'Test Customer',
'customer_name' => 'Test Customer',
Expand All @@ -257,6 +258,7 @@ protected function createMockInvoice(): Invoice
]),
]);

/** @var Invoice $invoice */
$invoice = Invoice::factory()->make([
'invoice_number' => 'INV-2024-001',
'invoice_item_subtotal' => 200,
Expand All @@ -269,7 +271,6 @@ protected function createMockInvoice(): Invoice
$invoice->setRelation('customer', $customer);
$invoice->setRelation('invoiceItems', $items);

/* @var Invoice $invoice */
return $invoice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class RecentPaymentsWidget extends TableWidget

protected function getTableQuery(): Builder|Relation|null
{
return Payment::query()->latest()->limit(10);
/** @var Builder<Payment> $query */
$query = Payment::query()->latest()->limit(10);

return $query;
}

protected function getTableColumns(): array
Expand Down
2 changes: 1 addition & 1 deletion Modules/Products/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @property int $company_id
* @property int $category_id
* @property int|null $unit_id
* @property string $type
* @property ProductType $type
* @property string|null $code
* @property string|null $product_name
* @property float|null $price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class RecentProjectsWidget extends TableWidget

protected static ?int $sort = 3;

/** @phpstan-ignore-next-line */
protected function getTableQuery(): Builder|Relation|null
{
return Project::query()->latest()->limit(10);
/** @var Builder<Project> $query */
$query = Project::query()->latest()->limit(10);

return $query;
}

protected function getTableColumns(): array
Expand Down
Loading