<style>
    .table thead tr >th{

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

<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="row">
                <div class="col-md-4  pull-right" style="vertical-align: top;">

                    <div class="form-group form-group-default input-group">
                        <label class="fade"><?php print CommonLanguage::getMessage('Date'); ?></label>
                        <input id="VatDate" name="VatDate" class="form-control" value="<?php echo $today; ?>" aria-required="true" aria-invalid="false">
                        <span class="input-group-addon bg-complete"><i class="fa fa-calendar"></i></span>
                    </div>

                    <br>
                </div>
            </div>
            <div class="panel-title"><?php print CommonLanguage::getMessage('vat_transaction_list'); ?></div>
            <div id="submitVat" class="alert alert-success hidden"></div>
            <!--            <div class="pull-right">
<div class="col-xs-12">
<input type="text" id="search-table" class="form-control pull-right" placeholder="Search"/>
</div>
</div>-->
            <div class="clearfix"></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:5%"><?php print CommonLanguage::getMessage('jv'); ?>#</th>
                        <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('account_code'); ?></th>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('account_name'); ?></th>
                        <th class="text-center" style="width:5%" ><?php print CommonLanguage::getMessage('type'); ?></th>
                        <th class="text-center" style="width:5%" ><?php print CommonLanguage::getMessage('amount'); ?></th>
                        <th class="text-center" style="width:5%" ><?php print CommonLanguage::getMessage('Date'); ?></th>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('description'); ?></th>

                    </tr>
                </thead>
                <tbody>
                    <?php
                    for ($x = 0; $x < count($list); $x++) {
                        $CurItem = $list [$x];
                        ?>
                        <tr data-id="<?php echo $CurItem["Transaction_ID"]; ?>">
                            <td class=' v-align-middle text-center bold'><?php echo $CurItem["JV_ID"]; ?></td>
                            <td class=' v-align-middle text-center bold'><?php echo $CurItem["Transaction_Account"]; ?></td>
                            <td class=' v-align-middle text-center bold'><?php echo $CurItem["Account_Name"]; ?></td>
                            <td class=' v-align-middle text-center bold'><?php echo $CurItem["Transaction_Type"]; ?></td>
                            <td class=' v-align-middle text-center bold'><?php echo CommonFunctions::public_round_number($CurItem["Transaction_Amount"]) . " " . $CurItem["Currency_Symbol"]; ?></td>
                            <td class=' v-align-middle text-center bold'><?php echo $CurItem["Transaction_Date"]; ?></td>
                            <td class=' v-align-middle text-center bold'><?php echo $CurItem["Transaction_Description"]; ?></td>
                        </tr>

                    <?php } ?>
                </tbody>
            </table>

            <div class="container-sm-height">
                <button class=" btn  btn-cons m-b-10 pull-right" id="SubmitButton" style="color:#fff;background-color:#4c0870 ;padding-top: 10px;top: 20px;min-width:253px;" type="button" <?php count($list) > 0 ? "" : "disabled" ?>><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('close_vat'); ?></span></button>
            </div>

        </div>
    </div>
</div>
<script>
    var Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            title = <?php print json_encode(CommonLanguage::getMessage('vat_transaction_list')); ?>;

    $(function () {
        RebuildDataTable(title, [], '', '', '#tableWithSearch');

        $("#VatDate").datepicker({autoclose: true})
        $("#VatDate").on("changeDate", function () {
            $.ajax({
                url: "ACCAjax/get_close_vat_trans",
                data: {date: $(this).val()},
                dataType: 'json',
                complete: function (v1, v2) {
                    if (v2 == "success") {
                        var data = v1.responseJSON;
                        var html = '';
                        $.each(data, function (indx, value) {
                            html += "<tr data-id='" + value['Transaction_ID'] + "'>" +
                                    "<td class=' v-align-middle text-center bold'>" + value['JV_ID'] + "</td>" +
                                    "<td class=' v-align-middle text-center bold'>" + value['Transaction_Account'] + "</td>" +
                                    "<td class=' v-align-middle text-center bold'>" + value['Account_Name'] + "</td>" +
                                    "<td class=' v-align-middle text-center bold'>" + value['Transaction_Type'] + "</td>" +
                                    "<td class=' v-align-middle text-center bold'>" + public_round_number(value['Transaction_Amount']) + " " + value['Currency_Symbol'] + "</td>" +
                                    "<td class=' v-align-middle text-center bold'>" + value['Transaction_Date'] + "</td>" +
                                    "<td class=' v-align-middle text-center bold'>" + value['Transaction_Description'] + "</td>" +
                                    "</tr>";
                        })
                        $("#tableWithSearch").DataTable().destroy();
                        $("#tableWithSearch tbody").empty().append($(html))
                        RebuildDataTable(title, [], '', '', '#tableWithSearch');


                    }
                }
            })
        })
        $("#SubmitButton").on("click", function () {

            var me = $(this);
            var Data = {
                Submit_Vat: 1,
                Date: $("#VatDate").val()
            };
            $.ajax({
                url: "ACCAjax/closeVATAjax",
                method: "POST",
                data: Data,
                complete: function (v1, v2) {
                    if (v2 == "success" && v1.responseText == "OK") {
                        $("#submitVat").attr("class", "alert alert-success").html(Submitted_Successfully)
                    } else {
                        $("#submitVat").attr("class", "alert alert-danger").html(Failed_Submit)
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                }
            })
        })
//        $('#tableWithSearch').dataTable({
//            "processing": false,
//            "serverSide": false,
//            "aLengthMenu": [[10, 25, 50, 100, 500], [10, 25, 50, 100, 500]],
//            "bSort": true,
//            dom: 'Blfrtip',
//            "pagingType": "full_numbers",
//            "aaSorting": [],
//            "columnDefs": [
//                {"className": "dt-center", "targets": "_all"}
//            ],
//            buttons: [
//                {
//                    extend: 'excelHtml5',
//                    exportOptions: {"columns": [0., 1, 2, 3, 4, 5, 6]},
//                    title: title,
//                    text: '<i class="fa fa-file-excel-o"></i> Excel'
//
//                },
//                {
//                    extend: 'print',
//                    text: '<i class="fa fa-print"></i> Print',
//                    exportOptions: {"columns": [0., 1, 2, 3, 4, 5, 6]},
//                    title: title
//                },
//                {
//                    extend: 'csv',
//                    text: '<i class="fa fa-file-excel-o"></i> CSV',
//                    exportOptions: {"columns": [0., 1, 2, 3, 4, 5, 6]},
//                    title: title
//
//                }
//            ],
//            "pageLength": 50
//        });

    })

</script>
