0 AND (calledstation LIKE '99090%' or calledstation LIKE '0%' ) "; //Filter only Speed call if ($dsttype == 'Domestic-SP') $sql = $sql." and calledstation not LIKE '9909%' "; //$orderbystr = " todate desc "; $sql = $sql." order by ".$orderbystr." desc"; //echo $sql; //set_time_limit(99000); $s = mysql_query($sql); if ($s == 0) { die('Failed to query data to database:
'."\n".mysql_error()); } $fields = mysql_num_fields ( $s ); // echo($sql); //Send Mail //add From: header $headers = "From: panya.p@jasmine.com\r\n"; //specify MIME version 1.0 $headers .= "MIME-Version: 1.0\r\n"; //unique boundary $boundary = uniqid("HTMLMAIL"); //tell e-mail client this e-mail contains//alternate versions $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; //plain text version of message //$body = "--$boundary\r\n" . // "Content-Type: text/plain; charset=windows-874\r\n" . // "Content-Transfer-Encoding: base64\r\n\r\n"; //$body .= chunk_split(base64_encode("This is the plain text version! ทดสอบครับ")); //HTML version of message $body .= "--$boundary\r\n" . "Content-Type: text/html; charset=windows-874\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $body_msg = ' Sabaydee Plus Account '.$dsttype.' Usage in last 3 months detail report for username '.$username.'
Sabaydee Plus Account '.$dsttype.' Usage in last 3 months detail report

SBD Account#
'; for($i=1;$i<$fields;$i++){ $body_msg .=''; } $sum_column = array(); $sum_column[] = 0; $irow = 0; while ($row = mysql_fetch_assoc($s)) { $body_msg .=''; $irow++; $ireset = 0; foreach( $row as $value ) { if(($ireset >3 & $ireset < 5)){ $nvalue = number_format($value,2); }else{ $nvalue = $value; if(substr($nvalue,0,4) == 'SATF') $phonelen = 7; else $phonelen = 4; } if(($irow%2)==0 ){ $body_msg .=''; }else{ $body_msg .=''; } $sum_column[$ireset] += $value; $ireset++; } // $ireset=0; } //while $body_msg .= ""; // mysql_close($link); // Sum value $sql = "select 'Total $dsttype' as srctype,'in last 3 months' AS dsttype, SUM(freq) AS attempt_calls, SUM(successcall) AS ans_calls, SUM(minutes) AS actmin, ROUND(SUM(minutes)/SUM(successcall),2) AS 'avgminpercall',round(SUM(successcall)/SUM(freq),2) as ASR, concat('From ',date_sub( date(now()), interval 3 month),' to ',date(now())) as lastcalldate FROM call_statistic WHERE username like '$username%' AND successcall>0 AND (calledstation LIKE '99090%' or calledstation LIKE '0%') "; //Filter only Speed call if ($dsttype == 'Domestic-SP') $sql = $sql." and calledstation not LIKE '9909%' "; $sql = $sql." GROUP BY srctype,dsttype "; $s = mysql_query($sql); if ($s == 0) { die('Failed to query data to database:
'."\n".mysql_error()); } $fields = mysql_num_fields ( $s ); $irow = 0; while ($row = mysql_fetch_assoc($s)) { $body_msg .=''; $irow++; $ireset = 0; foreach( $row as $value ) { if(($ireset >3 & $ireset < 5)){ $nvalue = number_format($value,2); }else{ $nvalue = $value; } if(($irow%2)==0 ){ $body_msg .=''; }else{ $body_msg .=''; } $sum_column[$ireset] += $value; $ireset++; } // $ireset=0; } //while $body_msg .= ""; //sum_column[0] = "Total usage"; //$sum_column[1] = "in last 3 months"; //$sum_column[4] = round(($sum_column[3]/$sum_column[2]),2) ; //$sum_column[2] = round(($sum_column[7]-$sum_column[5])*100/$sum_column[5],2) ; //$sum_column[12] = ''; /*for($i=0;$i<$fields;$i++){ if($i >=3 & $i < 5){ $body_msg .=''; }else{ $body_msg .=''; } } */ $body_msg .=''; //$body_msg .=' '; // for($i=1;$i<$fields;$i++){ // $body_msg .=''; // // }; $body_msg .='
'.mysql_field_name($s, 0).''.mysql_field_name($s, $i).'
'; if($ireset == 0 & $nvalue != 'LAND') { //Deep to each account usage $body_msg .= ' '.$nvalue.' '; } else if($ireset == 1 & substr($nvalue,0,3) == 'SBD') { //Deep to each account usage $body_msg .= ' '.$nvalue.' '; } else $body_msg .= $nvalue.' '; if($ireset == 0 & $nvalue != 'LAND') { //Deep to each account usage $body_msg .= ' '.$nvalue.' '; } else if($ireset == 1 & substr($nvalue,0,3) == 'SBD') { //Deep to each account usage $body_msg .= ' '.$nvalue.' '; } else $body_msg .= $nvalue.'
'.$nvalue.''.$nvalue.'
'.number_format($sum_column[$i],2).''.$sum_column[$i].'
'.mysql_field_name($s, 0).''.mysql_field_name($s, $i).'
'; $body_msg .='
'; $body .= chunk_split(base64_encode($body_msg)); mysql_close($link); //send message //mail($to_email, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //mail($to_email1, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //mail($to_email2, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //mail($to_email3, "Top 50 destination & custgroup for cybervoice of ".$report_data_date, $body, $headers); //echo "Report Send.
"; echo $body_msg; ?>