CaiWuXiTong/tests/Unit/EcommerceFinance/SupplierStatementMatcherTest.php
苏木 6e054e4e8a fix: 供应商对账支持日期两天容差匹配 (#845)
严格匹配未命中时,同采购单号、同商品编码且数量金额一致、日期相差不超过 2 天,按一致处理。
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
2026-11-04 09:17:18 +08:00

90 lines
3.0 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use Modules\EcommerceFinance\Services\SupplierStatementMatcher;
use Tests\TestCase;
class SupplierStatementMatcherTest extends TestCase
{
public function test_two_day_date_difference_matches_when_purchase_barcode_quantity_and_amount_match(): void
{
$mine = [[
'purchaseNo' => '879735',
'date' => '2026-09-10',
'skuCode' => 'DNZ033609',
'productCode' => 'DNZ033609N1178V01',
'unitPrice' => '100',
'qty' => '20',
'amount' => '2000',
]];
$theirs = [[
'purchaseNo' => '879735',
'createdAt' => '2026-09-12',
'barcode' => 'DNZ033609N1097V01',
'unitPrice' => '100',
'qty' => '20',
'amount' => '2000',
]];
$result = (new SupplierStatementMatcher())->compare($mine, $theirs);
$this->assertSame(1, $result['summary']['match']);
$this->assertSame(0, $result['summary']['supplierExtra']);
$this->assertSame(0, $result['summary']['supplierMissing']);
$this->assertSame(0, $result['summary']['mismatch']);
$this->assertSame(0.0, $result['summary']['differenceAmount']);
$this->assertSame(2000.0, $result['summary']['settleAmount']);
$this->assertSame(2, $result['rows'][0]['dateToleranceDays']);
$this->assertStringContainsString('日期相差 2 天', $result['rows'][0]['note']);
}
public function test_date_difference_over_two_days_remains_a_difference(): void
{
$mine = [[
'purchaseNo' => '879735',
'date' => '2026-09-10',
'skuCode' => 'DNZ033609',
'qty' => '20',
'amount' => '2000',
]];
$theirs = [[
'purchaseNo' => '879735',
'createdAt' => '2026-09-13',
'barcode' => 'DNZ033609N1097V01',
'qty' => '20',
'amount' => '2000',
]];
$result = (new SupplierStatementMatcher())->compare($mine, $theirs);
$this->assertSame(0, $result['summary']['match']);
$this->assertSame(1, $result['summary']['supplierExtra']);
$this->assertSame(1, $result['summary']['supplierMissing']);
}
public function test_date_tolerance_still_requires_equal_quantity_and_amount(): void
{
$mine = [[
'purchaseNo' => '879735',
'date' => '2026-09-10',
'skuCode' => 'DNZ033609',
'qty' => '20',
'amount' => '2000',
]];
$theirs = [[
'purchaseNo' => '879735',
'createdAt' => '2026-09-12',
'barcode' => 'DNZ033609N1097V01',
'qty' => '19',
'amount' => '1900',
]];
$result = (new SupplierStatementMatcher())->compare($mine, $theirs);
$this->assertSame(0, $result['summary']['match']);
$this->assertSame(1, $result['summary']['supplierExtra']);
$this->assertSame(1, $result['summary']['supplierMissing']);
}
}