Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]Different timezone CDR recording #681

Open
wants to merge 1 commit into
base: V6.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions web_interface/astpp/application/libraries/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ function uset_timezone() {
$account_data = $this->CI->session->userdata ( 'accountinfo' );
return $account_data ['timezone_id'];
}
function display_GMT($currDate, $fulldate = 1, $timezone_id = "") {
// ASTPPCOM-891 Ashish start
function display_GMT($currDate, $fulldate = 1, $timezone_id = "",$table_key = '') {
// ASTPPCOM-891 Ashish end
$number = ($timezone_id == "") ? $this->uset_timezone () : $timezone_id;
$SERVER_GMT = '0';
// ASTPPCOM-891 Ashish start
$SERVER_GMT = ($table_key == "livecall") ? $this->get_server_timezone(): '0' ;
// ASTPPCOM-891 Ashish end

$result = $this->CI->db->query ( "select gmtoffset from timezone where id =" . $number );
$timezone_offset = $result->result ();
Expand Down Expand Up @@ -63,7 +67,9 @@ function display_GMT($currDate, $fulldate = 1, $timezone_id = "") {
}
function convert_to_GMT_new($currDate, $fulldate = 1, $timezone_id = '') {
$number = ($timezone_id == "") ? $this->uset_timezone () : $timezone_id;
$SERVER_GMT = '0';
// ASTPPCOM-891 Ashish start
$SERVER_GMT = $this->get_server_timezone();
// ASTPPCOM-891 Ashish End
$result = $this->CI->db->query ( "select gmtoffset,timezone_name from timezone where id =" . $number );
$timezone_offset = $result->result ();
$USER_GMT = $timezone_offset ['0']->gmtoffset;
Expand All @@ -86,7 +92,9 @@ function convert_to_GMT_new($currDate, $fulldate = 1, $timezone_id = '') {

function convert_to_GMT($currDate, $fulldate = 1, $timezone_id = '') {
$number = ($timezone_id == "") ? $this->uset_timezone () : $timezone_id;
$SERVER_GMT = '0';
// ASTPPCOM-891 Ashish start
$SERVER_GMT = $this->get_server_timezone();
// ASTPPCOM-891 Ashish end
$result = $this->CI->db->query ( "select gmtoffset from timezone where id =" . $number );
$timezone_offset = $result->result ();
$USER_GMT = $timezone_offset ['0']->gmtoffset;
Expand Down Expand Up @@ -114,6 +122,17 @@ function get_login_type_timezone(){
$date = new DateTime("now", new DateTimeZone($timezone_name));
return $date->format('Y-m-d');
}

// ASTPPCOM-891 Ashish start
function get_server_timezone(){
$server_time_zone = exec("timedatectl | grep Time");
$server_time_zone = explode(":",$server_time_zone);
$server_time_zone = explode(" ",$server_time_zone[1]);
$result = $this->CI->db->query ( "select gmtoffset from timezone where timezone_name = '".$server_time_zone[1]."'" );
$timezone_offset = $result->result ();

$SERVER_GMT = $timezone_offset ['0']->gmtoffset;
return $SERVER_GMT;
}
// ASTPPCOM-891 Ashish end
}
?>
11 changes: 6 additions & 5 deletions web_interface/astpp/application/libraries/astpp/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -1862,14 +1862,15 @@ function emailFunction($from, $to, $subject, $message,$alert_template="",$usermo
$last_id=$this->CI->db->insert_id();
return $last_id;
}

function convert_GMT_to($select = "", $table = "", $date, $timezone_id = '') {

// ASTPPCOM-891 Ashish start
function convert_GMT_to($select = "", $table = "", $date, $timezone_id = '', $table_key = '') {
// ASTPPCOM-891 Ashish end
if ($date == '0000-00-00 00:00:00') {
return $date;
} else {

return $this->CI->timezone->display_GMT ( $date, 1, $timezone_id );
// ASTPPCOM-891 Ashish start
return $this->CI->timezone->display_GMT ( $date, 1, $timezone_id , $table_key);
// ASTPPCOM-891 Ashish end
}
}
function convert_GMT($date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,42 @@ function customerReport_call_statistics_with_profit() {
$month=isset($post['month'])&& $post['month'] >0 ? $post['month']:date("m");
$json_data = array();
if($post['drop_val'] == "t_week"){
$start_date = (date('D')!='Mon') ? date('Y-m-d ',strtotime('last Monday')) : date('Y-m-d');
$end_date = date('Y-m-d');
// ASTPPCOM-891 Ashish start
$start_date = (date('D')!='Mon') ? date('Y-m-d H:i:s',strtotime('last Monday')) : date('Y-m-d H:i:s');
$end_date = date('Y-m-d H:i:s');
$start_date_gmt = (date('D')!='Mon') ? date('Y-m-d',strtotime('last Monday')) : date('Y-m-d');
$end_date_gmt = date('Y-m-d');
$start_date = $this->common->convert_GMT_new($start_date);
$end_date = $this->common->convert_GMT_new($end_date);
// ASTPPCOM-891 Ashish end
}else{
$start_date=date($year.'-'.$month.'-01');
$end_day= $year==date("Y") && $month ==date("m") ? date("d") :cal_days_in_month(CAL_GREGORIAN, $month, $year);
$gmtoffset=$this->common->get_timezone_offset();
$end_date=date($year."-".$month."-".$end_day.' H:i:s');
$end_date=date('Y-m-d',strtotime($end_date)+$gmtoffset);
// ASTPPCOM-891 Ashish start
$end_date =date($year."-".$month."-".$end_day.' H:i:s');
$end_date=date('Y-m-d',strtotime($end_date));
$start_date_gmt = $start_date;
$end_date_gmt =$end_date;
$start_date = $this->common->convert_GMT_new($start_date);
$end_date = $this->common->convert_GMT_new($end_date);
// ASTPPCOM-891 Ashish end
}
$current_date=(int)date("d");
$count=0;
$i=0;
$begin = new DateTime($start_date);
$end = new DateTime($end_date);
// ASTPPCOM-891 Ashish start
$begin = new DateTime($start_date_gmt);
$end = new DateTime($end_date_gmt);
// ASTPPCOM-891 Ashish end
$end=$end->modify('+1 day');
$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
$records_date=array();
$accountinfo=$this->session->userdata('accountinfo');
$parent_id= ($accountinfo['type'] == 1) ? $accountinfo['id'] : 0;
$customerresult = $this->dashboard_model->get_call_statistics('cdrs_day_by_summary',$parent_id,$start_date,$end_date);
// ASTPPCOM-891 Ashish start
$customerresult = $this->dashboard_model->get_call_statistics('cdrs_day_by_summary',$parent_id,$start_date_gmt,$end_date_gmt);
// ASTPPCOM-891 Ashish end
$acc_arr = array();
$customer_total_result = array();
$customer_total_result['sum'] = '0';
Expand All @@ -125,6 +141,9 @@ function customerReport_call_statistics_with_profit() {
$res_mcd = 0;
if($customerresult -> num_rows > 0){
foreach ($customerresult->result_array() as $data) {
// ASTPPCOM-891 Ashish start
$data['day'] = date('d',strtotime($data['day']));
// ASTPPCOM-891 Ashish end
$acc_arr[$data['day']] = $data;
$customer_total_result['sum'] += $data['sum'];
$customer_total_result['answered'] += $data['answered'];
Expand Down Expand Up @@ -357,10 +376,18 @@ function customerReport_maximum_countryminutes() {


function customerReport_calculation(){
$today_start_date = date("Y-m-d 00:00:00");
$today_end_date = date("Y-m-d 23:59:59");
// ASTPPCOM-891 Ashish start
$current_date = $this->common->get_current_login_type_timezone();
$today_start_date = date($current_date." 00:00:00");
$today_end_date = date($current_date." 23:59:59");
$today_start_date=$this->common->convert_GMT_new ($today_start_date);
$today_end_date=$this->common->convert_GMT_new ($today_end_date);
// ASTPPCOM-891 Ashish End
$start_date = date('Y-m-01 00:00:00');
$end_date = date('Y-m-d H:i:s');
// ASTPPCOM-891 Ashish start
$end_date=$this->common->convert_GMT_new ($end_date);
// ASTPPCOM-891 Ashish End
$accountinfo = $this->session->userdata ( 'accountinfo' );
if($accountinfo['type'] == '1'){
$reseller_id = $accountinfo['id'];
Expand Down Expand Up @@ -546,39 +573,48 @@ function getrefill_value(){

function get_today_result(){
$accountinfo = $this->session->userdata ( 'accountinfo' );
// ASTPPCOM-891 Ashish start
$start_date = $this->common->convert_GMT_new (date("Y-m-d") . " 00:00:00");
$end_date = $this->common->convert_GMT_new (date("Y-m-d") . " 23:59:59");
// ASTPPCOM-891 Ashish end
if($accountinfo['type'] == '1'){
$reseller_id = $accountinfo['id'];
}else{
$reseller_id = "0";
}
$query_refill = 'Select sum(amount) as today_refill_amount from payment_transaction where date >= "'.date("Y-m-d 00:00:00").'" and date <= "'.date("Y-m-d 23:59:59").'" and reseller_id="'.$reseller_id.'"';
// ASTPPCOM-891 Ashish start
$query_refill = 'Select sum(amount) as today_refill_amount from payment_transaction where date >= "'.$start_date.'" and date <= "'.$end_date.'" and reseller_id="'.$reseller_id.'"';
// ASTPPCOM-891 Ashish end
$result_refill = $this->db->query($query_refill);
$result_refill = (array) $result_refill->first_row();
if($result_refill['today_refill_amount'] == "" OR $result_refill['today_refill_amount'] == NULL){
$result_array['today_refill_amount'] =$this->common_model->calculate_currency(0);
}else{
$result_array['today_refill_amount'] = $this->common_model->calculate_currency( $result_refill['today_refill_amount'] ) ;
}

$query_order = 'Select count(*) as order_count from orders where order_date <= "'.date("Y-m-d 23:59:59").'" and order_date >= "'.date("Y-m-d 00:00:00").'" and reseller_id="'.$reseller_id.'"';
// ASTPPCOM-891 Ashish start
$query_order = 'Select count(*) as order_count from orders where order_date <= "'.$end_date.'" and order_date >= "'.$start_date.'" and reseller_id="'.$reseller_id.'"';
// ASTPPCOM-891 Ashish end
$result_order = $this->db->query($query_order);
$count = (array) $result_order->first_row();
if($count['order_count'] == "" OR $count['order_count'] == NULL){
$result_array['today_order_count'] = 0;
}else{
$result_array['today_order_count'] = $count['order_count'];
}

$query = 'Select count(*) as account_count from accounts where creation <= "'.date("Y-m-d 23:59:59").'" and creation >= "'.date("Y-m-d 00:00:00").'" and reseller_id="'.$reseller_id.'" and status="0" and deleted="0"';
// ASTPPCOM-891 Ashish start
$query = 'Select count(*) as account_count from accounts where creation <= "'.$end_date.'" and creation >= "'.$start_date.'" and reseller_id="'.$reseller_id.'" and status="0" and deleted="0"';
// ASTPPCOM-891 Ashish end
$result = $this->db->query($query);
$count = (array) $result->first_row();
if($count['account_count'] == "" OR $count['account_count'] == NULL){
$result_array['today_account_count'] = 0;
}else{
$result_array['today_account_count'] = $count['account_count'];
}

$query = 'Select SUM(total_calls) as total_calls from cdrs_day_by_summary where calldate <= "'.date("Y-m-d 23:59:59").'" and calldate >= "'.date("Y-m-d 00:00:00").'" and reseller_id="'.$reseller_id.'"';
// ASTPPCOM-891 Ashish start
$query = 'Select SUM(total_calls) as total_calls from cdrs_day_by_summary where calldate <= "'.$end_date.'" and calldate >= "'.$start_date.'" and reseller_id="'.$reseller_id.'"';
// ASTPPCOM-891 Ashish end
$result = $this->db->query($query);
$count = (array) $result->first_row();
if($count['total_calls'] == "" OR $count['total_calls'] == NULL){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function get_recent_recharge() {
return $this->db->get ( 'payments' );
}
function get_call_statistics($table, $parent_id, $start_date = '', $end_date = '', $group_flag = true) {
// ASTPPCOM-891 Ashish start
$this->db->select ( "sum(total_calls) as sum,
SUM(total_answered_call) as answered,
MAX(mcd) AS mcd,
Expand All @@ -59,7 +60,8 @@ function get_call_statistics($table, $parent_id, $start_date = '', $end_date = '
sum(debit) as debit,
sum(cost) as cost,
SUM(total_answered_call) as completed,
DAY(calldate) as day", false );
calldate as day", false );
// ASTPPCOM-891 Ashish end
$this->db->where ( 'calldate >=', $start_date . " 00:00:00" );
$this->db->where ( 'calldate <=', $end_date . " 23:59:59" );
$this->db->where ( 'reseller_id', $parent_id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ function livecall_report_json()
'cell' => array(
"<a href='" . base_url() . "freeswitch/livecall_hangup?uuid=" . $value['uuid'] . "' class='btn btn-warning'> Hang Up </button>",
// Ashish ASTPPCOM-752
$this->common->convert_GMT_to('', '', $value['created']),
// ASTPPCOM-891 Ashish start
$this->common->convert_GMT_to('', '', $value['created'],'','livecall'),
// ASTPPCOM-891 Ashish end
// Ashish 752 End
$value['cid_name'] . " " . $value['cid_num'],
$value['ip_addr'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ function getcustomer_cdrs($flag, $start, $limit, $export = false)
// ASTPPCOM-825 end
$table_name = 'cdrs';
if ($this->session->userdata('advance_search_date') == 1) {
$where['callstart >= '] = date("Y-m-d") . " 00:00:00";
$where['callstart <='] = date("Y-m-d") . " 23:59:59";
// ASTPPCOM-891 Ashish start
$timezone = $this->common->get_current_login_type_timezone();
$where['callstart >= '] =$this->common->convert_GMT_new ( $timezone . " 00:00:00");
$where['callstart <='] =$this->common->convert_GMT_new ( $timezone . " 23:59:59");
// ASTPPENT-891 Ashish end
} else {
if ($this->session->userdata('customerReport_cdrs_year') != '' and $this->session->userdata('customerReport_cdrs_year') != '0') {
$table_name = $this->session->userdata('customerReport_cdrs_year');
Expand Down Expand Up @@ -110,14 +113,19 @@ function getreseller_cdrs($flag, $start, $limit, $export = false)
"accountid <>" => $account_data['id']
);
if ($this->session->userdata('advance_search_date') == 1) {
$where['callstart >= '] = date("Y-m-d") . " 00:00:00";
$where['callstart <='] = date("Y-m-d") . " 23:59:59";
// ASTPPENT-891 Ashish start
$timezone = $this->common->get_current_login_type_timezone();
$where['callstart >= '] =$this->common->convert_GMT_new ( $timezone . " 00:00:00");
$where['callstart <='] =$this->common->convert_GMT_new ( $timezone . " 23:59:59");
// ASTPPENT-891 Ashish end
}
} else {
if ($this->session->userdata('advance_search_date') == 1) {
$where = array(
'callstart >= ' => date("Y-m-d") . " 00:00:00",
'callstart <=' => date("Y-m-d") . " 23:59:59"
// ASTPPENT-891 Ashish start
'callstart >= ' =>$this->common->convert_GMT_new ( date("Y-m-d") . " 00:00:00"),
'callstart <=' => $this->common->convert_GMT_new (date("Y-m-d") . " 23:59:59")
// ASTPPENT-891 Ashish end
);
}
}
Expand Down Expand Up @@ -165,8 +173,11 @@ function getprovider_cdrs($flag, $start, $limit, $export = false)

if ($this->session->userdata('advance_search') != 1) {
if ($this->session->userdata('advance_search_date') == 1) {
$where['callstart >= '] = date("Y-m-d") . " 00:00:00";
$where['callstart <='] = date("Y-m-d") . " 23:59:59";
// ASTPPENT-891 Ashish start
$timezone = $this->common->get_current_login_type_timezone();
$where['callstart >= '] =$this->common->convert_GMT_new ( $timezone . " 00:00:00");
$where['callstart <='] =$this->common->convert_GMT_new ( $timezone . " 23:59:59");
// ASTPPENT-891 Ashish end
}
} else {
if ($this->session->userdata('providerreport_cdrs_year') != '' and $this->session->userdata('providerreport_cdrs_year') != '0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2814,6 +2814,10 @@ function user_invoice_unpaid_pay()
function user_get_current_info()
{
$account_data = $this->session->userdata("accountinfo");
// ASTPPCOM-891 Ashish start
$start_date = $this->common->convert_GMT_new (date("Y-m-d") . " 00:00:01");
$end_date = $this->common->convert_GMT_new (date("Y-m-d H:i:s"));
// ASTPPCOM-891 Ashish end
$where = array(
"accountid" => $account_data['id'],
"order_date >=" => date("Y-m-d 00:00:01"),
Expand All @@ -2823,8 +2827,10 @@ function user_get_current_info()
$result_array['product_count'] = $count_all;
$where_cdr = array(
"accountid" => $account_data['id'],
"callstart >=" => date("Y-m-d 00:00:01"),
"callstart <=" => date("Y-m-d H:i:s")
// ASTPPCOM-891 Ashish start
"callstart >=" => $start_date,
"callstart <=" => $end_date
// ASTPPCOM-891 Ashish end
);
$count_cdrs = $this->db_model->countQuery("*", "cdrs", $where_cdr);
$result_array['call_count'] = $count_cdrs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,11 @@ function getuser_cdrs_list($flag, $start, $limit, $export = true)
}
$table_name = $account_data['type'] != 1 ? 'cdrs' : 'reseller_cdrs';
if ($this->session->userdata('advance_search_date') == 1) {
$where['callstart >= '] = date("Y-m-d") . " 00:00:00";
$where['callstart <='] = date("Y-m-d") . " 23:59:59";
// ASTPPCOM-891 Ashish start
$timezone = $this->common->get_current_login_type_timezone();
$where['callstart >= '] = $this->common->convert_GMT_new ( $timezone . " 00:00:00");
$where['callstart <='] = $this->common->convert_GMT_new ( $timezone . " 23:59:59");
// ASTPPCOM-891 Ashish end
} else {
if ($this->session->userdata('cdrs_year') != '' and $this->session->userdata('cdrs_year') != '0') {
$table_name = $this->session->userdata('cdrs_year');
Expand Down