
<style>
    .table thead tr >th{

        background-color:#4c0870;
        color:#fff;
    }
    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }


</style>

<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print CommonLanguage::getMessage('close_year_trans_list'); ?></div>
            <div id="submitVat" class="alert alert-success hidden"></div>

            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <div class="row m-b-10 ">
                <div class="col-md-3 " >
                    <label></label>
                    <button id="open_year" class="btn btn-complete" style="margin-top:24px;"><?php echo CommonLanguage::getMessage('open_current_year'); ?>  </button>
                </div>
            </div>
            <div class="row m-b-10 ">
                <div class="col-md-3 form-group">
                    <label><?php echo CommonLanguage::getMessage('close_year_to') ?></label>
                    <select id="next_year" class="full-width" data-init-plugin="select2">
                        <?php foreach ($to_close_years as $year) { ?>
                            <option value="<?php echo $year['current_year_id'] ?>"><?php echo $year['current_year'] ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <div class="row">
                <table class="table table-bordered " id="tableWithSearch">
                    <thead>
                        <tr>
                            <!--<th class="text-center" style="width:5%"><?php // print CommonLanguage::getMessage('jv');        ?>#</th>-->
                            <th class="text-center" ><?php print CommonLanguage::getMessage('account_code'); ?></th>
                            <th class="text-center" ><?php print CommonLanguage::getMessage('account_name'); ?></th>
                            <th class="text-center"  ><?php print CommonLanguage::getMessage('type'); ?></th>
                            <th class="text-center"  ><?php print CommonLanguage::getMessage('amount'); ?></th>
                            <th class="text-center"  ><?php print CommonLanguage::getMessage('Date'); ?></th>
                            <th class="text-center"  ><?php print CommonLanguage::getMessage('description'); ?></th>
                            <th class="text-center"  ><?php print CommonLanguage::getMessage('branch'); ?></th>
                            <?php if (smc_session()['default_setting']['activate_accounting_job'] == 1) { ?>
                                <th class="text-center " style="width:15%" ><?php print CommonLanguage::getMessage('job'); ?></th>
                            <?php }if (smc_session()['default_setting']['activate_project'] == 1) { ?>
                                <th class="text-center " style="width:15%" ><?php print CommonLanguage::getMessage('project'); ?></th>
                            <?php } ?>

                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        for ($x = 0; $x < count($list); $x++) {
                            $CurItem = $list [$x];
                            ?>
                            <tr>
                                <!--<td class=' v-align-middle text-center bold'><?php // echo $CurItem["JV_ID"];        ?></td>-->
                                <td class=' v-align-middle text-center '><?php echo $CurItem["Account_Code"]; ?></td>
                                <td class=' v-align-middle text-center '><?php echo $CurItem["Account_Name"]; ?></td>
                                <td class=' v-align-middle text-center '><?php echo $CurItem["Transaction_Type"]; ?></td>
                                <td class=' v-align-middle text-center '><?php echo (smc_session()['local_currency_symbol'] . " " . CommonFunctions::formatNumber($CurItem["Transaction_Amount"])); ?></td>
                                <td class=' v-align-middle text-center '><?php echo $CurItem["Transaction_Date"]; ?></td>
                                <td class=' v-align-middle text-center '><?php echo $CurItem["Transaction_Description"]; ?></td>
                                <td class=' v-align-middle text-center '><?php echo $CurItem["branch_name"]; ?></td>
                                <?php if (smc_session()['default_setting']['activate_accounting_job'] == 1) { ?>
                                    <td class=' v-align-middle text-center '><?php echo $CurItem["job_name"]; ?></td>
                                <?php }if (smc_session()['default_setting']['activate_project'] == 1) { ?>
                                    <td class=' v-align-middle text-center '><?php echo $CurItem["project_name"]; ?></td>
                                <?php } ?>
                            </tr>

                        <?php } ?>
                    </tbody>
                </table>
            </div>
            <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_year'); ?></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('close_year_trans_list')); ?>,
            current_year_id = <?php echo smc_session()['current_year_id']; ?>,
            is_actual = <?php echo $is_actual; ?>;
    $(function () {//open_financial_year
        $("#open_year").on("click", function () {
            $.ajax({
                url: "ACCAjax/open_financial_year",
                method: "POST",
                data: {year_id: current_year_id, actual: is_actual},
                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(v1.responseText/*Failed_Submit*/)
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                }
            })
        })
        $("#SubmitButton").on("click", function () {
            //        $("#tableWithSearch tbody tr").each(function(e){
            var me = $(this);
            var Data = {
                actual: is_actual,
                next_year: $("#next_year").val()
            };
            $.ajax({
                url: "ACCAjax/closeYearAjax",
                method: "POST",
                data: Data,
                complete: function (v1, v2) {
                    if (v2 == "success" && v1.responseText == "OK") {
                        $("#submitVat").attr("class", "alert alert-success").html(Submitted_Successfully)
                        $("#SubmitButton").addClass('disabled')
                    } else {
                        $("#submitVat").attr("class", "alert alert-danger").html(Failed_Submit)
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                }
            })

        })
        RebuildDataTable('close_year', [], '', [], '', []);
    })

</script>
