新增「供应商对账」目录:财务端按供应商查看实时上传情况与行级差异(条码+单价 匹配:一致/厂家多/金额不一致/厂家少,口径分别为正常结算/不结算退回/按金额低结算/按厂家结算);厂家端上传严格按对账单模板校验(表头列名与顺序必须一致、快递名称/快递单号/单据编号可空、其余必填、数值列必须是数字、供应商必须与厂家一致,不合规整份失败并提示行号);复用终版按表数据存储与流式读取能力,模板随包发布。
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Business;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\EcommerceFinance\Services\SupplierStatementStore;
|
|
use Modules\EcommerceFinance\Services\SupplierStatementTemplate;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
/**
|
|
* 供应商对账:对账单模板下载 + 厂家对账单上传(严格按模板校验)。
|
|
*/
|
|
class SupplierReconciliation extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly SupplierStatementTemplate $template,
|
|
private readonly SupplierStatementStore $statements,
|
|
) {
|
|
$this->middleware('auth');
|
|
$this->middleware('company.identify');
|
|
}
|
|
|
|
public function template(): BinaryFileResponse
|
|
{
|
|
$path = $this->template->path();
|
|
abort_unless(is_file($path), 404, '对账单模板不存在。');
|
|
|
|
return response()->download($path, $this->template->filename());
|
|
}
|
|
|
|
public function upload(Request $request): JsonResponse|RedirectResponse
|
|
{
|
|
$request->validate([
|
|
'import' => ['required', 'file', 'mimes:xlsx,xls,csv', 'max:51200'],
|
|
'supplier' => ['required', 'string', 'max:191'],
|
|
]);
|
|
|
|
$supplier = trim((string) $request->input('supplier'));
|
|
if ($supplier === '') {
|
|
abort(422, '请选择厂家。');
|
|
}
|
|
|
|
$records = $this->template->parse($request->file('import'), $supplier);
|
|
$rows = $this->statements->save(
|
|
$supplier,
|
|
$records,
|
|
(string) $request->file('import')->getClientOriginalName(),
|
|
(int) (company_id() ?: 1),
|
|
user_id() ? (int) user_id() : null,
|
|
);
|
|
|
|
$message = "对账单已保存:{$supplier} 共 {$rows} 行。";
|
|
|
|
return $request->expectsJson()
|
|
? response()->json(['message' => $message, 'rows' => $rows])
|
|
: back()->with('success', $message);
|
|
}
|
|
}
|