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

        <div class="page-body">

          <!-- Container-fluid starts-->
            <div class="container-fluid">
                <div class="row">
                 
                    <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 %>">

                    <!-- Scroll - vertical dynamic Starts-->
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <div>
                                        <h3><span class="font-danger"> <%= lang_data.Tracking_ID %> </span>#<%= pickup_data.invoice %></h3> 
                                    </div>

                                    <hr>

                                    <div class="d-flex justify-content-between align-items-center">
                                        <% if (pickup_data.shipping_status == null) { %>

                                            <h5><%= lang_data.Package_Status %> <span class="badge badge-primary p-2">Pick Up</span></h5>
                                        <% } else { %>

                                            <h5><%= lang_data.Package_Status %> <span class="badge badge-primary p-2"><%= pickup_data.shipping_status %></span></h5>
                                        <% } %>
                                        <h5><%= lang_data.invoice_status %>
                                            <% if (pickup_data.due_amount == '0') { %>
                                                <span class="badge badge-success p-2">Paid</span>
                                            <% } else { %>
                                                <span class="badge badge-warning p-2">Pending</span>
                                            <% } %>
                                        </h5>
                                        <div>
                                                <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.id == '1' || role_data.role == '3') { %>
                                                                
                                                                <% if (pickup_data.delivery_status == '6') { %>

                                                                    <% if (pickup_data.due_amount != '0' && role_data.id == '1') { %>
                                                                        <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#add_payment_toggle" id="pickup_add_payment" data-id="<%= pickup_data.id %>" data-invoice="<%= pickup_data.invoice %>" data-due="<%= pickup_data.due_amount %>"><i class="fa fa-money"></i> <%= lang_data.Add_Payment %></a>
                                                                    <% } %> 
                                                                    <a class="dropdown-item" href="/pickup/print_shipment/<%= pickup_data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                   
                                                                <% } else { %>
                                                                    
                                                                    <% if (pickup_data.due_amount != '0' && role_data.id == '1') { %>
                                                                        <a class="dropdown-item" href="/pickup/edit_create_pickup/<%= pickup_data.id %>"><i class="fa fa-pencil f-14"></i> <%= lang_data.Edit_Package %></a>
                                                                        <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#add_payment_toggle" id="pickup_add_payment" data-id="<%= pickup_data.id %>" data-invoice="<%= pickup_data.invoice %>" data-due="<%= pickup_data.due_amount %>"><i class="fa fa-money"></i> <%= lang_data.Add_Payment %></a>
                                                                    <% } %> 
                                                                    <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#assigndriver_toggle" id="pickup_assign_driver" data-id="<%= pickup_data.id %>" data-name="<%= pickup_data.assign_driver %>"><i class="fa fa-car f-14"></i> <%= lang_data.Assign_Driver %></a>
                                                                    <a class="dropdown-item" href="/pickup/print_shipment/<%= pickup_data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                                    <a class="dropdown-item" href="/pickup/pickup_tracking/<%= pickup_data.id %>"><i class="fa fa-refresh f-14"></i> <%= lang_data.Shipment_Tracking %></a>
                                                                    <a class="dropdown-item" href="/pickup/deliver_pickup/<%= pickup_data.id %>"><i class="fa fa-cube f-14"></i> <%= lang_data.Deliver_The_Shipment %></a>
                                                                <% } %>
                                                                
                                                            <% } else { %>
                                                                    
                                                                <% if (pickup_data.due_amount != '0') { %>
                                                                    <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#add_payment_toggle" id="pickup_add_payment" data-id="<%= pickup_data.id %>" data-invoice="<%= pickup_data.invoice %>" data-due="<%= pickup_data.due_amount %>"><i class="fa fa-money"></i> <%= lang_data.Add_Payment %></a>
                                                                <% } %> 
                                                                <a class="dropdown-item" href="/pickup/print_shipment/<%= pickup_data.id %>"><i class="fa fa-print f-14"></i> <%= lang_data.Print_Shipment %></a>
                                                            <% } %>
                                                        </div>
                                                </div>
                                        </div>
                                    </div>

                                    <hr class="mt-3">

                                    <div class="col-4">
                                        <div>
                                            <h5><%= lang_data.Agency %></h5>
                                            <span><%= pickup_data.agency_name %></span>
                                        </div>
                                        <div class="mt-4">
                                            <h5><%= lang_data.Estimated_delivery_date %></h5>
                                            <span><%= pickup_data.date.toLocaleDateString() %></span>
                                        </div>
                                        <div class="mt-4">
                                            <h5><%= lang_data.Delivery_time %></h5>
                                            <span><%= pickup_data.shipping_times %></span>
                                        </div>
                                    </div>

                                    <div class="col-4">
                                        <div>
                                            <h5><%= lang_data.Office %></h5>
                                            <span><%= pickup_data.office_name %></span>
                                        </div>
                                        <div class="mt-4">
                                            <h5><%= lang_data.Package_Type %></h5>
                                            <span><%= pickup_data.packaging_type %></span>
                                        </div>
                                        <div class="mt-4">
                                            <h5><%= lang_data.Payment_Methods %></h5>
                                            <span><%= pickup_data.payment_type_name %></span>
                                        </div>
                                    </div>

                                    <div class="col-4">
                                        <div>
                                            <h5><%= lang_data.Shipping_Modes %></h5>
                                            <span><%= pickup_data.service_name %></span>
                                        </div>
                                        <div class="mt-4">
                                            <h5><%= lang_data.Courier_company %></h5>
                                            <span><%= pickup_data.companies_name %></span>
                                        </div>
                                        <div class="mt-4">
                                            <h5><%= lang_data.Ship_Mode %></h5>
                                            <span><%= pickup_data.shipping_modes_name %></span>
                                        </div>
                                    </div>

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

                        <% if (pickup_data.delivery_status == '6') { %>

                            <div class="card">
                                <div class="card-body">
                                    <div class="row">
                                        <% tracking_data.forEach((data) => { %>
                                            <% if (data.delivery_status == '6') { %>

                                                <div class="col-4">
                                                    <div>
                                                        <h5><%= lang_data.Delivery_Date %></h5>
                                                        <span><%= data.date.toLocaleDateString() %> <%= data.time %></span>
                                                    </div>
                                                    <div class="mt-3">
                                                        <h5><%= lang_data.Photo %></h5>
                                                        <img id="file-preview" width="250px" height="250px" src="../../uploads/<%= data.image %>" alt="image">
                                                    </div>
                                                    
                                                </div>
                                                <div class="col-4">
                                                    <div>
                                                        <h5><%= lang_data.Delivered_By %></h5>
                                                        <span><%= accessdata.data.site_title %></span>
                                                    </div>
                                                    
                                                </div>
                                                <div class="col-4">
                                                    <div>
                                                        <h5><%= lang_data.Received_by %></h5>
                                                        <span><%= data.person_receives %></span>
                                                    </div>
                                                    
                                                </div>
                                            <% } %>
                                        <% }) %>
                                    </div>
                                </div>
                            </div>
                        <% } %> 

                        <!-- Tracking History -->

                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <h5><%= lang_data.Tracking_History %></h5>

                                    <hr>

                                    <div class="table-responsive theme-scrollbar">
                                        <table class="table" aria-label="table">
                                            <thead class="table-dark">
                                                <tr>
                                                    <th scope="col"><%= lang_data.Date_updated %></th>
                                                    <th scope="col"><%= lang_data.Time_update %></th>
                                                    <th scope="col"><%= lang_data.New_location %></th>
                                                    <th scope="col"><%= lang_data.Package_Status %></th>
                                                    <th scope="col"><%= lang_data.Remarks %></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <% tracking_data.forEach((data) => { %>

                                                    <tr>
                                                        <td><%= data.date.toLocaleDateString() %></td>
                                                        <td><%= data.time %></td>
                                                        <td><%= data.countries_name %></td>
                                                        <td><%= data.status_name %></td>
                                                        <td><%= data.message %></td>
                                                    </tr>
                                                <% }) %>
                                            </tbody>
                                        </table>
                                    </div>

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

                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <h5><%= lang_data.Shipping_details %></h5>

                                    <hr>

                                    <div class="table-responsive theme-scrollbar">
                                        <table class="table" aria-label="table">
                                            <thead class="table-dark">
                                                <tr>
                                                    <th scope="col"><%= lang_data.Package_Name %></th>
                                                    <th scope="col"><%= lang_data.Package_Description %></th>
                                                    <th scope="col"><%= lang_data.Amount %></th>
                                                    <th scope="col"><%= lang_data.Weight %></th>
                                                    <th scope="col"><%= lang_data.Length %></th>
                                                    <th scope="col"><%= lang_data.Width %></th>
                                                    <th scope="col"><%= lang_data.Height %></th>
                                                    <th scope="col"><%= lang_data.Weight_Vol %></th>
                                                    <th scope="col"><%= lang_data.Fixed_charge %></th>
                                                    <th scope="col"><%= lang_data.Declared_value %></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <% package_name_list.forEach((data, x) => { %>

                                                    <tr>
                                                        <td><%= data %></td>
                                                        <td><%= package_description_list[x] %></td>
                                                        <td class="invosymbol"><%= package_amount_list[x] %></td>
                                                        <td><%= weight_list[x] %></td>
                                                        <td><%= length_list[x] %></td>
                                                        <td><%= width_list[x] %></td>
                                                        <td><%= height_list[x] %></td>
                                                        <td><%= weight_vol_list[x] %></td>
                                                        <td class="invosymbol"><%= f_charge_list[x] %></td>
                                                        <td class="invosymbol"><%= decvalue_list[x] %></td>
                                                    </tr>
                                                <% }) %>
                                            </tbody>
                                        </table>

                                        <div class="col-12 mt-4">
                                            <div class="d-flex align-items-center justify-content-end">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Subtotal %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.subtotal %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2"> 

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-between">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Price_kg %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.add_price_kg %></span>
                                                </div>
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Discount %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.discount %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2"> 

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-between">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Weight %> :</span>
                                                    <span><%= pickup_data.total_weight %></span>
                                                </div>
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Value_assured %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.add_value_assured %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2"> 

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-between">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Total_Weight_Vol %> :</span>
                                                    <span><%= pickup_data.total_weight_vol %></span>
                                                </div>
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Shipping_Insurance %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.shipping_insurance %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2"> 

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-between">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Fixed_charge %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.fixed_charge %></span>
                                                </div>
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Customs_Duties %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.customs_duties %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2"> 

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-between">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Total_DecValue %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.total_decvalue %></span>
                                                </div>
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Tax %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.tax %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2"> 

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-end">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Declared_value %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.declared_value %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2">

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-end">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Fixed_charge %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.fixed_charge %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2">

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-end">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Reissue %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.reissue %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2">

                                        <div class="col-12">
                                            <div class="d-flex align-items-center justify-content-end">
                                                <div>
                                                    <span class="text-nowrap m-r-15"><%= lang_data.Total %> :</span>
                                                    <span class="invosymbol"><%= pickup_data.total %></span>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-2">

                                    </div>

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

                        <!-- Sender details -->

                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <h5><%= lang_data.Sender_details %></h5>

                                    <hr>
                                    <% customers_address.forEach((data, x) => { %>
                                        <% if (data == pickup_data.customer_address) { %>
                                        
                                            <div class="col-4">
                                                <div>
                                                    <h5><%= lang_data.Name %></h5>
                                                    <span><%= sender_data.first_name %> <%= sender_data.last_name %></span>
                                                </div>
                                                <div class="mt-4">
                                                    <h5><%= lang_data.Address %></h5>
                                                    <span><%= data %></span>
                                                </div>
                                            </div>

                                            <div class="col-4">
                                                <div>
                                                    <h5><%= lang_data.EMail %></h5>
                                                    <span><%= sender_data.email %></span>
                                                </div>
                                                <div class="mt-4">
                                                    <h5><%= lang_data.Country %></h5>
                                                    <% country_name.forEach((country_name) => { %>
                                                        <% if (country_name.id == customers_country[x] ) { %>

                                                            <span><%= country_name.countries_name %></span>
                                                        <% } %>
                                                    <% }) %>
                                                </div>
                                            </div>

                                            <div class="col-4">
                                                <div>
                                                    <h5><%= lang_data.Phone_No %></h5>
                                                    <span><%= sender_data.mobile %></span>
                                                </div>
                                                <div class="mt-4">
                                                    <h5><%= lang_data.City %></h5>
                                                    <% city_name.forEach((city_name) => { %>
                                                        <% if (city_name.id == customers_city[x] ) { %>

                                                            <span><%= city_name.city_name %></span>
                                                        <% } %>
                                                    <% }) %>
                                                </div>
                                            </div>
                                        <% } %>
                                    <% }) %>
                                </div>
                            </div>
                        </div>

                        <!-- Recipient details -->

                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <h5><%= lang_data.Recipient_details %></h5>

                                    <hr>
                                    <% recipient_address.forEach((data, x) => { %>
                                        <% if (data == pickup_data.client_address) { %>

                                            <div class="col-4">
                                                <div>
                                                    <h5><%= lang_data.Name %></h5>
                                                    <span><%= recipient_data.first_name %> <%= recipient_data.last_name %></span>
                                                </div>
                                                <div class="mt-4">
                                                    <h5><%= lang_data.Address %></h5>
                                                    <span><%= data %></span>
                                                </div>
                                            </div>

                                            <div class="col-4">
                                                <div>
                                                    <h5><%= lang_data.EMail %></h5>
                                                    <span><%= recipient_data.email %></span>
                                                </div>
                                                <div class="mt-4">
                                                    <h5><%= lang_data.Country %></h5>
                                                    <% country_name.forEach((country_name) => { %>
                                                        <% if (country_name.id == recipient_country[x] ) { %>

                                                            <span><%= country_name.countries_name %></span>
                                                        <% } %>
                                                    <% }) %>
                                                </div>
                                            </div>

                                            <div class="col-4">
                                                <div>
                                                    <h5><%= lang_data.Phone_No %></h5>
                                                    <span><%= recipient_data.mobile %></span>
                                                </div>
                                                <div class="mt-4">
                                                    <h5><%= lang_data.City %></h5>
                                                    <% city_name.forEach((city_name) => { %>
                                                        <% if (city_name.id == recipient_city[x] ) { %>

                                                            <span><%= city_name.city_name %></span>
                                                        <% } %>
                                                    <% }) %>
                                                </div>
                                            </div>
                                    
                                        <% } %>
                                    <% }) %>
                                </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="/pickup/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>