<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
  
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='bank';
$menuh='Bank';
$phead='bnkchq';
$page='Cheque Management';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>

<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
<div class="row">
    <div class="col-md-10">
        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">Cheque Received</h3>
            </div>
            <div class="box-body">
                    <?php echo display_msg();?>    
                    <div class="col-md-12 table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice/Receipt</th>
                                        <th>Cheque No</th>
                                        <th>Cheque Date</th>
                                        <th>Amount</th>
                                        <th>A/C No</th>
                                        <th>Status</th>
                                        <th>Client</th>    
                                        <th>Cheque Bank</th>  
                                        <th>Note</th>     
                                        <th style="width:40px; text-align:center;">Action</th>    
                                    </tr>
                                </thead>    
                                <tbody>
                                    <?php
                                    $sql="SELECT * FROM tbl_cheqman where brid='$brid' AND paymod='REC' order by apdate desc";    
                                    $query=mysqli_query($con,$sql)or die(mysqli_error($con));
                                    while ($row=mysqli_fetch_array($query)){

                                        $acid=$row['acid'];
                                        $sql="SELECT tbl_bacount.id,CONCAT(tbl_bank.sort,' - ',tbl_bacount.acno) AS name FROM tbl_bacount LEFT JOIN tbl_bank ON tbl_bank.id=tbl_bacount.bid WHERE tbl_bacount.id='$acid' ORDER BY tbl_bank.sort ASC";    
                                        $querys=mysqli_query($con,$sql)or die(mysqli_error($con));
                                        $rows=mysqli_fetch_array($querys);
                                    ?>
                                        <tr>
                                            <td class="center"><?php echo count_id();?></td>
                                            <td><?php echo date("d M Y", strtotime($row['apdate']));?></td>        
                                            <td><?php echo $row['refinv'];?></td>
                                            <td><?php echo $row['chkno'];?></td>
                                            <td><?php echo $row['chkdt'];?></td>
                                            <td><?php echo numtolocal($row['amount']);?></td>
                                            <td><?php echo $rows['name'];?></td>
                                            <td>Received</td>
                                            <td>
                                                <?php
                                                    if($row['type']=='SU'){ 
                                                        echo show_addres(get_fild_data('tbl_supplier',$row['clientid'],'name'),get_fild_data('tbl_supplier',$row['clientid'],'cnumber'),get_fild_data('tbl_supplier',$row['clientid'],'cemail'),'',get_fild_data('tbl_supplier',$row['clientid'],'code'),$row['type'].'_'.$row['clientid']);
                                                    }else{
                                                    echo show_addres(get_fild_data('tbl_customer',$row['clientid'],'name'),get_fild_data('tbl_customer',$row['clientid'],'cnumber'),get_fild_data('tbl_customer',$row['clientid'],'cemail'),'',get_fild_data('tbl_customer',$row['clientid'],'code'),$row['type'].'_'.$row['clientid']);
                                                    }
                                                    
                                                ?>
                                            </td>
                                            <td><?php echo $row['chbnkid'];?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                            <td nowrap="">
                                                <a class="btn btn-flat bg-purple" href="#" onclick="update_item('DL_<?php echo $row['id'];?>')"><i class="fa fa-edit"></i></a>
                                                <form action="ban_checkman.php" id="DL_<?php echo $row['id'];?>" method="post" >
                                                <input type="hidden" name="delpay" value="<?php echo $row['id']; ?>" />
                                                </form>
                                            </td>    
                                        </tr>    
                                    <?php } ?>    
                                </tbody>   
                            </table>
                    </div>
            </div>

        </div>

        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">Cheque Payment</h3>
            </div>
            <div class="box-body">
                    <?php echo display_msg();?>    
                    <div class="col-md-12 table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice/Receipt</th>
                                        <th>Cheque No</th>
                                        <th>Cheque Date</th>
                                        <th>Amount</th>
                                        <th>A/C No</th>
                                        <th>Status</th>
                                        <th>Client</th>    
                                        <th>Cheque Bank</th>  
                                        <th>Note</th>     
                                        <th style="width:40px; text-align:center;">Action</th>    
                                    </tr>
                                </thead>    
                                <tbody>
                                    <?php
                                    $sql="SELECT * FROM tbl_cheqman where brid='$brid' and paymod='PAY' order by apdate desc";    
                                    $query=mysqli_query($con,$sql)or die(mysqli_error($con));
                                    while ($row=mysqli_fetch_array($query)){

                                        $acid=$row['acid'];
                                        $sql="SELECT tbl_bacount.id,CONCAT(tbl_bank.sort,' - ',tbl_bacount.acno) AS name FROM tbl_bacount LEFT JOIN tbl_bank ON tbl_bank.id=tbl_bacount.bid WHERE tbl_bacount.id='$acid' ORDER BY tbl_bank.sort ASC";    
                                        $querys=mysqli_query($con,$sql)or die(mysqli_error($con));
                                        $rows=mysqli_fetch_array($querys);
                                    ?>
                                        <tr>
                                            <td class="center"><?php echo count_id();?></td>
                                            <td><?php echo date("d M Y", strtotime($row['apdate']));?></td>        
                                            <td><?php echo $row['refinv'];?></td>
                                            <td><?php echo $row['chkno'];?></td>
                                            <td><?php echo $row['chkdt'];?></td>
                                            <td><?php echo numtolocal($row['amount']);?></td>
                                            <td><?php echo $rows['name'];?></td>
                                            <td>Given</td>
                                            <td>
                                                <?php
                                                    if($row['type']=='SU'){ 
                                                        echo show_addres(get_fild_data('tbl_supplier',$row['clientid'],'name'),get_fild_data('tbl_supplier',$row['clientid'],'cnumber'),get_fild_data('tbl_supplier',$row['clientid'],'cemail'),'',get_fild_data('tbl_supplier',$row['clientid'],'code'),$row['type'].'_'.$row['clientid']);
                                                    }else{
                                                    echo show_addres(get_fild_data('tbl_customer',$row['clientid'],'name'),get_fild_data('tbl_customer',$row['clientid'],'cnumber'),get_fild_data('tbl_customer',$row['clientid'],'cemail'),'',get_fild_data('tbl_customer',$row['clientid'],'code'),$row['type'].'_'.$row['clientid']);
                                                    }
                                                    
                                                ?>
                                            </td>
                                            <td><?php echo $row['chbnkid'];?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                            <td nowrap="">
                                                <a class="btn btn-flat bg-purple" href="#" onclick="update_item('DL_<?php echo $row['id'];?>')"><i class="fa fa-edit"></i></a>
                                                <form action="ban_checkman.php" id="DL_<?php echo $row['id'];?>" method="post" >
                                                <input type="hidden" name="delpay" value="<?php echo $row['id']; ?>" />
                                                </form>
                                            </td>    
                                        </tr>    
                                    <?php } ?>    
                                </tbody>   
                            </table>
                    </div>
            </div>

        </div>


    </div>


<div class="col-md-2">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php //if($_SESSION['access']=='1'){echo read_activity($aid,'PAY','A');}else{echo read_activity($aid,'PAY','U');}?>
</div>
</div>
</div>
</div>
</div>
</div> 
<?php include('../layout/quick.php');?>           
</section>


<!-- /.main content -->
<?php include('../layout/rside.php'); ?>     
</div>
<?php
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
ReadITEM();
function ReadITEM() {
$.ajax({
url: "ban_mobileaccountcre.php",
method: "POST",
data:{viewitem:1},
beforeSend: function () {
$('#datarec').DataTable().clear().destroy();    
},     
success: function(data) {
$('#itemdata').html(data);
$('#datarec').DataTable({stateSave: true});    
}
})
    
$.ajax({
url: "ban_mobileaccountcre.php",
method: "POST",
data:{viewitemhis:1},    
success: function(data) {
$('#hisdata').html(data);     
}
})   
}
    
$(document).on('click', function(e){
if (!$(e.target).is(".right-side-add, .side-cont, #addnew") && !$(e.target).parents(".right-side-add").length && $('.right-side-add').hasClass('open-right-add')) {
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');
}    
});


$(document).on('click', '.details-invoice', function(e) {    
id_arr = $(this).attr('id');
id = id_arr.split("_");
ids=id[1];    
$.ajax({
url: "ban_mobileaccountcre.php",
method: "POST",
data:{addsitem:1,item:ids},
success: function(data){
$('#addsitem').html(data);
$('.right-side-add').toggle('slide', { direction: 'right' }, 300);     
}
})    
e.preventDefault();    
});
    
$(document).on('click', '#addnew', function(e) {
$.ajax({
url: "ban_mobileaccountcre.php",
method: "POST",
data:{addsitem:1,item:0},
success: function(data){
$('#addsitem').html(data);
$('.right-side-add').toggle('slide', { direction: 'right' }, 300);     
}
})    
e.preventDefault();    
});    
    
$(document).on('click', '#closepop', function() {
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');    
});
    
$(document).on('click', '#additem', function() { 
var cash_data = $('.addservice input');
toastr.options = {'positionClass': 'toast-top-center'};    
if(!chek_error()){   
return;   
}
$.ajax({
url: "ban_mobileaccountcre.php",
data: cash_data,
type: 'post',
dataType: 'json',    
beforeSend: function () {
chek_error();    
},    
success: function(data){
if(data.status === "success"){
if($('.right-side-add').is(':visible')) { $('.right-side-add').toggle('slide', { direction: 'right' }, 300); }
$('#addsitem').html('');    
toastr.success(data.message);
ReadITEM();    
}else{
toastr.error(data.message);    
}         
}
})    
});    
</script>    
<!-- /page script --><!-- page script -->
<script type="text/javascript">
$(document).ready(function() {
$('#datarec').DataTable({stateSave: true});
});
    
function edit_item(id) {
document.getElementById(id).submit(); 
}
    
function remove_item(id) {
bootbox.confirm({
title: "Confirm",
message: "Are you sure to delete ?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-flat bg-purple'
},
cancel: {
label: 'Cancel',
className: 'btn-flat bg-gray'
}
},
callback: function (result) {
if (result == true) {
document.getElementById(id).submit();
}
}
});

}
    
$(".details-invoice").click(function (e) {
id_arr = $(this).attr('id');
id = id_arr.split("_");

$.ajax({
url: 'acc_viewpaylist.php',
method: "POST",
data:{ 
invid: id[1]
},
success: function(data){
$('#listitem').html(data);
pagelist();    
}
});    
    
$.ajax({
url: 'acc_viewpay.php',
method: "POST",
data:{ 
print: id[1]
},
success: function(data){
$('#invhold').html(data);
sethead();    
}
});
    
$('.right-side').toggle('slide', { direction: 'right' }, 300);    

e.preventDefault();
});

$(document).on('click', '#closepop', function() {
if($('.right-side').is(':visible')) { $('.right-side').toggle('slide', { direction: 'right' }, 300); }   
});    

$('#listitem').on('click','li', function(){
   $(this).addClass('active').siblings().removeClass('active');
});
    
$(document).on('click', '.invpayv', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
$.ajax({
url: 'acc_viewpay.php',
method: "POST",
data:{ 
print: ids
},
beforeSend: function() {
$("#invhold").fadeOut('slow');
},    
success: function(data){    
$('#invhold').html(data);
$("#invhold").fadeIn('slow');    
sethead();    
}
});     
});    
    
</script>    
<!-- /page script -->
</html>    