57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Modules\EcommerceFinance\Services\BankBillStatementImporter;
|
||
use Throwable;
|
||
|
||
class ImportBankBills extends Command
|
||
{
|
||
protected $signature = 'finance-ledger:import-bank-bills
|
||
{path : 银行批量账单 XLSX/XLS/CSV 文件}
|
||
{--bank= : 招商银行、华夏银行或网商银行}
|
||
{--dry-run : 只校验,不写入账单数据}
|
||
{--replace : 先清空该银行旧账单,再导入本次文件}';
|
||
|
||
protected $description = '按已导入的银行表头导入原始账单明细';
|
||
|
||
public function handle(BankBillStatementImporter $importer): int
|
||
{
|
||
try {
|
||
$result = $importer->import(
|
||
(string) $this->argument('path'),
|
||
(string) $this->option('bank'),
|
||
(bool) $this->option('dry-run'),
|
||
(bool) $this->option('replace'),
|
||
);
|
||
} catch (Throwable $exception) {
|
||
$this->error($exception->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$this->info(sprintf(
|
||
'%s%s:%d 条,新增 %d 条,更新 %d 条,跳过 %d 条;涉及 %d 个账户。',
|
||
$result['dry_run'] ? '校验完成,' : '账单已导入,',
|
||
$result['bank'],
|
||
$result['rows'],
|
||
$result['inserted'],
|
||
$result['updated'],
|
||
$result['skipped'],
|
||
$result['accounts'],
|
||
));
|
||
$this->line(sprintf(
|
||
'账务日期:%s 至 %s。',
|
||
$result['first_date'] ?? '无',
|
||
$result['last_date'] ?? '无',
|
||
));
|
||
$this->line(sprintf(
|
||
'已同步 %d 个账户的当前余额。',
|
||
$result['synced_accounts'],
|
||
));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|