feat: 展示负数预警最新账期合计 (#741)
在采购钉钉任务页展示最新账期供应商负数合计。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com>
This commit is contained in:
parent
c64c6f5a54
commit
75d63602ad
@ -26,10 +26,12 @@ class SupplierNegativeAlertDingTalkForms extends Controller
|
||||
}
|
||||
|
||||
$snapshot = json_decode((string) $assignment->snapshot, true);
|
||||
$snapshot = is_array($snapshot) ? array_values($snapshot) : [];
|
||||
|
||||
return view('business.pages.negative-alerts.dingtalk-task', [
|
||||
'assignment' => $assignment,
|
||||
'suppliers' => is_array($snapshot) ? array_values($snapshot) : [],
|
||||
'suppliers' => $snapshot,
|
||||
'latestPeriod' => $this->workflow->latestPeriodSummary($snapshot),
|
||||
'supplierResults' => $this->workflow->resultsForAssignment((int) $assignment->id),
|
||||
'token' => $token,
|
||||
]);
|
||||
|
||||
@ -439,6 +439,54 @@ class SupplierNegativeAlertDingTalkWorkflow
|
||||
return $latest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务页展示:按任务快照中的最新账期汇总该采购的负数金额。
|
||||
*
|
||||
* @param list<array<string,mixed>> $snapshot
|
||||
* @return array{month:string,negative_amount:float,supplier_count:int,row_count:int}
|
||||
*/
|
||||
public function latestPeriodSummary(array $snapshot): array
|
||||
{
|
||||
$latestMonth = '';
|
||||
foreach ($snapshot as $supplier) {
|
||||
foreach ((array) ($supplier['rows'] ?? []) as $row) {
|
||||
$month = trim((string) ($row['summary_month'] ?? ''));
|
||||
if (preg_match('/^\d{4}-\d{2}$/', $month) === 1 && $month > $latestMonth) {
|
||||
$latestMonth = $month;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$negativeAmount = 0.0;
|
||||
$supplierNames = [];
|
||||
$rowCount = 0;
|
||||
foreach ($snapshot as $supplier) {
|
||||
$supplierName = trim((string) ($supplier['supplier'] ?? ''));
|
||||
foreach ((array) ($supplier['rows'] ?? []) as $row) {
|
||||
$month = trim((string) ($row['summary_month'] ?? ''));
|
||||
if ($latestMonth !== '' && $month !== $latestMonth) {
|
||||
continue;
|
||||
}
|
||||
$amount = (float) ($row['alert_amount'] ?? 0);
|
||||
if ($amount >= 0) {
|
||||
continue;
|
||||
}
|
||||
$negativeAmount += $amount;
|
||||
$rowCount++;
|
||||
if ($supplierName !== '') {
|
||||
$supplierNames[$supplierName] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'month' => $latestMonth,
|
||||
'negative_amount' => round($negativeAmount, 2),
|
||||
'supplier_count' => count($supplierNames),
|
||||
'row_count' => $rowCount,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string,string> */
|
||||
public function resultsForAssignment(int $assignmentId): array
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
$assignment = $assignment ?? null;
|
||||
$suppliers = $suppliers ?? [];
|
||||
$supplierResults = $supplierResults ?? [];
|
||||
$latestPeriod = $latestPeriod ?? ['month' => '', 'negative_amount' => 0, 'supplier_count' => 0, 'row_count' => 0];
|
||||
$completed = ($assignment->status ?? '') === 'completed';
|
||||
$filledCount = collect($suppliers)->filter(
|
||||
static fn (array $supplier): bool => filled($supplierResults[$supplier['supplier'] ?? ''] ?? null)
|
||||
@ -66,6 +67,32 @@
|
||||
background: #FDF1F1;
|
||||
color: #7A1010;
|
||||
}
|
||||
.period-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 10px 20px;
|
||||
margin-bottom: 12px;
|
||||
padding: 16px;
|
||||
border: 1px solid #D7C39D;
|
||||
border-radius: 12px;
|
||||
background: #FFFDF8;
|
||||
}
|
||||
.period-summary__amount { display: grid; gap: 3px; }
|
||||
.period-summary__amount span { color: var(--muted); font-size: 12px; }
|
||||
.period-summary__amount strong {
|
||||
color: var(--danger);
|
||||
font-size: 24px;
|
||||
line-height: 1.25;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.period-summary__meta {
|
||||
max-width: 260px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.summary {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
@ -194,6 +221,20 @@
|
||||
<div class="notice is-error" role="alert">{{ $errors->first() }}</div>
|
||||
@endif
|
||||
|
||||
<section class="period-summary" aria-label="最新账期负数合计">
|
||||
<div class="period-summary__amount">
|
||||
<span>
|
||||
最新账期负数合计 ·
|
||||
{{ ($latestPeriod['month'] ?? '') !== '' ? $latestPeriod['month'] : '未标注月份' }}
|
||||
</span>
|
||||
<strong>¥{{ number_format((float) ($latestPeriod['negative_amount'] ?? 0), 2) }}</strong>
|
||||
</div>
|
||||
<div class="period-summary__meta">
|
||||
该账期涉及 {{ number_format((int) ($latestPeriod['supplier_count'] ?? 0)) }} 家供应商、
|
||||
{{ number_format((int) ($latestPeriod['row_count'] ?? 0)) }} 条负数预警
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="summary" aria-label="任务汇总">
|
||||
<div class="summary__item">
|
||||
<span>供应商</span>
|
||||
|
||||
@ -109,6 +109,11 @@ class SupplierNegativeAlertDingTalkTest extends FeatureTestCase
|
||||
->assertSeeText('供应商负数预警处理')
|
||||
->assertSeeText('三洋木业')
|
||||
->assertSeeText('久柯家具')
|
||||
->assertSeeText('最新账期负数合计')
|
||||
->assertSeeText('2026-09')
|
||||
->assertSeeText('¥-230.00')
|
||||
->assertSeeText('该账期涉及')
|
||||
->assertSeeText('3 条负数预警')
|
||||
->assertSee('placeholder="请填写该供应商的核对、沟通或处理结果"', false)
|
||||
->assertSeeText('处理结果');
|
||||
$this->assertSame(2, substr_count((string) $response->getContent(), 'name="results[]"'));
|
||||
@ -168,6 +173,36 @@ class SupplierNegativeAlertDingTalkTest extends FeatureTestCase
|
||||
->assertSeeText('任务链接无效或已过期');
|
||||
}
|
||||
|
||||
public function test_latest_period_summary_only_uses_the_newest_accounting_month(): void
|
||||
{
|
||||
$summary = app(SupplierNegativeAlertDingTalkWorkflow::class)->latestPeriodSummary([
|
||||
[
|
||||
'supplier' => '供应商甲',
|
||||
'rows' => [
|
||||
['summary_month' => '2026-08', 'alert_amount' => -100],
|
||||
['summary_month' => '2026-09', 'alert_amount' => -50],
|
||||
],
|
||||
],
|
||||
[
|
||||
'supplier' => '供应商乙',
|
||||
'rows' => [
|
||||
['summary_month' => '2026-09', 'alert_amount' => -30],
|
||||
],
|
||||
],
|
||||
[
|
||||
'supplier' => '供应商丙',
|
||||
'rows' => [
|
||||
['summary_month' => '2026-08', 'alert_amount' => -200],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame('2026-09', $summary['month']);
|
||||
$this->assertSame(-80.0, $summary['negative_amount']);
|
||||
$this->assertSame(2, $summary['supplier_count']);
|
||||
$this->assertSame(2, $summary['row_count']);
|
||||
}
|
||||
|
||||
public function test_one_click_sends_all_purchasers_in_one_group_message(): void
|
||||
{
|
||||
$this->seedBulkRows();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user