<!DOCTYPE html>
<html lang="en">
  
<head>
    <title><%= lang_data.Online_Shopping %></title>
    <%- include('./partials/meta'); -%>

</head>
<body>
    <%- include('./partials/header_sidebar'); -%> 

        <div class="page-body">
            <div class="container-fluid">
                <div class="page-title">
                    <div class="row">
                        <div class="col-sm-6">
                            <h3><%= lang_data.Online_Shopping %></h3>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="/index"><i data-feather="home"></i></a></li>
                                <li class="breadcrumb-item"><a href="/online_shopping/list_of_packages"><%= lang_data.List_of_Packages %></a></li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Container-fluid starts-->
            <div class="container-fluid">
                <div class="row">
                            
                    <!-- Scroll - vertical dynamic Starts-->
                    <div class="col-sm-12">
                        <div class="card">
                            <div class="card-header pb-0 d-flex justify-content-between">
                                <h4><%= lang_data.List_of_Packages %></h4>
                                <a href="/online_shopping/register_packages" class="btn btn-pill btn-primary btn-air-primary"><%= lang_data.Add_New_Packages %></a>
                            </div>

                            <input type="hidden" id="rates_sym" value="<%= accessdata.data.site_currency %>">
                            <input type="hidden" id="rates_pla" value="<%= accessdata.data.currency_placement %>">
                            <input type="hidden" id="thousands_replace" value="<%= accessdata.data.thousands_separator %>">

                            <div class="card-body">
                                <div class="table-responsive theme-scrollbar">
                                    <table class="display" id="basic-1" aria-label="table">
                                        <thead>
                                            <tr>
                                                <th class="d-none"><%= lang_data.Tracking %></th>
                                                <th><%= lang_data.Tracking %></th>
                                                <th><%= lang_data.date %></th>
                                                <th><%= lang_data.customer_name %></th>
                                                <th><%= lang_data.Shipping_Company %></th>
                                                <th><%= lang_data.Store %> / <%= lang_data.Supplier %></th>
                                                <th><%= lang_data.Purchase_Tracking %></th>
                                                <th><%= lang_data.Status %></th>
                                                <th><%= lang_data.Drivers %></th>
                                                <th><%= lang_data.Total_cost %></th>
                                                <th><%= lang_data.invoice_status %></th>
                                                <th><%= lang_data.Action %></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <% register_packages.forEach((data) => { %>

                                                <tr>
                                                    <td class="d-none"></td>
                                                    <td class="text-nowrap"><%= data.invoice %></td>
                                                    <td class="text-nowrap"><%= data.date.toLocaleDateString() %></td>
                                                    <td class="text-nowrap"><%= data.customers_firstname %> <%= data.customers_lastname %></td>
                                                    <td class="text-nowrap"><%= data.courier_companies %></td>
                                                    <td class="text-nowrap"><%= data.supplier %></td>
                                                    <td class="text-nowrap"><%= data.tracking_no %></td>
                                                    <td class="text-nowrap">
                                                        <% if (data.shipping_status == "Delivered") { %>

                                                            <span class="badge badge-success p-2"><%= data.shipping_status %></span>
                                                        <% } else { %>

                                                            <span class="badge badge-primary p-2"><%= data.shipping_status %></span>
                                                        <% } %>
                                                    </td>
                                                    <td class="text-nowrap"><%= data.driver_firstname %> <%= data.driver_lastname %></td>
                                                    <td class="invosymbol text-nowrap"><%= data.total %></td>
                                                    <td class="text-nowrap">
                                                        <% if (role_data.role == '1') { %>

                                                            <% if (data.due_amount != '0') { %>
                                                                <span class="badge badge-warning p-2">Pending</span>
                                                            <% } else { %>
                                                                <span class="badge badge-success p-2">Paid</span>
                                                            <% } %>

                                                        <% } else { %>

                                                            <% if (data.due_amount != '0') { %>
                                                                <span class="badge badge-warning p-2">Pending</span>
                                                            <% } else { %>
                                                                <span class="badge badge-success p-2">Paid</span>
                                                            <% } %>

                                                        <% } %>
                                                    </td>
                                                    <td class="text-nowrap"> 
                                                            <div class="dropdown">
                                                                    <button class="dropbtn btn-pill btn-primary px-4 py-2" type="button"><%= lang_data.Action %></button>
                                                                    <div class="dropdown-content myDropdown">
                                                                        <% if (role_data.role == '1') { %>

                                                                            <% if (data.due_amount != '0') { %>

                                                                                <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/edit_register_packages/<%= data.id %>" id="edit_register_packages"><i class="fa fa-pencil f-14"></i> <%= lang_data.Edit_Package %></a>
                                                                                <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#assigndriver_toggle" id="online_shopping_assign_driver" data-id="<%= data.id %>" data-name="<%= data.assign_driver %>"><i class="fa fa-car f-14"></i> <%= lang_data.Assign_Driver %></a>
                                                                                <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#add_payment_toggle" id="online_shopping_add_payment" data-id="<%= data.id %>" data-invoice="<%= data.invoice %>" data-due="<%= data.due_amount %>"><i class="fa fa-money"></i> <%= lang_data.Add_Payment %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_label/<%= data.id %>" id="rp_print_label"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Label %></a>

                                                                            <% } else { %>

                                                                                <% if (data.shipping_status == "Delivered") { %>
                                                                                    
                                                                                    <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/print_label/<%= data.id %>" id="rp_print_label"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Label %></a>
                                                                                <% } else { %>

                                                                                    <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                    <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#assigndriver_toggle" id="online_shopping_assign_driver" data-id="<%= data.id %>" data-name="<%= data.assign_driver %>"><i class="fa fa-car f-14"></i> <%= lang_data.Assign_Driver %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/print_label/<%= data.id %>" id="rp_print_label"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Label %></a>
                                                                                <% } %>

                                                                            <% } %>

                                                                        <% } else if (role_data.role == '2') { %>

                                                                            <% if (data.due_amount != '0') { %>

                                                                                <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#add_payment_toggle" id="online_shopping_add_payment" data-id="<%= data.id %>" data-invoice="<%= data.invoice %>" data-due="<%= data.due_amount %>"><i class="fa fa-money"></i> <%= lang_data.Add_Payment %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_label/<%= data.id %>" id="rp_print_label"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Label %></a>
                                                                                
                                                                            <% } else { %>
                                                                                    
                                                                                <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_label/<%= data.id %>" id="rp_print_label"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Label %></a>
                                                                            <% } %>

                                                                        <% } else { %>

                                                                            <% if (data.due_amount != '0') { %>
                                                                                <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#assigndriver_toggle" id="online_shopping_assign_driver" data-id="<%= data.id %>" data-name="<%= data.assign_driver %>"><i class="fa fa-car f-14"></i> <%= lang_data.Assign_Driver %></a>
                                                                                <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                            <% } else { %>
                                                                                <% if (data.shipping_status == "Delivered") { %>
                                                                                    <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                    
                                                                                <% } else { %>
                                                                                    <a class="dropdown-item" href="/online_shopping/show_register_packages/<%= data.id %>"><i class="fa fa-search f-14"></i> <%= lang_data.Show_Details %></a>
                                                                                    <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#assigndriver_toggle" id="online_shopping_assign_driver" data-id="<%= data.id %>" data-name="<%= data.assign_driver %>"><i class="fa fa-car f-14"></i> <%= lang_data.Assign_Driver %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/print_shipment/<%= data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/shipment_tracking/<%= data.id %>"><i class="fa fa-refresh f-14"></i> <%= lang_data.Shipment_Tracking %></a>
                                                                                    <a class="dropdown-item" href="/online_shopping/deliver_shipment/<%= data.id %>"><i class="fa fa-cube f-14"></i> <%= lang_data.Deliver_The_Shipment %></a>
                                                                                
                                                                                <% } %>
                                                                            <% } %>

                                                                        <% } %>
                                                                        
                                                                    </div>
                                                            </div>
                                                    </td>
                                                </tr>
                                            <% }) %>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- Scroll - vertical dynamic Ends-->
                </div>
            </div>
        <!-- Container-fluid Ends-->
        </div>


        <!-- edit status modal-->

        <div class="modal fade" id="assigndriver_toggle" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenter" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title"><%= lang_data.Assign_Driver %></h5>
                  <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <form action="/online_shopping/assigndriver" method="post">
                    <div class="modal-body">
                    <div class="row">
                        <input type="hidden" id="hidden_id" name="hidden_id">
                        <div class="col-12">
                            <select class="js-example-basic-single" name="assign_driver" id="assign_driver_toggle" required>
                                <option value selected disabled>Search Driver</option>
                                <% drivers_list.forEach((data) => { %>
                                <option value="<%= data.id %>"> <%= data.first_name %> <%= data.last_name %></option>
                                <% }) %>
                            </select>
                        </div>
    
                    </div>
                    </div>
                    <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-bs-dismiss="modal"><%= lang_data.Close %></button>
                    <button class="btn btn-primary" type="submit"><%= lang_data.Save_changes %></button>
                    </div>
                </form>
              </div>
            </div>
        </div>


        <!-- edit payment modal-->

        <div class="modal fade" id="add_payment_toggle" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenter" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title"><%= lang_data.Add_Payment %></h5>
                  <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <form id="payment_action" method="post">
                    <div class="modal-body">
                        <div class="row g-3">
                            <div class="col-12">
                                <label class="form-label"><%= lang_data.Tracking_ID %></label>
                                <input class="form-control" type="text" name="invoice" id="invoice" readonly>
                            </div>

                            <div class="col-12">
                                <label class="form-label"><%= lang_data.Payable_Amount %> (<%= accessdata.data.site_currency %>)</label>
                                <input class="form-control" type="number" name="payable_amount" step="0.01" id="payable_amount" readonly>
                            </div>

                            <div class="col-12">
                                <label class="form-label"><%= lang_data.Paid_Amount %> (<%= accessdata.data.site_currency %>)</label>
                                <input class="form-control" type="number" name="paid_amount" step="0.01" id="paid_amount" required>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-secondary" type="button" data-bs-dismiss="modal"><%= lang_data.Close %></button>
                        <button class="btn btn-primary" type="submit"><%= lang_data.Save_changes %></button>
                    </div>
                </form>
              </div>
            </div>
        </div>
        
        <%- include('./partials/footer'); -%>
        
    <%- include('./partials/script'); -%>

</body>

</html>