root/experimental_v2/A2BCustomer_UI/A2B_entity_call_details_pdf.php

Revision 566, 27.7 kB (checked in by areski, 1 year ago)

UPDATE : update patch lib

  • Property svn:executable set to *
Line 
1 <?php
2 include ("lib/customer.defines.php");
3 include ("lib/customer.module.access.php");
4 include ("lib/customer.smarty.php");
5
6
7
8 if (!$A2B->config["webcustomerui"]['invoice']) exit();
9
10 if (! has_rights (ACX_ACCESS)){
11     Header ("HTTP/1.0 401 Unauthorized");
12     Header ("Location: PP_error.php?c=accessdenied");       
13     die();
14 }
15
16 getpost_ifset(array('customer', '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', 'srctype', 'src', 'choose_currency','exporttype','terminatecause'));
17
18 $customer = $_SESSION["pr_login"];
19 $vat = $_SESSION["vat"];
20 //require (LANGUAGE_DIR.FILENAME_INVOICES);
21
22 if ($exporttype=="pdf")
23 {   
24     header("Content-Type: application/octet-stream");
25     header("Content-Disposition: attachment; filename=CallDetails_".date("d/m/Y-H:i").'.pdf');
26     //header("Content-Length: ".filesize($dl_full));
27     header("Accept-Ranges: bytes");
28     header("Pragma: no-cache");
29     header("Expires: 0");
30     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
31     header("Content-transfer-encoding: binary");   
32     
33 }
34
35 if (!isset ($current_page) || ($current_page == "")){   
36         $current_page=0;
37     }
38
39 // this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking)
40 $FG_DEBUG = 0;
41
42 // The variable FG_TABLE_NAME define the table name to use
43 $FG_TABLE_NAME="cc_call t1";
44
45 // THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE
46 $FG_TABLE_HEAD_COLOR = "#D1D9E7";
47
48 $FG_TABLE_EXTERN_COLOR = "#7F99CC"; //#CC0033 (Rouge)
49 $FG_TABLE_INTERN_COLOR = "#EDF3FF"; //#FFEAFF (Rose)
50
51 // THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE
52 $FG_TABLE_ALTERNATE_ROW_COLOR[] = "#F2F8FF";
53 $FG_TABLE_ALTERNATE_ROW_COLOR[] = "#FFFFFF";
54
55 $yesno = array();     $yesno["1"]  = array( "Yes", "1");     $yesno["0"]  = array( "No", "0");
56
57 $DBHandle  = DbConnect();
58
59 // The variable Var_col would define the col that we want show in your table
60 // First Name of the column in the html page, second name of the field
61 $FG_TABLE_COL = array();
62
63
64 /*******
65 Calldate Clid Src Dst Dcontext Channel Dstchannel Lastapp Lastdata Duration Billsec Disposition Amaflags Accountcode Uniqueid Serverid
66 *******/
67
68 $FG_TABLE_COL[]=array (gettext("Calldate"), "starttime", "18%", "center", "SORT", "19", "", "", "", "", "", "");
69 $FG_TABLE_COL[]=array (gettext("Source"), "src", "10%", "center", "SORT", "30");
70 $FG_TABLE_COL[]=array (gettext("Callednumber"), "calledstation", "18%", "right", "SORT", "30", "", "", "", "", "", "");
71 $FG_TABLE_COL[]=array (gettext("Destination"), "destination", "18%", "center", "SORT", "30", "", "", "", "", "", "remove_prefix");
72 $FG_TABLE_COL[]=array (gettext("Duration"), "sessiontime", "8%", "center", "SORT", "30", "", "", "", "", "", "display_minute");
73
74 if (!(isset($customer)  &&  ($customer>0)) && !(isset($entercustomer)  &&  ($entercustomer>0))){
75     $FG_TABLE_COL[]=array (gettext("Cardused"), "username", "11%", "center", "SORT", "30");
76 }
77
78 $FG_TABLE_COL[]=array (gettext("Cost"), "sessionbill", "9%", "center", "SORT", "30", "", "", "", "", "", "display_2bill");
79
80 // ??? cardID
81 $FG_TABLE_DEFAULT_ORDER = "t1.starttime";
82 $FG_TABLE_DEFAULT_SENS = "DESC";
83     
84 // This Variable store the argument for the SQL query
85
86 $FG_COL_QUERY='t1.starttime, t1.src, t1.calledstation, t1.destination, t1.sessiontime  ';
87 if (!(isset($customer)  &&  ($customer>0)) && !(isset($entercustomer)  &&  ($entercustomer>0))){
88     $FG_COL_QUERY.=', t1.username';
89 }
90 $FG_COL_QUERY.=', t1.sessionbill';
91 if (LINK_AUDIO_FILE == 'YES')
92     $FG_COL_QUERY .= ', t1.uniqueid';
93
94 $FG_COL_QUERY_GRAPH='t1.callstart, t1.duration';
95
96 // The variable LIMITE_DISPLAY define the limit of record to display by page
97 $FG_LIMITE_DISPLAY=500;
98
99 // Number of column in the html table
100 $FG_NB_TABLE_COL=count($FG_TABLE_COL);
101
102 // The variable $FG_EDITION define if you want process to the edition of the database record
103 $FG_EDITION=true;
104
105 //This variable will store the total number of column
106 $FG_TOTAL_TABLE_COL = $FG_NB_TABLE_COL;
107 if ($FG_DELETION || $FG_EDITION) $FG_TOTAL_TABLE_COL++;
108
109 //This variable define the Title of the HTML table
110 $FG_HTML_TABLE_TITLE=" - Call Logs - ";
111
112 //This variable define the width of the HTML table
113 $FG_HTML_TABLE_WIDTH="70%";
114
115     if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME      -     Col_query : $FG_COL_QUERY";
116     $instance_table = new Table($FG_TABLE_NAME, $FG_COL_QUERY);
117     $instance_table_graph = new Table($FG_TABLE_NAME, $FG_COL_QUERY_GRAPH);
118
119 if ( is_null ($order) || is_null($sens) ){
120     $order = $FG_TABLE_DEFAULT_ORDER;
121     $sens  = $FG_TABLE_DEFAULT_SENS;
122 }
123
124 if ($posted==1){
125  
126   $SQLcmd = '';
127   $SQLcmd = do_field($SQLcmd, 'src', 'src');
128   $SQLcmd = do_field($SQLcmd, 'dst', 'calledstation');
129  
130 }
131 $date_clause='';
132 // Period (Month-Day)
133 if (DB_TYPE == "postgres"){       
134          $UNIX_TIMESTAMP = "";
135 }else{
136         $UNIX_TIMESTAMP = "UNIX_TIMESTAMP";
137 }
138
139 $lastdayofmonth = date("t", strtotime($tostatsmonth.'-01'));
140
141 if ($Period=="Month"){
142         if ($frommonth && isset($fromstatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.starttime) >= $UNIX_TIMESTAMP('$fromstatsmonth-01')";
143         if ($tomonth && isset($tostatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.starttime) <= $UNIX_TIMESTAMP('".$tostatsmonth."-$lastdayofmonth 23:59:59')";
144         
145 }else{
146         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')";
147         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')";
148 }
149  
150 if (strpos($SQLcmd, 'WHERE') > 0) {
151     $FG_TABLE_CLAUSE = substr($SQLcmd,6).$date_clause;
152 }elseif (strpos($date_clause, 'AND') > 0){
153     $FG_TABLE_CLAUSE = substr($date_clause,5);
154 }
155
156
157 if (!isset ($FG_TABLE_CLAUSE) || strlen($FG_TABLE_CLAUSE)==0){
158         
159         $cc_yearmonth = sprintf("%04d-%02d-%02d",date("Y"),date("n"),date("d"));     
160         $FG_TABLE_CLAUSE=" $UNIX_TIMESTAMP(t1.starttime) >= $UNIX_TIMESTAMP('$cc_yearmonth')";
161 }
162
163
164 if (strlen($FG_TABLE_CLAUSE)>0) $FG_TABLE_CLAUSE.=" AND ";
165 $FG_TABLE_CLAUSE.="t1.username='$customer'";
166
167
168 if (!isset($terminatecause)){
169     $terminatecause="ALL";
170 }
171 if ($terminatecause=="ANSWER") {
172     if (strlen($FG_TABLE_CLAUSE)>0) $FG_TABLE_CLAUSE.=" AND ";
173     $FG_TABLE_CLAUSE.=" (t1.terminatecause='ANSWER' OR t1.terminatecause='ANSWERED') ";
174 }
175
176 $FG_TABLE_CLAUSE_NORMAL = $FG_TABLE_CLAUSE ." AND t1.sipiax not in (2,3)";
177
178 if (!$nodisplay){
179     $list = $instance_table -> Get_list ($DBHandle, $FG_TABLE_CLAUSE_NORMAL, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page*$FG_LIMITE_DISPLAY);
180 }
181 $FG_TABLE_CLAUSE_DID = $FG_TABLE_CLAUSE ." AND t1.sipiax in (2,3)";
182 if (!$nodisplay){
183     $list_did = $instance_table -> Get_list ($DBHandle, $FG_TABLE_CLAUSE_DID, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page*$FG_LIMITE_DISPLAY);
184 }
185
186 $_SESSION["pr_sql_export"]="SELECT $FG_COL_QUERY FROM $FG_TABLE_NAME WHERE $FG_TABLE_CLAUSE";
187
188 /************************/
189 $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)
190
191 if (!$nodisplay)
192 {
193     $list_total_day = $instance_table->SQLExec ($DBHandle, $QUERY);   
194     if ($FG_DEBUG == 3) echo "<br>Clause : $FG_TABLE_CLAUSE";
195     $nb_record = $instance_table -> Table_count ($DBHandle, $FG_TABLE_CLAUSE_NORMAL);
196     $nb_record_did = $instance_table -> Table_count ($DBHandle, $FG_TABLE_CLAUSE_DID);
197     if ($FG_DEBUG >= 1) var_dump ($list);
198
199 }//end IF nodisplay
200
201 // GROUP BY DESTINATION FOR THE INVOICE
202 $QUERY = "SELECT destination, sum(t1.sessiontime) AS calltime,
203 sum(t1.sessionbill) AS cost, count(*) as nbcall FROM $FG_TABLE_NAME WHERE ".$FG_TABLE_CLAUSE." GROUP BY destination";
204
205 if (!$nodisplay)
206 {
207     $list_total_destination = $instance_table->SQLExec ($DBHandle, $QUERY);   
208 }//end IF nodisplay
209
210 if ($nb_record<=$FG_LIMITE_DISPLAY){
211     $nb_record_max=1;
212 }else{
213     if ($nb_record % $FG_LIMITE_DISPLAY == 0){
214         $nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY));
215     }else{
216         $nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY)+1);
217     }   
218 }
219 if ($FG_DEBUG == 3) echo "<br>Nb_record : $nb_record";
220 if ($FG_DEBUG == 3) echo "<br>Nb_record_max : $nb_record_max";
221 /*************************************************************/
222 if ((isset($customer)  &&  ($customer>0)) || (isset($entercustomer)  &&  ($entercustomer>0))){
223
224     $FG_TABLE_CLAUSE = "";
225     if (isset($customer)  &&  ($customer>0)){       
226         $FG_TABLE_CLAUSE =" username='$customer' ";
227     }elseif (isset($entercustomer)  &&  ($entercustomer>0)){
228         $FG_TABLE_CLAUSE =" username='$entercustomer' ";
229     }
230     $instance_table_customer = new Table("cc_card", "id,  username, lastname, firstname, address, city, state, country, zipcode, phone, email, fax");
231     $info_customer = $instance_table_customer -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, "id", "ASC", null, null, null, null);
232 }
233 /************************************************************/
234 $date_clause='';
235
236 if ($Period=="Month"){       
237         if ($frommonth && isset($fromstatsmonth)) $date_clause.=" AND $UNIX_TIMESTAMP(t1.creationdate) >= $UNIX_TIMESTAMP('$fromstatsmonth-01')";
238         if ($tomonth && isset($tostatsmonth)) $date_clause.=" AND  $UNIX_TIMESTAMP(t1.creationdate) <= $UNIX_TIMESTAMP('".$tostatsmonth."-$lastdayofmonth 23:59:59')";
239 }else{
240         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')";
241         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')";
242 }
243 $QUERY = "SELECT substring(t1.creationdate,1,10) AS day, sum(t1.amount) AS cost, count(*) as nbcharge FROM cc_charge t1 ".
244          " WHERE id_cc_card='".$_SESSION["card_id"]."' $date_clause GROUP BY substring(t1.creationdate,1,10) ORDER BY day"; //extract(DAY from calldate)
245 if (!$nodisplay){
246     $list_total_day_charge  = $instance_table->SQLExec ($DBHandle, $QUERY);
247 }//end IF nodisplay
248 ?>
249 <?php
250 //$smarty->display( 'main.tpl');
251 if($exporttype == "pdf")
252 {
253     require('pdf-invoices/html2pdf/html2fpdf.php');
254        ob_start();
255 }
256 $currencies_list = get_currencies();
257 ?>
258
259 <!-- %%%%%%%%%%%%%%%%%Call Details Filter Code Here-->
260 <script language="JavaScript" type="text/JavaScript">
261 <!--
262 function MM_openBrWindow(theURL,winName,features) { //v2.0
263   window.open(theURL,winName,features);
264 }
265
266 //-->
267 </script>
268 <br><br>
269
270 <!-- %%%%%%%%%%%%%%%%%Call Details Filter ENDS Here-->
271 <!-- ################# Call Details            -->
272 <?php
273 $currencies_list = get_currencies();
274
275 //calculate calls cost
276 $totalcost = 0;
277 $totalcallmade = 0;
278
279 $totalcost_did = $totalcost;
280 if (is_array($list_total_destination) && count($list_total_destination)>0)
281 {
282     $totalcallmade = $totalcallmade + count($list_total_destination);
283     $mmax=0;
284     $totalcall=0;
285     $totalminutes=0;   
286     foreach ($list_total_destination as $data){   
287         if ($mmax < $data[1]) $mmax=$data[1];
288         $totalcall+=$data[3];
289         $totalminutes+=$data[1];
290         $totalcost+=$data[2];   
291     }   
292 }
293 ?>
294 <table cellpadding="0"  align="center">
295 <tr>
296 <td align="center">
297 <img src="<?php echo Images_Path;?>/asterisk01.jpg" align="middle">
298 </td>
299 </tr>
300 </table>
301 <br>
302 <center>
303   <h4><font color="#FF0000"><?php echo gettext("Call Details for Card Number")?>&nbsp;<?php echo $info_customer[0][1] ?> </font></h4>
304 </center>
305 <br>
306 <br>
307
308 <table  cellspacing="0"  cellpadding="2" width="80%" align="center">
309      
310       <tr>
311         <td  colspan="2"  width="100%" bgcolor="#FFFFCC"><font size="5" color="#FF0000"><?php echo gettext("Calls Details")?></font></td>
312       </tr>
313       <tr>
314               <td width="35%">&nbsp; </td>
315               <td width="65%">&nbsp; </td>
316             </tr>
317             <tr>
318               <td width="35%" ><font color="#003399"><?php echo gettext("Name")?>&nbsp; : </font></td>
319               <td width="65%" ><font color="#003399"><?php echo $info_customer[0][3] ." ".$info_customer[0][2] ?></font></td>
320             </tr>
321             <tr>
322               <td width="35%" ><font color="#003399"><?php echo gettext("Card Number")?>&nbsp; :</font></td>
323               <td width="65%" ><font color="#003399"><?php echo $info_customer[0][1] ?></font> </td>
324             </tr>           
325             <tr>
326               <td width="35%" ><font color="#003399"><?php echo gettext("As of Date")?>&nbsp; :</font></td>
327               <td width="65%" ><font color="#003399"><?php echo display_GMT(date('m-d-Y'), $_SESSION["gmtoffset"], 0);?> </font></td>
328             </tr>
329             <tr>
330               <td colspan="2">&nbsp; </td>
331        </tr>
332     </table>
333             <table width="80%">
334             <tr>
335         <td colspan="7">
336        
337         <table align="center" width="100%">
338         <?php if (is_array($list_total_destination) && count($list_total_destination)>0){?>
339             <tr>
340                 <td colspan="4" align="center"><font> <b><?php echo gettext("By Destination")?></b></font> </td>
341             </tr>
342
343             <tr bgcolor="#CCCCCC">
344               <td  width="29%"><font color="#003399"><b><?php echo gettext("Destination")?> </b></font></td>
345               <td width="38%" ><font color="#003399"><b><?php echo gettext("Duration")?></b></font> </td>
346              
347               <td width="12%" align="center" ><font color="#003399"><b><?php echo gettext("Calls")?> </b></font></td>
348               <td   align="right"><font color="#003399"><b><?php echo gettext("Amount")." (".BASE_CURRENCY.")"; ?> </b></font></td>
349             </tr>
350             <?php         
351                 $i=0;
352                 
353                 foreach ($list_total_destination as $data){   
354                 $i=($i+1)%2;       
355                 $tmc = $data[1]/$data[3];
356                 
357                 if ((!isset($resulttype)) || ($resulttype=="min")){ 
358                     $tmc = sprintf("%02d",intval($tmc/60)).":".sprintf("%02d",intval($tmc%60));       
359                 }else{
360                 
361                     $tmc =intval($tmc);
362                 }
363                 
364                 if ((!isset($resulttype)) || ($resulttype=="min")){ 
365                         $minutes = sprintf("%02d",intval($data[1]/60)).":".sprintf("%02d",intval($data[1]%60));
366                 }else{
367                         $minutes = $data[1];
368                 }
369                 if ($mmax>0)     $widthbar= intval(($data[1]/$mmax)*200);
370         
371             ?>
372             <tr class="invoice_rows">
373               <td width="29%" ><font color="#003399"><?php echo $data[0]?></font></td>
374               <td width="38%" ><font color="#003399"><?php echo $minutes?> </font></td>
375              
376               <td width="12%" align="right" ><font color="#003399"><?php echo $data[3]?></font> </td>
377               <td  align="right" ><font color="#003399"><?php  display_2bill($data[2]) ?></font></td>
378             </tr>
379             <?php      }             
380         
381             if ((!isset($resulttype)) || ($resulttype=="min")){ 
382                 $total_tmc = sprintf("%02d",intval(($totalminutes/$totalcall)/60)).":".sprintf("%02d",intval(($totalminutes/$totalcall)%60));               
383                 $totalminutes = sprintf("%02d",intval($totalminutes/60)).":".sprintf("%02d",intval($totalminutes%60));
384             }else{
385                 $total_tmc = intval($totalminutes/$totalcall);           
386             }
387              ?>   
388              <tr >
389               <td width="29%" >&nbsp;</td>
390               <td width="38%" >&nbsp;</td>             
391               <td width="12%" >&nbsp; </td>
392               <td  >&nbsp; </td>
393              
394             </tr>
395             <tr bgcolor="#CCCCCC">
396               <td width="29%" ><font color="#003399"><?php echo gettext("TOTAL");?> </font></td>
397               <td width="38%" ><font color="#003399"><?php echo $totalminutes?></font></td>             
398               <td width="12%"  align="right"><font color="#003399"><?php echo $totalcall?> </font></td>
399               <td  align="right" ><font color="#003399"><?php  display_2bill($totalcost - $totalcost_did) ?></font> </td>
400             </tr>   
401                      
402             <tr >
403               <td width="29%">&nbsp;</td>
404               <td width="38%">&nbsp;</td>
405              
406               <td width="12%">&nbsp; </td>
407               <td >&nbsp; </td>
408