203 lines
7.2 KiB
PHP
203 lines
7.2 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Business;
|
||
|
||
use App\Models\Auth\Permission;
|
||
use App\Models\Business\InputInvoiceReport;
|
||
use App\Models\Business\OutputInvoiceReport;
|
||
use Mockery;
|
||
use Modules\EcommerceFinance\Repositories\BusinessInformationMirrorRepository;
|
||
use Tests\Feature\FeatureTestCase;
|
||
|
||
class InvoiceReportsSummaryTest extends FeatureTestCase
|
||
{
|
||
private BusinessInformationMirrorRepository $companyInformation;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
$this->user->attachPermission(
|
||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||
);
|
||
|
||
$this->companyInformation = Mockery::mock(BusinessInformationMirrorRepository::class);
|
||
$this->companyInformation->shouldReceive('allCompaniesForClassification')
|
||
->byDefault()
|
||
->andReturn([]);
|
||
$this->app->instance(BusinessInformationMirrorRepository::class, $this->companyInformation);
|
||
}
|
||
|
||
public function test_invoice_reports_puts_summary_tab_before_input_and_output(): void
|
||
{
|
||
$page = collect(collect(config('business_navigation'))
|
||
->firstWhere('slug', 'invoice-management')['pages'])
|
||
->firstWhere('slug', 'invoice-reports');
|
||
|
||
$this->assertSame(
|
||
['summary', 'input', 'output'],
|
||
array_column($page['tabs'], 'slug')
|
||
);
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'invoice-management',
|
||
'page' => 'invoice-reports',
|
||
]))
|
||
->assertRedirect(route('business.pages.show', [
|
||
'section' => 'invoice-management',
|
||
'page' => 'invoice-reports',
|
||
'tab' => 'summary',
|
||
]));
|
||
}
|
||
|
||
public function test_summary_combines_input_and_output_reports_by_company(): void
|
||
{
|
||
$this->createReports();
|
||
|
||
$companyInformation = Mockery::mock(BusinessInformationMirrorRepository::class);
|
||
$companyInformation->shouldReceive('allCompaniesForClassification')
|
||
->once()
|
||
->andReturn([
|
||
['company_name' => '甲公司', 'taxpayer_category' => '一般纳税人'],
|
||
['company_name' => '乙公司', 'taxpayer_category' => '小规模纳税人'],
|
||
]);
|
||
$this->app->instance(BusinessInformationMirrorRepository::class, $companyInformation);
|
||
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'invoice-management',
|
||
'page' => 'invoice-reports',
|
||
'tab' => 'summary',
|
||
]))
|
||
->assertOk()
|
||
->assertSeeText('发票情况汇总')
|
||
->assertSeeText('公司')
|
||
->assertSeeText('纳税人类型')
|
||
->assertSeeText('销项金额')
|
||
->assertSeeText('销项税额')
|
||
->assertSeeText('进项金额')
|
||
->assertSeeText('进项税额')
|
||
->assertSeeText('是否预警')
|
||
->assertSeeText('全部公司')
|
||
->assertSeeText('全部类型')
|
||
->assertSeeText('甲公司')
|
||
->assertSeeText('乙公司')
|
||
->assertSeeText('一般纳税人')
|
||
->assertSeeText('小规模纳税人')
|
||
->assertSeeText('150.00')
|
||
->assertSeeText('16.00')
|
||
->assertSeeText('100.00')
|
||
->assertSeeText('10.00')
|
||
->assertSeeText('320.00')
|
||
->assertSeeText('41.60')
|
||
->assertSeeText('合计')
|
||
->assertSeeText('250.00')
|
||
->assertSeeText('26.00')
|
||
->assertSee('invoice-warning is-warning', false)
|
||
->assertSee('进项/销项 = 46.9%', false)
|
||
->assertSee('销项金额为 0,无法计算比例', false);
|
||
}
|
||
|
||
public function test_summary_filters_by_company_taxpayer_type_and_warning(): void
|
||
{
|
||
$this->createReports();
|
||
|
||
$companyInformation = Mockery::mock(BusinessInformationMirrorRepository::class);
|
||
$companyInformation->shouldReceive('allCompaniesForClassification')
|
||
->andReturn([
|
||
['company_name' => '甲公司', 'taxpayer_category' => '一般纳税人'],
|
||
['company_name' => '乙公司', 'taxpayer_category' => '小规模纳税人'],
|
||
]);
|
||
$this->app->instance(BusinessInformationMirrorRepository::class, $companyInformation);
|
||
|
||
$this->loginAs();
|
||
$url = route('business.pages.show', [
|
||
'section' => 'invoice-management',
|
||
'page' => 'invoice-reports',
|
||
'tab' => 'summary',
|
||
]);
|
||
|
||
$this->loginAs()
|
||
->get($url . '?company=' . urlencode('甲公司'))
|
||
->assertOk()
|
||
->assertSee('<option value="甲公司"', false)
|
||
->assertSeeText('150.00')
|
||
->assertDontSeeText('100.00');
|
||
|
||
$this->loginAs()
|
||
->get($url . '?taxpayer_type=' . urlencode('小规模纳税人'))
|
||
->assertOk()
|
||
->assertSeeText('100.00')
|
||
->assertDontSeeText('150.00');
|
||
|
||
$this->loginAs()
|
||
->get($url . '?warning=yes')
|
||
->assertOk()
|
||
->assertSeeText('150.00')
|
||
->assertDontSeeText('100.00');
|
||
|
||
$this->loginAs()
|
||
->get($url . '?warning=no')
|
||
->assertOk()
|
||
->assertSeeText('100.00')
|
||
->assertDontSeeText('150.00');
|
||
}
|
||
|
||
public function test_input_and_output_tabs_keep_their_detail_columns(): void
|
||
{
|
||
$this->createReports();
|
||
|
||
foreach (['input' => '进项报表', 'output' => '销项报表'] as $tab => $title) {
|
||
$this->loginAs()
|
||
->get(route('business.pages.show', [
|
||
'section' => 'invoice-management',
|
||
'page' => 'invoice-reports',
|
||
'tab' => $tab,
|
||
]))
|
||
->assertOk()
|
||
->assertSeeText($title)
|
||
->assertSeeText('公司名称')
|
||
->assertSeeText('商品金额')
|
||
->assertSeeText('服务费税额')
|
||
->assertSeeText('税额合计');
|
||
}
|
||
}
|
||
|
||
private function createReports(): void
|
||
{
|
||
InputInvoiceReport::create([
|
||
'company_id' => $this->company->id,
|
||
'company_name' => '甲公司',
|
||
'input_goods_amount' => 100,
|
||
'input_goods_tax' => 13,
|
||
'input_service_amount' => 50,
|
||
'input_service_tax' => 3,
|
||
'input_total_amount' => 150,
|
||
'input_total_tax' => 16,
|
||
]);
|
||
|
||
InputInvoiceReport::create([
|
||
'company_id' => $this->company->id,
|
||
'company_name' => '乙公司',
|
||
'input_goods_amount' => 80,
|
||
'input_goods_tax' => 8,
|
||
'input_service_amount' => 20,
|
||
'input_service_tax' => 2,
|
||
'input_total_amount' => 100,
|
||
'input_total_tax' => 10,
|
||
]);
|
||
|
||
OutputInvoiceReport::create([
|
||
'company_id' => $this->company->id,
|
||
'company_name' => '甲公司',
|
||
'output_goods_amount' => 200,
|
||
'output_goods_tax' => 26,
|
||
'output_service_amount' => 120,
|
||
'output_service_tax' => 15.6,
|
||
'output_total_amount' => 320,
|
||
'output_total_tax' => 41.6,
|
||
]);
|
||
}
|
||
}
|