|
|
|
@ -23,6 +23,7 @@ import (
|
|
|
|
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
|
|
|
|
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
|
|
|
|
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"
|
|
|
|
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
|
|
|
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
|
|
|
@ -43,6 +44,67 @@ type BeneficiariesForm struct {
|
|
|
|
|
Gender string `json:"gender"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Event_Beneficiary interface {
|
|
|
|
|
Name() string
|
|
|
|
|
Date() time.Time
|
|
|
|
|
DateEnd() time.Time
|
|
|
|
|
Type() string
|
|
|
|
|
Db() string
|
|
|
|
|
ID() string
|
|
|
|
|
Icons() string
|
|
|
|
|
Status() int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Event struct {
|
|
|
|
|
IDVal string
|
|
|
|
|
NameVal string
|
|
|
|
|
DateVal time.Time
|
|
|
|
|
DateEndVal time.Time
|
|
|
|
|
TypeVal string
|
|
|
|
|
DbVal string
|
|
|
|
|
Deleted bool
|
|
|
|
|
IconSet string
|
|
|
|
|
StatusVal int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) Name() string {
|
|
|
|
|
return e.NameVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) Date() time.Time {
|
|
|
|
|
return e.DateVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) DateEnd() time.Time {
|
|
|
|
|
return e.DateEndVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) Type() string {
|
|
|
|
|
return e.TypeVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) ID() string {
|
|
|
|
|
return e.IDVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) Db() string {
|
|
|
|
|
return e.DbVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) Icons() string {
|
|
|
|
|
return e.IconSet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e Event) Status() int {
|
|
|
|
|
return e.StatusVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sortByDate(events []Event_Beneficiary) {
|
|
|
|
|
sort.Slice(events, func(i, j int) bool {
|
|
|
|
|
return events[i].Date().After(events[j].Date())
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
accounts, err := h.beneficiaries(r)
|
|
|
|
@ -149,6 +211,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
events := []agendastorage.Event{}
|
|
|
|
|
currentTime := time.Now().Truncate(24 * time.Hour)
|
|
|
|
|
|
|
|
|
|
for _, e := range subcriptionresp.Subscription {
|
|
|
|
|
eventresquest := &agenda.GetEventRequest{
|
|
|
|
@ -160,10 +223,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
currentTime := time.Now().Truncate(24 * time.Hour)
|
|
|
|
|
if eventresp.Event.Startdate.AsTime().Equal(currentTime) || eventresp.Event.Startdate.AsTime().After(currentTime) {
|
|
|
|
|
events = append(events, eventresp.Event.ToStorageType())
|
|
|
|
|
}
|
|
|
|
|
events = append(events, eventresp.Event.ToStorageType())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sort.Sort(sorting.EventsByStartdate(events))
|
|
|
|
@ -178,12 +238,78 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bookings := []any{}
|
|
|
|
|
bookings := []fleetsstorage.Booking{}
|
|
|
|
|
|
|
|
|
|
for _, b := range bookingsresp.Bookings {
|
|
|
|
|
bookings = append(bookings, b.ToStorageType())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var events_list []Event_Beneficiary
|
|
|
|
|
var status_event int
|
|
|
|
|
|
|
|
|
|
for _, e := range events {
|
|
|
|
|
|
|
|
|
|
if e.Startdate.After(currentTime) {
|
|
|
|
|
status_event = 1
|
|
|
|
|
} else if e.Startdate.Before(currentTime) && e.Enddate.After(currentTime) || e.Enddate.Equal(currentTime) {
|
|
|
|
|
status_event = 2
|
|
|
|
|
} else {
|
|
|
|
|
status_event = 3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event := Event{
|
|
|
|
|
NameVal: e.Name,
|
|
|
|
|
DateVal: e.Startdate,
|
|
|
|
|
DateEndVal: e.Enddate,
|
|
|
|
|
TypeVal: e.Type,
|
|
|
|
|
IDVal: e.ID,
|
|
|
|
|
DbVal: "/app/agenda/",
|
|
|
|
|
IconSet: "calendar",
|
|
|
|
|
StatusVal: status_event,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
events_list = append(events_list, event)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var status_booking int
|
|
|
|
|
for _, b := range bookings {
|
|
|
|
|
|
|
|
|
|
if b.Enddate.After(currentTime) || b.Enddate.Equal(currentTime) {
|
|
|
|
|
GetVehiculeRequest := &fleets.GetVehicleRequest{
|
|
|
|
|
Vehicleid: b.Vehicleid,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetVehiculeResp, err := h.services.GRPC.Fleets.GetVehicle(context.Background(), GetVehiculeRequest)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.Startdate.After(currentTime) {
|
|
|
|
|
status_booking = 1
|
|
|
|
|
} else if b.Startdate.Before(currentTime) && b.Enddate.After(currentTime) || b.Enddate.Equal(currentTime) {
|
|
|
|
|
status_booking = 2
|
|
|
|
|
} else {
|
|
|
|
|
status_booking = 3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event := Event{
|
|
|
|
|
NameVal: GetVehiculeResp.Vehicle.ToStorageType().Data["name"].(string),
|
|
|
|
|
DateVal: b.Startdate,
|
|
|
|
|
DateEndVal: b.Enddate,
|
|
|
|
|
TypeVal: "Réservation de véhicule",
|
|
|
|
|
IDVal: b.ID,
|
|
|
|
|
DbVal: "/app/vehicles-management/bookings/",
|
|
|
|
|
IconSet: "vehicle",
|
|
|
|
|
StatusVal: status_booking,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
events_list = append(events_list, event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sortByDate(events_list)
|
|
|
|
|
|
|
|
|
|
groupsrequest := &groupsmanagement.GetGroupsRequest{
|
|
|
|
|
Namespaces: []string{"parcoursmob_organizations"},
|
|
|
|
|
Member: beneficiaryID,
|
|
|
|
@ -202,7 +328,7 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|
|
|
|
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
|
|
|
|
|
file_types_map := h.config.GetStringMapString("storage.files.file_types")
|
|
|
|
|
|
|
|
|
|
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events)
|
|
|
|
|
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|