<style>
    #category_data{
        padding: 4px !important;
        font-size: 12px !important;
    }
    #tableWithSearch tfoot td{
        font-weight:bold;
    }
    #tableWithSearch tbody tr td:last-child{
        font-weight:bold;
    }
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title">
                <h4 class="bold"><?php echo CommonLanguage::getMessage($title); ?> </h4>
            </div>
        </div>
        <div class="panel-body ">
            <div class="row form-group">
                <div class="col-md-4">
                    <label><?php echo CommonLanguage::getMessage('project') ?></label>
                    <input id="period_id" type="hidden" class="full-width" name="period_id"  />
                </div> 
                <div class="col-md-3" >
                    <label><?php print CommonLanguage::getMessage('Date'); ?></label>
                    <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" >
                </div> 

                <div class="col-md-3  <?php echo smc_session()['default_setting']['activate_second_currency'] == 1 ? '':'hidden'; ?>">
                    <label><?php echo CommonLanguage::getMessage('currency') ?></label>
                    <select id="currency_id" class="full-width" name="currency_id" data-init-plugin="select2" >
                        <option value="0"><?php echo CommonLanguage::getMessage('project_currency') ?></option>
                        <option value="1"><?php echo smc_session()['local_currency_name'] ?></option>
                        <option value="2"><?php echo smc_session()['second_currency']['name'] ?></option>
                    </select>
                </div> 
                <div class="col-md-2" style="display:grid;">
                    <label><?php echo CommonLanguage::getMessage('show_activity_alias') ?></label>
                    <input type="checkbox" id="show_alias" name="show_alias" />
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-2" style="display:grid;">
                    <label><?php echo CommonLanguage::getMessage('ignore_zero_row') ?></label>
                    <input type="checkbox" id="ignore_zero" name="ignore_zero" />
                </div>
                <div class="col-md-2 pull-right m-t-25">
                    <button  class="btn btn-complete full-width pull-right " id="generate" ><?php echo CommonLanguage::getMessage('generate') ?></button>
                </div>
            </div>
            <div class="row main_div ">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th><?php echo CommonLanguage::getMessage('activity_code'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('activity'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('total_funds'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('expenses'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('Expense_Date'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('supplier'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('note'); ?></th>
                                <th><?php echo CommonLanguage::getMessage('check'); ?>&nbsp;#</th>
                                <th><?php echo CommonLanguage::getMessage('balance'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>

                        <th><strong ><?php echo CommonLanguage::getMessage('totals') ?></strong></th>
                        <th></th>
                        <th class="text-center"><strong id="total_fund"></strong></th>
                        <th class="text-center"><strong id="total_exp"></strong></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th class="text-center"><strong id="total_balance"></strong></th>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
        <?php echo Forms::ModalLoader('report_loader'); ?>
    </div>
</div>
<script>
    $(function () {
        build_select2($('#period_id'), 'ACCAjax/searchProjectPeriod');
        $("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();

        });

        $('#generate').on('click', function () {
            if ($('#period_id').val()) {
                $('.main_div').removeClass('hidden');
                ChangeTable();
            } else {
                $('.main_div').addClass('hidden');
            }
        });
    });
    function ChangeTable() {
        var Data = {
            period_id: $("#period_id").val(),
            currency_id: $("#currency_id").val(),
            show_alias: $("#show_alias").is(':checked') ? 1 : 0,
            ignore_zero: $("#ignore_zero").is(':checked') ? 1 : 0,
            from_date: (window.startDate ? window.startDate : today),
            to_date: (window.endDate ? window.endDate : today)
        }
        $('#report_loader').removeClass('hidden');
        $.ajax({
            url: "ACCAjax/project_activities_report",
            data: Data,
            dataType: "json",
            complete: function (v1, v2) {
                if (v2 == "success") {
                    var response = v1.responseJSON;
                    $("#tableWithSearch").DataTable().destroy();
                    $("#tableWithSearch tbody").empty().html(response['body']);
                    var msg = '<h4><strong>Date:&nbsp' + Data.from_date + ' - ' + Data.to_date + '</strong></h4>';
                    RebuildDataTable($('.panel-heading .panel-title h4').html(), [], "", Data, '', [0, 1, 2, 8], {msg: msg}, false);
//                    var row = $("#tableWithSearch").dataTable().fnGetNodes();
                    $("#total_fund").html(response['total_fund'])
                    $("#total_balance").html(response['total_balance'])
                    $("#total_exp").html(response['total_exp'])

                    $('#report_loader').addClass('hidden');
                }
            }
        });
    }
</script>