feat(payments): add customer ledgers and allocations (#744)

This commit is contained in:
Darko Gjorgjijoski
2026-08-05 03:28:35 +02:00
committed by GitHub
parent 8ae82ae91e
commit f322c2b74d
74 changed files with 5693 additions and 693 deletions
+47
View File
@@ -1,7 +1,11 @@
<?php
use App\Models\Company;
use App\Models\Customer;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentAllocation;
use App\Models\Tax;
use App\Models\TaxType;
use App\Models\User;
@@ -73,3 +77,46 @@ test('company deletion removes receipt taxes through expense model events', func
$this->assertDatabaseMissing('taxes', ['id' => $tax->id]);
});
test('customer deletion removes payment allocations before bulk payment deletion', function () {
$customer = Customer::factory()->create();
$invoice = Invoice::factory()->create([
'company_id' => $customer->company_id,
'customer_id' => $customer->id,
]);
$payment = Payment::factory()->create([
'company_id' => $customer->company_id,
'customer_id' => $customer->id,
]);
$allocation = PaymentAllocation::factory()->create([
'payment_id' => $payment->id,
'invoice_id' => $invoice->id,
]);
app(CustomerService::class)->delete(collect([$customer->id]));
$this->assertDatabaseMissing('payment_allocations', ['id' => $allocation->id]);
});
test('company deletion removes payment allocations before bulk payment deletion', function () {
$user = User::find(1);
$company = Company::factory()->create(['owner_id' => $user->id]);
$user->companies()->attach($company);
$customer = Customer::factory()->create(['company_id' => $company->id]);
$invoice = Invoice::factory()->create([
'company_id' => $company->id,
'customer_id' => $customer->id,
]);
$payment = Payment::factory()->create([
'company_id' => $company->id,
'customer_id' => $customer->id,
]);
$allocation = PaymentAllocation::factory()->create([
'payment_id' => $payment->id,
'invoice_id' => $invoice->id,
]);
app(CompanyService::class)->delete($company, $user);
$this->assertDatabaseMissing('payment_allocations', ['id' => $allocation->id]);
});