fix(供应商门户): 仅展示上月退货明细 #1649
@ -110,9 +110,10 @@ class SupplierReconciliation extends Controller
|
||||
public function confirmAllReturns(Request $request): RedirectResponse
|
||||
{
|
||||
[, $supplier, $companyId] = $this->supplierContext();
|
||||
$month = $this->pageData->accountingMonthKey();
|
||||
$keys = array_values(array_map(
|
||||
static fn (array $row): string => (string) ($row['_action_key'] ?? ''),
|
||||
$this->pageData->returnRowsForFilters($supplier, $companyId, $request->all()),
|
||||
$this->pageData->returnRowsForFilters($supplier, $companyId, $request->all(), $month),
|
||||
));
|
||||
$confirmed = $this->returnConfirmations->confirmAll(
|
||||
$supplier,
|
||||
@ -127,7 +128,12 @@ class SupplierReconciliation extends Controller
|
||||
public function exportReturns(Request $request): StreamedResponse
|
||||
{
|
||||
[, $supplier, $companyId] = $this->supplierContext();
|
||||
$rows = $this->pageData->returnRowsForFilters($supplier, $companyId, $request->query());
|
||||
$rows = $this->pageData->returnRowsForFilters(
|
||||
$supplier,
|
||||
$companyId,
|
||||
$request->query(),
|
||||
$this->pageData->accountingMonthKey(),
|
||||
);
|
||||
|
||||
return $this->returnCsvExporter->download($rows, $supplier);
|
||||
}
|
||||
@ -137,7 +143,11 @@ class SupplierReconciliation extends Controller
|
||||
$request->validate(['key' => ['required', 'string', 'max:191']]);
|
||||
[, $supplier, $companyId] = $this->supplierContext();
|
||||
$key = (string) $request->input('key');
|
||||
$owned = collect($this->pageData->returnRows($supplier, $companyId))
|
||||
$owned = collect($this->pageData->returnRowsForMonth(
|
||||
$supplier,
|
||||
$companyId,
|
||||
$this->pageData->accountingMonthKey(),
|
||||
))
|
||||
->contains(static fn (array $row): bool => (string) ($row['_action_key'] ?? '') === $key);
|
||||
abort_unless($owned, 403, '该退货明细不属于当前厂家账号。');
|
||||
|
||||
|
||||
@ -381,9 +381,15 @@ class SupplierReconciliationPageData
|
||||
*/
|
||||
public function portalData(string $supplier, int $companyId): array
|
||||
{
|
||||
$periodContext = $this->vendorPeriodContext();
|
||||
$page = max((int) request()->query('rows_page', 1), 1);
|
||||
$statementPage = $this->statements->paginate($supplier, $companyId, self::PER_PAGE, $page);
|
||||
$returnData = $this->returnPanelData($supplier, $companyId, request()->query());
|
||||
$returnData = $this->returnPanelData(
|
||||
$supplier,
|
||||
$companyId,
|
||||
request()->query(),
|
||||
$periodContext['accountingMonthKey'],
|
||||
);
|
||||
|
||||
return [
|
||||
'statementRows' => $statementPage['rows'],
|
||||
@ -393,7 +399,12 @@ class SupplierReconciliationPageData
|
||||
'returnWarehouses' => $returnData['returnWarehouses'],
|
||||
'rowsPage' => $page,
|
||||
'perPage' => self::PER_PAGE,
|
||||
] + $this->vendorPeriodContext();
|
||||
] + $periodContext;
|
||||
}
|
||||
|
||||
public function accountingMonthKey(): string
|
||||
{
|
||||
return $this->vendorPeriodContext()['accountingMonthKey'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -496,11 +507,20 @@ class SupplierReconciliationPageData
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $input
|
||||
* @param string|null $restrictMonth 厂家端只允许指定账期,避免加载历史月份
|
||||
* @return array{returnPanel:array<string,mixed>,returnWarehouses:list<string>}
|
||||
*/
|
||||
private function returnPanelData(string $supplier, int $companyId, array $input): array
|
||||
private function returnPanelData(
|
||||
string $supplier,
|
||||
int $companyId,
|
||||
array $input,
|
||||
?string $restrictMonth = null,
|
||||
): array
|
||||
{
|
||||
$allReturnRows = $this->returnRows($supplier, $companyId);
|
||||
$restrictMonth = trim((string) $restrictMonth);
|
||||
$allReturnRows = $restrictMonth !== ''
|
||||
? $this->returnRowsForMonth($supplier, $companyId, $restrictMonth)
|
||||
: $this->returnRows($supplier, $companyId);
|
||||
$returnWarehouses = [];
|
||||
foreach ($allReturnRows as $row) {
|
||||
$warehouse = $this->filterText($row['warehouse'] ?? '');
|
||||
@ -511,7 +531,9 @@ class SupplierReconciliationPageData
|
||||
$returnWarehouses = array_keys($returnWarehouses);
|
||||
sort($returnWarehouses, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
|
||||
$filters = $this->returnFilters($input);
|
||||
$filters = $this->returnFilters(
|
||||
$this->returnInputForMonth($input, $restrictMonth),
|
||||
);
|
||||
$returnRows = $this->filterReturnRows(
|
||||
$allReturnRows,
|
||||
$filters,
|
||||
@ -1140,15 +1162,37 @@ class SupplierReconciliationPageData
|
||||
* @param array<string,mixed> $input
|
||||
* @return list<array<string,mixed>>
|
||||
*/
|
||||
public function returnRowsForFilters(string $supplier, int $companyId, array $input): array
|
||||
public function returnRowsForFilters(
|
||||
string $supplier,
|
||||
int $companyId,
|
||||
array $input,
|
||||
?string $restrictMonth = null,
|
||||
): array
|
||||
{
|
||||
$restrictMonth = trim((string) $restrictMonth);
|
||||
return $this->filterReturnRows(
|
||||
$this->returnRows($supplier, $companyId),
|
||||
$this->returnFilters($input),
|
||||
$restrictMonth !== ''
|
||||
? $this->returnRowsForMonth($supplier, $companyId, $restrictMonth)
|
||||
: $this->returnRows($supplier, $companyId),
|
||||
$this->returnFilters($this->returnInputForMonth($input, $restrictMonth)),
|
||||
$this->returnConfirmations->statuses($supplier, $companyId),
|
||||
);
|
||||
}
|
||||
|
||||
private function returnInputForMonth(array $input, string $month): array
|
||||
{
|
||||
if (preg_match('/^\d{4}-\d{2}$/', $month) !== 1) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
$start = \Illuminate\Support\Carbon::createFromFormat('!Y-m', $month, 'Asia/Shanghai')
|
||||
->startOfMonth();
|
||||
$input['return_date_from'] = $start->toDateString();
|
||||
$input['return_date_to'] = $start->copy()->endOfMonth()->toDateString();
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析厂家退货查询条件,空值会被忽略。
|
||||
*
|
||||
|
||||
@ -460,7 +460,7 @@
|
||||
<div class="sp-hero-copy">
|
||||
<span class="sp-eyebrow">SUPPLIER RECONCILIATION</span>
|
||||
<h2 id="supplier-reconciliation-title">{{ $supplier }} · 厂家对账</h2>
|
||||
<p>仅展示当前账号绑定厂家的上传数据与退货明细。先上传对账单,再核对退货扣减并提交确认或异议。</p>
|
||||
<p>仅展示当前账号绑定厂家的上传数据与上月退货明细;历史月份数据请及时导出保存。先上传对账单,再核对退货扣减并提交确认或异议。</p>
|
||||
</div>
|
||||
<div class="sp-context" aria-label="当前对账信息">
|
||||
<div class="sp-context-item"><span>当前厂家</span><strong>{{ $supplier }}</strong></div>
|
||||
@ -636,7 +636,7 @@
|
||||
<div class="sp-panel-head">
|
||||
<div>
|
||||
<h3 class="sp-title" id="sp-return-title"><span class="sp-title-number">2</span>退货扣减确认</h3>
|
||||
<p class="sp-caption">查看本厂家全部退货数据。系统只记录你的确认或异议,不会代替厂家点击确认。</p>
|
||||
<p class="sp-caption">查看本厂家上月退货数据。系统只记录你的确认或异议,不会代替厂家点击确认。</p>
|
||||
</div>
|
||||
<div class="sp-return-head-actions">
|
||||
<div class="sp-return-head-row">
|
||||
|
||||
@ -13,6 +13,7 @@ use App\Models\Common\Contact;
|
||||
use App\Services\Auth\SupplierPortalAccess;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@ -1473,6 +1474,7 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
|
||||
public function test_supplier_portal_upload_and_return_actions_ignore_spoofed_supplier(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-10-02 10:00:00', 'Asia/Shanghai'));
|
||||
$supplierUser = $this->createSupplierPortalUser('晨丰');
|
||||
$file = UploadedFile::fake()->createWithContent(
|
||||
'statement.csv',
|
||||
@ -1528,6 +1530,7 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
|
||||
$this->assertCount(1, app(SupplierStatementStore::class)->rows('晨丰', $companyId));
|
||||
$this->assertCount(0, app(SupplierStatementStore::class)->rows('鸣飞家具', $companyId));
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
|
||||
public function test_supplier_statement_upload_sends_a_dingtalk_receipt(): void
|
||||
@ -1646,8 +1649,9 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_vendor_portal_shows_only_all_returns_for_the_logged_in_supplier(): void
|
||||
public function test_vendor_portal_shows_only_previous_month_returns_for_the_logged_in_supplier(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-12-02 10:00:00', 'Asia/Shanghai'));
|
||||
$store = app(SupplierPayableOverrideStore::class);
|
||||
$companyId = (int) $this->company->id;
|
||||
$this->seedStatement('鸣飞家具', [
|
||||
@ -1655,8 +1659,8 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
]);
|
||||
for ($i = 1; $i <= 20; $i++) {
|
||||
$store->save('final:supplier:return-reconciliation', sprintf('portal:%02d', $i), [
|
||||
'summary_month' => '2026-09',
|
||||
'send_time' => '2026-09-20',
|
||||
'summary_month' => '2026-11',
|
||||
'send_time' => '2026-11-20',
|
||||
'supplier' => '晨丰',
|
||||
'barcode' => sprintf('PORTAL-%02d', $i),
|
||||
'sku_name' => '门户退货商品',
|
||||
@ -1665,9 +1669,19 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
'amount' => '100',
|
||||
], $companyId, null);
|
||||
}
|
||||
$store->save('final:supplier:return-reconciliation', 'portal:old-month', [
|
||||
'summary_month' => '2026-10',
|
||||
'send_time' => '2026-10-20',
|
||||
'supplier' => '晨丰',
|
||||
'barcode' => 'PORTAL-OLD-MONTH',
|
||||
'sku_name' => '历史月份退货',
|
||||
'qty' => '1',
|
||||
'unit_price' => '100',
|
||||
'amount' => '100',
|
||||
], $companyId, null);
|
||||
$store->save('final:supplier:return-reconciliation', 'portal:other', [
|
||||
'summary_month' => '2026-09',
|
||||
'send_time' => '2026-09-20',
|
||||
'summary_month' => '2026-11',
|
||||
'send_time' => '2026-11-20',
|
||||
'supplier' => '鸣飞家具',
|
||||
'barcode' => 'OTHER-SUPPLIER-RETURN',
|
||||
'qty' => '1',
|
||||
@ -1677,6 +1691,14 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
|
||||
$vendor = $this->createVendorPortalUser('晨丰');
|
||||
$portalUrl = route('portal.supplier-reconciliation.index', ['company_id' => $companyId]);
|
||||
$datasetQueries = [];
|
||||
DB::connection(config('database.supplier_payable_maintenance_connection'))
|
||||
->listen(function ($query) use (&$datasetQueries): void {
|
||||
if (str_contains($query->sql, 'supplier_payable_overrides')
|
||||
&& in_array('final:supplier:return-reconciliation', $query->bindings, true)) {
|
||||
$datasetQueries[] = $query->sql;
|
||||
}
|
||||
});
|
||||
|
||||
$this->post(route('login'), [
|
||||
'email' => $vendor->email,
|
||||
@ -1691,12 +1713,13 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
->assertSeeText('晨丰 · 厂家对账')
|
||||
->assertSeeText('上传并校验')
|
||||
->assertSeeText('退货扣减确认')
|
||||
->assertSeeText('查看本厂家全部退货数据')
|
||||
->assertSeeText('查看本厂家上月退货数据')
|
||||
->assertSeeText('导出当前筛选')
|
||||
->assertDontSeeText('本期处理进度')
|
||||
->assertDontSeeText('钉钉最终提醒话术')
|
||||
->assertSeeText('PORTAL-01')
|
||||
->assertDontSeeText('PORTAL-20')
|
||||
->assertDontSeeText('PORTAL-OLD-MONTH')
|
||||
->assertDontSeeText('OTHER-SUPPLIER-RETURN')
|
||||
->assertDontSeeText('鸣飞家具')
|
||||
->assertDontSeeText('最近上传')
|
||||
@ -1708,12 +1731,19 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
->assertSee('name="return_warehouse"', false)
|
||||
->assertSee('name="return_status"', false)
|
||||
->assertDontSeeText('预估单价');
|
||||
$this->assertNotEmpty($datasetQueries);
|
||||
foreach ($datasetQueries as $sql) {
|
||||
$this->assertMatchesRegularExpression('/supplier_name_key|json_extract\\([^)]*supplier/i', $sql);
|
||||
$this->assertMatchesRegularExpression('/summary_month|send_time/i', $sql);
|
||||
}
|
||||
|
||||
$this->loginAs($vendor)->get($portalUrl . '?return_page=2')
|
||||
->assertOk()
|
||||
->assertSeeText('PORTAL-20')
|
||||
->assertDontSeeText('PORTAL-01')
|
||||
->assertDontSeeText('OTHER-SUPPLIER-RETURN');
|
||||
->assertDontSeeText('OTHER-SUPPLIER-RETURN')
|
||||
->assertDontSeeText('PORTAL-OLD-MONTH');
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
|
||||
public function test_vendor_portal_shows_previous_month_period_and_confirmation_deadlines(): void
|
||||
@ -1754,6 +1784,7 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
|
||||
public function test_vendor_portal_export_and_confirmation_are_scoped_to_the_bound_supplier(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-10-02 10:00:00', 'Asia/Shanghai'));
|
||||
$this->withExceptionHandling();
|
||||
$store = app(SupplierPayableOverrideStore::class);
|
||||
$companyId = (int) $this->company->id;
|
||||
@ -1795,6 +1826,7 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
->statuses('晨丰', $companyId);
|
||||
$this->assertSame('confirmed', $statuses['portal:own']);
|
||||
$this->assertArrayNotHasKey('portal:foreign', $statuses);
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
|
||||
public function test_vendor_portal_upload_always_uses_the_bound_supplier(): void
|
||||
@ -1842,6 +1874,7 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
|
||||
public function test_return_bookkeeping_note_is_identical_on_finance_and_supplier_views(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-10-02 10:00:00', 'Asia/Shanghai'));
|
||||
$companyId = (int) $this->company->id;
|
||||
app(SupplierPayableOverrideStore::class)->save(
|
||||
'final:supplier:payment-reconciliation',
|
||||
@ -1913,6 +1946,7 @@ class SupplierReconciliationTest extends FeatureTestCase
|
||||
->assertSeeText('转物流记账')
|
||||
->assertSeeText('不扣本厂家,转常州松宇货运记账')
|
||||
->assertSeeText('原数量2件,CZ008407N1178V01*1记账物流');
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
|
||||
public function test_statement_rows_are_paginated_fifteen_per_page(): void
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user