<div class="container-fluid">
<div id="loading_wrapper" style="display:none;">
  <div id="loading"></div>
</div>
<div class="row">
 <!-- Column One -->
 <div class="col-lg-6 col-md-6 col-sm-6">

   <!-- Nav tabs -->
   <ul class="nav nav-tabs tab-col-teal" role="tablist" id="mytab">
   <li class="nav-item">
       <a class="nav-link" data-toggle="tab" href="#completed" role="tab"><%= t :competed %></a>
     </li>
     <li class="nav-item">
       <a class="nav-link " data-toggle="tab" href="#tables" role="tab"><%= t :tables %></a>
     </li>
     <li class="nav-item">
       <a class="nav-link active" data-toggle="tab" href="#rooms" role="tab"><%= t :rooms %></a>
     </li>
     <li class="nav-item">
       <a class="nav-link" data-toggle="tab" href="#orders" role="tab"><%= t :orders %></a>
     </li>
      <li class="nav-item credit_items">
        <a class="nav-link" data-toggle="tab" href="#credits" role="tab"><%= t :credits %></a>
      </li>
   </ul>
   <!-- Nav tabs - End -->
   <div id="custom-slimscroll">
     <div class="tab-content m-t-10" >
       <!--- Panel 0 - Completed Orders -->
       <div class="tab-pane dining" id="completed" role="tabpanel">
         <div class="card-columns">
           <% @complete.each do |sale| %>
           <div class="card sales red text-white" data-id = "<%= sale.sale_id %>">
             <div class="card-block">
                <%= sale.receipt_no %><span style="font-size:12px;float:right;line-height:inherit;"><%= sale.sale_status %></span>
             </div>
           </div>
           <% end %>
         </div>
       </div>

       <!--- Panel 1 - Table Orders -->
       <div class="tab-pane dining" id="tables" role="tabpanel">
         <div class="card-columns">
           <% @tables.each do |table| %>
           <% if table.status == 'occupied' %>
              <% if table.get_booking.nil? %>
                <% if table.get_checkout_booking.nil? %>
                  <div class="card tables red text-white table_<%= table.id %>" data-id="<%= table.id %>">
                <% else %>
                  <div class="card tables orange text-white table_<%= table.id %>" data-id="<%= table.id %>">
                <% end %>
                    <div class="card-block">
                      <%= table.name %> <br>
                      <%= table.zone.name %>
                      <!-- <% if !@order_items_count.nil? %>
                        <% if @order_items_count.key?(table.id) %>
                          (Orders : <%= @order_items_count[table.id] %>)
                        <% end %>
                      <% end %> -->
                         <span class="float-right font-12 new_text_<%= table.id %>"> billed</span>
                    </div>
                  </div>
              <% else %>
                  <% if table.get_checkout_booking.nil? %>
                    <div class="card tables blue text-white table_<%= table.id %>" data-id="<%= table.id %>">
                  <% else %>
                    <div class="card tables orange text-white table_<%= table.id %>" data-id="<%= table.id %>">
                  <% end %>
                    <div class="card-block">
                      <%= table.name %> <br>
                      <%= table.zone.name %>
                       <!-- <% if !@order_items_count.nil? %>
                        <% if @order_items_count.key?(table.id) %>
                          (Orders : <%= @order_items_count[table.id] %>)
                        <% end %>
                      <% end %> -->
                         <span class="float-right font-12 new_text_<%= table.id %>"> new</span>
                    </div>
                  </div>
              <% end %>
           <% else %>
           <div class="card tables green text-white table_<%= table.id %>" data-id="<%= table.id %>">
             <div class="card-block">
              <%= table.name %> <br>
              <%= table.zone.name %>
              <span class="float-right font-12 new_text_<%= table.id %> hide">
             </div>
           </div>
           <% end %>
           <% end %>
         </div>
       </div>

       <!--- Panel 2 - Room Orders -->
       <div class="tab-pane dining active" id="rooms" role="tabpanel">
         <div class="card-columns">
           <% @rooms.each do |room| %>
           <% if room.status == 'occupied' %>

             <% if room.get_booking.nil? %>
                <% if room.get_checkout_booking.nil? %>
                 <div class="card rooms red text-white table_<%= room.id %>" data-id="<%= room.id %>">
                <% else %>
                 <div class="card rooms orange text-white table_<%= room.id %>" data-id="<%= room.id %>">
                <% end %>
                   <div class="card-block">
                      <%= room.name %> <br>
                      <%= room.zone.name %>
                      <!-- <% if !@order_items_count.nil? %>
                        <% if @order_items_count.key?(room.id) %>
                          (Orders : <%= @order_items_count[room.id] %>)
                        <% end %>
                      <% end %> -->
                      <span class="float-right font-12 new_text_<%= room.id %>"> billed</span>
                      <div  style="font-size:12px;"></div>
                   </div>
                 </div>
             <% else %>
                <% if room.get_checkout_booking.nil? %>
                 <div class="card rooms blue text-white table_<%= room.id %>" data-id="<%= room.id %>">
                <% else %>
                 <div class="card rooms orange text-white table_<%= room.id %>" data-id="<%= room.id %>">
                <% end %>
                   <div class="card-block">
                      <%= room.name %> <br>
                      <%= room.zone.name %>
                      <!-- <% if !@order_items_count.nil? %>
                        <% if @order_items_count.key?(room.id) %>
                          (Orders : <%= @order_items_count[room.id] %>)
                        <% end %>
                      <% end %> -->
                      <span class="pull-right font-12 new_text_<%= room.id %>"> new</span>
                   </div>
                 </div>
             <% end %>
           <% else %>
           <div class="card rooms green text-white table_<%= room.id %>" data-id="<%= room.id %>">
             <div class="card-block">
                <%= room.name %> <br>
                <%= room.zone.name %>
                <span class="pull-right font-12 new_text_<%= room.id %> hide">
             </div>
           </div>
           <% end %>
           <% end %>
         </div>
       </div>

       <!--- Panel 3 - Orders -->
       <div class="tab-pane dining" id="orders" role="tabpanel">
         <div class="card-columns">
           <% @orders.each do |order| %>
             <div class="card orders <%=(order.status=="new") ? 'blue' : 'red'%> text-white" data-id="<%= order.order_id %>">
              <div class="card-block">
                <%
                  order_status = ""
                  sale_order = order.sale_orders.first
                  if sale_order
                    unless sale_order.sale_id.nil?
                      sale = Sale.find(sale_order.sale_id)
                      order_status = sale.sale_status
                      if order_status == 'new'
                        order_status  = order.status
                      end
                    end
                  else
                    order_status = order.status
                  end
                %>
                <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %>
              </div>
            </div>
           <% end %>
         </div>
       </div>

       <!-- Credit Item Lists-->
        <div class="tab-pane dining" id="credits" role="tabpanel">
          <div class="card-block">
            <div class="row m-t-10 m-l-10 clearfix">
              <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                <input type="text" name="filter" id="filter" style="height: 32px;" placeholder="Receipt No." class="form-control" onchange="getCreditData('cashier');">
              </div>
              <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                <select class="form-control" id="sel_customer" name="sel_customer" placeholder="Select Customer" onchange="getCreditData('cashier');" >
                  <option value="">-- Select Customer --</option>
                  <% if !@customers.empty? %>
                  <% @customers.each do |cus| %>
                  <option value="<%= cus[0] %>"><%= cus[1] %></option>
                  <% end %>
                  <% end %>
                </select>
              </div>
            </div>
            <div class="row clearfix m-t-20 m-l-10">
              <table class="table table-responsive tbl_credit_lists">
                <thead>
                  <th><%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %></th>
                  <th><%= t("views.right_panel.detail.receipt_no") %></th>
                  <th> <%= t :cashier %></th>
                  <th> <%= t :customer %></th>
                  <th> <%= t("views.right_panel.detail.credit_amount") %> </th>
                </thead>
                <tbody class="tbd_credit_lists"></tbody>
              </table>
            </div>
          </div>
        </div>
     </div>
   </div>
   <!-- tabs - End -->
 </div>
 <!-- Column One -->

 <!-- Column Two -->
  <div class="col-lg-5 col-md-5 col-sm-5">
     <div class="card"  >
        <% existing_class = "" %><% existing_order = false %>
        <% if @status_sale == 'sale'
          unless @order_items.nil? || @order_items.empty?%>
              <% existing_class = "existing_invoice"%>
              <% existing_order = true %>
              <% tooltip = ' data-toggle=modal title=Add_To_Existing data-target=#invoiceModal'%>
          <%end%>
        <%end%>
        <div class="card-header <%= existing_class %>" <%= tooltip %>>
         <% if @status_order == 'order' && @status_sale != 'sale' %>
          <% if !@obj_order.nil? %>
            <div id="save_order_id" data-order="<%= @obj_order.order_id %>">
          <% else %>
            <div id="save_order_id" data-order="">
          <% end %>
            <strong id="order-title">ORDER DETAILS </strong> |  Table <%= @room.name rescue "" %>
            <% if @booking.checkout_by.nil? && !@booking.reserved_by.nil? && %>
              <span class="float-right"><%= @booking.checkin_at.strftime("%I:%M %p") %> - <%= @booking.checkout_at.strftime("%I:%M %p") %></span>
            <% else %>
              <span class="float-right">Checkin Time : <%= @booking.checkin_at.strftime("%I:%M %p") %></span>
            <% end %>
            </div>

         <% elsif @status_sale == 'sale' %>
            <div><strong id="order-title">INVOICE DETAILS </strong> |  Table <%= @room.name rescue "" %>
            <% if @booking.checkout_by.nil? && !@booking.reserved_by.nil? && %>
              <span class="float-right"><%= @booking.checkin_at.strftime("%I:%M %p") %> - <%= @booking.checkout_at.strftime("%I:%M %p") %></span>
            <% else %>
              <span class="float-right">Checkin Time : <%= @booking.checkin_at.strftime("%I:%M %p") %></span>
            <% end %>
            </div>
          <% else %>
            <strong id="order-title">ORDER DETAILS </strong> | Room <%= @room.name rescue "" %>
         <% end %>

       </div>
       <div class="card-block">
         <div class="card-title row p-l-5 p-r-5">
           <% if (!@sale_array.empty?) && (!@date.nil?) %>
              <div class="col-lg-8 col-md-8 col-sm-8">
                &nbsp; Receipt No: <span id="receipt_no">
                   <% if @status_sale == 'sale' %>
                    <%= @sale_array[0].receipt_no rescue '' %>
                   <% end %>
                 </span>
                 <br>
              </div>
              <div class="col-lg-4 col-md-4 col-sm-4 text-right">
                Date: <span id="receipt_date"><%= @date.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %></span>
                <br>
              </div>
            <% elsif !@date.nil? %>
              <div class="col-lg-7 col-md-7 col-sm-7">
                &nbsp; Order No: <span id="order_no">
                   <% if @status_order == 'order' %>
                     <%= @obj_order.order_id rescue '' %>
                   <% end %>
                 </span>
                 <br>
              </div>
              <div class="col-lg-5 col-md-5 col-sm-5 text-right">
                Date: <span id="receipt_date"><%= @date.strftime("%d/%m/%Y") rescue '-' %></span>
                <br>
              </div>
            <% end %>
         </div>
         <div class="card-title row customer_detail p-l-5 p-r-5" >
           <div class="col-lg-6 col-md-6 col-sm-6">
             <% if @status_sale == 'sale' %>
              <p class="hidden customer-id"><%= @sale_array[0].customer_id rescue '' %></p>
              &nbsp; Customer : <%= @sale_array[0].customer.name rescue '' %>
              <% elsif @status_order == 'order'
              %>
              <p class="hidden customer-id"><%= @customer.customer_id rescue "" %></p>
              &nbsp; Customer : <%= @customer.name rescue "" %>
              <% end %>
           </div>

         </div>
         <div id="order-detail-slimscroll" data-height="<%= @status_sale=="sale" ? 240 : 160%>">
           <div class="card-text">
             <table class="table table-striped" id="order-items-table">
               <thead>
                 <tr>
                   <th>#</th>
                   <th class="item-name">Items</th>
                   <th class="item-attr">QTY</th>
                   <th class="item-attr">Price</th>
                 </tr>
               </thead>
               <tbody>
                 <%
                   count = 0
                   sub_total = 0
                   if @status_sale == "sale"
                    @sale_array[0].sale_items.each do |sale_item|

                      sub_total = sub_total + sale_item.price
                 %>
                 <input type="hidden" id="sale_id" value="<%= @sale_array[0].sale_id %>">
                 <%
                 # Can't check for discount
                  # unless sale_item.price == 0
                      count += 1
                  %>
                 <tr>
                   <td><%= count %></td>
                   <td class='item-name'><%= sale_item.product_name %></td>
                   <td class='item-attr'><%= sale_item.qty %></td>
                   <td class='item-attr'><%= sale_item.price %></td>
                 </tr>

                 <%

                       # end
                     end
                   end

                   if @status_order == 'order' && @status_sale != 'sale'
                      unless @order_items.nil? || @order_items.empty?
                         count = 0
                      @order_items.each do |order_item |
                        set_item_prices = 0
                        count += 1
                        sub_total = sub_total + (order_item.price * order_item.qty)

                  # unless order_item.price == 0 %>
                     <tr class="<%= @edit_order_origami== true ? 'edit_order' : ''%>" data-id='<%= order_item.order_items_id %>'>
                       <td><%= count %></td>
                       <td class='item-name'>
                        <%= order_item.item_name %>
                        <% if !order_item.options.nil? && !order_item.options.empty? && order_item.options != "undefined" %>
                          <% JSON.parse(order_item.options).each do |option| %>
                            <br><span class="font-13">
                              <%= option %>
                            </span>
                          <% end %>
                        <% end %>

                        <% if !order_item.set_menu_items.nil?
                          JSON.parse(order_item.set_menu_items).each do |item_instance|
                            set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %>
                          <br><span class="font-13">
                            <%= item_instance["item_instance_name"] %>
                              <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %>
                                <% (item_instance["options"]).each do |set_item_option| %>
                                  <br><span class="font-13">
                                    <%= set_item_option %>
                                  </span>
                                <% end %>
                              <% end %>
                            </span>
                        <% end
                          sub_total += set_item_prices
                        end %>
                        </td>
                       <td class='item-attr'><%= order_item.qty %></td>
                       <td class='item-attr'><%= (order_item.qty*order_item.price).to_f + set_item_prices %></td>
                     </tr>
                 <%

                       # end
                      end
                     end
                   end
                 %>
               </tbody>
             </table>
           </div>
         </div>
         <div class="card-footer">
           <table class="table" id="order-charges-table" border="0">
             <tr>
               <td class="charges-name"><strong>Sub Total:</strong></td>
               <td class="item-attr"><strong id="sub-total"><%= sub_total %></strong></td>
             </tr>
             <tr>
               <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%>
                <td class="charges-name"><strong>Member Discount:</strong></td>
               <%else%>
                <td class="charges-name"><strong>Discount:</strong></td>
               <%end%>

               <td class="item-attr"><strong id="order-discount">(<%= @obj_sale.total_discount rescue 0%>)</strong></td>
             </tr>
            <% if @status_sale == "sale" %>
             <tr>
               <td class="charges-name"><strong>
               <% if !@sale_taxes.empty? %>
               <input type="hidden" name="" id="check_tax" value="all">
                Tax:
                (<% @i = 0
                 @sale_taxes.each do |ct| %>
                    <%=ct.tax_name%>
                   <% if @sale_taxes.count != @i+1%>
                    +       <% @i =+1 %>
                   <%end%>
                  <%end %>)
                <% else %>
                <input type="hidden" name="" id="check_tax" value="">
                  No Tax
                <% end %></strong><br>
                <%if !@webview && @changable_tax %>
                  <button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button>
                <% end %>
              </td>
               <td class="item-attr"><strong id="order-Tax"><%= @obj_sale.total_tax rescue 0%></strong></td>
             </tr>
              <tr>
               <td class="charges-name"><strong>Rounding Adj:</strong></td>
               <td class="item-attr"><strong id="order-round-adj"><%= @obj_sale.rounding_adjustment rescue 0%></strong></td>
             </tr>
             <tr>
               <td class="charges-name"><strong>Grand Total:</strong></td>
               <td class="item-attr"><strong id="order-grand-total"><%= @obj_sale.grand_total rescue 0%></strong></td>
             </tr>
              <% end %>
              <tr class="rebate_amount"></tr>
           </table>
         </div>
         <br>
          <%
            if @status_sale == 'sale'
                unless @order_items.nil? || @order_items.empty?
                  %>
                  <!-- Pending New Order
                   <table class="table table-striped">
                  <%
                  count = 0
                  @order_items.each do |order_item |
                    set_item_prices = 0
                    count += 1
                  %>
                    <tr class="<%= @edit_order_origami== true ? 'edit_order' : ''%>" data-id='<%= order_item.order_items_id %>'>
                      <td><%= count %>
                      <td class='item-name'>
                        <%= order_item.item_name %>
                        <% if !order_item.options.nil? && !order_item.options.empty? && order_item.options != "undefined" %>
                          <% JSON.parse(order_item.options).each do |option| %>
                            <br><span class="font-13">
                              <%= option %>
                            </span>
                          <% end %>
                        <% end %>

                       <% if !order_item.set_menu_items.nil?  && order_item.set_menu_items != '[]'
                          JSON.parse(order_item.set_menu_items).each do |item_instance|
                            set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f
                        %>
                          <br><span class="font-13">
                            <%= item_instance["item_instance_name"] %>
                              <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %>
                                <% (item_instance["options"]).each do |set_item_option| %>
                                  <br><span class="font-13">
                                    <%= set_item_option %>
                                  </span>
                                <% end %>
                              <% end %>
                            </span>
                        <% end
                          sub_total += set_item_prices
                        end %>
                      </td>
                      <td class='item-attr'><%= order_item.qty %></td>
                      <td class='item-attr'><%= (order_item.qty*order_item.price).to_f + set_item_prices %></td>
                    </tr>

                  <%
                   end
                   %>
                     </table>
                    <button class='btn bg-primary btn-block' id='add_invoice'> Add to existing invoice </button>-->
                   <% end %>
                   <% if @sale_array.size > 1 %>
                   <br><br>
                    Pending Payment
                    <% end %>
                    <% @sale_array.each do |sale|
                      if @sale_array.size > 1
                      unless sale.receipt_no == @sale_array[0].receipt_no
                      %>

                        <table class="table table-striped">
                          <tr>
                            <td>Receipt No - <%= sale.receipt_no %></td>
                            <td><button class='btn btn-sm bg-blue invoicedetails' id="<%= sale.sale_id %>">Show Detail </button></td>
                          </tr>
                        </table>
                      <%
                       end
                     end
                  end
                end
          %>

       </div>
     </div>
  </div>

 <!-- Column Three -->
 <div class="col-lg-1 col-md-1 col-sm-1">
   <!-- Waiter Buttons -->
   <button type="button" class="btn btn-default btn-block" id='back'><i class="material-icons">reply</i> Back</button>
   <button type="button" id="add_order" class="btn btn-block btn- bg-blue waves-effect">Add Order</button>
   <button type="button" id="survey" class="btn btn-block bg-blue waves-effect">Survey</button>
   <% if @room.status != "available" %>
      <% if @status_order == 'order' && @status_sale != 'sale' %>
       <!-- <button type="button" class="btn bg-blue btn-block" >Add Order</button> -->
       <!-- <button type="button" id="customer" class="btn bg-blue btn-block" disabled>Customer</button> -->
       <!-- <button type="button" class="btn bg-blue btn-block" disabled >Edit</button> -->
       <!-- <button type="button" id="discount" class="btn bg-blue btn-block" disabled >Discount</button> -->
        <!-- <button type="button" id="other-charges" class="btn bg-blue btn-block" disabled>Charges</button> -->
        <% if !@order_items.empty? %>
          <button type="button" id="customer" class="btn bg-blue btn-block" >Customer</button>
        <% end %>
       <button type="button" class="btn bg-blue btn-block" id='move'>Move</button>
       <button type="button" id="in_duties" class="btn btn-block bg-blue waves-effect">In Duties</button>
       <button type="button" id="request_bills" class="btn bg-blue btn-block">Req.Bill</button>
        <% if !@split_bill.nil? %>
          <% if @split_bill == '1' && (!(@order_items.nil?) || !(@order_items.empty?)) %>
            <button type="button" id="split_bills" class="btn btn-block bg-blue waves-effect">Split Bill</button>
          <% end %>
        <% end %>
       <!-- <button type="button" id="first_bill" class="btn bg-blue btn-block" disabled>First Bill</button> -->
       <!-- <button type="button" id="pay" class="btn bg-blue btn-block" disabled>Pay</button> -->
       <!-- <button type="button" class="btn bg-blue btn-block" disabled=""> Void </button> -->
      <% end %>
      <% if @status_sale == 'sale' %>
        <!-- <button type="button" class="btn bg-blue btn-block" disabled>Add Order</button> -->
        <button type="button" id="customer" class="btn bg-blue btn-block" >Customer</button>
        <% if current_login_employee.role != "waiter" %>
          <button type="button" id="commissions" class="btn btn-block bg-blue waves-effect">Commissions</button>
          <button type="button" id="in_duties" class="btn btn-block bg-blue waves-effect">In Duties</button>
          <% if current_login_employee.role == "cashier" %>
          <a class="btn btn-block bg-blue waves-effect access_modal" data-toggle="modal"   data-type="edit">Edit</a>
          <a class="btn btn-block bg-red waves-effect access_modal" data-toggle="modal"  data-type="void"> Void</a>
          <% else %>
          <button type="button" class="btn btn-block bg-blue waves-effect" id='edit' <%= (can? :edit, :sale_edit)? ' ': 'disabled=' %> active="true">Edit</button>
           <button type="button" class="btn btn-block bg-red waves-effect" data-toggle="modal" data-target="#voidModal" <%= (can? :overall_void, :void)? ' ': 'disabled=' %> > Void</button>
          <% end %>
          <!-- <button type="button" class="btn btn-block bg-blue waves-effect" data-toggle="modal" data-target="#waste_spoileModal" > Waste & Spoile</button> -->
        <% end %>
        <button type="button" id="discount" class="btn btn-block bg-blue waves-effect" <%= (can? :index, :discount)? ' ': 'disabled=' %> active="true">Discount</button>
        <button type="button" id="other-charges" class="btn bg-blue btn-block" >Charges</button>

        <% if !@split_bill.nil? %>
          <% if @split_bill == '1' && (!(@order_items.nil?) || !(@order_items.empty?)) %>
            <button type="button" id="split_bills" class="btn btn-block bg-blue waves-effect">Split Bill</button>
          <% end %>
        <% end %>
        <% if current_login_employee.role != "waiter" %>
         <%if @membership.discount && @obj_sale.customer.membership_id %>
            <button type="button" class="btn btn-block bg-blue waves-effect" data-toggle="modal" data-target="#paymentModal">First Bill</button>
         <%else%>
            <button type="button" id="first_bill" class="btn btn-block bg-blue waves-effect">First Bill</button>
         <%end%>
        <button type="button" id="pay" class="btn bg-blue btn-block">Pay</button>
        <% end %>
       <!--  <button type="button" id="void" class="btn bg-blue btn-block" > Void </button> -->
      <% end %>
      <% if current_login_employee.role != "waiter" %>
          <input type="hidden" id="server_mode" value="<%= ENV["SERVER_MODE"] %>">
         <span class="hidden" id="member_discount"><%= @membership.discount%></span>
         <span class="hidden" id="membership_id"><%= @obj_sale.customer.membership_id rescue 0%></span>
        <div class="modal fade" id="paymentModal" tabindex="-1" role="dialog">
              <div class="modal-dialog" role="document">
                  <div class="modal-content">
                      <div class="modal-header">
                          <h4 class="modal-title" id="paymentModalLabel">Choose Payment</h4>
                      </div>
                      <div class="modal-body">
                        <div class="row text-center">
                          <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                            <button class='btn btn-md waves-effect btn-link payment-btn-box payment_btn bg-green' data-type='Credit' data-value='Credit'>Credit</button>
                          </div>

                          <% @payment_methods.each_with_index do |pay, pay_index| %>
                            <%if (pay_index+1)%3 == 0 %>
                              <div class="row clearfix"></div>
                            <% end %>
                            <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                              <button class='btn btn-md btn-link payment-btn-box waves-effect payment_btn bg-green' data-type='<%= pay.payment_method %>' data-value='<%= pay.payment_method %>'><%= pay.payment_method %></button>
                            </div>
                          <%end %>

                        </div>
                      </div>
                      <div class="modal-footer p-r-30 pb-3">
                          <button type="button" class="btn btn-md btn-link btn-danger waves-effect" data-dismiss="modal">CLOSE</button>
                          &nbsp;  &nbsp;
                         <button type="button" class="btn btn-md btn-link bg-blue waves-effect choose_payment">SAVE</button>
                      </div>
                  </div>
              </div>
          </div>
      <!-- Cashier Buttons -->
      <% end %>
   <!-- <button type="button" id="re-print" class="btn bg-blue btn-block" >Re.Print</button> -->
   <% else %>
      <% if !@checkout_time.empty? && !@checkout_alert_time.empty? %>
        <button type="button" id="check_in" class="btn btn-block bg-blue waves-effect"><%= t("views.btn.check_in") %></button>
      <% end %>
   <% end %>
 </div>
</div>
</div>

<%= print_settings %>

<div class="modal fade" id="voidModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
      <h4 class="modal-title" id="voidModalLabel">Please Enter Reason for Void</h4>
      </div>
      <div class="modal-body">
         <input type="textarea" name="remark" class="form-control col-md-12 remark" id="remark">
      </div>
      <div class="modal-footer ">
        <div class="row p-r-20">
          <div class="col-md-5">
            <button type="button" class="btn btn-link bg-red waves-effect " id="void" active="true">VOID</button>
          </div>
          <div class="col-md-5">
            <button type="button" class="btn btn-link bg-blue waves-effect" data-dismiss="modal">CLOSE</button>
          </div>
        </div>

      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="waste_spoileModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
      <h4 class="modal-title" id="waste_spoileModalLabel">Are you sure Waste or Spoile ?</h4>
      </div>
      <div class="modal-body">
      <div class="row p-r-20">
          <div class="col-md-3">
            <button type="button" class="btn btn-lg bg-red waves-effect " data-status="waste" value="waste" id="btn_waste" onclick="waste_and_spoilage('waste')"><strong>Waste</strong></button>
          </div>
          <div class="col-md-3">
              <button type="button" class="btn btn-lg bg-red waves-effect " data-status="spoile" value="spoile" id="btn_spoile" onclick="waste_and_spoilage('spoile')"><strong>Spoile</strong></button>
          </div>
          <div class="col-md-3">
            <button type="button" class="btn btn-lg bg-blue waves-effect" data-dismiss="modal"><strong>CLOSE</strong></button>
          </div>
        </div>
      </div>
      <div class="modal-footer ">
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="AccessCodeModal" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
      <h4 class="modal-title" id="AccessCodeModalLabel">Enter Access Code</h4>
      <button type="button" class="close" id="close" data-dismiss="modal" aria-hidden="true" style="font-size: 20px;color:#111;">&times;</button>
      </div>
      <div class="modal-body" style="padding: 0px 25px 15px 25px !important">
         <input type="password" id="access_code" class="access_code form-control col-md-12 ">
        <div class="row bottom p-l-15 p-r-15 m-t-10">
             <div class="col-md-3 access_number border-top border-left" data-value="1" data-type="num">1</div>
             <div class="col-md-3 access_number border-top border-left" data-value="2" data-type="num">2</div>
             <div class="col-md-3 access_number border-top border-left" data-value="3" data-type="num">3</div>
             <div class="col-md-3 access_number border-top border-left" data-value="4" data-type="num">4</div>
           </div>
           <div class="row bottom p-l-15 p-r-15">
             <div class="col-md-3 access_number border-top border-left" data-value="5" data-type="num">5</div>
             <div class="col-md-3 access_number border-top border-left" data-value="6" data-type="num">6</div>
             <div class="col-md-3 access_number border-top border-left" data-value="7" data-type="num">7</div>
             <div class="col-md-3 access_number border-top border-left" data-value="8" data-type="num">8</div>
           </div>
           <div class="row bottom p-l-15 p-r-15">
             <div class="col-md-3 access_number border-top border-left" data-value="9" data-type="num">9</div>
             <div class="col-md-3 access_number border-top border-left" data-value="0" data-type="num">0</div>
             <div class="col-md-3 access_number border-top border-left orange" data-type="clr">Clr</div>
             <div class="col-md-3 access_number ok border-top border-left blue" data-type="ok" data-action="">OK</div>

           </div>
      </div>
    </div>
  </div>
</div>
<% if @status_sale == 'sale' && (!@order_items.nil?) %>
<div class="modal fade" id="invoiceModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
      <h4 class="modal-title" id="invoiceModalLabel">Pending New Order</h4>
      </div>
      <div class="modal-body">
        <div class="card">
          <div id="pending-order-slimscroll" data-height="160">
            <table class="table table-striped">
               <thead>
                  <tr>
                    <th>#</th>
                    <th class="item-name">Items</th>
                    <th class="item-attr">QTY</th>
                    <th class="item-attr">Price</th>
                  </tr>
                </thead>
                <tbody>
                <% count = 0
                @order_items.each do |order_item|
                  set_item_prices = 0
                  count += 1 %>

                  <tr class="<%= @edit_order_origami==true ? 'edit_order' : '' %>" data-id='<%= order_item.order_items_id %>'>
                    <td><%= count %></td>
                    <td class='item-name'>
                        <%= order_item.item_name %>
                        <% if !order_item.options.nil? && !order_item.options.empty? && order_item.options != "undefined" %>
                        <% JSON.parse(order_item.options).each do |option| %>
                        <br><span class="font-13">
                        <%= option %>
                      </span>
                      <% end %>
                      <% end %>

                      <% if !order_item.set_menu_items.nil?
                        JSON.parse(order_item.set_menu_items).each do |item_instance|
                          set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f
                          %>
                          <br><span class="font-13">
                          <%= item_instance["item_instance_name"] %>
                          <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %>
                          <% (item_instance["options"]).each do |set_item_option| %>
                          <br><span class="font-13">
                          <%= set_item_option %>
                        </span>
                        <% end %>
                        <% end %>
                      </span>
                      <% end
                      sub_total += set_item_prices
                      end %>
                    </td>
                    <td class='item-attr'><%= order_item.qty %></td>
                    <td class='item-attr'><%= (order_item.qty*order_item.price).to_f + set_item_prices %></td>
                  </tr>
                  <%end %>
                </tbody>
            </table>
          </div>
        </div>
      </div>
      <div class="modal-footer ">
        <div class="row p-r-20">
          <div class="col-md-9">
            <button class='btn btn-link bg-blue waves-effect' data-dismiss="modal" id='add_invoice'> Add to existing invoice</button>
          </div>
          <div class="col-md-3">
            <button type="button" class="btn btn-link bg-blue waves-effect" data-dismiss="modal">CLOSE</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<%end%>
<!-- change tax modal -->
<div class="modal fade" id="change_taxModal" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-md" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title" id="change_taxModalLabel">TAX</h1>
        <button type="button" class="close" id="close" data-dismiss="modal" aria-hidden="true" style="font-size: 20px;color:#111;">&times;</button>
      </div>
      <div class="modal-body">
          <% if !@tax_arr.empty? %>
            <% if @tax_arr.count > 1 %>
            <div class="row text-center">
              <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                  <button type="button" class="btn btn-lg tax-btn-box btn-link bg-primary waves-effect" name="tax_type" data-value="all">
                  <% @i = 0
                  @tax_arr.each do |tax| %>
                    <%= tax %>
                    <% if @tax_arr.count != @i+1%>
                      + <% @i =+1 %><br>
                    <%end%>
                  <% end %>
                  </button>
              </div>

              <% @tax_arr.each_with_index do |tax, tax_index| %>
                <% if (tax_index+1)%2 == 0 %>
                  <div class="row clearfix"></div>
                <% end %>
                  <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                    <button type="button" class="btn btn-lg tax-btn-box btn-link bg-primary waves-effect" name="tax_type" data-value="<%= tax %>">
                      <%= tax %>
                    </button>
                  </div>
              <% end %>
            <% else %>
            <div class="row clearfix"></div>
            <div class="row text-center">
              <% @tax_arr.each do |tax| %>
                <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                  <button type="button" class="btn btn-lg tax-btn-box btn-link bg-primary waves-effect" name="tax_type" data-value="<%= tax %>"><%= tax %></button>
                </div>
              <% end %>
            <% end %>
          <% end %>
            <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
              <button type="button" class="btn btn-lg tax-btn-box btn-link bg-primary waves-effect" name="tax_type" data-value="no_tax">No Tax</button>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer"></div>
    </div>
  </div>
</div>

<!--  script data for credit lists -->
<script type="text/html" id="html_credit_items">
  <tr class="row_{key} credit_detail" data-id="{sale_id}" data-type="{cashier_type}">
    <td>{receipt_date}</td>
    <td>{receipt_no}</td>
    <td>{cashier_name}</td>
    <td>{customer_name}</td>
    <td>{credit_amount}</td>
  </tr>
</script>
<!-- script data for credit lists -->

<script>
var cashier_type = "cashier";
$(document).ready(function(){
  // localStorage.removeItem("tax_type");
  localStorage.removeItem("trans_flag");
   /* check webview loaded*/
    var webview = <%= @webview %>;
    showHideNavbar(webview);

    getCreditSales("","",cashier_type); //credit sales script data binding
  // $(".tables").on('click', function(){
  //     var customer_id=$(".customer-id").text();
  //     show_customer_details(customer_id);

  //     var dining_id = $(this).attr("data-id");
  //     window.location.href = '/origami/table/' + dining_id;
  // })
  // $(".sales").on('click',function(){
  //     var customer_id=$(".customer-id").text();
  //     show_customer_details(customer_id);

  //   var sale_id = $(this).attr("data-id");
  //   window.location.href = '/origami/sale/' + sale_id;
  // })
  // $(".rooms").on('click', function(){
  //     var customer_id=$(".customer-id").text();
  //     show_customer_details(customer_id);

  //     var dining_id = $(this).attr("data-id");
  //     window.location.href = '/origami/room/' + dining_id;
  // })
  // $(".orders").on('click',function(){
  //     var customer_id=$(".customer-id").text();
  //     show_customer_details(customer_id);

  //   var order_id = $(this).attr("data-id");
  //   window.location.href = '/origami/order/' + order_id;
  // })

  /* start check first bill or not*/
    var receipt_no = "";
    if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
      receipt_no = ($("#receipt_no").html()).trim();
    }
    // console.log(checkReceiptNoInFirstBillData(receipt_no));
    if ($("#server_mode").val() != "cloud") { // first bill not used in cloud
      if(checkReceiptNoInFirstBillData(receipt_no,"")){
        $("#pay").show();
      }else{
        $("#pay").hide();
      }
    }
  /* end check first bill or not*/

  $('.invoicedetails').on('click',function(){
    var dining_id = "<%= @room.id %>";
    var sale_id = this.id;
    window.location.href = '/origami/table/'+ dining_id + "/table_invoice/"+sale_id;
  })
  $(".tables").on('click', function(){

      var customer_id=$(".customer-id").text();
      show_customer_details(customer_id);

      var dining_id = $(this).attr("data-id");
      localStorage.setItem('dinning_type','table');
      localStorage.setItem('customer_id',customer_id);
      window.location.href = '/origami/table/' + dining_id;
  });

  $(".sales").on('click',function(){

      var customer_id=$(".customer-id").text();
      show_customer_details(customer_id);

      var sale_id = $(this).attr("data-id");
      window.location.href = '/origami/sale/' + sale_id;
  });

  $(".rooms").on('click', function(){

      var customer_id=$(".customer-id").text();
      show_customer_details(customer_id);

      var dining_id = $(this).attr("data-id");
      localStorage.setItem('dinning_type','room');
      localStorage.setItem('customer_id',customer_id);
      window.location.href = '/origami/room/' + dining_id;
  });

  $(".orders").on('click',function(){

      var customer_id=$(".customer-id").text();
      show_customer_details(customer_id);

      var order_id = $(this).attr("data-id");
      window.location.href = '/origami/order/' + order_id;
  });

   // bind survey to order or sale
        $("#survey").on('click', function () {
            var sale = $('#sale_id').val();
            if (sale) {
                var sale_id = sale
            } else {
                var sale_id = "<%= @room.id %>";
            }
            //var table_id = $('.tables').attr("data-id");
            window.location.href = '/origami/' + sale_id +"/"+cashier_type+ "/surveys"
        });
  // bind customer to order or sale
  $("#customer").on('click', function(){
    var sale = $('#sale_id').val();
    if (sale) {
      var sale_id = sale
    }else{
      var sale_id = $('#save_order_id').attr('data-order');
    }
    var table_id = $('.tables').attr("data-id");

    window.location.href = '/origami/' + sale_id+"/"+cashier_type + "/customers/normal";

  });

  $('#re-print').click(function() {
    var sale_id = $('#sale_id').val();
    window.location.href = '/origami/'+ sale_id  + "/reprint"

    return false;
  });

  // Discount for Payment
  $('#discount').click(function () {

    if ($(this).attr('active')=== "true") {
      var sale = $('#sale_id').val();
      if (sale != "") {
        var sale_id = sale
      } else {
        var sale_id = $('#save_order_id').attr('data-order');
      }

      if (sale_id != "") {
        window.location.href = '/origami/' + sale_id +"/"+cashier_type+ '/discount'
      }
      else {
        swal ( "Oops" ,  "Please select an table!" ,  "warning" );
      }
    }else{
      swal("Opps","You are not authorized for Discount","warning")
    }
    return false;
  });
  // Discount for Payment

  // Add Other Charges
  $('#other-charges').click(function() {
    var sale = $('#sale_id').val();
    if (sale!="") {
      var sale_id = sale
    }else{
      var sale_id = $('#save_order_id').attr('data-order');
    }

    if(sale_id!=""){
      window.location.href = '/origami/' + sale_id +"/"+cashier_type+ '/other_charges'
    }
    else {
      swal ( "Oops" ,  "Please select an table!" ,  "warning" );
    }

    return false;
  });

});

 // click select option icon for add
  $(document).on('click', '.payment_btn', function(event){
    active     = $(this).hasClass('selected-payment');
    value      = $(this).data('value');
    type       = $(this).data('type');
    group      = $(this).data('group');
    payments    = $(".payment_btn");

    if (active) {
      $(this).removeClass('selected-payment');
    }else{
      $(this).addClass('selected-payment');
    }
}); //End selecct attribute buttom

// Print for first bill
$("#first_bill").on('click', function(){

  swal({
    title: "Alert",
    text: "Are you sure want to print First Bill?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, print it!",
    closeOnConfirm: false
  }, function (isConfirm) {

    $('.confirm').off("click touchstart touchend");
    $('.confirm').attr("disabled","disabled");

    if (isConfirm) {
      var sale_id = $('#sale_id').val();
      var ajax_url = "/origami/sale/"+ sale_id + "/first_bill";

      $.ajax({
        type: "GET",
        url: ajax_url,
        success:function(result){
          receipt_no = ($("#receipt_no").html()).trim();
          if((receipt_no!=undefined) && (receipt_no!=""))
            createReceiptNoInFirstBillData(receipt_no,"");
            if (!$('#print_settings').data('action-cable')) {
              // For Server Print - from jade
              if ($("#server_mode").val() == "cloud") {
                if(typeof code2lab != 'undefined'){
                  code2lab.printFile(result.filepath.substr(6), result.printer_url);
                }
              }
            }
            location.reload();
          }
        });
      }
    });
  });

$(".choose_payment").on('click', function () {
  $( "#loading_wrapper").show();
  var sale_id = $('#sale_id').val();
  type    = get_selected_attributes('selected-payment');
  var tax_type = localStorage.getItem("tax_type") ? localStorage.getItem("tax_type") : 'all';
  // type = $('.payment_method').val();
  if(parseInt(jQuery.inArray("Credit", type)) == -1){
    if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1 || parseInt(jQuery.inArray("PAYMAL", type)) != -1) {
      if(!location.pathname.includes("credit_payment")){
        calculate_member_discount(sale_id,"Card",tax_type);
      }
    }else{
      if(!location.pathname.includes("credit_payment")){
        calculate_member_discount(sale_id,"Cash",tax_type);
      }
    }
  }
  var ajax_url = "/origami/sale/" + sale_id + "/first_bill";
  $.ajax({
    type: "GET",
    url: ajax_url,
    success: function (result) {
      $( "#loading_wrapper" ).hide();
      receipt_no = ($("#receipt_no").html()).trim();
      if((receipt_no!=undefined) && (receipt_no!=""))
        createReceiptNoInFirstBillData(receipt_no,type);

      if (!$('#print_settings').data('action-cable')) {
        // For Server Print - from jade
        if ($("#server_mode").val() == "cloud") {
          if(typeof code2lab != 'undefined'){
            code2lab.printFile(result.filepath.substr(6), result.printer_url);
          }
        }
      }
      location.reload();
    }
  });
});
function calculate_member_discount(sale_id,type,tax_type) {
 var sub_total = $('#sub-total').text();
 if (type == "Cash") {
   is_card = false
 }else{
  is_card = true
}
$.ajax({
  type: "POST",
  url: "/origami/" + sale_id + "/member_discount",
  data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card,'cashier_type':'cashier','tax_type':tax_type },
  async: false,
  success:function(result){
  }
});
}

$('#pay').on('click',function() {
   var sale_id = $('#sale_id').val();
   var url = '/origami/sale/'+ sale_id + "/rounding_adj" ;

   $.ajax({
      type: "POST",
        url: '/origami/sale/'+ sale_id + "/rounding_adj",
        success:function(result){
          window.location.href = '/origami/sale/'+ sale_id + "/cashier/payment";
        }
    });

});
// Bill Request
$('#request_bills').click(function() {
  var current_checkin_induties_count =localStorage.getItem("current_checkin_induties_count");
  localStorage.removeItem("current_checkin_induties_count");
  var order_id = $('#save_order_id').attr('data-order');
  var ajax_url = "/origami/" + order_id + "/request_bills";
  if(order_id!=undefined && order_id!=null && order_id!=""){
    if($('#request_bills').is(":visible")) {
      $('#request_bills').prop("disabled",true);
    }
    localStorage.setItem("tax_type", "all");
    $.ajax({
        type: "GET",
        url: ajax_url,
        data: {current_checkin_induties_count: current_checkin_induties_count},
        success: function (result) {
            if (!result.status) {
              swal({
                title: 'Oops',
                text: result.error_message,
                type: 'error',
                html: true,
                closeOnConfirm: false,
                closeOnCancel: false,
                allowOutsideClick: false
              }, function (isConfirm) {
                if(isConfirm){
                  location.reload();
                }
              });
            }
            else {
              location.reload();
            }
        }
    });
  }else{
    swal("Opps","There is no orders!","warning");
  }

});

//split bill process
$('#split_bills').click(function(){
  var dining_id = "<%= @room.id %>";
  window.location.href = '/origami/room/' + dining_id + "/" + cashier_type + "/split_bills";
});

$('#move').on('click',function(){
  if($('#move').is(":visible")) {
    $('#move').prop("disabled",true);
  }
  var dining_id = "<%= @room.id %>"
  window.location.href = '/origami/table/'+ dining_id + "/moveroom";
})

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

$('#add_invoice').on('click',function(){
  $("#first_bill").prop('disabled',true);
  $("#pay").prop('disabled',true);
  var dining_id = "<%= @room.id %>"
  var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %>
  var ajax_url = "/origami/sale/append_order";
  // var tax_type = localStorage.getItem("tax_type");
  var tax_type = $("#check_tax").val();
  $.ajax({
    type: "POST",
      url: ajax_url,
      data: 'dining_id='+ dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type,
      success:function(result){
        swal({
          title: "Information!",
          text: "Invoice updated",
          html: true,
          closeOnConfirm: false,
          closeOnCancel: false,
          allowOutsideClick: false
        }, function () {
          $("#first_bill").removeAttr('disabled');
          $("#pay").removeAttr('disabled');
          window.location.reload();
        });
      }
  });
});

// //show cusotmer rebate amount
// function show_customer_details(customer_id){
//   var url = '<%= @show_customer_details_path %>'
//       //Start Ajax
//       $.ajax({
//         type: "GET",
//         url: url,
//         data: {},
//         dataType: "json",
//         success: function(data) {
//           $("#customer_name").text(data["customer"].name);
//           if (data["response_data"]["data"].length) {
//             $.each(data["response_data"]["data"], function (i) {
//               if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){
//                 var balance = data["response_data"]["data"][i]["balance"];
//                 if (data["response_data"]["status"]==true) {
//                   $('.rebate_amount').removeClass('hide');
//                   row =
//                          '<td class="charges-name">' + "Rebate Balance" +'</td>'
//                          +'<td class="item-attr">' + balance + '</td>';

//                          $(".rebate_amount").html(row);
//                 }

//               }
//             });
//             }else{
//               $('.rebate_amount').addClass('hide');
//             }
//         }
//       });
//         //End Ajax
//   }

  //show cusotmer rebate amount
  function show_customer_details(customer_id){
  var url = '<%= @show_customer_details_path %>'
    //Start Ajax
    $.ajax({
      type: "GET",
      url: url,
      data: {},
      dataType: "json",
      success: function(data) {
        $("#customer_name").text(data["customer"].name);
        if (data["response_data"]["data"].length) {
          $.each(data["response_data"]["data"], function (i) {
            if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){
              var balance = data["response_data"]["data"][i]["balance"];
              if (data["response_data"]["status"]==true) {
                $('.rebate_amount').removeClass('hide');
                row =
                       '<td class="charges-name">' + "Rebate Balance" +'</td>'
                       +'<td class="item-attr">' + balance + '</td>';

                       $(".rebate_amount").html(row);
              }

            }
          });
          }else{
            $('.rebate_amount').addClass('hide');
          }
      }
    });
    //End Ajax
  }

  $('#edit').on('click',function(){
    var dining_id = "<%= @room.id %>"
    var sale_id = $('#sale_id').val(); //"<%= @obj_sale.sale_id rescue "" %>"
    window.location.href = '/origami/table/'+ dining_id + "/sale/"+ sale_id + "/cashier/edit";
  });

  // $('#void').on('click',function () {
  //     var sure = confirm("Are you sure want to Void");
  //     if (sure == true) {
  //         var sale_id = $('#sale_id').val();
  //         var ajax_url = "/origami/sale/" + sale_id + '/cashier/void';
  //         $.ajax({
  //             type: 'POST',
  //             url: ajax_url,
  //             success: function () {
  //                 window.location.href = '/origami/';
  //             }
  //         })
  //     } else {

  //     }
  // });

  $('#void').on('click', function () {
       var access_code  = localStorage.getItem("access_code");
      if ($(this).attr('active')=== "true") {
        swal({
            title: "Alert",
            text: "Are you sure want to Void?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, void it!",
            closeOnConfirm: false
        }, function (isConfirm) {
          if (isConfirm) {
            var sale_id = $('#sale_id').val();
            var ajax_url = "/origami/sale/" + sale_id + '/cashier/void';
            var remark  = $("#remark").val();

            $.ajax({
                type: 'POST',
                url: ajax_url,
                data: "remark="+ remark + "&sale_id=" + sale_id+ "&access_code=" + access_code,
                success: function (result) {
                  if (!$('#print_settings').data('action-cable')) {
                    // For Server Print - from jade
                    if ($("#server_mode").val() == "cloud") {
                      if(typeof code2lab != 'undefined'){
                        code2lab.printFile(result.filepath.substr(6), result.printer_url);
                      }
                    }
                  }
                  window.location.href = '/origami/';
                }
            });
          }
        });
      }else{
        swal("Opps","You are not authorized for void","warning");
      }
    });

  $('#commissions').on('click', function () {
        var dining_id = "<%= @room.id %>"
        var sale_id = $('#sale_id').val(); //"<%= @obj_sale.sale_id rescue "" %>"
        window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/load_commissioners";
    });

    $('#in_duties').on('click', function () {
      localStorage.setItem('dinning_id',<%= @room.id %>);
        var dining_id = "<%= @room.id %>";
        var booking_id = "<%= @booking.booking_id rescue "" %>";
        window.location.href = '/induties/'+ booking_id +'/assign';
    });

  // Ordering
  $('#add_order').on('click', function () {
        var dining_id = "<%= @room.id %>"
        window.location.href = '/origami/addorders/' + dining_id;
    });

  /* split bill in add to existing invoice*/
    $('#split_bill').on('click', function(){
      swal({
        title: "Alert",
        text: "Are you sure, you want to split bill?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, split it!",
        closeOnConfirm: false
      }, function (isConfirm) {
        if(isConfirm){
          var dining_id = "<%= @room.id %>";
          window.location.href = '/origami/table/' + dining_id + "/split_bills";
        }
      });
    });

    /*edit order in oqs*/
    $('.edit_order').on('click',function(){
      var assigned_order_item_id = $(this).attr('data-id');
      var dining_id = "<%= @room.id %>";
      if((assigned_order_item_id!=undefined) && (assigned_order_item_id!='')){
        window.location.href = '/oqs/'+ assigned_order_item_id  + "/edit/"+dining_id;
      }
    });
    // Get Selected Class
    function get_selected_attributes(selected_class) {
      var item_row      = $('.'+selected_class);
      var attribute_arr = [];
      $(item_row).each(function(i){
        value = $(item_row[i]).attr('data-value');
        str = value;
        attribute_arr.push(str);
      });
      return attribute_arr;
    }

    function waste_and_spoilage(remark) {
        swal({
            title: "Alert",
            text: "Are you sure want to " + remark +" ?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, " +remark+ " it!",
            closeOnConfirm: false
        }, function (isConfirm) {
          if (isConfirm) {
            var sale_id = $('#sale_id').val(); //"<%= @obj_sale.sale_id rescue "" %>"
            var url = "/origami/sale/" + sale_id + '/cashier/waste_and_spoilage';
            $.ajax({
                type: 'POST',
                url: url,
                data: "remark="+ remark + "&sale_id=" + sale_id,
                success: function (result) {
                  console.log(result)
                  if (!$('#print_settings').data('action-cable')) {
                    // For Server Print - from jade
                    if ($("#server_mode").val() == "cloud") {
                      if(typeof code2lab != 'undefined'){
                        code2lab.printFile(result.filepath.substr(6), result.printer_url);
                      }
                    }
                  }
                  window.location.href = '/origami/';
                }
            });
          }
        });
    }

    $(document).on('click', '.access_modal', function(event){
      type = $(this).data("type");
      $(".ok").attr("data-action",type)
      $('#AccessCodeModal').modal('show');
    });

    function check_emp_access_code(access_code,type) {
      var url = "/origami/check_emp_access_code/" + access_code ;
      $.ajax({
          type: 'POST',
          url: url,
          data: {},
          success: function (result) {
             console.log(result);
             if (result.status == true) {
              createAccessCode(code);
               if (type == "edit") {
                var dining_id = "<%= @room.id rescue ""%>";
                  var sale_id   = $('#sale_id').val(); //"<%= @obj_sale.sale_id rescue "" %>";
                  window.location.href = '/origami/table/' + dining_id + "/sale/" + sale_id + "/cashier/edit";
               }else if(type == "void"){
                 $('#AccessCodeModal').modal('hide');
                 $('#voidModal').modal('show');

                 // overall_void();
               }else if(type == "waste_and_spoilage"){

               }
             }else{
               swal("Opps",result.message,"warning")
             }
          }
      });
  }

  /* check in process */
  $('#check_in').on('click',function(){
    var room_id = "<%= @room.id %>";

    $.ajax({
      type: 'POST',
      data: {'dining_id' : room_id},
      datatype: 'JSON',
      url: '/origami/check_in',
      success: function(data) {
        if(data.status == 'ok'){
          window.location.reload();
        }
      }
    });
  });

  /* Start function for tax changable */
  $(".change_tax").on("click",function(){
    var balance = parseFloat($("#order-grand-total").text());
    var sub_total = parseFloat($("#sub-total").text());
    var total_tax = parseFloat($("#order-Tax").text());
    if(balance > 0 && (balance >= total_tax)){
      $("#change_taxModal").modal({show: true, backdrop: false, keyboard: false});
    }
    else{
      swal("Oops","You cann't change tax!","warning");
    }
  });

  $("button[name=tax_type]").on("click", function(){
    var tax_type = $(this).attr("data-value");
    var cashier_type = 'cashier';
    var sale_id = $('#sale_id').text();
    var dining_id = "<%= @room.id rescue "" %> ";
    var sale_id   = "<%= @obj_sale.sale_id rescue "" %>";
    localStorage.removeItem("tax_type");
    swal({
      title: "Alert",
      text: "Are you sure want to change tax?",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "Yes, change it!",
      closeOnConfirm: false
    }, function (isConfirm) {
      if (isConfirm) {
        $.ajax({
          type: "POST",
          url: "/origami/payment/"+cashier_type+"/change_tax",
          data: {sale_id: sale_id, cashier_type: cashier_type, tax_type: tax_type},
          success:function(data){
            if(data.status){
              // console.log(tax_type);
              localStorage.setItem("tax_type", tax_type);
              window.location.href = '/origami/room/'+dining_id;
            }
          }
        });
      }else{
        swal.close();
      }
    });
  });
  /* End function for tax changable */
</script>
