<style>
    #tableWithSearch thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
    .actionButton{
        background-color:#4c0870;
    }
</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 $title; ?> </h4>
            </div>
            <div class="row">
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                    <div class="input-group">
                        <span class="input-group-addon bg-complete"><i class="fa fa-calendar"></i></span>
                        <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" autocomplete="off" />
                    </div>
                </div> 
                <?php if ($permissions->hasPermission('add_project_expense')) { ?>
                <div class="floatingContainer pull-right">
                    <a href="ACC/project_expense" >
                        <div class="actionButton" >
                            <p class="floatingText"><span class="floatingTextBG"><?php echo CommonLanguage::getMessage('add') ?></span></p>
                        </div>
                    </a>
                </div>
                <?php } ?>
            </div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered table-hover" id="tableWithSearch">
                        <thead>
                            <tr>

                                <th class="text-center" style="width:10%" >#</th>
                                <th class="text-center" style="width:10%" > <?php print CommonLanguage::getMessage('Date'); ?></th>
                                <th class="text-center" style="width:10%" > <?php print CommonLanguage::getMessage('project'); ?></th>
                                <th class="text-center" style="width:10%" > <?php print CommonLanguage::getMessage('supplier'); ?></th>
                                <th class="text-center" style="width:10%" > <?php print CommonLanguage::getMessage('total'); ?></th>
                                <th class="text-center no-print" style="width:5%"><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var today = <?php echo json_encode($today) ?>;
    $(function () {
        var data_session = get_storage_element(page_link);
        if (data_session.Date != '') {
            window.startDate = data_session.from_date;
            window.endDate = data_session.to_date;
            $("input[name=From_To_Date]").val(data_session.Date)
        }
        ChangeTable();
        
        $("#tableWithSearch").on("click", ".delete", function () {
            var entry_value = $(this).parents('.Action').attr('data-id');
            IncludeDeleteModal(common_delete_modal, {project_expense_id:entry_value}, function () {
                ChangeTable();
            }, "ACCAjax/delete_project_expense");
        });
        $("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')]
            }, locale: {
                cancelLabel: 'Clear'
            }, allowEmpty: false,
            autoUpdateInput: false
        });

        $("input[name=From_To_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'));
            ChangeTable();
        });
        $("input[name=From_To_Date]").on('cancel.daterangepicker', function (ev, picker) {
            window.startDate = ''
            window.endDate = ''
            $(this).val('');
            ChangeTable();
        });

    });

    function ChangeTable() {
        var data ={ 
            Date: $("input[name=From_To_Date]").val(),
            from_date: window.startDate,
            to_date: window.endDate};
        set_storage_element(page_link, data)
        RebuildDataTable($('.panel-title h4').html(), [0, 1, 2, 3, 4, 5, 6, 7], 'ACCAjax/project_expense_list',data)
    }
</script>
