<div class="container-fluid">
  <div class="block-header">
    <h2><%= t :dashboard %></h2>
  </div>

  <!-- Widgets -->
  <div class="row clearfix">
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
      <div class="info-box bg-cyan hover-expand-effect">
        <div class="icon">
          <i class="material-icons">help</i>
        </div>
        <div class="content">
          <div class="text"><%= t :sale_count %></div>
          <div class="number count-to" data-from="0" data-to="<%= @total_count%>" data-speed="1000" data-fresh-interval="20"></div>
        </div>
      </div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
      <div class="info-box bg-pink hover-expand-effect">
        <div class="icon">
          <i class="material-icons">attach_money</i>
        </div>
        <div class="content">
          <div class="text"><%= t :total_sale %></div>
          <div class="number count-to" data-from="0" data-to="<%= @total_sale%>" data-speed="15" data-fresh-interval="20"></div>
        </div>
      </div>
    </div>

    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
      <div class="info-box bg-light-green hover-expand-effect">
        <div class="icon">
          <i class="material-icons">person_add</i>
        </div>
        <div class="content">
          <div class="text"><%= t :total_credit %></div>
          <div class="number count-to" data-from="0" data-to="<%= @total_credit%>" data-speed="1000" data-fresh-interval="20"></div>
        </div>
      </div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
      <div class="info-box bg-orange hover-expand-effect">
        <div class="icon">
          <i class="material-icons">credit_card</i>
        </div>
        <div class="content">
          <div class="text"><%= t :total_card %></div>
          <div class="number count-to" data-from="0" data-to="<%= @total_card%>" data-speed="1000" data-fresh-interval="20"></div>
        </div>
      </div>
    </div>
  </div>
  <!-- #END# Widgets -->
  <!-- CPU Usage -->

  <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
  <div class="row">
    <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
      <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
          <div class="card">
            <div class="body">
              <h4><i class="material-icons md-24">dashboard</i><%= (t :top) + " " + (t :products) %></h4>
              <!-- <canvas id="top_products" class="col-md-12"></canvas> -->
              <%= pie_chart @top_products %>
            </div>
          </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
          <div class="card">
            <div class="body">
              <h4><i class="material-icons md-24">dashboard</i><%= (t :bottom) + " " + (t :products) %></h4>
              <!-- <canvas id="top_products" class="col-md-12"></canvas> -->
              <%= pie_chart @bottom_products %>
            </div>
          </div>
        </div>
      </div>
          <!-- <div class="row">
          <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="card">
              <div class="body">
                <h4><i class="material-icons md-24">store</i><%= t :inventory %></h4>
                <canvas id="inventory" class="col-md-12"></canvas>
              </div>
            </div>
          </div>
        </div> -->
        <br />
        <div class="row">
          <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
           <div class="card">
            <div class="body">
              <h4><i class="material-icons md-24">av_timer</i><%= (t :hourly) + " " + (t :sale) %></h4>
              <!-- <canvas id="hourly_sales" class="col-md-12"></canvas> -->
              <%= column_chart @hourly_sales %>
            </div>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
          <div class="card">
            <div class="body">
              <h4><i class="material-icons md-24">assignment_ind</i><%= (t :staff) + " " + (t :sale) %></h4>
              <!-- <canvas id="employee_sales" class="col-md-12"></canvas> -->
              <%= column_chart @employee_sales %>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
    <% if !@summ_sale.nil? %>
      <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
          <div class="card">
            <div class="body">
              <h6><%= t :sale %></h6>
              <table class="table">
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.receipt") %> : </td>
                  <td align="right"><%= @summ_sale.total_receipt %></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t :sale %> : </td>
                  <td align="right"><%= @summ_sale.total_amount %></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : </td>
                  <td align="right"><%= @summ_sale.total_discount %></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : </td>
                  <td align="right"><%= @summ_sale.total_tax %></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.grand_total") %> : </td>
                  <td align="right"><%= @summ_sale.grand_total %></td>
                </tr>
              </table>
              <table class="table">
                <% if !(@total_payment_methods.nil?) %>
                  <% @total_payment_methods.each do |payment| %>
                    <% if !@sale_data[0].empty? %>
                      <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %>
                        <tr>
                          <td><%= payment.payment_method.to_s.capitalize %> Sale : </td>
                          <td align="right">
                            <% @sale_data.each do |data| %>
                              <% pay_mth = payment.payment_method %>
                              <%= data[""+pay_mth+""] %>
                            <% end %>
                          </td>
                        </tr>
                      <% end %>
                    <% end %>
                  <% end %>

                  <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %>
                      <% if !total_card.nil? %>
                      <tr>
                        <td><%= t("views.right_panel.detail.card_sale") %> : </td>
                        <td align="right">
                            <%= total_card["card"].to_f %>
                        </td>
                      </tr>
                  <% end %>
                  
                <% end %>
              </table>
            </div>
          </div>
        </div>
      </div>
      <% end %>

      <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
          <div class="card">
            <div class="body">
              <h6><%= t :customer %></h6>
              <table class="table">
                <% if !@total_customer.nil? %>
                  <tr>
                    <td><%= t("views.right_panel.detail.total") %> <%= t :customer %> : </td>
                    <td align="right"><%= @total_customer %></td>
                  </tr>
                <% end %>
                <% if !@total_dinein.nil? %>
                  <tr>
                    <td><%= t("views.right_panel.detail.dine_in") %> : </td>
                    <td align="right"><%= @total_dinein.total_dinein_cus %></td>
                  </tr>
                <% end %>
                <% if !@total_takeaway.nil? %>
                  <tr>
                    <td><%= t("views.right_panel.detail.takeaway") %> : </td>
                    <td align="right"><%= @total_takeaway.total_take_cus %></td>
                  </tr>
                <% end %>
                <% if !@total_other_customer.nil? %>
                  <tr>
                    <td><%= t :customer %> : </td>
                    <td align="right"><%= @total_other_customer.total_cus %></td>
                  </tr>
                <% end %>
                <% if !@total_membership.nil? %>
                  <tr>
                    <td><%= t("views.right_panel.detail.membership") %> : </td>
                    <td align="right"><%= @total_membership.total_memb_cus %></td>
                  </tr>
                <% end %>
              </table>
            </div>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
          <div class="card">
            <div class="body">
              <h6><%= t("views.right_panel.detail.order") %></h6>
              <table class="table">
                <% if !@total_order.nil? %>
                  <tr>
                    <td width="40px"><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.order") %> : </td>
                    <td align="right" width="60px"><%= @total_order.total_order %></td>
                  </tr>
                <% end %>
        
                <% if !@total_accounts.nil? %>
                  <% @total_accounts.each do |account| %>
                    <tr>
                      <td width="40px"><%= account.title %> (Account) : </td>
                      <td align="right" width="60px">
                        <% @account_data.each do |data| %>
                          <% acc = account.title %>
                          <%= data[""+acc+""] %> <% if !data[''+acc+''].nil? %> ( <%= data[''+acc+'_amount'] %> ) <% end %>
                        <% end %>
                      </td>
                    </tr>
                  <% end %>
                <% end %>
                <% if !@top_items.nil? %>
                <tr>
                  <td width="40px"><%= t :top %> <%= t("views.right_panel.detail.item") %> : </td>
                  <td align="right" width="60px"><%= @top_items.item_name %> 
                  <br>(<%= @top_items.item_total_price %>)</td>
                </tr>
                <% end %>
                <% if !@total_foc_items.nil? %>
                  <tr>
                    <td width="40px"><%= t("views.right_panel.detail.total") %> <%= t("views.btn.foc") %> <%= t("views.right_panel.detail.item") %> : </td>
                    <td align="right" width="60px"><%= @total_foc_items.to_int %></td>
                  </tr>
                <% end %>
              </table>
            </div>
          </div>
        </div>
      </div>    
    </div>
  </div>
  <% end %>
</div>