fix bulk broadcasting message

This commit is contained in:
iBNu Maksum
2025-02-04 15:13:42 +07:00
parent 3386b17b1b
commit 8d9919afa7
5 changed files with 136 additions and 67 deletions

View File

@ -95,49 +95,65 @@ EOT;
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
// Get form data
$group = $_POST['group'];
$message = $_POST['message'];
$via = $_POST['via'];
$test = isset($_POST['test']) && $_POST['test'] === 'on' ? 'yes' : 'no';
$batch = $_POST['batch'];
$delay = $_POST['delay'];
set_time_limit(0);
// Initialize counters
$totalSMSSent = 0;
$totalSMSFailed = 0;
$totalWhatsappSent = 0;
$totalWhatsappFailed = 0;
$batchStatus = [];
$totalCustomers = 0;
$batchStatus = $_SESSION['batchStatus'];
$page = _req('page', -1);
if (_req('send') == 'now') {
// Get form data
$group = $_REQUEST['group'];
$message = $_REQUEST['message'];
$via = $_REQUEST['via'];
$test = isset($_REQUEST['test']) && $_REQUEST['test'] === 'on' ? 'yes' : 'no';
$batch = $_REQUEST['batch'];
$delay = $_REQUEST['delay'];
$ui->assign('group', $group);
$ui->assign('message', $message);
$ui->assign('via', $via);
$ui->assign('test', $test);
$ui->assign('batch', $batch);
$ui->assign('delay', $delay);
if($page<0){
$batchStatus = [];
$page = 0;
}
$startpoint = $page * $batch;
$page++;
// Check if fields are empty
if ($group == '' || $message == '' || $via == '') {
r2(getUrl('message/send_bulk'), 'e', Lang::T('All fields are required'));
} else {
// Get customer details from the database based on the selected group
if ($group == 'all') {
$customers = ORM::for_table('tbl_customers')->find_many()->as_array();
$customers = ORM::for_table('tbl_customers')
->offset($startpoint)
->limit($batch)->find_array();
} elseif ($group == 'new') {
// Get customers created just a month ago
$customers = ORM::for_table('tbl_customers')->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")->find_many()->as_array();
$customers = ORM::for_table('tbl_customers')->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")
->offset($startpoint)->limit($batch)
->find_array();
} elseif ($group == 'expired') {
// Get expired user recharges where status is 'off'
$expired = ORM::for_table('tbl_user_recharges')->where('status', 'off')->find_many();
$customer_ids = [];
foreach ($expired as $recharge) {
$customer_ids[] = $recharge->customer_id;
}
$customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_many()->as_array();
$expired = ORM::for_table('tbl_user_recharges')->select('customer_id')->where('status', 'off')
->offset($startpoint)->limit($batch)
->find_array();
$customer_ids = array_column($expired, 'customer_id');
$customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_array();
} elseif ($group == 'active') {
// Get active user recharges where status is 'on'
$active = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
$customer_ids = [];
foreach ($active as $recharge) {
$customer_ids[] = $recharge->customer_id;
}
$customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_many()->as_array();
$active = ORM::for_table('tbl_user_recharges')->select('customer_id')->where('status', 'on')
->offset($startpoint)->limit($batch)
->find_array();
$customer_ids = array_column($active, 'customer_id');
$customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_array();
}
// Set the batch size
@ -225,6 +241,9 @@ EOT;
}
}
}
$ui->assign('page', $page);
$ui->assign('totalCustomers', $totalCustomers);
$_SESSION['batchStatus'] = $batchStatus;
$ui->assign('batchStatus', $batchStatus);
$ui->assign('totalSMSSent', $totalSMSSent);
$ui->assign('totalSMSFailed', $totalSMSFailed);

View File

@ -967,5 +967,15 @@
"Create_Bandwidth_Package_for_expired_Internet_Package": "Create Bandwidth Package for expired Internet Package",
"Maps": "Maps",
"Enable": "Enable",
"Continue_the_process_of_changing_Routers_": "Continue the process of changing Routers?"
"Continue_the_process_of_changing_Routers_": "Continue the process of changing Routers?",
"Customer_cannot_buy_disabled_Package__but_admin_can_recharge_it__use_it_if_you_want_only_admin_recharge_it": "Customer cannot buy disabled Package, but admin can recharge it, use it if you want only admin recharge it",
"Postpaid_will_have_fix_expired_date": "Postpaid will have fix expired date",
"Personal_Package_will_only_show_to_personal_Customer__Business_package_will_only_show_to_Business_Customer": "Personal Package will only show to personal Customer, Business package will only show to Business Customer",
"If_you_enable_Radius__choose_device_to_radius__except_if_you_have_custom_device_": "If you enable Radius, choose device to radius, except if you have custom device.",
"This_Device_are_the_logic_how_PHPNuxBill_Communicate_with_Mikrotik_or_other_Devices": "This Device are the logic how PHPNuxBill Communicate with Mikrotik or other Devices",
"Expired_will_be_this_date_every_month": "Expired will be this date every month",
"Continue_the_process_of_adding_the_PPPoE_Package_": "Continue the process of adding the PPPoE Package?",
"Personal_Package_will_only_show_to_personal_Customer__Business_Package_will_only_show_to_Business_Customer": "Personal Package will only show to personal Customer, Business Package will only show to Business Customer",
"Continue_the_PPPoE_Package_change_process_": "Continue the PPPoE Package change process?",
"Sending_message_in_progress__Don_t_close_this_page_": "Sending message in progress. Don't close this page."
}