mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 21:31:01 +00:00
fix(taxes): correct compound tax document flows (#754)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Accounts\Models\User;
|
||||
use App\Domains\Sales\Application\RecurringInvoiceService;
|
||||
use App\Domains\Sales\Http\Controllers\Company\RecurringInvoiceController;
|
||||
use App\Domains\Sales\Http\Requests\RecurringInvoiceRequest;
|
||||
use App\Domains\Sales\Models\InvoiceItem;
|
||||
@@ -60,6 +61,60 @@ test('store recurring invoice', function () {
|
||||
$this->assertDatabaseHas('recurring_invoices', $recurringInvoice);
|
||||
});
|
||||
|
||||
test('rejects a nonzero per-item placeholder tax row', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->raw([
|
||||
'items' => [
|
||||
InvoiceItem::factory()->raw([
|
||||
'taxes' => [[
|
||||
'tax_type_id' => 0,
|
||||
'amount' => 1,
|
||||
]],
|
||||
]),
|
||||
],
|
||||
]);
|
||||
|
||||
postJson('api/v1/recurring-invoices', $recurringInvoice)
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('items.0.taxes.0.amount');
|
||||
});
|
||||
|
||||
test('allows a zero-valued per-item placeholder tax row', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->raw([
|
||||
'items' => [
|
||||
InvoiceItem::factory()->raw([
|
||||
'taxes' => [[
|
||||
'tax_type_id' => 0,
|
||||
'amount' => 0,
|
||||
]],
|
||||
]),
|
||||
],
|
||||
]);
|
||||
|
||||
postJson('api/v1/recurring-invoices', $recurringInvoice)
|
||||
->assertCreated();
|
||||
});
|
||||
|
||||
test('generated invoices retain the recurring template tax-included semantics', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->create([
|
||||
'starts_at' => Carbon::yesterday(),
|
||||
'limit_by' => RecurringInvoice::NONE,
|
||||
'tax_included' => true,
|
||||
'sub_total' => 10000,
|
||||
'tax' => 2019,
|
||||
'total' => 10119,
|
||||
'due_amount' => 10119,
|
||||
]);
|
||||
|
||||
app(RecurringInvoiceService::class)->generateInvoice($recurringInvoice);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'recurring_invoice_id' => $recurringInvoice->id,
|
||||
'tax_included' => 1,
|
||||
'tax' => 2019,
|
||||
'total' => 10119,
|
||||
]);
|
||||
});
|
||||
|
||||
test('get recurring invoice', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user