指摘対応エラー修正
This commit is contained in:
parent
00a15f6a35
commit
c1973b96c0
@ -14,7 +14,8 @@ use Illuminate\Support\Facades\DB;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Response;
|
// use Response;
|
||||||
|
use Illuminate\Support\Facades\Response;
|
||||||
|
|
||||||
class PriceController extends Controller
|
class PriceController extends Controller
|
||||||
{
|
{
|
||||||
@ -136,74 +137,64 @@ class PriceController extends Controller
|
|||||||
return self::whereIn('price_parkplaceid', $ids)->delete();
|
return self::whereIn('price_parkplaceid', $ids)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export(Request $request)
|
public function exportGet(Request $request)
|
||||||
{
|
{
|
||||||
$headers = [
|
$headers = [
|
||||||
"Content-type" => "text/csv;charset=UTF-8",
|
"Content-Type" => "text/csv; charset=UTF-8",
|
||||||
'Content-Encoding: UTF-8',
|
"Content-Disposition" => "attachment; filename=駐輪場所、料金マスタ.csv",
|
||||||
"Content-Disposition" => "attachment; filename=file.csv",
|
|
||||||
"Pragma" => "no-cache",
|
|
||||||
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
|
|
||||||
"Expires" => "0"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = Price::query();
|
$query = Price::query();
|
||||||
|
|
||||||
// 🚩 条件付きエクスポート(park_id)
|
// 🔹 パラメータ取得(GETでもOK)
|
||||||
if ($request->filled('park_id')) {
|
if ($request->filled('park_id')) {
|
||||||
$query->where('park_id', $request->input('park_id'));
|
$query->where('park_id', $request->input('park_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ソート
|
|
||||||
if ($request->filled('sort')) {
|
if ($request->filled('sort')) {
|
||||||
$query->orderBy($request->input('sort'), $request->input('sort_type', 'asc'));
|
$query->orderBy($request->input('sort'), $request->input('sort_type', 'asc'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dataExport = $query->get();
|
$dataExport = $query->get();
|
||||||
|
|
||||||
|
// 🔹 CSV列定義
|
||||||
$columns = [
|
$columns = [
|
||||||
__('駐車場所ID'),
|
'駐車場所ID', '商品名', '期間', '駐輪場ID', '駐輪場名',
|
||||||
__('商品名'),
|
'車種区分ID', '車種区分', '駐輪分類ID', '駐輪分類',
|
||||||
__('期間'),
|
'利用者分類ID', '利用者分類', '駐車車室ID', '駐輪料金(税込)',
|
||||||
__('駐輪場ID'),
|
|
||||||
__('駐輪場名'),
|
|
||||||
__('車種区分ID'),
|
|
||||||
__('車種区分'),
|
|
||||||
__('駐輪分類ID'),
|
|
||||||
__('駐輪分類'),
|
|
||||||
__('利用者分類ID'),
|
|
||||||
__('利用者分類'),
|
|
||||||
__('駐車車室ID'),
|
|
||||||
__('駐輪料金(税込)'),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$filename = "駐輪場所、料金マスタ.csv";
|
// 🔹 CSV生成
|
||||||
$file = fopen($filename, 'w+');
|
$filename = '駐輪場所、料金マスタ.csv';
|
||||||
|
$path = storage_path('app/' . $filename);
|
||||||
|
$file = fopen($path, 'w+');
|
||||||
|
fwrite($file, "\xEF\xBB\xBF"); // Excel対応のBOM
|
||||||
fputcsv($file, $columns);
|
fputcsv($file, $columns);
|
||||||
|
|
||||||
foreach ($dataExport as $items) {
|
foreach ($dataExport as $item) {
|
||||||
fputcsv($file, [
|
fputcsv($file, [
|
||||||
$items->price_parkplaceid,
|
$item->price_parkplaceid,
|
||||||
$items->prine_name,
|
$item->prine_name,
|
||||||
$items->price_month,
|
$item->price_month,
|
||||||
$items->park_id,
|
$item->park_id,
|
||||||
optional($items->getPark())->park_name,
|
optional($item->getPark())->park_name,
|
||||||
$items->psection_id,
|
$item->psection_id,
|
||||||
optional($items->getPSection())->psection_subject,
|
optional($item->getPSection())->psection_subject,
|
||||||
$items->price_ptypeid,
|
$item->price_ptypeid,
|
||||||
optional($items->getPType())->ptype_subject,
|
optional($item->getPType())->ptype_subject,
|
||||||
$items->user_categoryid,
|
$item->user_categoryid,
|
||||||
optional($items->getUserType())->print_name,
|
optional($item->getUserType())->print_name,
|
||||||
$items->pplace_id,
|
$item->pplace_id,
|
||||||
$items->price,
|
$item->price,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($file);
|
fclose($file);
|
||||||
|
|
||||||
return Response::download($filename, $filename, $headers);
|
// 🔹 ダウンロードレスポンス
|
||||||
|
return response()->download($path, $filename, $headers)->deleteFileAfterSend(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function import(Request $request)
|
public function import(Request $request)
|
||||||
{
|
{
|
||||||
$file = $request->file('file');
|
$file = $request->file('file');
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class Price extends Model
|
|||||||
5 => '12ヶ月',
|
5 => '12ヶ月',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $table = 'price_a';
|
protected $table = 'price';
|
||||||
protected $primaryKey = 'price_parkplaceid';
|
protected $primaryKey = 'price_parkplaceid';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
@ -44,14 +44,14 @@ class Price extends Model
|
|||||||
{
|
{
|
||||||
$query = self::query()
|
$query = self::query()
|
||||||
->select(
|
->select(
|
||||||
'price_a.*',
|
'price.*',
|
||||||
\DB::raw("CONCAT_WS('/', usertype.usertype_subject1, usertype.usertype_subject2, usertype.usertype_subject3) as user_category_name"),
|
\DB::raw("CONCAT_WS('/', usertype.usertype_subject1, usertype.usertype_subject2, usertype.usertype_subject3) as user_category_name"),
|
||||||
'psection.psection_subject',
|
'psection.psection_subject',
|
||||||
'ptype.ptype_subject'
|
'ptype.ptype_subject'
|
||||||
)
|
)
|
||||||
->leftJoin('usertype', 'price_a.user_categoryid', '=', 'usertype.user_categoryid')
|
->leftJoin('usertype', 'price.user_categoryid', '=', 'usertype.user_categoryid')
|
||||||
->leftJoin('psection', 'price_a.psection_id', '=', 'psection.psection_id')
|
->leftJoin('psection', 'price.psection_id', '=', 'psection.psection_id')
|
||||||
->leftJoin('ptype', 'price_a.price_ptypeid', '=', 'ptype.ptype_id');
|
->leftJoin('ptype', 'price.price_ptypeid', '=', 'ptype.ptype_id');
|
||||||
|
|
||||||
// ソート対象カラム
|
// ソート対象カラム
|
||||||
$allowedSortColumns = [
|
$allowedSortColumns = [
|
||||||
|
|||||||
@ -41,17 +41,17 @@
|
|||||||
{{-- 削除 --}}
|
{{-- 削除 --}}
|
||||||
<button type="button" class="btn btn-sm btn-default mr10" id="delete">{{ __('削除') }}</button>
|
<button type="button" class="btn btn-sm btn-default mr10" id="delete">{{ __('削除') }}</button>
|
||||||
|
|
||||||
{{-- CSV出力(全件 or ソート条件付き) --}}
|
|
||||||
<form id="form_export" method="POST" action="{{ route('prices_export') }}" class="d-inline">
|
<form id="form_export_csv" method="POST" action="{{ route('prices_export') }}" style="display:inline;">
|
||||||
@csrf
|
@csrf
|
||||||
|
<input type="hidden" name="park_id" value="{{ $park_id ?? '' }}">
|
||||||
<input type="hidden" name="sort" value="{{ $sort ?? '' }}">
|
<input type="hidden" name="sort" value="{{ $sort ?? '' }}">
|
||||||
<input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">
|
<input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">
|
||||||
<button type="button" class="btn btn-sm btn-default mr10" id="btn_export_csv">CSV出力</button>
|
<button type="button" id="export_csv" class="btn btn-sm btn-default mr10">
|
||||||
|
CSV出力
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{{-- エクスポート(条件選択モーダル) --}}
|
{{-- エクスポート(条件選択モーダル) --}}
|
||||||
<button type="button" class="btn btn-sm btn-default mr10" data-toggle="modal" data-target="#exportModal">
|
<button type="button" class="btn btn-sm btn-default mr10" data-toggle="modal" data-target="#exportModal">
|
||||||
エクスポート
|
エクスポート
|
||||||
@ -83,7 +83,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-center">
|
<div class="modal-footer justify-content-center">
|
||||||
<button type="submit" class="btn btn-primary w-25">OK</button>
|
<button type="submit" class="btn btn-primary w-25">はい</button>
|
||||||
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
|
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -107,7 +107,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-center">
|
<div class="modal-footer justify-content-center">
|
||||||
<button type="submit" class="btn btn-primary w-25">OK</button>
|
<button type="submit" class="btn btn-primary w-25">はい</button>
|
||||||
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
|
<button type="button" class="btn btn-secondary w-25" data-dismiss="modal">キャンセル</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -225,65 +225,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
@endsection
|
|
||||||
|
|
||||||
|
|
||||||
@section('scripts')
|
|
||||||
<!-- 载入 jQuery 和 jquery-confirm 工具包(从 CDN) -->
|
|
||||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.css">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
|
|
||||||
|
|
||||||
<!-- CSV 出力脚本 -->
|
|
||||||
<script>
|
|
||||||
$(function() {
|
|
||||||
// ▼ CSV出力ボタン押下
|
|
||||||
$('#btn_export_csv').on('click', function () {
|
|
||||||
const _action = $(this).closest('form').attr('action') || '';
|
|
||||||
|
|
||||||
const park_id = $('#park_id').val() || '';
|
|
||||||
const user_category_id = $('#user_category_id').val() || '';
|
|
||||||
const price_parkplaceid = $('#price_parkplaceid').val() || '';
|
|
||||||
const prine_name = $('#prine_name').val() || '';
|
|
||||||
const ptype_id = $('#ptype_id').val() || '';
|
|
||||||
const psection_id = $('#psection_id').val() || '';
|
|
||||||
const pplace_id = $('#pplace_id').val() || '';
|
|
||||||
const sort = $('input[name="sort"]').val() || '';
|
|
||||||
const sort_type = $('input[name="sort_type"]').val() || '';
|
|
||||||
|
|
||||||
$.confirm({
|
|
||||||
title: '確認ダイアログ',
|
|
||||||
content: 'CSVファイルを出力します。よろしいですか?',
|
|
||||||
buttons: {
|
|
||||||
ok: {
|
|
||||||
text: 'はい',
|
|
||||||
btnClass: 'btn-primary',
|
|
||||||
keys: ['enter'],
|
|
||||||
action: function() {
|
|
||||||
const url =
|
|
||||||
`${_action}?` +
|
|
||||||
`park_id=${encodeURIComponent(park_id)}` +
|
|
||||||
`&user_category_id=${encodeURIComponent(user_category_id)}` +
|
|
||||||
`&price_parkplaceid=${encodeURIComponent(price_parkplaceid)}` +
|
|
||||||
`&prine_name=${encodeURIComponent(prine_name)}` +
|
|
||||||
`&ptype_id=${encodeURIComponent(ptype_id)}` +
|
|
||||||
`&psection_id=${encodeURIComponent(psection_id)}` +
|
|
||||||
`&pplace_id=${encodeURIComponent(pplace_id)}` +
|
|
||||||
`&sort=${encodeURIComponent(sort)}` +
|
|
||||||
`&sort_type=${encodeURIComponent(sort_type)}` +
|
|
||||||
`&isExport=1`;
|
|
||||||
|
|
||||||
window.location.href = url;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cancel: {
|
|
||||||
text: 'いいえ'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -184,8 +184,12 @@ Route::middleware('auth')->group(function () {
|
|||||||
Route::match(['get', 'post'], '/admin/prices/info/{id}', [PriceController::class, 'info'])->name('price_info')->where(['id' => '[0-9]+']);
|
Route::match(['get', 'post'], '/admin/prices/info/{id}', [PriceController::class, 'info'])->name('price_info')->where(['id' => '[0-9]+']);
|
||||||
Route::match(['get', 'post'], '/admin/prices/delete', [PriceController::class, 'delete'])->name('prices_delete');
|
Route::match(['get', 'post'], '/admin/prices/delete', [PriceController::class, 'delete'])->name('prices_delete');
|
||||||
Route::match(['get', 'post'], '/admin/prices/import', [PriceController::class, 'import'])->name('prices_import');
|
Route::match(['get', 'post'], '/admin/prices/import', [PriceController::class, 'import'])->name('prices_import');
|
||||||
|
|
||||||
// kin 修正
|
// kin 修正
|
||||||
Route::post('/admin/prices/export', [PriceController::class, 'export'])->name('prices_export');
|
// CSV出力(GET対応版)
|
||||||
|
Route::get('/admin/prices/export', [PriceController::class, 'exportGet'])
|
||||||
|
->name('prices_export');
|
||||||
|
|
||||||
|
|
||||||
//車種区分マスタ
|
//車種区分マスタ
|
||||||
Route::match(['get', 'post'], '/admin/psection', [PsectionController::class, 'list'])->name('psections');
|
Route::match(['get', 'post'], '/admin/psection', [PsectionController::class, 'list'])->name('psections');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user