CaiWuXiTong/app/Console/Commands/ImportKukaPostingMaterialSource.php
chenxi a1783bf0eb feat(顾家过账): 支持按整表物料源修正发货明细 (#1271)
整表物料源逐行修正有效物料、成本和发货金额,#N/A 行保持原样,页面优先使用修正物料。

验证:导入器 5 个测试、53 条断言;页面 9 个测试、112 条断言;生产审计 8,837 行有效、5,112 行 #N/A。
2026-11-19 15:32:05 +08:00

65 lines
2.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Business\KukaPostingBase\KukaPostingMaterialRepairImporter;
use Illuminate\Console\Command;
use Throwable;
class ImportKukaPostingMaterialSource extends Command
{
protected $signature = 'business-mirror:import-kuka-posting-material-source
{path : 包含完整发货明细和物料信息的 XLSX 文件}
{--month= : 账期 YYYY-MM}
{--sheet=Sheet1 : 工作表名称}
{--company=1 : 公司 ID}
{--dry-run : 只校验文件、物料报价和共享镜像,不写入}';
protected $description = '按整表物料源文件修正顾家过账发货明细的物料、成本和金额';
public function handle(KukaPostingMaterialRepairImporter $importer): int
{
$period = trim((string) $this->option('month'));
if ($period === '') {
$this->error('必须指定 --month=YYYY-MM。');
return self::FAILURE;
}
try {
$result = $importer->importSource(
(string) $this->argument('path'),
$period,
(string) ($this->option('sheet') ?: 'Sheet1'),
max(1, (int) $this->option('company')),
(bool) $this->option('dry-run'),
);
} catch (Throwable $exception) {
$this->error('顾家过账物料源修正未导入,原有数据未改变。' . $exception->getMessage());
return self::FAILURE;
}
$storeRows = [];
foreach ($result['stores'] as $store => $count) {
$storeRows[] = [$store, number_format($count)];
}
$this->table(['项目', '值'], [
['模式', $result['dry_run'] ? '仅校验' : '正式导入'],
['账期', $result['period']],
['源文件行数', number_format($result['rows'])],
['有效物料行数', number_format($result['valid_rows'])],
['#N/A 等跳过行数', number_format($result['skipped_unmapped_rows'])],
['物料编号数', number_format($result['materials'])],
['需要更新', number_format($result['updated'])],
['已一致', number_format($result['unchanged'])],
['文件 SHA-256', $result['file_sha256']],
]);
$this->table(['店铺', '有效物料行数'], $storeRows);
$this->info($result['dry_run'] ? '顾家过账整表物料校验完成。' : '顾家过账整表物料已修正。');
return self::SUCCESS;
}
}