<?php 
session_start();
ob_start();
error_reporting(0);
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("ledger.php?comp="+srchcomp+"&bran="+rbranch+"&start="+salestart+"&end="+saleend+" #example1");
			 //	$("#purchase_reg_print").load("ledger.php?comp="+srchcomp+"&bran="+rbranch+"&start="+salestart+"&end="+saleend+" #purchase_reg_print");
			 window.location.href="ledger.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;"> Ledger
          	<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">Ledger</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
    $comp = strip_tags($_GET['comp']);
    $bran = strip_tags($_GET['bran']);
    $start  = strip_tags($_GET['start']);
    $end = strip_tags($_GET['end']);     
	?>
	  <a href="ledger_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>Receipt No.</th>
<th>Date</th>
<th>Customer</th>
<th>Order Type</th>
<th>Amount Type</th>
<th>Amount</th>
</tr>
                    </thead>
                    <tbody>


<?php
$comp = strip_tags($_GET['comp']);
$bran = strip_tags($_GET['bran']);
$start  = strip_tags($_GET['start']);
$end = strip_tags($_GET['end']);

if($comp != ''){ 
$s1 = "`rcomp`='$comp'";
}

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

 
 if($comp != ''){
 
 $sqq = mysqli_query($con, "SELECT * FROM `p_receipts` WHERE ".$s1.$s2.$s3);
 $p=1;
 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['ramnt_type']; ?></td>
	<td><?php echo $res['ramount']; ?></td>
</tr>



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



                    </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>
