契約許容市区マスタCSVエクスポート修正
All checks were successful
Deploy main / deploy (push) Successful in 27s

This commit is contained in:
kin.rinzen 2025-10-28 15:16:44 +09:00
parent aa91bc6617
commit ae331335f8
4 changed files with 40 additions and 87 deletions

View File

@ -128,25 +128,6 @@ class ContractAllowableCityController extends Controller
]); ]);
} }
/**
* 詳細参照(表示のみ)
*/
public function info($id)
{
$record = ContractAllowableCity::getByPk($id);
if (!$record) {
return redirect()->route('contract_allowable_cities')->with('error', 'データが存在しません');
}
return view('admin.contract_allowable_cities.edit', [
'record' => $record,
'cityList' => City::getList(),
'parkList' => Park::getList(),
'mode' => 'info'
]);
}
/** /**
* 一括削除(単一・複数対応) * 一括削除(単一・複数対応)
*/ */
@ -174,37 +155,50 @@ class ContractAllowableCityController extends Controller
} }
/** /**
* CSVエクスポート * 契約許容市区マスタ CSVエクスポート
*/ */
public function export(Request $request) public function export(Request $request)
{ {
$filename = 'contract_allowable_cities_' . now()->format('Ymd_His') . '.csv'; $filename = '契約許容市区マスタ_' . now()->format('YmdHis') . '.csv';
// 検索条件でデータ取得
$list = ContractAllowableCity::search($request->all()); $list = ContractAllowableCity::search($request->all());
$headers = [ // CSVファイル作成
'Content-Type' => 'text/csv', $file = fopen($filename, 'w+');
'Content-Disposition' => "attachment; filename=\"$filename\"", fwrite($file, "\xEF\xBB\xBF"); // UTF-8 BOM追加
// ヘッダー行
$columns = [
'契約許容市区ID',
'市区ID',
'許容市区名',
'駐輪場ID',
'隣接区フラグ'
]; ];
fputcsv($file, $columns);
return new StreamedResponse(function () use ($list) { // データ行
$handle = fopen('php://output', 'w');
// ヘッダー
fputcsv($handle, ['契約許容市区ID', '市区ID', '許容市区名', '駐輪場ID', '隣接区フラグ']);
foreach ($list as $item) { foreach ($list as $item) {
fputcsv($handle, [ fputcsv($file, [
$item->contract_allowable_city_id, $item->contract_allowable_city_id,
$item->city_id, $item->city_id,
$item->contract_allowable_city_name, $item->contract_allowable_city_name,
$item->park_id, $item->park_id,
$item->same_district_flag == 0 ? '隣接市' : 'その他' $item->same_district_flag == 0 ? '隣接市' : 'その他',
]); ]);
} }
fclose($handle); fclose($file);
}, 200, $headers);
// ヘッダー設定
$headers = [
"Content-Type" => "text/csv; charset=UTF-8",
"Content-Disposition" => "attachment; filename={$filename}",
];
// ダウンロード後に一時ファイル削除
return response()->download($filename, $filename, $headers)->deleteFileAfterSend(true);
} }
} }

View File

@ -3,6 +3,7 @@
<!-- バリデーションエラー表示 --> <!-- バリデーションエラー表示 -->
@if ($errors->any()) @if ($errors->any())
<div class="form-group col-12"> <div class="form-group col-12">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<div class="alert alert-danger"> <div class="alert alert-danger">
<ul> <ul>
@foreach ($errors->all() as $error) @foreach ($errors->all() as $error)

View File

@ -146,46 +146,4 @@
<!-- 単一テーブル構成ここまで --> <!-- 単一テーブル構成ここまで -->
</div> </div>
</section> </section>
<script>
$(document).ready(function () {
// 並び替え
$('.sorting').click(function () {
var sortColumn = $(this).attr('sort');
var currentSortType = $('#sort_type').val();
var newSortType = (sortColumn === $('#sort').val() && currentSortType === 'asc') ? 'desc' : 'asc';
$('#sort').val(sortColumn);
$('#sort_type').val(newSortType);
$('#list-form').submit();
});
// 全選択チェック
$('#checkbox_all').change(function () {
$('.checkbox').prop('checked', this.checked);
});
// 削除ボタン
$('#delete').click(function () {
if ($('.checkbox:checked').length === 0) {
alert('削除する項目を選択してください。');
return false;
}
if (confirm('選択された項目を削除しますか?')) {
$('#form_delete').submit();
}
});
// CSV出力
$('#export_csv').click(function () {
var action = $(this).attr('action');
var form = $('#list-form');
var originalAction = form.attr('action');
form.attr('action', action);
form.find('[name="isExport"]').remove();
form.append('<input type="hidden" name="isExport" value="1">');
form.submit();
form.attr('action', originalAction);
});
});
</script>
@endsection @endsection

View File

@ -26,7 +26,7 @@
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" <input type="text"
name="ptype_id" name="ptype_id"
class="form-control" class="form-control form-control-lg"
value="{{ $record->ptype_id }}" value="{{ $record->ptype_id }}"
readonly> readonly>
</div> </div>
@ -41,7 +41,7 @@
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" <input type="text"
name="ptype_subject" name="ptype_subject"
class="form-control" class="form-control form-control-lg"
value="{{ $isEdit ? old('ptype_subject', $record->ptype_subject ?? '') : '' }}" value="{{ $isEdit ? old('ptype_subject', $record->ptype_subject ?? '') : '' }}"
placeholder="{{ __('validation.attributes.psection_subject') }}" placeholder="{{ __('validation.attributes.psection_subject') }}"
required> required>
@ -54,7 +54,7 @@
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" <input type="text"
name="floor_sort" name="floor_sort"
class="form-control" class="form-control form-control-lg"
value="{{ $isEdit ? old('floor_sort', $record->floor_sort ?? '') : '' }}" value="{{ $isEdit ? old('floor_sort', $record->floor_sort ?? '') : '' }}"
placeholder="{{ __('validation.attributes.floor_sort') }}"> placeholder="{{ __('validation.attributes.floor_sort') }}">
</div> </div>
@ -66,7 +66,7 @@
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" <input type="text"
name="ptype_remarks" name="ptype_remarks"
class="form-control" class="form-control form-control-lg"
value="{{ $isEdit ? old('ptype_remarks', $record->ptype_remarks ?? '') : '' }}" value="{{ $isEdit ? old('ptype_remarks', $record->ptype_remarks ?? '') : '' }}"
placeholder="{{ $isEdit ? '' : __('validation.attributes.ptype_remarks') }}"> placeholder="{{ $isEdit ? '' : __('validation.attributes.ptype_remarks') }}">
</div> </div>