mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 13:41:23 +00:00
Merge pull request #198 from mchev/invoice_cancellation
Support for Zero and Negative Item Quantities on Invoices
This commit is contained in:
committed by
Darko Gjorgjijoski
parent
e1a0a2d8e4
commit
967c225df9
@@ -231,13 +231,20 @@ test('estimate mark as rejected', function () {
|
||||
});
|
||||
|
||||
test('create invoice from estimate', function () {
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$response = postJson("api/v1/estimates/{$estimate->id}/convert-to-invoice")
|
||||
->assertStatus(200);
|
||||
$estimate = Estimate::factory()
|
||||
->create([
|
||||
'estimate_date' => now(),
|
||||
'expiry_date' => now()->addMonth(),
|
||||
]);
|
||||
|
||||
$response = postJson("api/v1/estimates/{$estimate->id}/convert-to-invoice");
|
||||
|
||||
if ($response->status() !== 200) {
|
||||
$this->fail('Response status is not 200. Response body: '.json_encode($response->json()));
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('delete multiple estimates using a form request', function () {
|
||||
|
||||
@@ -61,6 +61,67 @@ test('create invoice', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
test('create invoice with negative and zero item quantities', function () {
|
||||
$invoice = Invoice::factory()->raw([
|
||||
'items' => [
|
||||
InvoiceItem::factory()->raw([
|
||||
'quantity' => -2,
|
||||
'price' => 100,
|
||||
]),
|
||||
InvoiceItem::factory()->raw([
|
||||
'quantity' => 1,
|
||||
'price' => 50,
|
||||
]),
|
||||
InvoiceItem::factory()->raw([
|
||||
'quantity' => 0,
|
||||
'price' => 75,
|
||||
]),
|
||||
],
|
||||
'sub_total' => -150,
|
||||
'total' => -150,
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/invoices', $invoice);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'total' => -150,
|
||||
'sub_total' => -150,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'quantity' => -2,
|
||||
'total' => -200,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'quantity' => 1,
|
||||
'total' => 50,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'quantity' => 0,
|
||||
'total' => 0,
|
||||
]);
|
||||
|
||||
$createdInvoice = Invoice::where('total', -150)->first();
|
||||
$this->assertNotNull($createdInvoice);
|
||||
$this->assertEquals(3, $createdInvoice->items()->count());
|
||||
|
||||
$negativeItem = $createdInvoice->items()->where('quantity', -2)->first();
|
||||
$this->assertNotNull($negativeItem);
|
||||
$this->assertEquals(-200, $negativeItem->total);
|
||||
|
||||
$positiveItem = $createdInvoice->items()->where('quantity', 1)->first();
|
||||
$this->assertNotNull($positiveItem);
|
||||
$this->assertEquals(50, $positiveItem->total);
|
||||
|
||||
$zeroItem = $createdInvoice->items()->where('quantity', 0)->first();
|
||||
$this->assertNotNull($zeroItem);
|
||||
$this->assertEquals(0, $zeroItem->total);
|
||||
});
|
||||
|
||||
test('create invoice as sent', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->raw([
|
||||
|
||||
Reference in New Issue
Block a user