帝富尼、沐野竹木、沭阳简华家具有限公司纳入现结免上传范围。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com>
172 lines
7.1 KiB
PHP
172 lines
7.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\Repositories\SupplierStatementSettlementRepository;
|
|
use Modules\EcommerceFinance\Services\SupplierDingTalkNotifier;
|
|
use Modules\EcommerceFinance\Services\SupplierPayableOverrideStore;
|
|
use Modules\EcommerceFinance\Services\SupplierStatementReminder;
|
|
use Modules\EcommerceFinance\Services\SupplierStatementUploadEligibility;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class SupplierStatementUploadEligibilityTest extends FeatureTestCase
|
|
{
|
|
private const WEBHOOK = 'https://oapi.dingtalk.com/robot/send?access_token=statement-eligibility-test';
|
|
|
|
private string $mirrorConnection;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->company->makeCurrent();
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
$this->mirrorConnection = (string) config('upstream_mirrors.connection', 'business_mirror');
|
|
Schema::connection($this->mirrorConnection)->dropIfExists(SupplierStatementSettlementRepository::TABLE);
|
|
Schema::connection($this->mirrorConnection)->create(
|
|
SupplierStatementSettlementRepository::TABLE,
|
|
function (Blueprint $table): void {
|
|
$table->increments('id');
|
|
$table->string('Month', 20);
|
|
$table->string('supplier', 191);
|
|
$table->string('settleway', 191)->nullable();
|
|
},
|
|
);
|
|
}
|
|
|
|
public function test_classifies_latest_settlement_method_and_known_exemptions(): void
|
|
{
|
|
$this->seedSettlement('旧合同改月结', '2026-09', '订单合同');
|
|
$this->seedSettlement('旧合同改月结', '2026-10', '月结');
|
|
$this->seedSettlement('动态订单合同', '2026-10', '订单合同');
|
|
$this->seedSettlement('动态现结', '2026-10', '现结');
|
|
$this->seedSettlement('未来现结', '2026-12', '现结');
|
|
|
|
$result = app(SupplierStatementUploadEligibility::class)->classify([
|
|
'博曼特',
|
|
'帝富尼',
|
|
'动态订单合同',
|
|
'动态现结',
|
|
'旧合同改月结',
|
|
'沐野竹木',
|
|
'沭阳简华家具有限公司',
|
|
'未来现结',
|
|
], '2026-11');
|
|
|
|
$this->assertEqualsCanonicalizing([
|
|
'博曼特',
|
|
'帝富尼',
|
|
'动态订单合同',
|
|
'动态现结',
|
|
'沐野竹木',
|
|
'沭阳简华家具有限公司',
|
|
], $result['exempt']);
|
|
$this->assertSame(['旧合同改月结', '未来现结'], $result['required']);
|
|
$this->assertSame('月结', $result['settlement_methods']['旧合同改月结']);
|
|
$this->assertArrayNotHasKey('未来现结', $result['settlement_methods']);
|
|
}
|
|
|
|
public function test_reminder_skips_order_contract_cash_and_known_exempt_suppliers(): void
|
|
{
|
|
Carbon::setTestNow(Carbon::parse('2026-12-03 10:00:00', 'Asia/Shanghai'));
|
|
$this->seedSettlement('动态订单合同', '2026-10', '订单合同');
|
|
$this->seedSettlement('动态现结', '2026-10', '现结');
|
|
$this->seedSettlement('动态月结', '2026-10', '月结');
|
|
|
|
foreach (['博曼特', '动态订单合同', '动态现结', '动态月结'] as $index => $supplier) {
|
|
$this->seedSourceSupplier($supplier, 'eligibility:' . $index);
|
|
app(SupplierDingTalkNotifier::class)->save(
|
|
$supplier,
|
|
self::WEBHOOK . '-' . $index,
|
|
'',
|
|
false,
|
|
);
|
|
}
|
|
|
|
$result = app(SupplierStatementReminder::class)->send(
|
|
Carbon::parse('2026-12-03 10:00:00', 'Asia/Shanghai'),
|
|
(int) $this->company->id,
|
|
true,
|
|
'',
|
|
'10',
|
|
);
|
|
|
|
$this->assertSame(1, $result['source_suppliers']);
|
|
$this->assertSame(['动态月结'], $result['previewed']);
|
|
$this->assertEqualsCanonicalizing(['博曼特', '动态订单合同', '动态现结'], $result['exempt_suppliers']);
|
|
}
|
|
|
|
public function test_finance_overview_excludes_suppliers_without_statement_upload_requirement(): void
|
|
{
|
|
$this->seedSettlement('动态订单合同', '2026-10', '订单合同');
|
|
$this->seedSettlement('动态现结', '2026-10', '现结');
|
|
$this->seedSettlement('动态月结', '2026-10', '月结');
|
|
foreach (['博曼特', '动态订单合同', '动态现结', '动态月结'] as $index => $supplier) {
|
|
$this->seedSourceSupplier($supplier, 'overview:' . $index);
|
|
}
|
|
|
|
$response = $this->loginAs()->get(route('business.pages.show', [
|
|
'section' => 'supplier-reconciliation',
|
|
'page' => 'finance-data',
|
|
'month' => '2026-11',
|
|
]))->assertOk();
|
|
|
|
$html = (string) $response->getContent();
|
|
$this->assertStringContainsString('当月所有厂家', $html);
|
|
$this->assertStringContainsString('订单合同/现结厂家', $html);
|
|
$section = static function (string $key) use ($html): string {
|
|
preg_match(
|
|
'/<details class="sr-overview-stat [^"]*" data-overview="' . preg_quote($key, '/') . '">(.*?)<\/details>/s',
|
|
$html,
|
|
$matches,
|
|
);
|
|
|
|
return (string) ($matches[1] ?? '');
|
|
};
|
|
|
|
$this->assertStringContainsString('4 家', $section('total'));
|
|
$this->assertStringContainsString('3 家', $section('exempt'));
|
|
$this->assertStringContainsString('1 家', $section('not_uploaded'));
|
|
$this->assertStringContainsString('博曼特', $section('total'));
|
|
$this->assertStringContainsString('动态订单合同', $section('exempt'));
|
|
$this->assertStringContainsString('动态现结', $section('exempt'));
|
|
$this->assertStringContainsString('动态月结', $section('not_uploaded'));
|
|
$this->assertStringNotContainsString('博曼特', $section('not_uploaded'));
|
|
$this->assertStringNotContainsString('动态订单合同', $section('not_uploaded'));
|
|
$this->assertStringNotContainsString('动态现结', $section('not_uploaded'));
|
|
}
|
|
|
|
private function seedSettlement(string $supplier, string $month, string $method): void
|
|
{
|
|
DB::connection($this->mirrorConnection)->table(SupplierStatementSettlementRepository::TABLE)->insert([
|
|
'supplier' => $supplier,
|
|
'settleway' => $method,
|
|
'Month' => $month,
|
|
]);
|
|
}
|
|
|
|
private function seedSourceSupplier(string $supplier, string $key): void
|
|
{
|
|
app(SupplierPayableOverrideStore::class)->save(
|
|
'final:supplier:payment-reconciliation',
|
|
$key,
|
|
[
|
|
'summary_month' => '2026-11',
|
|
'date' => '2026-11-30',
|
|
'supplier' => $supplier,
|
|
'qty' => '1',
|
|
'amount' => '10',
|
|
],
|
|
(int) $this->company->id,
|
|
null,
|
|
);
|
|
}
|
|
}
|