Compare commits
18 Commits
8e2b0ada32
...
c8f8f82535
Author | SHA1 | Date |
---|---|---|
Arnaud Delcasse | c8f8f82535 | |
Arnaud Delcasse | 0f5a0ed5ab | |
Nicolas CARON | 275c8b1999 | |
Nicolas CARON | 18e890ceed | |
Nicolas CARON | b717be9b99 | |
Nicolas CARON | ddb08cf671 | |
Nicolas CARON | 4fe479c1fb | |
Nicolas CARON | b0dd81bf67 | |
soukainna | 3bfd2e1bfe | |
soukainna | b5154bf9be | |
soukainna | 96823f3289 | |
soukainna | 93cab33fb9 | |
soukainna | d5bc764ef3 | |
soukainna | 1aeb6d50ef | |
Nicolas CARON | f26d792b8b | |
Nicolas CARON | bfd14d7f4c | |
Nicolas CARON | 31e5eadc73 | |
Nicolas CARON | 8f20a12bc5 |
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module git.coopgo.io/coopgo-apps/parcoursmob
|
|||
|
||||
go 1.18
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||
replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
for _, account := range resp.Accounts[min:] {
|
||||
if filterAccount(r, account) {
|
||||
fmt.Println(account)
|
||||
a := account.ToStorageType()
|
||||
accounts = append([]any{a}, accounts...)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -188,36 +190,10 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
||||
// fmt.Println("lol")
|
||||
// }
|
||||
// fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
||||
|
||||
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
vehicleid := vars["vehicleid"]
|
||||
|
||||
if r.Method == "POST" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
request := &fleets.GetVehicleRequest{
|
||||
Vehicleid: vehicleid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType())
|
||||
}
|
||||
|
||||
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
|
@ -467,27 +443,232 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
|
|||
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", vehicleid), http.StatusFound)
|
||||
}
|
||||
|
||||
// func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) {
|
||||
// request := &fleets.GetVehiclesRequest{
|
||||
// Namespaces: []string{"parcoursmob"},
|
||||
// }
|
||||
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// }
|
||||
// vehicles := []fleetsstorage.Vehicle{}
|
||||
// fmt.Println(resp.Vehicles[0].Bookings)
|
||||
// for i, vehicle := range resp.Vehicles {
|
||||
// if len(resp.Vehicles[i].Bookings) == 0 {
|
||||
// v := vehicle.ToStorageType()
|
||||
// vehicles = append(vehicles, v)
|
||||
// }
|
||||
// }
|
||||
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
||||
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
|
||||
// // }
|
||||
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
||||
// fmt.Println(vehicles)
|
||||
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
||||
// }
|
||||
// func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) {
|
||||
// request := &fleets.GetVehiclesRequest{
|
||||
// Namespaces: []string{"parcoursmob"},
|
||||
// }
|
||||
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// }
|
||||
// vehicles := []fleetsstorage.Vehicle{}
|
||||
// fmt.Println(resp.Vehicles[0].Bookings)
|
||||
// for i, vehicle := range resp.Vehicles {
|
||||
// if len(resp.Vehicles[i].Bookings) == 0 {
|
||||
// v := vehicle.ToStorageType()
|
||||
// vehicles = append(vehicles, v)
|
||||
// }
|
||||
// }
|
||||
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
||||
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
|
||||
// // }
|
||||
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
||||
// fmt.Println(vehicles)
|
||||
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
||||
// }
|
||||
|
||||
func (h *ApplicationHandler) DeleteBooking(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bookingid := vars["bookingid"]
|
||||
|
||||
request := &fleets.DeleteBookingRequest{
|
||||
Id: bookingid,
|
||||
}
|
||||
|
||||
_, err := h.services.GRPC.Fleets.DeleteBooking(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/app/vehicles-management/bookings/", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bookingid := vars["bookingid"]
|
||||
|
||||
request := &fleets.GetBookingRequest{
|
||||
Bookingid: bookingid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// now := time.Now()
|
||||
// date := now.Format("2006-01-02")
|
||||
|
||||
date := "1970-01-01"
|
||||
unavailableto, _ := time.Parse("2006-01-02", date)
|
||||
unavailablefrom := unavailableto
|
||||
|
||||
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" {
|
||||
|
||||
request := &fleets.UpdateBookingRequest{
|
||||
Booking: &fleets.Booking{
|
||||
Id: resp.Booking.Id,
|
||||
Vehicleid: resp.Booking.Vehicleid,
|
||||
Driver: resp.Booking.Driver,
|
||||
Startdate: resp.Booking.Startdate,
|
||||
Enddate: resp.Booking.Enddate,
|
||||
Unavailablefrom: timestamppb.New(unavailablefrom),
|
||||
Unavailableto: timestamppb.New(unavailableto),
|
||||
Data: datapb,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/app/vehicles-management/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
h.Renderer.UnbookingVehicle(w, r, resp.Booking.ToStorageType())
|
||||
}
|
||||
|
||||
////////////////////////UpdateVehicle///////////////////////
|
||||
|
||||
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
vehicleID := vars["vehicleid"]
|
||||
request := &fleets.GetVehicleRequest{
|
||||
Vehicleid: vehicleID,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
namespaceV := resp.Vehicle.Namespace
|
||||
//typeV := resp.Vehicle.Type
|
||||
administratorsV := resp.Vehicle.Administrators
|
||||
|
||||
if r.Method == "POST" {
|
||||
fmt.Print(r.FormValue("vehicle_type"))
|
||||
if err := r.ParseForm(); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
dataMap := map[string]any{}
|
||||
if v := r.FormValue("name"); v != "" {
|
||||
dataMap["name"] = v
|
||||
}
|
||||
if v := r.FormValue("address"); v != "" {
|
||||
var address map[string]any
|
||||
err := json.Unmarshal([]byte(v), &address)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
dataMap["address"] = address
|
||||
}
|
||||
if v := r.FormValue("informations"); v != "" {
|
||||
dataMap["informations"] = v
|
||||
}
|
||||
if v := r.FormValue("licence_plate"); v != "" {
|
||||
dataMap["licence_plate"] = v
|
||||
}
|
||||
if v := r.FormValue("automatic"); v != "" {
|
||||
fmt.Println(v)
|
||||
dataMap["automatic"] = (v == "on")
|
||||
}
|
||||
|
||||
data, err := structpb.NewValue(dataMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request := &fleets.UpdateVehicleRequest{
|
||||
Vehicle: &fleets.Vehicle{
|
||||
Id: vehicleID,
|
||||
Namespace: namespaceV,
|
||||
Type: r.FormValue("type"),
|
||||
Administrators: administratorsV,
|
||||
Data: data.GetStructValue(),
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.UpdateVehicle(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", resp.Vehicle.Id), http.StatusFound)
|
||||
return
|
||||
}
|
||||
vehicles_types := h.config.GetStringSlice("modules.fleets.vehicle_types")
|
||||
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType(), vehicles_types)
|
||||
}
|
||||
|
|
|
@ -13,69 +13,127 @@ import (
|
|||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
func (h *ExportsHandler) Agenda(filter string) func(w http.ResponseWriter, r *http.Request) {
|
||||
switch filter {
|
||||
case "allEvents":
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
events := []agendastorage.Event{}
|
||||
|
||||
events := []agendastorage.Event{}
|
||||
groupids := []string{}
|
||||
beneficiaries_ids := []string{}
|
||||
for _, e := range resp.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
events = append(events, e.ToStorageType())
|
||||
|
||||
groupids := []string{}
|
||||
beneficiaries_ids := []string{}
|
||||
for _, e := range resp.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
events = append(events, e.ToStorageType())
|
||||
for _, subscriptions := range e.Subscriptions {
|
||||
beneficiaries_ids = append(beneficiaries_ids, subscriptions.Subscriber)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(events))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]groupsstorage.Group{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
f := h.generateExcel(events, groups, beneficiaries_map)
|
||||
|
||||
h.writeFileResponse(f, w)
|
||||
}
|
||||
|
||||
case "oneEvent":
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventId := vars["eventid"]
|
||||
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), &agenda.GetEventRequest{
|
||||
Id: eventId,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
groupids := []string{}
|
||||
beneficiaries_ids := []string{}
|
||||
groupids = append(groupids, resp.Event.Owners...)
|
||||
for _, subscriptions := range resp.Event.Subscriptions {
|
||||
beneficiaries_ids = append(beneficiaries_ids, subscriptions.Subscriber)
|
||||
}
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]groupsstorage.Group{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
f := h.generateExcel([]agendastorage.Event{resp.Event.ToStorageType()}, groups, beneficiaries_map)
|
||||
h.writeFileResponse(f, w)
|
||||
|
||||
for _, subscriptions := range e.Subscriptions {
|
||||
beneficiaries_ids = append(beneficiaries_ids, subscriptions.Subscriber)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(events))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]groupsstorage.Group{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
/////////////// Generate file
|
||||
|
||||
func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[string]groupsstorage.Group,
|
||||
beneficiaries_map map[string]accountsstorage.Account) *excelize.File {
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
f.SetCellValue("Sheet1", "A1", "Evénement")
|
||||
f.SetCellValue("Sheet1", "B1", "Date de début")
|
||||
f.SetCellValue("Sheet1", "C1", "Date de fin")
|
||||
|
@ -84,7 +142,8 @@ func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
|||
f.SetCellValue("Sheet1", "F1", "Numéro allocataire / Pole emploi")
|
||||
f.SetCellValue("Sheet1", "G1", "Prescipteur")
|
||||
f.SetCellValue("Sheet1", "H1", "Prescipteur Nom")
|
||||
f.SetCellValue("Sheet1", "I1", "Gestionnaire événement")
|
||||
f.SetCellValue("Sheet1", "I1", "Prescipteur Email")
|
||||
f.SetCellValue("Sheet1", "J1", "Gestionnaire événement")
|
||||
// f.SetCellValue("Sheet1", "I1", "Prescripteur téléphone")
|
||||
|
||||
i := 2
|
||||
|
@ -94,24 +153,27 @@ func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
admin := groups[e.Owners[0]]
|
||||
|
||||
subscribedbygroup := ""
|
||||
subscribedbyuser := ""
|
||||
if v, ok := e.Data["subscribed_by"].(map[string]any); ok {
|
||||
if v2, ok := v["group"].(map[string]any); ok {
|
||||
if v3, ok := v2["id"].(string); ok {
|
||||
subscribedbygroup = v3
|
||||
}
|
||||
|
||||
}
|
||||
if v4, ok := v["user"].(map[string]any); ok {
|
||||
if v5, ok := v4["display_name"].(string); ok {
|
||||
subscribedbyuser = v5
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range e.Subscriptions {
|
||||
subscribedbygroup := ""
|
||||
subscribedbyuser := ""
|
||||
subscribedbyemail := ""
|
||||
if v, ok := s.Data["subscribed_by"].(map[string]any); ok {
|
||||
if v2, ok := v["group"].(map[string]any); ok {
|
||||
if v3, ok := v2["name"].(string); ok {
|
||||
subscribedbygroup = v3
|
||||
}
|
||||
|
||||
}
|
||||
if v4, ok := v["user"].(map[string]any); ok {
|
||||
if v5, ok := v4["display_name"].(string); ok {
|
||||
subscribedbyuser = v5
|
||||
}
|
||||
if v6, ok := v4["email"].(string); ok {
|
||||
subscribedbyemail = v6
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
beneficiary := beneficiaries_map[s.Subscriber]
|
||||
|
||||
|
@ -121,17 +183,22 @@ func (h *ExportsHandler) Agenda(w http.ResponseWriter, r *http.Request) {
|
|||
f.SetCellValue("Sheet1", fmt.Sprintf("D%d", i), beneficiary.Data["last_name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("E%d", i), beneficiary.Data["first_name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("F%d", i), beneficiary.Data["file_number"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("G%d", i), groups[subscribedbygroup].Data["name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("G%d", i), subscribedbygroup)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("H%d", i), subscribedbyuser)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("I%d", i), admin.Data["name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("I%d", i), subscribedbyemail)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("J%d", i), admin.Data["name"])
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
}
|
||||
return f
|
||||
|
||||
}
|
||||
|
||||
func (h *ExportsHandler) writeFileResponse(file *excelize.File, w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
w.Header().Set("Expires", "0")
|
||||
f.Write(w)
|
||||
file.Write(w)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
|
@ -18,7 +19,6 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
vehicles := map[string]fleetsstorage.Vehicle{}
|
||||
bookings := []fleetsstorage.Booking{}
|
||||
|
||||
reequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
|
@ -93,8 +93,10 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
|||
f.SetCellValue("Sheet1", "H1", "Fin de mise Ă disposition")
|
||||
f.SetCellValue("Sheet1", "I1", "Début indisponibilité")
|
||||
f.SetCellValue("Sheet1", "J1", "Fin indisponibilité")
|
||||
f.SetCellValue("Sheet1", "K1", "Retrait par le gestionnaire")
|
||||
f.SetCellValue("Sheet1", "L1", "Commentaire")
|
||||
f.SetCellValue("Sheet1", "K1", "Véhicule retiré")
|
||||
f.SetCellValue("Sheet1", "L1", "Commentaire - Retrait véhicule")
|
||||
f.SetCellValue("Sheet1", "M1", "Réservation supprimée")
|
||||
f.SetCellValue("Sheet1", "N1", "Motif de la suppression")
|
||||
|
||||
i := 2
|
||||
for _, b := range bookings {
|
||||
|
@ -106,14 +108,31 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
bookedby := ""
|
||||
if v, ok := b.Data["booked_by"].(map[string]any); ok {
|
||||
if v2, ok := v["group"].(map[string]any); ok {
|
||||
if v3, ok := v2["name"].(string); ok {
|
||||
if v2, ok := v["user"].(map[string]any); ok {
|
||||
if v3, ok := v2["display_name"].(string); ok {
|
||||
bookedby = v3
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bookedbygroup := ""
|
||||
if v4, ok := b.Data["booked_by"].(map[string]any); ok {
|
||||
if v5, ok := v4["group"].(map[string]any); ok {
|
||||
if v6, ok := v5["id"].(string); ok {
|
||||
bookedbygroup = v6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// filter by group
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
group := g.(groupsstorage.Group)
|
||||
|
||||
if bookedbygroup != group.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
beneficiary := beneficiaries_map[b.Driver]
|
||||
adminunavailability := false
|
||||
|
||||
|
@ -121,6 +140,14 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
|||
adminunavailability = true
|
||||
}
|
||||
|
||||
deleted := ""
|
||||
v, ok := b.Data["Deleted"]
|
||||
fmt.Println(v)
|
||||
fmt.Println(ok)
|
||||
if b.Deleted || (ok && v.(bool)) {
|
||||
deleted = "DELETED"
|
||||
}
|
||||
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("A%d", i), vehicle.Data["licence_plate"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("B%d", i), vehicle.Type)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("C%d", i), admin.Data["name"])
|
||||
|
@ -133,6 +160,8 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
|||
f.SetCellValue("Sheet1", fmt.Sprintf("J%d", i), b.Unavailableto.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("K%d", i), adminunavailability)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("L%d", i), b.Data["comment"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("M%d", i), deleted)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("N%d", i), b.Data["motif"])
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
|
|
8
main.go
8
main.go
|
@ -108,6 +108,10 @@ func main() {
|
|||
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
|
||||
/////////////////////////////////////Remove booking vehicle/////////////////////////////////////////
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/delete", applicationHandler.UnbookingVehicle)
|
||||
// application.HandleFunc("/vehicles-management/bookings/{bookingid}/delete", applicationHandler.DeleteBooking)
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
||||
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
||||
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
|
||||
|
@ -163,7 +167,9 @@ func main() {
|
|||
|
||||
export := r.PathPrefix("/exports").Subrouter()
|
||||
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
||||
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda)
|
||||
export.HandleFunc("/fleets/bookings/{groupid}", exportsHandler.Bookings)
|
||||
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda("allEvents"))
|
||||
export.HandleFunc("/agenda/{eventid}", exportsHandler.Agenda("oneEvent"))
|
||||
export.Use(idp.Middleware)
|
||||
export.Use(idp.GroupsMiddleware)
|
||||
|
||||
|
|
|
@ -53,11 +53,12 @@ func (renderer *Renderer) VehiclesFleetDisplay(w http.ResponseWriter, r *http.Re
|
|||
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any) {
|
||||
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any, vehicle_types []string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.fleet_update.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"vehicle": vehicle,
|
||||
"vehicle": vehicle,
|
||||
"vehicle_types": vehicle_types,
|
||||
}
|
||||
|
||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||
|
@ -78,3 +79,14 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
|
|||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) UnbookingVehicle(w http.ResponseWriter, r *http.Request, booking any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"booking": booking,
|
||||
}
|
||||
|
||||
renderer.Render("vehicule unbooking", w, r, files, state)
|
||||
|
||||
}
|
Loading…
Reference in New Issue