109 lines
3.7 KiB
PHP
109 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use App\Models\Business\InvoiceBasic;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class InvoiceQuotaPageTest extends FeatureTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$this->createInvoiceBasic('甲公司', '甲店铺组', 10000, 8500, '2026-11');
|
|
$this->createInvoiceBasic('乙公司', '乙店铺', 2000, 2500, '2026-11');
|
|
$this->createInvoiceBasic('丙公司', '丙店铺', 5000, 1000, '2026-11');
|
|
$this->createInvoiceBasic('零额度公司', '零额度店铺', 0, 0, '2026-11');
|
|
$this->createInvoiceBasic('历史公司', '历史店铺', 100, 100, '2026-10');
|
|
}
|
|
|
|
public function test_invoice_quota_is_listed_after_invoice_basic_information(): void
|
|
{
|
|
$pages = collect(config('business_navigation'))
|
|
->firstWhere('slug', 'invoice-management')['pages'];
|
|
|
|
$this->assertSame(
|
|
['automatic-invoicing', 'basic-information', 'invoice-quota', 'invoice-reports', 'store-backend-invoicing'],
|
|
array_column($pages, 'slug')
|
|
);
|
|
}
|
|
|
|
public function test_invoice_quota_defaults_to_latest_period_and_shows_usage_summary(): void
|
|
{
|
|
$this->loginAs()
|
|
->get($this->pageUrl())
|
|
->assertOk()
|
|
->assertSeeText('发票额度')
|
|
->assertSeeText('当前开票额度')
|
|
->assertSeeText('17,000.00')
|
|
->assertSeeText('12,000.00')
|
|
->assertSeeText('5,000.00')
|
|
->assertSeeText('甲公司')
|
|
->assertSeeText('8,500.00')
|
|
->assertSeeText('1,500.00')
|
|
->assertSeeText('85.0%')
|
|
->assertSeeText('乙公司')
|
|
->assertSeeText('-500.00')
|
|
->assertSeeText('超额')
|
|
->assertSeeText('需关注')
|
|
->assertSeeText('未设置额度')
|
|
->assertSeeText('超额 1 · 需关注 1')
|
|
->assertDontSeeText('历史公司')
|
|
->assertSee('<option value="2026-11" selected>', false);
|
|
}
|
|
|
|
public function test_invoice_quota_filters_by_period_and_seller_entity(): void
|
|
{
|
|
$this->loginAs()
|
|
->get($this->pageUrl(['seller_entity' => '甲公司']))
|
|
->assertOk()
|
|
->assertSeeText('甲公司')
|
|
->assertSeeText('10,000.00')
|
|
->assertSeeText('8,500.00')
|
|
->assertDontSeeText('乙公司')
|
|
->assertDontSeeText('丙公司');
|
|
|
|
$this->loginAs()
|
|
->get($this->pageUrl(['period' => '2026-10']))
|
|
->assertOk()
|
|
->assertSeeText('历史公司')
|
|
->assertDontSeeText('甲公司')
|
|
->assertSee('<option value="2026-10" selected>', false);
|
|
}
|
|
|
|
private function createInvoiceBasic(
|
|
string $entity,
|
|
string $storeName,
|
|
float $invoiceLimit,
|
|
float $outputAmount,
|
|
string $period
|
|
): void {
|
|
InvoiceBasic::create([
|
|
'company_id' => $this->company->id,
|
|
'store_name' => $storeName,
|
|
'store_entity' => $entity,
|
|
'invoice_issuer' => $entity . '开票员',
|
|
'invoice_limit' => $invoiceLimit,
|
|
'output_amount' => $outputAmount,
|
|
'input_amount' => 0,
|
|
'period' => $period,
|
|
]);
|
|
}
|
|
|
|
private function pageUrl(array $query = []): string
|
|
{
|
|
$url = route('business.pages.show', [
|
|
'section' => 'invoice-management',
|
|
'page' => 'invoice-quota',
|
|
]);
|
|
|
|
return $query === [] ? $url : $url . '?' . http_build_query($query);
|
|
}
|
|
}
|