<?php
    $general->pageHeader($rModule['title']);
?>
<div class="row">
    <div class="col-sm-12" id="message_show_box"></div>
    <div class="col-sm-12">
        <div class="white-box">
            <div class="row">
                <?php 
                $general->inputBoxTextForReport('dRange','Date',className:'daterangepickerMulti form-control');
                $heads=$db->allUsers('order by username asc');
                $general->inputBoxSelectForReport($heads,'User','user_id','id','name');
                $types = $acc->all_voucher_type();
                $general->inputBoxSelectForReport($types,'Type','type','id','title');
                ?>
              
                <div class="col-md-2">
                    <h5 class="box-title">Search</h5>
                    <input type="submit" value="Search"class="btn btn-success" name="s" onclick="voucher_list(0);">
                </div>
                <div class="col-sm-12 col-lg-12"><?php show_msg();?></div>
                <div class="col-sm-12 col-lg-12" id="trDetailsArea"></div>
            </div>
        </div>
    </div>
</div>
<script>
    function voucher_list(){
        let user_id = parse_int($('#user_id').val());
        let type = parse_int($('#type').val());
        ajax_report_request({voucher_list:1,user_id:user_id,type:type},'trDetailsArea');
    }
    function delete_voucher(voucher_id){
        if(voucher_id>0){
            buttonLoading(`delete_voucher_${voucher_id}`);
            $.ajax({
                type:'post',
                url:ajUrl,
                data:{voucherRemove:1,voucher_id:voucher_id},
                success:function(data){
                    button_loading_destroy(`delete_voucher_${voucher_id}`,'');
                    if(typeof(data.status)  !== "undefined"){ 
                        if(data.status==1){
                            $(`#delete_voucher_${voucher_id}`).remove()
                        }
                        setTimeout(() => {swMessageFromJs(data.m);}, 500);
                        
                    }
                    else{
                        
                        setTimeout(() => {swMessage(AJAX_ERROR_MESSAGE); }, 500);
                    }   
                },
                error: function(data) { 
                    button_loading_destroy(`delete_voucher_${voucher_id}`,'Remove');
                    setTimeout(() => {swMessage(AJAX_ERROR_MESSAGE); }, 500);
                }
            });
        }
    }
</script>
