Compare commits
No commits in common. "c8f8f825356acf9c558417b4b29713e70cc804eb" and "8e2b0ada3255077904490ed6f51fdb83fd6356ea" have entirely different histories.
c8f8f82535
...
8e2b0ada32
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module git.coopgo.io/coopgo-apps/parcoursmob
|
||||||
|
|
||||||
go 1.18
|
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/
|
// replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
for _, account := range resp.Accounts[min:] {
|
for _, account := range resp.Accounts[min:] {
|
||||||
if filterAccount(r, account) {
|
if filterAccount(r, account) {
|
||||||
fmt.Println(account)
|
|
||||||
a := account.ToStorageType()
|
a := account.ToStorageType()
|
||||||
accounts = append([]any{a}, accounts...)
|
accounts = append([]any{a}, accounts...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,8 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
|
||||||
vehicleBookings := []fleetsstorage.Booking{}
|
vehicleBookings := []fleetsstorage.Booking{}
|
||||||
for _, b := range v.Bookings {
|
for _, b := range v.Bookings {
|
||||||
if b.Status() != fleetsstorage.StatusOld {
|
if b.Status() != fleetsstorage.StatusOld {
|
||||||
if deleted, ok := b.Data["Deleted"].(bool); !ok && !deleted {
|
|
||||||
bookings = append(bookings, b)
|
bookings = append(bookings, b)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if b.Unavailableto.After(time.Now()) {
|
if b.Unavailableto.After(time.Now()) {
|
||||||
vehicleBookings = append(vehicleBookings, b)
|
vehicleBookings = append(vehicleBookings, b)
|
||||||
}
|
}
|
||||||
|
@ -190,10 +188,36 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
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())
|
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 {
|
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||||
g := r.Context().Value(identification.GroupKey)
|
g := r.Context().Value(identification.GroupKey)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
@ -467,208 +491,3 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
|
||||||
// fmt.Println(vehicles)
|
// fmt.Println(vehicles)
|
||||||
// h.Renderer.UnbookingVehicles(w, r, 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,17 +13,14 @@ import (
|
||||||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *ExportsHandler) Agenda(filter string) func(w http.ResponseWriter, r *http.Request) {
|
func (h *ExportsHandler) Agenda(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{
|
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@ -70,70 +67,15 @@ func (h *ExportsHandler) Agenda(filter string) func(w http.ResponseWriter, r *ht
|
||||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||||
}
|
}
|
||||||
|
|
||||||
f := h.generateExcel(events, groups, beneficiaries_map)
|
/////////////// Generate file
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[string]groupsstorage.Group,
|
|
||||||
beneficiaries_map map[string]accountsstorage.Account) *excelize.File {
|
|
||||||
f := excelize.NewFile()
|
f := excelize.NewFile()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := f.Close(); err != nil {
|
if err := f.Close(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
f.SetCellValue("Sheet1", "A1", "Evénement")
|
f.SetCellValue("Sheet1", "A1", "Evénement")
|
||||||
f.SetCellValue("Sheet1", "B1", "Date de début")
|
f.SetCellValue("Sheet1", "B1", "Date de début")
|
||||||
f.SetCellValue("Sheet1", "C1", "Date de fin")
|
f.SetCellValue("Sheet1", "C1", "Date de fin")
|
||||||
|
@ -142,8 +84,7 @@ func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[
|
||||||
f.SetCellValue("Sheet1", "F1", "Numéro allocataire / Pole emploi")
|
f.SetCellValue("Sheet1", "F1", "Numéro allocataire / Pole emploi")
|
||||||
f.SetCellValue("Sheet1", "G1", "Prescipteur")
|
f.SetCellValue("Sheet1", "G1", "Prescipteur")
|
||||||
f.SetCellValue("Sheet1", "H1", "Prescipteur Nom")
|
f.SetCellValue("Sheet1", "H1", "Prescipteur Nom")
|
||||||
f.SetCellValue("Sheet1", "I1", "Prescipteur Email")
|
f.SetCellValue("Sheet1", "I1", "Gestionnaire événement")
|
||||||
f.SetCellValue("Sheet1", "J1", "Gestionnaire événement")
|
|
||||||
// f.SetCellValue("Sheet1", "I1", "Prescripteur téléphone")
|
// f.SetCellValue("Sheet1", "I1", "Prescripteur téléphone")
|
||||||
|
|
||||||
i := 2
|
i := 2
|
||||||
|
@ -153,13 +94,11 @@ func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[
|
||||||
}
|
}
|
||||||
admin := groups[e.Owners[0]]
|
admin := groups[e.Owners[0]]
|
||||||
|
|
||||||
for _, s := range e.Subscriptions {
|
|
||||||
subscribedbygroup := ""
|
subscribedbygroup := ""
|
||||||
subscribedbyuser := ""
|
subscribedbyuser := ""
|
||||||
subscribedbyemail := ""
|
if v, ok := e.Data["subscribed_by"].(map[string]any); ok {
|
||||||
if v, ok := s.Data["subscribed_by"].(map[string]any); ok {
|
|
||||||
if v2, ok := v["group"].(map[string]any); ok {
|
if v2, ok := v["group"].(map[string]any); ok {
|
||||||
if v3, ok := v2["name"].(string); ok {
|
if v3, ok := v2["id"].(string); ok {
|
||||||
subscribedbygroup = v3
|
subscribedbygroup = v3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,13 +107,12 @@ func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[
|
||||||
if v5, ok := v4["display_name"].(string); ok {
|
if v5, ok := v4["display_name"].(string); ok {
|
||||||
subscribedbyuser = v5
|
subscribedbyuser = v5
|
||||||
}
|
}
|
||||||
if v6, ok := v4["email"].(string); ok {
|
|
||||||
subscribedbyemail = v6
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, s := range e.Subscriptions {
|
||||||
|
|
||||||
beneficiary := beneficiaries_map[s.Subscriber]
|
beneficiary := beneficiaries_map[s.Subscriber]
|
||||||
|
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("A%d", i), e.Name)
|
f.SetCellValue("Sheet1", fmt.Sprintf("A%d", i), e.Name)
|
||||||
|
@ -183,22 +121,17 @@ func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("D%d", i), beneficiary.Data["last_name"])
|
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("E%d", i), beneficiary.Data["first_name"])
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("F%d", i), beneficiary.Data["file_number"])
|
f.SetCellValue("Sheet1", fmt.Sprintf("F%d", i), beneficiary.Data["file_number"])
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("G%d", i), subscribedbygroup)
|
f.SetCellValue("Sheet1", fmt.Sprintf("G%d", i), groups[subscribedbygroup].Data["name"])
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("H%d", i), subscribedbyuser)
|
f.SetCellValue("Sheet1", fmt.Sprintf("H%d", i), subscribedbyuser)
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("I%d", i), subscribedbyemail)
|
f.SetCellValue("Sheet1", fmt.Sprintf("I%d", i), admin.Data["name"])
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("J%d", i), admin.Data["name"])
|
|
||||||
i = i + 1
|
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-Type", "application/octet-stream")
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
||||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
w.Header().Set("Expires", "0")
|
w.Header().Set("Expires", "0")
|
||||||
file.Write(w)
|
f.Write(w)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
|
||||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
|
@ -19,6 +18,7 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
vehicles := map[string]fleetsstorage.Vehicle{}
|
vehicles := map[string]fleetsstorage.Vehicle{}
|
||||||
bookings := []fleetsstorage.Booking{}
|
bookings := []fleetsstorage.Booking{}
|
||||||
|
|
||||||
reequest := &fleets.GetVehiclesRequest{
|
reequest := &fleets.GetVehiclesRequest{
|
||||||
Namespaces: []string{"parcoursmob"},
|
Namespaces: []string{"parcoursmob"},
|
||||||
}
|
}
|
||||||
|
@ -93,10 +93,8 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
||||||
f.SetCellValue("Sheet1", "H1", "Fin de mise Ă disposition")
|
f.SetCellValue("Sheet1", "H1", "Fin de mise Ă disposition")
|
||||||
f.SetCellValue("Sheet1", "I1", "Début indisponibilité")
|
f.SetCellValue("Sheet1", "I1", "Début indisponibilité")
|
||||||
f.SetCellValue("Sheet1", "J1", "Fin indisponibilité")
|
f.SetCellValue("Sheet1", "J1", "Fin indisponibilité")
|
||||||
f.SetCellValue("Sheet1", "K1", "Véhicule retiré")
|
f.SetCellValue("Sheet1", "K1", "Retrait par le gestionnaire")
|
||||||
f.SetCellValue("Sheet1", "L1", "Commentaire - Retrait véhicule")
|
f.SetCellValue("Sheet1", "L1", "Commentaire")
|
||||||
f.SetCellValue("Sheet1", "M1", "Réservation supprimée")
|
|
||||||
f.SetCellValue("Sheet1", "N1", "Motif de la suppression")
|
|
||||||
|
|
||||||
i := 2
|
i := 2
|
||||||
for _, b := range bookings {
|
for _, b := range bookings {
|
||||||
|
@ -108,31 +106,14 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
bookedby := ""
|
bookedby := ""
|
||||||
if v, ok := b.Data["booked_by"].(map[string]any); ok {
|
if v, ok := b.Data["booked_by"].(map[string]any); ok {
|
||||||
if v2, ok := v["user"].(map[string]any); ok {
|
if v2, ok := v["group"].(map[string]any); ok {
|
||||||
if v3, ok := v2["display_name"].(string); ok {
|
if v3, ok := v2["name"].(string); ok {
|
||||||
bookedby = v3
|
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]
|
beneficiary := beneficiaries_map[b.Driver]
|
||||||
adminunavailability := false
|
adminunavailability := false
|
||||||
|
|
||||||
|
@ -140,14 +121,6 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
||||||
adminunavailability = true
|
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("A%d", i), vehicle.Data["licence_plate"])
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("B%d", i), vehicle.Type)
|
f.SetCellValue("Sheet1", fmt.Sprintf("B%d", i), vehicle.Type)
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("C%d", i), admin.Data["name"])
|
f.SetCellValue("Sheet1", fmt.Sprintf("C%d", i), admin.Data["name"])
|
||||||
|
@ -160,8 +133,6 @@ 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("J%d", i), b.Unavailableto.Format("2006-01-02"))
|
||||||
f.SetCellValue("Sheet1", fmt.Sprintf("K%d", i), adminunavailability)
|
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("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
|
i = i + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
main.go
8
main.go
|
@ -108,10 +108,6 @@ func main() {
|
||||||
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
||||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
||||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
|
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("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
||||||
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
||||||
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
|
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
|
||||||
|
@ -167,9 +163,7 @@ func main() {
|
||||||
|
|
||||||
export := r.PathPrefix("/exports").Subrouter()
|
export := r.PathPrefix("/exports").Subrouter()
|
||||||
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
||||||
export.HandleFunc("/fleets/bookings/{groupid}", exportsHandler.Bookings)
|
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda)
|
||||||
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda("allEvents"))
|
|
||||||
export.HandleFunc("/agenda/{eventid}", exportsHandler.Agenda("oneEvent"))
|
|
||||||
export.Use(idp.Middleware)
|
export.Use(idp.Middleware)
|
||||||
export.Use(idp.GroupsMiddleware)
|
export.Use(idp.GroupsMiddleware)
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,11 @@ func (renderer *Renderer) VehiclesFleetDisplay(w http.ResponseWriter, r *http.Re
|
||||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any, vehicle_types []string) {
|
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.fleet_update.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.fleet_update.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
"vehicle": vehicle,
|
"vehicle": vehicle,
|
||||||
"vehicle_types": vehicle_types,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||||
|
@ -79,14 +78,3 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
|
||||||
|
|
||||||
renderer.Render("vehicles search", w, r, files, state)
|
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