<div class="container-fluid">
<div id="loading_wrapper" style="display:none;">
    <div id="loading"></div>
  </div>
  <div class="block-header">
    <!-- <h2><%= t :dashboard %></h2> -->
    <h2><%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %></h2>
  </div>
  <% if @print_settings.precision.to_i > 0
    precision = @print_settings.precision
  else
    precision = 0
  end
    #check delimiter
    if @print_settings.delimiter
      delimiter = ","
    else
      delimiter = ""
    end
    %>

    <!-- Widgets -->
    <div class="row clearfix">
    <% if @quick_service == '1' %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-10 qs_view">
        <div class="info-box bg-purple">
          <div class="icon" >
            <i class="material-icons">arrow_forward</i>
          </div>
          <div class="text font-20 m-l-5" style="line-height: 80px;"><%= t :quick_service %></div>
        </div>
      </div>
      <% end %>
      <% if @food_court == '1' %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-10 fc_view">
        <div class="info-box bg-pink">
          <div class="icon" >
            <i class="material-icons">arrow_forward</i>
          </div>
          <div class="text font-20 m-l-5" style="line-height: 80px;"><%= @food_court_name %></div>
        </div>
      </div>
      <% end %>
      <% if @dinein_cashier == '1' %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-10 cashier_view">
        <div class="info-box bg-green">
          <div class="icon" >
            <i class="material-icons">arrow_forward</i>
          </div>
          <div class="text font-20 m-l-5" style="line-height: 80px;"><%= t :dine_in_cashier %></div>
        </div>
      </div>
      <% end %>
      <% if @reservation == '1' %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-10 reservation">
        <div class="info-box bg-orange">
          <div class="icon" >
            <i class="material-icons">arrow_forward</i>
          </div>
          <div class="text font-20 m-l-5" style="line-height: 80px;"><%= t :reservation %></div>
        </div>
      </div>
      <% end %>
      <% if @order_reservation == '1' %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-10 order_reservation">
        <div class="info-box bg-blue">
          <div class="icon" >
            <i class="material-icons">arrow_forward</i>
          </div>
          <div class="text font-20 m-l-5" style="line-height: 80px;"><%= t :order_reservation %></div>
        </div>
      </div>
      <% end %>
    </div>
    <!-- #END# Widgets -->
    <% if !@current_user.nil? && @current_user.role != 'waiter' && @setting_flag %>
    <!-- CPU Usage -->
    <div class="row clearfix">

      <% if !@summ_sale.nil? %>

        <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
          <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>
                <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%>
                  <td><%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : </td>
                  <td align="right"><%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : </td>
                  <td align="right"><%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : </td>
                  <td align="right"><%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%></td>
                </tr>
                <tr>
                  <td><%= t("views.right_panel.detail.total") %> <%= t :sale %> : </td>
                  <td align="right"><%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%></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>
                <% if payment.payment_method == 'paypar' %>
                  <td>Redeem Sale : </td>
                <% else %>
                  <td><%= payment.payment_method.to_s.capitalize %> Sale : </td>
                <% end %>
                  <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.other_payment") %> : </td>
                  <td align="right">
                    <%= total_card["card"].to_f %>
                  </td>
                </tr>
                <% end %>

                <% end %>
              </table>
            </div>
          </div>
        </div>
      <% end %>
      <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
        <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 %></td>
              </tr>
              <% end %>
              <% if !@total_takeaway.nil? %>
              <tr>
                <td><%= t("views.right_panel.detail.takeaway") %> : </td>
                <td align="right"><%= @total_takeaway %></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 %></td>
              </tr>
              <% end %>
            </table>
          </div>
        </div>
      </div>
      <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
        <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>
      <% end %>
    </div>
 <button type="button" data-href="<%=origami_second_display_index_path%>" target="_blank" id="second_view" class="btn action-btn bg-blue waves-effect second_view hidden" style="height: 45px">Customer View</button>
 <input type="hidden" name="server_mode" value="<%=ENV["SERVER_MODE"]%>" id="server_mode">
<script>
$(function() {
  $("#loading_wrapper").show();
  getAllMenu();

  $(".cashier_view").on('click', function() {
    window.location.href = '/origami';
  });

  $(".qs_view").on('click', function() {
    var display_type = '<%= @display_type %>';
    if (display_type.length>0) {
      display_type = '<%= @display_type %>';
    }else{
      display_type = null;
    }
    if ($('#server_mode').val() != "cloud" && display_type == 2) {
      document.getElementById('second_view').click();
    }
     window.location.href = '/origami/quick_service';
  });

  $(".fc_view").on('click', function() {
    var display_type = '<%= @display_type %>';
    if (display_type.length>0) {
      display_type = '<%= @display_type %>';
    }else{
      display_type = null;
    }
    if ($('#server_mode').val() != "cloud" && display_type == 2) {
      document.getElementById('second_view').click();
    }
     window.location.href = '/origami/food_court';
  });

  $(".order_reservation").on('click', function() {
     window.location.href = '/origami/order_reservation';
  });

  $("#second_view").on('click', function () {
    var url = $(this).attr("data-href");
    window.open(url,'_blank');
  });

  $(".reservation").on("click", function(){
    window.location.href = '/origami/reservation';
  });
});
</script>
