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