<?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 add_new_receipts(){
             var rcompany = $('#rcompany').val();
             var rbranch = $('#rbranch').val();
             var rcust = $('#rcust').val();
             var recorders = $('#recorders').val();
             var ramnt_type = $('#ramnt_type').val();
             var ramount = $('#ramount').val();
             var rcheque = $('#rcheque').val();
             var rbank = $('#rbank').val();
             var rdate = $('#rdate').val();
             var rremarks = $('#rremarks').val();
              if($("#custsmssent").is(':checked'))
                 var custsmssent =1;
             else
                 var custsmssent =0;
                 
             if(rcompany == ''){
                alert("Select Company");   	
             } else if(rbranch == ''){
             	alert("Select Branch");
             } else if(rcust == ''){
             	alert("Select Customer");
             } else if(recorders == ''){
             	alert("Select Order");
             } else if(ramnt_type == ''){
             	alert("Select Amount Type");
             } else if(ramount == ''){
             	alert("Enter Amount");
             }
             else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          add_new_receipts : 1,
                          rcompany         : rcompany,
                          rbranch          : rbranch,
                          rcust            : rcust,
                          recorders        : recorders,
                          ramnt_type       : ramnt_type,
                          ramount          : ramount,
                          rcheque          : rcheque,
                          rbank            : rbank,
                          rdate            : rdate,
                          rremarks         : rremarks,
                          custsmssent      : custsmssent
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#rcompany').val('');
                     	   	$('#rbranch').val('');
                     	   	$('#rcust').val('');
                           	$('#recorders').val('');
                           	$('#ramnt_type').val('');
                           	$('#ramount').val('');
                           	$('#rcheque').val('');
                           	$('#rbank').val('');
                           	$('#rdate').val('');
                            $('#rremarks').val('');   
                           	$("#marketingdiv123").load("receipts.php #marketingdiv123");   
                            datat2();                    
                      }
                   }); 
    	    } 	
    }


    	
    	
        function edit_news_receipts()
        {
           var rcompany = $('#rcompany').val();
             var rbranch = $('#rbranch').val();
             var rcust = $('#rcust').val();
             var recorders = $('#recorders').val();
             var ramnt_type = $('#ramnt_type').val();
             var ramount = $('#ramount').val();
             var rcheque = $('#rcheque').val();
             var rbank = $('#rbank').val();
             var rdate = $('#rdate').val();
             var rremarks = $('#rremarks').val();
             var hidvall = $('#hidvall').val();
             if(rcompany == ''){
                alert("Select Company");   	
             } else if(rbranch == ''){
             	alert("Select Branch");
             } else if(rcust == ''){
             	alert("Select Customer");
             } else if(recorders == ''){
             	alert("Select Order");
             } else if(ramnt_type == ''){
             	alert("Select Amount Type");
             } else if(ramount == ''){
             	alert("Enter Amount");
             }
             else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          edit_new_receipts : 1,
                          rcompany         : rcompany,
                          rbranch          : rbranch,
                          rcust            : rcust,
                          recorders        : recorders,
                          ramnt_type       : ramnt_type,
                          ramount          : ramount,
                          rcheque          : rcheque,
                          rbank            : rbank,
                          rdate            : rdate,
                          rremarks         : rremarks,
                          hidvall          : hidvall
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#rcompany').val('');
                     	   	$('#rbranch').val('');
                     	   	$('#rcust').val('');
                           	$('#recorders').val('');
                           	$('#ramnt_type').val('');
                           	$('#ramount').val('');
                           	$('#rcheque').val('');
                           	$('#rbank').val('');
                           	$('#rdate').val('');
                            $('#rremarks').val('');   
                           	$("#marketingdiv123").load("receipts.php #marketingdiv123");   
                            datat3();                    
                      }
                   }); 
    	    }        
        }
        
        
    	
    	    	
    	function delete_receipt(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delete_receipt: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			      $("#marketingdiv123").load("receipts.php #marketingdiv123");
			      datat();
         	
			}  
			});
   			}
    	}
    	
    	
    	function edit_receipt(id)
    	{
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_receipt: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			
	         	$("#marketingdiv2").load("receipts.php?idd2="+id+" #marketingdiv2"); 	
			}  
			});
    	}
    	
    	


 function amount_type(amt_typ)
        {
         if(amt_typ == 'Cheque'){
           document.getElementById('cheque_idd').style.display='block';
	     } else {
           document.getElementById('cheque_idd').style.display='none';
         } 
        }
        
        
function cust_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("recorders").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajaxmarket.php?cust_idd="+str,true);
xmlhttp.send();
}

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();
}
    </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> Receipts
          	<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">Receipts</li> 
          </ol>
        </section>
  <!-- Main content -->
        <section class="content" >
          <div class="row" >
            <div class="col-xs-12" >





   <div class="box-body" id="marketingdiv2">
 <?php 
    $idd2='';
    if(!isset($_GET)){
      $idd2 = strip_tags(base64_decode($_GET['idd2']));
    }
	  $sq = mysqli_query($con, "SELECT * FROM `p_receipts` WHERE `rid`='$idd2' " );
	  $rs = mysqli_fetch_assoc($sq);
 
 ?>			  	
	<div class="box-body" >
 <div class="row" >	
<div class="col-md-12" style="" >
	
<div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<select class="form-control" id="rcompany" name="rcompany" onchange="branch_change(this.value);">
	<option value="">Company</option>
	<?php
	$sq2 = mysqli_query($con,"SELECT cid,c_comp FROM `p_company` ");
	while($res2 = mysqli_fetch_array($sq2)){
		if($rs['rcomp'] == $res2['cid']){
	?>	
	<option value="<?php echo $res2['cid']; ?>" selected><?php echo $res2['c_comp']; ?></option>
	<?php } else { ?>
		<option value="<?php echo $res2['cid']; ?>"><?php echo $res2['c_comp']; ?></option>
    <?php } } ?>
	</select>	
</div></div>

<div class="col-md-3" style=" padding-left: 2px; padding-right: 0px; ">					
  <div class="form-group">
	<select class="form-control" id="rbranch" name="rbranch">
		<option value="">Branch</option>
		<?php
		$p_bran = $rs['rbran'];
		$p_comp = $rs['rcomp'];
		$bselect = mysqli_query($con,"SELECT * FROM `p_branch` WHERE `b_comp`='$p_comp' ");
		while($rsult = mysqli_fetch_array($bselect)) { 
		    if($p_bran == $rsult['b_branchna']){ ?>
		  <option value="<?php echo $rsult['b_branchna']; ?>" selected><?php echo $rsult['b_branchna']; ?></option> 	
	     <?php } else { ?>		
		  <option value="<?php echo $rsult['b_branchna']; ?>"><?php echo $rsult['b_branchna']; ?></option>	
		<?php } } ?>
	</select>
 </div></div>
	
 <div class="col-md-3" style=" padding-left: 2px; padding-right: 0px; ">					
  <div class="form-group">
	<select class="form-control" id="rcust" name="rcust" onchange="cust_change(this.value);">
		<option value="">Customer</option>
		<?php 
	$cust = mysqli_query($con, "SELECT * FROM `p_customers` ");
    while($sj= mysqli_fetch_array($cust)){
    	if($rs['rcust'] == $sj['cid']){	
		?>
	<option value="<?php echo $sj['cid']; ?>" selected><?php echo $sj['cname']; ?></option>	
	<?php } else { ?>	
	<option value="<?php echo $sj['cid']; ?>"><?php echo $sj['cname']; ?></option>	
	<?php } } ?>	
	</select>	
 </div></div>	
 
  <div class="col-md-3" style=" padding-left: 2px; padding-right: 0px; ">					
  <div class="form-group">
	<select class="form-control" id="recorders" name="recorders">
		<option value="">Orders</option>
	<?php 
	$rorder = $rs['rorder'];
	$custid = $rs['rcust'];
	$sq2 = mysqli_query($con, "SELECT * FROM `p_orders` WHERE `ocustm` = '$custid' ");
	while($rs2 = mysqli_fetch_array($sq2)){
		if($rs2['order_id'] == $rorder){
	?>	
	<option value="<?php echo $rs2['order_id']; ?>" selected><?php echo $rs2['ordr_type']."-".$rs2['order_id']; ?></option>
	<?php } else { ?>
	<option value="<?php echo $rs2['order_id']; ?>"><?php echo $rs2['ordr_type']."-".$rs2['order_id']; ?></option>
	<?php } } ?>
	</select>
 </div></div>
 

 
  
 	
 	</div>	

</div>	


<div class="row" >	
<div class="col-md-12" style="" >
	
		
<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">			
		
<div class="form-group">
  <select class="form-control" id="ramnt_type" name="ramnt_type" onchange="amount_type(this.value);">
  <option value="">Amount Type</option> 
  <option value="Cash" <?php if($rs['ramnt_type'] == 'Cash'){ ?> selected <?php } ?>>Cash</option>
  <option value="Cheque" <?php if($rs['ramnt_type'] == 'Cheque'){ ?> selected <?php } ?>>Cheque</option>
  </select> 
</div></div>


<div class="col-md-3" style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
    <input name="ramount" id="ramount" onkeypress="return isNumber2(event)" class="form-control" placeholder="Amount" value="<?php echo $rs['ramount']; ?>" >
</div></div>





<div id="cheque_idd" style=" display: none;">
	
		<div class="col-md-3" style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
    <input name="rcheque" id="rcheque" class="form-control" placeholder="Cheque No." value="<?php echo $rs['rcheque']; ?>" >
</div></div>
<div class="col-md-2" style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
    <input name="rbank" id="rbank" class="form-control" placeholder="Bank" value="<?php echo $rs['rbank']; ?>" >
</div></div>
<div class="col-md-2" style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
    <input name="rdate" id="rdate" class="form-control tcal" placeholder="Date" value="<?php echo $rs['rcheq_date']; ?>" >
</div></div>


</div>







<div class="col-md-5" style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
   <textarea name="rremarks" id="rremarks" class="form-control" placeholder="Remarks" style=" height: 35px;"><?php echo $rs['rremarks']; ?></textarea>		
</div></div>

	

<div class="col-md-2" style=" padding-left: 2px; padding-right: 0px; ">				
<div class="form-group">
  <?php if($idd2 != ''){ ?>
	<input type="hidden" name="hidvall" id="hidvall" value="<?php echo $rs['rid']; ?>" />
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Update" onclick="edit_news_receipts();" style=" float: right; 
margin-right: 20px; " /> 

<?php } else { ?>
	<input type="checkbox" name="custsmssent" id="custsmssent" value="sms" >&nbsp; Sent SMS
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" onclick="add_new_receipts();" style=" float: right; 
margin-right: 20px; " />	
<?php } ?> 
</div></div>

</div>




</div>



	
	

</div>
  </div>
  
  
  
  
  
  
<div id="marketingdiv123">


<div class="box" >
   <div class="box-body" >
        <div class="box-body table-responsive no-padding" >
   
  	                 	
                  <table id="example1" class="table table-bordered table-striped" >
                    <thead >
<tr >
<th>#</th>
<th>Receipt No.</th>                                        	
<th>Branch</th>
<th>Customer</th>
<th>Amount Type</th>
<th>Amount</th>
<th>Date</th>
<th></th>
</tr>
                    </thead>
                    <tbody>
<?php 
$sq = mysqli_query($con, "SELECT * FROM `p_receipts` ORDER BY `rid` DESC ");
$k=1;
while($rs = mysqli_fetch_array($sq)){
	
 $rdate = $rs['rdate'];
 $exp = explode("-",$rdate);
 $yearr =  substr($exp[0], 0, 4);
 $rec_dat = $exp[2].'/'.$exp[1].'/'.$yearr; 
 		
 $comid = $rs['rcomp'];	
 $sq1 = mysqli_query($con,"SELECT c_comp FROM `p_company` WHERE `cid`='$comid' ");
 $rs1 = mysqli_fetch_array($sq1);	
 $cusid = $rs['rcust'];
 $sq2 = mysqli_query($con,"SELECT cname FROM `p_customers` WHERE `cid`='$cusid' ");
 $rs2 = mysqli_fetch_array($sq2);
?>
<tr>
<td><?php echo $k; ?></td>
<td><?php echo $rs['ridentity']; ?></td>

<td><?php echo $rs['rbran']; ?></td>
<td><?php echo $rs2['cname']; ?></td>
<td><?php echo $rs['ramnt_type']; ?></td>
<td><?php echo $rs['ramount']; ?></td>
<td><?php echo $rec_dat; ?></td>
<td>
	&nbsp;&nbsp;  <a href="invoice/receipt_print.php?receipts=<?php echo base64_encode($rs['rid']); ?>" style=" cursor: pointer;" target="_blank"><span class="fa fa-print" style="font-size:14px;"></span></a>
&nbsp;&nbsp;  <a href="" data-toggle="modal" data-target="#myModal<?php echo $rs['rid']; ?>" style=" cursor: pointer;"><span class="glyphicon glyphicon-eye-open" style="font-size:14px;"></span></a> &nbsp; &nbsp;                	
    <a onClick="edit_receipt('<?php echo base64_encode($rs['rid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp; &nbsp;
    <a onClick="delete_receipt('<?php echo base64_encode($rs['rid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;	
</td>	
</tr>

<div class="modal fade" id="myModal<?php echo $rs['rid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style=" background-color: #E8E8E8;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Receipt #<?php echo $rs['rid']; ?></h4>
      </div>
   <div class="modal-body" id="myModal2">
  
   <div style=" width:550px; ">
   <div style=" float:left; width:150px;  font-size:14px; color:#0000FF; ">Company Name</div><div style="width:375px; ">: &nbsp;&nbsp; <?php echo $rs1['c_comp']; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Branch Name</div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["rbran"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Customer </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs2['cname']; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Order No.</div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["rorder"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Amount Type </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["ramnt_type"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Amount </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["ramount"]; ?></div>
   <?php if($rs["rcheque"] != ''){ ?>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Cheque No.</div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["rcheque"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Bank </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["rbank"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Date </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["rcheq_date"]; ?></div>
   <?php } ?>  
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Remarks </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $rs["rremarks"]; ?></div>
   </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
       
      </div>
    </div>
  </div>
</div>
<?php $k=$k+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>
