入库明细数据:加仓库/条码筛选与导出接口,样式对齐进销存总表筛选栏
This commit is contained in:
parent
f43ab57c49
commit
5ee0813490
@ -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,
|
||||
|
||||
@ -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 @@
|
||||
<span class="material-icons-outlined" aria-hidden="true">cloud_done</span>
|
||||
<span>已从共享业务镜像读取 {{ $inboundTotal }} 条入库明细,当前页面为只读展示。</span>
|
||||
</div>
|
||||
<div class="installation-filter-bar" aria-label="入库明细月份切换">
|
||||
<form method="GET" action="{{ request()->url() }}" class="installation-filter-bar" aria-label="入库明细筛选查询栏">
|
||||
<label class="installation-filter-field">
|
||||
<span>月份:</span>
|
||||
<select onchange="window.location.href='{{ request()->url() }}?detail_month=' + this.value + '#inventory-report-inbound-detail-panel'">
|
||||
<select name="detail_month" aria-label="月份">
|
||||
@foreach ($inboundMonths as $inboundMonthRow)
|
||||
@php $inboundMonthValue = substr((string) $inboundMonthRow->report_month, 0, 10); @endphp
|
||||
<option value="{{ $inboundMonthValue }}" @selected($inboundMonthValue === $inboundMonth)>
|
||||
@ -1564,7 +1575,20 @@
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<label class="installation-filter-field">
|
||||
<span>仓库:</span>
|
||||
<input type="text" name="detail_warehouse" value="{{ $inboundWarehouse }}" placeholder="仓库名称或简称,支持包含查询">
|
||||
</label>
|
||||
<label class="installation-filter-field">
|
||||
<span>条码:</span>
|
||||
<input type="text" name="detail_barcode" value="{{ $inboundBarcode }}" placeholder="支持包含查询">
|
||||
</label>
|
||||
<div class="installation-filter-actions">
|
||||
<button type="submit" class="biz-btn biz-btn-primary">查询</button>
|
||||
<a href="{{ request()->url() }}#inventory-report-inbound-detail-panel" class="biz-btn biz-btn-ghost">清除</a>
|
||||
<a href="{{ route('business.product-inventory.inventory-report.inbound-detail.export', ['detail_month' => $inboundMonth, 'detail_warehouse' => $inboundWarehouse ?: null, 'detail_barcode' => $inboundBarcode ?: null]) }}" class="biz-btn">导出</a>
|
||||
</div>
|
||||
</form>
|
||||
<div class="directory-table-scroll">
|
||||
<table class="directory-table" id="inventory-inbound-detail-table" data-finance-table-native>
|
||||
<thead>
|
||||
|
||||
@ -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');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user