<?php
include("../../pidbco/pidbjoin.php");

$domtype = strip_tags(base64_decode($_GET['type']));
$sort = strip_tags(base64_decode($_GET['sort']));
//$start  = strip_tags(base64_decode($_GET['start']));
//$end = strip_tags(base64_decode($_GET['end']));
$today_dat = date('Y/m/d');
?>
<style>
   	@media print {
   thead {display: table-header-group;}
    }
</style>	
<body style="margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:12px;">
  <div id="invoice" style=" height:1010px; margin:0px auto; background-color:#FFFFFF; padding:25px 0px;">
            <div style="  height:1100px; margin:0px auto;">
               <div style="text-align:right;margin-top: -25px;  " >
                <img src="./invoice/images/logo.jpg" alt="logo" />
               </div>
            <div style="text-align:left; margin-top:25px;font-weight:bold; font-size:20px;">
             <?php 
             //$newDate1 = date("d M Y", strtotime($start));
             //$newDate2 = date("d M Y", strtotime($end));
            // echo 'Domain Register of  '.$newDate1.' to '.$newDate2;
             if($sort == 'Active'){
                echo 'Active Domain Register';
			 } else if($sort == 'Deactive'){
			 	echo 'InActive Domain Register';
			 } else if($sort == 'Full'){
			 	echo 'Domain Register';
			 }	 
			   
             ?>
         </div>

         <br />

         <div style="width:100%; height:390px;">

            <table style="width:100%; font-size:11px; border:none; ">
 <thead>
                <tr style="text-align:left; background-color:#CCCCCC;">

                    <th style="width:5%; border:solid 1px #999999;">
                        SlNo. 
                    </th>
                    <th style=" border:solid 1px #999999;">
                        Domain Name
                    </th>
                     <th style="border:solid 1px #999999;">
                        Contact Person
                    </th>
                    <th style="width:10%;border:solid 1px #999999;">
                        Mobile    
                    </th>
                    <th style="width:15%; border:solid 1px #999999;">
                        Email
                    </th>
                    
                      <th style="width:10%; border:solid 1px #999999;">
                        Reg Date
                    </th>
                    
                      <th style="width:10%; border:solid 1px #999999;">
                        Expiry Date
                    </th>
                    
                    <th style="width:10%; border:solid 1px #999999;">
                        Status
                    </th>
                    

                      
                             
                </tr>
     </thead>  
<?php
    if($domtype == 'Active'){
		$dom1 = " `d_renewel`>'$today_dat'";
	} else if($domtype == 'Deactive'){
		$dom1 = " `d_renewel`<'$today_dat'"; 
	} else {
		$dom1 = " 1=1 ";
	}	

    if($sort == 'Expiry'){
		$sort1 = " ORDER BY `d_renewel` DESC ";
	} else if($sort == 'Domain'){
		$sort1 = " ORDER BY `d_domain` DESC ";
	} else if($sort == 'Reg'){
		$sort1 = " ORDER BY `d_regdate` DESC ";	
	} else {
		$sort1 = " ORDER BY `did` DESC ";	
	}


 $sqq = mysqli_query($con, "SELECT * FROM `p_domain` WHERE ".$dom1.$sort1);
 $p=1;
 while($res = mysqli_fetch_array($sqq)){
 	 $dorder = $res['dorder'];
     $dcust = $res['dcust'];
if($sort != 'Expiry'){	 
            $dat  = date('Y/m/d');
           $d_renewel    = $res['d_renewel'];
           $myDateTime = DateTime::createFromFormat('d/m/Y', $d_renewel);
            $d_renewel9 = $myDateTime->format('Y/m/d');
$datetime1 = new DateTime($d_renewel9);
$datetime2 = new DateTime($dat);
$interval = $datetime1->diff($datetime2);
$days_between = $interval->format('%a');

 }
		
	    $sq1 = mysqli_query($con, "SELECT ocustm FROM `p_orders` WHERE `order_id`='$dorder' ");
		$rs1 = mysqli_fetch_array($sq1);
		$ocustm = $rs1['ocustm'];
		$sq2 = mysqli_query($con, "SELECT cname,cmob,cemail FROM `p_customers` WHERE `cidentity`='$dcust' ");
		$rs2 = mysqli_fetch_array($sq2);
		
		
	/*$d_regdate2 = $res['d_regdate'];
	$exp = explode("/",$d_regdate2);
	$yearr =  substr($exp[0], 2, 4);
	$d_regdate = $exp[2].'/'.$exp[1].'/'.$yearr; 
	
    $d_renewel2 = $res['d_renewel'];
	$exp = explode("/",$d_renewel2);
	$yearr2 =  substr($exp[0], 2, 4);
	$d_renewel = $exp[2].'/'.$exp[1].'/'.$yearr2;*/
	
	$dom_amnt = $res['d_amnt'];
	$dom_tax  = $res['d_tax'];
	if($dom_tax != ''){
	$dom_taxamnt = ($dom_amnt * $dom_tax)/100;
	} else { $dom_taxamnt = ''; }
	$tot_domamnt = $dom_amnt + $dom_taxamnt;
 	?>
        <tr style="line-height:20px;">

        <td style="text-align:center; border:solid 1px #999999; border-top:none;">
        <?php echo $p; ?>
        </td>
        <td style="padding-left:5px; border:solid 1px #999999; border-top:none;text-align:center;">
        <?php  echo $res['d_domain']; ?> <br>
      <span style=" background-color:#D3D3D3;">Cost: (<?php  echo $res['d_amnt']; ?>)+ Tax@ <?php if($res['d_tax'] != ''){ echo $res['d_tax']; } else{ echo '0'; } ?>%
      <?php if($dom_taxamnt != ''){ ?> ( <?php echo $dom_taxamnt; ?>) <?php } ?> = <?php echo $tot_domamnt; ?></span> 
        </td>
       <td style="text-align:center; padding-right:5px; border:solid 1px #999999; border-top:none;">
       	<?php echo $rs2['cname']; ?>
       	</td>
        <td style="text-align:center; border:solid 1px #999999; border-top:none;">
        <?php echo $rs2['cmob']; ?>
        </td>
        
        <td style="text-align:center; border:solid 1px #999999; border-top:none;">
        <?php echo $rs2['cemail']; ?>
        </td>
        <td style="text-align:center; border:solid 1px #999999; border-top:none;">
       <?php echo $res['d_regdate']; ?>
        </td>
        <td style="text-align:center; border:solid 1px #999999; border-top:none;">
        <?php echo $res['d_renewel']; ?>
        </td>
        
        <td style="text-align:center; padding-right:5px; border:solid 1px #999999; border-top:none;">
        <?php if($days_between <= 30){ echo "R"; } else if($res['d_renewel'] < $dat){ echo "E"; } else { echo "L"; } ?>
        </td>

    </tr>
    
<?php 
   $p = $p+1; } 
?>
    
 </table>
 <?php
   if($domtype == 'Active'){
		$dom1 = " `d_renewel`>'$today_dat'";
	    $expdom = 0;


		$renewlmonth ='';
	} else if($domtype == 'Deactive'){
		 $dom1 = " `d_renewel`<'$today_dat'"; 
		 $sqq3 = mysqli_query($con, "SELECT COUNT(`did`) AS expdom FROM `p_domain` WHERE ".$dom1);
         $res3 = mysqli_fetch_array($sqq3); 
		 $expdom = $res3['expdom'];
		 $renewlmonth =0;
		 
	} else {
		$dom1 = " 1=1 ";
		$ddat = date('Y/m/d');
		$dom11 = "`d_renewel` < '$ddat'";
		$sqq4 = mysqli_query($con, "SELECT COUNT(`did`) AS expdom FROM `p_domain` WHERE ".$dom11);
        $res4 = mysqli_fetch_array($sqq4); 
		$expdom = $res4['expdom'];	
		$renewlmonth ='';	
	} 
	
 $sqq2 = mysqli_query($con, "SELECT COUNT(`did`) AS totdom FROM `p_domain` WHERE ".$dom1);
 $res2 = mysqli_fetch_array($sqq2);
 
 
/* $dat = date('Y/m/d');	
$d_renewel = $res['d_renewel'];
$datetime1 = new DateTime($d_renewel);
$datetime2 = new DateTime($dat);
$interval = $datetime1->diff($datetime2);
$days_between = $interval->format('%a');  */


	
 ?>
<span style="float:left; margin-top: 10px; font-size: 11px;">Total Domains : <?php echo $res2['totdom']; ?> &nbsp;&nbsp;&nbsp;  Expired : <?php echo $expdom; ?> &nbsp;&nbsp;&nbsp; Renewal this Month : <?php echo $renewlmonth; ?></span>
<span style="float:right; margin-top: 10px; font-size: 11px;">E - Expired &nbsp;&nbsp;&nbsp;  L - Live &nbsp;&nbsp;&nbsp; R - Renewal this Month</span>


</div>

<br />
<br />


</div>

</div>

</body>
