diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index d03ea7b311e6..94854bb6acc9 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -498,6 +498,8 @@ class InvoiceRepository extends BaseRepository if ($invoice->is_amount_discount) { $total -= $invoice->discount; } else { + //$total *= (100 - $invoice->discount) / 100; + //$total = round($total, 2); $discount = round($total * ($invoice->discount / 100), 2); $total -= $discount; } diff --git a/tests/acceptance/InvoiceCest.php b/tests/acceptance/InvoiceCest.php index 1637726bd54d..bcc59512565d 100644 --- a/tests/acceptance/InvoiceCest.php +++ b/tests/acceptance/InvoiceCest.php @@ -15,7 +15,7 @@ class InvoiceCest $this->faker = Factory::create(); } - /* + public function createInvoice(AcceptanceTester $I) { $clientEmail = $this->faker->safeEmail; @@ -27,6 +27,12 @@ class InvoiceCest $I->click('Save'); $I->see($clientEmail); + $I->amOnPage('/tax_rates/create'); + $I->fillField(['name' => 'name'], 'TAX_21'); + $I->fillField(['name' => 'rate'], 21); + $I->click('Save'); + $I->see($itemTaxName); + $I->amOnPage('/invoices/create'); $invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value'); @@ -35,15 +41,16 @@ class InvoiceCest $I->selectDataPicker($I, '#invoice_date'); $I->selectDataPicker($I, '#due_date', '+ 15 day'); $I->fillField('#po_number', rand(100, 200)); - $I->fillField('#discount', rand(0, 20)); + $I->fillField('#discount', 15); - $this->fillItems($I); + $this->fillItem($I, 'Item', 'Notes', 64.50, 3); $I->click('#saveButton'); $I->wait(1); $I->see($invoiceNumber); } + /* public function editInvoice(AcceptanceTester $I) { $I->wantTo('edit an invoice'); @@ -78,7 +85,7 @@ class InvoiceCest } } */ - public function createRecurringInvoice(AcceptanceTester $I) + private function createRecurringInvoice(AcceptanceTester $I) { $clientEmail = $this->faker->safeEmail; @@ -109,7 +116,7 @@ class InvoiceCest } - public function cloneInvoice(AcceptanceTester $I) + private function cloneInvoice(AcceptanceTester $I) { $I->wantTo('clone an invoice'); $I->amOnPage('/invoices/1/clone'); @@ -146,15 +153,20 @@ class InvoiceCest for ($i = 1; $i <= $max; $i++) { $row_selector = sprintf('table.invoice-table tbody tr:nth-child(%d) ', $i); - $product_key = $this->faker->text(10); - $description = $this->faker->text(80); - $unit_cost = $this->faker->randomFloat(2, 0, 100); - $quantity = $this->faker->randomDigitNotNull; + $product = $this->faker->text(10); + $description = $this->faker->text(80); + $cost = $this->faker->randomFloat(2, 0, 100); + $quantity = $this->faker->randomDigitNotNull; - $I->fillField($row_selector.'#product_key', $product_key); - $I->fillField($row_selector.'textarea', $description); - $I->fillField($row_selector.'td:nth-child(4) input', $unit_cost); - $I->fillField($row_selector.'td:nth-child(5) input', $quantity); + $this->fillItem($I, $product, $description, $cost, $quantity); } } + + private function fillItem(AcceptanceTester $I, $product, $description, $cost, $quantity) + { + $I->fillField($row_selector.'#product_key', $product_key); + $I->fillField($row_selector.'textarea', $description); + $I->fillField($row_selector.'td:nth-child(4) input', $unit_cost); + $I->fillField($row_selector.'td:nth-child(5) input', $quantity); + } }