feat: 同步账户资金汇总并新增数据来源 (#1114)
Co-authored-by: 92451 <924518135@qq.com> Co-committed-by: 92451 <924518135@qq.com>
This commit is contained in:
parent
c34175c3d1
commit
f4f0d5d7b1
@ -1506,6 +1506,27 @@ class FinanceLedger extends Controller
|
||||
], 200, ['Cache-Control' => 'private, no-store']);
|
||||
}
|
||||
|
||||
public function updateFlowSummarySource(
|
||||
Request $request,
|
||||
FinanceLedgerFlowSummaryEditor $editor,
|
||||
): JsonResponse {
|
||||
abort_unless(FinanceLedgerAccess::canEditAccountStatus(user()), 403, '只有财务台账管理员可以编辑账户资金汇总数据来源。');
|
||||
|
||||
$data = $request->validate([
|
||||
'account_short' => ['required', 'string', 'max:100'],
|
||||
'value' => ['nullable', 'string', 'max:500'],
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'value' => $editor->updateSource(
|
||||
trim((string) $data['account_short']),
|
||||
$data['value'] ?? null,
|
||||
),
|
||||
'message' => '数据来源已保存。',
|
||||
], 200, ['Cache-Control' => 'private, no-store']);
|
||||
}
|
||||
|
||||
public function updateTransactionAccount(Request $request, int $id, FinanceLedgerCalculator $calculator): JsonResponse
|
||||
{
|
||||
abort_unless(FinanceLedgerAccess::canEditTransactions(user()), 403, '当前账号没有修改动账账户关联权限。');
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private function connection(): string
|
||||
{
|
||||
return (string) config('upstream_mirrors.connection', 'business_mirror');
|
||||
}
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$schema = Schema::connection($this->connection());
|
||||
|
||||
if (! $schema->hasTable('fin_flow_summary_account_sources')) {
|
||||
$schema->create('fin_flow_summary_account_sources', function (Blueprint $table): void {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('account_short', 100)->unique('fin_flow_summary_account_source_short_unique');
|
||||
$table->string('data_source', 500)->nullable();
|
||||
$table->string('updated_by', 100)->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::connection($this->connection())->dropIfExists('fin_flow_summary_account_sources');
|
||||
}
|
||||
};
|
||||
@ -146,15 +146,17 @@ class FinanceLedgerAccountEditor
|
||||
{
|
||||
$now = now();
|
||||
foreach ([
|
||||
'fin_account_opening' => ['account_short' => [], 'updated_at' => $now],
|
||||
'fin_daily_flows' => ['account_short' => [], 'updated_at' => $now],
|
||||
'fin_transactions' => ['account_short' => [], 'updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_map' => ['account_short' => [], 'updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_statuses' => ['account_short' => [], 'updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_type_overrides' => ['account_short' => [], 'updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_todos' => ['account_short' => [], 'updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_keep_todos' => ['account_short' => [], 'updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_shops' => ['account_short' => [], 'updated_at' => $now],
|
||||
'fin_account_opening' => ['updated_at' => $now],
|
||||
'fin_daily_flows' => ['updated_at' => $now],
|
||||
'fin_transactions' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_map' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_statuses' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_type_overrides' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_todos' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_account_keep_todos' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
'fin_shops' => ['updated_at' => $now],
|
||||
'fin_flow_summary_custom_values' => ['updated_at' => $now],
|
||||
'fin_flow_summary_account_sources' => ['updated_by' => (string) (user()?->name ?? ''), 'updated_at' => $now],
|
||||
] as $table => $extra) {
|
||||
if (! Schema::connection($this->connection->getName())->hasTable($table)
|
||||
|| ! Schema::connection($this->connection->getName())->hasColumn($table, 'account_short')) {
|
||||
|
||||
@ -61,6 +61,11 @@ class FinanceLedgerFlowSummaryEditor
|
||||
'field_names' => '一次新增的列名不能重复。',
|
||||
]);
|
||||
}
|
||||
if (in_array('数据来源', $normalizedNames, true)) {
|
||||
throw ValidationException::withMessages([
|
||||
'field_names' => '“数据来源”是账户资金汇总固定列,不能重复新增。',
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->connection->transaction(function () use (
|
||||
$fieldNames,
|
||||
@ -257,6 +262,67 @@ class FinanceLedgerFlowSummaryEditor
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function updateSource(string $accountShort, mixed $value): array
|
||||
{
|
||||
$accountShort = preg_replace('/\s+/u', ' ', trim($accountShort)) ?? trim($accountShort);
|
||||
$text = trim((string) ($value ?? ''));
|
||||
$text = preg_replace('/\s+/u', ' ', $text) ?? $text;
|
||||
|
||||
return $this->connection->transaction(function () use ($accountShort, $text): array {
|
||||
if ($accountShort === '' || FinanceLedgerIndependentAccounts::contains($accountShort)) {
|
||||
throw ValidationException::withMessages([
|
||||
'account_short' => '请选择账户资金汇总中的账户。',
|
||||
]);
|
||||
}
|
||||
if (! $this->connection->table('fin_accounts')->where('account_short', $accountShort)->exists()) {
|
||||
throw ValidationException::withMessages([
|
||||
'account_short' => '账户简称不存在,请刷新页面后重试。',
|
||||
]);
|
||||
}
|
||||
|
||||
$query = $this->connection->table('fin_flow_summary_account_sources')
|
||||
->where('account_short', $accountShort);
|
||||
$existing = $query->lockForUpdate()->first();
|
||||
$before = $existing?->data_source;
|
||||
$nextValue = $text !== '' ? mb_substr($text, 0, 500) : null;
|
||||
if ($nextValue === null) {
|
||||
if ($existing !== null) {
|
||||
$query->delete();
|
||||
}
|
||||
} elseif ($existing === null) {
|
||||
$this->connection->table('fin_flow_summary_account_sources')->insert([
|
||||
'account_short' => $accountShort,
|
||||
'data_source' => $nextValue,
|
||||
'updated_by' => (string) (user()?->name ?? ''),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
} else {
|
||||
$query->update([
|
||||
'data_source' => $nextValue,
|
||||
'updated_by' => (string) (user()?->name ?? ''),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
$this->audit(
|
||||
'flow_summary_source_set',
|
||||
$accountShort,
|
||||
[
|
||||
'before' => $before,
|
||||
'after' => $nextValue,
|
||||
],
|
||||
);
|
||||
|
||||
return [
|
||||
'account_short' => $accountShort,
|
||||
'data_source' => $nextValue,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $changes
|
||||
*/
|
||||
|
||||
@ -674,11 +674,16 @@ class FinanceLedgerPageData
|
||||
$accountRows = $accountQuery
|
||||
->orderBy('a.company_name')
|
||||
->orderBy('a.account_short')
|
||||
->get(['a.company_name', 'a.account_short', 'a.account_type'])
|
||||
->filter(static fn ($account): bool => trim((string) ($account->account_short ?? '')) !== '')
|
||||
->unique('account_short')
|
||||
->keyBy('account_short');
|
||||
$accountShorts = $accountRows->keys()->map(static fn (mixed $value): string => (string) $value)->all();
|
||||
->orderBy('a.id')
|
||||
->get(['a.id', 'a.company_name', 'a.account_short', 'a.account_type']);
|
||||
$accountShorts = $accountRows
|
||||
->pluck('account_short')
|
||||
->map(static fn (mixed $value): string => trim((string) $value))
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
$accountSources = $this->flowSummaryAccountSources($accountShorts);
|
||||
|
||||
$flowQuery = FinanceLedgerIndependentAccounts::exclude($this->db()->table('fin_daily_flows'))
|
||||
->whereIn('account_short', $accountShorts)
|
||||
@ -695,8 +700,8 @@ class FinanceLedgerPageData
|
||||
->groupBy('account_short');
|
||||
|
||||
$rows = [];
|
||||
foreach ($accountRows as $accountShort => $account) {
|
||||
$accountShort = (string) $accountShort;
|
||||
foreach ($accountRows as $account) {
|
||||
$accountShort = trim((string) ($account->account_short ?? ''));
|
||||
$accountFlows = $flowRows->get($accountShort, collect());
|
||||
$inPeriod = $accountFlows->filter(static function ($row) use ($period): bool {
|
||||
$date = substr((string) $row->flow_date, 0, 10);
|
||||
@ -720,9 +725,11 @@ class FinanceLedgerPageData
|
||||
->count();
|
||||
$hasBalance = $openingRow !== null || $closingRow !== null;
|
||||
$rows[] = [
|
||||
'account_id' => (int) $account->id,
|
||||
'company_name' => (string) ($account->company_name ?? ''),
|
||||
'account_short' => $accountShort,
|
||||
'bank_affiliation' => $this->bankAffiliation($accountShort),
|
||||
'data_source' => $accountSources[$accountShort] ?? null,
|
||||
'opening_balance' => $latestBeforePeriod !== null
|
||||
? round((float) $latestBeforePeriod->closing_balance, 2)
|
||||
: ($firstInPeriod === null ? null : round((float) $firstInPeriod->opening_balance, 2)),
|
||||
@ -772,6 +779,23 @@ class FinanceLedgerPageData
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $accountShorts
|
||||
* @return array<string,string|null>
|
||||
*/
|
||||
private function flowSummaryAccountSources(array $accountShorts): array
|
||||
{
|
||||
if ($accountShorts === [] || ! $this->db()->getSchemaBuilder()->hasTable('fin_flow_summary_account_sources')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->db()->table('fin_flow_summary_account_sources')
|
||||
->whereIn('account_short', $accountShorts)
|
||||
->pluck('data_source', 'account_short')
|
||||
->map(static fn (mixed $value): ?string => $value !== null ? (string) $value : null)
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{id:int,field_key:string,field_name:string}>
|
||||
*/
|
||||
@ -1820,6 +1844,7 @@ class FinanceLedgerPageData
|
||||
'account_short' => ['sort' => 'account_short', 'type' => 'text'],
|
||||
'bank_affiliation' => ['sort' => 'bank_affiliation', 'type' => 'text'],
|
||||
'company_name' => ['sort' => 'company_name', 'type' => 'text'],
|
||||
'data_source' => ['sort' => 'data_source', 'type' => 'text'],
|
||||
'opening_balance' => ['sort' => 'opening_balance', 'type' => 'number'],
|
||||
'inflow' => ['sort' => 'inflow', 'type' => 'number'],
|
||||
'outflow' => ['sort' => 'outflow', 'type' => 'number'],
|
||||
|
||||
@ -198,6 +198,7 @@
|
||||
['account_short', '账户简称', 'text'],
|
||||
['bank_affiliation', '所属银行', 'text'],
|
||||
['company_name', '公司', 'text'],
|
||||
['data_source', '数据来源', 'text'],
|
||||
['opening_balance', '期初余额', 'number', ['headerClass' => 'num', 'align' => 'end']],
|
||||
['inflow', '当期收入', 'number', ['headerClass' => 'num', 'align' => 'end']],
|
||||
['outflow', '当期支出', 'number', ['headerClass' => 'num', 'align' => 'end']],
|
||||
@ -1152,10 +1153,17 @@
|
||||
@endforelse
|
||||
@else
|
||||
@forelse ($ledgerFlows as $row)
|
||||
<tr data-flow-summary-account="{{ $row->account_short }}">
|
||||
<tr data-flow-summary-account="{{ $row->account_short }}" data-flow-summary-account-id="{{ $row->account_id }}">
|
||||
<td>{{ $row->account_short }}</td>
|
||||
<td>{{ $row->bank_affiliation ?: '—' }}</td>
|
||||
<td>{{ $row->company_name }}</td>
|
||||
<td class="wrap">
|
||||
@if ($canEditAccounts && $row->account_short !== '')
|
||||
<input class="ledger-summary-custom-input" type="text" maxlength="500" value="{{ $row->data_source ?? '' }}" placeholder="填写数据来源" aria-label="{{ $row->account_short }} - 数据来源" data-ledger-flow-summary-source data-source-account-short="{{ $row->account_short }}" data-previous-value="{{ $row->data_source ?? '' }}" data-value-url="{{ route('business.financial-ledger.flows.summary.source.update') }}">
|
||||
@else
|
||||
{{ filled($row->data_source ?? null) ? $row->data_source : '—' }}
|
||||
@endif
|
||||
</td>
|
||||
<td class="num">{{ $row->opening_balance === null ? '—' : $money($row->opening_balance) }}</td>
|
||||
<td class="num">{{ $row->inflow > 0 ? $money($row->inflow) : '' }}</td>
|
||||
<td class="num">{{ $row->outflow > 0 ? $money($row->outflow) : '' }}</td>
|
||||
@ -1165,7 +1173,7 @@
|
||||
@foreach ($flowSummaryCustomFields as $customField)
|
||||
@php $customValue = $row->custom_values[$customField['field_key']] ?? ''; @endphp
|
||||
<td class="wrap">
|
||||
@if ($canEditAccounts)
|
||||
@if ($canEditAccounts && $row->account_short !== '')
|
||||
<input class="ledger-summary-custom-input" type="text" maxlength="4000" value="{{ $customValue }}" placeholder="填写{{ $customField['field_name'] }}" aria-label="{{ $row->account_short }} - {{ $customField['field_name'] }}" data-ledger-flow-summary-custom-value data-field-id="{{ $customField['id'] }}" data-account-short="{{ $row->account_short }}" data-previous-value="{{ $customValue }}" data-value-url="{{ route('business.financial-ledger.flows.summary.values.update') }}">
|
||||
@else
|
||||
{{ $customValue }}
|
||||
@ -1173,7 +1181,7 @@
|
||||
</td>
|
||||
@endforeach
|
||||
<td>
|
||||
@if ($canEditAccounts)
|
||||
@if ($canEditAccounts && $row->account_short !== '')
|
||||
<button class="ledger-row-edit ledger-row-edit--text" type="button" title="编辑 {{ $row->account_short }} 每日流水,默认 {{ $flowSummaryEditDate }},可在弹窗中更改日期" aria-label="编辑 {{ $row->account_short }} 每日流水" data-ledger-flow-edit data-flow-summary-edit data-edit-url="{{ route('business.financial-ledger.flows.edit', ['flow_date' => $flowSummaryEditDate, 'account_short' => $row->account_short]) }}" data-save-url="{{ route('business.financial-ledger.flows.update') }}" data-reset-url="{{ route('business.financial-ledger.flows.reset') }}" data-flow-date="{{ $flowSummaryEditDate }}" data-flow-account-short="{{ $row->account_short }}"><span class="material-icons-outlined" aria-hidden="true">edit</span><span>编辑</span></button>
|
||||
@else
|
||||
<span class="muted">—</span>
|
||||
@ -1181,7 +1189,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="{{ 10 + count($flowSummaryCustomFields) }}"><div class="ledger-empty">没有匹配的账户。</div></td></tr>
|
||||
<tr><td colspan="{{ 11 + count($flowSummaryCustomFields) }}"><div class="ledger-empty">没有匹配的账户。</div></td></tr>
|
||||
@endforelse
|
||||
@endif
|
||||
</tbody>
|
||||
@ -3759,7 +3767,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
flowsPanel?.querySelectorAll('[data-ledger-flow-summary-custom-value]').forEach((input) => {
|
||||
flowsPanel?.querySelectorAll('[data-ledger-flow-summary-custom-value], [data-ledger-flow-summary-source]').forEach((input) => {
|
||||
const isDataSource = input.hasAttribute('data-ledger-flow-summary-source');
|
||||
const saveValue = async () => {
|
||||
if (input.dataset.saving === '1') return;
|
||||
const previousValue = input.dataset.previousValue || '';
|
||||
@ -3779,25 +3788,30 @@
|
||||
'X-CSRF-TOKEN': ledgerCsrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
field_id: Number(input.dataset.fieldId || 0),
|
||||
account_short: input.dataset.accountShort || '',
|
||||
value: nextValue,
|
||||
}),
|
||||
body: JSON.stringify(isDataSource
|
||||
? {
|
||||
account_short: input.dataset.sourceAccountShort || '',
|
||||
value: nextValue,
|
||||
}
|
||||
: {
|
||||
field_id: Number(input.dataset.fieldId || 0),
|
||||
account_short: input.dataset.accountShort || '',
|
||||
value: nextValue,
|
||||
}),
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
const firstError = Object.values(payload.errors || {})[0]?.[0];
|
||||
throw new Error(firstError || payload.message || '自定义列数据保存失败');
|
||||
throw new Error(firstError || payload.message || (isDataSource ? '数据来源保存失败' : '自定义列数据保存失败'));
|
||||
}
|
||||
const savedValue = payload.value?.value || '';
|
||||
const savedValue = (isDataSource ? payload.value?.data_source : payload.value?.value) || '';
|
||||
input.value = savedValue;
|
||||
input.dataset.previousValue = savedValue;
|
||||
notify(payload.message || '自定义列数据已保存');
|
||||
notify(payload.message || (isDataSource ? '数据来源已保存' : '自定义列数据已保存'));
|
||||
} catch (error) {
|
||||
input.value = previousValue;
|
||||
input.classList.add('is-error');
|
||||
notify(error.message || '自定义列数据保存失败', true);
|
||||
notify(error.message || (isDataSource ? '数据来源保存失败' : '自定义列数据保存失败'), true);
|
||||
} finally {
|
||||
input.disabled = false;
|
||||
input.classList.remove('is-saving');
|
||||
|
||||
@ -939,6 +939,10 @@ Route::post('workspace/financial-ledger/flows/summary/values', [\App\Http\Contro
|
||||
->middleware('business.page:financial-operations,ledger')
|
||||
->name('business.financial-ledger.flows.summary.values.update');
|
||||
|
||||
Route::post('workspace/financial-ledger/flows/summary/source', [\App\Http\Controllers\Business\FinanceLedger::class, 'updateFlowSummarySource'])
|
||||
->middleware('business.page:financial-operations,ledger')
|
||||
->name('business.financial-ledger.flows.summary.source.update');
|
||||
|
||||
Route::post('workspace/financial-ledger/accounts/status', [\App\Http\Controllers\Business\FinanceLedger::class, 'updateAccountStatus'])
|
||||
->middleware('business.page:financial-operations,ledger')
|
||||
->name('business.financial-ledger.accounts.status');
|
||||
|
||||
@ -92,6 +92,115 @@ class FinanceLedgerFlowSummarySpreadsheetTest extends FeatureTestCase
|
||||
], 'business_mirror');
|
||||
}
|
||||
|
||||
public function test_summary_keeps_every_account_master_row_and_follows_account_edits(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
$originalId = (int) $connection->table('fin_accounts')
|
||||
->where('account_short', $this->accountShort)
|
||||
->value('id');
|
||||
$duplicateId = (int) $connection->table('fin_accounts')->insertGetId([
|
||||
'company_name' => '重名账户测试公司',
|
||||
'account_short' => $this->accountShort,
|
||||
'account_type' => '公户',
|
||||
'current_balance' => 20,
|
||||
'daily_available' => 20,
|
||||
'blocked_amount' => 0,
|
||||
]);
|
||||
|
||||
$html = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent();
|
||||
|
||||
$this->assertStringContainsString('data-flow-summary-account-id="' . $originalId . '"', $html);
|
||||
$this->assertStringContainsString('data-flow-summary-account-id="' . $duplicateId . '"', $html);
|
||||
$this->assertStringContainsString('汇总表格测试公司', $html);
|
||||
$this->assertStringContainsString('重名账户测试公司', $html);
|
||||
|
||||
$renamedShort = $this->accountShort . '-已同步';
|
||||
$this->loginAs()->postJson(route('business.financial-ledger.accounts.update', [
|
||||
'company_id' => $this->company->id,
|
||||
'id' => $duplicateId,
|
||||
]), [
|
||||
'company_name' => '账户编辑后公司',
|
||||
'account_short' => $renamedShort,
|
||||
'status' => 'normal',
|
||||
])->assertOk()->assertJsonPath('account.company_name', '账户编辑后公司');
|
||||
|
||||
$renamedHtml = $this->loginAs()->get($this->pageUrlForAccount($renamedShort))
|
||||
->assertOk()
|
||||
->getContent();
|
||||
$this->assertStringContainsString('data-flow-summary-account-id="' . $duplicateId . '"', $renamedHtml);
|
||||
$this->assertStringContainsString('账户编辑后公司', $renamedHtml);
|
||||
$this->assertStringNotContainsString('重名账户测试公司', $renamedHtml);
|
||||
}
|
||||
|
||||
public function test_data_source_is_after_company_and_can_be_edited_inline(): void
|
||||
{
|
||||
$html = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent();
|
||||
$flowsStart = strpos($html, 'id="ledger-panel-flows"');
|
||||
$transactionsStart = strpos($html, 'id="ledger-panel-transactions"');
|
||||
$flowsHtml = substr($html, (int) $flowsStart, (int) $transactionsStart - (int) $flowsStart);
|
||||
$accountHeader = strpos($flowsHtml, 'data-ledger-header-field="account_short"');
|
||||
$companyHeader = strpos($flowsHtml, 'data-ledger-header-field="company_name"');
|
||||
$sourceHeader = strpos($flowsHtml, 'data-ledger-header-field="data_source"');
|
||||
$openingHeader = strpos($flowsHtml, 'data-ledger-header-field="opening_balance"');
|
||||
|
||||
$this->assertIsInt($accountHeader);
|
||||
$this->assertIsInt($companyHeader);
|
||||
$this->assertIsInt($sourceHeader);
|
||||
$this->assertIsInt($openingHeader);
|
||||
$this->assertTrue($accountHeader < $companyHeader);
|
||||
$this->assertTrue($companyHeader < $sourceHeader);
|
||||
$this->assertTrue($sourceHeader < $openingHeader);
|
||||
$this->assertStringContainsString('data-ledger-flow-summary-source', $flowsHtml);
|
||||
$this->assertStringContainsString('placeholder="填写数据来源"', $flowsHtml);
|
||||
|
||||
$this->loginAs()->postJson($this->sourceUrl(), [
|
||||
'account_short' => $this->accountShort,
|
||||
'value' => '银行流水',
|
||||
])->assertOk()
|
||||
->assertJsonPath('value.data_source', '银行流水');
|
||||
$this->assertDatabaseHas('fin_flow_summary_account_sources', [
|
||||
'account_short' => $this->accountShort,
|
||||
'data_source' => '银行流水',
|
||||
], 'business_mirror');
|
||||
|
||||
$accountId = (int) DB::connection('business_mirror')->table('fin_accounts')
|
||||
->where('account_short', $this->accountShort)
|
||||
->value('id');
|
||||
$renamedShort = $this->accountShort . '-来源同步';
|
||||
$this->loginAs()->postJson(route('business.financial-ledger.accounts.update', [
|
||||
'company_id' => $this->company->id,
|
||||
'id' => $accountId,
|
||||
]), [
|
||||
'company_name' => '汇总表格测试公司',
|
||||
'account_short' => $renamedShort,
|
||||
'status' => 'normal',
|
||||
])->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('fin_flow_summary_account_sources', [
|
||||
'account_short' => $renamedShort,
|
||||
'data_source' => '银行流水',
|
||||
], 'business_mirror');
|
||||
$this->assertDatabaseHas('fin_account_opening', [
|
||||
'account_short' => $renamedShort,
|
||||
], 'business_mirror');
|
||||
$this->assertDatabaseMissing('fin_account_opening', [
|
||||
'account_short' => $this->accountShort,
|
||||
], 'business_mirror');
|
||||
$renamedHtml = $this->loginAs()->get($this->pageUrlForAccount($renamedShort))
|
||||
->assertOk()
|
||||
->getContent();
|
||||
$this->assertStringContainsString('value="银行流水"', $renamedHtml);
|
||||
}
|
||||
|
||||
public function test_data_source_column_name_is_reserved_for_the_fixed_column(): void
|
||||
{
|
||||
$this->withExceptionHandling()->loginAs()->postJson($this->columnStoreUrl(), [
|
||||
'field_names' => ['数据来源'],
|
||||
'position' => 'end',
|
||||
])->assertUnprocessable()
|
||||
->assertJsonPath('errors.field_names.0', '“数据来源”是账户资金汇总固定列,不能重复新增。');
|
||||
}
|
||||
|
||||
public function test_summary_spreadsheet_endpoints_reject_account_viewers(): void
|
||||
{
|
||||
$viewer = user_model_class()::create([
|
||||
@ -110,9 +219,18 @@ class FinanceLedgerFlowSummarySpreadsheetTest extends FeatureTestCase
|
||||
$this->withExceptionHandling()->loginAs($viewer)->postJson($this->columnStoreUrl(), [
|
||||
'field_names' => ['无权限列'],
|
||||
])->assertForbidden();
|
||||
$this->withExceptionHandling()->loginAs($viewer)->postJson($this->sourceUrl(), [
|
||||
'account_short' => $this->accountShort,
|
||||
'value' => '无权限来源',
|
||||
])->assertForbidden();
|
||||
}
|
||||
|
||||
private function pageUrl(): string
|
||||
{
|
||||
return $this->pageUrlForAccount($this->accountShort);
|
||||
}
|
||||
|
||||
private function pageUrlForAccount(string $accountShort): string
|
||||
{
|
||||
return route('business.pages.show', [
|
||||
'company_id' => $this->company->id,
|
||||
@ -123,7 +241,7 @@ class FinanceLedgerFlowSummarySpreadsheetTest extends FeatureTestCase
|
||||
'flows_view' => 'summary',
|
||||
'flows_from' => '2026-11-01',
|
||||
'flows_to' => '2026-11-30',
|
||||
'flows_account' => $this->accountShort,
|
||||
'flows_account' => $accountShort,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -148,4 +266,11 @@ class FinanceLedgerFlowSummarySpreadsheetTest extends FeatureTestCase
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function sourceUrl(): string
|
||||
{
|
||||
return route('business.financial-ledger.flows.summary.source.update', [
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,8 +140,8 @@ class FinanceLedgerHeaderControlsTest extends FeatureTestCase
|
||||
$response = $this->loginAs()->get($this->pageUrl());
|
||||
$html = $response->assertOk()->getContent();
|
||||
|
||||
$this->assertSame(66, preg_match_all('/<details\b[^>]*data-ledger-header-details/', $html));
|
||||
$this->assertSame(66, preg_match_all('/<span\b[^>]*data-ledger-header-label/', $html));
|
||||
$this->assertSame(67, preg_match_all('/<details\b[^>]*data-ledger-header-details/', $html));
|
||||
$this->assertSame(67, preg_match_all('/<span\b[^>]*data-ledger-header-label/', $html));
|
||||
$this->assertSame(2, preg_match_all('/<select name="transactions_filter_value"/', $html));
|
||||
$this->assertSame(1, preg_match_all('/<input\b[^>]*name="transactions_filter_value"[^>]*list="ledger-header-options-transactions-effective_account_short"/', $html));
|
||||
$this->assertStringContainsString(
|
||||
@ -437,17 +437,17 @@ class FinanceLedgerHeaderControlsTest extends FeatureTestCase
|
||||
'flows_to' => '2026-10-31',
|
||||
]))->assertOk()->getContent();
|
||||
|
||||
$this->assertSame(1, preg_match('/<tr data-flow-summary-account="账户甲">.*?<\/tr>/s', $summaryHtml, $accountRow));
|
||||
$this->assertSame(1, preg_match('/<tr data-flow-summary-account="账户甲"[^>]*>.*?<\/tr>/s', $summaryHtml, $accountRow));
|
||||
$this->assertMatchesRegularExpression('/<td>账户甲<\/td>\s*<td>—<\/td>\s*<td>甲公司<\/td>/', $accountRow[0]);
|
||||
$this->assertStringContainsString('>所属银行</span>', $summaryHtml);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<td class="num">100\.00<\/td>\s*<td class="num">10\.00<\/td>\s*<td class="num"><\/td>\s*<td class="num">110\.00<\/td>\s*<td class="num">1<\/td>/',
|
||||
'/<td class="wrap">.*?<\/td>\s*<td class="num">100\.00<\/td>\s*<td class="num">10\.00<\/td>\s*<td class="num"><\/td>\s*<td class="num">110\.00<\/td>\s*<td class="num">1<\/td>/s',
|
||||
$accountRow[0],
|
||||
);
|
||||
$this->assertStringContainsString('data-flow-summary-edit', $accountRow[0]);
|
||||
$this->assertStringContainsString('data-edit-url=', $accountRow[0]);
|
||||
$this->assertStringContainsString('>编辑</span>', $accountRow[0]);
|
||||
$this->assertSame(1, preg_match('/<tr data-flow-summary-account="账户丙">.*?<\/tr>/s', $summaryHtml, $emptyAccountRow));
|
||||
$this->assertSame(1, preg_match('/<tr data-flow-summary-account="账户丙"[^>]*>.*?<\/tr>/s', $summaryHtml, $emptyAccountRow));
|
||||
$this->assertMatchesRegularExpression('/<td>账户丙<\/td>\s*<td>—<\/td>\s*<td>丙公司<\/td>/', $emptyAccountRow[0]);
|
||||
$this->assertStringContainsString('<td class="num">—</td>', $emptyAccountRow[0]);
|
||||
$this->assertStringContainsString('<td>尚未起账</td>', $emptyAccountRow[0]);
|
||||
|
||||
@ -239,7 +239,7 @@ class FinanceLedgerManualEditTest extends FeatureTestCase
|
||||
]))->assertOk()->getContent();
|
||||
$this->assertSame(
|
||||
1,
|
||||
preg_match('/<tr data-flow-summary-account="手动编辑测试账户">.*?<\/tr>/s', $summaryHtml, $accountRow),
|
||||
preg_match('/<tr data-flow-summary-account="手动编辑测试账户"[^>]*>.*?<\/tr>/s', $summaryHtml, $accountRow),
|
||||
);
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<td class="num">100\.00<\/td>\s*<td class="num">35\.00<\/td>\s*<td class="num">30\.00<\/td>\s*<td class="num">105\.00<\/td>/',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user