added sender ID export, edit payment bug fix, profile page bug fix

This commit is contained in:
Kwesi Banson
2026-10-29 12:23:00 +00:00
parent 8428d94abd
commit 965892ac62
15 changed files with 792 additions and 139 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Exports;
use App\Models\SenderId;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
class SenderIdsExport implements FromQuery, WithHeadings, WithMapping
{
use Exportable;
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function query()
{
$query = SenderId::query();
// Apply the same filters used on the index page
if ($this->request->filled('search')) {
$search = $this->request->input('search');
$query->where('senderid', 'like', "%{$search}%")
->orWhere('mno_name', 'like', "%{$search}%")
->orWhere('supplier_name', 'like', "%{$search}%");
}
if ($this->request->filled('direct_mno')) {
$query->where('direct_mno', $this->request->input('direct_mno'));
}
if ($this->request->filled('status')) {
$query->where('status', $this->request->input('status'));
}
return $query->orderBy('created_at', 'desc');
}
public function headings(): array
{
return [
'Sender ID', 'Direct MNO', 'MNO Name', 'Supplier Name',
'Type', 'Bind Name', 'Status', 'Remarks', 'Created At'
];
}
public function map($sender): array
{
return [
$sender->senderid,
$sender->direct_mno,
$sender->mno_name ?? 'N/A',
$sender->supplier_name ?? 'N/A',
$sender->type,
$sender->bind_name,
strtoupper($sender->status),
$sender->remarks,
$sender->created_at ? $sender->created_at->format('Y-m-d H:i') : '',
];
}
}

View File

@@ -110,7 +110,7 @@ class ClientsController extends Controller
$voice_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'voice')->get() ?? collect();
$sms_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'sms')->get() ?? collect();
$ussd_codes = Models\ClientShortCode::where('client_id', $id)->where('code_type', 'ussd')->get() ?? collect();
$recent_payments = Models\ClientPayment::where('client_id', $id)->latest('id')->get() ?? collect();
$recent_payments = Models\ClientPayment::where('client_id', $id)->latest('updated_at')->get() ?? collect();
$showdocuments = Models\ClientFile::where('client_id', $id)->get() ?? collect();
// Also ensure client attributes are safe arrays
@@ -667,7 +667,7 @@ class ClientsController extends Controller
'invoice_date' => 'required',
'invoice_status' => 'required'
]);
dd($request->all());
$auth_user = Auth::user();
$payment = Models\ClientPayment::findOrFail($request->payment_id);
@@ -883,7 +883,7 @@ class ClientsController extends Controller
}
public function update_payment(Request $request, $id)
{
// Validate the inputs based on the fields in your edit modal
$validated = $request->validate([
'invoice_number' => 'required|string',
'invoice_amount' => 'required|numeric',

View File

@@ -12,7 +12,6 @@ class ProfileController extends Controller
public function index()
{
$staff = StaffMember::with('dependents')->where('email', auth()->user()->email)->firstOrFail();
return view('profile.index', compact('staff'));
}

View File

@@ -4,11 +4,15 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models;
use App\Exports\SenderIdsExport;
use Barryvdh\DomPDF\Facade\Pdf;
use Maatwebsite\Excel\Facades\Excel;
class SenderidsController extends Controller
{
public function index(Request $request)
{
// Fetch KPI Metrics (Keep your existing counts)
@@ -68,6 +72,34 @@ class SenderidsController extends Controller
return view('senderids.index', $data);
}
public function exportExcel(Request $request)
{
return Excel::download(new SenderIdsExport($request), 'Sender_IDs_Export_' . date('Ymd_Hi') . '.xlsx');
}
public function exportPdf(Request $request)
{
$query = \App\Models\SenderId::query();
if ($request->filled('search')) {
$search = $request->input('search');
$query->where('senderid', 'like', "%{$search}%")
->orWhere('mno_name', 'like', "%{$search}%")
->orWhere('supplier_name', 'like', "%{$search}%");
}
if ($request->filled('direct_mno')) {
$query->where('direct_mno', $request->input('direct_mno'));
}
if ($request->filled('status')) {
$query->where('status', $request->input('status'));
}
$senderIds = $query->orderBy('created_at', 'desc')->get();
$pdf = Pdf::loadView('senderids.pdf', compact('senderIds'))->setPaper('a4', 'landscape');
return $pdf->download('Sender_IDs_Export_' . date('Ymd_Hi') . '.pdf');
}
public function store(Request $request)
{
$validated = $request->validate([

View File

@@ -1,11 +0,0 @@
<?php
namespace App\models;
use Illuminate\Database\Eloquent\Model;
class IncomingEmail extends Model
{
protected $guarded = array('id');
public $table = "incoming_emails";
}

View File

@@ -1,109 +0,0 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;
class VpnClient extends Model
{
protected $table = 'vpn_clients';
protected $fillable = [
'name',
'username',
'type',
'server_id',
'auth_type',
'password',
'allowed_ips',
'routes',
'push_dns',
'compress',
'notes',
'active',
'config_path', // optional stored config file path
];
protected $casts = [
'push_dns' => 'boolean',
'compress' => 'boolean',
'active' => 'boolean',
];
// Relationships
public function server()
{
return $this->belongsTo(Server::class);
}
// Scopes
public function scopeActive($q)
{
return $q->where('active', 1);
}
public function scopeOfType($q, $type)
{
return $q->where('type', $type);
}
// Generate a basic OpenVPN config (example). Adapt to your templates and security needs.
public function generateConfig()
{
// If a pre-generated config is stored, return it
if ($this->config_path && Storage::exists($this->config_path)) {
return Storage::get($this->config_path);
}
// Example template — replace with your real generation logic
$server = $this->server ? $this->server->address : 'vpn.example.com';
$proto = 'udp';
$port = 1194;
$conf = [];
$conf[] = "client";
$conf[] = "dev tun";
$conf[] = "proto {$proto}";
$conf[] = "remote {$server} {$port}";
$conf[] = "resolv-retry infinite";
$conf[] = "nobind";
if ($this->compress) {
$conf[] = "comp-lzo";
}
if ($this->push_dns) {
$conf[] = "dhcp-option DNS 10.8.0.1";
}
if ($this->allowed_ips) {
// allowed_ips are usually server-side; include as comment for operator
$conf[] = "# Allowed IPs: " . $this->allowed_ips;
}
// insert certs/keys placeholders — do NOT store private keys in cleartext unless secure
if ($this->auth_type === 'cert') {
$conf[] = "<ca>\n# CA cert here\n</ca>";
$conf[] = "<cert>\n# Client cert here\n</cert>";
$conf[] = "<key>\n# Client key hidden\n</key>";
} else {
// username/password auth
$conf[] = "auth-user-pass";
}
return implode("\n", $conf) . "\n";
}
/**
* Store generated config to disk (optional).
* Returns storage path.
*/
public function storeGeneratedConfig()
{
$config = $this->generateConfig();
$filename = 'vpn/configs/' . Str::slug($this->name) . '-' . $this->id . '.ovpn';
Storage::put($filename, $config);
$this->config_path = $filename;
$this->save();
return $filename;
}
}