invoices.php

来自「asterisk用 的voip记费软件」· PHP 代码 · 共 1,049 行 · 第 1/3 页

PHP
1,049
字号
<?phpinclude ("../lib/defines.php");include ("../lib/module.access.php");include ("../lib/smarty.php");if (! has_rights (ACX_INVOICING)){	Header ("HTTP/1.0 401 Unauthorized");	Header ("Location: PP_error.php?c=accessdenied");	   	die();}session_start();getpost_ifset(array('customer', 'entercustomer', 'enterprovider', 'entertrunk', 'posted', 'Period', 'frommonth', 'fromstatsmonth', 'tomonth', 'tostatsmonth', 'fromday', 'fromstatsday_sday', 'fromstatsmonth_sday', 'today', 'tostatsday_sday', 'tostatsmonth_sday', 'dsttype', 'sourcetype', 'clidtype', 'channel', 'resulttype', 'stitle', 'atmenu', 'current_page', 'order', 'sens', 'dst', 'src', 'clid', 'fromstatsmonth_sday', 'fromstatsmonth_shour', 'tostatsmonth_sday', 'tostatsmonth_shour', 'fromstatsmonth_smin', '','tostatsmonth_smin', 'src', 'choose_currency','exporttype'));if (($_GET[download]=="file") && $_GET[file] ) {	$value_de=base64_decode($_GET[file]);	$dl_full = MONITOR_PATH."/".$value_de;	$dl_name=$value_de;	if (!file_exists($dl_full))	{ 		echo gettext("ERROR: Cannot download file ".$dl_full.", it does not exist.<br>");		exit();	} 		header("Content-Type: application/octet-stream");	header("Content-Disposition: attachment; filename=$dl_name");	header("Content-Length: ".filesize($dl_full));	header("Accept-Ranges: bytes");	header("Pragma: no-cache");	header("Expires: 0");	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");	header("Content-transfer-encoding: binary");		@readfile($dl_full);	exit();}if (!isset ($current_page) || ($current_page == "")){		$current_page=0; }// this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking)$FG_DEBUG = 0;// The variable FG_TABLE_NAME define the table name to use$FG_TABLE_NAME="cc_call t1 LEFT OUTER JOIN cc_trunk t3 ON t1.id_trunk = t3.id_trunk";if ($_SESSION["is_admin"]==0){ 	$FG_TABLE_NAME.=", cc_card t2";}// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE$FG_TABLE_HEAD_COLOR = "#D1D9E7";$FG_TABLE_EXTERN_COLOR = "#7F99CC"; //#CC0033 (Rouge)$FG_TABLE_INTERN_COLOR = "#EDF3FF"; //#FFEAFF (Rose)// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#FFFFFF";$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#F2F8FF";$yesno = array(); 	$yesno["1"]  = array( gettext("Yes"), "1");	 $yesno["0"]  = array( gettext("No"), "0");//$link = DbConnect();$DBHandle  = DbConnect();// The variable Var_col would define the col that we want show in your table// First Name of the column in the html page, second name of the field$FG_TABLE_COL = array();/*******Calldate Clid Src Dst Dcontext Channel Dstchannel Lastapp Lastdata Duration Billsec Disposition Amaflags Accountcode Uniqueid Serverid*******/$FG_TABLE_COL[]=array (gettext("Calldate"), "starttime", "18%", "center", "SORT", "19", "", "", "", "", "", "display_dateformat");//$FG_TABLE_COL[]=array ("Callend", "stoptime", "15%", "center", "SORT", "19");$FG_TABLE_COL[]=array (gettext("Source"), "src", "10%", "center", "SORT", "30");$FG_TABLE_COL[]=array (gettext("CalledNumber"), "calledstation", "18%", "right", "SORT", "30", "", "", "", "", "", "");$FG_TABLE_COL[]=array (gettext("Destination"), "destination", "18%", "center", "SORT", "30", "", "", "", "", "", "remove_prefix");$FG_TABLE_COL[]=array (gettext("Duration"), "sessiontime", "8%", "center", "SORT", "30", "", "", "", "", "", "display_minute");if (!(isset($customer)  &&  ($customer>0)) && !(isset($entercustomer)  &&  ($entercustomer>0))){	$FG_TABLE_COL[]=array (gettext("CardUsed"), "username", "11%", "center", "SORT", "30");}//if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Buycosts", "buycosts", "12%", "center", "SORT", "30");//-- $FG_TABLE_COL[]=array ("InitialRate", "calledrate", "10%", "center", "SORT", "30", "", "", "", "", "", "display_2dec");$FG_TABLE_COL[]=array (gettext("Cost"), "sessionbill", "9%", "center", "SORT", "30", "", "", "", "", "", "display_2bill");$FG_TABLE_DEFAULT_ORDER = "t1.starttime";$FG_TABLE_DEFAULT_SENS = "DESC";	// This Variable store the argument for the SQL query$FG_COL_QUERY='t1.starttime, t1.src, t1.calledstation, t1.destination, t1.sessiontime  ';if (!(isset($customer)  &&  ($customer>0)) && !(isset($entercustomer)  &&  ($entercustomer>0))){	$FG_COL_QUERY.=', t1.username';}$FG_COL_QUERY.=', t1.sessionbill';$FG_COL_QUERY_GRAPH='t1.callstart, t1.duration';// The variable LIMITE_DISPLAY define the limit of record to display by page$FG_LIMITE_DISPLAY=500;// Number of column in the html table$FG_NB_TABLE_COL=count($FG_TABLE_COL);// The variable $FG_EDITION define if you want process to the edition of the database record$FG_EDITION=true;//This variable will store the total number of column$FG_TOTAL_TABLE_COL = $FG_NB_TABLE_COL;if ($FG_DELETION || $FG_EDITION) $FG_TOTAL_TABLE_COL++;//This variable define the width of the HTML table$FG_HTML_TABLE_WIDTH="70%";if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME  	- 	Col_query : $FG_COL_QUERY";$instance_table = new Table($FG_TABLE_NAME, $FG_COL_QUERY);$instance_table_graph = new Table($FG_TABLE_NAME, $FG_COL_QUERY_GRAPH);if ( is_null ($order) || is_null($sens) ){	$order = $FG_TABLE_DEFAULT_ORDER;	$sens  = $FG_TABLE_DEFAULT_SENS;}if ($posted==1){	function do_field($sql,$fld,$dbfld){		$fldtype = $fld.'type';		global $$fld;		global $$fldtype;		if ($$fld){				if (strpos($sql,'WHERE') > 0){						$sql = "$sql AND ";				}else{						$sql = "$sql WHERE ";				}				$sql = "$sql t1.$dbfld";				if (isset ($$fldtype)){                						switch ($$fldtype) {											case 1:	$sql = "$sql='".$$fld."'";  break;				case 2: $sql = "$sql LIKE '".$$fld."%'";  break;				case 3: $sql = "$sql LIKE '%".$$fld."%'";  break;				case 4: $sql = "$sql LIKE '%".$$fld."'";  break;				case 5:	$sql = "$sql <> '".$$fld."'";  			}				}else{ $sql = "$sql LIKE '%".$$fld."%'"; }		}		return $sql;	}  	$SQLcmd = '';	$SQLcmd = do_field($SQLcmd, 'src', 'src');	$SQLcmd = do_field($SQLcmd, 'dst', 'calledstation');}$date_clause='';// Period (Month-Day)if (DB_TYPE == "postgres"){			$UNIX_TIMESTAMP = "";}else{	$UNIX_TIMESTAMP = "UNIX_TIMESTAMP";}$lastdayofmonth = date("t", strtotime($tostatsmonth.'-01'));if ($Period=="Month"){	if ($frommonth && isset($fromstatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.starttime) >= $UNIX_TIMESTAMP('$fromstatsmonth-01')";	if ($tomonth && isset($tostatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.starttime) <= $UNIX_TIMESTAMP('".$tostatsmonth."-$lastdayofmonth 23:59:59')"; }else{	if ($fromday && isset($fromstatsday_sday) && isset($fromstatsmonth_sday) && isset($fromstatsmonth_shour) && isset($fromstatsmonth_smin) ) $date_clause.=" AND $UNIX_TIMESTAMP(t1.starttime) >= $UNIX_TIMESTAMP('$fromstatsmonth_sday-$fromstatsday_sday $fromstatsmonth_shour:$fromstatsmonth_smin')";	if ($today && isset($tostatsday_sday) && isset($tostatsmonth_sday) && isset($tostatsmonth_shour) && isset($tostatsmonth_smin)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.starttime) <= $UNIX_TIMESTAMP('$tostatsmonth_sday-".sprintf("%02d",intval($tostatsday_sday))." $tostatsmonth_shour:$tostatsmonth_smin')";}  if (strpos($SQLcmd, 'WHERE') > 0) { 	$FG_TABLE_CLAUSE = substr($SQLcmd,6).$date_clause; }elseif (strpos($date_clause, 'AND') > 0){	$FG_TABLE_CLAUSE = substr($date_clause,5); }if (!isset ($FG_TABLE_CLAUSE) || strlen($FG_TABLE_CLAUSE)==0){		$cc_yearmonth = sprintf("%04d-%02d-%02d",date("Y"),date("n"),date("d")); 		$FG_TABLE_CLAUSE=" $UNIX_TIMESTAMP(t1.starttime) >= $UNIX_TIMESTAMP('$cc_yearmonth')";}if (isset($customer)  &&  ($customer>0)){	if (strlen($FG_TABLE_CLAUSE)>0) $FG_TABLE_CLAUSE.=" AND ";	$FG_TABLE_CLAUSE.="t1.username='$customer'";}else{	if (isset($entercustomer)  &&  ($entercustomer>0)){		if (strlen($FG_TABLE_CLAUSE)>0) $FG_TABLE_CLAUSE.=" AND ";		$FG_TABLE_CLAUSE.="t1.username='$entercustomer'";	}}if ($_SESSION["is_admin"] == 1){	if (isset($enterprovider) && $enterprovider > 0) {		if (strlen($FG_TABLE_CLAUSE) > 0) $FG_TABLE_CLAUSE .= " AND ";		$FG_TABLE_CLAUSE .= "t3.id_provider = '$enterprovider'";	}	if (isset($entertrunk) && $entertrunk > 0) {		if (strlen($FG_TABLE_CLAUSE) > 0) $FG_TABLE_CLAUSE .= " AND ";		$FG_TABLE_CLAUSE .= "t3.id_trunk = '$entertrunk'";	}}if ($_SESSION["is_admin"]==0){ 		if (strlen($FG_TABLE_CLAUSE)>0) $FG_TABLE_CLAUSE.=" AND ";	$FG_TABLE_CLAUSE.="t1.cardID=t2.IDCust AND t2.IDmanager='".$_SESSION["pr_reseller_ID"]."'";	}if (!$nodisplay){	$list = $instance_table -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page*$FG_LIMITE_DISPLAY);}$_SESSION["pr_sql_export"]="SELECT $FG_COL_QUERY FROM $FG_TABLE_NAME WHERE $FG_TABLE_CLAUSE";/************************///$QUERY = "SELECT substring(calldate,1,10) AS day, sum(duration) AS calltime, count(*) as nbcall FROM cdr WHERE ".$FG_TABLE_CLAUSE." GROUP BY substring(calldate,1,10)"; //extract(DAY from calldate) $QUERY = "SELECT substring(t1.starttime,1,10) AS day, sum(t1.sessiontime) AS calltime, sum(t1.sessionbill) AS cost, count(*) as nbcall FROM $FG_TABLE_NAME WHERE ".$FG_TABLE_CLAUSE." GROUP BY substring(t1.starttime,1,10) ORDER BY day"; //extract(DAY from calldate) if (!$nodisplay){	$res = $DBHandle -> Execute($QUERY);	if ($res){		$num = $res -> RecordCount();		for($i=0;$i<$num;$i++)		{							$list_total_day [] =$res -> fetchRow();				 		}	}		if ($FG_DEBUG == 3) echo "<br>Clause : $FG_TABLE_CLAUSE";	$nb_record = $instance_table -> Table_count ($DBHandle, $FG_TABLE_CLAUSE);	if ($FG_DEBUG >= 1) var_dump ($list);}//end IF nodisplay// GROUP BY DESTINATION FOR THE INVOICE$QUERY = "SELECT destination, sum(t1.sessiontime) AS calltime, sum(t1.sessionbill) AS cost, count(*) as nbcall FROM $FG_TABLE_NAME WHERE ".$FG_TABLE_CLAUSE." GROUP BY destination"; if (!$nodisplay){	$res = $DBHandle -> Execute($QUERY);	if ($res){		$num = $res -> RecordCount();		for($i=0;$i<$num;$i++)		{							$list_total_destination [] =$res -> fetchRow();				 		}	}	if ($FG_DEBUG == 3) echo "<br>Clause : $FG_TABLE_CLAUSE";	if ($FG_DEBUG >= 1) var_dump ($list_total_destination);}//end IF nodisplayif ($nb_record<=$FG_LIMITE_DISPLAY){ 	$nb_record_max=1;}else{ 	if ($nb_record % $FG_LIMITE_DISPLAY == 0){		$nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY));	}else{		$nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY)+1);	}	}if ($FG_DEBUG == 3) echo "<br>Nb_record : $nb_record";if ($FG_DEBUG == 3) echo "<br>Nb_record_max : $nb_record_max";/*************************************************************/$instance_table_customer = new Table("cc_card", "id,  username, lastname");$FG_TABLE_CLAUSE = "";if ($_SESSION["is_admin"]==0){ 		$FG_TABLE_CLAUSE =" IDmanager='".$_SESSION["pr_reseller_ID"]."'";	}$list_customer = $instance_table_customer -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, "id", "ASC", null, null, null, null);$nb_customer = count($list_customer);/*************************************************************/if ((isset($customer)  &&  ($customer>0)) || (isset($entercustomer)  &&  ($entercustomer>0))){	$FG_TABLE_CLAUSE = "";	if (isset($customer)  &&  ($customer>0)){				$FG_TABLE_CLAUSE =" username='$customer' ";	}elseif (isset($entercustomer)  &&  ($entercustomer>0)){		$FG_TABLE_CLAUSE =" username='$entercustomer' ";	}		$instance_table_customer = new Table("cc_card", "id,  username, lastname, firstname, address, city, state, country, zipcode, phone, email, fax");		$info_customer = $instance_table_customer -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, "id", "ASC", null, null, null, null);	}if ($_SESSION["is_admin"] == 1){	if (isset($enterprovider) && $enterprovider > 0) {		if (strlen($FG_TABLE_CLAUSE) > 0) $FG_TABLE_CLAUSE .= " AND ";		$FG_TABLE_CLAUSE .= "t3.id_provider = '$enterprovider'";	}	if (isset($entertrunk) && $entertrunk > 0) {		if (strlen($FG_TABLE_CLAUSE) > 0) $FG_TABLE_CLAUSE .= " AND ";		$FG_TABLE_CLAUSE .= "t3.id_trunk = '$entertrunk'";	}}/************************************************************/$date_clause='';if ($Period=="Month"){	if ($frommonth && isset($fromstatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.creationdate) >= $UNIX_TIMESTAMP('$fromstatsmonth-01')";	if ($tomonth && isset($tostatsmonth)) $date_clause.=" AND  $UNIX_TIMESTAMP(t1.creationdate) <= $UNIX_TIMESTAMP('".$tostatsmonth."-$lastdayofmonth 23:59:59')"; }else{	if ($fromday && isset($fromstatsday_sday) && isset($fromstatsmonth_sday) && isset($fromstatsmonth_shour) && isset($fromstatsmonth_smin) ) $date_clause.=" AND  $UNIX_TIMESTAMP(t1.creationdate) >= $UNIX_TIMESTAMP('$fromstatsmonth_sday-$fromstatsday_sday $fromstatsmonth_shour:$fromstatsmonth_smin')";	if ($today && isset($tostatsday_sday) && isset($tostatsmonth_sday) && isset($tostatsmonth_shour) && isset($tostatsmonth_smin)) $date_clause.=" AND  $UNIX_TIMESTAMP(t1.creationdate) <= $UNIX_TIMESTAMP('$tostatsmonth_sday-".sprintf("%02d",intval($tostatsday_sday))." $tostatsmonth_shour:$tostatsmonth_smin')";}if (strpos($date_clause, 'AND') > 0){	$date_clause = ' WHERE '.substr($date_clause,5); }if (isset($entercustomer) && $entercustomer > 0) {	$tclause = (strlen($date_clause)>1)?'AND':'WHERE';	$date_clause .= " $tclause t1.id_cc_card = t2.id AND t2.username = '$entercustomer' ";	$QUERY = "SELECT substring(t1.creationdate,1,10) AS day, sum(t1.amount) AS cost, count(*) as nbcharge FROM cc_charge t1, cc_card t2 ".$date_clause." GROUP BY substring(t1.creationdate,1,10) ORDER BY day"; //extract(DAY from calldate) 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?