<style>
    #tableWithSearch thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
    #tableWithSearch thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }
    .datepicker thead tr .dow {
        color:#4c0870  !important;
    }
    .datepicker table tr td.day:hover {
        background: #4c0870  !important;
        color:#fff;
    }
    .datepicker table tr td.active {
        background-color: #4c0870  !important;
    }
    .datepicker thead tr .datepicker-switch {
        color: #4c0870   !important;
        font-size: 13px;
    }
    .datepicker table tr td span.active {
        background-color: #4c0870  !important;
    }
    .datepicker table tr td span:hover {
        background-color: #4c0870  !important;
        color:#fff;
    }
    datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870  !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    .datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870  !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    /*
    .btn-default:hover{
    background-color:#ed9421 !important;
    color:#fff;
    border: none;
    }
    */
    .complete ,.btn-group  .active{
        background-color:#ed9421 !important;
        color:#fff;
    }
    /*    .MonthPicker,.YearPicker,.FromToPicker{
            display:none;
        }*/
    #selected_entry{
        height:90px;
        color: black;
        margin-top:20px;
        font-size: 16px;
        padding-top: 2%;
    }
    .select_table td{
        padding-left: 70px;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover,.dataTables_wrapper .dataTables_paginate .paginate_button:hover{
        color:#fff !important;
        border-radius: 50%;
        background: #ed9421 !important;
        border-color: #4c0870
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover{
        color:#fff !important;
    }

</style>

<script src="<?php echo THEME_PATH; ?>/plugins/moment/moment.min.js"></script>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php echo CommonLanguage::getMessage('vat_report'); ?> </div>
            <div class="row ">
                <div class="col-md-12 ">

                    <div class="col-md-3" >
                        <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                        <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" >
                    </div> 
                    <div class="col-md-3">
                        <label><?php echo CommonLanguage::getMessage('type') ?></label>
                        <select id="type" class="full-width" data-init-plugin="select2">
                            <option value="cust"><?php echo CommonLanguage::getMessage('customers') ?></option>
                            <option value="supp"><?php echo CommonLanguage::getMessage('suppliers') ?></option>
                        </select>
                    </div>
                    <div class="col-md-3 <?php echo $permissions->hasPermission('Branches') ? '':'hidden'; ?>">
                        <label><?php echo CommonLanguage::getMessage('choose_branch') ?></label>
                        <input id="search_branch_id" type="hidden" class="full-width" name="search_branch_id"  >
                    </div>

                </div>
            </div>
        </div>
        <div class="panel-body">

            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                <thead>
                    <tr>
                        <th class="text-center" style="width:10%" > <?php print CommonLanguage::getMessage('Code'); ?></th>
                        <th class="text-center" style="width:15%" > <?php print CommonLanguage::getMessage('Name'); ?></th>
                        <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('amount'); ?></th>                        
                        <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('second_amount'); ?></th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
                <tfoot>
                <th></th><th></th><th><span class="total_vat"></span>&nbsp;<span><?php echo smc_session()['local_currency_symbol'] ?></span></th>
                <th><span class="second_currency"></span>&nbsp;<span><?php echo smc_session()['local_currency_symbol'] ?></span></th>
                </tfoot>
            </table>
        </div>

    </div>
</div>

<script>
    var IsActual = <?php echo $is_actual ? "true" : "false" ?>;
    var title = <?php echo json_encode(CommonLanguage::getMessage('vat_report')); ?>;
    var today = <?php echo json_encode($today) ?>;
    $(function () {
        build_select2($("#search_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");

        ChangeTable()
        $("input[name=From_To_Date]").daterangepicker({
        }, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                    window.endDate = end.format("YYYY-MM-DD")
            ChangeTable();

        });
        $("#type,#search_branch_id").on("change", function () {
            ChangeTable()
        })
    })

    function ChangeTable() {
        var data = {type: $("#type").val(), is_actual: IsActual ? 1 : 0,
            from_date: window.startDate ? window.startDate : today,
            to_date: window.endDate ? window.endDate : today,
            search_branch_id: $("#search_branch_id").val()
        };

        $.ajax({
            url: "ACCAjax/customer_supplier_vat_report",
            data: data,
            dataType: 'JSON',
            complete: function (v1, v2) {
                if (v2 == 'success') {
//                    $("#tableWithSearch tbody").empty()
                    $("#tableWithSearch").DataTable().destroy();
                    $("#tableWithSearch tbody").empty().html(v1.responseJSON['html'])
                    RebuildDataTable('', [], "", {}, '', '', {
                        initComplete: function (settings, json) {
//                            console.log(v1.responseJSON['total'])
                            $(".total_vat").html(AddCommas(public_round_number(v1.responseJSON['total'])));
                        }
                    });
                }
            }
        })
//         RebuildDataTable(title, [], 'ACCAjax/customer_supplier_vat_report', Date,'#tableWithSearch')

    }


</script>
