|
|
|
@ -33,7 +33,7 @@ class VoucherController extends Controller
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
return inertia('Voucher/Form', [
|
|
|
|
|
'levels' => CustomerLevel::all()
|
|
|
|
|
'levels' => CustomerLevel::all(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -55,7 +55,7 @@ class VoucherController extends Controller
|
|
|
|
|
'expired_unit' => 'required|string',
|
|
|
|
|
'prices' => 'nullable|array',
|
|
|
|
|
'prices.*.customer_level_id' => 'required|exists:customer_levels,id',
|
|
|
|
|
'prices.*.display_price' => 'required|numeric'
|
|
|
|
|
'prices.*.display_price' => 'required|numeric',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
@ -96,7 +96,7 @@ class VoucherController extends Controller
|
|
|
|
|
{
|
|
|
|
|
return inertia('Voucher/Form', [
|
|
|
|
|
'voucher' => $voucher->load(['prices.level']),
|
|
|
|
|
'levels' => CustomerLevel::all()
|
|
|
|
|
'levels' => CustomerLevel::all(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -118,11 +118,13 @@ class VoucherController extends Controller
|
|
|
|
|
'expired_unit' => 'required|string',
|
|
|
|
|
'prices' => 'nullable|array',
|
|
|
|
|
'prices.*.customer_level_id' => 'required|exists:customer_levels,id',
|
|
|
|
|
'prices.*.display_price' => 'required|numeric'
|
|
|
|
|
'prices.*.display_price' => 'required|numeric',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
$voucher->update([
|
|
|
|
|
|
|
|
|
|
$vouchers = Voucher::where('batch_id', $voucher->batch_id);
|
|
|
|
|
$vouchers->update([
|
|
|
|
|
'name' => $request->name,
|
|
|
|
|
'description' => $request->description,
|
|
|
|
|
'location_id' => $request->location_id,
|
|
|
|
@ -137,6 +139,7 @@ class VoucherController extends Controller
|
|
|
|
|
'expired' => $request->expired,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
foreach ($vouchers->get() as $voucher) {
|
|
|
|
|
$voucher->prices()->delete();
|
|
|
|
|
foreach (collect($request->prices) as $price) {
|
|
|
|
|
$finalPrice = $price['display_price'];
|
|
|
|
@ -149,6 +152,7 @@ class VoucherController extends Controller
|
|
|
|
|
'display_price' => $price['display_price'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('voucher.index')
|
|
|
|
@ -166,7 +170,7 @@ class VoucherController extends Controller
|
|
|
|
|
public function form_import()
|
|
|
|
|
{
|
|
|
|
|
return inertia('Voucher/Import', [
|
|
|
|
|
'levels' => CustomerLevel::all()
|
|
|
|
|
'levels' => CustomerLevel::all(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -182,7 +186,7 @@ class VoucherController extends Controller
|
|
|
|
|
'expired_unit' => 'required|string',
|
|
|
|
|
'prices' => 'nullable|array',
|
|
|
|
|
'prices.*.customer_level_id' => 'required|exists:customer_levels,id',
|
|
|
|
|
'prices.*.display_price' => 'required|numeric'
|
|
|
|
|
'prices.*.display_price' => 'required|numeric',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$batchId = Str::ulid();
|
|
|
|
|