validate([ 'receipt_from_supplier' => ['present', 'nullable', 'numeric', 'min:0', 'max:99999999999999'], ]); $amount = $data['receipt_from_supplier'] === null ? null : round((float) $data['receipt_from_supplier'], 2); $companyName = $repository->updateSupplierReceipt($record, $amount, user_id()); abort_if($companyName === null, 404); $projectionPayload = null; $projectionError = null; try { $projectionPayload = $projection->forMonth(); } catch (Throwable $exception) { report($exception); $projectionError = '主体维度报表上月业绩暂时无法读取,已保存供应商收票,其他自动计算暂时保留原值。'; } $saved = $repository->find($record, $projectionPayload); $filters = [ 'company_name' => (string) $request->input('company_name', ''), 'tag' => (string) $request->input('tag', ''), ]; if ($request->expectsJson()) { return response()->json([ 'ok' => true, 'record' => [ 'id' => (int) ($saved['id'] ?? $record), 'receipt_from_supplier' => $saved['receipt_from_supplier'] ?? null, 'receipt_total' => $saved['receipt_total'] ?? null, 'remaining_gap' => $saved['remaining_gap'] ?? null, ], 'summary' => $repository->summary($filters, $projectionPayload), 'warning' => $projectionError, ]); } return back()->with( $projectionError === null ? 'success' : 'warning', $projectionError ?? '收票-供应商已保存。', ); } }