<?php 
session_start();
ob_start();
include("../../pidbco/pidbjoin.php");
$sujpath="./";
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Projects</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" type="text/css" href="tcal.css" />    
    <script type="text/javascript" src="tcal.js"></script>
    
  <script>
    function branch_change(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("rbranch").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajaxmarket.php?comp_idd="+str,true);
xmlhttp.send();
}



        function leadger_report()
    	{
		  var srchcomp = $('#srchcomp').val();
		  var rbranch = $('#rbranch').val();
		  var purvendor = $('#purvendor').val();
		  var salestart = $('#salestart').val();
		  var saleend = $('#saleend').val();
		  
		  if(srchcomp == ''){
		     alert("Select Company");
		  } else if(salestart == ''){
		     alert("Enter Start Date");
		  } else if(saleend == ''){
		     alert("Enter End Date ");
		  } else {
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1
			},
			cache: true,
			success: function(res)
			{
			 	//$("#example1").load("cash_book.php?comp="+srchcomp+"&bran="+rbranch+"&start="+salestart+"&end="+saleend+" #example1");
				//$("#purchase_reg_print").load("cash_book.php?comp="+srchcomp+"&bran="+rbranch+"&start="+salestart+"&end="+saleend+" #purchase_reg_print");
				  window.location.href="cash_book.php?comp="+srchcomp+"&bran="+rbranch+"&start="+salestart+"&end="+saleend; 	 	
					
			}  
			});
			}
    	 }  
  </script>
    
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
     <div class="wrapper">
  <?php include("head.php");
    include("left.php"); ?> 
	 
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper" >
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1 style=" font-size: 22px;"> Cash Book
          	<small>- Control panel</small>
          	</h1>
          <ol class="breadcrumb">
            <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Cash Book</li> 
          </ol>
        </section>
  <!-- Main content -->
        <section class="content" >
          <div class="row" >
            <div class="col-xs-12" >


  
  <div class="row" style=" margin-top: 20px;">	
<div class="col-md-12" style="" >
	
<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<select name="srchcomp" id="srchcomp" class="form-control" onChange="branch_change(this.value);">
		<option value="" selected="selected">Company</option>	
<?php
$comp= mysqli_query($con,"SELECT * FROM `p_company` ");
while($res=mysqli_fetch_array($comp)){
?>			
<option value="<?php echo $res['cid']; ?>"><?php echo $res['c_prefex']; ?></option>
<?php } ?>
	</select>	
</div></div>

<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<select name="rbranch" id="rbranch" class="form-control">
		<option value="" selected="selected">Branch</option>		
	</select>	
</div></div>



<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<input type="text" name="salestart" id="salestart" class="form-control tcal" placeholder="Start Date"/>
</div></div>

<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<input type="text" name="saleend" id="saleend" class="form-control tcal" placeholder="End Date"/>
</div></div>

<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" onClick="leadger_report();" style=" float: left; margin-left: 10px; " />	
</div></div>

</div></div>

  
  
<div id="marketingdiv123" >


<div class="box" >
   <div class="box-body" >
        <div class="box-body table-responsive no-padding" >
         
  	   <div style=" float: right;" id="purchase_reg_print">
	  <?php
    if(empty($_GET)){
      $comp   = '';
      $bran   = '';
      $start  = '';
      $end    = '';
      }else{
      $comp   = strip_tags($_GET['comp']);
      $bran   = strip_tags($_GET['bran']);
      $start  = strip_tags($_GET['start']);
      $end    = strip_tags($_GET['end']);
    }     
	?>
	  <a href="cashbook_print.php?company=<?php echo base64_encode($comp); ?>&branch=<?php echo base64_encode($bran); ?>&start=<?php echo base64_encode($start); ?>&end=<?php echo base64_encode($end); ?>" target="_blank"><span class="fa fa-print" style="font-size:14px;"></span> Print</a></div>              	
                  <table id="example1" class="table table-bordered table-striped" >
                    <thead >
                    <tr >
<th>#</th>                    	
<th>Rec/Vou No.</th>
<th>Date</th>
<th>Customer</th>
<th>Order Type</th>
<th>Deposit</th>
<th>Withdraw</th>
</tr>
                    </thead>
                    <tbody>


<?php
if(empty($_GET)){
      $comp   = '';
      $bran   = '';
      $start  = '';
      $end    = '';
      }else{
      $comp   = strip_tags($_GET['comp']);
      $bran   = strip_tags($_GET['bran']);
      $start  = strip_tags($_GET['start']);
      $end    = strip_tags($_GET['end']);
    }


$datetime1 = new DateTime($start);
$datetime2 = new DateTime($end);
$interval = $datetime1->diff($datetime2);
$days_between = $interval->format('%a');
for($j=0;$j<=$days_between;$j++){
$s11=1;
$s22=1;
$s33=1;
$p=1;
if($comp != ''){ 
$s1 = " AND `rcomp`='$comp'";
}

if($bran !=''){
 $s2 = " AND `rbran`='$bran'";
} 
 
if($start != '' && $end != ''){
 $s3 = " AND `rdate` = '$start' ";
}

 
 if($comp != ''){
 
 $sqq = mysqli_query($con, "SELECT * FROM `p_receipts` WHERE `ramnt_type`='Cash' ".$s1.$s2.$s3);

 while($res = mysqli_fetch_array($sqq)){
  
 $cusid = $res['rcust'];
 $sq2 = mysqli_query($con,"SELECT cname FROM `p_customers` WHERE `cid`='$cusid' ");
 $rs2 = mysqli_fetch_array($sq2);
 $rorder = $res['rorder'];
 $sq1 = mysqli_query($con,"SELECT ordr_type FROM `p_orders` WHERE `oid`='$rorder' ");
 $rs1 = mysqli_fetch_array($sq1);
?>
<tr>
	<td><?php echo $p; ?></td>
	<td><?php echo $res['ridentity']; ?></td>
	<td><?php echo $res['rdate']; ?></td>
	<td><?php echo $rs2['cname']; ?></td>
	<td><?php echo $rs1['ordr_type']; ?></td>
	<td><?php echo $res['ramount']; ?></td>
	<td>-</td>
</tr>



<?php $p=$p+1; } } 


if($comp != ''){ 
$s11 = " `vcomp`='$comp'";
}
if($bran !=''){
 $s22 = " AND `vbranch`='$bran'";
} 
if($start != '' && $end != ''){
 $s33 = " AND `vdate`='$start' ";
}

$sqq2 = mysqli_query($con, "SELECT * FROM `p_voucher` WHERE `vamnt_type`='Cash' AND ".$s11.$s22.$s33);
$rowcount2=mysqli_num_rows($sqq2);
while($res22 = mysqli_fetch_array($sqq2)){
	$vaccnt_head1 =$res22['vaccnt_head1']; 	
	$ss1 = mysqli_query($con, "SELECT ma_cat FROM `p_accnt_head` WHERE `mid`='$vaccnt_head1'");
	$rr1 = mysqli_fetch_array($ss1);
	$ma_cat = $rr1['ma_cat']; 
		
	$vaccnt_head2 =$res22['vaccnt_head2'];	
	$ss2 = mysqli_query($con, "SELECT sub_cat FROM `p_sub_head` WHERE `sid`='$vaccnt_head2'");
	$rr2 = mysqli_fetch_array($ss2);
	$sub_cat = $rr2['sub_cat']; 
	 ?>

<tr>
	<td><?php echo $p; ?></td>
	<td><?php echo $res22['videntity']; ?></td>
	<td><?php echo $res22['vdate']; ?></td>
	<td>
	<?php 
    $vvendr = $res22['vvendr'];
    $sq2 = mysqli_query($con,"SELECT v_company	FROM `p_vendor` WHERE `vid`='$vvendr' ");
    $rs2 = mysqli_fetch_array($sq2);
    echo $rs2['v_company'];
    ?>	
	</td>
	<td><?php echo $ma_cat.'&nbsp;'.'-'.'&nbsp;'.$sub_cat; ?></td>
	<td>-</td>
	<td><?php echo $res22['vamnt']; ?></td>
</tr>

<?php 
$p=$p+1;  }
$start = date('Y/m/d', strtotime($start. ' + 1 days'));
 }
?>

                    </tbody>
                    </table>
  
         		  </div>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
	
	
</div>
	
		
			
			
			








                           
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
  </div><!-- /.content-wrapper -->
  </div>
    <!-- jQuery 2.1.4 -->
    <script src="<?php echo $sujpath; ?>plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="<?php echo $sujpath; ?>bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
	<script src="<?php echo $sujpath; ?>plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="<?php echo $sujpath; ?>plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="<?php echo $sujpath; ?>plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="<?php echo $sujpath; ?>dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="<?php echo $sujpath; ?>dist/js/demo.js"></script>
    <!-- page script -->
    
  <script type="text/javascript">
    function PreviewImage(no) {
    	var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById("uploadImage"+no).files[0]);
        oFReader.onload = function (oFREvent) {
            document.getElementById("uploadPreview"+no).src = oFREvent.target.result;
        };
    }
</script>

<style>
label.filebutton {
    width:120px;
    height:80px;
    overflow:hidden;
    position:relative;
}
label span input {
    z-index: 999;
    line-height: 0;
    font-size: 50px;
    position: absolute;
    top: -2px;
    left: -700px;
    opacity: 0;
    filter: alpha(opacity = 0);
    -ms-filter: "alpha(opacity=0)";
    cursor: pointer;
    _cursor: hand;
    margin: 0;
    padding:0;
}
</style>



    <script>
      $(document).ready(function() {
        $("#example1").DataTable();
      });
      
	function datat(){
	  alert("Data Deleted Successfully.");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat2(){
	  alert("Data Added Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat3(){
	  alert("Updated Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
   </script>  
  </body>
</html>