<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('26','views','R');    
$_SESSION['cuPages']='acc_paylist.php';   
$cuPage='acc_paylist.php';    
$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());
$now = date("Y-m-d", 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" id='datarec'>
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice/Received</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' AND status='1' 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 get_fild_data('tbl_bank',$row['chbnkid'],'name');?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                            <td nowrap="">
                                            <a class="btn btn-flat bg-purple details-invoice" href="#" id="ser_<?php echo $row['id']; ?>"><i class="fa fa-edit cat-child"></i></a>    
                                            </td>    
                                        </tr>    
                                    <?php } ?>    
                                </tbody>   
                            </table>

                </div>  
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">Cheque Given</h3>
            </div>
            <div class="box-body">
                <?php echo display_msg();?>    
                <div class="col-md-12 table-responsive">
                <table class="table table-bordered table-striped" id='datagiv'>
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice/Given</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
                                    $i=1;
                                    $sql="SELECT * FROM tbl_cheqman where brid='$brid' and paymod='PAY' AND status='1' 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 $i++;?></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 date("d M Y", strtotime($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 get_fild_data('tbl_bank',$row['chbnkid'],'name');?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                            <td nowrap="">
                                            <?php
                                            
                                                    if(date("Y-m-d", strtotime($row['chkdt'])) == $now){ ?>
                                                      <a class="btn btn-flat bg-purple details-invoice" href="#" id="ser_<?php echo $row['id']; ?>"><i class="fa fa-edit cat-child"></i></a>   
                                                    <?php } ?> 
                                            </td>    
                                        </tr>    
                                    <?php } ?>    
                                </tbody>   
                            </table>

                </div>  
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">Cheque Deposit List</h3>
            </div>
            <div class="box-body">
                <?php echo display_msg();?>    
                <div class="col-md-12 table-responsive">
                <table class="table table-bordered table-striped" id='datadep'>
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice/Deposit</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
                                    $i=1;
                                    $sql="SELECT * FROM tbl_cheqman where brid='$brid' and paymod='REC' AND status='3' 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 $i++;?></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 date("d M Y", strtotime($row['chkdt']));?></td>
                                            <td><?php echo numtolocal($row['amount']);?></td>
                                            <td><?php echo $rows['name'];?></td>
                                            <td>Deposit</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 get_fild_data('tbl_bank',$row['chbnkid'],'name');?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                            <!-- <td nowrap="">
                                            <?php
                                            
                                                    if(date("Y-m-d", strtotime($row['chkdt'])) == $now){ ?>
                                                      <a class="btn btn-flat bg-purple details-invoice" href="#" id="ser_<?php echo $row['id']; ?>"><i class="fa fa-edit cat-child"></i></a>   
                                                    <?php } ?> 
                                            </td>    
                                        </tr>     -->
                                    <?php } ?>    
                                </tbody>   
                            </table>

                </div>  
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">Cheque Payment List</h3>
            </div>
            <div class="box-body">
                <?php echo display_msg();?>    
                <div class="col-md-12 table-responsive">
                <table class="table table-bordered table-striped" id='datapay'>
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice/Payment</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
                                    $i=1;
                                    $sql="SELECT * FROM tbl_cheqman where brid='$brid' and paymod='PAY' AND status='4' 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 $i++;?></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 date("d M Y", strtotime($row['chkdt']));?></td>
                                            <td><?php echo numtolocal($row['amount']);?></td>
                                            <td><?php echo $rows['name'];?></td>
                                            <td>Payment</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 get_fild_data('tbl_bank',$row['chbnkid'],'name');?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                            <!-- <td nowrap="">
                                            <?php
                                            
                                                    if(date("Y-m-d", strtotime($row['chkdt'])) == $now){ ?>
                                                      <a class="btn btn-flat bg-purple details-invoice" href="#" id="ser_<?php echo $row['id']; ?>"><i class="fa fa-edit cat-child"></i></a>   
                                                    <?php } ?> 
                                            </td>     -->
                                        </tr>    
                                    <?php } ?>    
                                </tbody>   
                            </table>

                </div>  
            </div>
        </div>
        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">Cheque Bounce/Return List</h3>
            </div>
        <div class="box-body">
                <?php echo display_msg();?>    
                <div class="col-md-12 table-responsive">
                <table class="table table-bordered table-striped" id='databou'>
                                <thead>
                                    <tr>
                                        <th style="width:40px;">SN</th>   
                                        <th>Date</th>
                                        <th>Invnoice</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
                                    $i=1;
                                    $sql="SELECT * FROM tbl_cheqman where brid='$brid' AND status='5' or status='6' or (chkdt <'$now' and status!='3' and status!='4')   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 $i++;?></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 date("d M Y", strtotime($row['chkdt']));?></td>
                                            <td><?php echo numtolocal($row['amount']);?></td>
                                            <td><?php echo $rows['name'];?></td>
                                            <td><?php if($row['status']=='5'){echo 'Bounce';}elseif($row['status']=='6'){echo 'Return';} ?></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 get_fild_data('tbl_bank',$row['chbnkid'],'name');?></td>
                                            <td><?php echo $row['ref'];?></td>     
                                             <td nowrap="">
                                            <?php
                                            
                                                    if(date("Y-m-d", strtotime($row['chkdt'])) < $now){ ?>
                                                      <a class="btn btn-flat bg-purple details-invoice" href="#" id="ser_<?php echo $row['id']; ?>"><i class="fa fa-edit cat-child"></i></a>   
                                                    <?php } ?> 
                                            </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,'CHK','A');}else{echo read_activity($aid,'PAY','U');}?>
</div>
</div>
</div>
</div>
</div>
</div> 

<?php include('../layout/quick.php');?>    
</section>
<?php include('../layout/rside.php'); ?>  
<!-- /.main content -->
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function() {
$('#datarec').DataTable({stateSave: true});
});    
$(document).ready(function() {
$('#datagiv').DataTable({stateSave: true});
}); 
$(document).ready(function() {
$('#datadep').DataTable({stateSave: true});
}); 
$(document).ready(function() {
$('#datapay').DataTable({stateSave: true});
}); 
$(document).ready(function() {
$('#databou').DataTable({stateSave: true});
}); 

    
    
$(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_checkupdate.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_checkupdate.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, .addservice select, .addservice textarea');
toastr.options = {'positionClass': 'toast-top-center'};    
if(!chek_error()){   
return;   
}

$.ajax({
url: "ban_checkupdate.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);    
}         
}
})    
});
    
function remove_item(id) {
ide = id.split("_");
var ids = ide[1];  
toastr.options = {'positionClass': 'toast-top-center'};     
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) {
$.ajax({
url: "ban_checkupdate.php",
data: {delseritem:1,item:ids},
type: 'post',
dataType: 'json',        
success: function(data){
if(data.status === "success"){   
toastr.success(data.message);
ReadITEM();    
}else{
toastr.error(data.message);    
}         
}
})
}
}
});
}    
</script>    
<!-- /page script -->
</html>    