<?php  
  if(priv($_SESSION['role'],'view','Accounting',$connect)==1){ }else{
exit("You dont have permisiion to access this page ");}
?>
 <div>
    <ul class="breadcrumb">
        <li>
            <a href="index.php">Home</a>
        </li>
        <li>
            <a href="index.php?page=reports"> Add Services</a>
        </li>
    </ul>
</div>

<div class="row">
        <div class="box col-md-12">
            <div class="box-inner">
                <div class="box-header well" data-original-title="">
                    <h2><i class=" glyphicon glyphicon-th-list"></i> Subscribers Reports</h2>

                    <div class="box-icon">
                        <a href="#" class="btn btn-setting btn-round btn-default"><i
                                class="glyphicon glyphicon-cog"></i></a>
                        <a href="#" class="btn btn-minimize btn-round btn-default"><i
                                class="glyphicon glyphicon-chevron-up"></i></a>
                        <a href="#" class="btn btn-close btn-round btn-default"><i
                                class="glyphicon glyphicon-remove"></i></a>
                    </div>
                </div>
                <div class="box-content">
                
                <br />
 
                       
                       
                       
                       
                       
                       
                       
                       
                       
                      
                  <fieldset>
<legend>Search</legend>
                       
                       
                       <form method="post"  class="login_form"  action="index.php?page=acctReport">
<input type="hidden" name="optsearch" value="1" />
 
<div class="form-group">

</div>
 
 



 





<div class="form-group">
<div class="row ">
<div class="col-md-2">from</div>
<div class="col-md-4"><input type="date" name="fromd" id="fromd" class="form-control" placeholder="From Date" value="<?php echo($_REQUEST['fromd']); ?>" /></div>
 
<div class="col-md-2">To</div>
<div class="col-md-4"><input type="date" name="tod" id="tod" class="form-control" placeholder="To Date" value="<?php echo($_REQUEST['tod']); ?>" /></div>
</div>
</div>

 



<div class="form-group">
<div class="row ">

<div class="col-md-12"><input type="submit" name="update_Services" value="Search" class="action-button"  style="width:120px"/></div>
</div>
</div>

</form>
                       
                       
                       
                       
                      
            </fieldset>           
                       
                       
                       
                       
                       
                       
                       
                       
                       
                        <?php if($_REQUEST['optsearch']==1){ 
						
						
						
			 
			 $query_Services=" select count(*) afc,affAPILogs_price,  (count(*) *affAPILogs_price) sumofAff ,     affiliates_name from affAPILogs
 inner join affiliates on affAPILogs_affid=affiliates_id
 where date(affAPILogs_date) between    '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'
 

 
 



" ;
 
    
		 
			 $Services_res=mysqli_query($connect,$query_Services ."  group by  affAPILogs_affid,affAPILogs_price order by affAPILogs_affid desc  ");
			
						
						
					 
						
						?>  
                  <div class="row">
                       <div class="col-md-12">
                     

                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                         
                         
                         
                           <tr>
                             <td>#</td>
                             <td>Affilate</td>
                             <td>Count </td>
                             <td align="center" valign="middle">Price  </td>
                             <td align="center" valign="middle">Sum</td>
                           </tr>
                           <?php  
						   
						
			
			
			 if($Services_res){
				 $x=0;
				 $sumTotalAff=0;
				 while($row=mysqli_fetch_assoc($Services_res))
				 {
				$x++;
			  ?>
						
                           <tr>
                             <td><?php echo($x); ?></td>
                             <td><?php echo($row['affiliates_name']); ?></td>
                          <td><?php echo($row['afc']); ?></td>
                            <td align="center" valign="middle"><?php echo($row['affAPILogs_price']); ?></td>
                            <td align="center" valign="middle"><?php echo(round($row['sumofAff'],2));
							
							$sumTotalAff+=round($row['sumofAff'],2);
							
							 ?></td>
                           </tr>
                         
                           
                           
                           <?php  }}?>
                           
                             <tr>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td align="center" valign="middle"><strong>Total</strong></td>
                             <td align="center" valign="middle"><strong><?php echo($sumTotalAff); ?></strong></td>
                           </tr>
                        
                  </table>
                  <br />


                 
                  </div></div>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  <?php 
				  	
			 
			 $query_Services="
   select count(*) afc,affAPILogs_price,Services_name 
   , (count(*) *affAPILogs_price) sumofAff 
   
   from affAPILogs
   inner join Subscribers on Subscribers_id=affAPILogs_subID
   inner join services on Services_id=Subscribers_serviceID
 inner join affiliates on affAPILogs_affid=affiliates_id
 where date(affAPILogs_date)  
 
 
 between    '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'
 

 
 



" ;
 
    
		 
			 $Services_res=mysqli_query($connect,$query_Services ." group by  affAPILogs_price,Services_id
 order by Services_id asc   ");
			
						
						
				  
				   ?>
                  
                  
                  
                  
                  
                  
                  
                  <div class="row">
                       <div class="col-md-12">
                     

                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                         
                         
                         
                           <tr>
                             <td>#</td>
                             <td>Services</td>
                             <td>Count </td>
                             <td align="center" valign="middle">Price  </td>
                             <td align="center" valign="middle">Sum</td>
                           </tr>
                           <?php  
						   
						
			
			
			 if($Services_res){
				 $x=0;
				  $sumTotalServ=0;
				 while($row=mysqli_fetch_assoc($Services_res))
				 {
				$x++;
			  ?>
						
                           <tr>
                             <td><?php echo($x); ?></td>
                             <td><?php echo($row['Services_name']); ?></td>
                          <td><?php echo($row['afc']); ?></td>
                            <td align="center" valign="middle"><?php echo($row['affAPILogs_price']); ?></td>
                            <td align="center" valign="middle"><?php echo(round($row['sumofAff'],2));
							
							 $sumTotalServ+=round($row['sumofAff'],2);
							
							 ?></td>
                           </tr>
                        
                           
                           
                           <?php  }}?>   
                           <tr>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td align="center" valign="middle"><strong>Total</strong></td>
                             <td align="center" valign="middle"><strong><?php echo( $sumTotalServ); ?></strong></td>
                           </tr>
                        
                  </table>
                  <br />


                 
                  </div></div>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  <div class="row">
                       <div class="col-md-12">
                     

                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                                         
                         
                         
                           <tr>
                             <td>#</td>
                             <td>Service</td>
                             <td>Affilate</td>
                             <td>Count </td>
                             <td align="center" valign="middle">Price  </td>
                             <td align="center" valign="middle">Sum</td>
                           </tr>
                           <?php  
						   
						
			
			 $Services_res=mysqli_query($connect,"select count(*) afc,affiliates_name,Services_name,affAPILogs_price 
			  , (count(*) *affAPILogs_price) sumofAff 
			 
			 from affAPILogs
inner join Subscribers on Subscribers_id=affAPILogs_id
inner join affiliates on affiliates_id=affAPILogs_affid
inner join services on Services_id=Subscribers_serviceID
where date(affAPILogs_date) between  '".$_REQUEST['fromd']."' and '".$_REQUEST['tod']."'
group by 
affiliates_id, Services_id ,affAPILogs_price
order by Services_id asc ,affiliates_id asc");
			
			
			 if($Services_res){
				 $x=0;
				 $sumTotalAff=0;
				 while($row=mysqli_fetch_assoc($Services_res))
				 {
				$x++;
			  ?>
						
                           <tr>
                             <td><?php echo($x); ?></td>
                             <td><?php echo($row['Services_name']); ?></td>
                             <td><?php echo($row['affiliates_name']); ?></td>
                          <td><?php echo($row['afc']); ?></td>
                            <td align="center" valign="middle"><?php echo($row['affAPILogs_price']); ?></td>
                            <td align="center" valign="middle"><?php echo(round($row['sumofAff'],2));
							
							$sumTotalAff+=round($row['sumofAff'],2);
							
							 ?></td>
                           </tr>
                         
                           
                           
                           <?php  }}?>
                           
                             <tr>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td>&nbsp;</td>
                             <td align="center" valign="middle"><strong>Total</strong></td>
                             <td align="center" valign="middle"><strong><?php echo($sumTotalAff); ?></strong></td>
                           </tr>
                        
                  </table>
                  <br />


                 
                  </div></div>
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                   <?php }  ?>
                </div>
            </div>
        </div>