worked on short code and sender ID modules
This commit is contained in:
@@ -3,14 +3,141 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models;
|
||||
class SenderidsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
|
||||
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Fetch KPI Metrics (Keep your existing counts)
|
||||
// $totalCount = \App\Models\SenderId::count();
|
||||
// $approvedCount = \App\Models\SenderId::where('status', 'APPROVED')->count();
|
||||
// $pendingCount = \App\Models\SenderId::where('status', 'PENDING')->count();
|
||||
// $rejectedCount = \App\Models\SenderId::where('status', 'REJECTED')->count();
|
||||
|
||||
$totalCount = \App\Models\SenderId::count();
|
||||
$approvedCount = \App\Models\SenderId::where('status', 'LIKE', 'Approved%')->count();
|
||||
$pendingCount = \App\Models\SenderId::where('status', 'LIKE', 'Applied%')->count();
|
||||
$rejectedCount = \App\Models\SenderId::where('status', 'Rejected')->count();
|
||||
// Fetch dynamic lists for the modal dropdowns
|
||||
$clients = Models\Client::orderBy('name', 'asc')->get();
|
||||
$networkOperators = Models\NetworkOperator::orderBy('name', 'asc')->get();
|
||||
|
||||
// Start the query
|
||||
$query = \App\Models\SenderId::query();
|
||||
|
||||
// 1. Search Filter (Sender ID, MNO, or Supplier)
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function($q) use ($search) {
|
||||
$q->where('senderid', 'like', "%{$search}%")
|
||||
->orWhere('mno_name', 'like', "%{$search}%")
|
||||
->orWhere('supplier_name', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Direct MNO Filter
|
||||
if ($request->filled('direct_mno')) {
|
||||
$query->where('direct_mno', $request->direct_mno);
|
||||
}
|
||||
|
||||
// 3. Status Filter
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', 'LIKE', '%' . $request->status . '%');
|
||||
}
|
||||
|
||||
// Execute query with pagination
|
||||
$senderIds = $query->orderBy('created_at', 'desc')->paginate(10);
|
||||
|
||||
// Crucial: Append the current request query strings to pagination links
|
||||
$senderIds->appends($request->query());
|
||||
|
||||
$data = [
|
||||
'page_title' => 'Dashboard'
|
||||
'page_title' => 'Sender IDs',
|
||||
'totalCount' => $totalCount,
|
||||
'approvedCount' => $approvedCount,
|
||||
'pendingCount' => $pendingCount,
|
||||
'rejectedCount' => $rejectedCount,
|
||||
'senderIds' => $senderIds,
|
||||
'clients' => $clients, // <-- Pass Clients
|
||||
'networkOperators' => $networkOperators, // <-- Pass MNOs
|
||||
];
|
||||
|
||||
return view('senderids.index', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'senderid' => 'required|string|max:20',
|
||||
'direct_mno' => 'required|in:YES,NO',
|
||||
|
||||
// Conditional Validation Rules
|
||||
'mno_name' => 'required_if:direct_mno,YES|nullable|string|max:192',
|
||||
'supplier_name' => 'required_if:direct_mno,NO|nullable|string|max:192',
|
||||
|
||||
'bind_name' => 'nullable|string|max:50',
|
||||
'type' => 'nullable|string|max:25',
|
||||
'status' => 'nullable|string|max:154',
|
||||
'remarks' => 'nullable|string|max:250',
|
||||
], [
|
||||
'mno_name.required_if' => 'The MNO Name is required when routing directly to an MNO.',
|
||||
'supplier_name.required_if' => 'The Supplier Name is required when not routing directly to an MNO.',
|
||||
]);
|
||||
|
||||
// Attach creator ID and save
|
||||
$validated['created_by'] = auth()->id();
|
||||
|
||||
// Create the Sender ID
|
||||
$senderId = \App\Models\SenderId::create($validated);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Sender ID added successfully!']);
|
||||
}
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$senderId = Models\SenderId::findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'senderid' => 'required|string|max:20',
|
||||
'direct_mno' => 'required|in:YES,NO',
|
||||
|
||||
// Conditional validation rules for update as well
|
||||
'mno_name' => 'required_if:direct_mno,YES|nullable|string|max:192',
|
||||
'supplier_name' => 'required_if:direct_mno,NO|nullable|string|max:192',
|
||||
|
||||
'bind_name' => 'nullable|string|max:50',
|
||||
'type' => 'nullable|string|max:25',
|
||||
'status' => 'nullable|string|max:154',
|
||||
'remarks' => 'nullable|string|max:250',
|
||||
], [
|
||||
'mno_name.required_if' => 'The MNO Name is required when routing directly to an MNO.',
|
||||
'supplier_name.required_if' => 'The Supplier Name is required when not routing directly to an MNO.',
|
||||
]);
|
||||
|
||||
// Clear out the opposite field depending on the Direct MNO choice to keep data clean
|
||||
if ($validated['direct_mno'] === 'YES') {
|
||||
$validated['supplier_name'] = null;
|
||||
} else {
|
||||
$validated['mno_name'] = null;
|
||||
}
|
||||
|
||||
$validated['last_modified_by'] = auth()->id();
|
||||
|
||||
$senderId->update($validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Sender ID updated successfully!'
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$senderId = SenderId::findOrFail($id);
|
||||
$senderId->delete();
|
||||
|
||||
return redirect()->route('sender-ids.index')->with('success', 'Sender ID deleted successfully.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,119 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ShortCode;
|
||||
use App\Models\Client;
|
||||
use App\Models\NetworkOperator;
|
||||
use App\Models\Country;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ShortCodesController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
// KPI Metrics
|
||||
$totalCount = ShortCode::count();
|
||||
$smsCount = ShortCode::where('code_type', 'sms')->count();
|
||||
$ussdCount = ShortCode::where('code_type', 'ussd')->count();
|
||||
$voiceCount = ShortCode::where('code_type', 'voice')->count();
|
||||
$countries = Country::orderBy('en_short_name', 'asc')->get();
|
||||
// dd($countries);
|
||||
|
||||
// Dropdown options
|
||||
$clients = Client::orderBy('name', 'asc')->get();
|
||||
$networkOperators = NetworkOperator::orderBy('name', 'asc')->get();
|
||||
|
||||
$query = ShortCode::query();
|
||||
|
||||
// Search Filter
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function($q) use ($search) {
|
||||
$q->where('shortcode', 'like', "%{$search}%")
|
||||
->orWhere('name', 'like', "%{$search}%")
|
||||
->orWhere('toll_free', 'like', "%{$search}%")
|
||||
->orWhere('country', 'like', "%{$search}%")
|
||||
->orWhere('network', 'like', "%{$search}%")
|
||||
->orWhere('code_type', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// Status Filter
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->status);
|
||||
}
|
||||
|
||||
// Execute query with pagination (Fixed variable name from $senderIds to $shortcodes)
|
||||
$shortcodes = $query->orderBy('created_at', 'desc')->paginate(10);
|
||||
$shortcodes->appends($request->query());
|
||||
|
||||
$data = [
|
||||
'page_title' => 'Dashboard'
|
||||
'page_title' => 'Short Codes Management',
|
||||
'totalCount' => $totalCount,
|
||||
'smsCount' => $smsCount,
|
||||
'ussdCount' => $ussdCount,
|
||||
'voiceCount' => $voiceCount,
|
||||
'shortcodes' => $shortcodes,
|
||||
'clients' => $clients,
|
||||
'countries' => $countries,
|
||||
'networkOperators' => $networkOperators,
|
||||
];
|
||||
|
||||
return view('shortcodes.index', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'client_id' => 'nullable|integer',
|
||||
'name' => 'nullable|string|max:192',
|
||||
'shortcode' => 'required|string|max:20',
|
||||
'code_type' => 'nullable|string|max:15',
|
||||
'toll_free' => 'nullable|string|max:10',
|
||||
'monthly_fee' => 'nullable|numeric',
|
||||
'country' => 'nullable|string|max:45',
|
||||
'network' => 'nullable|string|max:45',
|
||||
'status' => 'nullable|string|max:15',
|
||||
'launch_date' => 'nullable|date',
|
||||
'expiry_date' => 'nullable|date',
|
||||
'remarks' => 'nullable|string|max:250',
|
||||
]);
|
||||
|
||||
ShortCode::create($validated);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Short code created successfully!']);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$shortcode = ShortCode::findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'client_id' => 'nullable|integer',
|
||||
'name' => 'nullable|string|max:192',
|
||||
'shortcode' => 'required|string|max:20',
|
||||
'code_type' => 'nullable|string|max:15',
|
||||
'toll_free' => 'nullable|string|max:10',
|
||||
'monthly_fee' => 'nullable|numeric',
|
||||
'country' => 'nullable|string|max:45',
|
||||
'network' => 'nullable|string|max:45',
|
||||
'status' => 'nullable|string|max:15',
|
||||
'launch_date' => 'nullable|date',
|
||||
'expiry_date' => 'nullable|date',
|
||||
'remarks' => 'nullable|string|max:250',
|
||||
]);
|
||||
|
||||
$validated['last_updated_by'] = auth()->id();
|
||||
$shortcode->update($validated);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Short code updated successfully!']);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$shortcode = ShortCode::findOrFail($id);
|
||||
$shortcode->delete();
|
||||
|
||||
return redirect()->route('shortcodes.index')->with('success', 'Short code deleted successfully.');
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Country extends Model
|
||||
{
|
||||
protected $guarded = array('id');
|
||||
public $table = "countries";
|
||||
public $table = "countries_new";
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class ShortCode extends Model
|
||||
{
|
||||
protected $guarded = array('id');
|
||||
public $table = "short_codes";
|
||||
public $table = "client_short_codes";
|
||||
|
||||
public function client_info(){
|
||||
return $this->hasOne('App\Models\Client', 'id', 'client_id');
|
||||
}
|
||||
public function update_info(){
|
||||
return $this->hasOne('App\Models\SystemUser', 'id', 'last_updated_by');
|
||||
return $this->hasOne('App\Models\StaffMember', 'id', 'last_updated_by');
|
||||
}
|
||||
public function account_mgr_info(){
|
||||
return $this->hasOne('App\Models\SystemUser', 'id', 'account_manager_id');
|
||||
return $this->hasOne('App\Models\StaffMember', 'id', 'account_manager_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user