配件运费扣除明细:支持财务确认单号免扣 #1789

Open
limeng wants to merge 1 commits from fix/limeng-accessory-freight-exclusions into main
2 changed files with 48 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Modules\EcommerceFinance\View;
use App\Support\CourierBills\Waybill;
use Illuminate\Pagination\LengthAwarePaginator;
use Modules\EcommerceFinance\Repositories\SupplierAccessoryFreightRepository;
use Modules\EcommerceFinance\Services\SupplierAccessoryFreightMatcher;
@ -42,7 +43,16 @@ class SupplierAccessoryFreightPageData
public function rows(array $filters): \Generator
{
$excludedWaybills = setting('supplier_accessory_freight.excluded_waybills', []);
$excludedWaybills = is_array($excludedWaybills) ? $excludedWaybills : [];
foreach ($this->repository->rows($filters['month']) as $row) {
$waybill = Waybill::normalize((string) ($row['express_no'] ?? ''));
$reason = $waybill === null ? null : ($excludedWaybills[$waybill] ?? null);
if (is_string($reason) && trim($reason) !== '') {
$row['state'] = 'excluded';
$row['deduction_cents'] = 0;
$row['reason'] = '财务确认不扣款:' . trim($reason);
}
foreach (self::TEXT_FILTERS as $key => $label) {
if (($filters[$key] ?? '') !== '' && mb_stripos((string) ($row[$key] ?? ''), $filters[$key]) === false) continue 2;
}

View File

@ -32,6 +32,7 @@ class SupplierAccessoryFreightTest extends TestCase
{
$app = new Application(dirname(__DIR__, 2));
$app->instance('config', new Repository(['app' => ['platform_timezone' => 'Asia/Shanghai']]));
$app->instance('setting', new \Akaunting\Setting\Drivers\Memory);
$db = new Manager($app);
$db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']);
$db->setEventDispatcher(new \Illuminate\Events\Dispatcher($app));
@ -314,6 +315,43 @@ class SupplierAccessoryFreightTest extends TestCase
$this->assertSame(['DROPSHIP-1', '代发', '0.00', '代发厂家配置匹配「工厂-河北浩浦代发仓」,不扣配件运费'], array_slice(str_getcsv($lines[2]), 3));
}
public function test_finance_exclusions_zero_deductions_in_summary_filters_and_export(): void
{
setting()->set('supplier_accessory_freight.excluded_waybills', [
'EXEMPT-100' => '不属于应扣款项', 'EXEMPT-200' => '不属于应扣款项',
]);
$repository = Mockery::mock(SupplierAccessoryFreightRepository::class);
$repository->shouldReceive('rows')->with('2026-09')->andReturnUsing(function () {
foreach (['EXEMPT-100', " 'exempt-200 ", 'EXEMPT-1000', 'OTHER-300'] as $waybill) {
yield (new SupplierAccessoryFreightMatcher)->match($this->row(['express_no' => $waybill]),
[['name' => '成品', 'supplier_name' => '供应商甲']], [['linkerprovience' => '河北']], [], null, true);
}
});
$data = new SupplierAccessoryFreightPageData($repository);
app()->instance('request', Request::create('/?month=2026-09&state=ready'));
$page = $data->page();
$this->assertSame(['all' => 4, 'ready' => 2, 'excluded' => 2, 'pending' => 0, 'amount' => 2470], $page['freightSummary']);
$this->assertSame(['EXEMPT-1000', 'OTHER-300'], array_column($page['freightRows']->items(), 'express_no'));
$controller = new \App\Http\Controllers\Business\SupplierAccessoryFreight;
$response = $controller->export($data);
ob_start(); $response->sendContent(); $csv = ob_get_clean();
$this->assertSame(3, substr_count($csv, "\n"));
$this->assertStringNotContainsString(',EXEMPT-100,', $csv);
$this->assertStringContainsString('EXEMPT-1000', $csv);
app()->instance('request', Request::create('/?month=2026-09&state=excluded&columns=express_no,deduction,reason'));
$excluded = $data->page();
$this->assertCount(2, $excluded['freightRows']);
foreach ($excluded['freightRows'] as $row) {
$this->assertSame(0, $row['deduction_cents']);
$this->assertSame(1235, $row['freight_cents']);
$this->assertSame('供应商甲', $row['supplier_name']);
$this->assertSame('财务确认不扣款:不属于应扣款项', $row['reason']);
}
$response = $controller->export($data);
ob_start(); $response->sendContent(); $csv = ob_get_clean();
$this->assertSame(2, substr_count($csv, ',0.00,财务确认不扣款:不属于应扣款项'));
}
public function test_unready_courier_mirror_does_not_produce_deductions(): void
{
$registry = Mockery::mock(BusinessMirrorDatasetRegistry::class);