diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index c8e7866d..be7ea85c 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -551,6 +551,59 @@ class Pages extends Controller }, $filename, ['Content-Type' => 'text/csv; charset=UTF-8']); } + /** + * 进销存报表 → 入库明细数据导出(按月份/仓库/条码筛选,列顺序与页面一致)。 + */ + public function exportInventoryInboundDetail(Request $request): StreamedResponse + { + $connection = (string) config('upstream_mirrors.connection', 'business_mirror'); + $labels = [ + 'source_no' => '来源单号', 'document_no' => '单据编号(采购单号)', 'created_serial' => '创建时间', + 'supplier' => '供应商', 'item_no' => '货号', 'barcode' => '条码', 'spec_name' => '规格名', + 'quantity' => '库存变动量', 'unit_price' => '单价', 'amount' => '金额', + 'estimated_unit_price' => '预估单价', 'estimated_amount' => '预估金额', + 'supplier_barcode' => '供应商条码', 'remark' => '备注', 'warehouse' => '仓库', + 'warehouse_short_name' => '仓库简称', 'created_at_raw' => '创建时间(实际)', + 'express_name' => '快递名称', 'express_no' => '快递单号', 'not_sent' => '未发出', 'owner_name' => '负责人', + ]; + + $query = DB::connection($connection)->table('inventory_inbound_detail_rows'); + $month = substr(trim((string) $request->query('detail_month', '')), 0, 10); + if ($month !== '') { + $query->where('report_month', $month); + } + $warehouse = trim((string) $request->query('detail_warehouse', '')); + if ($warehouse !== '') { + $like = '%' . addcslashes($warehouse, '%_\\') . '%'; + $query->where(function ($inner) use ($like): void { + $inner->where('warehouse', 'like', $like)->orWhere('warehouse_short_name', 'like', $like); + }); + } + $barcode = trim((string) $request->query('detail_barcode', '')); + if ($barcode !== '') { + $query->where('barcode', 'like', '%' . addcslashes($barcode, '%_\\') . '%'); + } + + $filename = '入库明细数据_' . ($month !== '' ? $month : 'all') . '.csv'; + + return response()->streamDownload(function () use ($query, $labels): void { + $out = fopen('php://output', 'w'); + fwrite($out, "\xEF\xBB\xBF"); + fputcsv($out, array_values($labels)); + $query->orderBy('row_key')->chunk(1000, function ($rows) use ($out, $labels): void { + foreach ($rows as $row) { + $line = []; + foreach (array_keys($labels) as $column) { + $value = $row->{$column} ?? ''; + $line[] = is_string($value) ? $value : (string) $value; + } + fputcsv($out, $line); + } + }); + fclose($out); + }, $filename, ['Content-Type' => 'text/csv; charset=UTF-8']); + } + protected function viewData( array $section, ?array $page = null, diff --git a/resources/views/business/pages/partials/directory-table.blade.php b/resources/views/business/pages/partials/directory-table.blade.php index 986739a4..d49eb666 100644 --- a/resources/views/business/pages/partials/directory-table.blade.php +++ b/resources/views/business/pages/partials/directory-table.blade.php @@ -1528,11 +1528,22 @@ } $inboundPage = max((int) request('detail_page', 1), 1); $inboundPerPage = 25; + $inboundWarehouse = trim((string) request('detail_warehouse', '')); + $inboundBarcode = trim((string) request('detail_barcode', '')); $inboundQuery = \Illuminate\Support\Facades\DB::connection($inboundConnection) ->table('inventory_inbound_detail_rows'); if ($inboundMonth !== '') { $inboundQuery->where('report_month', $inboundMonth); } + if ($inboundWarehouse !== '') { + $like = '%' . addcslashes($inboundWarehouse, '%_\\') . '%'; + $inboundQuery->where(function ($inner) use ($like): void { + $inner->where('warehouse', 'like', $like)->orWhere('warehouse_short_name', 'like', $like); + }); + } + if ($inboundBarcode !== '') { + $inboundQuery->where('barcode', 'like', '%' . addcslashes($inboundBarcode, '%_\\') . '%'); + } $inboundTotal = (clone $inboundQuery)->count(); $inboundRows = $inboundQuery ->orderBy('row_key') @@ -1552,10 +1563,10 @@ 已从共享业务镜像读取 {{ $inboundTotal }} 条入库明细,当前页面为只读展示。 -
+
-
+ + +
+ + 清除 + 导出 +
+
diff --git a/routes/admin.php b/routes/admin.php index ee40843a..042f6085 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -160,6 +160,10 @@ Route::get('workspace/product-inventory/monthly-weighted-average-price/export', ->middleware('permission:read-business-pages') ->name('business.product-inventory.monthly-weighted-average-price.export'); +Route::get('workspace/product-inventory/inventory-report/inbound-detail/export', 'Business\Pages@exportInventoryInboundDetail') + ->middleware('permission:read-business-pages') + ->name('business.product-inventory.inventory-report.inbound-detail.export'); + Route::get('workspace/product-inventory/inventory-report/export', 'Business\Pages@exportInventoryReport') ->middleware('business.page:product-inventory,inventory-report') ->name('business.product-inventory.inventory-report.export');