133 lines
5.7 KiB
PHP
133 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Models;
|
|
use Session;
|
|
|
|
class OfficeLocationsController extends Controller
|
|
{
|
|
public function index(){
|
|
// $offices_arr = new Models\OfficeLocation;
|
|
$offices_arr = Models\OfficeLocation::with( 'created_by_info', 'country_manager_info')->orderBy('country', 'ASC')->paginate(15);
|
|
$data = [
|
|
'page_title' => 'Office Locations',
|
|
'offices_arr' => $offices_arr,
|
|
'current_user' => session('current_user')
|
|
];
|
|
// dd($offices_arr->isEmpty());
|
|
return view('officelocations.index', $data);
|
|
}
|
|
public function getSenderIdsJson(Request $request)
|
|
{
|
|
#$this->log_query();
|
|
$senderid_arr = \DB::table('sender_ids')
|
|
->join('staff_members AS staffcreate', 'staffcreate.id', '=', 'sender_ids.created_by')
|
|
->join('staff_members AS staffmodify', 'staffmodify.id', '=', 'sender_ids.last_modified_by')
|
|
->join('network_operators', 'network_operators.id', '=', 'sender_ids.network_id')
|
|
->join('clients', 'clients.id', '=', 'sender_ids.client_id')
|
|
->select('sender_ids.id', 'clients.name AS clientName', 'network_operators.name AS networkName', 'network_operators.country', 'sender_ids.senderid', 'sender_ids.status', 'sender_ids.network_id', 'network_operators.country','sender_ids.remarks', 'staffcreate.name As createdBy', 'staffmodify.name AS modifiedBy')
|
|
->orderBy('sender_ids.senderid', 'ASC')
|
|
->paginate(15);
|
|
|
|
if($request->has('keyword')){
|
|
$keyword = $request->keyword;
|
|
$senderid_arr = \DB::table('sender_ids')
|
|
->join('staff_members AS staffcreate', 'staffcreate.id', '=', 'sender_ids.created_by')
|
|
->join('staff_members AS staffmodify', 'staffmodify.id', '=', 'sender_ids.last_modified_by')
|
|
->join('network_operators', 'network_operators.id', '=', 'sender_ids.network_id')
|
|
->join('clients', 'clients.id', '=', 'sender_ids.client_id')
|
|
->select('sender_ids.id', 'clients.name AS clientName', 'network_operators.name AS networkName', 'network_operators.country', 'sender_ids.senderid', 'sender_ids.status', 'sender_ids.network_id', 'network_operators.country','sender_ids.remarks', 'staffcreate.name As createdBy', 'staffmodify.name AS modifiedBy')
|
|
->whereRaw("sender_ids.senderid LIKE '%$keyword%' OR sender_ids.status LIKE '%$keyword%' OR network_operators.name LIKE '%$keyword%' OR network_operators.country LIKE '%$keyword%' OR staffcreate.name LIKE '%$keyword%' OR staffmodify.name LIKE '%$keyword%' OR clients.name LIKE '%$keyword%'")
|
|
->orderBy('sender_ids.senderid', 'ASC')
|
|
->paginate(15);
|
|
}
|
|
return response()->json($senderid_arr);
|
|
}
|
|
public function create()
|
|
{
|
|
|
|
$countries = Models\Country::pluck('en_short_name','en_short_name');
|
|
$staffmembers = Models\StaffMember::pluck('name', 'id');
|
|
$data = [
|
|
'page_title' => 'Add Office Location',
|
|
'countries' => $countries,
|
|
'staffmembers' => $staffmembers
|
|
];
|
|
|
|
return view('officelocations.create', $data);
|
|
}
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'street_name' => 'required',
|
|
'house_number' => 'required',
|
|
'block_number' => 'sometimes',
|
|
'country' => 'required|unique:office_locations,country',
|
|
'country_manager_id' => 'required|unique:office_locations,country_manager_id',
|
|
'office_phone' => 'required'
|
|
]);
|
|
$flag = Models\CountryFlag::where('country', $request->country)->first();
|
|
if ($flag) {
|
|
$flag_url = $flag->url;
|
|
}
|
|
else{
|
|
$flag_url = "https://via.placeholder.com/100x60";
|
|
}
|
|
$office_arr = $request->except('_token');
|
|
$office_arr['user_id'] = session('current_user.id');
|
|
|
|
$office_arr['flag_url'] = $flag_url;
|
|
$result = Models\OfficeLocation::create($office_arr);
|
|
Session::flash('success_message', 'Office Location successfully added');
|
|
return redirect(url('officelocations'));
|
|
}
|
|
public function edit($id){
|
|
$office = Models\OfficeLocation::findOrFail($id);
|
|
|
|
$countries = Models\Country::pluck('en_short_name','en_short_name');
|
|
$staffmembers = Models\StaffMember::pluck('name', 'id');
|
|
|
|
$data = [
|
|
'page_title' => 'Edit Office Location',
|
|
'countries' => $countries,
|
|
'staffmembers' => $staffmembers
|
|
];
|
|
return view('officelocations.edit', $data);
|
|
}
|
|
public function update(Request $request, $id)
|
|
{
|
|
|
|
$request->validate([
|
|
'street_name' => 'required',
|
|
'house_number' => 'required',
|
|
'block_number' => 'sometimes',
|
|
'country' => 'sometimes',
|
|
'country_manager_id' => 'required',
|
|
'office_phone' => 'required'
|
|
]);
|
|
|
|
$office = Models\OfficeLocation::findOrFail($id);
|
|
|
|
$office->street_name = $request->street_name;
|
|
$office->house_number = $request->house_number;
|
|
$office->block_number = $request->block_number;
|
|
$office->country = $request->country;
|
|
$office->country_manager_id = $request->country_manager_id;
|
|
$office->office_phone = $request->office_phone;
|
|
|
|
$office->save();
|
|
|
|
Session::flash('success_message', 'Office Location details successfully Updated');
|
|
return redirect(url('officelocations'));
|
|
}
|
|
}
|