Merge remote-tracking branch 'origin/main' into feature/yueyang-systemization-todo-structured-editing
This commit is contained in:
commit
33acf737e3
@ -76,9 +76,6 @@ class BusinessSummaryCards
|
||||
$normalStores = (int) ($summary['normal_stores'] ?? 0);
|
||||
$previousStores = (int) ($summary['previous_month_stores'] ?? 0);
|
||||
$currentStores = (int) ($summary['current_month_stores'] ?? 0);
|
||||
$previousShare = $normalStores > 0
|
||||
? number_format($previousStores / $normalStores * 100, 1) . '%'
|
||||
: '0.0%';
|
||||
|
||||
return [
|
||||
$this->card('正常存续店铺', $normalStores, '只统计开店中店铺,不含关店和已注销', ['status' => '0'], 'integer', 'accent'),
|
||||
@ -92,16 +89,6 @@ class BusinessSummaryCards
|
||||
'sort' => $summary['current_month_key'] ?? null,
|
||||
'direction' => 'desc',
|
||||
], 'amount', 'warning'),
|
||||
$this->card($previousLabel . '有销量店铺', $previousStores, '占正常存续店铺 ' . $previousShare, [
|
||||
'status' => '0',
|
||||
'sort' => $summary['previous_month_key'] ?? null,
|
||||
'direction' => 'desc',
|
||||
]),
|
||||
$this->card($currentLabel . '有销量店铺', $currentStores, $currentStores === 0 ? '当前还未同步当月销量' : '正常存续店铺中当月已有销量', [
|
||||
'status' => '0',
|
||||
'sort' => $summary['current_month_key'] ?? null,
|
||||
'direction' => 'desc',
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
@ -143,7 +130,7 @@ class BusinessSummaryCards
|
||||
$this->card('数据状态', '待取数', '规则已定义,业务数据尚未接入', [], 'text', 'warning'),
|
||||
$this->card('完整表头', '22 列', '包含序号、征管口径、收入、税额与备注', [], 'text'),
|
||||
$this->card('计算税种', '4 类', '增值税、附加税、印花税、所得税', [], 'text'),
|
||||
$this->card('必补口径', '2 项', '工商类型与征收方式', [], 'text', 'warning'),
|
||||
$this->card('计税口径', '3 项', '公司税务类型、工商类型和征收方式', [], 'text'),
|
||||
$this->card('当前记录', '0 条', '数据接入后按完整字段展示', [], 'text'),
|
||||
];
|
||||
}
|
||||
|
||||
@ -319,6 +319,12 @@ SQL);
|
||||
$filters = StoreReportRepository::requestFilters();
|
||||
$rows = $this->storeReportRows($filters);
|
||||
|
||||
// 整列为 0 的月份视为没有销量,默认隐藏;仍可从「筛选字段」手动打开。
|
||||
request()->attributes->set(
|
||||
'store-report.default_hidden_columns',
|
||||
$this->columnsWithoutData($rows, 'sales_', zeroCountsAsData: false),
|
||||
);
|
||||
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
return [
|
||||
@ -544,12 +550,20 @@ SQL);
|
||||
$row['tax_type'] = $retained
|
||||
? ($this->normalizeTaxType($taxType) ?? '待维护')
|
||||
: '/';
|
||||
$businessType = trim((string) $businessType);
|
||||
$row['business_registration_type'] = $retained
|
||||
? (trim((string) $businessType) !== '' ? trim((string) $businessType) : '待维护')
|
||||
&& in_array($businessType, ['核定', '个人独资企业'], true)
|
||||
? $businessType
|
||||
: '/';
|
||||
}
|
||||
unset($row);
|
||||
|
||||
// 整列为空的月份默认隐藏;金额 0 仍视为有账单,不隐藏。
|
||||
request()->attributes->set(
|
||||
'subject-operating-report.default_hidden_columns',
|
||||
$this->columnsWithoutData($rows, 'income_', zeroCountsAsData: true),
|
||||
);
|
||||
|
||||
$rows = array_values(array_filter($rows, fn (array $row): bool => $this->subjectMatchesFilters($row, $filters)));
|
||||
$summary = $this->subjectSummary($rows, $companyStatusReady);
|
||||
$this->sortSubjectRows($rows, $filters);
|
||||
@ -641,6 +655,36 @@ SQL);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回整列都没有数据的月份列;这类列只默认隐藏,字段和数据不会被删除。
|
||||
*
|
||||
* @param list<array<string,mixed>> $rows
|
||||
* @return list<string>
|
||||
*/
|
||||
private function columnsWithoutData(array $rows, string $prefix, bool $zeroCountsAsData): array
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$key = sprintf('%s%02d', $prefix, $month);
|
||||
foreach ($rows as $row) {
|
||||
$value = $row[$key] ?? null;
|
||||
if ($value === null || $value === '') {
|
||||
continue;
|
||||
}
|
||||
if (! $zeroCountsAsData && (float) $value === 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
$columns[] = $key;
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $row @param array<string,string> $filters */
|
||||
private function subjectMatchesFilters(array $row, array $filters): bool
|
||||
{
|
||||
@ -1024,7 +1068,9 @@ SQL);
|
||||
default => $row['company_status'] ?? null,
|
||||
};
|
||||
$businessType = trim((string) ($row['business_registration_type'] ?? ''));
|
||||
$row['business_registration_type'] = in_array($businessType, ['', '/'], true) ? null : $businessType;
|
||||
$row['business_registration_type'] = in_array($businessType, ['核定', '个人独资企业'], true)
|
||||
? $businessType
|
||||
: '/';
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
43
app/Console/Commands/ImportDingProcessDetails.php
Normal file
43
app/Console/Commands/ImportDingProcessDetails.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorImporter;
|
||||
use Throwable;
|
||||
|
||||
class ImportDingProcessDetails extends Command
|
||||
{
|
||||
protected $signature = 'ding:import-process-details
|
||||
{file : 15 列流程明细 CSV 文件路径}
|
||||
{--scope=personal_permission : 数据权限范围标识}
|
||||
{--replace : 导入前清空同一范围的数据}';
|
||||
|
||||
protected $description = '导入钉钉流程明细到共享业务镜像';
|
||||
|
||||
public function handle(DingProcessDetailMirrorImporter $importer): int
|
||||
{
|
||||
try {
|
||||
$result = $importer->import(
|
||||
(string) $this->argument('file'),
|
||||
(string) $this->option('scope'),
|
||||
(bool) $this->option('replace'),
|
||||
);
|
||||
} catch (Throwable $exception) {
|
||||
$this->error('导入失败:' . $exception->getMessage());
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info(sprintf(
|
||||
'导入完成:%d 行,跳过占位 %d 行,跳过无效 %d 行,重复 %d 行,范围 %s。',
|
||||
$result['rows'],
|
||||
$result['placeholders'],
|
||||
$result['invalid'],
|
||||
$result['duplicates'],
|
||||
$result['scope'],
|
||||
));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,29 @@ class BusinessNavigation
|
||||
public static function all(): array
|
||||
{
|
||||
$navigation = config('business_navigation', []);
|
||||
$pageExtensions = (array) config('business_navigation_page_extensions', []);
|
||||
|
||||
foreach ($navigation as &$section) {
|
||||
$sectionSlug = (string) ($section['slug'] ?? '');
|
||||
|
||||
foreach ((array) ($pageExtensions[$sectionSlug] ?? []) as $extension) {
|
||||
$extensionSlug = trim((string) ($extension['slug'] ?? ''));
|
||||
|
||||
if ($extensionSlug === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$exists = collect($section['pages'] ?? [])->contains(
|
||||
static fn (array $page): bool => (string) ($page['slug'] ?? '') === $extensionSlug
|
||||
);
|
||||
|
||||
if (! $exists) {
|
||||
$section['pages'][] = $extension;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($section);
|
||||
|
||||
$titles = (array) setting('navigation.titles', []);
|
||||
$sectionTitles = (array) ($titles['sections'] ?? []);
|
||||
$pageTitles = (array) ($titles['pages'] ?? []);
|
||||
|
||||
19
config/business_navigation_page_extensions.php
Normal file
19
config/business_navigation_page_extensions.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Module-owned page extensions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Keep additive page entries out of the shared navigation configuration.
|
||||
| Entries are appended to an existing section in configuration order.
|
||||
|
|
||||
*/
|
||||
'financial-operations' => [
|
||||
[
|
||||
'slug' => 'process-details',
|
||||
'title' => '流程明细',
|
||||
],
|
||||
],
|
||||
];
|
||||
@ -19,20 +19,20 @@ return [
|
||||
['key' => 'F', 'label' => '8月应发工资', 'group' => 'original', 'kind' => 'number'],
|
||||
['key' => 'G', 'label' => '原社保个人扣款', 'group' => 'original', 'kind' => 'number'],
|
||||
['key' => 'H', 'label' => '原公积金个人扣款', 'group' => 'original', 'kind' => 'number'],
|
||||
['key' => 'I', 'label' => '扣除额', 'group' => 'original', 'kind' => 'number'],
|
||||
['key' => 'I', 'label' => '扣除额', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=5000'],
|
||||
['key' => 'J', 'label' => '原需报个税基数', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=F#-G#-H#-I#'],
|
||||
['key' => 'K', 'label' => '原个税比列', 'group' => 'original', 'kind' => 'formula_percent', 'formula' => '=IF(J#<=0,"",IF(J#<=3000,0.03,IF(J#<=12000,0.1,IF(J#<=25000,0.2,IF(J#<=35000,0.25,IF(J#<=55000,0.3,IF(J#<=80000,0.35,0.45)))))))'],
|
||||
['key' => 'L', 'label' => '原速算扣除数', 'group' => 'original', 'kind' => 'number'],
|
||||
['key' => 'M', 'label' => '原需交个税金额', 'group' => 'original', 'kind' => 'number'],
|
||||
['key' => 'L', 'label' => '原速算扣除数', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=IF(J#<=0,"",IF(J#<=3000,0,IF(J#<=12000,210,IF(J#<=25000,1410,IF(J#<=35000,2660,IF(J#<=55000,4410,IF(J#<=80000,7160,15160)))))))'],
|
||||
['key' => 'M', 'label' => '原需交个税金额', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=J#*K#-L#'],
|
||||
['key' => 'N', 'label' => '原需年交个税金额', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=M#*12'],
|
||||
['key' => 'O', 'label' => '新公积金缴存基数', 'group' => 'fund', 'kind' => 'number'],
|
||||
['key' => 'P', 'label' => '新单位公积金月缴存12%', 'group' => 'fund', 'kind' => 'number'],
|
||||
['key' => 'Q', 'label' => '新个人公积金月缴存12%', 'group' => 'fund', 'kind' => 'number'],
|
||||
['key' => 'R', 'label' => '超额代扣缴', 'group' => 'fund', 'kind' => 'number'],
|
||||
['key' => 'O', 'label' => '新公积金缴存基数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(F#<=0,"",IF(F#<=8500,4952,IF(F#<=15000,8000,IF(F#<=25000,10000,12000))))'],
|
||||
['key' => 'P', 'label' => '新单位公积金月缴存12%', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=O#*0.12'],
|
||||
['key' => 'Q', 'label' => '新个人公积金月缴存12%', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=O#*0.12'],
|
||||
['key' => 'R', 'label' => '超额代扣缴', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=Q#-H#'],
|
||||
['key' => 'S', 'label' => '新月度应纳税所得额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=F#-G#-I#-P#-R#'],
|
||||
['key' => 'T', 'label' => '新月度个税比列', 'group' => 'fund', 'kind' => 'formula_percent', 'formula' => '=IF(S#<=0,"",IF(S#<=3000,0.03,IF(S#<=12000,0.1,IF(S#<=25000,0.2,IF(S#<=35000,0.25,IF(S#<=55000,0.3,IF(S#<=80000,0.35,0.45)))))))'],
|
||||
['key' => 'U', 'label' => '新月度新速算扣除数', 'group' => 'fund', 'kind' => 'number'],
|
||||
['key' => 'V', 'label' => '新月度个税金额', 'group' => 'fund', 'kind' => 'number'],
|
||||
['key' => 'U', 'label' => '新月度新速算扣除数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(S#<=0,"",IF(S#<=3000,0,IF(S#<=12000,210,IF(S#<=25000,1410,IF(S#<=35000,2660,IF(S#<=55000,4410,IF(S#<=80000,7160,15160)))))))'],
|
||||
['key' => 'V', 'label' => '新月度个税金额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=S#*T#-U#'],
|
||||
['key' => 'W', 'label' => '全年应纳税所得额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=S#*12'],
|
||||
['key' => 'X', 'label' => '年度税率', 'group' => 'fund', 'kind' => 'formula_percent', 'formula' => '=IF(S#=0,"",IF(W#<=0,0,IF(W#<=36000,0.03,IF(W#<=144000,0.1,IF(W#<=300000,0.2,IF(W#<=420000,0.25,IF(W#<=660000,0.3,IF(W#<=960000,0.35,0.45))))))))'],
|
||||
['key' => 'Y', 'label' => '年度速算扣除数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(W#=0,"",IF(W#<=0,0,IF(W#<=36000,0,IF(W#<=144000,2520,IF(W#<=300000,16920,IF(W#<=420000,31920,IF(W#<=660000,52920,IF(W#<=960000,85920,181920))))))))'],
|
||||
@ -44,7 +44,7 @@ return [
|
||||
['key' => 'AE', 'label' => '新8月工资应发', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=F#-AD#'],
|
||||
['key' => 'AF', 'label' => '新月度应纳税所得额', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=AE#-G#-I#-P#-R#'],
|
||||
['key' => 'AG', 'label' => '新月度个税比列', 'group' => 'salary_parttime', 'kind' => 'formula_percent', 'formula' => '=IF(AF#<=0,"",IF(AF#<=3000,0.03,IF(AF#<=12000,0.1,IF(AF#<=25000,0.2,IF(AF#<=35000,0.25,IF(AF#<=55000,0.3,IF(AF#<=80000,0.35,0.45)))))))'],
|
||||
['key' => 'AH', 'label' => '新月度新速算扣除数', 'group' => 'salary_parttime', 'kind' => 'number'],
|
||||
['key' => 'AH', 'label' => '新月度新速算扣除数', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=IF(AF#<=0,"",IF(AF#<=3000,0,IF(AF#<=12000,210,IF(AF#<=25000,1410,IF(AF#<=35000,2660,IF(AF#<=55000,4410,IF(AF#<=80000,7160,15160)))))))'],
|
||||
['key' => 'AI', 'label' => '新月度个税金额', 'group' => 'salary_parttime', 'kind' => 'number'],
|
||||
['key' => 'AJ', 'label' => '全年应纳税所得额', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=AF#*12'],
|
||||
['key' => 'AK', 'label' => '年度税率', 'group' => 'salary_parttime', 'kind' => 'formula_percent', 'formula' => '=IF(AJ#=0,"",IF(AJ#<=0,0,IF(AJ#<=36000,0.03,IF(AJ#<=144000,0.1,IF(AJ#<=300000,0.2,IF(AJ#<=420000,0.25,IF(AJ#<=660000,0.3,IF(AJ#<=960000,0.35,0.45))))))))'],
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
<?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
|
||||
{
|
||||
if (app()->environment('testing')
|
||||
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema = Schema::connection($this->connection());
|
||||
|
||||
if ($schema->hasTable('ding_process_detail_mirror')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema->create('ding_process_detail_mirror', function (Blueprint $table): void {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('business_id', 32);
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6)->index();
|
||||
$table->string('originator_name', 100)->nullable()->index();
|
||||
$table->string('status', 20)->nullable()->index();
|
||||
$table->string('document_type', 100)->nullable()->index();
|
||||
$table->text('purpose')->nullable();
|
||||
$table->string('account_code', 64)->nullable();
|
||||
$table->string('account_name', 255)->nullable();
|
||||
$table->decimal('amount', 18, 2)->nullable();
|
||||
$table->string('bank_account_code', 255)->nullable();
|
||||
$table->string('bank_account_name', 255)->nullable();
|
||||
$table->decimal('bank_amount', 18, 2)->nullable();
|
||||
$table->string('payment_method', 50)->nullable();
|
||||
$table->string('paid_at', 50)->nullable();
|
||||
$table->string('source_scope', 40)->default('personal_permission')->index();
|
||||
$table->dateTime('synced_at', 6);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(
|
||||
['business_id', 'line_no'],
|
||||
'ding_process_detail_business_line_unique',
|
||||
);
|
||||
$table->index(
|
||||
['business_month', 'document_type'],
|
||||
'ding_process_detail_month_type_index',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (app()->environment('testing')
|
||||
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::connection($this->connection())->dropIfExists('ding_process_detail_mirror');
|
||||
}
|
||||
};
|
||||
@ -1,4 +1,5 @@
|
||||
[
|
||||
"ding:import-process-details",
|
||||
"accessory-reship:import-courier-configs",
|
||||
"account-ledger-remarks:import",
|
||||
"account-mapping:import-files",
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
| 2 | 主体 | 主体名称;作为主体合并键 |
|
||||
| 3 | 公司类型 | 主体公司类型,来源于 `rpt` |
|
||||
| 4 | 税务类型 | 主体税务类型,优先读取 `fin_companies.tax_type`,缺失时使用 `rpt.fys_companyInfo.taxCategoryAndType` |
|
||||
| 5 | 工商类型 | 主体工商类型,读取 `fin_companies.business_type`;空值或 `/` 按统一缺失值展示 |
|
||||
| 5 | 工商类型 | 主体工商类型,读取 `fin_companies.business_type`;仅“核定”和“个人独资企业”为有效值,其他统一显示 `/` |
|
||||
| 6 | 最近12个月累计收入 | 最近12个完整自然月收入合计,排除当前月 |
|
||||
| 7 | 1月收入 | 当前年份 1 月收入,当前月或无账单时为空 |
|
||||
| 8 | 2月收入 | 当前年份 2 月收入,当前月或无账单时为空 |
|
||||
|
||||
139
modules/EcommerceFinance/Http/Controllers/ProcessDetails.php
Normal file
139
modules/EcommerceFinance/Http/Controllers/ProcessDetails.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
|
||||
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorImporter;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Throwable;
|
||||
|
||||
class ProcessDetails extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DingProcessDetailMirrorRepository $repository,
|
||||
) {}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$filters = $this->filters($request);
|
||||
$page = max((int) $request->query('page', 1), 1);
|
||||
$perPage = 50;
|
||||
|
||||
try {
|
||||
$result = $this->repository->paginate($filters, $page, $perPage);
|
||||
$options = $this->repository->filterOptions();
|
||||
|
||||
return view('business.pages.financial-operations.process-details', [
|
||||
'section' => ['slug' => 'financial-operations', 'title' => '财务经营报表'],
|
||||
'page' => ['slug' => 'process-details', 'title' => '流程明细'],
|
||||
'rows' => new LengthAwarePaginator(
|
||||
$result['data'],
|
||||
$result['total'],
|
||||
$perPage,
|
||||
$page,
|
||||
['path' => $request->url(), 'query' => $request->except('page')],
|
||||
),
|
||||
'filters' => $filters,
|
||||
'summary' => $result['summary'],
|
||||
'months' => $options['months'],
|
||||
'documentTypes' => $options['document_types'],
|
||||
'statuses' => $options['statuses'],
|
||||
'mirrorStatus' => $result['status'],
|
||||
'mirrorSyncedAt' => $result['last_synced_at'],
|
||||
'scope' => $result['scope'],
|
||||
'error' => null,
|
||||
]);
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return view('business.pages.financial-operations.process-details', [
|
||||
'section' => ['slug' => 'financial-operations', 'title' => '财务经营报表'],
|
||||
'page' => ['slug' => 'process-details', 'title' => '流程明细'],
|
||||
'rows' => new LengthAwarePaginator([], 0, $perPage, $page, [
|
||||
'path' => $request->url(),
|
||||
'query' => $request->except('page'),
|
||||
]),
|
||||
'filters' => $filters,
|
||||
'summary' => [
|
||||
'rows' => 0,
|
||||
'approvals' => 0,
|
||||
'amount_total' => 0.0,
|
||||
'bank_amount_total' => 0.0,
|
||||
],
|
||||
'months' => [],
|
||||
'documentTypes' => [],
|
||||
'statuses' => [],
|
||||
'mirrorStatus' => 'unavailable',
|
||||
'mirrorSyncedAt' => null,
|
||||
'scope' => $this->repository->scope(),
|
||||
'error' => '流程明细镜像尚未完成导入,请稍后重试。',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function export(Request $request): StreamedResponse|RedirectResponse
|
||||
{
|
||||
if (! $this->repository->ready()) {
|
||||
return redirect()
|
||||
->route('business.pages.show', [
|
||||
'section' => 'financial-operations',
|
||||
'page' => 'process-details',
|
||||
])
|
||||
->withErrors(['export' => '流程明细镜像尚未完成导入,暂时不能导出。']);
|
||||
}
|
||||
|
||||
$filters = $this->filters($request);
|
||||
|
||||
return response()->streamDownload(function () use ($filters): void {
|
||||
$stream = fopen('php://output', 'wb');
|
||||
fwrite($stream, "\xEF\xBB\xBF");
|
||||
fputcsv($stream, DingProcessDetailMirrorImporter::HEADERS);
|
||||
|
||||
$number = 0;
|
||||
foreach ($this->repository->exportRows($filters) as $row) {
|
||||
$number++;
|
||||
fputcsv($stream, [
|
||||
$number,
|
||||
(string) ($row['business_id'] ?? ''),
|
||||
(string) ($row['originator_name'] ?? ''),
|
||||
(string) ($row['status'] ?? ''),
|
||||
(string) ($row['document_type'] ?? ''),
|
||||
(string) ($row['purpose'] ?? ''),
|
||||
(int) ($row['line_no'] ?? 0),
|
||||
(string) ($row['account_code'] ?? ''),
|
||||
(string) ($row['account_name'] ?? ''),
|
||||
$row['amount'] ?? '',
|
||||
(string) ($row['bank_account_code'] ?? ''),
|
||||
(string) ($row['bank_account_name'] ?? ''),
|
||||
$row['bank_amount'] ?? '',
|
||||
(string) ($row['payment_method'] ?? ''),
|
||||
(string) ($row['paid_at'] ?? ''),
|
||||
]);
|
||||
}
|
||||
|
||||
fclose($stream);
|
||||
}, '流程明细_' . now()->format('Ymd_His') . '.csv', [
|
||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string,string> */
|
||||
private function filters(Request $request): array
|
||||
{
|
||||
$month = trim((string) $request->query('month', ''));
|
||||
$status = trim((string) $request->query('status', ''));
|
||||
|
||||
return [
|
||||
'month' => preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : '',
|
||||
'document_type' => mb_substr(trim((string) $request->query('document_type', '')), 0, 100),
|
||||
'status' => mb_substr($status, 0, 20),
|
||||
'business_id' => mb_substr(trim((string) $request->query('business_id', '')), 0, 32),
|
||||
'originator_name' => mb_substr(trim((string) $request->query('originator_name', '')), 0, 100),
|
||||
'keyword' => mb_substr(trim((string) $request->query('keyword', '')), 0, 100),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -175,7 +175,7 @@ SQL)
|
||||
->all();
|
||||
}
|
||||
|
||||
/** @return array<string,array{status:?string,tax_type:?string,business_registration_type:?string}> */
|
||||
/** @return array<string,array{status:?string,tax_type:?string,business_registration_type:string}> */
|
||||
public function companyClassificationsByNames(array $names): array
|
||||
{
|
||||
$names = array_values(array_unique(array_filter(array_map('trim', $names))));
|
||||
@ -194,7 +194,9 @@ SQL)
|
||||
return [trim((string) $row->name) => [
|
||||
'status' => $status !== '' ? $status : null,
|
||||
'tax_type' => trim((string) ($row->tax_type ?? '')) ?: null,
|
||||
'business_registration_type' => in_array($businessType, ['', '/'], true) ? null : $businessType,
|
||||
'business_registration_type' => in_array($businessType, ['核定', '个人独资企业'], true)
|
||||
? $businessType
|
||||
: '/',
|
||||
]];
|
||||
})
|
||||
->all();
|
||||
|
||||
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\Repositories;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use RuntimeException;
|
||||
|
||||
class DingProcessDetailMirrorRepository
|
||||
{
|
||||
public const DEFAULT_SCOPE = 'personal_permission';
|
||||
|
||||
public const DATASET_PREFIX = 'ding.process_details.';
|
||||
|
||||
private readonly ConnectionInterface $connection;
|
||||
|
||||
public function __construct(DatabaseManager $database)
|
||||
{
|
||||
$this->connection = $database->connection(
|
||||
(string) config('upstream_mirrors.connection', 'business_mirror')
|
||||
);
|
||||
}
|
||||
|
||||
public function scope(): string
|
||||
{
|
||||
$scope = trim((string) config(
|
||||
'upstream_mirrors.ding_process_details.scope',
|
||||
self::DEFAULT_SCOPE,
|
||||
));
|
||||
|
||||
return $scope !== '' ? $scope : self::DEFAULT_SCOPE;
|
||||
}
|
||||
|
||||
public function datasetKey(): string
|
||||
{
|
||||
return self::DATASET_PREFIX . $this->scope();
|
||||
}
|
||||
|
||||
public function ready(): bool
|
||||
{
|
||||
$schema = Schema::connection($this->connection->getName());
|
||||
|
||||
if (! $schema->hasTable('ding_process_detail_mirror')
|
||||
|| ! $schema->hasTable('business_mirror_table_states')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$state = $this->state();
|
||||
|
||||
return $state !== null && ($state['initial_completed_at'] ?? null) !== null;
|
||||
}
|
||||
|
||||
/** @return array<string,mixed>|null */
|
||||
public function state(): ?array
|
||||
{
|
||||
if (! Schema::connection($this->connection->getName())->hasTable('business_mirror_table_states')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = $this->connection->table('business_mirror_table_states')
|
||||
->where('dataset_key', $this->datasetKey())
|
||||
->first();
|
||||
|
||||
return $row === null ? null : (array) $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,string> $filters
|
||||
* @return array{
|
||||
* data:list<object>,
|
||||
* total:int,
|
||||
* summary:array{rows:int,approvals:int,amount_total:float,bank_amount_total:float},
|
||||
* status:string,
|
||||
* last_synced_at:?string,
|
||||
* scope:string
|
||||
* }
|
||||
*/
|
||||
public function paginate(array $filters, int $page, int $perPage): array
|
||||
{
|
||||
if (! $this->ready()) {
|
||||
throw new RuntimeException('ding_process_detail_mirror_not_ready');
|
||||
}
|
||||
|
||||
$page = max($page, 1);
|
||||
$perPage = min(max($perPage, 1), 100);
|
||||
$query = $this->filteredQuery($filters);
|
||||
|
||||
$total = (clone $query)->count();
|
||||
$summary = [
|
||||
'rows' => $total,
|
||||
'approvals' => (clone $query)->distinct()->count('business_id'),
|
||||
'amount_total' => (float) ((clone $query)->sum('amount') ?? 0),
|
||||
'bank_amount_total' => (float) ((clone $query)->sum('bank_amount') ?? 0),
|
||||
];
|
||||
$data = $query
|
||||
->orderByDesc('business_month')
|
||||
->orderByDesc('business_id')
|
||||
->orderBy('line_no')
|
||||
->forPage($page, $perPage)
|
||||
->get()
|
||||
->all();
|
||||
$state = $this->state();
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'total' => $total,
|
||||
'summary' => $summary,
|
||||
'status' => (string) ($state['status'] ?? 'unknown'),
|
||||
'last_synced_at' => isset($state['last_succeeded_at'])
|
||||
? (string) $state['last_succeeded_at']
|
||||
: null,
|
||||
'scope' => $this->scope(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{months:list<string>,document_types:list<string>,statuses:list<string>} */
|
||||
public function filterOptions(): array
|
||||
{
|
||||
if (! Schema::connection($this->connection->getName())->hasTable('ding_process_detail_mirror')) {
|
||||
return ['months' => [], 'document_types' => [], 'statuses' => []];
|
||||
}
|
||||
|
||||
$base = $this->connection->table('ding_process_detail_mirror')
|
||||
->where('source_scope', $this->scope());
|
||||
|
||||
return [
|
||||
'months' => (clone $base)
|
||||
->whereNotNull('business_month')
|
||||
->where('business_month', '!=', '')
|
||||
->distinct()
|
||||
->orderByDesc('business_month')
|
||||
->pluck('business_month')
|
||||
->map(static function (mixed $value): string {
|
||||
$month = (string) $value;
|
||||
|
||||
return preg_match('/^\d{6}$/', $month) === 1
|
||||
? substr($month, 0, 4) . '-' . substr($month, 4, 2)
|
||||
: $month;
|
||||
})
|
||||
->all(),
|
||||
'document_types' => (clone $base)
|
||||
->whereNotNull('document_type')
|
||||
->where('document_type', '!=', '')
|
||||
->distinct()
|
||||
->orderBy('document_type')
|
||||
->pluck('document_type')
|
||||
->map(static fn (mixed $value): string => (string) $value)
|
||||
->all(),
|
||||
'statuses' => (clone $base)
|
||||
->whereNotNull('status')
|
||||
->where('status', '!=', '')
|
||||
->distinct()
|
||||
->orderBy('status')
|
||||
->pluck('status')
|
||||
->map(static fn (mixed $value): string => (string) $value)
|
||||
->all(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @param array<string,string> $filters */
|
||||
public function exportCount(array $filters): int
|
||||
{
|
||||
if (! Schema::connection($this->connection->getName())->hasTable('ding_process_detail_mirror')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) $this->filteredQuery($filters)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,string> $filters
|
||||
* @return \Generator<int,array<string,mixed>>
|
||||
*/
|
||||
public function exportRows(array $filters): \Generator
|
||||
{
|
||||
$query = $this->filteredQuery($filters)
|
||||
->orderByDesc('business_month')
|
||||
->orderByDesc('business_id')
|
||||
->orderBy('line_no');
|
||||
|
||||
foreach ($query->cursor() as $row) {
|
||||
yield (array) $row;
|
||||
}
|
||||
}
|
||||
|
||||
/** @param array<string,string> $filters */
|
||||
private function filteredQuery(array $filters): Builder
|
||||
{
|
||||
$query = $this->connection->table('ding_process_detail_mirror')
|
||||
->where('source_scope', $this->scope());
|
||||
|
||||
$month = trim((string) ($filters['month'] ?? ''));
|
||||
if (preg_match('/^\d{4}-\d{2}$/', $month) === 1) {
|
||||
$query->where('business_month', str_replace('-', '', $month));
|
||||
}
|
||||
|
||||
foreach ([
|
||||
'document_type' => 'document_type',
|
||||
'status' => 'status',
|
||||
] as $filter => $column) {
|
||||
$value = trim((string) ($filters[$filter] ?? ''));
|
||||
if ($value !== '') {
|
||||
$query->where($column, $value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ([
|
||||
'business_id' => 'business_id',
|
||||
'originator_name' => 'originator_name',
|
||||
'keyword' => 'purpose',
|
||||
] as $filter => $column) {
|
||||
$value = mb_substr(trim((string) ($filters[$filter] ?? '')), 0, 100);
|
||||
if ($value !== '') {
|
||||
$query->where($column, 'like', '%' . $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\EcommerceFinance\Http\Controllers\ProcessDetails;
|
||||
|
||||
Route::admin('ecommerce-finance', function () {
|
||||
Route::view('/', 'ecommerce-finance::index')->name('index');
|
||||
});
|
||||
|
||||
// 通用 workspace/{section}/{page} 路由在 App\Providers\Route::boot() 中注册;
|
||||
// 模块路由在 register 阶段先注册,因此这里的精确路由会优先命中。沿用
|
||||
// business.pages.show 名称,侧边栏仍能生成与通用页面一致的可访问 URL。
|
||||
Route::admin('ecommerce-finance', function (): void {
|
||||
Route::get('workspace/financial-operations/process-details', [ProcessDetails::class, 'show'])
|
||||
->middleware('business.page.viewer')
|
||||
->defaults('section', 'financial-operations')
|
||||
->defaults('page', 'process-details')
|
||||
->name('business.pages.show');
|
||||
|
||||
Route::get('workspace/financial-operations/process-details/export', [ProcessDetails::class, 'export'])
|
||||
->middleware('business.page.viewer')
|
||||
->defaults('section', 'financial-operations')
|
||||
->defaults('page', 'process-details')
|
||||
->name('business.process-details.export');
|
||||
}, ['prefix' => '', 'as' => '']);
|
||||
|
||||
@ -0,0 +1,282 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\Services;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
|
||||
class DingProcessDetailMirrorImporter
|
||||
{
|
||||
public const DATASET_PREFIX = 'ding.process_details.';
|
||||
|
||||
public const DEFAULT_SCOPE = 'personal_permission';
|
||||
|
||||
public const HEADERS = [
|
||||
'序号',
|
||||
'审批编号',
|
||||
'发起人',
|
||||
'状态',
|
||||
'单据类型',
|
||||
'用途/摘要',
|
||||
'单据内行号',
|
||||
'科目编码',
|
||||
'科目名称',
|
||||
'金额(元)',
|
||||
'银行科目编码',
|
||||
'银行科目名称',
|
||||
'银行付款金额',
|
||||
'付款方式',
|
||||
'打款时间',
|
||||
];
|
||||
|
||||
private readonly ConnectionInterface $connection;
|
||||
|
||||
public function __construct(DatabaseManager $database)
|
||||
{
|
||||
$this->connection = $database->connection(
|
||||
(string) config('upstream_mirrors.connection', 'business_mirror')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status:string,rows:int,invalid:int,placeholders:int,duplicates:int,scope:string,dataset_key:string}
|
||||
*/
|
||||
public function import(
|
||||
string $path,
|
||||
string $scope = self::DEFAULT_SCOPE,
|
||||
bool $replace = false,
|
||||
): array {
|
||||
$scope = trim($scope) !== '' ? trim($scope) : self::DEFAULT_SCOPE;
|
||||
|
||||
if (! is_file($path)) {
|
||||
throw new RuntimeException('流程明细 CSV 文件不存在:' . $path);
|
||||
}
|
||||
|
||||
[$rows, $invalid, $placeholders, $duplicates] = $this->readCsv($path, $scope);
|
||||
|
||||
if ($rows === []) {
|
||||
throw new RuntimeException('流程明细 CSV 没有可导入的数据。');
|
||||
}
|
||||
|
||||
$now = now();
|
||||
$datasetKey = self::DATASET_PREFIX . $scope;
|
||||
$generation = (string) Str::uuid();
|
||||
$upserted = 0;
|
||||
|
||||
$this->connection->transaction(function () use (
|
||||
$rows,
|
||||
$replace,
|
||||
$scope,
|
||||
$now,
|
||||
$generation,
|
||||
&$upserted,
|
||||
): void {
|
||||
if ($replace) {
|
||||
$this->connection->table('ding_process_detail_mirror')
|
||||
->where('source_scope', $scope)
|
||||
->delete();
|
||||
}
|
||||
|
||||
foreach (array_chunk($rows, 500) as $chunk) {
|
||||
$this->connection->table('ding_process_detail_mirror')->upsert(
|
||||
$chunk,
|
||||
['business_id', 'line_no'],
|
||||
[
|
||||
'business_month',
|
||||
'originator_name',
|
||||
'status',
|
||||
'document_type',
|
||||
'purpose',
|
||||
'account_code',
|
||||
'account_name',
|
||||
'amount',
|
||||
'bank_account_code',
|
||||
'bank_account_name',
|
||||
'bank_amount',
|
||||
'payment_method',
|
||||
'paid_at',
|
||||
'source_scope',
|
||||
'synced_at',
|
||||
'updated_at',
|
||||
],
|
||||
);
|
||||
$upserted += count($chunk);
|
||||
}
|
||||
});
|
||||
|
||||
$rowCount = (int) $this->connection->table('ding_process_detail_mirror')
|
||||
->where('source_scope', $scope)
|
||||
->count();
|
||||
$values = [
|
||||
'source_key' => 'dingtalk_oa',
|
||||
'source_object' => $scope === self::DEFAULT_SCOPE
|
||||
? 'oa approval detail (personal permission scope)'
|
||||
: 'oa approval detail (' . $scope . ')',
|
||||
'target_table' => 'ding_process_detail_mirror',
|
||||
'status' => 'succeeded',
|
||||
'run_mode' => 'full',
|
||||
'generation' => $generation,
|
||||
'cursor' => null,
|
||||
'high_watermark' => null,
|
||||
'window_started_at' => null,
|
||||
'window_ends_at' => null,
|
||||
'initial_completed_at' => $now,
|
||||
'last_full_succeeded_at' => $now,
|
||||
'last_attempted_at' => $now,
|
||||
'last_succeeded_at' => $now,
|
||||
'last_upserted_rows' => $upserted,
|
||||
'mirror_row_count' => $rowCount,
|
||||
'last_error_code' => null,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
|
||||
$this->connection->table('business_mirror_table_states')->updateOrInsert(
|
||||
['dataset_key' => $datasetKey],
|
||||
$values + ['created_at' => $now],
|
||||
);
|
||||
|
||||
return [
|
||||
'status' => 'succeeded',
|
||||
'rows' => $upserted,
|
||||
'invalid' => $invalid,
|
||||
'placeholders' => $placeholders,
|
||||
'duplicates' => $duplicates,
|
||||
'scope' => $scope,
|
||||
'dataset_key' => $datasetKey,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0:list<array<string,mixed>>,1:int,2:int,3:int}
|
||||
*/
|
||||
private function readCsv(string $path, string $scope): array
|
||||
{
|
||||
$handle = fopen($path, 'rb');
|
||||
|
||||
if ($handle === false) {
|
||||
throw new RuntimeException('流程明细 CSV 无法打开:' . $path);
|
||||
}
|
||||
|
||||
try {
|
||||
$header = fgetcsv($handle);
|
||||
|
||||
if ($header === false) {
|
||||
throw new RuntimeException('流程明细 CSV 缺少表头。');
|
||||
}
|
||||
|
||||
$header[0] = preg_replace('/^\xEF\xBB\xBF/', '', (string) $header[0]);
|
||||
$header = array_map(static fn (mixed $value): string => trim((string) $value), $header);
|
||||
$missing = array_values(array_diff(self::HEADERS, $header));
|
||||
|
||||
if ($missing !== []) {
|
||||
throw new RuntimeException('流程明细 CSV 缺少列:' . implode('、', $missing));
|
||||
}
|
||||
|
||||
$index = array_flip($header);
|
||||
$rows = [];
|
||||
$qualities = [];
|
||||
$invalid = 0;
|
||||
$placeholders = 0;
|
||||
$duplicates = 0;
|
||||
$now = now();
|
||||
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
if ($data === [null] || count(array_filter(
|
||||
$data,
|
||||
static fn (mixed $value): bool => trim((string) $value) !== '',
|
||||
)) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$businessId = trim((string) ($data[$index['审批编号']] ?? ''));
|
||||
$lineNo = trim((string) ($data[$index['单据内行号']] ?? ''));
|
||||
|
||||
if ($businessId === '' || preg_match('/^\d+$/', $lineNo) !== 1) {
|
||||
$invalid++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$accountCode = trim((string) ($data[$index['科目编码']] ?? ''));
|
||||
$accountName = trim((string) ($data[$index['科目名称']] ?? ''));
|
||||
$amountRaw = trim((string) ($data[$index['金额(元)']] ?? ''));
|
||||
|
||||
// 历史导入遗留的占位行:用途/科目/银行字段全部是 251,金额为空。
|
||||
if ($accountCode === '251' && $accountName === '251' && $amountRaw === '') {
|
||||
$placeholders++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = $businessId . '|' . (int) $lineNo;
|
||||
$candidate = [
|
||||
'business_id' => mb_substr($businessId, 0, 32),
|
||||
'line_no' => (int) $lineNo,
|
||||
'business_month' => preg_match('/^\d{6}/', $businessId) === 1
|
||||
? substr($businessId, 0, 6)
|
||||
: '',
|
||||
'originator_name' => mb_substr(trim((string) ($data[$index['发起人']] ?? '')), 0, 100),
|
||||
'status' => mb_substr(trim((string) ($data[$index['状态']] ?? '')), 0, 20),
|
||||
'document_type' => mb_substr(trim((string) ($data[$index['单据类型']] ?? '')), 0, 100),
|
||||
'purpose' => trim((string) ($data[$index['用途/摘要']] ?? '')),
|
||||
'account_code' => mb_substr($accountCode, 0, 64),
|
||||
'account_name' => mb_substr($accountName, 0, 255),
|
||||
'amount' => $this->decimal($data[$index['金额(元)']] ?? null),
|
||||
'bank_account_code' => mb_substr(trim((string) ($data[$index['银行科目编码']] ?? '')), 0, 255),
|
||||
'bank_account_name' => mb_substr(trim((string) ($data[$index['银行科目名称']] ?? '')), 0, 255),
|
||||
'bank_amount' => $this->decimal($data[$index['银行付款金额']] ?? null),
|
||||
'payment_method' => mb_substr(trim((string) ($data[$index['付款方式']] ?? '')), 0, 50),
|
||||
'paid_at' => mb_substr(trim((string) ($data[$index['打款时间']] ?? '')), 0, 50),
|
||||
'source_scope' => $scope,
|
||||
'synced_at' => $now,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
$quality = $this->quality($candidate);
|
||||
|
||||
if (isset($qualities[$key])) {
|
||||
$duplicates++;
|
||||
if ($quality < $qualities[$key]) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$key] = $candidate;
|
||||
$qualities[$key] = $quality;
|
||||
}
|
||||
|
||||
return [array_values($rows), $invalid, $placeholders, $duplicates];
|
||||
} finally {
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
private function decimal(mixed $value): ?string
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
|
||||
if ($value === '' || ! is_numeric($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return number_format((float) $value, 2, '.', '');
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $row */
|
||||
private function quality(array $row): int
|
||||
{
|
||||
$score = 0;
|
||||
$score += trim((string) ($row['purpose'] ?? '')) !== ''
|
||||
&& trim((string) ($row['purpose'] ?? '')) !== '251' ? 1 : 0;
|
||||
$score += trim((string) ($row['account_name'] ?? '')) !== ''
|
||||
&& trim((string) ($row['account_name'] ?? '')) !== '251' ? 1 : 0;
|
||||
$score += is_numeric($row['amount'] ?? null) && (float) $row['amount'] !== 0.0 ? 4 : 0;
|
||||
$score += trim((string) ($row['bank_account_code'] ?? '')) !== ''
|
||||
&& trim((string) ($row['bank_account_code'] ?? '')) !== '251' ? 2 : 0;
|
||||
$score += is_numeric($row['bank_amount'] ?? null) && (float) $row['bank_amount'] !== 0.0 ? 2 : 0;
|
||||
$score += trim((string) ($row['paid_at'] ?? '')) !== ''
|
||||
&& trim((string) ($row['paid_at'] ?? '')) !== '251' ? 1 : 0;
|
||||
|
||||
return $score;
|
||||
}
|
||||
}
|
||||
@ -377,7 +377,7 @@
|
||||
<div class="labor-expense-head">
|
||||
<div>
|
||||
<strong>人工费用测算表</strong>
|
||||
<p>表头与公式依据 {{ $laborExpenseTable['source_label'] ?? '工资表' }}。黄色字段用于录入,浅金列按公式实时计算;月度工资税率按月度应纳税所得额、年度税率按全年应纳税所得额匹配税法档位,公式中的 # 表示当前行。</p>
|
||||
<p>表头与公式依据 {{ $laborExpenseTable['source_label'] ?? '工资表' }}。黄色字段用于录入,浅金列按公式实时计算;月度基本减除费用为 5000 元、年度汇算为 60000 元,个税金额、税率、速算扣除数及公积金缴存基数均按对应规则自动匹配,公式中的 # 表示当前行。</p>
|
||||
</div>
|
||||
<span class="labor-expense-badge">{{ count($laborFields) }} 个业务列 · {{ $laborFormulaCount }} 个公式</span>
|
||||
</div>
|
||||
@ -506,13 +506,13 @@
|
||||
|
||||
const monthlyWageBracket = (income) => {
|
||||
if (income <= 0) return null;
|
||||
if (income <= 3000) return 0.03;
|
||||
if (income <= 12000) return 0.1;
|
||||
if (income <= 25000) return 0.2;
|
||||
if (income <= 35000) return 0.25;
|
||||
if (income <= 55000) return 0.3;
|
||||
if (income <= 80000) return 0.35;
|
||||
return 0.45;
|
||||
if (income <= 3000) return { rate: 0.03, deduction: 0 };
|
||||
if (income <= 12000) return { rate: 0.1, deduction: 210 };
|
||||
if (income <= 25000) return { rate: 0.2, deduction: 1410 };
|
||||
if (income <= 35000) return { rate: 0.25, deduction: 2660 };
|
||||
if (income <= 55000) return { rate: 0.3, deduction: 4410 };
|
||||
if (income <= 80000) return { rate: 0.35, deduction: 7160 };
|
||||
return { rate: 0.45, deduction: 15160 };
|
||||
};
|
||||
|
||||
const annualBracket = (income) => {
|
||||
@ -526,6 +526,14 @@
|
||||
return { rate: 0.45, deduction: 181920 };
|
||||
};
|
||||
|
||||
const housingFundBase = (salary) => {
|
||||
if (salary <= 0) return null;
|
||||
if (salary <= 8500) return 4952;
|
||||
if (salary <= 15000) return 8000;
|
||||
if (salary <= 25000) return 10000;
|
||||
return 12000;
|
||||
};
|
||||
|
||||
const calculate = (row) => {
|
||||
const hasNumericInput = fields.some((field) => {
|
||||
if (!numericKinds.has(field.kind)) return false;
|
||||
@ -539,9 +547,16 @@
|
||||
}
|
||||
|
||||
const v = (key) => numeric(row[key]);
|
||||
const originalTaxable = v('F') - v('G') - v('H') - v('I');
|
||||
const originalAnnualTax = v('M') * 12;
|
||||
const newMonthlyTaxable = v('F') - v('G') - v('I') - v('P') - v('R');
|
||||
const monthlyBasicDeduction = 5000;
|
||||
const originalTaxable = v('F') - v('G') - v('H') - monthlyBasicDeduction;
|
||||
const newHousingFundBase = housingFundBase(v('F'));
|
||||
const newEmployerHousingFund = newHousingFundBase === null ? null : newHousingFundBase * 0.12;
|
||||
const newPersonalHousingFund = newHousingFundBase === null ? null : newHousingFundBase * 0.12;
|
||||
const excessHousingFundWithholding = newPersonalHousingFund === null
|
||||
? null
|
||||
: newPersonalHousingFund - v('H');
|
||||
const newMonthlyTaxable = v('F') - v('G') - monthlyBasicDeduction
|
||||
- numeric(newEmployerHousingFund) - numeric(excessHousingFundWithholding);
|
||||
const newAnnualTaxable = newMonthlyTaxable * 12;
|
||||
const newAnnualBracket = annualBracket(newAnnualTaxable);
|
||||
const originalRate = newMonthlyTaxable === 0 ? null : newAnnualBracket.rate;
|
||||
@ -549,12 +564,20 @@
|
||||
const originalAnnualTaxAmount = originalRate === null || originalDeduction === null
|
||||
? null
|
||||
: newAnnualTaxable * originalRate - originalDeduction;
|
||||
const originalMonthlyRate = monthlyWageBracket(originalTaxable);
|
||||
const originalMonthlyBracket = monthlyWageBracket(originalTaxable);
|
||||
const originalMonthlyTax = originalMonthlyBracket === null
|
||||
? null
|
||||
: originalTaxable * originalMonthlyBracket.rate - originalMonthlyBracket.deduction;
|
||||
const originalAnnualTax = originalMonthlyTax === null ? null : originalMonthlyTax * 12;
|
||||
const parttimeSalary = v('AB') + v('AC');
|
||||
const newSalary = v('F') - parttimeSalary;
|
||||
const salaryTaxable = newSalary - v('G') - v('I') - v('P') - v('R');
|
||||
const newMonthlyRate = monthlyWageBracket(newMonthlyTaxable);
|
||||
const salaryMonthlyRate = monthlyWageBracket(salaryTaxable);
|
||||
const salaryTaxable = newSalary - v('G') - monthlyBasicDeduction
|
||||
- numeric(newEmployerHousingFund) - numeric(excessHousingFundWithholding);
|
||||
const newMonthlyBracket = monthlyWageBracket(newMonthlyTaxable);
|
||||
const newMonthlyTax = newMonthlyBracket === null
|
||||
? null
|
||||
: newMonthlyTaxable * newMonthlyBracket.rate - newMonthlyBracket.deduction;
|
||||
const salaryMonthlyBracket = monthlyWageBracket(salaryTaxable);
|
||||
const salaryAnnualTaxable = salaryTaxable * 12;
|
||||
const salaryBracket = annualBracket(salaryAnnualTaxable);
|
||||
const salaryRate = salaryAnnualTaxable === 0 ? null : salaryBracket.rate;
|
||||
@ -580,9 +603,11 @@
|
||||
const salaryIncome = newSalary * 12;
|
||||
const parttimeIncome = monthlyParttime * 12 * 0.8;
|
||||
const totalIncome = salaryIncome + parttimeIncome;
|
||||
const basicDeduction = 60000;
|
||||
const socialFundDeduction = (v('G') + v('P') + v('R')) * 12;
|
||||
const settlementTaxable = totalIncome - basicDeduction - socialFundDeduction;
|
||||
const annualBasicDeduction = 60000;
|
||||
const socialFundDeduction = (
|
||||
v('G') + numeric(newEmployerHousingFund) + numeric(excessHousingFundWithholding)
|
||||
) * 12;
|
||||
const settlementTaxable = totalIncome - annualBasicDeduction - socialFundDeduction;
|
||||
const settlementBracket = annualBracket(settlementTaxable);
|
||||
const settlementRate = settlementTaxable <= 0 ? null : settlementBracket.rate;
|
||||
const settlementDeduction = settlementTaxable <= 0 ? null : settlementBracket.deduction;
|
||||
@ -600,19 +625,29 @@
|
||||
: originalAnnualTaxAmount - settlementTax;
|
||||
|
||||
Object.assign(result, {
|
||||
I: monthlyBasicDeduction,
|
||||
J: originalTaxable,
|
||||
M: originalMonthlyTax,
|
||||
N: originalAnnualTax,
|
||||
O: newHousingFundBase,
|
||||
P: newEmployerHousingFund,
|
||||
Q: newPersonalHousingFund,
|
||||
R: excessHousingFundWithholding,
|
||||
S: newMonthlyTaxable,
|
||||
V: newMonthlyTax,
|
||||
W: newAnnualTaxable,
|
||||
X: originalRate,
|
||||
Y: originalDeduction,
|
||||
Z: originalAnnualTaxAmount,
|
||||
K: originalMonthlyRate,
|
||||
T: newMonthlyRate,
|
||||
K: originalMonthlyBracket?.rate ?? null,
|
||||
L: originalMonthlyBracket?.deduction ?? null,
|
||||
T: newMonthlyBracket?.rate ?? null,
|
||||
U: newMonthlyBracket?.deduction ?? null,
|
||||
AD: parttimeSalary,
|
||||
AE: newSalary,
|
||||
AF: salaryTaxable,
|
||||
AG: salaryMonthlyRate,
|
||||
AG: salaryMonthlyBracket?.rate ?? null,
|
||||
AH: salaryMonthlyBracket?.deduction ?? null,
|
||||
AJ: salaryAnnualTaxable,
|
||||
AK: salaryRate,
|
||||
AL: salaryDeduction,
|
||||
@ -628,7 +663,7 @@
|
||||
AW: salaryIncome,
|
||||
AX: parttimeIncome,
|
||||
AY: totalIncome,
|
||||
AZ: basicDeduction,
|
||||
AZ: annualBasicDeduction,
|
||||
BA: socialFundDeduction,
|
||||
BB: settlementTaxable,
|
||||
BC: settlementRate,
|
||||
|
||||
@ -0,0 +1,456 @@
|
||||
@php
|
||||
$rows = $rows ?? null;
|
||||
$filters = $filters ?? [];
|
||||
$summary = $summary ?? [];
|
||||
$months = $months ?? [];
|
||||
$documentTypes = $documentTypes ?? [];
|
||||
$statuses = $statuses ?? [];
|
||||
$error = $error ?? null;
|
||||
$scope = $scope ?? 'personal_permission';
|
||||
$scopeLabel = $scope === 'personal_permission' ? '当前账号权限范围' : $scope;
|
||||
$money = static fn (mixed $value): string => $value === null || $value === ''
|
||||
? '-'
|
||||
: number_format((float) $value, 2);
|
||||
$text = static fn (mixed $value): string => $value === null || trim((string) $value) === ''
|
||||
? '-'
|
||||
: (string) $value;
|
||||
$statusClass = static fn (string $status): string => match ($status) {
|
||||
'已完成' => 'is-success',
|
||||
'审批中' => 'is-warning',
|
||||
'已终止', '已撤销' => 'is-danger',
|
||||
default => 'is-neutral',
|
||||
};
|
||||
$pageUrl = route('business.pages.show', [
|
||||
'section' => 'financial-operations',
|
||||
'page' => 'process-details',
|
||||
]);
|
||||
$exportFilters = array_filter(
|
||||
$filters,
|
||||
static fn (mixed $value): bool => $value !== '' && $value !== null,
|
||||
);
|
||||
$exportUrl = url('/' . company_id() . '/workspace/financial-operations/process-details/export');
|
||||
if ($exportFilters !== []) {
|
||||
$exportUrl .= '?' . http_build_query($exportFilters);
|
||||
}
|
||||
@endphp
|
||||
|
||||
<x-layouts.admin>
|
||||
<x-slot name="title">
|
||||
流程明细
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="content">
|
||||
<style>
|
||||
.process-details-page {
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font-size: .8125rem;
|
||||
}
|
||||
|
||||
.process-details-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: .4rem .9rem;
|
||||
margin-bottom: .85rem;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: .75rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.process-details-meta strong {
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.process-details-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: .75rem;
|
||||
padding: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-radius: .5rem;
|
||||
background: var(--vip-surface, #fff);
|
||||
}
|
||||
|
||||
.process-details-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: .35rem;
|
||||
min-width: 10.5rem;
|
||||
}
|
||||
|
||||
.process-details-field.is-wide {
|
||||
min-width: 13.5rem;
|
||||
}
|
||||
|
||||
.process-details-field label {
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: .75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.process-details-field input,
|
||||
.process-details-field select {
|
||||
height: 2.25rem;
|
||||
padding: 0 .65rem;
|
||||
border: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-radius: .5rem;
|
||||
background: #fff;
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.process-details-field input:focus,
|
||||
.process-details-field select:focus {
|
||||
border-color: var(--vip-content-accent-dark, #856632);
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px rgba(133, 102, 50, .2);
|
||||
}
|
||||
|
||||
.process-details-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: .5rem;
|
||||
}
|
||||
|
||||
.process-details-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: .35rem;
|
||||
height: 2.25rem;
|
||||
padding: 0 .85rem;
|
||||
border: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-radius: .5rem;
|
||||
background: #fff;
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.process-details-button:hover {
|
||||
border-color: var(--vip-content-accent, #B9954F);
|
||||
color: var(--vip-content-accent-dark, #856632);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.process-details-button.is-primary {
|
||||
border-color: var(--vip-content-accent-dark, #856632);
|
||||
background: var(--vip-content-accent-dark, #856632);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.process-details-button.is-primary:hover {
|
||||
background: #6A5129;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.process-details-alert {
|
||||
padding: .75rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid var(--vip-danger, #B80000);
|
||||
border-radius: .5rem;
|
||||
background: #fff5f5;
|
||||
color: var(--vip-danger, #B80000);
|
||||
}
|
||||
|
||||
.process-details-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem 2rem;
|
||||
padding: .8rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-radius: .5rem;
|
||||
background: var(--vip-content-accent-soft, #F7F0DE);
|
||||
}
|
||||
|
||||
.process-details-summary .item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: .15rem;
|
||||
}
|
||||
|
||||
.process-details-summary .item span {
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: .7rem;
|
||||
}
|
||||
|
||||
.process-details-summary .item b {
|
||||
font-size: .95rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.process-details-note {
|
||||
margin-bottom: .75rem;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: .75rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.process-details-table-wrap {
|
||||
overflow: auto;
|
||||
max-height: min(68vh, 46rem);
|
||||
border: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-radius: .5rem;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.process-details-table {
|
||||
width: 100%;
|
||||
min-width: 112rem;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: .78rem;
|
||||
}
|
||||
|
||||
.process-details-table th,
|
||||
.process-details-table td {
|
||||
padding: .55rem .65rem;
|
||||
border-right: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-bottom: 1px solid var(--vip-border, #D8D2C7);
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.process-details-table th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background: var(--vip-content-accent-soft, #F7F0DE);
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font-size: .75rem;
|
||||
font-weight: 700;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.process-details-table tr:hover td {
|
||||
background: #fcfaf4;
|
||||
}
|
||||
|
||||
.process-details-table .num {
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.process-details-table .center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.process-details-table .wide {
|
||||
max-width: 18rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.process-details-table .wide:hover {
|
||||
overflow: visible;
|
||||
white-space: normal;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.process-details-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: .15rem .5rem;
|
||||
border-radius: 999px;
|
||||
font-size: .7rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.process-details-status.is-success {
|
||||
background: rgba(83, 121, 62, .12);
|
||||
color: var(--vip-success, #53793E);
|
||||
}
|
||||
|
||||
.process-details-status.is-warning {
|
||||
background: rgba(147, 95, 7, .12);
|
||||
color: var(--vip-warning, #935F07);
|
||||
}
|
||||
|
||||
.process-details-status.is-danger {
|
||||
background: rgba(184, 0, 0, .09);
|
||||
color: var(--vip-danger, #B80000);
|
||||
}
|
||||
|
||||
.process-details-status.is-neutral {
|
||||
background: #f1f1f1;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
}
|
||||
|
||||
.process-details-empty {
|
||||
padding: 4rem 1rem;
|
||||
text-align: center;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.process-details-footer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: .75rem;
|
||||
padding: .8rem 1rem;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: .75rem;
|
||||
}
|
||||
|
||||
.process-details-footer .pagination {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.process-details-toolbar {
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.process-details-field,
|
||||
.process-details-field.is-wide {
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.process-details-actions {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="process-details-page">
|
||||
<div class="process-details-meta">
|
||||
<span>数据范围:<strong>{{ $scopeLabel }}</strong></span>
|
||||
<span>镜像状态:<strong>{{ $mirrorStatus ?? 'unknown' }}</strong></span>
|
||||
@if (! empty($mirrorSyncedAt))
|
||||
<span>最近同步:<strong>{{ $mirrorSyncedAt }}</strong></span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if ($error)
|
||||
<div class="process-details-alert" role="alert">{{ $error }}</div>
|
||||
@endif
|
||||
|
||||
<form method="GET" action="{{ $pageUrl }}" class="process-details-toolbar" aria-label="流程明细筛选">
|
||||
<div class="process-details-field">
|
||||
<label for="process-details-month">月份</label>
|
||||
<input id="process-details-month" type="month" name="month" value="{{ $filters['month'] ?? '' }}">
|
||||
</div>
|
||||
<div class="process-details-field">
|
||||
<label for="process-details-type">单据类型</label>
|
||||
<select id="process-details-type" name="document_type">
|
||||
<option value="">全部类型</option>
|
||||
@foreach ($documentTypes as $option)
|
||||
<option value="{{ $option }}" @selected(($filters['document_type'] ?? '') === $option)>{{ $option }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="process-details-field">
|
||||
<label for="process-details-status">状态</label>
|
||||
<select id="process-details-status" name="status">
|
||||
<option value="">全部状态</option>
|
||||
@foreach ($statuses as $option)
|
||||
<option value="{{ $option }}" @selected(($filters['status'] ?? '') === $option)>{{ $option }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="process-details-field is-wide">
|
||||
<label for="process-details-business-id">审批编号</label>
|
||||
<input id="process-details-business-id" type="search" name="business_id" value="{{ $filters['business_id'] ?? '' }}" placeholder="支持包含查询">
|
||||
</div>
|
||||
<div class="process-details-field">
|
||||
<label for="process-details-originator">发起人</label>
|
||||
<input id="process-details-originator" type="search" name="originator_name" value="{{ $filters['originator_name'] ?? '' }}" placeholder="支持包含查询">
|
||||
</div>
|
||||
<div class="process-details-field is-wide">
|
||||
<label for="process-details-keyword">用途/摘要</label>
|
||||
<input id="process-details-keyword" type="search" name="keyword" value="{{ $filters['keyword'] ?? '' }}" placeholder="支持包含查询">
|
||||
</div>
|
||||
<div class="process-details-actions">
|
||||
<button class="process-details-button is-primary" type="submit">
|
||||
<span class="material-icons-outlined" aria-hidden="true">search</span>查询
|
||||
</button>
|
||||
<a class="process-details-button" href="{{ $pageUrl }}">
|
||||
<span class="material-icons-outlined" aria-hidden="true">refresh</span>重置
|
||||
</a>
|
||||
<a class="process-details-button" href="{{ $exportUrl }}" title="导出当前筛选结果(CSV,包含全部匹配行)">
|
||||
<span class="material-icons-outlined" aria-hidden="true">download</span>导出
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="process-details-summary">
|
||||
<div class="item"><span>明细行数</span><b>{{ number_format((int) ($summary['rows'] ?? 0)) }}</b></div>
|
||||
<div class="item"><span>审批单数</span><b>{{ number_format((int) ($summary['approvals'] ?? 0)) }}</b></div>
|
||||
<div class="item"><span>金额合计</span><b>{{ $money($summary['amount_total'] ?? null) }}</b></div>
|
||||
<div class="item"><span>银行付款合计</span><b>{{ $money($summary['bank_amount_total'] ?? null) }}</b></div>
|
||||
</div>
|
||||
|
||||
<p class="process-details-note">
|
||||
当前展示的是当前账号权限范围内可读取的钉钉审批流程明细;审批中的金额和行项目仍可能随流程变化。
|
||||
企业级全量数据待领导开通 OA 权限后切换。
|
||||
</p>
|
||||
|
||||
<div class="process-details-table-wrap">
|
||||
<table class="process-details-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>序号</th>
|
||||
<th>审批编号</th>
|
||||
<th>发起人</th>
|
||||
<th>状态</th>
|
||||
<th>单据类型</th>
|
||||
<th>用途/摘要</th>
|
||||
<th class="center">单据内行号</th>
|
||||
<th>科目编码</th>
|
||||
<th>科目名称</th>
|
||||
<th class="num">金额(元)</th>
|
||||
<th>银行科目编码</th>
|
||||
<th>银行科目名称</th>
|
||||
<th class="num">银行付款金额</th>
|
||||
<th>付款方式</th>
|
||||
<th>打款时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($rows as $row)
|
||||
<tr>
|
||||
<td class="num">{{ ($rows->currentPage() - 1) * $rows->perPage() + $loop->iteration }}</td>
|
||||
<td>{{ $row->business_id }}</td>
|
||||
<td>{{ $text($row->originator_name) }}</td>
|
||||
<td class="center">
|
||||
<span class="process-details-status {{ $statusClass((string) $row->status) }}">{{ $text($row->status) }}</span>
|
||||
</td>
|
||||
<td>{{ $text($row->document_type) }}</td>
|
||||
<td class="wide" title="{{ $row->purpose }}">{{ $text($row->purpose) }}</td>
|
||||
<td class="center">{{ $row->line_no }}</td>
|
||||
<td>{{ $text($row->account_code) }}</td>
|
||||
<td class="wide" title="{{ $row->account_name }}">{{ $text($row->account_name) }}</td>
|
||||
<td class="num">{{ $money($row->amount) }}</td>
|
||||
<td>{{ $text($row->bank_account_code) }}</td>
|
||||
<td class="wide" title="{{ $row->bank_account_name }}">{{ $text($row->bank_account_name) }}</td>
|
||||
<td class="num">{{ $money($row->bank_amount) }}</td>
|
||||
<td>{{ $text($row->payment_method) }}</td>
|
||||
<td>{{ $text($row->paid_at) }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="15" class="process-details-empty">
|
||||
当前筛选条件没有流程明细。可以调整月份、单据类型、状态或关键词后重试。
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="process-details-footer">
|
||||
<span>
|
||||
第 {{ $rows->currentPage() }} / {{ max($rows->lastPage(), 1) }} 页,共 {{ number_format($rows->total()) }} 行
|
||||
</span>
|
||||
<div>{{ $rows->links() }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
</x-layouts.admin>
|
||||
@ -1418,6 +1418,7 @@
|
||||
data-directory-user="{{ auth()->id() ?? 'guest' }}"
|
||||
data-directory-section="{{ $section['slug'] ?? '' }}"
|
||||
data-directory-tab="{{ $activeTab['slug'] ?? '' }}"
|
||||
data-directory-column-preference-version="{{ in_array($directoryPageKey, ['company-management/subject-operating-report', 'store-management/store-report'], true) ? 'empty-month-columns-v1' : '' }}"
|
||||
aria-label="{{ $page['title'] ?? $section['title'] }}"
|
||||
>
|
||||
@if ($directoryUsesFieldQuery)
|
||||
@ -1915,7 +1916,7 @@
|
||||
'tax_type' => ['一般纳税人', '小规模纳税人', '个体工商户', '无税务登记', 'CORP'],
|
||||
'company_status' => ['正常', '已注销'],
|
||||
'company_type' => ['个体工商户', '个体户', '二级公司', '人力资源公司', '仓储公司', '其他', '合同公司', '品牌公司', '店铺-国标公司', '店铺-国标商标', '店铺-大店公司', '店铺-普通公司', '母公司', '资产型'],
|
||||
'business_registration_type' => ['个人独资企业', '合伙企业', '有限责任公司', '有限责任公司(自然人独资)', '个体工商户', '核定', '其他'],
|
||||
'business_registration_type' => ['核定', '个人独资企业', '/'],
|
||||
'collection_method' => ['查账征收', '核定征收', '定期定额'],
|
||||
'status' => ['0' => '开店中', '3' => '关店中', '6' => '关店'],
|
||||
'can_change', 'can_change_entity' => ['是', '否'],
|
||||
@ -3662,12 +3663,14 @@
|
||||
const tableKey = tableScope?.dataset.directoryTableKey || section?.dataset.directoryTab || 'table';
|
||||
const sourceUrl = tableScope?.dataset.directorySourceUrl || window.location.href;
|
||||
const lastPage = Number(tableScope?.dataset.directoryLastPage || section?.dataset.directoryLastPage || 1);
|
||||
const preferenceVersion = section.dataset.directoryColumnPreferenceVersion || '';
|
||||
const storageKey = [
|
||||
'directory-fields',
|
||||
section.dataset.directoryUser || 'guest',
|
||||
section.dataset.directorySection || 'section',
|
||||
section.dataset.directoryPage || 'page',
|
||||
tableKey,
|
||||
...(preferenceVersion ? [preferenceVersion] : []),
|
||||
].join(':');
|
||||
const defaultOrder = checks.map((check) => check.value);
|
||||
const orderedChecks = () => [...(picker?.querySelectorAll('[data-directory-field-option]') || [])]
|
||||
@ -3841,7 +3844,7 @@
|
||||
const options = [...picker.querySelectorAll('[data-directory-field-option]')];
|
||||
const byKey = new Map(options.map((option) => [option.querySelector('[data-directory-field-check]').value, option]));
|
||||
defaultOrder.forEach((key) => picker.querySelector('.directory-field-picker__panel').appendChild(byKey.get(key)));
|
||||
checks.forEach((check) => { check.checked = !['sales_01', 'sales_02', 'sales_03', 'sales_04', 'sales_05', 'sales_06'].includes(check.value); });
|
||||
checks.forEach((check) => { check.checked = check.defaultChecked; });
|
||||
applyColumns();
|
||||
};
|
||||
const resetButton = tools.querySelector('[data-directory-reset]');
|
||||
|
||||
@ -5,36 +5,26 @@
|
||||
|
||||
.installation-fee-card {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: min(100%, 52rem);
|
||||
min-height: 9.25rem;
|
||||
padding: 0.95rem 1.15rem 0.8rem 1.25rem;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 8rem;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
padding: 0.7rem 1rem 0 1.15rem;
|
||||
border: 1px solid #d8d2c7;
|
||||
border-left: 3px solid #006395;
|
||||
border-radius: 0.75rem;
|
||||
background: #ffffff;
|
||||
color: #171717;
|
||||
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
|
||||
font: inherit;
|
||||
font-family: "JetBrains Mono", "Microsoft YaHei", "PingFang SC", monospace;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.installation-fee-card:hover,
|
||||
.installation-fee-card:focus-visible {
|
||||
border-color: #b9954f;
|
||||
border-left-color: #006395;
|
||||
background: #fffdf8;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.installation-fee-card:focus-visible {
|
||||
box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.2);
|
||||
}
|
||||
|
||||
.installation-fee-card__top {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
@ -64,15 +54,15 @@
|
||||
align-items: baseline;
|
||||
gap: 0.35rem;
|
||||
min-width: 0;
|
||||
margin: 0.35rem 0 0.58rem;
|
||||
margin: 0.2rem 0 0.3rem;
|
||||
}
|
||||
|
||||
.installation-fee-card__value {
|
||||
color: #171717;
|
||||
font-size: 2.625rem;
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
letter-spacing: -0.035em;
|
||||
line-height: 1;
|
||||
letter-spacing: 0;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
@ -107,9 +97,11 @@
|
||||
.installation-fee-card__split {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.45rem;
|
||||
flex-wrap: wrap;
|
||||
padding-top: 0.55rem;
|
||||
margin: auto -1rem 0 -1.15rem;
|
||||
padding: 0.43rem 1rem 0.48rem 1.15rem;
|
||||
border-top: 1px solid #e5e0d7;
|
||||
color: #171717;
|
||||
font-size: 0.75rem;
|
||||
@ -117,6 +109,14 @@
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.installation-fee-card__split-summary {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
gap: 0.45rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.installation-fee-card__split strong {
|
||||
font-weight: 600;
|
||||
}
|
||||
@ -127,15 +127,52 @@
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.installation-fee-card__split-unit {
|
||||
margin-left: 0.12rem;
|
||||
color: #595959;
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.installation-fee-card__split-sep {
|
||||
color: #d8d2c7;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.installation-fee-card__detail-button {
|
||||
display: inline-flex;
|
||||
min-height: 1.55rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.25rem;
|
||||
margin-left: auto;
|
||||
padding: 0 0.45rem;
|
||||
border: 0;
|
||||
border-radius: 0.3rem;
|
||||
background: transparent;
|
||||
color: #006395;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.installation-fee-card__detail-button:hover {
|
||||
background: #eef6fa;
|
||||
}
|
||||
|
||||
.installation-fee-card__detail-button:focus-visible {
|
||||
background: #eef6fa;
|
||||
box-shadow: 0 0 0 3px rgba(0, 99, 149, 0.16);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.installation-fee-card {
|
||||
min-height: 0;
|
||||
padding: 0.9rem 0.95rem 0.8rem 1rem;
|
||||
height: auto;
|
||||
min-height: 8rem;
|
||||
padding: 0.7rem 0.85rem 0 0.95rem;
|
||||
}
|
||||
.installation-fee-card__top {
|
||||
flex-direction: column;
|
||||
@ -149,7 +186,17 @@
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.installation-fee-card__value {
|
||||
font-size: 2.625rem;
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
.installation-fee-card__split {
|
||||
margin-right: -0.85rem;
|
||||
margin-left: -0.95rem;
|
||||
padding-right: 0.85rem;
|
||||
padding-left: 0.95rem;
|
||||
}
|
||||
.installation-fee-card__detail-button {
|
||||
width: 100%;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,13 +398,9 @@
|
||||
</style>
|
||||
|
||||
<section class="installation-fee-board" aria-label="安装费金额汇总">
|
||||
<button
|
||||
type="button"
|
||||
<div
|
||||
class="installation-fee-card"
|
||||
data-installation-fee-open
|
||||
data-url="{{ route('business.installation-details.summary') }}"
|
||||
aria-label="查看安装费金额明细"
|
||||
title="查看安装费金额明细"
|
||||
data-installation-fee-card
|
||||
>
|
||||
<span class="installation-fee-card__top">
|
||||
<strong class="installation-fee-card__title">安装费金额</strong>
|
||||
@ -370,11 +413,20 @@
|
||||
<span class="installation-fee-card__trend-note">较上月</span>
|
||||
</span>
|
||||
<span class="installation-fee-card__split">
|
||||
<span>包安装 <strong data-installation-fee-package>0.00</strong><span class="installation-fee-card__split-percent" data-installation-fee-package-percent>(0%)</span></span>
|
||||
<span class="installation-fee-card__split-sep" aria-hidden="true">|</span>
|
||||
<span>不包安装 <strong data-installation-fee-non-package>0.00</strong><span class="installation-fee-card__split-percent" data-installation-fee-non-package-percent>(0%)</span></span>
|
||||
<span class="installation-fee-card__split-summary">
|
||||
<span>包安装金额 <strong data-installation-fee-package>0.00</strong><span class="installation-fee-card__split-unit">万元</span><span class="installation-fee-card__split-percent" data-installation-fee-package-percent>(0.0%)</span></span>
|
||||
<span class="installation-fee-card__split-sep" aria-hidden="true">|</span>
|
||||
<span>不包安装金额 <strong data-installation-fee-non-package>0.00</strong><span class="installation-fee-card__split-unit">万元</span><span class="installation-fee-card__split-percent" data-installation-fee-non-package-percent>(0.0%)</span></span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="installation-fee-card__detail-button"
|
||||
data-installation-fee-open
|
||||
data-url="{{ route('business.installation-details.summary') }}"
|
||||
aria-label="查看安装费金额明细"
|
||||
>查看明细 →</button>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<dialog class="installation-fee-dialog" id="installation-fee-dialog" aria-labelledby="installation-fee-dialog-title">
|
||||
@ -451,9 +503,10 @@
|
||||
<script>
|
||||
(function () {
|
||||
var form = document.getElementById('installationFilterForm');
|
||||
var card = document.querySelector('[data-installation-fee-open]');
|
||||
var card = document.querySelector('[data-installation-fee-card]');
|
||||
var openButton = document.querySelector('[data-installation-fee-open]');
|
||||
var dialog = document.getElementById('installation-fee-dialog');
|
||||
if (!form || !card || !dialog) { return; }
|
||||
if (!form || !card || !openButton || !dialog) { return; }
|
||||
|
||||
var fromInput = form.elements.namedItem('date_from');
|
||||
var toInput = form.elements.namedItem('date_to');
|
||||
@ -486,13 +539,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
function wan(value) {
|
||||
return (Number(value || 0) / 10000).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2
|
||||
});
|
||||
}
|
||||
|
||||
function amount(value) {
|
||||
return Number(value || 0).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
@ -500,6 +546,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
function wanAmount(value) {
|
||||
return amount(Number(value || 0) / 10000);
|
||||
}
|
||||
|
||||
function captionRange(value) {
|
||||
var matchFrom = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.from);
|
||||
var matchTo = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.to);
|
||||
@ -541,14 +591,23 @@
|
||||
nonPackageTotal += Number(row.amount || 0);
|
||||
}
|
||||
});
|
||||
var packageRate = total > 0 ? Math.round((packageTotal / total) * 100) : 0;
|
||||
var nonPackageRate = total > 0 ? 100 - packageRate : 0;
|
||||
var packageRate = total > 0 ? Math.round((packageTotal / total) * 1000) / 10 : 0;
|
||||
var nonPackageRate = total > 0 ? Math.round((100 - packageRate) * 10) / 10 : 0;
|
||||
var percent = function (rate) {
|
||||
return Number(rate || 0).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 1,
|
||||
maximumFractionDigits: 1
|
||||
});
|
||||
};
|
||||
|
||||
cardTotal.textContent = wan(total);
|
||||
packageAmount.textContent = amount(packageTotal);
|
||||
nonPackageAmount.textContent = amount(nonPackageTotal);
|
||||
packagePercent.textContent = '(' + packageRate + '%)';
|
||||
nonPackagePercent.textContent = '(' + nonPackageRate + '%)';
|
||||
cardTotal.textContent = wanAmount(total);
|
||||
cardTotal.title = '¥' + amount(total);
|
||||
packageAmount.textContent = wanAmount(packageTotal);
|
||||
packageAmount.title = '¥' + amount(packageTotal);
|
||||
nonPackageAmount.textContent = wanAmount(nonPackageTotal);
|
||||
nonPackageAmount.title = '¥' + amount(nonPackageTotal);
|
||||
packagePercent.textContent = '(' + percent(packageRate) + '%)';
|
||||
nonPackagePercent.textContent = '(' + percent(nonPackageRate) + '%)';
|
||||
setTrend(data.change_rate);
|
||||
status.classList.remove('is-error');
|
||||
status.textContent = '按客服审核时间 · ' + captionRange(value) + ' · ' + rows.length + ' 单';
|
||||
@ -558,8 +617,11 @@
|
||||
cardTotal.textContent = '0.00';
|
||||
packageAmount.textContent = '0.00';
|
||||
nonPackageAmount.textContent = '0.00';
|
||||
packagePercent.textContent = '(0%)';
|
||||
nonPackagePercent.textContent = '(0%)';
|
||||
cardTotal.removeAttribute('title');
|
||||
packageAmount.removeAttribute('title');
|
||||
nonPackageAmount.removeAttribute('title');
|
||||
packagePercent.textContent = '(0.0%)';
|
||||
nonPackagePercent.textContent = '(0.0%)';
|
||||
setTrend(null);
|
||||
status.textContent = message;
|
||||
status.classList.toggle('is-error', message.indexOf('失败') >= 0 || message.indexOf('不能') >= 0);
|
||||
@ -713,7 +775,7 @@
|
||||
status.classList.remove('is-error');
|
||||
status.textContent = '按客服审核时间 · 正在汇总…';
|
||||
cardTotal.textContent = '…';
|
||||
var url = new URL(card.dataset.url, window.location.origin);
|
||||
var url = new URL(openButton.dataset.url, window.location.origin);
|
||||
url.searchParams.set('customer_review_from', value.from);
|
||||
url.searchParams.set('customer_review_to', value.to);
|
||||
|
||||
@ -754,7 +816,7 @@
|
||||
timer = window.setTimeout(function () { refresh(true); }, 250);
|
||||
}
|
||||
|
||||
card.addEventListener('click', function () {
|
||||
openButton.addEventListener('click', function () {
|
||||
openDialog();
|
||||
refresh(false);
|
||||
});
|
||||
|
||||
@ -69,7 +69,7 @@ class LaborExpensePageAccessTest extends FeatureTestCase
|
||||
);
|
||||
|
||||
$this->assertCount(61, $fields);
|
||||
$this->assertCount(37, $formulaFields);
|
||||
$this->assertCount(47, $formulaFields);
|
||||
|
||||
$response = $this->loginAs($chenxi)->get(route('business.pages.show', [
|
||||
'section' => 'financial-operations',
|
||||
@ -85,12 +85,68 @@ class LaborExpensePageAccessTest extends FeatureTestCase
|
||||
->assertSee('data-labor-expense-table', false)
|
||||
->assertSee('=F#-G#-H#-I#', false)
|
||||
->assertSee('=IF(AN#<=0,0,IF(AN#<=4000,800,AN#*0.2))', false)
|
||||
->assertSee('=IF(J#<=0,"",IF(J#<=3000,0.03', false)
|
||||
->assertSee('=IF(J#<=0,"",IF(J#<=3000,0.03', false)
|
||||
->assertSee('=IF(J#<=0,"",IF(J#<=3000,0,IF(J#<=12000,210', false)
|
||||
->assertSee('=J#*K#-L#', false)
|
||||
->assertSee('=IF(F#<=0,"",IF(F#<=8500,4952', false)
|
||||
->assertSee('=O#*0.12', false)
|
||||
->assertSee('=Q#-H#', false)
|
||||
->assertSee('=S#*T#-U#', false)
|
||||
->assertDontSee('data-labor-row="0"', false);
|
||||
|
||||
$html = $response->getContent();
|
||||
$this->assertSame(61, substr_count($html, 'data-labor-header="'));
|
||||
$this->assertSame(37, substr_count($html, 'class="labor-expense-formula"'));
|
||||
$this->assertSame(47, substr_count($html, 'class="labor-expense-formula"'));
|
||||
}
|
||||
|
||||
public function test_basic_deduction_tax_amount_and_housing_fund_base_are_formula_driven(): void
|
||||
{
|
||||
$fields = collect(config('labor_expense_table.fields'))->keyBy('key');
|
||||
|
||||
$this->assertSame('formula_number', $fields['I']['kind']);
|
||||
$this->assertSame('=5000', $fields['I']['formula']);
|
||||
$this->assertSame('formula_number', $fields['AZ']['kind']);
|
||||
$this->assertSame('=60000', $fields['AZ']['formula']);
|
||||
$this->assertSame('formula_number', $fields['M']['kind']);
|
||||
$this->assertSame('=J#*K#-L#', $fields['M']['formula']);
|
||||
$this->assertSame('=M#*12', $fields['N']['formula']);
|
||||
|
||||
$this->assertSame('formula_number', $fields['O']['kind']);
|
||||
$this->assertSame(
|
||||
[4952, 8000, 10000, 12000],
|
||||
$this->housingFundBases($fields['O']['formula'])
|
||||
);
|
||||
|
||||
foreach (['P' => '=O#*0.12', 'Q' => '=O#*0.12', 'R' => '=Q#-H#', 'V' => '=S#*T#-U#'] as $key => $formula) {
|
||||
$this->assertSame('formula_number', $fields[$key]['kind']);
|
||||
$this->assertSame($formula, $fields[$key]['formula']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_monthly_and_annual_tax_quick_deductions_are_formula_driven(): void
|
||||
{
|
||||
$fields = collect(config('labor_expense_table.fields'))->keyBy('key');
|
||||
|
||||
foreach (['L', 'U', 'AH', 'Y', 'AL', 'BD'] as $key) {
|
||||
$this->assertNotEmpty($fields[$key]['formula'] ?? null, "{$key} 应配置速算扣除数公式");
|
||||
}
|
||||
|
||||
foreach (['L' => 'J', 'U' => 'S', 'AH' => 'AF'] as $key => $taxableKey) {
|
||||
$this->assertSame('formula_number', $fields[$key]['kind']);
|
||||
$this->assertStringStartsWith("=IF({$taxableKey}#<=0,\"\"", $fields[$key]['formula']);
|
||||
$this->assertSame(
|
||||
[0, 210, 1410, 2660, 4410, 7160, 15160],
|
||||
$this->quickDeductions($fields[$key]['formula'])
|
||||
);
|
||||
}
|
||||
|
||||
foreach (['Y' => 'W', 'AL' => 'AJ', 'BD' => 'BB'] as $key => $taxableKey) {
|
||||
$this->assertStringStartsWith("=IF({$taxableKey}#", $fields[$key]['formula']);
|
||||
$this->assertSame(
|
||||
[0, 2520, 16920, 31920, 52920, 85920, 181920],
|
||||
$this->quickDeductions($fields[$key]['formula'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function pageIsVisible(User $user): bool
|
||||
@ -119,4 +175,28 @@ class LaborExpensePageAccessTest extends FeatureTestCase
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function quickDeductions(string $formula): array
|
||||
{
|
||||
preg_match_all('/IF\([A-Z]+#<=\d+,(\d+)/', $formula, $matches);
|
||||
$deductions = array_values(array_unique(array_map('intval', $matches[1])));
|
||||
|
||||
if (preg_match('/,(\d+)\)+\s*$/', $formula, $fallback)) {
|
||||
$deductions[] = (int) $fallback[1];
|
||||
}
|
||||
|
||||
return $deductions;
|
||||
}
|
||||
|
||||
private function housingFundBases(string $formula): array
|
||||
{
|
||||
preg_match_all('/IF\(F#<=\d+,(\d+)/', $formula, $matches);
|
||||
$bases = array_map('intval', $matches[1]);
|
||||
|
||||
if (preg_match('/,(\d+)\)+\s*$/', $formula, $fallback)) {
|
||||
$bases[] = (int) $fallback[1];
|
||||
}
|
||||
|
||||
return $bases;
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,19 +276,26 @@ class ManagementCrudTest extends FeatureTestCase
|
||||
->assertSee("window.CaiWuDatePicker.setup(form)", false)
|
||||
->assertSee("input.addEventListener('input', syncClear)", false)
|
||||
->assertSee('结束日期不能早于开始日期。')
|
||||
->assertSee('data-installation-fee-card', false)
|
||||
->assertSee('data-installation-fee-open', false)
|
||||
->assertSee('id="installation-fee-dialog"', false)
|
||||
->assertSeeText('安装费金额')
|
||||
->assertSeeText('查看明细 →')
|
||||
->assertSeeText('较上月')
|
||||
->assertSeeText('包安装')
|
||||
->assertSeeText('不包安装')
|
||||
->assertSeeText('包安装金额')
|
||||
->assertSeeText('不包安装金额')
|
||||
->assertSee('installation-fee-card__split-unit', false)
|
||||
->assertSee('data-installation-fee-trend', false)
|
||||
->assertSee('data-installation-fee-package', false)
|
||||
->assertSee('data-installation-fee-non-package', false)
|
||||
->assertSee('border-left: 3px solid #006395', false)
|
||||
->assertSee('font-size: 2.625rem', false)
|
||||
->assertSee('height: 8rem', false)
|
||||
->assertSee('font-size: 2.5rem', false)
|
||||
->assertSee('font-family: "JetBrains Mono", "Microsoft YaHei", "PingFang SC", monospace', false)
|
||||
->assertSee('<span class="installation-fee-card__unit">万元</span>', false)
|
||||
->assertSee('function captionRange(value)', false)
|
||||
->assertSee('function setCardValue(total, rows, value, data)', false)
|
||||
->assertSee('function wanAmount(value)', false)
|
||||
->assertSeeText('平台')
|
||||
->assertSeeText('店铺名称')
|
||||
->assertSeeText('安装公司')
|
||||
|
||||
133
tests/Feature/Business/ProcessDetailsPageTest.php
Normal file
133
tests/Feature/Business/ProcessDetailsPageTest.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Business;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use Mockery;
|
||||
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
|
||||
use RuntimeException;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class ProcessDetailsPageTest extends FeatureTestCase
|
||||
{
|
||||
public function test_page_renders_process_detail_rows_and_filters(): void
|
||||
{
|
||||
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
|
||||
|
||||
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
|
||||
$repository->shouldReceive('paginate')->once()->andReturn([
|
||||
'data' => [
|
||||
(object) [
|
||||
'business_id' => '202601011200000000001',
|
||||
'line_no' => 1,
|
||||
'originator_name' => '张三',
|
||||
'status' => '已完成',
|
||||
'document_type' => '公摊日常报销',
|
||||
'purpose' => '办公用品采购',
|
||||
'account_code' => '5602.04',
|
||||
'account_name' => '管理费用_办公费',
|
||||
'amount' => 100.00,
|
||||
'bank_account_code' => '1002.01.001',
|
||||
'bank_account_name' => '华夏银行-测试',
|
||||
'bank_amount' => 100.00,
|
||||
'payment_method' => '银行卡',
|
||||
'paid_at' => '2026-01-02 00:00',
|
||||
],
|
||||
],
|
||||
'total' => 1,
|
||||
'summary' => [
|
||||
'rows' => 1,
|
||||
'approvals' => 1,
|
||||
'amount_total' => 100.0,
|
||||
'bank_amount_total' => 100.0,
|
||||
],
|
||||
'status' => 'succeeded',
|
||||
'last_synced_at' => '2026-10-26 15:00:00',
|
||||
'scope' => 'personal_permission',
|
||||
]);
|
||||
$repository->shouldReceive('filterOptions')->once()->andReturn([
|
||||
'months' => ['2026-01'],
|
||||
'document_types' => ['公摊日常报销'],
|
||||
'statuses' => ['已完成'],
|
||||
]);
|
||||
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
|
||||
|
||||
$financeSection = collect(\App\Utilities\BusinessNavigation::all())
|
||||
->firstWhere('slug', 'financial-operations');
|
||||
$this->assertContains(
|
||||
'process-details',
|
||||
array_column($financeSection['pages'] ?? [], 'slug'),
|
||||
);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'financial-operations',
|
||||
'page' => 'process-details',
|
||||
]))->assertOk()
|
||||
->assertSee('流程明细')
|
||||
->assertSee('审批编号')
|
||||
->assertSee('发起人')
|
||||
->assertSee('单据类型')
|
||||
->assertSee('银行付款金额')
|
||||
->assertSee('202601011200000000001')
|
||||
->assertSee('张三')
|
||||
->assertSee('管理费用_办公费')
|
||||
->assertSee('100.00')
|
||||
->assertSee('当前账号权限范围')
|
||||
->assertSee('导出');
|
||||
}
|
||||
|
||||
public function test_page_stays_readable_when_mirror_is_not_ready(): void
|
||||
{
|
||||
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
|
||||
|
||||
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
|
||||
$repository->shouldReceive('paginate')->once()->andThrow(new RuntimeException('not ready'));
|
||||
$repository->shouldReceive('scope')->once()->andReturn('personal_permission');
|
||||
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'financial-operations',
|
||||
'page' => 'process-details',
|
||||
]))->assertOk()
|
||||
->assertSee('流程明细镜像尚未完成导入')
|
||||
->assertSee('当前账号权限范围');
|
||||
}
|
||||
|
||||
public function test_export_streams_filtered_csv(): void
|
||||
{
|
||||
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
|
||||
|
||||
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
|
||||
$repository->shouldReceive('ready')->once()->andReturn(true);
|
||||
$repository->shouldReceive('exportRows')->once()->andReturnUsing(function (): \Generator {
|
||||
yield [
|
||||
'business_id' => '202601011200000000001',
|
||||
'originator_name' => '张三',
|
||||
'status' => '已完成',
|
||||
'document_type' => '公摊日常报销',
|
||||
'purpose' => '办公用品采购',
|
||||
'line_no' => 1,
|
||||
'account_code' => '5602.04',
|
||||
'account_name' => '管理费用_办公费',
|
||||
'amount' => '100.00',
|
||||
'bank_account_code' => '1002.01.001',
|
||||
'bank_account_name' => '华夏银行-测试',
|
||||
'bank_amount' => '100.00',
|
||||
'payment_method' => '银行卡',
|
||||
'paid_at' => '2026-01-02 00:00',
|
||||
];
|
||||
});
|
||||
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
|
||||
|
||||
$response = $this->loginAs()->get(route('business.process-details.export', [
|
||||
'status' => '已完成',
|
||||
]));
|
||||
|
||||
$response->assertOk();
|
||||
$content = $response->streamedContent();
|
||||
$this->assertStringContainsString('审批编号', $content);
|
||||
$this->assertStringContainsString('202601011200000000001', $content);
|
||||
$this->assertStringContainsString('张三', $content);
|
||||
$this->assertStringContainsString('管理费用_办公费', $content);
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ class PrototypePageTest extends FeatureTestCase
|
||||
{
|
||||
$pages = [
|
||||
['company-cost-arrangement', ['数据状态', '完整表头', '11 列', '核心结果', '缺口提示', '配平提示']],
|
||||
['tax-forecast', ['数据状态', '完整表头', '22 列', '计算税种', '必补口径', '当前记录']],
|
||||
['tax-forecast', ['数据状态', '完整表头', '22 列', '计算税种', '计税口径', '当前记录']],
|
||||
['personnel-inventory', ['数据状态', '完整表头', '17 列', '敏感字段', '容量规则', '当前记录']],
|
||||
];
|
||||
|
||||
@ -227,11 +227,16 @@ class PrototypePageTest extends FeatureTestCase
|
||||
->assertSeeTextInOrder(['最近12个月累计收入', '1月收入', '12月收入']);
|
||||
}
|
||||
|
||||
public function testSubjectOperatingReportShowsAllMonthsByDefaultAndStillSupportsColumnSelection(): void
|
||||
public function testSubjectOperatingReportHidesMonthsWithoutDataAndKeepsThemSelectable(): void
|
||||
{
|
||||
$service = Mockery::mock(UpstreamBusinessInformation::class);
|
||||
$service->shouldReceive('paginate')->with('company-management', 'subject-operating-report', 50)
|
||||
->andReturnUsing(function (): LengthAwarePaginator {
|
||||
request()->attributes->set(
|
||||
'subject-operating-report.default_hidden_columns',
|
||||
['income_01', 'income_02'],
|
||||
);
|
||||
|
||||
return new LengthAwarePaginator([(object) [
|
||||
'entity' => '测试主体',
|
||||
'city' => '常州市',
|
||||
@ -255,13 +260,15 @@ class PrototypePageTest extends FeatureTestCase
|
||||
$response->assertOk();
|
||||
$html = $response->getContent();
|
||||
|
||||
// 所有原始月份表头默认显示,避免新增汇总卡后缩减原表字段。
|
||||
$this->assertDoesNotMatchRegularExpression('/<th[^>]*data-column-key="income_01"[^>]*is-column-hidden/', $html);
|
||||
$this->assertDoesNotMatchRegularExpression('/<th[^>]*data-column-key="income_02"[^>]*is-column-hidden/', $html);
|
||||
// 没有数据的月份默认隐藏,但表头和「筛选字段」勾选项仍在页面中。
|
||||
$this->assertMatchesRegularExpression('/<th[^>]*data-column-key="income_01"[^>]*is-column-hidden/', $html);
|
||||
$this->assertMatchesRegularExpression('/<th[^>]*data-column-key="income_02"[^>]*is-column-hidden/', $html);
|
||||
$this->assertDoesNotMatchRegularExpression('/<th[^>]*data-column-key="income_03"[^>]*is-column-hidden/', $html);
|
||||
$this->assertStringContainsString('value="income_01" data-directory-query-column', $html);
|
||||
$this->assertStringContainsString('value="income_01" data-directory-query-column checked', $html);
|
||||
$this->assertStringNotContainsString('value="income_01" data-directory-query-column checked', $html);
|
||||
$this->assertStringContainsString('value="income_03" data-directory-query-column checked', $html);
|
||||
$this->assertStringContainsString('筛选字段 19/21', $html);
|
||||
$this->assertStringContainsString('data-directory-column-preference-version="empty-month-columns-v1"', $html);
|
||||
|
||||
// 手动勾选(columns 参数)后,对应月份列恢复显示。
|
||||
$restored = $this->get(route('business.pages.show', [
|
||||
@ -277,11 +284,16 @@ class PrototypePageTest extends FeatureTestCase
|
||||
$this->assertMatchesRegularExpression('/<th[^>]*data-column-key="income_04"[^>]*is-column-hidden/', $restoredHtml);
|
||||
}
|
||||
|
||||
public function testStoreReportShowsAllMonthsByDefaultAndStillSupportsColumnSelection(): void
|
||||
public function testStoreReportHidesSalesMonthsWithoutDataAndKeepsThemSelectable(): void
|
||||
{
|
||||
$service = Mockery::mock(UpstreamBusinessInformation::class);
|
||||
$service->shouldReceive('paginate')->with('store-management', 'store-report', 50)
|
||||
->andReturnUsing(function (): LengthAwarePaginator {
|
||||
request()->attributes->set(
|
||||
'store-report.default_hidden_columns',
|
||||
['sales_01', 'sales_08'],
|
||||
);
|
||||
|
||||
return new LengthAwarePaginator([(object) [
|
||||
'erp_store_name' => 'ERP测试店铺',
|
||||
'store_name' => '前台测试店铺',
|
||||
@ -305,13 +317,15 @@ class PrototypePageTest extends FeatureTestCase
|
||||
$response->assertOk();
|
||||
$html = $response->getContent();
|
||||
|
||||
// 所有原始月份表头默认显示,避免新增汇总卡后缩减原表字段。
|
||||
$this->assertDoesNotMatchRegularExpression('/<th[^>]*data-column-key="sales_01"[^>]*is-column-hidden/', $html);
|
||||
$this->assertDoesNotMatchRegularExpression('/<th[^>]*data-column-key="sales_08"[^>]*is-column-hidden/', $html);
|
||||
// 没有业绩的月份默认隐藏,但表头和「筛选字段」勾选项仍在页面中。
|
||||
$this->assertMatchesRegularExpression('/<th[^>]*data-column-key="sales_01"[^>]*is-column-hidden/', $html);
|
||||
$this->assertMatchesRegularExpression('/<th[^>]*data-column-key="sales_08"[^>]*is-column-hidden/', $html);
|
||||
$this->assertDoesNotMatchRegularExpression('/<th[^>]*data-column-key="sales_07"[^>]*is-column-hidden/', $html);
|
||||
$this->assertStringContainsString('value="sales_01" data-directory-query-column', $html);
|
||||
$this->assertStringContainsString('value="sales_01" data-directory-query-column checked', $html);
|
||||
$this->assertStringNotContainsString('value="sales_01" data-directory-query-column checked', $html);
|
||||
$this->assertStringContainsString('value="sales_07" data-directory-query-column checked', $html);
|
||||
$this->assertStringContainsString('筛选字段 24/26', $html);
|
||||
$this->assertStringContainsString('data-directory-column-preference-version="empty-month-columns-v1"', $html);
|
||||
|
||||
// 手动勾选(columns 参数)后,对应月份列恢复显示。
|
||||
$restored = $this->get(route('business.pages.show', [
|
||||
|
||||
271
tests/Feature/Console/ImportDingProcessDetailsTest.php
Normal file
271
tests/Feature/Console/ImportDingProcessDetailsTest.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorImporter;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ImportDingProcessDetailsTest extends TestCase
|
||||
{
|
||||
private string $fixture;
|
||||
|
||||
/** @var list<string> */
|
||||
private array $tempFiles = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config([
|
||||
'database.connections.business_mirror' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
],
|
||||
'upstream_mirrors.connection' => 'business_mirror',
|
||||
'upstream_mirrors.ding_process_details.scope' => 'personal_permission',
|
||||
]);
|
||||
DB::purge('business_mirror');
|
||||
$this->createMirrorTables();
|
||||
|
||||
$this->fixture = base_path('tests/Fixtures/ding_process_details_sample.csv');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
foreach ($this->tempFiles as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_imports_csv_and_publishes_mirror_state(): void
|
||||
{
|
||||
$result = app(DingProcessDetailMirrorImporter::class)
|
||||
->import($this->fixture, 'personal_permission', true);
|
||||
|
||||
$this->assertSame('succeeded', $result['status']);
|
||||
$this->assertSame(4, $result['rows']);
|
||||
$this->assertSame(0, $result['invalid']);
|
||||
$this->assertSame(0, $result['placeholders']);
|
||||
$this->assertSame(4, DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->count());
|
||||
|
||||
$row = DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')
|
||||
->where('business_id', '202601011200000000001')
|
||||
->where('line_no', 1)
|
||||
->first();
|
||||
|
||||
$this->assertNotNull($row);
|
||||
$this->assertSame('张三', $row->originator_name);
|
||||
$this->assertSame('已完成', $row->status);
|
||||
$this->assertSame('公摊日常报销', $row->document_type);
|
||||
$this->assertSame('5602.04', $row->account_code);
|
||||
$this->assertSame('管理费用_办公费', $row->account_name);
|
||||
$this->assertEqualsWithDelta(100.0, (float) $row->amount, 0.001);
|
||||
$this->assertSame('202601', $row->business_month);
|
||||
$this->assertSame('personal_permission', $row->source_scope);
|
||||
|
||||
$state = DB::connection('business_mirror')
|
||||
->table('business_mirror_table_states')
|
||||
->where('dataset_key', 'ding.process_details.personal_permission')
|
||||
->first();
|
||||
|
||||
$this->assertNotNull($state);
|
||||
$this->assertSame('succeeded', $state->status);
|
||||
$this->assertSame('ding_process_detail_mirror', $state->target_table);
|
||||
$this->assertNotNull($state->initial_completed_at);
|
||||
$this->assertSame(4, (int) $state->mirror_row_count);
|
||||
}
|
||||
|
||||
public function test_import_is_idempotent_by_business_id_and_line_number(): void
|
||||
{
|
||||
$importer = app(DingProcessDetailMirrorImporter::class);
|
||||
$importer->import($this->fixture, 'personal_permission', true);
|
||||
$importer->import($this->fixture, 'personal_permission', false);
|
||||
|
||||
$this->assertSame(4, DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->count());
|
||||
}
|
||||
|
||||
public function test_replace_removes_rows_that_are_not_in_the_new_file(): void
|
||||
{
|
||||
$importer = app(DingProcessDetailMirrorImporter::class);
|
||||
$importer->import($this->fixture, 'personal_permission', true);
|
||||
|
||||
$replacement = $this->makeCsv([[
|
||||
'1',
|
||||
'202603011200000000003',
|
||||
'王五',
|
||||
'已完成',
|
||||
'店铺日常报销',
|
||||
'替换后的流程',
|
||||
'1',
|
||||
'5601.01',
|
||||
'销售费用',
|
||||
'10.00',
|
||||
'1002.01.003',
|
||||
'银行-测试3',
|
||||
'10.00',
|
||||
'银行卡',
|
||||
'2026-03-02 00:00',
|
||||
]]);
|
||||
|
||||
$importer->import($replacement, 'personal_permission', true);
|
||||
|
||||
$this->assertSame(1, DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->count());
|
||||
$this->assertSame(
|
||||
'202603011200000000003',
|
||||
(string) DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')
|
||||
->value('business_id'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_missing_headers_does_not_delete_existing_rows(): void
|
||||
{
|
||||
$importer = app(DingProcessDetailMirrorImporter::class);
|
||||
$importer->import($this->fixture, 'personal_permission', true);
|
||||
|
||||
$path = tempnam(sys_get_temp_dir(), 'ding-process-bad-');
|
||||
file_put_contents($path, "序号,审批编号\n1,202603011200000000003\n");
|
||||
$this->tempFiles[] = $path;
|
||||
|
||||
try {
|
||||
$importer->import($path, 'personal_permission', true);
|
||||
$this->fail('缺少表头时应抛出异常。');
|
||||
} catch (RuntimeException $exception) {
|
||||
$this->assertStringContainsString('缺少列', $exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame(4, DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->count());
|
||||
}
|
||||
|
||||
public function test_placeholder_rows_are_skipped_and_the_better_duplicate_wins(): void
|
||||
{
|
||||
$path = $this->makeCsv([
|
||||
[
|
||||
'1', '202604011200000000004', '赵六', '已完成', '公摊日常报销', '真实费用',
|
||||
'1', '5602.04', '管理费用_办公费', '100.00', '1002.01.001', '华夏银行-测试',
|
||||
'100.00', '银行卡', '2026-04-02 00:00',
|
||||
],
|
||||
[
|
||||
'2', '202604011200000000004', '赵六', '已完成', '公摊日常报销', '251',
|
||||
'1', '251', '251', '', '251', '251', '251', '251', '251',
|
||||
],
|
||||
[
|
||||
'3', '202604011200000000004', '赵六', '已完成', '公摊日常报销', '251',
|
||||
'1', '1221.05', '251', '0.00', '1002.01.001', '华夏银行-测试',
|
||||
'100.00', '银行卡', '2026-04-02 00:00',
|
||||
],
|
||||
[
|
||||
'4', '202604021200000000005', '钱七', '已完成', '店铺日常报销', '251',
|
||||
'1', '251', '251', '', '251', '251', '251', '251', '251',
|
||||
],
|
||||
]);
|
||||
|
||||
$result = app(DingProcessDetailMirrorImporter::class)
|
||||
->import($path, 'personal_permission', true);
|
||||
|
||||
$this->assertSame(1, $result['rows']);
|
||||
$this->assertSame(2, $result['placeholders']);
|
||||
$this->assertSame(1, $result['duplicates']);
|
||||
$row = DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')
|
||||
->first();
|
||||
$this->assertSame('5602.04', $row->account_code);
|
||||
$this->assertSame('管理费用_办公费', $row->account_name);
|
||||
$this->assertEqualsWithDelta(100.0, (float) $row->amount, 0.001);
|
||||
}
|
||||
|
||||
public function test_artisan_command_imports_the_file(): void
|
||||
{
|
||||
$this->artisan('ding:import-process-details', [
|
||||
'file' => $this->fixture,
|
||||
'--scope' => 'personal_permission',
|
||||
'--replace' => true,
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->assertSame(4, DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->count());
|
||||
}
|
||||
|
||||
private function createMirrorTables(): void
|
||||
{
|
||||
Schema::connection('business_mirror')->create(
|
||||
'business_mirror_table_states',
|
||||
function (Blueprint $table): void {
|
||||
$table->string('dataset_key')->primary();
|
||||
$table->string('source_key');
|
||||
$table->string('source_object');
|
||||
$table->string('target_table');
|
||||
$table->string('status')->default('pending');
|
||||
$table->string('run_mode')->nullable();
|
||||
$table->string('generation')->nullable();
|
||||
$table->json('cursor')->nullable();
|
||||
$table->json('high_watermark')->nullable();
|
||||
$table->dateTime('window_started_at')->nullable();
|
||||
$table->dateTime('window_ends_at')->nullable();
|
||||
$table->dateTime('initial_completed_at')->nullable();
|
||||
$table->dateTime('last_full_succeeded_at')->nullable();
|
||||
$table->dateTime('last_attempted_at')->nullable();
|
||||
$table->dateTime('last_succeeded_at')->nullable();
|
||||
$table->unsignedBigInteger('last_upserted_rows')->default(0);
|
||||
$table->unsignedBigInteger('mirror_row_count')->default(0);
|
||||
$table->string('last_error_code')->nullable();
|
||||
$table->timestamps();
|
||||
},
|
||||
);
|
||||
|
||||
Schema::connection('business_mirror')->create(
|
||||
'ding_process_detail_mirror',
|
||||
function (Blueprint $table): void {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('business_id', 32);
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6)->index();
|
||||
$table->string('originator_name', 100)->nullable()->index();
|
||||
$table->string('status', 20)->nullable()->index();
|
||||
$table->string('document_type', 100)->nullable()->index();
|
||||
$table->text('purpose')->nullable();
|
||||
$table->string('account_code', 64)->nullable();
|
||||
$table->string('account_name', 255)->nullable();
|
||||
$table->decimal('amount', 18, 2)->nullable();
|
||||
$table->string('bank_account_code', 255)->nullable();
|
||||
$table->string('bank_account_name', 255)->nullable();
|
||||
$table->decimal('bank_amount', 18, 2)->nullable();
|
||||
$table->string('payment_method', 50)->nullable();
|
||||
$table->string('paid_at', 50)->nullable();
|
||||
$table->string('source_scope', 40)->default('personal_permission')->index();
|
||||
$table->dateTime('synced_at', 6);
|
||||
$table->timestamps();
|
||||
$table->unique(['business_id', 'line_no']);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** @param list<list<string>> $rows */
|
||||
private function makeCsv(array $rows): string
|
||||
{
|
||||
$path = tempnam(sys_get_temp_dir(), 'ding-process-');
|
||||
$handle = fopen($path, 'wb');
|
||||
fputcsv($handle, DingProcessDetailMirrorImporter::HEADERS);
|
||||
foreach ($rows as $row) {
|
||||
fputcsv($handle, $row);
|
||||
}
|
||||
fclose($handle);
|
||||
$this->tempFiles[] = $path;
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
5
tests/Fixtures/ding_process_details_sample.csv
Normal file
5
tests/Fixtures/ding_process_details_sample.csv
Normal file
@ -0,0 +1,5 @@
|
||||
序号,审批编号,发起人,状态,单据类型,用途/摘要,单据内行号,科目编码,科目名称,金额(元),银行科目编码,银行科目名称,银行付款金额,付款方式,打款时间
|
||||
1,202601011200000000001,张三,已完成,公摊日常报销,办公用品采购,1,5602.04,管理费用_办公费,100.00,1002.01.001,华夏银行-测试,100.00,银行卡,2026-01-02 00:00
|
||||
2,202601011200000000001,张三,已完成,公摊日常报销,交通费,2,5602.06,管理费用_交通费,50.50,1002.01.001,华夏银行-测试,50.50,银行卡,2026-01-02 00:00
|
||||
3,202602031200000000002,李四,审批中,应付申请流程,供应商货款,1,,,200.00,1002.01.002,银行-测试2,200.00,银行卡,
|
||||
4,202602031200000000002,李四,审批中,应付申请流程,供应商货款,2,,,300.00,1002.01.002,银行-测试2,300.00,银行卡,
|
||||
|
@ -140,7 +140,7 @@ class BusinessInformationMirrorRepositoryTest extends TestCase
|
||||
$this->assertSame('待注销', $companyClassifications['其他公司']['status']);
|
||||
$this->assertSame('小规模纳税人', $companyClassifications['新公司']['tax_type']);
|
||||
$this->assertSame('个人独资企业', $companyClassifications['新公司']['business_registration_type']);
|
||||
$this->assertNull($companyClassifications['旧公司']['business_registration_type']);
|
||||
$this->assertSame('/', $companyClassifications['旧公司']['business_registration_type']);
|
||||
$this->assertSame('个人独资企业', $companyDetails['新公司'][0]['business_registration_type']);
|
||||
$this->assertSame([
|
||||
'total' => 3,
|
||||
|
||||
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\EcommerceFinance;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DingProcessDetailMirrorRepositoryTest extends TestCase
|
||||
{
|
||||
private DingProcessDetailMirrorRepository $repository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config([
|
||||
'database.connections.business_mirror' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
],
|
||||
'upstream_mirrors.connection' => 'business_mirror',
|
||||
'upstream_mirrors.ding_process_details.scope' => 'personal_permission',
|
||||
]);
|
||||
DB::purge('business_mirror');
|
||||
$this->createMirrorTables();
|
||||
$this->seedRows();
|
||||
|
||||
$this->repository = app(DingProcessDetailMirrorRepository::class);
|
||||
}
|
||||
|
||||
public function test_paginate_returns_rows_summary_and_filter_options(): void
|
||||
{
|
||||
$result = $this->repository->paginate([], 1, 50);
|
||||
|
||||
$this->assertSame(4, $result['total']);
|
||||
$this->assertCount(4, $result['data']);
|
||||
$this->assertSame(4, $result['summary']['rows']);
|
||||
$this->assertSame(2, $result['summary']['approvals']);
|
||||
$this->assertEqualsWithDelta(650.5, $result['summary']['amount_total'], 0.001);
|
||||
$this->assertEqualsWithDelta(650.5, $result['summary']['bank_amount_total'], 0.001);
|
||||
$this->assertSame('personal_permission', $result['scope']);
|
||||
|
||||
$options = $this->repository->filterOptions();
|
||||
$this->assertSame(['2026-02', '2026-01'], $options['months']);
|
||||
$this->assertContains('公摊日常报销', $options['document_types']);
|
||||
$this->assertContains('应付申请流程', $options['document_types']);
|
||||
$this->assertContains('已完成', $options['statuses']);
|
||||
$this->assertContains('审批中', $options['statuses']);
|
||||
}
|
||||
|
||||
public function test_paginate_applies_month_status_and_keyword_filters(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
2,
|
||||
$this->repository->paginate(['month' => '2026-01'], 1, 50)['total'],
|
||||
);
|
||||
$this->assertSame(
|
||||
2,
|
||||
$this->repository->paginate(['status' => '审批中'], 1, 50)['total'],
|
||||
);
|
||||
$this->assertSame(
|
||||
1,
|
||||
$this->repository->paginate(['keyword' => '办公'], 1, 50)['total'],
|
||||
);
|
||||
}
|
||||
|
||||
public function test_paginate_applies_document_type_originator_and_business_id_filters(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
2,
|
||||
$this->repository->paginate([
|
||||
'document_type' => '应付申请流程',
|
||||
'originator_name' => '李四',
|
||||
], 1, 50)['total'],
|
||||
);
|
||||
$this->assertSame(
|
||||
2,
|
||||
$this->repository->paginate(['business_id' => '0002'], 1, 50)['total'],
|
||||
);
|
||||
}
|
||||
|
||||
public function test_export_rows_returns_every_filtered_row(): void
|
||||
{
|
||||
$rows = iterator_to_array($this->repository->exportRows(['status' => '已完成']));
|
||||
|
||||
$this->assertCount(2, $rows);
|
||||
$this->assertSame('202601011200000000001', (string) $rows[0]['business_id']);
|
||||
}
|
||||
|
||||
public function test_not_ready_when_state_is_missing(): void
|
||||
{
|
||||
DB::connection('business_mirror')
|
||||
->table('business_mirror_table_states')
|
||||
->where('dataset_key', 'ding.process_details.personal_permission')
|
||||
->delete();
|
||||
|
||||
$this->assertFalse($this->repository->ready());
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('ding_process_detail_mirror_not_ready');
|
||||
$this->repository->paginate([], 1, 50);
|
||||
}
|
||||
|
||||
private function seedRows(): void
|
||||
{
|
||||
$now = now();
|
||||
$rows = [
|
||||
$this->row('202601011200000000001', 1, '202601', '张三', '已完成', '公摊日常报销', '办公用品采购', 100.00),
|
||||
$this->row('202601011200000000001', 2, '202601', '张三', '已完成', '公摊日常报销', '交通费', 50.50),
|
||||
$this->row('202602031200000000002', 1, '202602', '李四', '审批中', '应付申请流程', '供应商货款', 200.00),
|
||||
$this->row('202602031200000000002', 2, '202602', '李四', '审批中', '应付申请流程', '供应商货款', 300.00),
|
||||
];
|
||||
|
||||
DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')
|
||||
->insert($rows);
|
||||
|
||||
DB::connection('business_mirror')
|
||||
->table('business_mirror_table_states')
|
||||
->insert([
|
||||
'dataset_key' => 'ding.process_details.personal_permission',
|
||||
'source_key' => 'dingtalk_oa',
|
||||
'source_object' => 'oa approval detail (personal permission scope)',
|
||||
'target_table' => 'ding_process_detail_mirror',
|
||||
'status' => 'succeeded',
|
||||
'run_mode' => 'full',
|
||||
'generation' => '00000000-0000-0000-0000-000000000001',
|
||||
'initial_completed_at' => $now,
|
||||
'last_full_succeeded_at' => $now,
|
||||
'last_attempted_at' => $now,
|
||||
'last_succeeded_at' => $now,
|
||||
'last_upserted_rows' => 4,
|
||||
'mirror_row_count' => 4,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function row(
|
||||
string $businessId,
|
||||
int $lineNo,
|
||||
string $month,
|
||||
string $originator,
|
||||
string $status,
|
||||
string $documentType,
|
||||
string $purpose,
|
||||
float $amount,
|
||||
): array {
|
||||
$now = now();
|
||||
|
||||
return [
|
||||
'business_id' => $businessId,
|
||||
'line_no' => $lineNo,
|
||||
'business_month' => $month,
|
||||
'originator_name' => $originator,
|
||||
'status' => $status,
|
||||
'document_type' => $documentType,
|
||||
'purpose' => $purpose,
|
||||
'account_code' => '5602.04',
|
||||
'account_name' => '管理费用_办公费',
|
||||
'amount' => $amount,
|
||||
'bank_account_code' => '1002.01.001',
|
||||
'bank_account_name' => '华夏银行-测试',
|
||||
'bank_amount' => $amount,
|
||||
'payment_method' => '银行卡',
|
||||
'paid_at' => '2026-01-02 00:00',
|
||||
'source_scope' => 'personal_permission',
|
||||
'synced_at' => $now,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
}
|
||||
|
||||
private function createMirrorTables(): void
|
||||
{
|
||||
Schema::connection('business_mirror')->create(
|
||||
'business_mirror_table_states',
|
||||
function (Blueprint $table): void {
|
||||
$table->string('dataset_key')->primary();
|
||||
$table->string('source_key');
|
||||
$table->string('source_object');
|
||||
$table->string('target_table');
|
||||
$table->string('status')->default('pending');
|
||||
$table->string('run_mode')->nullable();
|
||||
$table->string('generation')->nullable();
|
||||
$table->json('cursor')->nullable();
|
||||
$table->json('high_watermark')->nullable();
|
||||
$table->dateTime('window_started_at')->nullable();
|
||||
$table->dateTime('window_ends_at')->nullable();
|
||||
$table->dateTime('initial_completed_at')->nullable();
|
||||
$table->dateTime('last_full_succeeded_at')->nullable();
|
||||
$table->dateTime('last_attempted_at')->nullable();
|
||||
$table->dateTime('last_succeeded_at')->nullable();
|
||||
$table->unsignedBigInteger('last_upserted_rows')->default(0);
|
||||
$table->unsignedBigInteger('mirror_row_count')->default(0);
|
||||
$table->string('last_error_code')->nullable();
|
||||
$table->timestamps();
|
||||
},
|
||||
);
|
||||
|
||||
Schema::connection('business_mirror')->create(
|
||||
'ding_process_detail_mirror',
|
||||
function (Blueprint $table): void {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('business_id', 32);
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6)->index();
|
||||
$table->string('originator_name', 100)->nullable()->index();
|
||||
$table->string('status', 20)->nullable()->index();
|
||||
$table->string('document_type', 100)->nullable()->index();
|
||||
$table->text('purpose')->nullable();
|
||||
$table->string('account_code', 64)->nullable();
|
||||
$table->string('account_name', 255)->nullable();
|
||||
$table->decimal('amount', 18, 2)->nullable();
|
||||
$table->string('bank_account_code', 255)->nullable();
|
||||
$table->string('bank_account_name', 255)->nullable();
|
||||
$table->decimal('bank_amount', 18, 2)->nullable();
|
||||
$table->string('payment_method', 50)->nullable();
|
||||
$table->string('paid_at', 50)->nullable();
|
||||
$table->string('source_scope', 40)->default('personal_permission')->index();
|
||||
$table->dateTime('synced_at', 6);
|
||||
$table->timestamps();
|
||||
$table->unique(['business_id', 'line_no']);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -291,11 +291,11 @@ class StoreReportRepositoryTest extends TestCase
|
||||
$this->assertSame(1, $summaryCards['正常存续店铺']['value']);
|
||||
$this->assertSame(0.0, (float) $summaryCards['上月(6月)销量']['value']);
|
||||
$this->assertSame(60.0, (float) $summaryCards['当月(7月)销量']['value']);
|
||||
$this->assertSame(0, $summaryCards['上月(6月)有销量店铺']['value']);
|
||||
$this->assertSame(1, $summaryCards['当月(7月)有销量店铺']['value']);
|
||||
$this->assertArrayNotHasKey('上月(6月)有销量店铺', $summaryCards);
|
||||
$this->assertArrayNotHasKey('当月(7月)有销量店铺', $summaryCards);
|
||||
}
|
||||
|
||||
public function test_store_report_keeps_all_sales_months_visible_by_default(): void
|
||||
public function test_store_report_hides_sales_months_without_data_by_default(): void
|
||||
{
|
||||
Carbon::setTestNow('2026-09-15 10:00:00');
|
||||
$this->insertBill('店铺A', '2026-07-05', 60);
|
||||
@ -315,7 +315,8 @@ class StoreReportRepositoryTest extends TestCase
|
||||
|
||||
$paginator = $service->paginate('store-management', 'store-report', 50);
|
||||
|
||||
$this->assertNull(
|
||||
$this->assertSame(
|
||||
['sales_01', 'sales_02', 'sales_03', 'sales_04', 'sales_05', 'sales_06', 'sales_08', 'sales_09', 'sales_10', 'sales_11', 'sales_12'],
|
||||
$this->app['request']->attributes->get('store-report.default_hidden_columns'),
|
||||
);
|
||||
$this->assertSame(1, $paginator->total());
|
||||
@ -350,7 +351,7 @@ class StoreReportRepositoryTest extends TestCase
|
||||
$this->assertSame(2, $paginator->total());
|
||||
$this->assertSame(1, $summaryCards['正常存续店铺']['value']);
|
||||
$this->assertSame(10.0, (float) $summaryCards['当月(7月)销量']['value']);
|
||||
$this->assertSame(1, $summaryCards['当月(7月)有销量店铺']['value']);
|
||||
$this->assertArrayNotHasKey('当月(7月)有销量店铺', $summaryCards);
|
||||
}
|
||||
|
||||
public function test_subject_operating_report_aggregates_income_by_entity(): void
|
||||
@ -467,7 +468,7 @@ class StoreReportRepositoryTest extends TestCase
|
||||
$summaryCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label');
|
||||
|
||||
$this->assertSame('小规模纳税人', $rows['存续主体']->tax_type);
|
||||
$this->assertSame('待维护', $rows['存续主体']->business_registration_type);
|
||||
$this->assertSame('/', $rows['存续主体']->business_registration_type);
|
||||
$this->assertSame('/', $rows['注销主体']->tax_type);
|
||||
$this->assertSame('/', $rows['注销主体']->business_registration_type);
|
||||
$this->assertSame(1, $summaryCards['正常存续主体']['value']);
|
||||
@ -521,7 +522,7 @@ class StoreReportRepositoryTest extends TestCase
|
||||
$rows = collect($service->paginate('company-management', 'subject-operating-report', 50)->items())->keyBy('entity');
|
||||
$summaryCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label');
|
||||
|
||||
$this->assertSame('待维护', $rows['保留主体']->business_registration_type);
|
||||
$this->assertSame('/', $rows['保留主体']->business_registration_type);
|
||||
$this->assertSame('/', $rows['待注销主体']->tax_type);
|
||||
$this->assertSame('/', $rows['待注销主体']->business_registration_type);
|
||||
$this->assertSame(1, $summaryCards['正常存续主体']['value']);
|
||||
|
||||
@ -219,7 +219,7 @@ class UpstreamBusinessInformationTest extends TestCase
|
||||
->paginate('store-management', 'basic-information');
|
||||
}
|
||||
|
||||
public function test_subject_operating_report_keeps_all_income_months_visible_by_default(): void
|
||||
public function test_subject_operating_report_hides_income_months_without_data_by_default(): void
|
||||
{
|
||||
$mirror = Mockery::mock(BusinessInformationMirrorRepository::class);
|
||||
$mirror->shouldReceive('ready')->with('store-information.read')->andReturnTrue();
|
||||
@ -258,7 +258,8 @@ class UpstreamBusinessInformationTest extends TestCase
|
||||
|
||||
$paginator = $information->paginate('company-management', 'subject-operating-report', 50);
|
||||
|
||||
$this->assertNull(
|
||||
$this->assertSame(
|
||||
['income_01', 'income_04', 'income_05', 'income_06', 'income_07', 'income_08', 'income_09', 'income_10', 'income_11', 'income_12'],
|
||||
$this->app['request']->attributes->get('subject-operating-report.default_hidden_columns'),
|
||||
);
|
||||
$this->assertSame(1, $paginator->total());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user