2024-06-07 12:44:51 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\ManageState;
|
2024-06-28 19:48:56 +05:30
|
|
|
use App\Models\TimeInterval;
|
2024-06-07 12:44:51 +05:30
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Exception;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class ManageLocationController extends Controller
|
|
|
|
|
{
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
/*
|
|
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To get the page.
|
|
|
|
|
*/
|
2024-07-02 15:24:49 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
public function index()
|
|
|
|
|
{
|
2024-06-28 19:48:56 +05:30
|
|
|
$location = ManageState::with('timeInterval')->orderBy('id', 'asc')->get();
|
2024-07-02 15:24:49 +05:30
|
|
|
// return $location;
|
2024-06-07 12:44:51 +05:30
|
|
|
return view('Admin.pages.manage_states.manage_states', compact('location'));
|
|
|
|
|
}
|
2024-06-17 13:41:03 +05:30
|
|
|
/*
|
2024-06-07 12:44:51 +05:30
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To store the location.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
public function store(Request $request)
|
2024-06-17 13:41:03 +05:30
|
|
|
{
|
2024-06-28 19:48:56 +05:30
|
|
|
// dd($request);
|
2024-06-17 13:41:03 +05:30
|
|
|
$request->validate([
|
2024-06-28 19:48:56 +05:30
|
|
|
'location_name' => 'required|string|max:255',
|
|
|
|
|
'timeHours' => 'required|numeric|min:1',
|
|
|
|
|
'timeInterval' => 'required|in:day,week,month'
|
2024-06-17 13:41:03 +05:30
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (ManageState::where('name', $request->location_name)->exists()) {
|
|
|
|
|
return response()->json(['success' => false, 'error' => 'Location name already exists', 'status' => 422]);
|
|
|
|
|
}
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-28 19:48:56 +05:30
|
|
|
// new location
|
2024-06-17 13:41:03 +05:30
|
|
|
$location = new ManageState();
|
|
|
|
|
$location->name = $request->location_name;
|
|
|
|
|
$location->save();
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-28 19:48:56 +05:30
|
|
|
// time interval
|
|
|
|
|
$timeInterval = new TimeInterval();
|
|
|
|
|
$timeInterval->manage_state_xid = $location->id;
|
|
|
|
|
$timeInterval->time_hours = $request->timeHours;
|
|
|
|
|
$timeInterval->time_interval = $request->timeInterval;
|
|
|
|
|
$timeInterval->quantity = $request->timeQuantity;
|
|
|
|
|
$timeInterval->save();
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return response()->json(['success' => false, 'error' => $e->getMessage(), 'status' => 500]);
|
|
|
|
|
}
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
|
2024-06-28 19:48:56 +05:30
|
|
|
|
|
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
/*
|
|
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To change status.
|
|
|
|
|
*/
|
2024-06-17 13:41:03 +05:30
|
|
|
public function change_location_status(Request $request)
|
2024-06-07 12:44:51 +05:30
|
|
|
{
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
$status = ManageState::find($request->location_id);
|
|
|
|
|
$status->is_active = $request->status;
|
|
|
|
|
$status->save();
|
|
|
|
|
// return response()->json(['status' => 200]);
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
|
|
return jsonResponseWithSuccessMessage(__('success.update_data'));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Update Status function Load Failed " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
2024-06-17 13:41:03 +05:30
|
|
|
}
|
2024-06-07 12:44:51 +05:30
|
|
|
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
/*
|
2024-06-07 12:44:51 +05:30
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To delete location.
|
|
|
|
|
*/
|
|
|
|
|
public function delete_location($id)
|
|
|
|
|
{
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
|
|
$passport = ManageState::find($id);
|
|
|
|
|
$passport->delete();
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
Log::error("delete_location function Load Failed " . $e->getMessage());
|
|
|
|
|
return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
/*
|
2024-06-07 12:44:51 +05:30
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To update location.
|
2024-06-17 13:41:03 +05:30
|
|
|
*/
|
2024-06-28 19:48:56 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-02 15:24:49 +05:30
|
|
|
public function update_location(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
2024-06-28 19:48:56 +05:30
|
|
|
|
2024-07-02 15:24:49 +05:30
|
|
|
// Find the location data
|
|
|
|
|
$location_data = ManageState::find($request->id);
|
|
|
|
|
if (!$location_data) {
|
|
|
|
|
return response()->json(['success' => false, 'error' => 'Location not found', 'status' => 404]);
|
|
|
|
|
}
|
2024-06-28 19:48:56 +05:30
|
|
|
|
2024-07-02 15:24:49 +05:30
|
|
|
// Update the location data
|
|
|
|
|
$location_data->name = $request->location_name;
|
|
|
|
|
$location_data->save();
|
|
|
|
|
|
|
|
|
|
// Update or create the TimeInterval data
|
|
|
|
|
$timeInterval = TimeInterval::where('manage_state_xid', $request->input('id'))->first();
|
|
|
|
|
|
|
|
|
|
if ($timeInterval) {
|
|
|
|
|
// Update existing record
|
|
|
|
|
$timeInterval->update([
|
|
|
|
|
'manage_state_xid' => $request->input('id'),
|
|
|
|
|
|
|
|
|
|
'time_hours' => $request->input('time_hours'),
|
|
|
|
|
'time_interval' => $request->input('time_interval'),
|
|
|
|
|
'quantity' => $request->input('quantity'),
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
// Create new record
|
|
|
|
|
TimeInterval::create([
|
|
|
|
|
'manage_state_xid' => $request->input('id'),
|
|
|
|
|
'time_hours' => $request->input('time_hours'),
|
|
|
|
|
'time_interval' => $request->input('time_interval'),
|
|
|
|
|
'quantity' => $request->input('quantity'),
|
|
|
|
|
]);
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|
2024-07-02 15:24:49 +05:30
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'message' => __('success.update_data'), 'status' => 200]);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
Log::error("Failed to update location: " . $e->getMessage());
|
|
|
|
|
return response()->json(['success' => false, 'error' => __('auth.something_went_wrong'), 'status' => 500]);
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|
2024-07-02 15:24:49 +05:30
|
|
|
}
|
|
|
|
|
|
2024-06-28 19:48:56 +05:30
|
|
|
|
2024-07-02 15:24:49 +05:30
|
|
|
|
2024-06-26 19:12:45 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|