
<style>
    .panel-default{
        min-height:550px;
    }
    #TopContainer {
        background: #ddd;
        padding:12px 6px;
    }
    .DropDownForForms > .dropdown-menu{
        width:100%;
        height:200px;
        max-height:200px;
        overflow-y:scroll;
    }
    .DropDownForForms > .dropdown-menu{
        height:auto;
        cursor: pointer;
        overflow-y:auto;
    }

    .DropDownForForms > button > input{
        position: absolute;
        left:5;
        top: 0;
        width:90%;
        cursor: pointer;
        -webkit-user-select:none;
        -moz-user-select:none;
        user-select:none;
        padding: 0;
        border: 0;
        background: transparent;
    }
    .dropdown-menu>li>a{

        color: #000 !Important;
        opacity: 1;
    }


    .control-label{
        font-size: 14px !important;
        color: rgb(70,70,70) !important;
        opacity: 1 !important;
    }
    .form-horizontal .form-group .control-label{
        white-space:nowrap;   
    }
    .ValueSpan{
        height: 35px;
        display: block;
        padding: 6px 6px;
        font-size: 18px;
        font-family:"Segoe UI",Arial,sans-serif;
    }
    #ledgerTable_filter,#ledgerTable_length{
        display: none
    }
    #ledgerTable th{
        color: #444;
        background: #ddd;
        text-align: center;
        border-top: 1px solid #4c0870;
    }
    #ledgerTable td{
        text-align:center;
    }
    .panel.panel-default{
        border:1px solid #4c0870;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }
    .form-horizontal .form-group {
        border-bottom: 1px solid #4c0870;
    }
    @media print{
        .print-only{
            display:block;
        }
        h4{
            font-size: 18px !important;
            line-height: 23px !important;
        }

        .table thead tr th,.table tbody tr td{
            border:2px solid #000 !important;
        }
        .table-bordered{
            border:2px solid #000 !important;
        }
        .table thead tr >th,.table tbody tr td{
            font-size: 0.8em !important;
        }

    }
    .advance_search{
        margin-left:5px !important;
        margin-right:5px !important;
        margin-bottom: 0px !important;
    }
</style>
<script>
//    function AddCommas(val) {
//        val = parseFloat(val.toString()).toString();
//        while (/(\d+)(\d{3})/.test(val.toString())) {
//            val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
//        }
//        return val.replace(/\.0$|\.00$/, "") || "0";
//    }
//    function FixNumber(val) {
//        return AddCommas(parseFloat(val + "").toXFixed(2));
//    }
</script>
<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-body"> 
            <div class="row">
                <input type="hidden" id="is_activity" name="is_activity" value="<?php  echo $is_activity;?>"/>
                <div class="row form-group advance_search">
                    <div class="card-group horizontal " id="accordion" role="tablist" aria-multiselectable="true">
                        <div class="card card-default m-b-0">
                            <div class="card-header " role="tab" id="headingOne">
                                <h4 class="card-title">
                                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne" class="collapsed btn btn-search">
                                        <span class="filter-title"> <i class="fa fa-search"></i><?php echo CommonLanguage::getMessage('advanced_search'); ?></span>
                                    </a>
                                </h4>
                            </div>
                            <div id="collapseOne" class="collapse" role="tabcard" aria-labelledby="headingOne" aria-expanded="false" style="">
                                <div class="card-block">
                                    <div class="row p-15" >
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                                            <input id="range_date" type="text" class="form-control" readonly name="range_date" >
                                        </div>
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('due_date') ?></label>
                                            <input id="range_duedate" type="text" class="form-control" readonly name="range_duedate" >
                                        </div>

                                        <div class="col-md-3">
                                            <div class="row">
                                                <div class="col-md-6"><label><?php echo CommonLanguage::getMessage('from_jv') ?></label></div>
                                                <div class="col-md-6"><label><?php echo CommonLanguage::getMessage('to_jv') ?></label></div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6"><input type="number" min="1" id="from_jv" class="form-control full-width"></div>
                                                <div class="col-md-6"><input type="number" min="1" id="to_jv" class="form-control full-width"></div>
                                            </div>

                                        </div>
                                        <div class="col-md-3">
                                            <div class="row">
                                                <div class="col-md-6"><label><?php echo CommonLanguage::getMessage('from_account') ?></label></div>
                                                <div class="col-md-6"><label><?php echo CommonLanguage::getMessage('to_account') ?></label></div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6"><input type="number" min="1" id="from_account" class="form-control full-width"></div>
                                                <div class="col-md-6"><input type="number" min="1" id="to_account" class="form-control full-width"></div>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="row p-15" >
                                        <!--                                        <div class="col-md-3">
                                                                                    <label><?php echo CommonLanguage::getMessage('project') ?></label>
                                                                                    <input type="hidden" class="full-width" id="project_id"/>
                                                                                </div>-->

                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('multi_accounts') ?></label>
                                            <input type="hidden" class="full-width" id="multi_accounts"/>
                                        </div>
                                        <div class="col-md-3 trans_curr_div">
                                            <label><?php echo CommonLanguage::getMessage('trans_in_currency'); ?></label>
                                            <input type="hidden" class="full-width" id="trans_in_currrency"/>
                                            <?php // echo Forms::CurrencyDropDown(1, 'complete') ?>
                                        </div>
                                        <div class="col-md-3">
                                            <div class="row">
                                                <div class="col-md-6"><label><?php echo CommonLanguage::getMessage('from_amount') ?></label></div>
                                                <div class="col-md-6"><label><?php echo CommonLanguage::getMessage('to_amount') ?></label></div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6"><input type="number" min="0" step="any" id="from_amount" class="form-control full-width"></div>
                                                <div class="col-md-6"><input type="number" min="0" step="any" id="to_amount" class="form-control full-width"></div>
                                            </div>

                                        </div>
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('currency'); ?></label>
                                            <?php echo Forms::CurrencyDropDown(1, 'complete') ?>
                                        </div>
                                    </div>
                                    <div class="row p-15">
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('entry_type') ?></label>
                                            <input type="hidden" class="full-width" id="ref_type"/>
                                        </div>
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('family_accounts') ?></label>
                                            <input type="hidden" class="full-width" id="family_acc"/>
                                        </div>
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('users'); ?></label>
                                            <select  id="users"  class="full-width Account_Code " multiple data-init-plugin="select2">
                                                <?php foreach ($users as $user): ?>
                                                    <option value="<?php echo $user['User_ID']; ?>"><?php echo $user['User_Name']; ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                        <div class="col-md-3 ">
                                            <label><?php echo CommonLanguage::getMessage('Transaction_Type'); ?></label>
                                            <select id ="TypeTrans" class="full-width Transaction" data-init-plugin="select2" >
                                                <option value="All"><?php print CommonLanguage::getMessage('All'); ?></option>
                                                <option value="Credit"><?php print CommonLanguage::getMessage('credit'); ?></option>
                                                <option value="Debit"><?php print CommonLanguage::getMessage('debit'); ?></option>
                                            </select>
                                        </div>

                                    </div>
                                    <div class="row p-15">
                                        <div class="col-md-3">
                                            <label><?php echo CommonLanguage::getMessage('type'); ?></label>
                                            <select id="transaction_type" class="full-width" multiple  data-init-plugin="select2">
                                                <option value=""><?php echo CommonLanguage::getMessage('All') ?></option>
                                                <option value="inv"><?php echo CommonLanguage::getMessage('invoice') ?></option>
                                                <option value="pur"><?php echo CommonLanguage::getMessage('purchase') ?></option>
                                                <option value="pay"><?php echo CommonLanguage::getMessage('payment') ?></option>
                                                <option value="rec"><?php echo CommonLanguage::getMessage('receipt') ?></option>
                                                <option value="mjv"><?php echo CommonLanguage::getMessage('manual_jv') ?></option>
                                                <option value="exp"><?php echo CommonLanguage::getMessage('expense') ?></option>

                                            </select>
                                        </div>
                                        <?php if ($is_actual) { ?>
                                            <div class="col-md-1">
                                                <label><?php print CommonLanguage::getMessage('actual_only'); ?></label>
                                                <input type="checkbox"  id="actual_only" name="actual_only"/>
                                            </div>
                                        <?php } ?>
                                        <!--                                        <div class="col-md-1">
                                                                                    <label><?php print CommonLanguage::getMessage('multi_year'); ?></label>
                                                                                    <input type="checkbox"  id="multi_year" name="multi_year"/>
                                                                                </div>-->
                                    </div>
                                    <div class="row p-15" >
                                        <div class="col-md-2 pull-right">
                                            <button id="Generate_Report" type="button" class="btn btn-complete pull-right" data-toggle="dropdown" aria-expanded="false">
                                                <?php print CommonLanguage::getMessage('generate_report'); ?></button>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>


                    </div>
                </div>
                <div class="col-md-12">
                    <div class="panel panel-default">

                        <div id="TopContainer" >

                            <div class="row Row1 callout callout-info col-md-5 col-xs-5 form-horizontal">
                                <div class="form-group">
                                    <label for="fname" class="col-sm-4 control-label"><?php print CommonLanguage::getMessage('project'); ?></label>
                                    <div class="col-sm-8 col-xs-8">
                                        <input type="hidden" class="full-width" id="project_id"/>

                                    </div>
                                </div>

                            </div>
                            <div class="row Row1 callout callout-info col-md-5 col-xs-5 form-horizontal pull-right" style="margin: 20px;">

                                <div class="form-group hidden" style="padding:0;">
                                    <label for="fname" class="col-sm-4 col-xs-4 control-label"><?php print CommonLanguage::getMessage('opening_balance'); ?></label>
                                    <div class="col-sm-1 col-xs-3" style="margin-top: 6px; font-size: 20px;">
                                        <span class="totalCurr"><?php echo $defCurrencySymbol; ?></span>
                                    </div>  
                                    <div class="col-sm-7">
                                        <span id="PreviousBalance" class="ValueSpan"> 0</span>
                                    </div>
                                </div>
                                <div class="form-group" style="padding:0;">
                                    <label for="fname" class="col-sm-4 col-xs-4 control-label"><?php print CommonLanguage::getMessage('current_balance'); ?></label>
                                    <div class="col-sm-1 col-xs-3" style="margin-top: 6px; font-size: 20px;">
                                        <span class="totalCurr"><?php echo $defCurrencySymbol; ?></span>
                                    </div> 
                                    <div class="col-sm-7">
                                        <span id="Current_Balance" class="ValueSpan"> 0</span>
                                    </div>
                                </div>
                                <div class="form-group hidden" style="padding:0;">
                                    <label for="fname" class="col-sm-4 col-xs-4 control-label"><?php print CommonLanguage::getMessage('overall_balance'); ?></label>
                                    <div class="col-sm-1 col-xs-3" style="margin-top: 6px; font-size: 20px;">
                                        <span class="totalCurr"><?php echo $defCurrencySymbol; ?></span>
                                    </div>  
                                    <div class="col-sm-7">
                                        <span id="OverAll" class="ValueSpan">0</span>
                                    </div>
                                </div>
                            </div>
                            <div style="clear:both"></div>
                        </div>
                        <div class="box-body no-padding">
                            <table class="table table-hover" id="ledgerTable">
                                <thead>
                                    <tr>
                                        <th><?php print CommonLanguage::getMessage('Date'); ?></th>
                                        <th><?php print CommonLanguage::getMessage('jv'); ?>#</th>
                                        <th><?php print CommonLanguage::getMessage($is_activity == 1 ? 'activity' : 'account'); ?></th>
                                        <th><?php echo CommonLanguage::getMessage('check'); ?>&nbsp;#</th>
                                        <th><?php print CommonLanguage::getMessage('ref'); ?>#</th>
                                        <th style="min-width: 70px"><?php print CommonLanguage::getMessage('description'); ?></th>
                                        <th><?php print CommonLanguage::getMessage('debit'); ?></th>
                                        <th><?php print CommonLanguage::getMessage('credit'); ?></th>
                                        <th><?php print CommonLanguage::getMessage('balance'); ?></th>
                                        <?php if (smc_session()['default_setting']['activate_second_currency'] == 1) { ?>
                                            <th><?php print CommonLanguage::getMessage('debit') . ' ' . smc_session()['local_currency_symbol']; ?></th>
                                            <th><?php print CommonLanguage::getMessage('credit') . ' ' . smc_session()['local_currency_symbol']; ?></th>
                                            <th><?php print CommonLanguage::getMessage('balance') . ' ' . smc_session()['local_currency_symbol']; ?></th>
                                            <th><?php print CommonLanguage::getMessage('debit') . ' ' . smc_session()['second_currency']['symbol']; ?></th>
                                            <th><?php print CommonLanguage::getMessage('credit') . ' ' . smc_session()['second_currency']['symbol']; ?></th>
                                            <th><?php print CommonLanguage::getMessage('balance') . ' ' . smc_session()['second_currency']['symbol']; ?></th>
                                        <?php } ?>
                                        <th><?php print CommonLanguage::getMessage('overall_balance'); ?></th>
                                    </tr>
                                </thead>
                                <tbody id="transactions">

                                </tbody>
                            </table>
                        </div>
                    </div>


                </div>
            </div>

        </div>
    </div>
</div>


<script type="text/javascript">
    var TotalLang = <?php echo json_encode(CommonLanguage::getMessage('total')); ?>,
            CurrentTotalLang = <?php echo json_encode(CommonLanguage::getMessage('current_balance')); ?>;
    var general_ledger = <?php echo json_encode(CommonLanguage::getMessage('general_ledger')); ?>;
    var today = <?php echo json_encode($today) ?>,
            fromdate = <?php echo json_encode($from_day) ?>,
            project_id = <?php echo json_encode($project_id) ?>,
            is_actual = <?php echo json_encode($is_actual) ?>;
    var startDate = '', endDate = '';
    var startDueDate = '', endDueDate = '';
    var activate_second_currency = <?php echo json_encode(smc_session()['default_setting']['activate_second_currency']); ?>;

    var org_name = org_head[0]['Organization_Legal_Name'],
            org_phone = org_head[0]['Organization_Phone'],
            org_email = org_head[0]['Organization_Email'],
            org_address = org_head[0]['Name'] + '-' + org_head[0]['Organization_Province'];
    if (!is_actual) {
        $("#transactions").on("click", ".desc", function () {
            var link_id = $(this).parents("tr").attr("data-id"),
                    link_type = $(this).parents("tr").attr("data-type"),
                    link_prefix = $(this).parents("tr").attr("data-prefix"),
                    url = site_link;
            if (link_type == 'inv') {
                url = url + "Inventory/ViewInvoice/" + link_id + "/0?is_pop=1";
            } else if (link_type == 'pur') {
                url = url + "Inventory/ViewInvoice/vendor/" + link_id + "/0?is_pop=1";
            } else if (link_type == 'pay') {
                url = url + "ACC/ViewReceipt/" + link_id + "/" + link_prefix + "?is_pop=1";
            } else if (link_type == 'rec') {
                url = url + "ACC/ViewReceipt/Receipt/" + link_id + "/" + link_prefix + "?is_pop=1";
            } else if (link_type == 'exp') {
                url = url + "ACC/view_expense/" + link_id + "?is_pop=1";
            }
            open_frame_modal(url);
        })
    }

    $(document).ready(function () {
                new Switchery($("#actual_only").get(0), {color: $.Pages.getColor("complete")})

        build_select2($("#project_id"), "ACCAjax/projectSearch", 1)
        build_select2($("#trans_in_currrency"), "xhr/CurrencySearch", 1)
        build_select2($("#multi_accounts"), ("xhr/accIDSearch?type=Payment"), 1)
        build_select2($("#ref_type"), "xhr/CommonSearch?col_id=subtype_abbrv&col_name=subtype_abbrv&table=tbl_accounting_transaction_subtype", 1)
        build_select2($("#family_acc"), "xhr/CommonSearch?col_id=family_id&col_name=family_name&table=tbl_family_accounts", 1)
//        new Switchery($("#multi_year").get(0), {color: $.Pages.getColor("complete")})
        if (project_id != 0) {
            $.ajax({
                url: 'ACCAjax/get_project_by_id',
                method: 'GET',
                data: {id: project_id},
                dataType: 'json',
                complete: function (data, vv) {
                    var mydata = {id: project_id, text: data.responseJSON['project_name']}
                    console.log(mydata)
                    $('#project_id').data().select2.updateSelection(mydata)
//                    $("#project_id").trigger("change");
//                    $("#project_id").val(project_id)./attr("")
AjaxCall();
                }
            })
        }
        $("input[name=range_date]").daterangepicker({
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }, locale: {
                cancelLabel: 'Clear'
            }, allowEmpty: true,
            //            autoApply: true,
            autoUpdateInput: false,
        }, function (start, end, label) {
//            window.startDate = start.format("YYYY-MM-DD"),
//                    window.endDate = end.format("YYYY-MM-DD")
            AjaxCall();
        });
        $('input[name="range_date"]').on('apply.daterangepicker', function (ev, picker) {
            window.startDate = picker.startDate.format('YYYY-MM-DD'),
                    window.endDate = picker.endDate.format('YYYY-MM-DD');
            $(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD'));
        });
        $('input[name="range_date"]').on('cancel.daterangepicker', function (ev, picker) {
            window.startDate = ''
            window.endDate = ''
            $(this).val('');
        });
        $("input[name=range_duedate]").daterangepicker({
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }, locale: {
                cancelLabel: 'Clear'
            }, allowEmpty: true,
            //            autoApply: true,
            autoUpdateInput: false,
        }, function (start, end, label) {
//            window.startDueDate = start.format("YYYY-MM-DD"),
//                    window.endDueDate = end.format("YYYY-MM-DD");
        });
        $('input[name="range_duedate"]').on('apply.daterangepicker', function (ev, picker) {
            window.startDueDate = picker.startDate.format('YYYY-MM-DD'),
                    window.endDueDate = picker.endDate.format('YYYY-MM-DD');
            $(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD'));
        });
        $('input[name="range_duedate"]').on('cancel.daterangepicker', function (ev, picker) {
            window.startDueDate = ''
            window.endDueDate = ''
            $(this).val('');
        });
//                        $(".applyBtn").on("click",function(){
//
//
//
//                            AjaxCall();
//
//                        })
        RebuildDataTable(general_ledger, [0, 2, 3, 4, 5, 6, 7], '', [], '#ledgerTable', [], {bSort: false});

//        $("#CurrencyDropDown .dropdown-menu li").click(function () {
//            setTimeout(function () {
//                AjaxCall();
//            }, 300)
//        })
        $("#project_id").on("change", function () {
            setTimeout(function () {
                AjaxCall();
            }, 300)
        })
        $("#Generate_Report").on("click", function () {
            AjaxCall();
        })

    });
    function FixFloatVal(what) {
        return what.replace(/\.0$|\.00$|\.000$/, "");
    }
    function AjaxCall() {
        var From_Date = startDate, To_Date = endDate, Type = $("#TypeTrans").val(),
                Currency_ID = (parseInt($("#CurrencyDropDown button input").val()));
        $('#ledgerTable').DataTable().destroy();
        $("#ledgerTable  tbody").empty()
//        var project_id = $("#project_id").val();
        var DataArr = {
            From_Date: From_Date,
            To_Date: To_Date,
            Currency_ID: Currency_ID,
            Type: Type,
            actual: is_actual,
            users: $("#users").val(),
            trans_type: $("#transaction_type").val(),
            from_jv: $("#from_jv").val(),
            to_jv: $("#to_jv").val(),
            from_account: $("#from_account").val(),
            to_account: $("#to_account").val(),
            project_ids: $("#project_id").val(),
            multi_accounts: $("#multi_accounts").val(),
            trans_currency: $("#trans_in_currrency").val(),
            from_amount: $("#from_amount").val(),
            to_amount: $("#to_amount").val(),
            ref_type: $("#ref_type").val(),
            family_acc: $("#family_acc").val(),
            is_activity: $("#is_activity").val(),
            due_date_from: startDueDate,
            due_date_to: endDueDate,
            Actual_Only: $("#actual_only").is(":checked") ? 1 : 0,
//            multi_year:$("#multi_year").is(":checked") ? 1 : 0

        }
        $.ajax({
            url: 'ACCAjax/statement_of_project_ajax',
            method: 'GET',
            data: {data: DataArr},
            dataType: 'json',
            complete: function (data, vv) {
                $('#ledgerTable tbody').empty()
                var results = data.responseJSON;
//                console.log(results)
                var results = $.map(
                        data.responseJSON,
                        function (el) {
                            return el;
                        }
                );
                var final_results = results[results.length - 2];
                var overall_results = results[results.length - 1];



                var total_debit = final_results['Debit'];
                var total_credit = final_results['Credit'];
                var Current_Balance = final_results['Current_Balance'];
                var All_Balance = final_results['All_Balance'];
                var Prev_Balance = final_results['Prev_Balance'];
                var Currency = results[results.length - 3];
                //console.log(Currency)
                var Default_Currency = Currency['Currency_Symbol'];
//                $("#PreviousBalance").html(AddCommas(parseFloat(Prev_Balance + "").toXFixed(2)));
                $("#Current_Balance").html(AddCommas(public_round_number(parseFloat(Current_Balance + ""))));
//                $("#OverAll").html(AddCommas(parseFloat(All_Balance + "").toXFixed(2)));

                $('.totalCurr').html(Default_Currency)



//                if(results.length <= 2)
//                    $("#ledgerTable > tbody").append($('<tr class="odd"><td style="display:none"></td><td style="display:none"></td><td style="display:none"></td><td style="display:none"></td><td style="display:none"></td><td style="display:none"></td><td style="display:none"></td><td style="display:none"></td><td valign="top" colspan="9" class="dataTables_empty PrintThisTable">No data available in table</td></tr>'));
                var transactions = '';
                if (results.length > 3) {
                    for (var i = 0; i < (results.length) - 3; i++) {
                        transactions += "<tr data-id='" + results[i]['main_id'] + "' data-type='" + results[i]['main_type'] + "' data-prefix = '" + results[i]['serial_prefix'] + "'>" +
                                "<td>" + results[i]["Transaction_Date"] + "</td>" +
                                "<td>" + results[i]["JV_ID"] + "</td>" +
                                "<td>" + results[i][$("#is_activity").val() == 1 ? "activity_code" : "Transaction_Account"] + ' - ' + results[i][$("#is_activity").val() == 1 ? "activity_title" : "Account_Name"] + "</td>" +
                                "<td>" + (results[i]["check_nb"] && results[i]["check_nb"]!=0 ? results[i]["check_nb"] : '') + "</td>" +
                                "<td>" + results[i]["Ref_ID"] + "</td>" +
                                "<td class='desc' " + (is_actual ? '' : "style='cursor:pointer'") + " > " + results[i]["Transaction_Description"] + "</td>" +
                                "<td>" + Default_Currency + " " + AddCommas(public_round_number(parseFloat(results[i]["Debit"] + ""))) + "</td>" +
                                "<td>" + Default_Currency + " " + AddCommas(public_round_number(parseFloat(results[i]["Credit"] + ""))) + "</td>" +
                                "<td>" + Default_Currency + " " + AddCommas(public_round_number(parseFloat(results[i]['Current_Balance'] + ""))) + "</td>";
                        if (activate_second_currency == 1) {
                            transactions += "<td>" + AddCommas(public_round_number(parseFloat(results[i]["local_debit"]))) + "</td>" +
                                    "<td>" + AddCommas(public_round_number(parseFloat(results[i]["local_credit"]))) + "</td>" +
                                    "<td>" + AddCommas(public_round_number(parseFloat(results[i]["local_balance"]))) + "</td>" +
                                    "<td>" + AddCommas(public_round_number(parseFloat(results[i]["second_debit"]))) + "</td>" +
                                    "<td>" + AddCommas(public_round_number(parseFloat(results[i]["second_credit"]))) + "</td>" +
                                    "<td>" + AddCommas(public_round_number(parseFloat(results[i]["second_balance"]))) + "</td>";
                        }
                        transactions += "<td>" + Default_Currency + " " + AddCommas(public_round_number(parseFloat(results[i]["All_Balance"] + ""))) + "</td>" +
                                "</tr>";


                    }
                    $("#ledgerTable tbody").append($(transactions));
//                    console.log(transactions)
                    var finaltr = "<tr style='color:#4c0870;'><td>&nbsp;</td><td></td><td></td><td></td><td></td><td style='font-size: 1.3em' class='bold'>" + CurrentTotalLang + "</td>" +
                            "<td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(total_debit + ""))) + "</td><td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(total_credit + ""))) + "</td><td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(Current_Balance + ""))) + "</td>";
                    if (activate_second_currency == 1) {
                        finaltr += "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(final_results['local_debit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(final_results['local_credit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(final_results['local_balance']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(final_results['second_debit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(final_results['second_credit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(final_results['second_balance']))) + "</td>";
                    }
                    finaltr += "</td><td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(All_Balance + ""))) + "</td></tr>";

                    $("#ledgerTable > tbody:last").append($(finaltr))
                    var finaltr = "<tr style='color:#4c0870;'><td>&nbsp;</td><td></td><td></td><td></td><td></td><td style='font-size: 1.3em' class='bold'>" + TotalLang + "</td>" +
                            "<td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(overall_results['Debit'] + ""))) + "</td><td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(overall_results['Credit'] + ""))) + "</td><td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(overall_results['Current_Balance'] + ""))) + "</td>";
                    if (activate_second_currency == 1) {
                        finaltr += "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(overall_results['local_debit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(overall_results['local_credit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(overall_results['local_balance']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(overall_results['second_debit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(overall_results['second_credit']))) + "</td>" +
                                "<td style='font-size: 1.3em' class='bold'>" + AddCommas(public_round_number(parseFloat(overall_results['second_balance']))) + "</td>";
                    }
                    finaltr += "</td><td style='font-size: 1.3em' class='bold'>" + Default_Currency + ' ' + AddCommas(public_round_number(parseFloat(overall_results['All_Balance'] + ""))) + "</td></tr>";

                    $("#ledgerTable > tbody:last").append($(finaltr))

                }
                RebuildTable()
            }
        });
    }
    function RebuildTable() {
        RebuildDataTable(general_ledger, [0, 2, 3, 4, 5, 6, 7], '', [], '#ledgerTable', [], {bSort: false});

    }




</script>
