{% extends 'staff/report/base.html' %}
{% load i18n %}
{% block opts_modify %}
    var hide_fields = ['nick_name', 'position_code', 'position_name', 'dept_code', 'timetable']
    var baseCols = [
    {field:'emp_code', width:120, title: "{% trans 'report_column_empCode' %}", sort: true}
    ,{field:'first_name', title: "{% trans 'report_column_firstName' %}", width:120}
    ,{field:'last_name', title: "{% trans 'report_column_lastName' %}", width:120}
    ,{field:'nick_name', title: "{% trans 'report_column_nickName' %}", width:120}
    ,{field:'gender', width:80, title: "{% trans 'report_column_gender' %}", width:60}
    ,{field:'dept_code', title: "{% trans 'report_column_departmentCode' %}", width:60}
    ,{field:'dept_name', width:140, title: "{% trans 'report_column_departmentName' %}", width:120}
    ,{field:'position_code', title: "{% trans 'report_column_positionCode' %}", width:60}
    ,{field:'position_name', title: "{% trans 'report_column_positionName' %}", width:120}
    ,{field:'att_date', width:80, title: "{% trans 'report_column_attendanceDate' %}", sort: true}
    ,{field:'timetable', title: "{% trans 'report_column_timetable' %}"}
    ,{field:'total_time', title: "{% trans 'report_column_summaryTotalTimeDuration' %}", width:100}
  ];
  var _cols = $.extend(true, [], baseCols);
  var periodCount = 1;
    $.ajax({
        type: "GET",
        url: '/att/api/mulBreakTimeReport/period_count/',
        cache:false,
        async:false,
        dataType: "json",
        success: function(response, xhr){
            periodCount = response.data;
        }
    });
    for(var i=0; i < periodCount; i ++){
      _cols.push({field:'break_out'+i, title: "{% trans 'report_column_breakOutTime' %}", width:100});
      _cols.push({field:'break_in'+i, title: "{% trans 'report_column_breakInTime' %}", width:100});
      _cols.push({field:'total_time'+i, title: "{% trans 'report_column_totalTimeDuration' %}", width:80});
    }
  $.extend(opts, {
      cols: [_cols]
      ,method: "get"
      ,url: "/att/api/mulBreakTimeReport/"
  });
{% endblock %}
{% block columns_modify %}
   var periodCount = 1;
    $.ajax({
        type: "GET",
        url: '/att/api/mulBreakTimeReport/period_count/',
        data: c,
        cache:false,
        async:false,
        dataType: "json",
        success: function(response, xhr){
            periodCount = response.data;
        }
    });
    _cols = $.extend(true, [], baseCols);
    for(var i=0; i < periodCount; i ++){
      _cols.push({field:'break_out'+i, title: "{% trans 'report_column_breakOutTime' %}", width:100});
      _cols.push({field:'break_in'+i, title: "{% trans 'report_column_breakInTime' %}", width:100});
      _cols.push({field:'total_time'+i, title: "{% trans 'report_column_totalTimeDuration' %}", width:80});
    }
    $.extend(opts, {
        cols: [_cols]
        ,method: "get"
        ,url: "/att/api/mulBreakTimeReport/"
        ,where: c
        ,page: {curr: 1}
    });
    table.reload(tb.config.id, opts)

    var export_headers =[];
    var report_headers = tb.config.cols[0];
    var url = '/att/api/mulBreakTimeReport/export/?';
    report_headers.forEach(function (item) {
        if (item.hide === false)
            export_headers.push(item.field)
    })
    url += 'start_date=' + c.start_date + '&end_date=' + c.end_date
        +'&export_headers=' + export_headers;
    $("#{{model_name}}_fluid" + " div.grid-toolbar").actions({
        container: "#{{model_name}}_fluid",
        actionContainer: "#{{model_name}}_fluid" + " div.grid-toolbar",
        model: "{{model_name}}",
        table: table,
        tableId: "id_grid_{{model_name}}",
        form: form,
        element: element,
        curTable: tb,
        gridOpts: "",
        actions: "",
        export_url: url,
        disabled_fields_url: "",
        init_disabled_fields: [],
        dimension: {height: "auto", width: "auto"},
        disabled_action_panel_east: ["history"],
        prefer_best_fit_op: 'best_fit',
        callback: {}
      });
    form.on("submit({{ model_name }}-search)", function (data) {
        refreshReport('');
    });
{% endblock %}