mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 07:02:34 +01:00
204 lines
5.2 KiB
PHP
204 lines
5.2 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace Tests\Feature\Export;
|
|
|
|
use Tests\TestCase;
|
|
use App\Models\User;
|
|
use App\Models\Client;
|
|
use App\Models\Account;
|
|
use App\Models\Company;
|
|
use App\Models\Invoice;
|
|
use App\Utils\Traits\MakesHash;
|
|
use App\DataMapper\CompanySettings;
|
|
use App\Factory\InvoiceItemFactory;
|
|
use App\Services\Report\ClientSalesReport;
|
|
use App\Services\Report\ClientBalanceReport;
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
class ClientSalesReportTest extends TestCase
|
|
{
|
|
use MakesHash;
|
|
|
|
public $faker;
|
|
|
|
protected function setUp() :void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
$this->withoutMiddleware(
|
|
ThrottleRequests::class
|
|
);
|
|
|
|
$this->withoutExceptionHandling();
|
|
}
|
|
|
|
public $company;
|
|
|
|
public $user;
|
|
|
|
public $payload;
|
|
|
|
public $account;
|
|
|
|
public $client;
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
private function buildData()
|
|
{
|
|
$this->account = Account::factory()->create([
|
|
'hosted_client_count' => 1000,
|
|
'hosted_company_count' => 1000,
|
|
]);
|
|
|
|
$this->account->num_users = 3;
|
|
$this->account->save();
|
|
|
|
$this->user = User::factory()->create([
|
|
'account_id' => $this->account->id,
|
|
'confirmation_code' => 'xyz123',
|
|
'email' => $this->faker->unique()->safeEmail(),
|
|
]);
|
|
|
|
$settings = CompanySettings::defaults();
|
|
$settings->client_online_payment_notification = false;
|
|
$settings->client_manual_payment_notification = false;
|
|
|
|
$this->company = Company::factory()->create([
|
|
'account_id' => $this->account->id,
|
|
'settings' => $settings,
|
|
]);
|
|
|
|
$this->company->settings = $settings;
|
|
$this->company->save();
|
|
|
|
$this->payload = [
|
|
'start_date' => '2000-01-01',
|
|
'end_date' => '2030-01-11',
|
|
'date_range' => 'custom',
|
|
'is_income_billed' => true,
|
|
'include_tax' => false,
|
|
];
|
|
|
|
$this->client = Client::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'company_id' => $this->company->id,
|
|
'is_deleted' => 0,
|
|
]);
|
|
}
|
|
|
|
public function testUserSalesInstance()
|
|
{
|
|
$this->buildData();
|
|
|
|
$pl = new ClientSalesReport($this->company, $this->payload);
|
|
|
|
$this->assertInstanceOf(ClientSalesReport::class, $pl);
|
|
|
|
$this->account->delete();
|
|
}
|
|
|
|
public function testSimpleReport()
|
|
{
|
|
$this->buildData();
|
|
|
|
|
|
$this->payload = [
|
|
'start_date' => '2000-01-01',
|
|
'end_date' => '2030-01-11',
|
|
'date_range' => 'custom',
|
|
'client_id' => $this->client->id,
|
|
'report_keys' => []
|
|
];
|
|
|
|
$i = Invoice::factory()->create([
|
|
'client_id' => $this->client->id,
|
|
'user_id' => $this->user->id,
|
|
'company_id' => $this->company->id,
|
|
'amount' => 0,
|
|
'balance' => 0,
|
|
'status_id' => 2,
|
|
'total_taxes' => 1,
|
|
'date' => now()->format('Y-m-d'),
|
|
'terms' => 'nada',
|
|
'discount' => 0,
|
|
'tax_rate1' => 0,
|
|
'tax_rate2' => 0,
|
|
'tax_rate3' => 0,
|
|
'tax_name1' => '',
|
|
'tax_name2' => '',
|
|
'tax_name3' => '',
|
|
'uses_inclusive_taxes' => false,
|
|
'line_items' => $this->buildLineItems(),
|
|
]);
|
|
|
|
$i = $i->calc()->getInvoice();
|
|
|
|
$pl = new ClientSalesReport($this->company, $this->payload);
|
|
$response = $pl->run();
|
|
|
|
$this->assertIsString($response);
|
|
|
|
$this->account->delete();
|
|
}
|
|
|
|
|
|
private function buildLineItems()
|
|
{
|
|
$line_items = [];
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
$item->quantity = 1;
|
|
$item->cost = 10;
|
|
$item->product_key = 'test';
|
|
$item->notes = 'test_product';
|
|
// $item->task_id = $this->encodePrimaryKey($this->task->id);
|
|
// $item->expense_id = $this->encodePrimaryKey($this->expense->id);
|
|
|
|
$line_items[] = $item;
|
|
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
$item->quantity = 1;
|
|
$item->cost = 10;
|
|
$item->product_key = 'pumpkin';
|
|
$item->notes = 'test_pumpkin';
|
|
// $item->task_id = $this->encodePrimaryKey($this->task->id);
|
|
// $item->expense_id = $this->encodePrimaryKey($this->expense->id);
|
|
|
|
$line_items[] = $item;
|
|
|
|
|
|
return $line_items;
|
|
}
|
|
}
|