feat: add service type selection and display in message bulk management
This commit is contained in:
parent
4e3d89a23c
commit
ec9a06f468
@ -134,30 +134,55 @@ EOT;
|
||||
$page = $_REQUEST['page'] ?? 0;
|
||||
$router = $_REQUEST['router'] ?? null;
|
||||
$test = isset($_REQUEST['test']) && $_REQUEST['test'] === 'on' ? true : false;
|
||||
$service = $_REQUEST['service'] ?? '';
|
||||
|
||||
if (empty($group) || empty($message) || empty($via)) {
|
||||
if (empty($group) || empty($message) || empty($via) || empty($service)) {
|
||||
die(json_encode(['status' => 'error', 'message' => 'All fields are required']));
|
||||
}
|
||||
|
||||
// Get batch of customers based on group
|
||||
$startpoint = $page * $batch;
|
||||
$customers = [];
|
||||
$totalCustomers = 0;
|
||||
|
||||
if (isset($router) && !empty($router)) {
|
||||
$router = ORM::for_table('tbl_routers')->find_one($router);
|
||||
if (!$router) {
|
||||
die(json_encode(['status' => 'error', 'message' => 'Invalid router']));
|
||||
switch ($router) {
|
||||
case 'radius':
|
||||
$routerName = 'Radius';
|
||||
break;
|
||||
default:
|
||||
$router = ORM::for_table('tbl_routers')->find_one($router);
|
||||
if (!$router) {
|
||||
die(json_encode(['status' => 'error', 'message' => 'Invalid router']));
|
||||
}
|
||||
$routerName = $router->name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($router) && !empty($router)) {
|
||||
$query = ORM::for_table('tbl_user_recharges')
|
||||
->left_outer_join('tbl_customers', 'tbl_user_recharges.customer_id = tbl_customers.id')
|
||||
->where('tbl_user_recharges.routers', $router->name)
|
||||
->offset($startpoint)
|
||||
->where('tbl_user_recharges.routers', $routerName);
|
||||
|
||||
switch ($service) {
|
||||
case 'all':
|
||||
break;
|
||||
default:
|
||||
$validServices = ['PPPoE', 'Hotspot', 'VPN'];
|
||||
if (in_array($service, $validServices)) {
|
||||
$query->where('type', $service);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$totalCustomers = $query->count();
|
||||
|
||||
$query->offset($startpoint)
|
||||
->limit($batch);
|
||||
|
||||
switch ($group) {
|
||||
case 'all':
|
||||
// No additional conditions needed
|
||||
break;
|
||||
case 'new':
|
||||
$query->where_raw("DATE(recharged_on) >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)");
|
||||
@ -170,6 +195,7 @@ EOT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Fetch the customers
|
||||
$query->selects([
|
||||
['tbl_customers.phonenumber', 'phonenumber'],
|
||||
['tbl_user_recharges.customer_id', 'customer_id'],
|
||||
@ -179,20 +205,74 @@ EOT;
|
||||
} else {
|
||||
switch ($group) {
|
||||
case 'all':
|
||||
$customers = ORM::for_table('tbl_customers')->offset($startpoint)->limit($batch)->find_array();
|
||||
$totalCustomersQuery = ORM::for_table('tbl_customers');
|
||||
|
||||
switch ($service) {
|
||||
case 'all':
|
||||
break;
|
||||
default:
|
||||
$validServices = ['PPPoE', 'Hotspot', 'VPN'];
|
||||
if (in_array($service, $validServices)) {
|
||||
$totalCustomersQuery->where('service_type', $service);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$totalCustomers = $totalCustomersQuery->count();
|
||||
$customers = $totalCustomersQuery->offset($startpoint)->limit($batch)->find_array();
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$customers = ORM::for_table('tbl_customers')
|
||||
->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")
|
||||
->offset($startpoint)->limit($batch)->find_array();
|
||||
$totalCustomersQuery = ORM::for_table('tbl_customers')
|
||||
->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)");
|
||||
|
||||
switch ($service) {
|
||||
case 'all':
|
||||
break;
|
||||
default:
|
||||
$validServices = ['PPPoE', 'Hotspot', 'VPN'];
|
||||
if (in_array($service, $validServices)) {
|
||||
$totalCustomersQuery->where('service_type', $service);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$totalCustomers = $totalCustomersQuery->count();
|
||||
$customers = $totalCustomersQuery->offset($startpoint)->limit($batch)->find_array();
|
||||
break;
|
||||
|
||||
case 'expired':
|
||||
$customers = ORM::for_table('tbl_user_recharges')->where('status', 'off')
|
||||
->select('customer_id')->offset($startpoint)->limit($batch)->find_array();
|
||||
$totalCustomersQuery = ORM::for_table('tbl_user_recharges')
|
||||
->where('status', 'off');
|
||||
|
||||
switch ($service) {
|
||||
case 'all':
|
||||
break;
|
||||
default:
|
||||
$validServices = ['PPPoE', 'Hotspot', 'VPN'];
|
||||
if (in_array($service, $validServices)) {
|
||||
$totalCustomersQuery->where('type', $service);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$totalCustomers = $totalCustomersQuery->count();
|
||||
$customers = $totalCustomersQuery->select('customer_id')->offset($startpoint)->limit($batch)->find_array();
|
||||
break;
|
||||
|
||||
case 'active':
|
||||
$customers = ORM::for_table('tbl_user_recharges')->where('status', 'on')
|
||||
->select('customer_id')->offset($startpoint)->limit($batch)->find_array();
|
||||
$totalCustomersQuery = ORM::for_table('tbl_user_recharges')
|
||||
->where('status', 'on');
|
||||
|
||||
switch ($service) {
|
||||
case 'all':
|
||||
break;
|
||||
default:
|
||||
$validServices = ['PPPoE', 'Hotspot', 'VPN'];
|
||||
if (in_array($service, $validServices)) {
|
||||
$totalCustomersQuery->where('type', $service);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$totalCustomers = $totalCustomersQuery->count();
|
||||
$customers = $totalCustomersQuery->select('customer_id')->offset($startpoint)->limit($batch)->find_array(); // Get customer data
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -202,45 +282,6 @@ EOT;
|
||||
$customers = [];
|
||||
}
|
||||
|
||||
// Calculate total customers for the group
|
||||
$totalCustomers = 0;
|
||||
if ($router) {
|
||||
switch ($group) {
|
||||
case 'all':
|
||||
$totalCustomers = ORM::for_table('tbl_user_recharges')->where('routers', $router->routers)->count();
|
||||
break;
|
||||
case 'new':
|
||||
$totalCustomers = ORM::for_table('tbl_user_recharges')
|
||||
->where_raw("DATE(recharged_on) >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)")
|
||||
->where('routers', $router->routers)
|
||||
->count();
|
||||
break;
|
||||
case 'expired':
|
||||
$totalCustomers = ORM::for_table('tbl_user_recharges')->where('status', 'off')->where('routers', $router->routers)->count();
|
||||
break;
|
||||
case 'active':
|
||||
$totalCustomers = ORM::for_table('tbl_user_recharges')->where('status', 'on')->where('routers', $router->routers)->count();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch ($group) {
|
||||
case 'all':
|
||||
$totalCustomers = ORM::for_table('tbl_customers')->count();
|
||||
break;
|
||||
case 'new':
|
||||
$totalCustomers = ORM::for_table('tbl_customers')
|
||||
->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")
|
||||
->count();
|
||||
break;
|
||||
case 'expired':
|
||||
$totalCustomers = ORM::for_table('tbl_user_recharges')->where('status', 'off')->count();
|
||||
break;
|
||||
case 'active':
|
||||
$totalCustomers = ORM::for_table('tbl_user_recharges')->where('status', 'on')->count();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Send messages
|
||||
$totalSMSSent = 0;
|
||||
$totalSMSFailed = 0;
|
||||
@ -271,7 +312,9 @@ EOT;
|
||||
'name' => $customer['fullname'],
|
||||
'phone' => $customer['phonenumber'],
|
||||
'status' => 'Test Mode',
|
||||
'message' => $currentMessage
|
||||
'message' => $currentMessage,
|
||||
'service' => $service,
|
||||
'router' => $routerName,
|
||||
];
|
||||
} else {
|
||||
if ($via == 'sms' || $via == 'both') {
|
||||
@ -307,7 +350,9 @@ EOT;
|
||||
'message' => $currentMessage,
|
||||
'totalSent' => $totalSMSSent + $totalWhatsappSent,
|
||||
'totalFailed' => $totalSMSFailed + $totalWhatsappFailed,
|
||||
'hasMore' => $hasMore
|
||||
'hasMore' => $hasMore,
|
||||
'service' => $service,
|
||||
'router' => $routerName,
|
||||
]);
|
||||
break;
|
||||
|
||||
|
@ -15,12 +15,26 @@
|
||||
<div class="col-md-6">
|
||||
<select class="form-control select2" name="router" id="router">
|
||||
<option value="">{Lang::T('All Routers')}</option>
|
||||
{if $_c['radius_enable']}
|
||||
<option value="radius">{Lang::T('Radius')}</option>
|
||||
{/if}
|
||||
{foreach $routers as $router}
|
||||
<option value="{$router['id']}">{$router['name']}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">{Lang::T('Service Type')}</label>
|
||||
<div class="col-md-6">
|
||||
<select class="form-control" name="service" id="service">
|
||||
<option value="all" {if $group=='all' }selected{/if}>{Lang::T('All')}</option>
|
||||
<option value="PPPoE" {if $service=='PPPoE' }selected{/if}>{Lang::T('PPPoE')}</option>
|
||||
<option value="Hotspot" {if $service=='Hotspot' }selected{/if}>{Lang::T('Hotspot')}</option>
|
||||
<option value="VPN" {if $service=='VPN' }selected{/if}>{Lang::T('VPN')}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">{Lang::T('Group')}</label>
|
||||
<div class="col-md-6">
|
||||
@ -101,6 +115,8 @@
|
||||
<th>{Lang::T('Phone')}</th>
|
||||
<th>{Lang::T('Status')}</th>
|
||||
<th>{Lang::T('Message')}</th>
|
||||
<th>{Lang::T('Router')}</th>
|
||||
<th>{Lang::T('Service Type')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
@ -140,7 +156,8 @@
|
||||
batch: $('#batch').val(),
|
||||
router: $('#router').val() || '',
|
||||
page: page,
|
||||
test: $('#test').is(':checked') ? 'on' : 'off'
|
||||
test: $('#test').is(':checked') ? 'on' : 'off',
|
||||
service: $('#service').val(),
|
||||
},
|
||||
dataType: 'json',
|
||||
beforeSend: function () {
|
||||
@ -171,7 +188,9 @@
|
||||
msg.name,
|
||||
msg.phone,
|
||||
`<span class="text-${statusClass}">${msg.status}</span>`,
|
||||
msg.message || 'No message'
|
||||
msg.message || 'No message',
|
||||
msg.router ? msg.router : 'All Router',
|
||||
msg.service == 'all' ? 'All Service' : (msg.service || 'No Service')
|
||||
]).draw(false); // Add row without redrawing the table
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user