<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('history_scheduled_checklist'); ?></div>
            <div class="row">
                <div class=" col-md-3 input-daterange">
                    <label><?php echo CommonLanguage::getMessage('Date');?></label>
                    <input id="history_date" type="text" autocomplete="off" class="form-control" name="history_date" >
                </div>
                <div class="col-md-3">  
                    <label><?php echo CommonLanguage::getMessage('line');?></label>
                    <input  type="hidden" name="line_id" id="line_id" class="full-width"/>
                </div>
                <div class="col-md-3">  
                    <label><?php echo CommonLanguage::getMessage('machine');?></label>
                    <input  type="hidden" name="Product_ID" id="Product_ID" class="full-width"/>
                </div>
                <div class="col-md-3">  
                    <label><?php echo CommonLanguage::getMessage('section');?></label>
                    <input  type="hidden" name="section_id" id="section_id" class="full-width"/>
                </div>
            </div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered maintenance-table" id="tableWithSearch">
                            <thead>
                                <tr>
                                    <th><?php print CommonLanguage::getMessage('schedule') ?></th>
                                    <th><?php print CommonLanguage::getMessage('checklist_name') ?></th>
                                    <th><?php print CommonLanguage::getMessage('line') ?></th>
                                    <th><?php print CommonLanguage::getMessage('machine') ?></th>
                                    <th><?php print CommonLanguage::getMessage('part') ?></th>
                                    <th><?php print CommonLanguage::getMessage('date_time') ?></th>
                                    <th><?php print CommonLanguage::getMessage('Action') ?></th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="view-answers-modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="width:60%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class=" text-left bold"><?php echo CommonLanguage::getMessage('view_answers'); ?></h5>
            </div>
            <div class="modal-body">
                <div class="row m-t-10 questions_main_div">
                    <div id="questions_content">
                    </div>
                </div>
            </div>
            <?php echo Forms::ModalLoader('checklistScheduleAnswersLoader'); ?>
        </div>
    </div>
</div>
<script>
    var startDate = today, endDate = today;
    $(function(){
        build_select2($("#Product_ID"), "xhr/MachinePartSearch?type=1");
        build_select2($("#section_id"), "xhr/CommonSearch?col_name=section_name&col_id=section_id&table=tbl_product_sections");
        build_select2($("#line_id"), "xhr/CommonSearch?col_name=line_name&col_id=line_id&table=tbl_line");

        RebuildDataTable($('.panel-heading .panel-title').html(), [0,1,2,3,4], 'MaintenanceAjax/getScheduleChecklistHistory',{Product_ID:$("#Product_ID").val(),start_date:startDate,end_date:endDate,section_id:$("#section_id").val(),line_id:$('#line_id').val()});
        $('#tableWithSearch').on('click','.view_answers',function(){
            CommonViewById('MaintenanceAjax/getAnswers', {answer_main_id: $(this).attr('data-id')},
                           '#checklistScheduleAnswersLoader', function (response) {
                fillQuestionDetails(response,'#questions_content','.questions_main_div');
            });
        });
        $('#history_date').daterangepicker({locale: {
            format: 'YYYY-MM-DD'
        }, 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");
            RebuildDataTable($('.panel-heading .panel-title').html(), [0,1,2,3,4], 'MaintenanceAjax/getScheduleChecklistHistory',{Product_ID:$("#Product_ID").val(),start_date:startDate,end_date:endDate,section_id:$("#section_id").val(),line_id:$('#line_id').val()});
        });
        $("#Product_ID,#section_id,#line_id").on('change',function(){
            RebuildDataTable($('.panel-heading .panel-title').html(), [0,1,2,3,4], 'MaintenanceAjax/getScheduleChecklistHistory',{Product_ID:$("#Product_ID").val(),start_date:startDate,end_date:endDate,section_id:$("#section_id").val(),line_id:$('#line_id').val()});
        });
    });
</script>