feat(财务台账): 增加不保留账户表头排序 #511
@ -246,6 +246,7 @@ class FinanceLedger extends Controller
|
||||
->leftJoin('fin_account_keep_todos as account_todo', 'account_todo.account_short', '=', 'accounts.account_short')
|
||||
->select([
|
||||
'accounts.*',
|
||||
'accounts.account_type as sort_account_type',
|
||||
'account_status.status as effective_account_status',
|
||||
'type_override.id as type_override_id',
|
||||
'type_override.account_type as effective_account_type',
|
||||
@ -447,11 +448,57 @@ class FinanceLedger extends Controller
|
||||
];
|
||||
|
||||
$sortField = (string) $request->query('keep_sort', '');
|
||||
$sortField = in_array($sortField, ['started_at', 'completed_at'], true) ? $sortField : '';
|
||||
$sortField = in_array($sortField, $headerFilterColumns, true) ? $sortField : '';
|
||||
$sortDirection = strtolower((string) $request->query('keep_direction', 'asc'));
|
||||
$sortDirection = $sortDirection === 'desc' ? 'desc' : 'asc';
|
||||
if ($sortField !== '') {
|
||||
$query->orderBy('account_todo.' . $sortField, $sortDirection);
|
||||
if ($sortField === 'legal_representative') {
|
||||
if ($connection->getSchemaBuilder()->hasTable('ops_fys_company_info')) {
|
||||
$legalRepresentativeOrder = $connection->table('ops_fys_company_info')
|
||||
->select('legalRepresentative')
|
||||
->whereColumn('businessLicenseName', 'accounts.company_name')
|
||||
->orderByDesc('Id')
|
||||
->limit(1);
|
||||
$query->orderBy($legalRepresentativeOrder, $sortDirection);
|
||||
} else {
|
||||
$query->orderBy('accounts.company_name', $sortDirection);
|
||||
}
|
||||
} elseif ($sortField === 'account_type') {
|
||||
$query->orderByRaw(
|
||||
'CASE WHEN type_override_id IS NOT NULL THEN effective_account_type'
|
||||
. ' ELSE sort_account_type END ' . $sortDirection,
|
||||
);
|
||||
} elseif ($sortField === 'account_status') {
|
||||
$query->orderByRaw(
|
||||
"CASE COALESCE(effective_account_status, 'normal')"
|
||||
. " WHEN 'normal' THEN 1"
|
||||
. " WHEN 'online_banking_abnormal' THEN 2"
|
||||
. " WHEN 'limited' THEN 3"
|
||||
. " WHEN 'business_deregistered' THEN 4"
|
||||
. ' ELSE 99 END ' . $sortDirection,
|
||||
);
|
||||
} elseif ($sortField === 'handling_method') {
|
||||
$query->orderByRaw(
|
||||
'CASE todo_handling_method'
|
||||
. " WHEN 'online' THEN 1"
|
||||
. " WHEN 'offline' THEN 2"
|
||||
. ' ELSE 0 END ' . $sortDirection,
|
||||
);
|
||||
} elseif ($sortField === 'current_progress') {
|
||||
$query->orderByRaw(
|
||||
"CASE COALESCE(todo_current_progress, 'not_started')"
|
||||
. " WHEN 'not_started' THEN 1"
|
||||
. " WHEN 'in_progress' THEN 2"
|
||||
. " WHEN 'completed' THEN 3"
|
||||
. ' ELSE 99 END ' . $sortDirection,
|
||||
);
|
||||
} elseif ($sortField === 'owner_name') {
|
||||
$query->orderBy('account_todo.owner_name', $sortDirection);
|
||||
} elseif (in_array($sortField, ['started_at', 'completed_at'], true)) {
|
||||
$query->orderBy('account_todo.' . $sortField, $sortDirection);
|
||||
} elseif ($sortField !== 'account_should_keep') {
|
||||
$query->orderBy('accounts.' . $sortField, $sortDirection);
|
||||
}
|
||||
}
|
||||
|
||||
$rows = $query
|
||||
|
||||
@ -252,7 +252,7 @@
|
||||
'column' => $header['column'],
|
||||
'label' => $header['label'],
|
||||
'filterType' => $header['filterType'],
|
||||
'showSort' => $header['showSort'] ?? false,
|
||||
'showSort' => true,
|
||||
'includeTabField' => false,
|
||||
'keepColumnKey' => $header['column'],
|
||||
'pageParameter' => 'page',
|
||||
|
||||
@ -194,6 +194,11 @@ class FinanceLedgerAccountKeepTodoTest extends FeatureTestCase
|
||||
->assertSee('list="ledger-header-options-keep-account_short"', false)
|
||||
->assertSee('name="keep_filter_column"', false)
|
||||
->assertSee('name="keep_filter_value"', false)
|
||||
->assertSee('公司名称排序和筛选')
|
||||
->assertSee('keep_sort=account_short', false)
|
||||
->assertSee('keep_sort=account_status', false)
|
||||
->assertSee('keep_sort=owner_name', false)
|
||||
->assertSee('keep_sort=current_progress', false)
|
||||
->assertSee('已完成')
|
||||
->assertSee('进行中')
|
||||
->assertSee('待开始')
|
||||
@ -225,6 +230,79 @@ class FinanceLedgerAccountKeepTodoTest extends FeatureTestCase
|
||||
], $matches[1]);
|
||||
}
|
||||
|
||||
public function test_keep_tasks_sort_all_headers_by_effective_display_values(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
$connection->table('fin_accounts')->insert([
|
||||
[
|
||||
'company_name' => '排序公司甲',
|
||||
'account_short' => '排序账户甲',
|
||||
'account_type' => '公户',
|
||||
'company_plan' => '保留',
|
||||
'account_should_keep' => '否',
|
||||
],
|
||||
[
|
||||
'company_name' => '排序公司乙',
|
||||
'account_short' => '排序账户乙',
|
||||
'account_type' => '网商银行',
|
||||
'company_plan' => '待注销',
|
||||
'account_should_keep' => null,
|
||||
],
|
||||
]);
|
||||
$connection->table('fin_account_type_overrides')->insert([
|
||||
'account_short' => '排序账户甲',
|
||||
'account_type' => '个人卡',
|
||||
'updated_by' => 'Test User',
|
||||
]);
|
||||
$connection->table('fin_account_statuses')->insert([
|
||||
'account_short' => '排序账户甲',
|
||||
'status' => 'limited',
|
||||
'updated_by' => 'Test User',
|
||||
]);
|
||||
$connection->table('fin_account_keep_todos')->insert([
|
||||
[
|
||||
'account_short' => '排序账户甲',
|
||||
'handling_method' => 'online',
|
||||
'owner_name' => '玉兔',
|
||||
'current_progress' => 'completed',
|
||||
],
|
||||
[
|
||||
'account_short' => '排序账户乙',
|
||||
'handling_method' => 'offline',
|
||||
'owner_name' => '山时',
|
||||
'current_progress' => 'not_started',
|
||||
],
|
||||
]);
|
||||
$connection->table('ops_fys_company_info')->insert([
|
||||
[
|
||||
'Id' => 21,
|
||||
'businessLicenseName' => '排序公司甲',
|
||||
'legalRepresentative' => '鲍法人',
|
||||
],
|
||||
[
|
||||
'Id' => 22,
|
||||
'businessLicenseName' => '排序公司乙',
|
||||
'legalRepresentative' => '安法人',
|
||||
],
|
||||
]);
|
||||
|
||||
$sort = function (string $field, string $direction = 'asc'): array {
|
||||
$response = $this->loginAs()->get($this->keepTasksUrl([
|
||||
'keep_sort' => $field,
|
||||
'keep_direction' => $direction,
|
||||
]))->assertOk();
|
||||
preg_match_all('/data-keep-account="([^"]+)"/u', $response->getContent(), $matches);
|
||||
|
||||
return $matches[1];
|
||||
};
|
||||
|
||||
$this->assertSame(['排序账户乙', '排序账户甲'], $sort('legal_representative'));
|
||||
$this->assertSame(['排序账户甲', '排序账户乙'], $sort('account_type'));
|
||||
$this->assertSame(['排序账户乙', '排序账户甲'], $sort('account_status'));
|
||||
$this->assertSame(['排序账户乙', '排序账户甲'], $sort('current_progress'));
|
||||
$this->assertSame(['排序账户甲', '排序账户乙'], $sort('current_progress', 'desc'));
|
||||
}
|
||||
|
||||
public function test_keep_tasks_header_filters_apply_with_typeahead_options(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user