feat: 增加供应商合作合同到期提醒
This commit is contained in:
parent
99e94f7939
commit
959aafb005
@ -22,7 +22,7 @@ class CourierContractPageData
|
||||
'unknown' => '期限待核对',
|
||||
];
|
||||
|
||||
public function page(bool $includeRows = true): array
|
||||
public function page(bool $includeRows = true, string $partnerType = 'courier'): array
|
||||
{
|
||||
$search = mb_substr(trim((string) request()->query('contract_search', '')), 0, 255);
|
||||
$status = (string) request()->query('contract_status', '');
|
||||
@ -61,7 +61,7 @@ class CourierContractPageData
|
||||
'signed_pdf_path', 'certificate_path', 'archived_at', 'created_by', 'created_at'])
|
||||
->lazyById(250);
|
||||
foreach ($signatures as $signature) {
|
||||
$payload = $signature->archivedCourierContractPayload();
|
||||
$payload = $signature->archivedContractPayload($partnerType);
|
||||
if ($payload === null) {
|
||||
try {
|
||||
$signature->payload;
|
||||
|
||||
@ -11,9 +11,19 @@ class CourierContracts extends Controller
|
||||
{
|
||||
/** A read-only archive entry point with courier-information page access, not signing-management access. */
|
||||
public function download(CourierAgreementSignature $agreementSignature, string $kind): StreamedResponse
|
||||
{
|
||||
return $this->serveFile($agreementSignature, $kind, 'courier');
|
||||
}
|
||||
|
||||
public function downloadSupplier(CourierAgreementSignature $agreementSignature, string $kind): StreamedResponse
|
||||
{
|
||||
return $this->serveFile($agreementSignature, $kind, 'supplier');
|
||||
}
|
||||
|
||||
private function serveFile(CourierAgreementSignature $agreementSignature, string $kind, string $partnerType): StreamedResponse
|
||||
{
|
||||
abort_unless($agreementSignature->company_id === (int) company_id()
|
||||
&& $agreementSignature->archivedCourierContractPayload() !== null, 404);
|
||||
&& $agreementSignature->archivedContractPayload($partnerType) !== null, 404);
|
||||
$path = match ($kind) {
|
||||
'signed' => $agreementSignature->signed_pdf_path,
|
||||
'certificate' => $agreementSignature->certificate_path,
|
||||
|
||||
@ -5439,6 +5439,17 @@ class Pages extends Controller
|
||||
return $this->resolveContent($page, $tab);
|
||||
}
|
||||
|
||||
protected function contentForSupplierManagement(): array
|
||||
{
|
||||
$showContracts = request()->query('supplier_view') === 'contracts';
|
||||
$data = $showContracts
|
||||
? ['view' => 'business.pages.supplier-payables.supplier-management']
|
||||
: app(\Modules\EcommerceFinance\View\SupplierManagementPageData::class)->page();
|
||||
|
||||
return $data + ['supplierShowContracts' => $showContracts]
|
||||
+ app(\App\Business\CourierContractPageData::class)->page($showContracts, 'supplier');
|
||||
}
|
||||
|
||||
protected function resolveContent(string $page, ?string $tab): ?array
|
||||
{
|
||||
return match ($page) {
|
||||
@ -5460,7 +5471,7 @@ class Pages extends Controller
|
||||
'warehouse-freight' => ['view' => 'business.pages.courier-payables.warehouse-freight'],
|
||||
'board-deductions' => $this->contentForBoardDeductions(),
|
||||
'supplier-payables-report' => $this->contentForSupplierPayablesReport(),
|
||||
'supplier-management' => app(\Modules\EcommerceFinance\View\SupplierManagementPageData::class)->page(),
|
||||
'supplier-management' => $this->contentForSupplierManagement(),
|
||||
'accessory-freight-deductions' => app(\Modules\EcommerceFinance\View\SupplierAccessoryFreightPageData::class)->page(),
|
||||
'manufacturer-bookkeeping' => app(\Modules\EcommerceFinance\View\SupplierBookkeepingPageData::class)->page(),
|
||||
'payable-cloud-warehouse-vehicle-fee' => $this->contentForDingPayableWorkflows(),
|
||||
|
||||
@ -105,8 +105,12 @@ class CourierAgreementSignature extends Model
|
||||
return $this->partnerType() === 'supplier' ? '供应商' : '快递公司';
|
||||
}
|
||||
|
||||
/** Only completed archives with a readable courier snapshot belong to contract management. */
|
||||
public function archivedCourierContractPayload(): ?array
|
||||
{
|
||||
return $this->archivedContractPayload('courier');
|
||||
}
|
||||
|
||||
public function archivedContractPayload(string $partnerType): ?array
|
||||
{
|
||||
if ($this->status !== self::STATUS_ARCHIVED || $this->document_type !== 'cooperation-contract') {
|
||||
return null;
|
||||
@ -119,7 +123,7 @@ class CourierAgreementSignature extends Model
|
||||
}
|
||||
|
||||
// Before partner_type was introduced all signing tasks were courier tasks.
|
||||
return is_array($payload) && ($payload['partner_type'] ?? 'courier') === 'courier' ? $payload : null;
|
||||
return is_array($payload) && ($payload['partner_type'] ?? 'courier') === $partnerType ? $payload : null;
|
||||
}
|
||||
|
||||
public function credentialDocuments(): array
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
@php
|
||||
$contractLabels = \App\Business\CourierContractPageData::STATUSES;
|
||||
$fileUrl = static fn (int $id, bool $preview = false): string => route('business.supplier-contracts.download', [
|
||||
'agreementSignature' => $id, 'kind' => 'signed',
|
||||
] + ($preview ? ['preview' => 1] : []));
|
||||
@endphp
|
||||
|
||||
<form method="GET" action="{{ $listUrl }}" class="supplier-management-toolbar" data-supplier-query aria-label="供应商合同筛选">
|
||||
<input type="hidden" name="supplier_view" value="contracts">
|
||||
<div class="supplier-management-field">
|
||||
<label for="supplier-contract-search">供应商 / 合同编号 / 签署主体</label>
|
||||
<input id="supplier-contract-search" name="contract_search" maxlength="255" value="{{ $courierContractFilters['contract_search'] }}" placeholder="也可查签署单号">
|
||||
</div>
|
||||
<div class="supplier-management-field">
|
||||
<label for="supplier-contract-status">合同期限状态</label>
|
||||
<select id="supplier-contract-status" name="contract_status">
|
||||
<option value="">全部状态</option>
|
||||
@foreach ($contractLabels as $key => $label)
|
||||
<option value="{{ $key }}" @selected($courierContractFilters['contract_status'] === $key)>{{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="supplier-management-actions">
|
||||
<button type="submit" class="supplier-management-button is-primary">查询</button>
|
||||
<a href="{{ $contractUrl() }}" class="supplier-management-button" data-supplier-local>重置</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p class="supplier-management-status">按归档合同的约定日期提前 {{ \App\Business\CourierContractPageData::REMINDER_DAYS }} 天提醒。约定期限届满后,请核对续签及自动续期条款。</p>
|
||||
|
||||
@if ($courierContractError)
|
||||
<div class="supplier-management-alert is-error" role="alert">{{ $courierContractError }}</div>
|
||||
@else
|
||||
@if ($courierContractUnreadable > 0)
|
||||
<div class="supplier-management-alert" role="status">有 {{ $courierContractUnreadable }} 条归档记录的签署快照无法读取,未纳入合同列表和提醒。</div>
|
||||
@endif
|
||||
<div class="supplier-management-panel">
|
||||
<div class="supplier-management-scroll">
|
||||
<table class="supplier-management-table" aria-label="已归档的供应商合作合同">
|
||||
<thead><tr>
|
||||
<th scope="col">供应商</th><th scope="col">期限状态</th><th scope="col">合同编号</th>
|
||||
<th scope="col">开始日期</th><th scope="col">结束日期</th><th scope="col">距到期天数</th>
|
||||
<th scope="col">甲方签署主体</th><th scope="col">乙方签署主体</th><th scope="col">签署单号</th><th scope="col">签署原件</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
@forelse ($courierContractRows as $contract)
|
||||
<tr>
|
||||
<td>{{ $contract['courier_name'] }}</td>
|
||||
<td><span class="supplier-management-badge">{{ $contractLabels[$contract['status']] }}</span></td>
|
||||
<td>{{ $contract['number'] ?: '未填写' }}</td>
|
||||
<td>{{ $contract['start_date'] ?: '待核对' }}</td>
|
||||
<td>{{ $contract['end_date'] ?: '待核对' }}</td>
|
||||
<td>@if ($contract['days'] === null)无法计算 @elseif ($contract['days'] < 0)已届满 {{ abs($contract['days']) }} 天 @elseif ($contract['days'] === 0)今天到期 @else{{ $contract['days'] }} 天@endif</td>
|
||||
<td>{{ $contract['party_a'] ?: '未填写' }}</td>
|
||||
<td>{{ $contract['party_b'] ?: '未填写' }}</td>
|
||||
<td>{{ $contract['business_no'] }}</td>
|
||||
<td>
|
||||
@if ($contract['has_signed_file'])
|
||||
<a href="{{ $fileUrl($contract['id'], true) }}" target="_blank" rel="noopener">查看签署原件</a> ·
|
||||
<a href="{{ $fileUrl($contract['id']) }}">下载</a>
|
||||
@else
|
||||
归档附件缺失
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="10" class="supplier-management-empty">当前条件下没有已归档的供应商合作合同。</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="supplier-management-pagination">
|
||||
<span>第 {{ $courierContractRows->currentPage() }} / {{ $courierContractRows->lastPage() }} 页,共 {{ $courierContractRows->total() }} 份合同</span>
|
||||
<nav aria-label="供应商合同分页">
|
||||
@if ($courierContractRows->previousPageUrl())<a href="{{ $courierContractRows->previousPageUrl() }}" data-supplier-local>上一页</a>@endif
|
||||
@if ($courierContractRows->nextPageUrl())<a href="{{ $courierContractRows->nextPageUrl() }}" data-supplier-local>下一页</a>@endif
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@ -3,7 +3,11 @@
|
||||
$localUrl = static fn (array $changes): string => $listUrl . '?' . http_build_query(array_merge(request()->except('detail_page'), $changes));
|
||||
$cell = static fn ($value): string => $value === null || $value === '' ? '—' : (string) $value;
|
||||
$freeShippingColumn = \Modules\EcommerceFinance\View\SupplierManagementPageData::FREE_SHIPPING_COLUMN;
|
||||
$detailColumns = match ($supplierDetailTab) {
|
||||
$contractUrl = static fn (array $filters = []): string => route('business.pages.show', [
|
||||
'section' => 'supplier-payables', 'page' => 'supplier-management', 'supplier_view' => 'contracts',
|
||||
] + $filters);
|
||||
$contractAttention = $courierContractCounts['due'] + $courierContractCounts['expired'];
|
||||
$detailColumns = match ($supplierDetailTab ?? null) {
|
||||
'contacts' => ['sourcefrom' => '数据来源', 'linker' => '联系人', 'linkjob' => '职务', 'linkmobile' => '联系电话', 'linkweixin' => '微信', 'memo' => '备注'],
|
||||
'payments' => ['enable' => '是否启用', 'sourcefrom' => '数据来源', 'accounttype' => '账户类型', 'account' => '打款账号', 'accountname' => '账户名称', 'accountbank' => '开户银行', 'accountnature' => '账户性质', 'invoice' => '开票信息', 'memo' => '备注'],
|
||||
'logs' => ['time' => '操作时间', 'user' => '操作人', 'action' => '操作内容'],
|
||||
@ -47,7 +51,7 @@
|
||||
.supplier-management-detail-heading { padding:12px 16px; border-bottom:1px solid var(--vip-border,#D8D2C7); color:var(--vip-content-muted,#595959); }
|
||||
.supplier-management-detail-tabs { display:flex; gap:20px; padding:0 16px; border-bottom:1px solid var(--vip-border,#D8D2C7); }
|
||||
.supplier-management-detail-tabs a { padding:10px 0; color:var(--vip-content-muted,#595959); border-bottom:2px solid transparent; font-size:.75rem; }
|
||||
.supplier-management-detail-tabs a[aria-selected="true"] { color:var(--vip-content-accent-dark,#856632); border-color:var(--vip-content-accent,#B9954F); }
|
||||
.supplier-management-detail-tabs a[aria-selected="true"],.supplier-management-detail-tabs a[aria-current="page"] { color:var(--vip-content-accent-dark,#856632); border-color:var(--vip-content-accent,#B9954F); }
|
||||
.supplier-management-alert { margin-bottom:12px; padding:12px; border:1px solid var(--vip-border,#D8D2C7); border-radius:8px; background:var(--vip-content-accent-soft,#F7F0DE); }
|
||||
.supplier-management-alert.is-error { color:var(--vip-danger,#B80000); border-color:var(--vip-danger,#B80000); }
|
||||
.supplier-management-import { position:fixed; inset:0; z-index:1060; display:grid; place-items:center; padding:16px; }
|
||||
@ -63,6 +67,25 @@
|
||||
.supplier-management-import__dialog footer { display:flex; justify-content:flex-end; gap:8px; padding:16px; border-top:1px solid var(--vip-border,#D8D2C7); }
|
||||
@media (max-width:640px) { .supplier-management-field { width:100%; } .supplier-management-detail-tabs { gap:12px; overflow-x:auto; white-space:nowrap; } }
|
||||
</style>
|
||||
<nav class="supplier-management-detail-tabs" aria-label="供应商管理分组">
|
||||
<a href="{{ $listUrl }}" data-supplier-local @if (! $supplierShowContracts) aria-current="page" @endif>供应商资料</a>
|
||||
<a href="{{ $contractUrl() }}" data-supplier-local @if ($supplierShowContracts) aria-current="page" @endif>
|
||||
合同管理@if ($contractAttention > 0) <span class="supplier-management-badge">{{ $contractAttention }} 份待关注</span>@endif
|
||||
</a>
|
||||
</nav>
|
||||
<p role="status" aria-live="polite" data-supplier-load-status></p>
|
||||
<div class="supplier-management-alert is-error" role="alert" data-supplier-load-error hidden>加载失败,当前内容已保留,请重新查询。</div>
|
||||
@if (! $courierContractError && ($contractAttention > 0 || $courierContractCounts['unknown'] > 0))
|
||||
<div class="supplier-management-alert" role="status">
|
||||
合同到期提醒:
|
||||
<a href="{{ $contractUrl(['contract_status' => 'due']) }}" data-supplier-local>{{ $courierContractCounts['due'] }} 份将在30天内到期(含今天)</a>,
|
||||
<a href="{{ $contractUrl(['contract_status' => 'expired']) }}" data-supplier-local>{{ $courierContractCounts['expired'] }} 份约定期限已届满</a>,
|
||||
<a href="{{ $contractUrl(['contract_status' => 'unknown']) }}" data-supplier-local>{{ $courierContractCounts['unknown'] }} 份期限待核对</a>。
|
||||
</div>
|
||||
@endif
|
||||
@if ($supplierShowContracts)
|
||||
@include('business.pages.supplier-payables.partials.supplier-contracts')
|
||||
@else
|
||||
<form method="GET" action="{{ $listUrl }}" class="supplier-management-toolbar" data-supplier-query aria-label="供应商管理筛选">
|
||||
<div class="supplier-management-field">
|
||||
<label for="supplier-management-name">供应商名称</label>
|
||||
@ -90,14 +113,12 @@
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
<p role="status" aria-live="polite" data-supplier-load-status></p>
|
||||
@if (session('supplier_management_message'))
|
||||
<div class="supplier-management-alert" role="status">{{ session('supplier_management_message') }}</div>
|
||||
@endif
|
||||
@if ($errors->has('import'))
|
||||
<div class="supplier-management-alert is-error" role="alert">{{ $errors->first('import') }}</div>
|
||||
@endif
|
||||
<div class="supplier-management-alert is-error" role="alert" data-supplier-load-error hidden>加载失败,当前内容已保留,请重新查询。</div>
|
||||
@if ($supplierError)
|
||||
<div class="supplier-management-alert is-error" role="alert">{{ $supplierError }}</div>
|
||||
@elseif (!$supplierReady)
|
||||
@ -209,6 +230,7 @@
|
||||
</section>
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
</section>
|
||||
@push('body_end')
|
||||
<script data-caiwu-replay>
|
||||
@ -232,10 +254,11 @@
|
||||
if (!next) throw new Error('session');
|
||||
if (!current.isConnected) return;
|
||||
const scroll = current.querySelector('.supplier-management-scroll');
|
||||
const scrollLeft = scroll.scrollLeft;
|
||||
const scrollLeft = scroll?.scrollLeft ?? 0;
|
||||
const mounted = document.importNode(next,true);
|
||||
current.replaceWith(mounted);
|
||||
mounted.querySelector('.supplier-management-scroll').scrollLeft = scrollLeft;
|
||||
const nextScroll = mounted.querySelector('.supplier-management-scroll');
|
||||
if (nextScroll) nextScroll.scrollLeft = scrollLeft;
|
||||
history.pushState({},'',href);
|
||||
window.dispatchEvent(new Event('caiwu:supplier-page-updated'));
|
||||
} catch (error) {
|
||||
|
||||
@ -254,6 +254,10 @@ Route::get('workspace/courier-payables/courier-information/contracts/{agreementS
|
||||
->middleware('business.page:courier-payables,courier-information')
|
||||
->name('business.courier-contracts.download');
|
||||
|
||||
Route::get('workspace/supplier-payables/supplier-management/contracts/{agreementSignature}/files/{kind}', 'Business\CourierContracts@downloadSupplier')
|
||||
->middleware('business.page:supplier-payables,supplier-management')
|
||||
->name('business.supplier-contracts.download');
|
||||
|
||||
Route::get('workspace/product-inventory/normal-products/export', 'Business\Pages@exportNormalProducts')
|
||||
->middleware('business.page:product-inventory,normal-products')
|
||||
->name('business.product-inventory.normal-products.export');
|
||||
|
||||
@ -165,6 +165,47 @@ class CourierContractManagementTest extends FeatureTestCase
|
||||
$this->assertTrue($data['courierContractRows']->items()[0]['has_signed_file']);
|
||||
}
|
||||
|
||||
public function test_supplier_reminder_uses_only_archived_supplier_contracts_and_protects_the_signed_pdf(): void
|
||||
{
|
||||
$supplier = ['partner_type' => 'supplier'];
|
||||
$today = $this->signature('今日到期供应商', $supplier + ['cooperation_end_date' => '2026-10-15']);
|
||||
$this->signature('三十天边界供应商', $supplier + ['cooperation_end_date' => '2026-11-14']);
|
||||
$this->signature('届满供应商', $supplier + ['cooperation_end_date' => '2026-10-14']);
|
||||
$this->signature('期限待核对供应商', $supplier + ['cooperation_end_date' => null]);
|
||||
$pending = $this->signature('待归档供应商', $supplier, ['status' => 'completed']);
|
||||
$foreign = $this->signature('其他租户供应商', $supplier, ['company_id' => $this->company->id + 10]);
|
||||
$courier = $this->signature('快递合同不应出现');
|
||||
$repository = Mockery::mock(\Modules\EcommerceFinance\Repositories\SupplierManagementMirrorRepository::class);
|
||||
$repository->shouldReceive('state')->once()->andReturn(null);
|
||||
$repository->shouldReceive('ready')->once()->andReturn(false);
|
||||
$this->app->instance(\Modules\EcommerceFinance\Repositories\SupplierManagementMirrorRepository::class, $repository);
|
||||
|
||||
$this->loginAs();
|
||||
$page = route('business.pages.show', ['section' => 'supplier-payables', 'page' => 'supplier-management']);
|
||||
$this->get($page)->assertOk()->assertSeeText('合同到期提醒')->assertSeeText('2 份将在30天内到期');
|
||||
$this->get($page . '?supplier_view=contracts&contract_status=due')->assertOk()
|
||||
->assertSeeText('今日到期供应商')->assertSeeText('今天到期')->assertSeeText('三十天边界供应商')
|
||||
->assertSeeText('1 份约定期限已届满')->assertSeeText('1 份期限待核对')
|
||||
->assertDontSeeText('届满供应商')->assertDontSeeText('待归档供应商')
|
||||
->assertDontSeeText('其他租户供应商')->assertDontSeeText('快递合同不应出现');
|
||||
|
||||
$fileUrl = static fn ($signature) => route('business.supplier-contracts.download', [
|
||||
'agreementSignature' => $signature->id, 'kind' => 'signed',
|
||||
]);
|
||||
$this->get($fileUrl($today))->assertOk()->assertHeader('content-type', 'application/pdf');
|
||||
$this->withExceptionHandling();
|
||||
foreach ([$pending, $foreign, $courier] as $excluded) {
|
||||
$this->getJson($fileUrl($excluded), ['X-Requested-With' => 'XMLHttpRequest'])->assertNotFound();
|
||||
}
|
||||
$this->user->syncRoles([\App\Models\Auth\Role::where('name', 'user')->firstOrFail()->id]);
|
||||
setting()->set('system.sidebar_permissions', json_encode([
|
||||
'configured' => ['user_' . $this->user->id],
|
||||
'subjects' => ['user_' . $this->user->id => ['courier-payables/courier-information']],
|
||||
]));
|
||||
setting()->save();
|
||||
$this->getJson($fileUrl($today), ['X-Requested-With' => 'XMLHttpRequest'])->assertForbidden();
|
||||
}
|
||||
|
||||
private function page(array $query = [])
|
||||
{
|
||||
return $this->loginAs()->get(route('business.pages.show', ['section' => 'courier-payables',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user