1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/tests/acceptance/DiscountCest.php

80 lines
2.7 KiB
PHP
Raw Normal View History

2017-12-21 20:36:00 +01:00
<?php
use Codeception\Util\Fixtures;
use Faker\Factory;
class DiscountCest
{
private $faker;
public function _before(AcceptanceTester $I)
{
$I->checkIfLogin($I);
$this->faker = Factory::create();
}
public function lineItemDiscounts(AcceptanceTester $I)
{
$I->wantTo('test line item discounts');
$clientEmail = $this->faker->safeEmail;
$itemTaxName = $this->faker->word;
2017-12-24 11:19:31 +01:00
$productKey = $this->faker->word;
2017-12-21 20:36:00 +01:00
$itemTaxRate = rand(1, 1000) / 10;
$itemDiscount = rand(1, 1000) / 10;
2017-12-24 11:19:31 +01:00
$itemDiscount = rand(1, 1000) / 10;
2017-12-21 20:36:00 +01:00
$discount = rand(1, 1000) / 10;
$itemAmount = rand(1, 10000) / 10;
$quantity = rand(1,20);
$I->amOnPage('/settings/invoice_design#product_fields');
$I->selectOption('#product_fields_select', 'product.discount');
$I->click('Save');
$I->amOnPage('/clients/create');
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
$I->click('Save');
$I->see($clientEmail);
$clientId = $I->grabFromCurrentUrl('~clients/(\d+)~');
$I->amOnPage('/tax_rates/create');
$I->fillField(['name' => 'name'], $itemTaxName);
$I->fillField(['name' => 'rate'], $itemTaxRate);
$I->click('Save');
$I->see($itemTaxName);
2017-12-24 11:19:31 +01:00
// create product
$I->amOnPage('/products/create');
$I->fillField(['name' => 'product_key'], $productKey);
$I->fillField(['name' => 'notes'], $this->faker->text(80));
$I->fillField(['name' => 'cost'], $itemAmount);
$I->selectOption('select[name=tax_select1]', $itemTaxName . ': ' . number_format($itemTaxRate, 3) . '%');
$I->click('Save');
$I->wait(1);
2017-12-21 20:36:00 +01:00
$I->amOnPage('/invoices/create');
$invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value');
// check tax and discount rounding
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
$I->fillField('#discount', $discount);
2017-12-25 14:23:30 +01:00
$I->fillField('table.invoice-table tbody tr:nth-child(1) td:nth-child(2) input.tt-input', $productKey);
2017-12-24 11:19:31 +01:00
$I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable');
$I->fillField('table.invoice-table tbody tr:nth-child(1) td:nth-child(6) input', $itemDiscount);
$I->fillField('table.invoice-table tbody tr:nth-child(1) td:nth-child(5) input', $quantity);
2017-12-21 20:36:00 +01:00
$I->click('Mark Sent');
2017-12-24 11:19:31 +01:00
$total = $itemAmount * $quantity;
$total -= $total * $itemDiscount / 100;
$total -= $total * $discount / 100;
$total += $total * $itemTaxRate / 100;
2017-12-21 20:36:00 +01:00
2017-12-24 11:19:31 +01:00
$I->see(number_format($total,2));
2017-12-21 20:36:00 +01:00
}
}