?? a2b_entity_invoice_detail.php
字號:
<?phpinclude ("../lib/defines.php");include ("../lib/module.access.php");include ("../lib/Form/Class.FormHandler.inc.php");include ("../lib/smarty.php");if (! has_rights (ACX_INVOICING)){ Header ("HTTP/1.0 401 Unauthorized"); Header ("Location: PP_error.php?c=accessdenied"); die(); }getpost_ifset(array('customer', 'posted', 'Period', 'cardid','exporttype','choose_billperiod','id','invoice_type','payment_status'));if ($invoice_type == ""){ $invoice_type = 1;}if ($invoice_type == 1){ if($cardid == "" ) { exit("Invalid ID"); }}if ( $invoice_type == 2){ if(($id == "" || !is_numeric($id))) { exit(gettext("Invalid ID")); }}if ($invoice_type == 1){ $invoice_heading = gettext("Unbilled Details"); }else{ $invoice_heading = gettext("Billed Details");}$DBHandle = DbConnect();$num = 0;if ($invoice_type == 1){ $QUERY = "Select username, vat, t1.id from cc_card t1 where t1.id = $cardid";}else{ $QUERY = "Select username, vat, t1.id from cc_card t1, cc_invoices t2 where t1.id = t2.cardid and t2.id = $id";}$res_user = $DBHandle -> Execute($QUERY);if ($res_user) $num = $res_user -> RecordCount( );if($num > 0){ $userRecord = $res_user -> fetchRow(); $customer = $userRecord[0]; $vat = $userRecord[1]; $customerID = $userRecord[2]; }else{ exit(gettext("No User found"));}if($payment_status != ""){ $QUERY = "UPDATE cc_invoices SET payment_status ='$payment_status' WHERE id='$id'"; $DBHandle -> Execute($QUERY);}// 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";$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();$FG_TABLE_COL[]=array (gettext("Calldate"), "starttime", "18%", "center", "SORT", "19", "", "", "", "", "", "display_dateformat");$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");}$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';if (LINK_AUDIO_FILE == 'YES') $FG_COL_QUERY .= ', t1.uniqueid';$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);//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++; 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";}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($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 (strlen($FG_TABLE_CLAUSE)>0){ $FG_TABLE_CLAUSE.=" AND ";}if ($invoice_type == 1){ $FG_TABLE_CLAUSE.="t1.starttime >(Select CASE WHEN max(cover_enddate) IS NULL THEN '0001-01-01 01:00:00' ELSE max(cover_enddate) END from cc_invoices WHERE cardid = '$cardid') ";}else{ $FG_TABLE_CLAUSE.="t1.starttime >(Select cover_startdate from cc_invoices where id ='$id') AND t1.stoptime <(Select cover_enddate from cc_invoices where id ='$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(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){ $list_total_day = $instance_table->SQLExec ($DBHandle, $QUERY); $nb_record = $instance_table -> Table_count ($DBHandle, $FG_TABLE_CLAUSE);}//end IF nodisplay/************************************************ DID Billing Section *********************************************/// Fixed + Dial = 0// Fixed = 1// Dail = 2// Free = 3// 1. Billing Type:: All DID Calls that have DID Type 0 and 2if ($invoice_type == 1){ $QUERY = "SELECT t1.amount, t1.creationdate, t1.description, t3.countryname, t2.did, t1.currency ". " FROM cc_charge t1 LEFT JOIN (cc_did t2, cc_country t3 ) ON ( t1.id_cc_did = t2.id AND t2.id_cc_country = t3.id ) ". " WHERE (t1.chargetype = 1 OR t1.chargetype = 2) AND t1.id_cc_card = ".$cardid. " AND t1.creationdate >(Select CASE WHEN max(cover_enddate) IS NULL THEN '0001-01-01 01:00:00' ELSE max(cover_enddate) END from cc_invoices)";}else{ $QUERY = "SELECT t1.amount, t1.creationdate, t1.description, t3.countryname, t2.did, t1.currency ". " FROM cc_charge t1 LEFT JOIN (cc_did t2, cc_country t3 ) ON ( t1.id_cc_did = t2.id AND t2.id_cc_country = t3.id ) ". " WHERE (t1.chargetype = 2 OR t1.chargetype = 1) AND t1.id_cc_card = ".$customerID. " AND t1.creationdate > (Select cover_startdate from cc_invoices where id ='$id') AND t1.creationdate <(Select cover_enddate from cc_invoices where id ='$id')";} if (!$nodisplay){ $list_total_did = $instance_table->SQLExec ($DBHandle, $QUERY); }//end IF nodisplay/************************************************ END DID Billing Section *********************************************//*************************************************CHARGES SECTION START ************************************************/// Charge Types// Connection charge for DID setup = 1// Monthly Charge for DID use = 2// Subscription fee = 3// Extra charge = 4if ($invoice_type == 1){ $QUERY = "SELECT t1.id_cc_card, t1.iduser, t1.creationdate, t1.amount, t1.chargetype, t1.id_cc_did, t1.currency, t1.description" . " FROM cc_charge t1, cc_card t2 WHERE (t1.chargetype <> 1 AND t1.chargetype <> 2) " . " AND t2.username = '$customer' AND t1.id_cc_card = t2.id AND t1.creationdate >= (Select CASE WHEN max(cover_enddate) is NULL " . " THEN '0001-01-01 01:00:00' ELSE max(cover_enddate) END from cc_invoices) Order by t1.creationdate";}else{ $QUERY = "SELECT t1.id_cc_card, t1.iduser, t1.creationdate, t1.amount, t1.chargetype, t1.id_cc_did, t1.currency, t1.description" . " FROM cc_charge t1, cc_card t2 WHERE (t1.chargetype <> 2 AND t1.chargetype <> 1)" . " AND t2.username = '$customer' AND t1.id_cc_card = t2.id AND " . " t1.creationdate >(Select cover_startdate from cc_invoices where id ='$id') " . " AND t1.creationdate <(Select cover_enddate from cc_invoices where id ='$id')";}//echo "<br>".$QUERY."<br>";if (!$nodisplay){ $list_total_charges = $instance_table->SQLExec ($DBHandle, $QUERY); }//end IF nodisplay/*************************************************CHARGES SECTION END ************************************************/// 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){ $list_total_destination = $instance_table->SQLExec ($DBHandle, $QUERY); }//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";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, activated, creationdate"); $info_customer = $instance_table_customer -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, "id", "ASC", null, null, null, null); if($invoice_type == 1) { $QUERY = "Select CASE WHEN max(cover_enddate) is NULL THEN '0001-01-01 01:00:00' ELSE max(cover_enddate) END from cc_invoices WHERE cardid = ".$cardid; } else { $QUERY = "Select cover_enddate, cover_startdate, payment_status from cc_invoices where id ='$id'"; } if (!$nodisplay){ $invoice_data = $instance_table->SQLExec ($DBHandle, $QUERY); if ($invoice_data[0][0] == '0001-01-01 01:00:00') { $invoice_data[0][0] = $info_customer[0][13]; } }//end IF nodisplay}$payment_status_list = array();$payment_status_list["0"] = array( gettext("UNPAID"), "0");$payment_status_list["1"] = array( gettext("SENT-UNPAID"), "1");$payment_status_list["2"] = array( gettext("SENT-PAID"), "2");$payment_status_list["3"] = array( gettext("PAID"), "3");?><?php$smarty->display( 'main.tpl');?><?php $currencies_list = get_currencies();//For DID DIAL & Fixed + Dial$totalcost = 0;if (is_array($list_total_destination) && count($list_total_destination)>0){ $mmax=0; $totalcall=0; $totalminutes=0; foreach ($list_total_destination as $data){ if ($mmax < $data[1]) $mmax=$data[1]; $totalcall+=$data[3]; $totalminutes+=$data[1]; $totalcost+=$data[2]; }}?> <table cellspacing="0" class="invoice_main_table"> <tr> <td class="invoice_heading"><?php echo $invoice_heading; ?></td> </tr> <tr> <td valign="top"><table width="60%" align="left" cellpadding="0" cellspacing="0"> <tr> <td width="35%"> </td> <td width="65%"> </td> </tr> <tr> <td width="35%" class="invoice_td"><?php echo gettext("Name");?> : </td> <td width="65%" class="invoice_td"><?php echo $info_customer[0][3] ." ".$info_customer[0][2] ?></td> </tr> <tr> <td width="35%" class="invoice_td"><?php echo gettext("Card Number");?> :</td> <td width="65%" class="invoice_td"><?php echo $info_customer[0][1] ?> </td> </tr> <?php if ($invoice_type == 1){ ?> <tr> <td width="35%" class="invoice_td"><?php echo gettext("As of Date");?> :</td> <td width="65%" class="invoice_td"><?php echo display_dateonly($invoice_data[0][0]);?> </td> </tr> <?php }else{ ?> <tr> <td width="35%" class="invoice_td"><?php echo gettext("From Date");?> :</td> <td width="65%" class="invoice_td"><?php echo display_dateonly($invoice_data[0][1]);?> </td> </tr> <tr> <td width="35%" class="invoice_td"><?php echo gettext("To Date");?> :</td> <td width="65%" class="invoice_td"><?php echo display_dateonly($invoice_data[0][0]);?> </td> </tr> <tr> <td width="35%" class="invoice_td"><?php echo gettext("Status");?> :</td> <td width="65%" class="invoice_td" valign="middle"> <form method="post" action="A2B_entity_invoice_detail.php?id=<?php echo $id;?>&invoice_type=<?php echo $invoice_type;?>"> <select NAME="payment_status" size="1" class="form_input_select"> <?php foreach($payment_status_list as $data) { ?> <option value='<?php echo $data[1] ?>' <?php if ($invoice_data[0][2]==$data[1]){?>selected<?php } ?>><?php echo $data[0]; ?> </option>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -