<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print $title; ?></div>
        </div>
        <div class="panel-body">
            <div class="row form-group">
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                    <div class="input-group">
                        <span class="input-group-addon bg-primary"><i class="fa fa-calendar"></i></span>
                        <input id="From_To_Date" type="text" class="form-control" name="From_To_Date">
                    </div>
                </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 class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered inventory" id="tableWithSearch">
                            <thead>
                                <tr>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('Code'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('product_name'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('returned_quantity'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('Damaged_Quantity'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('UOM'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('total_price') . ' (' .  smc_session()['local_currency_symbol'] . ')'; ?></th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var today = <?php echo json_encode($today) ?>,
        is_actual = <?php echo json_encode($is_actual ? 1 : 0); ?>;
    $(function() {
        build_select2($("#search_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");
        $('#search_branch_id').on('change', function () {
            ajaxTable();
        });

        ajaxTable();
        $("input[name=From_To_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')]
            }
        }, function(start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                window.endDate = end.format("YYYY-MM-DD")
            ajaxTable()
        });
    });

    function ajaxTable() {
        var Data = {
            from_date: window.startDate ? window.startDate : today,
            to_date: window.endDate ? window.endDate : today,
            is_actual: is_actual,
            search_branch_id: $('#search_branch_id').val()
        };
        RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'InventoryAjax/return_damage_report', Data);
    }
</script>