2022-05-10 12:06:40 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2022-05-10 12:06:40 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-10 12:06:40 +02:00
|
|
|
namespace Tests\Feature\Export;
|
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
use App\DataMapper\ClientSettings;
|
2022-05-13 03:13:25 +02:00
|
|
|
use App\DataMapper\CompanySettings;
|
2022-05-13 06:06:21 +02:00
|
|
|
use App\Factory\ExpenseCategoryFactory;
|
2022-05-13 08:42:04 +02:00
|
|
|
use App\Factory\ExpenseFactory;
|
2022-05-12 05:57:41 +02:00
|
|
|
use App\Factory\InvoiceFactory;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
2022-05-13 05:07:42 +02:00
|
|
|
use App\Models\ClientContact;
|
2022-05-12 02:57:58 +02:00
|
|
|
use App\Models\Company;
|
2022-05-13 05:07:42 +02:00
|
|
|
use App\Models\Expense;
|
2022-05-13 06:06:21 +02:00
|
|
|
use App\Models\ExpenseCategory;
|
2022-05-10 12:06:40 +02:00
|
|
|
use App\Models\Invoice;
|
2022-05-12 05:57:41 +02:00
|
|
|
use App\Models\User;
|
2022-05-12 02:57:58 +02:00
|
|
|
use App\Services\Report\ProfitLoss;
|
2022-05-10 12:06:40 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2022-05-13 05:07:42 +02:00
|
|
|
use Database\Factories\ClientContactFactory;
|
2022-05-10 12:06:40 +02:00
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use League\Csv\Writer;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2022-05-12 02:57:58 +02:00
|
|
|
* @covers App\Services\Report\ProfitLoss
|
2022-05-10 12:06:40 +02:00
|
|
|
*/
|
|
|
|
class ProfitAndLossReportTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2022-05-12 05:57:41 +02:00
|
|
|
|
|
|
|
public $faker;
|
2022-05-10 12:06:40 +02:00
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2022-05-12 05:57:41 +02:00
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
2022-05-10 12:06:40 +02:00
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
}
|
|
|
|
|
2022-05-12 03:10:47 +02:00
|
|
|
public $company;
|
|
|
|
|
2022-05-12 05:57:41 +02:00
|
|
|
public $user;
|
|
|
|
|
2022-05-12 03:10:47 +02:00
|
|
|
public $payload;
|
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
public $account;
|
2022-05-12 03:10:47 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
/**
|
|
|
|
* start_date - Y-m-d
|
|
|
|
end_date - Y-m-d
|
|
|
|
date_range -
|
|
|
|
all
|
|
|
|
last7
|
|
|
|
last30
|
|
|
|
this_month
|
|
|
|
last_month
|
|
|
|
this_quarter
|
|
|
|
last_quarter
|
|
|
|
this_year
|
|
|
|
custom
|
|
|
|
is_income_billed - true = Invoiced || false = Payments
|
|
|
|
expense_billed - true = Expensed || false = Expenses marked as paid
|
|
|
|
include_tax - true tax_included || false - tax_excluded
|
|
|
|
*/
|
2022-05-12 03:10:47 +02:00
|
|
|
private function buildData()
|
2022-05-10 12:06:40 +02:00
|
|
|
{
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->account = Account::factory()->create([
|
2022-05-12 05:57:41 +02:00
|
|
|
'hosted_client_count' => 1000,
|
2022-06-21 11:57:17 +02:00
|
|
|
'hosted_company_count' => 1000,
|
2022-05-12 05:57:41 +02:00
|
|
|
]);
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->account->num_users = 3;
|
|
|
|
$this->account->save();
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-12 05:57:41 +02:00
|
|
|
$this->user = User::factory()->create([
|
2022-05-12 06:40:44 +02:00
|
|
|
'account_id' => $this->account->id,
|
2022-05-12 05:57:41 +02:00
|
|
|
'confirmation_code' => 'xyz123',
|
2022-06-21 11:59:36 +02:00
|
|
|
'email' => $this->faker->unique()->safeEmail(),
|
2022-05-12 05:57:41 +02:00
|
|
|
]);
|
|
|
|
|
2022-05-13 03:13:25 +02:00
|
|
|
$settings = CompanySettings::defaults();
|
2022-06-21 11:57:17 +02:00
|
|
|
$settings->client_online_payment_notification = false;
|
|
|
|
$settings->client_manual_payment_notification = false;
|
2022-05-13 03:13:25 +02:00
|
|
|
|
2022-05-12 03:10:47 +02:00
|
|
|
$this->company = Company::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $this->account->id,
|
|
|
|
'settings' => $settings,
|
|
|
|
]);
|
2022-05-10 12:06:40 +02:00
|
|
|
|
2022-05-12 03:10:47 +02:00
|
|
|
$this->payload = [
|
2022-05-12 02:57:58 +02:00
|
|
|
'start_date' => '2000-01-01',
|
|
|
|
'end_date' => '2030-01-11',
|
|
|
|
'date_range' => 'custom',
|
2022-05-12 05:57:41 +02:00
|
|
|
'is_income_billed' => true,
|
2022-06-21 11:57:17 +02:00
|
|
|
'include_tax' => false,
|
2022-05-12 02:57:58 +02:00
|
|
|
];
|
2022-05-12 03:10:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testProfitLossInstance()
|
|
|
|
{
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->buildData();
|
|
|
|
|
2022-05-12 03:10:47 +02:00
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
2022-05-12 02:57:58 +02:00
|
|
|
|
|
|
|
$this->assertInstanceOf(ProfitLoss::class, $pl);
|
2022-05-10 12:06:40 +02:00
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->account->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSimpleInvoiceIncome()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_deleted' => 0,
|
|
|
|
]);
|
2022-05-12 06:40:44 +02:00
|
|
|
|
|
|
|
Invoice::factory()->count(2)->create([
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'amount' => 11,
|
|
|
|
'balance' => 11,
|
|
|
|
'status_id' => 2,
|
|
|
|
'total_taxes' => 1,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'terms' => 'nada',
|
|
|
|
'discount' => 0,
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
|
|
|
'tax_name1' => '',
|
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'uses_inclusive_taxes' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$this->assertEquals(20.0, $pl->getIncome());
|
|
|
|
$this->assertEquals(2, $pl->getIncomeTaxes());
|
|
|
|
|
|
|
|
$this->account->delete();
|
2022-05-10 12:06:40 +02:00
|
|
|
}
|
2022-05-12 05:57:41 +02:00
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
public function testSimpleInvoiceIncomeWithInclusivesTaxes()
|
2022-05-12 05:57:41 +02:00
|
|
|
{
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->buildData();
|
2022-05-12 05:57:41 +02:00
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_deleted' => 0,
|
|
|
|
]);
|
2022-05-12 05:57:41 +02:00
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
Invoice::factory()->count(2)->create([
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'balance' => 10,
|
|
|
|
'status_id' => 2,
|
|
|
|
'total_taxes' => 1,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'terms' => 'nada',
|
|
|
|
'discount' => 0,
|
|
|
|
'tax_rate1' => 10,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
2022-06-21 11:57:17 +02:00
|
|
|
'tax_name1' => 'GST',
|
2022-05-12 06:40:44 +02:00
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'uses_inclusive_taxes' => true,
|
|
|
|
]);
|
2022-05-12 05:57:41 +02:00
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->assertEquals(18.0, $pl->getIncome());
|
|
|
|
$this->assertEquals(2, $pl->getIncomeTaxes());
|
|
|
|
|
|
|
|
$this->account->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSimpleInvoiceIncomeWithForeignExchange()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$settings = ClientSettings::defaults();
|
2022-06-21 11:57:17 +02:00
|
|
|
$settings->currency_id = '2';
|
2022-05-12 06:40:44 +02:00
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'settings' => $settings,
|
|
|
|
]);
|
2022-05-12 06:40:44 +02:00
|
|
|
|
|
|
|
Invoice::factory()->count(2)->create([
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'balance' => 10,
|
|
|
|
'status_id' => 2,
|
|
|
|
'total_taxes' => 1,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'terms' => 'nada',
|
|
|
|
'discount' => 0,
|
|
|
|
'tax_rate1' => 10,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
2022-06-21 11:57:17 +02:00
|
|
|
'tax_name1' => 'GST',
|
2022-05-12 06:40:44 +02:00
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'uses_inclusive_taxes' => true,
|
2022-06-21 11:57:17 +02:00
|
|
|
'exchange_rate' => 0.5,
|
2022-05-12 06:40:44 +02:00
|
|
|
]);
|
2022-05-12 05:57:41 +02:00
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$this->assertEquals(36.0, $pl->getIncome());
|
|
|
|
$this->assertEquals(4, $pl->getIncomeTaxes());
|
2022-05-12 05:57:41 +02:00
|
|
|
|
2022-05-12 06:40:44 +02:00
|
|
|
$this->account->delete();
|
2022-05-12 05:57:41 +02:00
|
|
|
}
|
2022-05-12 06:40:44 +02:00
|
|
|
|
2022-05-13 01:11:40 +02:00
|
|
|
public function testSimpleInvoicePaymentIncome()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$this->payload = [
|
|
|
|
'start_date' => '2000-01-01',
|
|
|
|
'end_date' => '2030-01-11',
|
|
|
|
'date_range' => 'custom',
|
|
|
|
'is_income_billed' => false,
|
2022-06-21 11:57:17 +02:00
|
|
|
'include_tax' => false,
|
2022-05-13 01:11:40 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$settings = ClientSettings::defaults();
|
2022-06-21 11:57:17 +02:00
|
|
|
$settings->currency_id = '1';
|
2022-05-13 01:11:40 +02:00
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'settings' => $settings,
|
|
|
|
]);
|
2022-05-13 01:11:40 +02:00
|
|
|
|
2022-05-13 05:07:42 +02:00
|
|
|
$contact = ClientContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'client_id' => $client->id,
|
2022-05-13 05:07:42 +02:00
|
|
|
]);
|
|
|
|
|
2022-05-13 01:11:40 +02:00
|
|
|
$i = Invoice::factory()->create([
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'balance' => 10,
|
|
|
|
'status_id' => 2,
|
|
|
|
'total_taxes' => 0,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'terms' => 'nada',
|
|
|
|
'discount' => 0,
|
|
|
|
'tax_rate1' => 0,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
2022-06-21 11:57:17 +02:00
|
|
|
'tax_name1' => '',
|
2022-05-13 01:11:40 +02:00
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'uses_inclusive_taxes' => true,
|
2022-06-21 11:57:17 +02:00
|
|
|
'exchange_rate' => 1,
|
2022-05-13 01:11:40 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$i->service()->markPaid()->save();
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$this->assertEquals(10.0, $pl->getIncome());
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-13 01:11:40 +02:00
|
|
|
$this->account->delete();
|
|
|
|
}
|
|
|
|
|
2022-05-13 05:07:42 +02:00
|
|
|
public function testSimpleExpense()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$e = Expense::factory()->create([
|
|
|
|
'amount' => 10,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$expenses = $pl->getExpenses();
|
|
|
|
|
|
|
|
$expense = $expenses[0];
|
|
|
|
|
|
|
|
$this->assertEquals(10, $expense->total);
|
|
|
|
|
|
|
|
$this->account->delete();
|
2022-05-13 08:42:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSimpleExpenseAmountTax()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$e = ExpenseFactory::create($this->company->id, $this->user->id);
|
|
|
|
$e->amount = 10;
|
|
|
|
$e->date = '2022-01-01';
|
|
|
|
$e->calculate_tax_by_amount = true;
|
|
|
|
$e->tax_amount1 = 10;
|
|
|
|
$e->save();
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$expenses = $pl->getExpenses();
|
|
|
|
|
|
|
|
$expense = $expenses[0];
|
|
|
|
|
|
|
|
$this->assertEquals(10, $expense->total);
|
|
|
|
$this->assertEquals(10, $expense->tax);
|
|
|
|
|
|
|
|
$this->account->delete();
|
2022-05-13 05:07:42 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 08:42:04 +02:00
|
|
|
public function testSimpleExpenseTaxRateExclusive()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$e = ExpenseFactory::create($this->company->id, $this->user->id);
|
|
|
|
$e->amount = 10;
|
|
|
|
$e->date = '2022-01-01';
|
|
|
|
$e->tax_rate1 = 10;
|
|
|
|
$e->tax_name1 = 'GST';
|
|
|
|
$e->uses_inclusive_taxes = false;
|
|
|
|
$e->save();
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$expenses = $pl->getExpenses();
|
|
|
|
|
|
|
|
$expense = $expenses[0];
|
|
|
|
|
|
|
|
$this->assertEquals(10, $expense->total);
|
|
|
|
$this->assertEquals(1, $expense->tax);
|
|
|
|
|
|
|
|
$this->account->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSimpleExpenseTaxRateInclusive()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$e = ExpenseFactory::create($this->company->id, $this->user->id);
|
|
|
|
$e->amount = 10;
|
|
|
|
$e->date = '2022-01-01';
|
|
|
|
$e->tax_rate1 = 10;
|
|
|
|
$e->tax_name1 = 'GST';
|
|
|
|
$e->uses_inclusive_taxes = false;
|
|
|
|
$e->save();
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$expenses = $pl->getExpenses();
|
|
|
|
|
|
|
|
$expense = $expenses[0];
|
|
|
|
|
|
|
|
$this->assertEquals(10, $expense->total);
|
|
|
|
$this->assertEquals(1, $expense->tax);
|
|
|
|
|
|
|
|
$this->account->delete();
|
|
|
|
}
|
|
|
|
|
2022-05-13 05:07:42 +02:00
|
|
|
public function testSimpleExpenseBreakdown()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$e = Expense::factory()->create([
|
|
|
|
'amount' => 10,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'exchange_rate' => 1,
|
2022-06-21 11:57:17 +02:00
|
|
|
'currency_id' => $this->company->settings->currency_id,
|
2022-05-13 05:07:42 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$expenses = $pl->getExpenses();
|
|
|
|
|
|
|
|
$bd = $pl->getExpenseBreakDown();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertEquals(array_sum(array_column($bd, 'total')), 10);
|
2022-05-13 05:07:42 +02:00
|
|
|
|
|
|
|
$this->account->delete();
|
|
|
|
}
|
|
|
|
|
2022-05-13 06:06:21 +02:00
|
|
|
public function testSimpleExpenseCategoriesBreakdown()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$ec = ExpenseCategoryFactory::create($this->company->id, $this->user->id);
|
|
|
|
$ec->name = 'Accounting';
|
|
|
|
$ec->save();
|
|
|
|
|
|
|
|
$e = Expense::factory()->create([
|
|
|
|
'category_id' => $ec->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'exchange_rate' => 1,
|
2022-06-21 11:57:17 +02:00
|
|
|
'currency_id' => $this->company->settings->currency_id,
|
2022-05-13 06:06:21 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$ec = ExpenseCategoryFactory::create($this->company->id, $this->user->id);
|
|
|
|
$ec->name = 'Fuel';
|
|
|
|
$ec->save();
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-13 06:06:21 +02:00
|
|
|
$e = Expense::factory(2)->create([
|
|
|
|
'category_id' => $ec->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'exchange_rate' => 1,
|
2022-06-21 11:57:17 +02:00
|
|
|
'currency_id' => $this->company->settings->currency_id,
|
2022-05-13 06:06:21 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$expenses = $pl->getExpenses();
|
|
|
|
|
|
|
|
$bd = $pl->getExpenseBreakDown();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertEquals(array_sum(array_column($bd, 'total')), 30);
|
2022-05-13 08:42:04 +02:00
|
|
|
|
|
|
|
$this->account->delete();
|
|
|
|
}
|
2022-05-13 06:06:21 +02:00
|
|
|
|
2022-05-13 08:42:04 +02:00
|
|
|
public function testCsvGeneration()
|
|
|
|
{
|
|
|
|
$this->buildData();
|
|
|
|
|
|
|
|
$client = Client::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_deleted' => 0,
|
|
|
|
]);
|
2022-05-13 08:42:04 +02:00
|
|
|
|
|
|
|
Invoice::factory()->count(1)->create([
|
|
|
|
'client_id' => $client->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'balance' => 10,
|
|
|
|
'status_id' => 2,
|
|
|
|
'total_taxes' => 1,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'terms' => 'nada',
|
|
|
|
'discount' => 0,
|
|
|
|
'tax_rate1' => 10,
|
|
|
|
'tax_rate2' => 0,
|
|
|
|
'tax_rate3' => 0,
|
2022-06-21 11:57:17 +02:00
|
|
|
'tax_name1' => 'GST',
|
2022-05-13 08:42:04 +02:00
|
|
|
'tax_name2' => '',
|
|
|
|
'tax_name3' => '',
|
|
|
|
'uses_inclusive_taxes' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$ec = ExpenseCategoryFactory::create($this->company->id, $this->user->id);
|
|
|
|
$ec->name = 'Accounting';
|
|
|
|
$ec->save();
|
|
|
|
|
|
|
|
$e = Expense::factory()->create([
|
|
|
|
'category_id' => $ec->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'exchange_rate' => 1,
|
2022-06-21 11:57:17 +02:00
|
|
|
'currency_id' => $this->company->settings->currency_id,
|
2022-05-13 08:42:04 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$ec = ExpenseCategoryFactory::create($this->company->id, $this->user->id);
|
|
|
|
$ec->name = 'Fuel';
|
|
|
|
$ec->save();
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-13 08:42:04 +02:00
|
|
|
$e = Expense::factory(2)->create([
|
|
|
|
'category_id' => $ec->id,
|
|
|
|
'amount' => 10,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'date' => '2022-01-01',
|
|
|
|
'exchange_rate' => 1,
|
2022-06-21 11:57:17 +02:00
|
|
|
'currency_id' => $this->company->settings->currency_id,
|
2022-05-13 08:42:04 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$pl = new ProfitLoss($this->company, $this->payload);
|
|
|
|
$pl->build();
|
|
|
|
|
|
|
|
$this->assertNotNull($pl->getCsv());
|
2022-05-13 06:06:21 +02:00
|
|
|
|
|
|
|
$this->account->delete();
|
|
|
|
}
|
2022-05-10 12:06:40 +02:00
|
|
|
}
|