  <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.strftime("%Y-%m-%d %I:%M %p") %></h2>
    </div>

      <!-- 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 origami_cashier">
          <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 origami_cashier">
          <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 origami_cashier">
          <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 origami_cashier">
          <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 origami_cashier">
          <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_format( 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_format( @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_format( @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_format( @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_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 Sales : </td>
                        <% elsif payment.payment_method == 'paymal' %>
                          <td>Card Sales : </td>
                        <% else %>
                          <td><%= payment.payment_method.to_s.capitalize %> Sales : </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 } %>
                  <% if !total_card.nil? %>
                    <tr>
                      <td><%= t("views.right_panel.detail.other_payment") %> : </td>
                      <td align="right">
                        <% total_other_amt = 0 %>
                        <% @sale_data.map { |k,v| k.map{|meth,amt| meth != 'cash' && meth != 'foc' && meth != 'creditnote' ? total_other_amt += amt : meth }} %>
                        <%= total_other_amt %>
                      </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();

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

  var role = '<%= @current_user.role %>';
  var current_shift = '<%= ShiftSale.current_shift %>'
  var food_court = '<%= @food_court %>'

  if ((role == 'administrator' || role == 'manager') && current_shift === "") {
    $(".origami_cashier").on('click', function() {
      swal({
        title: "There is no current open shift!",
        text: "",
        type: "warning",
        showCancelButton: false,
        confirmButtonClass: "btn-info",
        confirmButtonText: "OK",
        closeOnConfirm: true
      });
    });
  } else if (role == 'cashier' && current_shift === "") {
    if (food_court == 1){
      window.location.href = '/foodcourt/shifts/new'
    }else {
      window.location.href = '/origami/shifts/new'
    }

  } else {
    $(".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 = '/foodcourt/food_court#';
    });

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

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

    $(".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';
    });

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

});
</script>
