CaiWuXiTong/app/Console/Commands/ImportInventoryInboundDetail.php

43 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Business\InventoryInboundDetailImporter;
use Illuminate\Console\Command;
use Throwable;
/**
* 进销存报表 → 入库明细数据:按原始 Excel 原样导入,仓库简称用仓库名称映射表按「仓库」唯一匹配。
*/
class ImportInventoryInboundDetail extends Command
{
protected $signature = 'inventory:inbound-detail:import {file : 入库明细表 Excel} {--month= : 统一指定月份(不传则按创建时间判断)}';
protected $description = '导入进销存报表的入库明细数据';
public function handle(InventoryInboundDetailImporter $importer): int
{
$file = (string) $this->argument('file');
$forcedMonth = trim((string) ($this->option('month') ?? ''));
try {
$result = $importer->import($file, $forcedMonth);
$this->info(sprintf(
'导入完成:%d 行,仓库简称匹配上 %d 行,跳过 %d 行;库中该表共 %d 行',
$result['imported'],
$result['mapped'],
$result['skipped'],
$result['total'],
));
return self::SUCCESS;
} catch (Throwable $exception) {
report($exception);
$this->error('入库明细导入失败:' . $exception->getMessage());
$this->warn('已保留上一版有效数据。');
return self::FAILURE;
}
}
}