<div class="row">
  <div class="col-lg-12">
    <ol class="breadcrumb">
       <li><a href="<%= crm_root_path %>">Home</a></li>
       <li class="active">
           <a href="<%= transactions_sales_path %>">Sale</a>
       </li>
       <li class="active">
           <a href="<%= transactions_sale_path(@sale.sale_id) %>"><%= @sale.sale_id %></a>
       </li>
       <span style="float: right">
            <a href="<%= transactions_sales_path%>" class="btn btn-primary btn-sm">
              <i class="fa fa-arrow-left fa-lg"></i> Back
            </a>
            
            
             <a href="<%= transactions_void_path(@sale)%>"  class="btn btn-danger  btn-sm">
              <i class="fa fa-trash fa-lg"></i>  Void Sale
             </a>
            <a href="<%= transactions_manual_complete_sale_path(@sale)%>"  class="btn btn-success  btn-sm" disabled>
              <i class="fa fa-invoice fa-lg"></i> Complete Sale
            </a>
      </span>
    </ol>
  </div>
</div>
<div class="row">
    <div class="col-lg-12 col-md-12 col-sm-12">
      <!-- Column One -->

        <!-- Nav tabs -->
        <ul class="nav nav-tabs" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#queue" role="tab">Sale Details </a>
            </li>
            <li class="nav-item">
                <a class="nav-link " data-toggle="tab" href="#booking" role="tab">Orders Details</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#customer" role="tab">Customer Details</a>
            </li>
        </ul>
        <!-- Nav tabs - End -->

        <div class="tab-content" style="min-height:670px; max-height:670px;">

            <div class="tab-pane active" id="queue" role="tabpanel" style="min-height:670px; max-height:670px; overflow-y:">
                <div class="table-responsive">
                    <table class="table table-striped">
                      <thead>
                        <tr>
                          <td colspan="6">&nbsp;</td>
                        </tr>
                        <tr>
                          <th>Receipt Date </th>
                          <th>Receipt no</th>
                          <th>Cashier</th>
                          <th>Sales status</th>
                          <th>Receipt generated at</th>
                        </tr>
                      </thead>

                      <tbody>
                          <tr>
                            <td><%= @sale.receipt_date.strftime("%d-%M-%Y") %></td>
                            <td><%= @sale.receipt_no %></td>
                            <td><%= @sale.cashier_name rescue '-' %></td>
                            <td> <%= @sale.sale_status %> </td>
                            <td> <%= @sale.requested_at.strftime("%m-%d-%Y %H:%M %p") %> </td>
                          </tr> 
                          <tr style="border-top:2px solid #000">
                            <th>Sale item name</th>
                            <th> Qty</th>
                            <th>Unit price</th>
                            <th>Total pirce </th>
                            <th>Created at</th>
                          </tr>   
                          <% @sale.sale_items.each do |s| %>

                          <tr>
                            <td><%=s.product_name rescue ' '%></td>
                            <td><%=s.qty rescue ' '%></td>
                            <td><%= number_with_precision(s.price, :precision => 2, :delimiter => ',') rescue ' '%></td>
                            <td><%= number_with_precision(s.qty * s.price, :precision => 2, :delimiter => ',') rescue ' '%></td>  
                            <td><%=l s.created_at.utc.getlocal , :format => :short rescue ' ' %></td>
                          </tr>
                          <% end %>  
                          <tr style="border-top:2px solid #000">
                              <td colspan=2 style="text-align:center"></td>
                              <td>Total</td>    
                              <td colspan="2"><%= number_with_precision(@sale.total_amount, :precision => 2, :delimiter => ',') rescue ' '%></td>
                          </tr>
                          <tr>
                            <td colspan=2 style="text-align:center"></td>
                            <td>Discount</td>
                            <td colspan="2"><%= number_with_precision(@sale.total_discount, :precision => 2, :delimiter => ',') rescue ' '%></td>
                            </tr>
                          <% @sale.sale_taxes.each do |r|%>
                          <tr>
                            <td colspan=2 style="text-align:center"></td>
                            <td><%= r.tax_name %> </td>    
                            <td colspan="2"><%= number_with_precision(r.tax_payable_amount, :precision => 2, :delimiter => ',') rescue ' '%></td>
                            </tr>
                          <% end %> 
                          <tr>
                            <td colspan=2 style="text-align:center"></td>
                            <td>Grand Total</td>
                            <td colspan="2"><%= number_with_precision(@sale.grand_total, :precision => 2, :delimiter => ',') rescue ' '%></td>
                            </tr>
                          <tr><td colspan="5">&nbsp;<td></tr>
                          <tr>
                            <td colspan=2 style="text-align:center"></td>
                            <td>Total Pay Amount</td>
                            <td colspan="2"><%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%></td>
                            </tr>
                          
                          <% @sale_receivables.each do |r|%>
                          <tr>
                            <td colspan=2 style="text-align:center"></td>
                            <td> <%= r.payment_method.capitalize rescue ' '%> Payment</td>
                            <td colspan="2"><%= number_with_precision(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%>
                            </td>
                          </tr> 

                          <% end %> 


                          <tr>
                            <td colspan=2 style="text-align:center"></td>
                            <td>Change</td>
                            <td colspan="2"><%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%></td>
                          </tr>

                      </tbody>
                    </table>

                </div>
            </div>

            <div class="tab-pane" id="booking" role="tabpanel">
                <div class="table-responsive">
                    <table class="table table-striped">
                      <thead>
                        <tr>
                          <td colspan="8">&nbsp;</td>
                        </tr>
                        <tr>
                          <th>Order ID</th>
                          <th>Menu Item</th>
                          <th>QTY</th>
                          <th>Unit Price </th>
                          <th>Option</th>
                          <th>Status</th>
                          <th>Waiter</th>
                          <th>Created at </th>
                        </tr>
                      </thead>

                    <tbody>
                    <% @order_items.each do |order_item| %>
                        <tr>
                          <td><%= order_item.order_id %></td>
                          <td><%= order_item.item_name %></td>
                          <td><%= order_item.qty %></td>
                          <td><%= order_item.price %></td>
                          <td><%= order_item.options %></td>
                          <td><%= order_item.order_item_status %></td>
                          <td><%= order_item.item_order_by %> </td>
                          <td><%= order_item.created_at.strftime("%d-%m-%y") %></td>
                        </tr>
                      <% end %>
                    </tbody>
                    </table>
                </div>
            </div>

            <div class="tab-pane" id="customer" role="tabpanel">
                <br>
                <div class="table-responsive">
                  <table class="table table-striped">
                  <thead>
                    <tr>
                      <th>Card No</th>
                      <th>Name</th>
                      <th>Company</th>
                      <th>Contact no</th>
                      <th>Email</th>
                      <th>NRC/Passport No</th>
                      <th>Address</th>
                      <th>DOB</th>
                    </tr>
                  </thead>

                  <tbody>
                    <tr>
                      <td><%= @customer.card_no rescue '-'%></td>
                      <td><%= @customer.name %></td>
                      <td><%= @customer.company rescue '-' %></td>
                      <td><%= @customer.contact_no %></td>
                      <td><%= @customer.email %></td>
                      <td><%= @customer.nrc_no %></td>
                      <td><%= @customer.address%></td>
                      <td><%= @customer.date_of_birth %></td>
                    </tr>
                    <tr>
                      <th colspan="8">Membership Transactions</th>
                    </tr>
                    <tr>
                      <th>Date</th>
                      <th>Redeem</th>
                      <th>Rebate</th>
                      <th>Balance</th>
                      <!-- <th>Account No</th> -->
                      <th>Status</th>
                      <th>Receipt No</th>
                    </tr>
                    
                    <% 
                     if @response["status"] == true %>
                    <% @response["data"].each do |transaction| %>
                        <tr>
                          <td><%= transaction["date"]%></td>
                          <td><%= transaction["redeem"]%></td>
                          <td><%= transaction["rebate"] %></td>
                          <td><%= transaction["balance"] %></td>
                          <!-- <td><%= transaction["account_no"] %></td> -->
                          <td><%= transaction["status"] %></td>
                           <td><%= transaction["receipt_no"] %></td>
                         
                        </tr>
                      <% end %>
                    <% end %>
                  </tbody>
                </table>
                </div>
            </div>

        </div>

    </div>

    <!-- <div class="col-lg-2 col-md-2 col-sm-2">
      <a href="<%= transactions_sales_path%>" style="margin-top: 10px " class="btn btn-primary btn-lg">
        <i class="fa fa-arrow-left fa-lg"></i> Back
      </a>
      
      
       <a href="<%= transactions_void_path(@sale)%>" style="margin-top: 10px " class="btn btn-danger  btn-lg">
        <i class="fa fa-trash fa-lg"></i>  Void Sale
       </a>
      <a href="<%= transactions_manual_complete_sale_path(@sale)%>"  style="margin-top: 10px " class="btn btn-success  btn-lg">
        <i class="fa fa-invoice fa-lg"></i> Complete Sale
      </a>
    </div> -->

</div>




     

