|
|
|
|
@@ -45,7 +45,9 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
|
|
|
|
|
vehicleBookings := []fleetsstorage.Booking{}
|
|
|
|
|
for _, b := range v.Bookings {
|
|
|
|
|
if b.Status() != fleetsstorage.StatusOld {
|
|
|
|
|
bookings = append(bookings, b)
|
|
|
|
|
if deleted, ok := b.Data["Deleted"].(bool); !ok && !deleted {
|
|
|
|
|
bookings = append(bookings, b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if b.Unavailableto.After(time.Now()) {
|
|
|
|
|
vehicleBookings = append(vehicleBookings, b)
|
|
|
|
|
@@ -494,6 +496,7 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
|
|
|
|
|
func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
|
bookingid := vars["bookingid"]
|
|
|
|
|
|
|
|
|
|
request := &fleets.GetBookingRequest{
|
|
|
|
|
Bookingid: bookingid,
|
|
|
|
|
}
|
|
|
|
|
@@ -504,6 +507,63 @@ func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Req
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
now := time.Now()
|
|
|
|
|
date := now.Format("2006-01-02")
|
|
|
|
|
unavailableto, _ := time.Parse("2006-01-02", date)
|
|
|
|
|
|
|
|
|
|
current_group, err := h.currentGroup(r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_user_token, current_user_claims, err := h.currentUser(r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
booked_by_id := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
|
|
|
|
booked_by_name := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
|
|
|
|
booked_by_email := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
|
|
|
|
booked_by_group_id := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
|
|
|
|
booked_by_group_name := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
|
|
|
|
|
|
|
|
|
data := map[string]any{
|
|
|
|
|
"booked_by": map[string]any{
|
|
|
|
|
"user": map[string]any{
|
|
|
|
|
"id": booked_by_id,
|
|
|
|
|
"display_name": booked_by_name,
|
|
|
|
|
"email": booked_by_email,
|
|
|
|
|
},
|
|
|
|
|
"group": map[string]any{
|
|
|
|
|
"id": booked_by_group_id,
|
|
|
|
|
"name": booked_by_group_name,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"unbooked_by": map[string]any{
|
|
|
|
|
"user": map[string]any{
|
|
|
|
|
"id": current_user_token.Subject,
|
|
|
|
|
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
|
|
|
|
"email": current_user_claims["email"],
|
|
|
|
|
},
|
|
|
|
|
"group": map[string]any{
|
|
|
|
|
"id": current_group.ID,
|
|
|
|
|
"name": current_group.Data["name"],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"Deleted": true,
|
|
|
|
|
"motif": r.FormValue("motif"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datapb, err := structpb.NewStruct(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if r.Method == "POST" {
|
|
|
|
|
|
|
|
|
|
@@ -515,9 +575,8 @@ func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Req
|
|
|
|
|
Startdate: resp.Booking.Startdate,
|
|
|
|
|
Enddate: resp.Booking.Enddate,
|
|
|
|
|
Unavailablefrom: resp.Booking.Unavailablefrom,
|
|
|
|
|
Unavailableto: resp.Booking.Unavailableto,
|
|
|
|
|
Data: resp.Booking.Data,
|
|
|
|
|
Deleted: true,
|
|
|
|
|
Unavailableto: timestamppb.New(unavailableto),
|
|
|
|
|
Data: datapb,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -532,5 +591,5 @@ func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Req
|
|
|
|
|
http.Redirect(w, r, "/app/vehicles-management/", http.StatusFound)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
h.Renderer.UnbookingVehicle(w, r, bookingid)
|
|
|
|
|
h.Renderer.UnbookingVehicle(w, r, resp.Booking.ToStorageType())
|
|
|
|
|
}
|
|
|
|
|
|