<%= render partial: 'tech_bonuses/styles' %> <% report = @report %> <% previous_week = @week - 1 %> <% next_week = @week + 1 %>
<%= link_to "« #{previous_week.label}", tech_bonus_week_path(previous_week.to_param) %> <% if next_week.start_date <= Date.current %> | <%= link_to "#{next_week.label} »", tech_bonus_week_path(next_week.to_param) %> <% end %> | <%= link_to sprite_icon('time', l(:label_tech_bonus_time_report)), report_time_entries_path(report.redmine_report_params), class: 'icon icon-time' %>

<%= link_to l(:label_tech_bonus_plural), tech_bonuses_path %> » <%= bonus_week_title(@week) %>

<%= l(:label_tech_bonus_total_hours) %> <%= bonus_hours(report.total_hours) %>
<%= l(:label_tech_bonus_goal_hours) %> <%= bonus_hours(report.goal_hours) %>
<%= l(:label_tech_bonus_tiers) %> <%= report.tiers %> <%= l(:text_tech_bonus_tier_every, hours: bonus_hours(report.tier_hours)) %>
<% if report.goal_met? %> <%= l(:label_tech_bonus_next_tier) %> <% else %> <%= l(:label_tech_bonus_short_of_goal) %> <% end %> <%= bonus_hours(report.hours_to_next_tier) %>
<% unless @week.completed? %>

<%= l(:text_tech_bonus_week_in_progress, date: format_date(@week.end_date)) %>

<% end %>

<%= l(:label_tech_bonus_technicians) %>

<% if report.lines.empty? %>

<%= l(:text_tech_bonus_no_technicians) %> <% if User.current.admin? %><%= link_to l(:label_bonus_technician_new), new_bonus_technician_path %><% end %>

<% else %> <%= form_tag tech_bonus_week_path(@week.to_param), method: :post, id: 'tech-bonus-run' do %>
<% report.lines.each do |line| %> <% tech = line.technician %> <% credit = @credits[tech.user_id] %> <% credited = credit&.credited? %> <% if credited %> <% else %> <% end %> <% end %>
<%= l(:label_user) %> <%= l(:field_role) %> <%= l(:label_tech_bonus_hours) %> <%= l(:label_tech_bonus_attended) %> <%= l(:label_tech_bonus_base) %> <%= l(:label_tech_bonus_tier_bonus) %> <%= l(:label_tech_bonus_amount) %> <%= l(:label_tech_bonus_credit_memo) %> <%= l(:field_status) %>
<%= link_to_user tech.user %> <% if @can_run %>
<%= tech.customer&.name || l(:text_tech_bonus_no_customer) %><% end %>
<%= tech.role_name %> <%= bonus_hours(line.hours) %> <% if credited %> <%= sprite_icon('checked', l(:general_text_Yes)) %> <% elsif @can_run && line.eligible? %> <%= check_box_tag 'attended[]', tech.user_id, credit.nil? || credit.message != l(:text_tech_bonus_missed_shift), id: "attended_#{tech.user_id}", disabled: !report.goal_met? %> <% end %> <%= bonus_money(credit.base_amount) %> <%= bonus_money(credit.tier_amount) %> <%= bonus_money(credit.amount) %><%= bonus_money(line.base_amount) %> <%= bonus_money(line.tier_amount) %> <%= bonus_money(line.amount) %><%= @can_run ? credit_memo_link(credit) : (credit&.doc_number.presence && "##{credit.doc_number}") %> <%= bonus_status_tag(credit) %> <% message = credit&.message.presence || line.ineligible_reason %> <% if @can_run && credit&.emailed_to.present? %>
<%= credit.emailed_to %><% end %> <% if message %>
<%= message %><% end %>
<% if credited && @can_run %> <%= link_to sprite_icon('email', l(:button_tech_bonus_resend)), resend_tech_bonus_credit_path(credit), method: :post, class: 'icon icon-email', data: { confirm: l(:text_tech_bonus_resend_confirm) } %> <% end %>
<% if @can_run %>

<%= l(:text_tech_bonus_attendance) %>

<% end %> <% if @can_run && @week.completed? %>

<% label = report.goal_met? ? l(:button_tech_bonus_run) : l(:button_tech_bonus_record) %> <%= submit_tag label, data: { confirm: report.goal_met? ? l(:text_tech_bonus_run_confirm) : nil } %> <% if @bonus_week %> <%= l(:text_tech_bonus_already_run, user: @bonus_week.run_by&.name, time: format_time(@bonus_week.updated_at)) %> <% end %>

<% end %> <% end %> <% end %>

<%= l(:label_tech_bonus_shop_hours) %>

<% if report.hours_by_user.empty? %>

<%= l(:label_no_data) %>

<% else %> <% tech_ids = report.technicians.map(&:user_id) %>
<% report.hours_by_user.each do |user_id, hours| %> <% end %>
<%= l(:label_user) %><%= l(:label_tech_bonus_hours) %>
<%= report.users[user_id] ? link_to_user(report.users[user_id]) : "##{user_id}" %> <% unless tech_ids.include?(user_id) %>(<%= l(:text_tech_bonus_helping) %>)<% end %> <%= bonus_hours(hours) %>
<%= l(:label_total_time) %><%= bonus_hours(report.total_hours) %>
<% end %> <% html_title "#{l(:label_tech_bonus_plural)} #{@week.label}" %>