90 lines
3.0 KiB
PHP
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_seven_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-17',
|
|
'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(7, $result['rows'][0]['dateToleranceDays']);
|
|
$this->assertStringContainsString('日期相差 7 天', $result['rows'][0]['note']);
|
|
}
|
|
|
|
public function test_date_difference_over_seven_days_remains_a_difference(): void
|
|
{
|
|
$mine = [[
|
|
'purchaseNo' => '879735',
|
|
'date' => '2026-09-10',
|
|
'skuCode' => 'DNZ033609',
|
|
'qty' => '20',
|
|
'amount' => '2000',
|
|
]];
|
|
$theirs = [[
|
|
'purchaseNo' => '879735',
|
|
'createdAt' => '2026-09-18',
|
|
'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']);
|
|
}
|
|
}
|