This commit is contained in:
parent
b74d8fd4a8
commit
ed7d4482b8
@ -32,16 +32,26 @@ class PriceListController extends Controller
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($parkId) {
|
if ($parkId) {
|
||||||
// parkとprice_aをJOIN
|
// price_a に必要なマスタを JOIN
|
||||||
$aRows = \DB::table('price_a')
|
$aRows = \DB::table('price_a')
|
||||||
->join('park', 'park.park_id', '=', 'price_a.park_id')
|
->join('park', 'park.park_id', '=', 'price_a.park_id')
|
||||||
|
->leftJoin('ptype', 'price_a.ptype_id', '=', 'ptype.ptype_id')
|
||||||
|
->leftJoin('usertype', 'price_a.user_categoryid', '=', 'usertype.user_categoryid')
|
||||||
|
->leftJoin('pplace', 'price_a.pplace_id', '=', 'pplace.pplace_id')
|
||||||
->where('price_a.park_id', $parkId)
|
->where('price_a.park_id', $parkId)
|
||||||
->select('price_a.*') // 必要ならpark.*も
|
->select([
|
||||||
|
'price_a.*',
|
||||||
|
'ptype.ptype_subject',
|
||||||
|
'usertype.usertype_subject1',
|
||||||
|
'usertype.usertype_subject2',
|
||||||
|
'usertype.usertype_subject3',
|
||||||
|
'pplace.pplace_number'
|
||||||
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$aGrouped = $this->groupPriceRows($aRows);
|
$aGrouped = $this->groupPriceRows($aRows);
|
||||||
|
|
||||||
$masterList[0]['groups'] = $aGrouped;
|
$masterList[0]['groups'] = $aGrouped;
|
||||||
|
|
||||||
// マスターBも同様に取得・整形する場合はここに追加
|
// マスターBも同様に取得・整形する場合はここに追加
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,36 +70,38 @@ class PriceListController extends Controller
|
|||||||
$result = [];
|
$result = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
// グループキーは分類ID+ユーザ分類ID+駐輪場ID
|
// グループキーは分類ID+ユーザ分類ID+駐輪場ID
|
||||||
$key = $row->price_ptypeid . '-' . $row->user_categoryid . '-' . $row->park_id;
|
$key = $row->ptype_id . '-' . $row->user_categoryid . '-' . $row->park_id;
|
||||||
|
|
||||||
if (!isset($result[$key])) {
|
if (!isset($result[$key])) {
|
||||||
$result[$key] = [
|
$result[$key] = [
|
||||||
'id' => $row->price_parkplaceid,
|
'id' => $row->price_parkplaceid,
|
||||||
'classification' => $row->price_ptypeid,
|
'classification' => $row->ptype_subject ?? '',
|
||||||
'room_number' => '', // 必要ならpplace_id等をセット
|
'room_number' => $row->pplace_number ?? '',
|
||||||
'category1' => $row->prine_name ?? '',
|
'category1' => $row->usertype_subject1 ?? '',
|
||||||
'category2' => '',
|
'category2' => $row->usertype_subject2 ?? '',
|
||||||
'category3' => '',
|
'category3' => $row->usertype_subject3 ?? '',
|
||||||
'bike_1m' => '',
|
'bike_1m' => '', 'bike_2m' => '', 'bike_3m' => '', 'bike_6m' => '', 'bike_12m' => '',
|
||||||
'bike_2m' => '',
|
'moped_1m' => '', 'moped_2m' => '', 'moped_3m' => '', 'moped_6m' => '', 'moped_12m' => '',
|
||||||
'bike_3m' => '',
|
'motorcycle_1m' => '', 'motorcycle_2m' => '', 'motorcycle_3m' => '', 'motorcycle_6m' => '', 'motorcycle_12m' => '',
|
||||||
'bike_6m' => '',
|
'car_1m' => '', 'car_2m' => '', 'car_3m' => '', 'car_6m' => '', 'car_12m' => '',
|
||||||
'bike_12m' => '',
|
|
||||||
// 必要なら原付・自動二輪も同様に追加
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 月数ごとに金額をセット
|
$month = $row->price_month;
|
||||||
if ($row->price_month == 1) {
|
$price = $row->price;
|
||||||
$result[$key]['bike_1m'] = $row->price;
|
switch ($row->psection_id) {
|
||||||
} elseif ($row->price_month == 2) {
|
case 1:
|
||||||
$result[$key]['bike_2m'] = $row->price;
|
$result[$key]["bike_{$month}m"] = $price;
|
||||||
} elseif ($row->price_month == 3) {
|
break;
|
||||||
$result[$key]['bike_3m'] = $row->price;
|
case 2:
|
||||||
} elseif ($row->price_month == 6) {
|
$result[$key]["moped_{$month}m"] = $price;
|
||||||
$result[$key]['bike_6m'] = $row->price;
|
break;
|
||||||
} elseif ($row->price_month == 12) {
|
case 3:
|
||||||
$result[$key]['bike_12m'] = $row->price;
|
$result[$key]["motorcycle_{$month}m"] = $price;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$result[$key]["car_{$month}m"] = $price;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array_values($result);
|
return array_values($result);
|
||||||
@ -101,44 +113,60 @@ class PriceListController extends Controller
|
|||||||
$id = $row['id'] ?? null;
|
$id = $row['id'] ?? null;
|
||||||
if (!$id) continue;
|
if (!$id) continue;
|
||||||
|
|
||||||
// 更新対象の月リスト
|
$vehicleTypes = [
|
||||||
$months = [
|
'bike' => 1,
|
||||||
'bike_1m' => 1,
|
'moped' => 2,
|
||||||
'bike_2m' => 2,
|
'motorcycle' => 3,
|
||||||
'bike_3m' => 3,
|
'car' => 4,
|
||||||
'bike_6m' => 6,
|
|
||||||
'bike_12m' => 12,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($months as $field => $month) {
|
$months = [1, 2, 3, 6, 12];
|
||||||
|
|
||||||
|
foreach ($vehicleTypes as $prefix => $psectionId) {
|
||||||
|
foreach ($months as $month) {
|
||||||
|
$field = "{$prefix}_{$month}m";
|
||||||
if (isset($row[$field])) {
|
if (isset($row[$field])) {
|
||||||
// price_aから該当レコードを取得
|
$value = $row[$field];
|
||||||
$item = \App\Models\PriceA::where('price_parkplaceid', $id)
|
|
||||||
|
// バリデーション:空欄はスキップ
|
||||||
|
if (!ctype_digit((string)$value)) {
|
||||||
|
return back()->withErrors([
|
||||||
|
"{$field}" => "金額は整数で入力してください。"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// バリデーション:最大値を超えないこと
|
||||||
|
if ((int)$value > 9999999999) {
|
||||||
|
return back()->withErrors([
|
||||||
|
"{$field}" => "金額は最大 9,999,999,999 までです。"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = PriceA::where('price_parkplaceid', $id)
|
||||||
->where('price_month', $month)
|
->where('price_month', $month)
|
||||||
|
->where('psection_id', $psectionId)
|
||||||
->first();
|
->first();
|
||||||
if ($item) {
|
if ($item) {
|
||||||
$item->price = $row[$field];
|
$item->price = $value;
|
||||||
$item->save();
|
$item->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 原付・自動二輪も同様に必要なら追加
|
}
|
||||||
}
|
}
|
||||||
return back()->with('success', '金額を更新しました');
|
return back()->with('success', '金額を更新しました');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(Request $request)
|
public function insert(Request $request)
|
||||||
{
|
{
|
||||||
// 例:bike_2m(2ヶ月)だけ新規追加する場合
|
|
||||||
if ($request->filled('bike_2m')) {
|
if ($request->filled('bike_2m')) {
|
||||||
$row = new \App\Models\PriceA();
|
$row = new PriceA();
|
||||||
$row->park_id = $request->input('park_id'); // 必要に応じて
|
$row->park_id = $request->input('park_id');
|
||||||
$row->price = $request->input('bike_2m');
|
$row->price = $request->input('bike_2m');
|
||||||
$row->price_month = 2;
|
$row->price_month = 2;
|
||||||
// 他の必要なカラムもセット
|
$row->psection_id = 1; // 自転車
|
||||||
$row->save();
|
$row->save();
|
||||||
}
|
}
|
||||||
// 他の月も同様に必要なら追加
|
|
||||||
return back()->with('success', '金額を追加しました');
|
return back()->with('success', '金額を追加しました');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,16 +26,21 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{{-- 登録(POST フォームを指定して送信) --}}
|
{{-- 登録(POST フォームを指定して送信) --}}
|
||||||
<button type="submit"
|
<button type="submit" class="btn btn-default btn-sm ml-3 register" form="bulkUpdateForm">登録</button>
|
||||||
class="btn btn-primary btn-sm ml-3"
|
|
||||||
form="bulkUpdateForm">登録</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if ($errors->any())
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul class="mb-0">
|
||||||
|
@foreach ($errors->all() as $error)
|
||||||
|
<li>{{ $error }}</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
{{-- 一括更新フォーム(POST) --}}
|
{{-- 一括更新フォーム(POST) --}}
|
||||||
<form id="bulkUpdateForm"
|
<form id="bulkUpdateForm" method="POST" action="{{ route('pricelist_update') }}" onsubmit="return;">
|
||||||
method="POST"
|
|
||||||
action="{{ route('pricelist_update') }}"
|
|
||||||
onsubmit="return confirm('登録してよろしいですか?');">
|
|
||||||
@csrf
|
@csrf
|
||||||
{{-- 必要なら park_id を一緒に送る --}}
|
{{-- 必要なら park_id を一緒に送る --}}
|
||||||
<input type="hidden" name="park_id" value="{{ $parkId }}">
|
<input type="hidden" name="park_id" value="{{ $parkId }}">
|
||||||
@ -43,7 +48,7 @@
|
|||||||
@if(isset($masterList) && count($masterList))
|
@if(isset($masterList) && count($masterList))
|
||||||
@foreach($masterList as $master)
|
@foreach($masterList as $master)
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<div style="font-weight:bold;font-size:1.1em;">
|
<div class="text-center fw-bold" style="font-size:1.1em;">
|
||||||
{{ $master['name'] }}
|
{{ $master['name'] }}
|
||||||
<button type="button" class="btn btn-warning btn-sm ml-2" disabled>{{ $master['status'] }}</button>
|
<button type="button" class="btn btn-warning btn-sm ml-2" disabled>{{ $master['status'] }}</button>
|
||||||
</div>
|
</div>
|
||||||
@ -62,9 +67,21 @@
|
|||||||
<th colspan="5">自動二輪</th>
|
<th colspan="5">自動二輪</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>1ヶ月</th><th>2ヶ月</th><th>3ヶ月</th><th>6ヶ月</th><th>12ヶ月</th>
|
<th>1ヶ月</th>
|
||||||
<th>1ヶ月</th><th>2ヶ月</th><th>3ヶ月</th><th>6ヶ月</th><th>12ヶ月</th>
|
<th>2ヶ月</th>
|
||||||
<th>1ヶ月</th><th>2ヶ月</th><th>3ヶ月</th><th>6ヶ月</th><th>12ヶ月</th>
|
<th>3ヶ月</th>
|
||||||
|
<th>6ヶ月</th>
|
||||||
|
<th>12ヶ月</th>
|
||||||
|
<th>1ヶ月</th>
|
||||||
|
<th>2ヶ月</th>
|
||||||
|
<th>3ヶ月</th>
|
||||||
|
<th>6ヶ月</th>
|
||||||
|
<th>12ヶ月</th>
|
||||||
|
<th>1ヶ月</th>
|
||||||
|
<th>2ヶ月</th>
|
||||||
|
<th>3ヶ月</th>
|
||||||
|
<th>6ヶ月</th>
|
||||||
|
<th>12ヶ月</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -75,32 +92,48 @@
|
|||||||
<td>{{ $group['category1'] ?? '' }}</td>
|
<td>{{ $group['category1'] ?? '' }}</td>
|
||||||
<td>{{ $group['category2'] ?? '' }}</td>
|
<td>{{ $group['category2'] ?? '' }}</td>
|
||||||
<td>{{ $group['category3'] ?? '' }}</td>
|
<td>{{ $group['category3'] ?? '' }}</td>
|
||||||
|
|
||||||
<input type="hidden" name="rows[{{ $group['id'] }}][id]" value="{{ $group['id'] }}">
|
<input type="hidden" name="rows[{{ $group['id'] }}][id]" value="{{ $group['id'] }}">
|
||||||
|
|
||||||
{{-- 自転車 --}}
|
{{-- 自転車 --}}
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][bike_1m]" class="form-control form-control-sm price-input" value="{{ $group['bike_1m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][bike_1m]"
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][bike_2m]" class="form-control form-control-sm price-input" value="{{ $group['bike_2m'] ?? '' }}"></td>
|
class="form-control form-control-sm price-input" value="{{ $group['bike_1m'] ?? '' }}"></td>
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][bike_3m]" class="form-control form-control-sm price-input" value="{{ $group['bike_3m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][bike_2m]"
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][bike_6m]" class="form-control form-control-sm price-input" value="{{ $group['bike_6m'] ?? '' }}"></td>
|
class="form-control form-control-sm price-input" value="{{ $group['bike_2m'] ?? '' }}"></td>
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][bike_12m]" class="form-control form-control-sm price-input" value="{{ $group['bike_12m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][bike_3m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['bike_3m'] ?? '' }}"></td>
|
||||||
|
<td><input type="text" name="rows[{{ $group['id'] }}][bike_6m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['bike_6m'] ?? '' }}"></td>
|
||||||
|
<td><input type="text" name="rows[{{ $group['id'] }}][bike_12m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['bike_12m'] ?? '' }}"></td>
|
||||||
|
|
||||||
{{-- 原付 --}}
|
{{-- 原付 --}}
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][moped_1m]" class="form-control form-control-sm price-input" value="{{ $group['moped_1m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][moped_1m]"
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][moped_2m]" class="form-control form-control-sm price-input" value="{{ $group['moped_2m'] ?? '' }}"></td>
|
class="form-control form-control-sm price-input" value="{{ $group['moped_1m'] ?? '' }}"></td>
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][moped_3m]" class="form-control form-control-sm price-input" value="{{ $group['moped_3m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][moped_2m]"
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][moped_6m]" class="form-control form-control-sm price-input" value="{{ $group['moped_6m'] ?? '' }}"></td>
|
class="form-control form-control-sm price-input" value="{{ $group['moped_2m'] ?? '' }}"></td>
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][moped_12m]" class="form-control form-control-sm price-input" value="{{ $group['moped_12m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][moped_3m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['moped_3m'] ?? '' }}"></td>
|
||||||
|
<td><input type="text" name="rows[{{ $group['id'] }}][moped_6m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['moped_6m'] ?? '' }}"></td>
|
||||||
|
<td><input type="text" name="rows[{{ $group['id'] }}][moped_12m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['moped_12m'] ?? '' }}"></td>
|
||||||
|
|
||||||
{{-- 自動二輪 --}}
|
{{-- 自動二輪 --}}
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_1m]" class="form-control form-control-sm price-input" value="{{ $group['motorcycle_1m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_1m]"
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_2m]" class="form-control form-control-sm price-input" value="{{ $group['motorcycle_2m'] ?? '' }}"></td>
|
class="form-control form-control-sm price-input" value="{{ $group['motorcycle_1m'] ?? '' }}"></td>
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_3m]" class="form-control form-control-sm price-input" value="{{ $group['motorcycle_3m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_2m]"
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_6m]" class="form-control form-control-sm price-input" value="{{ $group['motorcycle_6m'] ?? '' }}"></td>
|
class="form-control form-control-sm price-input" value="{{ $group['motorcycle_2m'] ?? '' }}"></td>
|
||||||
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_12m]" class="form-control form-control-sm price-input" value="{{ $group['motorcycle_12m'] ?? '' }}"></td>
|
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_3m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['motorcycle_3m'] ?? '' }}"></td>
|
||||||
|
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_6m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['motorcycle_6m'] ?? '' }}"></td>
|
||||||
|
<td><input type="text" name="rows[{{ $group['id'] }}][motorcycle_12m]"
|
||||||
|
class="form-control form-control-sm price-input" value="{{ $group['motorcycle_12m'] ?? '' }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr><td colspan="21" class="text-center">データがありません。</td></tr>
|
<tr>
|
||||||
|
<td colspan="21" class="text-center">データがありません。</td>
|
||||||
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -113,7 +146,9 @@
|
|||||||
<table class="table table-bordered table-sm bg-white mt-2" style="min-width:1300px;">
|
<table class="table table-bordered table-sm bg-white mt-2" style="min-width:1300px;">
|
||||||
<thead> …(省略:空表のヘッダは従来どおり)… </thead>
|
<thead> …(省略:空表のヘッダは従来どおり)… </thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td colspan="21" class="text-center">データがありません。</td></tr>
|
<tr>
|
||||||
|
<td colspan="21" class="text-center">データがありません。</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@ -123,7 +158,20 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.price-input:read-only{ background:#fff700!important; color:#222!important; border:1px solid #ccc; }
|
.price-input:read-only {
|
||||||
th{ white-space:nowrap!important; word-break:keep-all!important; font-size:13px; text-align:center; vertical-align:middle; min-width:50px; }
|
background: #fff700 !important;
|
||||||
|
color: #222 !important;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
white-space: nowrap !important;
|
||||||
|
word-break: keep-all !important;
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
min-width: 50px;
|
||||||
|
background: #efefef !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@endsection
|
@endsection
|
||||||
Loading…
Reference in New Issue
Block a user