<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder">
  <tr>
    <td class="mainTableTitle">

      <span>&nbsp;&nbsp;&raquo;</span> Wholesale P/L Summary

    </td>
  </tr>


 <tr>
    <td>

 <!-- Clinets List -->

 <table class="gbTable">

   <tr class="header">
     <td width="2%"><div align="left" style="padding-left:5px;">NR</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Date</div></td>
     <td width="17%"><div align="left" style="padding-left:5px;">Carrier</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Prefix</div></td>
     <td width="17%"><div align="left" style="padding-left:5px;">Gateway</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Calls</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Duration</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">Org Cost</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">Ter Cost</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">P/L</div></td>

   </tr>



<?
$i=1;
$totalNumberCall = 0;
$totalDuration  = 0;
$totalOrgCost = 0;
$totalTerCost = 0;
$totalProfitCost = 0;

if(is_array($callList))
{
foreach($callList as $row)
{
$passid =$i;


$totalNumberCall = $totalNumberCall + $row->totalCall;
$totalDuration = $totalDuration + $row->callDuration;

$acd = round($row->callDuration/$row->totalCall,0);

$gatewayName = $this->generallib->getTrunkName($row->id_trunk);
//$ = $this->geberallib->getTrunkName($row->id_trunk);
$orgCost = ($row->callDuration*$row->call_rate)/60;
$orgCost = number_format($orgCost, 4, '.', '');

$terCost = ($row->callDuration*$row->trunk_rate)/60;
$terCost = number_format($terCost, 4, '.', '');

$profit = $orgCost - $terCost;
$profit = number_format($profit, 4, '.', '');

$totalOrgCost = $totalOrgCost + $orgCost;
$totalTerCost = $totalTerCost + $terCost;
$totalProfitCost = $totalProfitCost + $profit;


?>

      <?

	  		if($i%2==0)
	  		 {

	  		 $str = "
	  		 		 <TR id = \"$passid\" class=\"row2 \"
	  		 		               onmousedown=\"rowPointer(this, 'down', 'row2', 'rowSel', 'rowMark')\"
	  		 		               onmouseover=\"rowPointer(this, 'over', 'row2', 'rowSel', 'rowMark')\"
	  		               onmouseout=\"rowPointer(this, 'out', 'row2', 'rowSel', 'rowMark')\">";


	  		 }
	  		else
	  		 {
	  			$str = "
	  					 <TR id = \"$passid\" class=\"row1 \"
	  					               onmousedown=\"rowPointer(this, 'down', 'row1', 'rowSel', 'rowMark')\"
	  					               onmouseover=\"rowPointer(this, 'over', 'row1', 'rowSel', 'rowMark')\"
	  		               onmouseout=\"rowPointer(this, 'out', 'row1', 'rowSel', 'rowMark')\">";
	  		 }



	  echo $str;

	  ?>


 <td align=center class="tableBorderAll" style="padding-left:0px;padding-top:2px;padding-bottom:2px;"><input name="checkActive" type="checkbox"  id="checkActive" value="1" /></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->callDay?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->login?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->tariff_prefix?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$gatewayName?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->totalCall?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$this->generallib->sec_to_time($row->callDuration)?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$orgCost?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$terCost?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$profit?></td>

   </tr>

<?
$i++;
}

}

?>


 </table>

<!-- End Clients List -->

    </td>
  </tr>

  <tr>
    <td align="center" style="padding-top:5px;">

    <input type="hidden" name="callStart" id="callStart" value="<?=$callStart?>" />
    <input type="hidden" name="callEnd" id="callEnd" value="<?=$callEnd?>" />
    <input type="hidden" name="idTrunk" id="idTrunk" value="<?=$idTrunk?>" />
	<input type="hidden" name="limit" id="limit" value="" />
	<input type="hidden" name="startoffset" id="startoffset" value="" />
	<input type="hidden" name="calledPrefix" id="calledPrefix" value="<?=$calledPrefix?>" />



    </td>
  </tr>

  <tr>
    <td align="center" style="padding-top:0px;">

<table width="50%" border="0" cellspacing="0" cellpadding="0" class="tableBorder">
  <tr>
    <td colspan="2" class="mainTableTitle"><span>&nbsp;&nbsp;&raquo;</span> Total P/L Summary</td>
  </tr>

 <tr>
	<td class='formLabelRigit' width="50%" style='padding-top:10px;'> Number of Calls :  </td>
	<td class='formLabelLeft' width="50%" style='padding-top:10px;'> <?=$totalNumberCall?>	</td>
</tr>

<tr>
	<td class='formLabelRigit'>  Total Call Duration :  </td>
	<td class='formLabelLeft'><?=$this->generallib->sec_to_time($totalDuration)?>	</td>
</tr>

<tr>
	<td class='formLabelRigit'>  Total Org Cost :  </td>
	<td class='formLabelLeft'><?=number_format($totalOrgCost, 4, '.', '');?>	</td>
</tr>

<tr>
	<td class='formLabelRigit'>  Total Ter Cost :  </td>
	<td class='formLabelLeft'><?=number_format($totalTerCost, 4, '.', '');?>	</td>
</tr>

<tr>
	<td class='formLabelRigit'>  Total Profit :  </td>
	<td class='formLabelLeft'><?=number_format($totalProfitCost, 4, '.', '');?>	</td>
</tr>


</table>


    </td>
  </tr>


</table>