rafamsilva

new booking

Apr 18th, 2023 (edited)
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <div class="container">
  2. <h1>Stormer Booking Details</h1>
  3. <div class="profile-info">
  4. <p><b>Stormer Name:</b> <%= @stormer.user.name %></p>
  5. <p><b>Cost Per Day:</b> <%= @stormer.costday %> AUD</p>
  6. </div>
  7.  
  8. <%= simple_form_for([@stormer, @booking]) do |f| %>
  9. <div class="form-inputs">
  10. <%= f.input :startdate, label: "Start Date",
  11. as: :date, start_year: Date.today.year,
  12. end_year: Date.today.year + 5,
  13. order: [:day, :month, :year],
  14. input_html: { id: "booking_startdate" } %>
  15. <%= f.input :enddate, label: "End Date", as: :date,
  16. end_year: Date.today.year + 5,
  17. order: [:day, :month, :year],
  18. input_html: { id: "booking_enddate" } %>
  19.  
  20. <%= f.input :status, as: :hidden, input_html: { value: 1 } %>
  21.  
  22. <div id="finalcost"></div>
  23.  
  24. <%= f.input :details, label: false, placeholder: "Details about the Storm" %>
  25. </div>
  26. <div class="form-actions">
  27. <%= f.button :submit, class: "btn btn-outline-success rounded-pill" %>
  28. </div>
  29. <% end %>
  30. </div>
  31.  
  32. <script>
  33. const startDateInput = document.querySelector('#booking_startdate');
  34. const endDateInput = document.querySelector('#booking_enddate');
  35. startDateInput.addEventListener('input', calculateTotalCost);
  36. endDateInput.addEventListener('input', calculateTotalCost);
  37.  
  38. function calculateTotalCost() {
  39. const startDate = startDateInput.value
  40. const endDate = endDateInput.value
  41. const days = endDate - startDate + 1
  42. const costPerDay = <%= @stormer.costday %>;
  43. const totalCost = costPerDay * days;
  44. document.querySelector('#finalcost').textContent = `Total Cost: ${totalCost} AUD`;
  45. </script>
  46.  
Advertisement
Add Comment
Please, Sign In to add comment