2017-03-19 17:23:57 +02:00
|
|
|
<?php
|
2016-01-18 10:30:42 +02:00
|
|
|
|
|
|
|
|
use Codeception\Util\Fixtures;
|
|
|
|
|
use Faker\Factory;
|
|
|
|
|
|
|
|
|
|
class TaxRatesCest
|
|
|
|
|
{
|
|
|
|
|
private $faker;
|
|
|
|
|
|
|
|
|
|
public function _before(AcceptanceTester $I)
|
|
|
|
|
{
|
|
|
|
|
$I->checkIfLogin($I);
|
|
|
|
|
|
|
|
|
|
$this->faker = Factory::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function taxRates(AcceptanceTester $I)
|
|
|
|
|
{
|
2016-01-18 15:11:37 +02:00
|
|
|
$I->wantTo('test tax rates');
|
2016-01-18 10:30:42 +02:00
|
|
|
|
|
|
|
|
$clientEmail = $this->faker->safeEmail;
|
|
|
|
|
$productKey = $this->faker->text(10);
|
2016-01-18 15:11:37 +02:00
|
|
|
$itemTaxRate = $this->faker->randomFloat(2, 5, 15);
|
|
|
|
|
$itemTaxName = $this->faker->word();
|
|
|
|
|
$invoiceTaxRate = $this->faker->randomFloat(2, 5, 15);
|
|
|
|
|
$invoiceTaxName = $this->faker->word();
|
|
|
|
|
$itemCost = $this->faker->numberBetween(1, 20);
|
|
|
|
|
|
|
|
|
|
$total = $itemCost;
|
|
|
|
|
$total += round($itemCost * $itemTaxRate / 100, 2);
|
|
|
|
|
$total += round($itemCost * $invoiceTaxRate / 100, 2);
|
2016-10-02 12:51:10 +03:00
|
|
|
|
2016-03-15 15:25:00 +02:00
|
|
|
$itemTaxRate = number_format($itemTaxRate, 3);
|
|
|
|
|
$invoiceTaxRate = number_format($invoiceTaxRate, 3);
|
2016-01-18 15:11:37 +02:00
|
|
|
|
|
|
|
|
// create tax rates
|
2017-03-19 15:31:25 +02:00
|
|
|
$I->createTaxRate($I, $itemTaxName, $itemTaxRate);
|
|
|
|
|
$I->createTaxRate($I, $invoiceTaxName, $invoiceTaxRate);
|
2016-01-18 10:30:42 +02:00
|
|
|
|
2016-01-18 15:11:37 +02:00
|
|
|
// enable line item taxes
|
|
|
|
|
$I->amOnPage('/settings/tax_rates');
|
|
|
|
|
$I->checkOption('#invoice_item_taxes');
|
2016-01-18 10:30:42 +02:00
|
|
|
$I->click('Save');
|
|
|
|
|
|
|
|
|
|
// create product
|
|
|
|
|
$I->amOnPage('/products/create');
|
|
|
|
|
$I->fillField(['name' => 'product_key'], $productKey);
|
|
|
|
|
$I->fillField(['name' => 'notes'], $this->faker->text(80));
|
2016-01-18 15:11:37 +02:00
|
|
|
$I->fillField(['name' => 'cost'], $itemCost);
|
2017-03-19 16:02:49 +02:00
|
|
|
$I->selectOption('select[name=default_tax_rate_id]', $itemTaxName . ': ' . $itemTaxRate . '%');
|
2016-01-18 10:30:42 +02:00
|
|
|
$I->click('Save');
|
|
|
|
|
$I->wait(1);
|
2016-10-02 12:51:10 +03:00
|
|
|
//$I->see($productKey);
|
2016-01-18 10:30:42 +02:00
|
|
|
|
2016-01-18 15:11:37 +02:00
|
|
|
// create client
|
|
|
|
|
$I->amOnPage('/clients/create');
|
|
|
|
|
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
|
|
|
|
|
$I->click('Save');
|
|
|
|
|
$I->see($clientEmail);
|
|
|
|
|
|
2016-01-18 10:30:42 +02:00
|
|
|
// create invoice
|
|
|
|
|
$I->amOnPage('/invoices/create');
|
|
|
|
|
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
|
|
|
|
|
$I->fillField('table.invoice-table tbody tr:nth-child(1) #product_key', $productKey);
|
2016-02-29 20:08:09 +02:00
|
|
|
$I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable');
|
2017-03-19 18:31:24 +02:00
|
|
|
$I->selectOption('#taxRateSelect1', $invoiceTaxName . ' ' . floatval($invoiceTaxRate) . '%');
|
2016-04-15 10:25:26 +03:00
|
|
|
$I->wait(3);
|
2016-01-18 15:11:37 +02:00
|
|
|
|
|
|
|
|
// check total is right before saving
|
|
|
|
|
$I->see("\${$total}");
|
2016-01-18 10:30:42 +02:00
|
|
|
$I->click('Save');
|
2016-04-30 21:41:05 +03:00
|
|
|
$I->wait(3);
|
2016-01-18 10:30:42 +02:00
|
|
|
$I->see($clientEmail);
|
|
|
|
|
|
2016-01-18 15:11:37 +02:00
|
|
|
// check total is right after saving
|
|
|
|
|
$I->see("\${$total}");
|
|
|
|
|
$I->amOnPage('/invoices');
|
2016-05-05 09:35:39 +03:00
|
|
|
$I->wait(2);
|
2016-10-02 12:51:10 +03:00
|
|
|
|
2016-01-18 15:11:37 +02:00
|
|
|
// check total is right in list view
|
|
|
|
|
$I->see("\${$total}");
|
2016-01-18 10:30:42 +02:00
|
|
|
}
|
2016-01-18 15:11:37 +02:00
|
|
|
|
2016-10-02 12:51:10 +03:00
|
|
|
}
|