feat: 费用明细增加税务类型和公司主体 (#1311)
This commit is contained in:
parent
27a025a33d
commit
9de660ae55
@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use Modules\EcommerceFinance\Services\AccountLedgerRemarkMap;
|
||||
use Modules\EcommerceFinance\Services\AccountMappingMatcher;
|
||||
use Modules\EcommerceFinance\Services\AccountMappingStore;
|
||||
use Modules\EcommerceFinance\Services\PerformanceDetailSubjectMatcher;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@ -24,6 +25,8 @@ class BillingDetailsPageData
|
||||
{
|
||||
private const EXPENSE_FORCED_FILTERS = ['type' => ['费用']];
|
||||
|
||||
private ?PerformanceDetailSubjectMatcher $subjectMatcher = null;
|
||||
|
||||
/**
|
||||
* 各平台账单表;periods 非空表示该表按 active_generation 区分版本,必须用 periods 表锁定当前版本。
|
||||
*/
|
||||
@ -87,7 +90,7 @@ class BillingDetailsPageData
|
||||
'columns' => self::COLUMNS,
|
||||
'pageTitle' => '费用明细',
|
||||
'expenseOnly' => true,
|
||||
] + $this->data(null, self::EXPENSE_FORCED_FILTERS);
|
||||
] + $this->data(null, self::EXPENSE_FORCED_FILTERS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,10 +113,12 @@ class BillingDetailsPageData
|
||||
'remark' => ['备注', 'text'],
|
||||
];
|
||||
|
||||
/** 费用明细精简列:平台、店铺、线上单号、账单费用、收支净额。 */
|
||||
/** 费用明细精简列:平台、店铺、当前主体资料、线上单号、账单费用、收支净额。 */
|
||||
public const EXPENSE_COLUMNS = [
|
||||
'platform' => ['平台', 'text'],
|
||||
'store_name' => ['店铺', 'text'],
|
||||
'taxpayer_type' => ['税务类型', 'text'],
|
||||
'company_name' => ['公司主体', 'text'],
|
||||
'online_order_no' => ['线上单号', 'text'],
|
||||
'finance_remark' => ['账单费用', 'text'],
|
||||
'amount' => ['金额(收-支)', 'num'],
|
||||
@ -183,6 +188,14 @@ class BillingDetailsPageData
|
||||
{
|
||||
$connection = $this->connection();
|
||||
$rules = $this->rules();
|
||||
$withStoreSubjects = isset($columns['taxpayer_type']) || isset($columns['company_name']);
|
||||
$subjectMap = $withStoreSubjects
|
||||
? $this->storeSubjectMap(
|
||||
$filters['store'] !== []
|
||||
? $filters['store']
|
||||
: ($this->options()['stores'] ?? []),
|
||||
)
|
||||
: [];
|
||||
|
||||
foreach (self::SOURCES as $label => $meta) {
|
||||
$branch = $this->branch($label, $meta, $filters);
|
||||
@ -195,7 +208,10 @@ class BillingDetailsPageData
|
||||
. ' ORDER BY ' . $branch['date'] . ' DESC, record_code DESC',
|
||||
$scope['bind']
|
||||
) as $raw) {
|
||||
yield $this->presentRow((array) $raw, $rules);
|
||||
$row = $this->presentRow((array) $raw, $rules);
|
||||
yield $withStoreSubjects
|
||||
? $this->applySubjectRow($row, $subjectMap)
|
||||
: $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,6 +230,7 @@ class BillingDetailsPageData
|
||||
$pick = static fn (?string $column): ?string => $column !== null && $column !== '' ? $column : null;
|
||||
$want = array_flip(array_keys($columns));
|
||||
$finance = isset($want['finance_remark']) || isset($want['finance_type']);
|
||||
$subject = isset($want['company_name']) || isset($want['taxpayer_type']);
|
||||
|
||||
$select = [];
|
||||
$add = static function (string $alias, ?string $expr) use (&$select): void {
|
||||
@ -224,7 +241,7 @@ class BillingDetailsPageData
|
||||
};
|
||||
|
||||
if (isset($want['record_code'])) { $add('record_code', 'record_code'); }
|
||||
if (isset($want['store_name']) || $finance) { $add('store_name', 'store_name'); }
|
||||
if (isset($want['store_name']) || $finance || $subject) { $add('store_name', 'store_name'); }
|
||||
if (isset($want['bill_item']) || $finance) { $add('bill_item', 'bill_item'); }
|
||||
if (isset($want['online_order_no'])) { $add('online_order_no', $pick(is_string($meta['online_order']) ? (string) $meta['online_order'] : null)); }
|
||||
if (isset($want['merchant_order_no'])) { $add('merchant_order_no', $pick(is_string($meta['merchant_order']) ? (string) $meta['merchant_order'] : null)); }
|
||||
@ -282,7 +299,7 @@ class BillingDetailsPageData
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function data(?array $input = null, array $forcedFilters = []): array
|
||||
public function data(?array $input = null, array $forcedFilters = [], bool $withStoreSubjects = false): array
|
||||
{
|
||||
$input ??= request()->all();
|
||||
$filters = array_replace($this->parseFilters($input), $forcedFilters);
|
||||
@ -348,6 +365,12 @@ class BillingDetailsPageData
|
||||
|
||||
$rules = $this->rules();
|
||||
$rows = array_map(fn ($row): array => $this->presentRow((array) $row, $rules), $rows);
|
||||
if ($withStoreSubjects) {
|
||||
$rows = $this->applySubjectColumns(
|
||||
$rows,
|
||||
$this->storeSubjectMap(array_column($rows, 'store_name')),
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'filters' => $filters,
|
||||
@ -1419,6 +1442,65 @@ class BillingDetailsPageData
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string,mixed>> $rows
|
||||
* @param array{
|
||||
* current_companies:array<string,string>,
|
||||
* taxpayer_types:array<string,string>,
|
||||
* company_plan_shops:array<string,array<string,mixed>>
|
||||
* } $subjectMap
|
||||
* @return list<array<string,mixed>>
|
||||
*/
|
||||
private function applySubjectColumns(array $rows, array $subjectMap): array
|
||||
{
|
||||
return array_map(
|
||||
fn (array $row): array => $this->applySubjectRow($row, $subjectMap),
|
||||
$rows,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $row
|
||||
* @param array{
|
||||
* current_companies:array<string,string>,
|
||||
* taxpayer_types:array<string,string>,
|
||||
* company_plan_shops:array<string,array<string,mixed>>
|
||||
* } $subjectMap
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function applySubjectRow(array $row, array $subjectMap): array
|
||||
{
|
||||
if (($subjectMap['current_companies'] ?? []) === []) {
|
||||
return $row + ['taxpayer_type' => '', 'company_name' => ''];
|
||||
}
|
||||
|
||||
$this->subjectMatcher ??= app(PerformanceDetailSubjectMatcher::class);
|
||||
|
||||
return $this->subjectMatcher->applyArray($row, $subjectMap);
|
||||
}
|
||||
|
||||
/** @param list<string> $storeNames */
|
||||
private function storeSubjectMap(array $storeNames): array
|
||||
{
|
||||
$names = array_values(array_unique(array_filter(array_map(
|
||||
static fn (mixed $name): string => trim((string) $name),
|
||||
$storeNames,
|
||||
))));
|
||||
if ($names === []) {
|
||||
return ['current_companies' => [], 'taxpayer_types' => [], 'company_plan_shops' => []];
|
||||
}
|
||||
sort($names, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
$companyId = (int) (company_id() ?: 1);
|
||||
$cacheKey = 'billing-details-store-subject-map-v1:'
|
||||
. $companyId . ':' . sha1(implode("\n", $names));
|
||||
|
||||
return cache()->remember(
|
||||
$cacheKey,
|
||||
now()->addMinutes(5),
|
||||
static fn (): array => app(PerformanceDetailSubjectMatcher::class)->map($names, $companyId),
|
||||
);
|
||||
}
|
||||
|
||||
private function normalizedItemSql(): string
|
||||
{
|
||||
return "(CASE WHEN bill_item LIKE 'wx%' THEN LTRIM(SUBSTRING(bill_item, 3)) ELSE bill_item END)";
|
||||
|
||||
@ -169,6 +169,7 @@
|
||||
数据源=各平台已导入账单(与「店铺收款账户账单」同源);<b>财务备注</b>、<b>财务类型</b>由科目映射表按「平台+账单项目(wx 自动去前缀)」带出,匹配不到的留空并标红。
|
||||
@if ($expenseOnly)
|
||||
本页只展示科目映射表中<b>财务类型=费用</b>的账单;费用按<b>账单费用</b>分类汇总,金额单位为<b>万</b>。
|
||||
<b>税务类型</b>和<b>公司主体</b>按店铺当前存续主体带出。
|
||||
@else
|
||||
同一交易单号跨月合并后已与订单实付对平的,差额备注优先显示为<b>差额=跨月收款(合并已对平)</b>;未对平仍显示<b>差额待核实</b>。
|
||||
@endif
|
||||
@ -406,6 +407,7 @@
|
||||
<tr>
|
||||
@if ($expenseOnly)
|
||||
<th data-col="platform">平台</th><th data-col="store_name">店铺</th>
|
||||
<th data-col="taxpayer_type">税务类型</th><th data-col="company_name">公司主体</th>
|
||||
<th data-col="online_order_no">线上单号</th><th data-col="finance_remark">账单费用</th>
|
||||
<th data-col="amount">金额(收-支)</th>
|
||||
@else
|
||||
@ -423,6 +425,8 @@
|
||||
@if ($expenseOnly)
|
||||
<td data-col="platform">{{ $row['platform'] }}</td>
|
||||
<td data-col="store_name">{{ $row['store_name'] }}</td>
|
||||
<td data-col="taxpayer_type">{{ $row['taxpayer_type'] ?? '' }}</td>
|
||||
<td data-col="company_name">{{ $row['company_name'] ?? '' }}</td>
|
||||
<td data-col="online_order_no">{{ $row['online_order_no'] }}</td>
|
||||
<td data-col="finance_remark">{!! $row['finance_remark'] !== '' ? e($row['finance_remark']) : '<span class="pd-miss">—</span>' !!}</td>
|
||||
<td data-col="amount" class="num">{{ number_format((float) $row['income'] - (float) $row['expense'], 2) }}</td>
|
||||
@ -444,7 +448,7 @@
|
||||
@endif
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="{{ $expenseOnly ? 5 : 14 }}" style="text-align:center;color:#8a8377;padding:1.5rem;">当前条件下没有数据。</td></tr>
|
||||
<tr><td colspan="{{ $expenseOnly ? 7 : 14 }}" style="text-align:center;color:#8a8377;padding:1.5rem;">当前条件下没有数据。</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -30,6 +30,8 @@ class ExpenseDetailsDrilldownPageTest extends FeatureTestCase
|
||||
$template = (string) file_get_contents(resource_path(
|
||||
'views/business/pages/financial-operations/billing-details.blade.php',
|
||||
));
|
||||
$this->assertStringContainsString('data-col="taxpayer_type">税务类型</th>', $template);
|
||||
$this->assertStringContainsString('data-col="company_name">公司主体</th>', $template);
|
||||
$this->assertSame(1, preg_match(
|
||||
'/<table class="pd-table">\s*<thead>\s*<tr>\s*@if \(\$expenseOnly\)(.*?)@else/s',
|
||||
$template,
|
||||
@ -39,6 +41,8 @@ class ExpenseDetailsDrilldownPageTest extends FeatureTestCase
|
||||
$this->assertSame([
|
||||
'platform',
|
||||
'store_name',
|
||||
'taxpayer_type',
|
||||
'company_name',
|
||||
'online_order_no',
|
||||
'finance_remark',
|
||||
'amount',
|
||||
|
||||
@ -19,6 +19,8 @@ class BillingDetailsExpenseFilterTest extends TestCase
|
||||
$this->assertSame([
|
||||
'platform',
|
||||
'store_name',
|
||||
'taxpayer_type',
|
||||
'company_name',
|
||||
'online_order_no',
|
||||
'finance_remark',
|
||||
'amount',
|
||||
@ -29,6 +31,29 @@ class BillingDetailsExpenseFilterTest extends TestCase
|
||||
$this->assertSame('账单费用', BillingDetailsPageData::EXPENSE_COLUMNS['finance_remark'][0]);
|
||||
}
|
||||
|
||||
public function test_expense_rows_include_current_company_and_taxpayer_type(): void
|
||||
{
|
||||
$data = app(BillingDetailsPageData::class);
|
||||
$apply = new ReflectionMethod(BillingDetailsPageData::class, 'applySubjectRow');
|
||||
$apply->setAccessible(true);
|
||||
|
||||
$row = $apply->invoke($data, [
|
||||
'store_name' => '天猫-亿家达旗舰店',
|
||||
'online_order_no' => '512789121088013442',
|
||||
], [
|
||||
'current_companies' => [
|
||||
'天猫-亿家达旗舰店' => '常州市测试家居有限公司',
|
||||
],
|
||||
'taxpayer_types' => [
|
||||
'常州市测试家居有限公司' => '一般纳税人',
|
||||
],
|
||||
'company_plan_shops' => [],
|
||||
]);
|
||||
|
||||
$this->assertSame('一般纳税人', $row['taxpayer_type']);
|
||||
$this->assertSame('常州市测试家居有限公司', $row['company_name']);
|
||||
}
|
||||
|
||||
public function test_ledger_memo_totals_split_invoice_buckets(): void
|
||||
{
|
||||
$data = app(BillingDetailsPageData::class);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user