started work on OTP and disabled registration
This commit is contained in:
118
app/Http/Controllers/OfficeLocationController.php
Normal file
118
app/Http/Controllers/OfficeLocationController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\OfficeLocation;
|
||||
use App\Models\StaffMember;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OfficeLocationController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$locations = OfficeLocation::with('manager', 'documents')
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(9);
|
||||
|
||||
$staffMembers = StaffMember::where('status', 'ACTIVE')->orderBy('name')->get();
|
||||
|
||||
$countries = DB::table('countries')->orderBy('en_short_name', 'asc')->get();
|
||||
|
||||
return view('offices.index', compact('locations', 'staffMembers', 'countries'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'country' => 'required|string|max:191',
|
||||
'city' => 'required|string|max:191',
|
||||
'physical_address' => 'nullable|string',
|
||||
'postal_address' => 'nullable|string|max:191',
|
||||
'zip_code' => 'nullable|string|max:15',
|
||||
'office_phone' => 'nullable|string|max:20',
|
||||
'country_manager_id' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
OfficeLocation::create($validated);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Office location added successfully!']);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$location = OfficeLocation::findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'country' => 'required|string|max:191',
|
||||
'city' => 'required|string|max:191',
|
||||
'physical_address' => 'nullable|string',
|
||||
'postal_address' => 'nullable|string|max:191',
|
||||
'zip_code' => 'nullable|string|max:15',
|
||||
'office_phone' => 'nullable|string|max:20',
|
||||
'country_manager_id' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$location->update($validated);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Office location updated successfully!']);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
OfficeLocation::findOrFail($id)->delete();
|
||||
return response()->json(['success' => true, 'message' => 'Office location removed.']);
|
||||
}
|
||||
|
||||
// --- ADD THESE METHODS TO OfficeLocationController.php ---
|
||||
|
||||
public function showDocuments($id)
|
||||
{
|
||||
$location = OfficeLocation::with('documents')->findOrFail($id);
|
||||
return view('offices.documents', compact('location'));
|
||||
}
|
||||
|
||||
public function storeDocument(Request $request, $id)
|
||||
{
|
||||
$location = OfficeLocation::findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:191',
|
||||
'file' => 'required|file|mimes:pdf,jpg,jpeg,png,doc,docx|max:10240',
|
||||
'validity_period' => 'required|string',
|
||||
// Require a date UNLESS the period is 'On Demand'
|
||||
'next_renewal_date' => 'nullable|required_unless:validity_period,On Demand|date'
|
||||
]);
|
||||
|
||||
$file = $request->file('file');
|
||||
$filename = time() . '_' . preg_replace('/\s+/', '_', $file->getClientOriginalName());
|
||||
$filePath = $file->storeAs("office_documents/{$location->id}", $filename, 'public');
|
||||
|
||||
// Get current staff ID
|
||||
$staff = \App\Models\StaffMember::where('email', auth()->user()->email)->first();
|
||||
|
||||
\App\Models\OfficeLocationDocument::create([
|
||||
'office_location_id' => $location->id,
|
||||
'name' => $request->name,
|
||||
'file_path' => $filePath,
|
||||
'file_extension' => $file->getClientOriginalExtension(),
|
||||
'validity_period' => $request->validity_period,
|
||||
'next_renewal_date' => $request->validity_period === 'On Demand' ? null : $request->next_renewal_date,
|
||||
'uploaded_by' => $staff ? $staff->id : null,
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Document archived successfully!']);
|
||||
}
|
||||
|
||||
public function destroyDocument($docId)
|
||||
{
|
||||
$document = \App\Models\OfficeLocationDocument::findOrFail($docId);
|
||||
|
||||
if ($document->file_path && \Illuminate\Support\Facades\Storage::disk('public')->exists($document->file_path)) {
|
||||
\Illuminate\Support\Facades\Storage::disk('public')->delete($document->file_path);
|
||||
}
|
||||
|
||||
$document->delete();
|
||||
return response()->json(['success' => true, 'message' => 'Document deleted.']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user