<?php
include("../../pidbco_ems/pidbjoin.php");
include("../../pidbco_ems/function.php");
if(!isset($_SESSION))
{
    session_start();
}
if(!isset($_SESSION['karyasthan']))
{
    echo '<script type="text/javascript"> alert("You need to Login Now..!"); window.location.href="Ems_Login";</script>';
}
$comp_id = $_SESSION['pro_comp_reg_id'];
$qry_comp_dt = mysql_query("SELECT id,es_database,end_date FROM $main_dbb.esoft_company_det WHERE id='$comp_id' ");
$qry_comp_dt_fet = mysql_fetch_array($qry_comp_dt);
$my_sel_db = $qry_comp_dt_fet['es_database'];
$today = date('Y-m-d ');
$end = $qry_comp_dt_fet['end_date'];
$exp_date = strtotime($end);

$start_date = base64_decode($_GET['start_date']);
$end_date = base64_decode($_GET['end_date']);
if(!empty($_GET['select_branch']))
{
    $select_branch = base64_decode($_GET['select_branch']);
    $qry_br=mysql_query("select branch_name,id from $main_dbb.esoft_branch_det where id='$select_branch'");
    $qry_br_fet=mysql_fetch_array($qry_br);
}
?>
<html>
<title>Daily Income Branch Wise</title>
<head>
    <link type="text/css" href="css/pdfstyle.css" rel="stylesheet">
    <link type="text/css" href="css/reset.css" rel="stylesheet">
</head>
<body onload="window.print();">
<div class="container" >
    <br>
    <div  style="width: 100%;text-align: center;"><img src="img_pdf/order_report.jpg" /><br>
    </div>
    <br><br>
    <?php
    if(!empty($start_date))
    {
        list($year,$month,$day) = explode('-', $start_date);
        ?>
        <p style="font-size: 16px;font-weight: bold;text-transform: uppercase;">FROM &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp;<?php echo $day.'-'.$month.'-'.$year; ?></p>
    <?php
    }
    if(!empty($end_date))
    {
        list($year,$month,$day) = explode('-', $end_date);
        ?><br>
        <p style="font-size: 16px;font-weight: bold;text-transform: uppercase;">TO  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp;<?php echo $day.'-'.$month.'-'.$year; ?></p>
    <?php
    }
    if(!empty($_GET['select_branch']))
    {
    	$select_branch = base64_decode($_GET['select_branch']);
        ?><br>
        <p style="font-size: 16px;font-weight: bold;text-transform: uppercase;">BRANCH &nbsp;&nbsp; :&nbsp;<?php if($select_branch == 'All'){ echo "All"; } else { echo $qry_br_fet['branch_name']; } ?></p>
    <?php
    }
    ?>
    <br>
    <!-- Heads -->
    <div style="height: 25px;border: 2px solid #000000;width: 100px;float: left;border-right: 0px solid #000000;"><p style="text-align: center;font-weight: bolder;">Date </p></div>
    
     <div style="height: 25px;border: 2px solid #000000;width: 150px;float: left;border-right: 0px solid #000000;"><p style="text-align: center;font-weight: bolder;">Customer</p></div>
    <div style="height: 25px;border: 2px solid #000000;width: 120px;float: left;border-right: 0px solid #000000;"><p style="text-align: center;font-weight: bolder;font-size: 14px;">Order No.</p></div>
    <div style="height: 25px;border: 2px solid #000000;width: 305px;float: left;border-right: 0px solid #000000;"><p style="text-align: center;font-weight: bolder;">Function</p></div>
    <div style="height: 25px;border: 2px solid #000000;width: 193px;float: left;border-right: 0px solid #000000;"><p style="text-align: center;font-weight: bolder;">Function Date</p></div>
    <div style="height: 25px;border: 2px solid #000000;width: 100px;float: left;border-right: 2px solid #000000;"><p style="text-align: center;font-weight: bolder;">Amount</p></div>
    <!--<div style="height: 25px;border: 2px solid #000000;width: 85px;float: left;border-right: 2px solid #000000;"><p style="text-align: center;font-weight: bolder;">Status</p></div> -->
    
    <!-- Heads End -->
    <!-- CONTENTS LIST -->
    <div>
    
   <?php
          $select_branch = base64_decode($_GET['select_branch']);
          if(!empty($_GET['select_branch']) && ($select_branch != 'All'))
            {
                $select_branch = base64_decode($_GET['select_branch']);
                $qry_25 = mysql_query("select * from $my_sel_db.`order_details` WHERE branch_id ='$select_branch' AND `fun_from_date` >= '$start_date' AND `fun_to_date`<='$end_date' ");

            }
            else
            {
              $qry_25 = mysql_query("select * from $my_sel_db.`order_details` WHERE `fun_from_date` >= '$start_date' AND `fun_to_date`<='$end_date'");
            }
            $qry_25_num=mysql_num_rows($qry_25);
            if($qry_25_num > 0)
            {
                while($qry13_fet=mysql_fetch_array($qry_25))
                {
                	
				 $gr_tot51 += $qry13_fet['rate'];
				 	
      $c_id = $qry13_fet['cust_id'];
      $qry_555 = mysql_query("SELECT id,cust_name FROM $my_sel_db.`customer_det` WHERE id='$c_id'");
      $qry_555_fet = mysql_fetch_array($qry_555);
	  
	  $br_id = $qry13_fet['branch_id'];
	  $qry22=mysql_query("SELECT branch_name FROM $main_dbb.`esoft_branch_det` WHERE `id`='$br_id' ");
	  $res22=mysql_fetch_array($qry22);
	  	
	  $functid=$qry13_fet['category_id'];
	  $sq2=mysql_query("SELECT event_name FROM `evnt_category_tb` WHERE `evnt_id`='$functid' ");
	  $rs2=mysql_fetch_array($sq2);
	  
	  $ststatus=$qry13_fet['order_status'];
	  if($ststatus == 1){
	  	$st="Open";
	  } else {
	  	$st="Closed";
	  }
	  
	  $funct_date=$qry13_fet['fun_from_date'].'&nbsp;'.'To'.'&nbsp;'.$qry13_fet['fun_to_date'];
	  $arrEventSeatArrangement[] = array(	"date"	    => $qry13_fet['order_date'],
									"branch" 	=> $res22['branch_name'],
									"custm" 	=> $qry_555_fet['cust_name'],
									"ordrno" 	=> $qry13_fet['order_no'],
									"functn" 	=> $rs2['event_name'],
									"functndate" 	    => $funct_date,
									"amt" 	    => $qry13_fet['rate'],
									"status" 	    => $st
								   );	

	   }

	
 $lastChar = '';
sort($arrEventSeatArrangement, SORT_NATURAL | SORT_NUMERIC); 													
if(is_array($arrEventSeatArrangement) && count($arrEventSeatArrangement)>0){
foreach($arrEventSeatArrangement as $seatArrangement){
?>
    <div style="height: 18px;width: 100px;float: left;border-bottom: 2px solid #000000;border-left: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['date']; ?></p></div>             
    <div style="height: 18px;width: 150px;float: left;border-left: 2px solid #000000;border-bottom: 2px solid #000000;border-right: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['custm']; ?></p></div>
    <div style="height: 18px;width: 120px;float: left;border-bottom: 2px solid #000000;border-right: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['ordrno']; ?></p></div>
    <div style="height: 18px;width: 305px;float: left;border-bottom: 2px solid #000000;border-right: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['functn']; ?></p></div>
    <div style="height: 18px;width: 193px;float: left;border-bottom: 2px solid #000000;border-right: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['functndate']; ?></p></div>
    <div style="height: 18px;width: 100px;float: left;border-bottom: 2px solid #000000;border-right: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['amt']; ?></p></div>
    <!--<div style="height: 18px;width: 85px;float: left;border-bottom: 2px solid #000000;border-right: 2px solid #000000;overflow: hidden;"><p style="margin-left: 5px;font-size: 11px;font-weight: bold;text-align: center;"><?php echo $seatArrangement['status']; ?></p></div> -->
    
   <?php
   } }             
           
           }
        ?>
    </div>
<!-- TOTAL, DUE , BALANCE --->
<div style="width: 997px;height: 32px;">
    <?php
   /* if(!empty($_GET['select_branch']))
    {
    $select_branch = base64_decode($_GET['select_branch']);
    }
    if(!empty($select_branch) && empty($start_date) && !empty($end_date))
    {
        $qry155 = mysql_query("SELECT SUM(rate) as gt from $my_sel_db.`order_details` where branch_id='$select_branch' AND fun_to_date ='$end_date'");
    }
    if(!empty($select_branch) && !empty($start_date) && empty($end_date))
    {
        $qry155 = mysql_query("SELECT SUM(rate) as gt from $my_sel_db.`order_details` where branch_id='$select_branch' AND fun_from_date ='$start_date'");
    }
    if(!empty($select_branch) && !empty($start_date) && !empty($end_date))
    {
        $qry155 = mysql_query("SELECT SUM(rate) as gt from $my_sel_db.`order_details` where branch_id='$select_branch' AND `fun_from_date` >= '$start_date' AND `fun_to_date`<='$end_date'");
    }
   
                $qry342_fet = mysql_fetch_array($qry155);
                    $gr_tot51 += $qry342_fet['gt'];
					
   */
           
        $gr_total += $gr_tot51;
    ?>
    <p style="text-align: right;font-weight: bold;line-height: 30px; margin-right: 25px;">Total Credit&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo number_format((float)$gr_total, 2, '.', '').'/-'; ?> </p> 
   
   
   
    <?php
 /* if(!empty($select_branch) && empty($start_date) && !empty($end_date))
    {
        $qry142 = mysql_query("SELECT * FROM $my_sel_db.`receipt_det` WHERE amt_type='cheque' AND branch_id = '$select_branch' AND receipt_date = '$end_date'");
    }
    if(!empty($select_branch) && !empty($start_date) && empty($end_date))
    {
        $qry142 = mysql_query("SELECT * FROM $my_sel_db.`receipt_det` WHERE amt_type='cheque' AND branch_id = '$select_branch' AND receipt_date = '$start_date'");
    }
    if(!empty($select_branch) && !empty($start_date) && !empty($end_date))
    {
        $qry142 = mysql_query("SELECT * FROM $my_sel_db.`receipt_det` WHERE amt_type='cheque' AND branch_id = '$select_branch' AND receipt_date BETWEEN '$start_date' AND '$end_date'");
    }
    $grand_tot51 = 0;
    $qry142_num = mysql_num_rows($qry142);
    if($qry142_num > 0)
    {
        while($qry142_fet = mysql_fetch_array($qry142))
        {
            $grand_tot51 += $qry142_fet['amount'];
        }
    }  */

    ?>
   <!--  <p style="text-align: right;font-weight: bold;line-height: 30px;padding-left: 40px;">Total Debit&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo number_format((float)$grand_tot51, 2, '.', '').' Rs'; ?></p> -->
</div>
<div style="width: 997px;height: 32px;float: right;">
    <?php
   /* $bal1 = 0;
    $due1 = 0;
    if($grand_tot51 > $gr_total)
    {
        $bal1 = ($grand_tot51 - $gr_total);
    }
    elseif($gr_total > $grand_tot51)
    {
        $due1 = ($gr_total - $grand_tot51);
    }
    else
    {
        $bal1 = 0;
        $due1 = 0;
    } */
    ?>
    <!-- <p style="font-weight: bold;">Balance &nbsp;:&nbsp;&nbsp;&nbsp;<?php echo number_format((float)$bal1, 2, '.', ''); ?></p>
    <p style="font-weight: bold;">Due &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;<?php echo number_format((float)$due1, 2, '.', ''); ?></p> -->
</div>
<!-- END -->
</div>
</div>
</body>
</html>
