<?php 
$customers = $db->selectAll('customer','where base_id='.$userData['base_id'],'id,name,code');
foreach($customers as $key=>$customer){
    $customers[$key]['name'] = $customer['name'].' ('.$customer['code'].')';
}
?>

<section class="mb-4" id="sale_area">
    <div class="card">
        <div class="card-header text-center py-3"> 
            <h5 class="mb-0 text-center">
                <strong>Paid unpaid report</strong>
            </h5>
        </div>
        <div class="card-body">
            <div class="row">
                
        <div class="col-md-2">
            <div class="col-sm-12 col-lg-12">   
                <h5 class="box-title">Date</h5>
                <input type="text" id="dRange" class="daterangepickerMulti form-control" value="">
            </div> 
        </div>
        <?php 
            $general->inputBoxSelectForReport($customers,'Customer','customer_id','id','name',@$_GET['customer-id']);
            $general->inputBoxSelectForReport([
                ['id'=>PAY_TYPE_CASH,'name'=>'Cash'],
                ['id'=>PAY_TYPE_CREDIT,'name'=>'Credit'],
            ],'Pay type','pay_type','id','name');
            $general->inputBoxSelectForReport([
                ['id'=>2,'name'=>'Paid'],
                ['id'=>3,'name'=>'Unpaid'],
            ],'Paid/unpaid','paid_type','id','name');
            ?>
            <div class="col-md-2">
                <h5 class="box-title">&nbsp</h5>
                <button class="btn btn-success" onclick="paid_unpaid_report()">Search</button>
            </div>
            <div class="row" style="overflow: scroll;">
                <div class="col-md-12" id="reportArea">

                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    function paid_unpaid_report(){
        let dRange  = $('#dRange').val();
        let customer_id=$('#customer_id').val();
        let paid_type = $('#paid_type').val();
    let pay_type = $('#pay_type').val();
        $('#reportArea').html(loadingImage);
        $.ajax({
            type:'post',
            url:ajUrl,
            data:{module:'paid_unpaid_report',dRange:dRange,customer_id:customer_id,paid_type:paid_type,pay_type:pay_type},
            success:function(data){
                $('#reportArea').html('');
                if(typeof(data.status)!=='undefined'){
                    if(data.status==1){
                        $('#reportArea').html(data.html);
                    }
                    swMessageFromJs(data.m);
                }
                else{
                    swMessage(AJAX_ERROR_MESSAGE); 
                }
            },
            error:function(){
                $('#reportArea').html('');
                swMessage(AJAX_ERROR_MESSAGE); 
            }
        });
    }
    
    $(document).ready(function(){
        order_list();
    })
</script>
