github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/core/datamodel/acces_field.go (about) 1 package datamodel 2 3 import ( 4 "math" 5 6 rd "github.com/benoitkugler/goACVE/server/core/rawdata" 7 ) 8 9 const ( 10 // zero est utile pour ignorer une colonne 11 _ rd.Field = iota 12 13 // partagé avec les organismes 14 PersonneNom 15 PersonnePrenom 16 PersonneSexe 17 PersonneAge 18 PersonneDateNaissance 19 PersonneRangMembreAsso 20 PersonneCotisation 21 22 PersonneTels // concrete type rd.Tels 23 PersonneMail 24 PersonneAdresse 25 PersonneCodePostal 26 PersonneVille 27 PersonnePays 28 29 PersonneCommune // codepostal + ville 30 31 PersonneNomPrenom 32 PersonneTelsLines 33 PersonneVersionPapier 34 PersonnePubHiver 35 PersonnePubEte 36 PersonneEchoRocher 37 PersonneQuotientFamilial 38 PersonneVilleNaissance 39 PersonneDepartementNaissance 40 PersonneNomJeuneFille 41 PersonneProfession 42 PersonneEtudiant 43 PersonneFonctionnaire 44 PersonneSecuriteSociale 45 PersonneEonews 46 PersonnePertinence 47 PersonneIdentifie 48 49 CampLieu 50 CampNom 51 CampPrix 52 CampNbPlaces 53 CampPassword 54 CampOuvert 55 CampNbPlacesReservees 56 CampIdJs 57 CampAnnee 58 CampDateDebut 59 CampDateFin 60 CampPeriode 61 CampRemplissage 62 CampLabel 63 CampJoomeoAlbumId 64 65 GroupeLabel 66 67 AideValeur 68 AideValide 69 AideMontant 70 AideNbJoursMax 71 AideStructure 72 AideCamp 73 AideAnnee 74 AideNomPrenom 75 76 StructureaideNom 77 StructureaideImmatriculation 78 StructureaideAdresse 79 StructureaideCodePostal 80 StructureaideVille 81 StructureaideTelephone 82 StructureaideInfo 83 84 DonValeur 85 DonModePaiement 86 DonDateReception 87 DonRemercie 88 DonRecuEmis 89 DonDetails 90 DonAffectation 91 DonDonateur 92 // coordonnées du donateur 93 DonDonateurTels 94 DonDonateurMail 95 DonDonateurAdresse 96 DonDonateurCodePostal 97 DonDonateurVille 98 DonDonateurPays 99 100 DocumentCategorie 101 DocumentTaille 102 DocumentNomClient 103 DocumentDescription 104 DocumentDateHeureModif 105 DocumentNomPrenom 106 107 PaiementIsAcompte 108 PaiementIsRemboursement 109 PaiementLabelPayeur 110 PaiementNomBanque 111 PaiementModePaiement 112 PaiementNumero 113 PaiementValeur 114 PaiementDateReglement 115 PaiementDetails 116 PaiementInBordereau 117 118 FactureCamps 119 FactureParticipants 120 121 ParticipantCamp 122 ParticipantGroupe 123 ParticipantAnimateur 124 ParticipantBus 125 ParticipantMaterielSki 126 ParticipantMaterielSkiType 127 ParticipantAgeDebutCamp 128 ParticipantRaisonAttente 129 ParticipantRespoNom 130 ParticipantRespoPrenom 131 ParticipantRespoNomPrenom 132 ParticipantRespoMail 133 ParticipantRespoTels 134 ParticipantRespoTelsLines 135 ParticipantRespoAdresse 136 ParticipantRespoCodePostal 137 ParticipantRespoVille 138 ParticipantRespoCommune // Ville + Code postal 139 ParticipantRespoPays 140 ParticipantEtat 141 ParticipantOptionPrix // requis par les directeurs 142 143 EquipierCamp 144 EquipierRoles 145 EquipierPresence 146 EquipierDiplome 147 EquipierAppro 148 149 InscriptionDateHeure 150 151 LastField 152 ) 153 154 // La couleur du text interpole de vert à rouge, 155 // en fonction de la `pertinence`. 156 func (ac AccesPersonne) AsItem(pertinence float64) rd.Item { 157 raw := ac.RawData() 158 fields := rd.F{ 159 PersonneNom: rd.String(raw.Nom.ToUpper()), 160 PersonnePrenom: rd.String(rd.FormatPrenom(raw.Prenom)), 161 PersonneNomPrenom: raw.NomPrenom(), 162 PersonneSexe: raw.Sexe.String(), 163 164 PersonneTels: raw.Tels, 165 PersonneTelsLines: raw.Tels.StringLines(), 166 PersonneMail: raw.Mail, 167 PersonneAdresse: raw.Adresse, 168 PersonneCodePostal: raw.CodePostal, 169 PersonneVille: raw.Ville, 170 PersonnePays: raw.Pays, 171 PersonneCommune: raw.CodePostal + " - " + raw.Ville, 172 173 PersonneVersionPapier: raw.VersionPapier.String(), 174 PersonnePubHiver: raw.PubHiver.String(), 175 PersonnePubEte: raw.PubEte.String(), 176 PersonneEchoRocher: raw.EchoRocher.String(), 177 PersonneRangMembreAsso: raw.RangMembreAsso, 178 PersonneQuotientFamilial: raw.QuotientFamilial, 179 PersonneVilleNaissance: raw.VilleNaissance, 180 PersonneDepartementNaissance: raw.DepartementNaissance, 181 PersonneNomJeuneFille: raw.NomJeuneFille, 182 PersonneDateNaissance: raw.DateNaissance, 183 PersonneProfession: raw.Profession, 184 PersonneEtudiant: raw.Etudiant.String(), 185 PersonneFonctionnaire: raw.Fonctionnaire.String(), 186 PersonneSecuriteSociale: rd.FormatSecuriteSocial(raw.SecuriteSociale), 187 PersonneCotisation: raw.Cotisation, 188 PersonneEonews: raw.Eonews.String(), 189 PersonneAge: rd.Int(raw.Age()), 190 PersonnePertinence: rd.Pourcent(int(pertinence * 100)), 191 PersonneIdentifie: (!raw.IsTemporaire).String(), 192 } 193 194 var textColor rd.Color 195 if pertinence != 0 { 196 greenLevel := uint8(math.Floor(pertinence * 160)) 197 textColor = rd.RGBA{R: 255 - greenLevel, G: greenLevel, B: 15, A: 255} 198 } 199 200 idColor := rd.Complete.Color() 201 if raw.IsTemporaire { 202 idColor = rd.NonCommencee.Color() 203 } 204 bgColors := rd.MapColors{PersonneIdentifie: idColor} 205 return rd.Item{Id: rd.IdPersonne(ac.Id), Fields: fields, TextColors: rd.ConstantColor{Color: textColor}, BackgroundColors: bgColors} 206 } 207 208 // La couleur de fond dépend de la période du séjour 209 func (ac AccesCamp) AsItem(cache1 LiensCampParticipants, cache2 LiensCampParticipantsimples) rd.Item { 210 raw := ac.RawData() 211 bgColor := raw.ColorPeriode() 212 fields := rd.F{ 213 CampLieu: raw.Lieu, 214 CampNom: raw.Nom, 215 CampPrix: raw.Prix, 216 CampNbPlaces: raw.NbPlaces, 217 CampPassword: raw.Password, 218 CampOuvert: raw.Ouvert.String(), 219 CampNbPlacesReservees: raw.NbPlacesReservees, 220 CampIdJs: raw.NumeroJS, 221 CampAnnee: raw.Annee(), 222 CampDateDebut: raw.DateDebut, 223 CampDateFin: raw.DateFin, 224 CampPeriode: raw.Periode(), 225 CampRemplissage: rd.Int(ac.Remplissage(cache1, cache2)), 226 CampLabel: raw.Label(), 227 CampJoomeoAlbumId: raw.JoomeoAlbumId, 228 } 229 return rd.Item{Id: rd.Id(ac.Id), Fields: fields, BackgroundColors: rd.ConstantColor{Color: bgColor}} 230 } 231 232 func (ac AccesGroupe) AsItem() rd.Item { 233 fields := rd.F{GroupeLabel: ac.Label()} 234 return rd.Item{Id: rd.Id(ac.Id), Fields: fields} 235 } 236 237 func (ac AccesAide) AsItem() rd.Item { 238 raw := ac.RawData() 239 camp := ac.GetParticipant().GetCamp() 240 fields := rd.F{ 241 AideValeur: raw.Valeur, 242 AideValide: raw.Valide.String(), 243 AideMontant: raw.Montant(), 244 AideNbJoursMax: raw.NbJoursMax, 245 AideStructure: ac.GetStructureaide().RawData().Nom, 246 AideCamp: camp.RawData().Nom, 247 AideAnnee: camp.RawData().Annee(), 248 AideNomPrenom: ac.GetParticipant().GetPersonne().RawData().NomPrenom(), 249 } 250 return rd.Item{Id: rd.Id(ac.Id), Fields: fields} 251 } 252 253 func (ac AccesStructureaide) AsItem() rd.Item { 254 raw := ac.RawData() 255 fields := rd.F{ 256 StructureaideNom: raw.Nom, 257 StructureaideImmatriculation: raw.Immatriculation, 258 StructureaideAdresse: raw.Adresse, 259 StructureaideCodePostal: raw.CodePostal, 260 StructureaideVille: raw.Ville, 261 StructureaideTelephone: raw.Telephone, 262 StructureaideInfo: raw.Info, 263 } 264 return rd.Item{Id: rd.Id(ac.Id), Fields: fields} 265 } 266 267 func (ac AccesDon) AsItem() rd.Item { 268 raw := ac.RawData() 269 var ( 270 donateurLabel rd.String 271 donateurCoord rd.Coordonnees 272 ) 273 switch donateur := ac.GetDonateur().(type) { 274 case AccesPersonne: 275 donateurLabel = donateur.RawData().NomPrenom() 276 donateurCoord = donateur.CoordonneesDons() 277 case AccesOrganisme: 278 donateurLabel = donateur.RawData().Nom 279 donateurCoord = donateur.CoordonneesDons() 280 default: 281 donateurLabel = "Don anonyme" 282 } 283 284 fields := rd.F{ 285 DonValeur: raw.Valeur, 286 DonModePaiement: raw.ModePaiement.String(), 287 DonDateReception: raw.DateReception, 288 DonRemercie: raw.Remercie.String(), 289 DonRecuEmis: raw.RecuEmis, 290 DonDetails: raw.Details, 291 DonAffectation: raw.Affectation, 292 DonDonateur: donateurLabel, 293 DonDonateurTels: donateurCoord.Tels, 294 DonDonateurMail: donateurCoord.Mail, 295 DonDonateurAdresse: donateurCoord.Adresse, 296 DonDonateurCodePostal: donateurCoord.CodePostal, 297 DonDonateurVille: donateurCoord.Ville, 298 DonDonateurPays: donateurCoord.Pays, 299 } 300 return rd.Item{Id: rd.Id(ac.Id), Fields: fields} 301 } 302 303 func (ac AccesDocumentPersonne) AsItem() rd.Item { 304 base := ac.AccesDocument.baseItem() 305 base.Fields[DocumentCategorie] = ac.GetContrainte().Nom 306 base.Fields[DocumentNomPrenom] = ac.GetProprietaire().RawData().NomPrenom() 307 return base 308 } 309 310 func (ac AccesDocumentAide) AsItem() rd.Item { 311 base := ac.AccesDocument.baseItem() 312 base.Fields[DocumentCategorie] = nil 313 base.Fields[DocumentNomPrenom] = ac.GetAide().GetParticipant().GetPersonne().RawData().NomPrenom() 314 return base 315 } 316 317 func (ac AccesDocument) baseItem() rd.Item { 318 raw := ac.RawData() 319 fields := rd.F{ 320 DocumentTaille: raw.Taille, 321 DocumentNomClient: raw.NomClient, 322 DocumentDescription: raw.Description, 323 DocumentDateHeureModif: raw.DateHeureModif, 324 } 325 return rd.Item{Id: rd.Id(ac.Id), Fields: fields} 326 } 327 328 func (ac AccesPaiement) AsItem() rd.Item { 329 raw := ac.RawData() 330 fields := rd.F{ 331 PaiementIsAcompte: raw.IsAcompte.String(), 332 PaiementIsRemboursement: raw.IsRemboursement.String(), 333 PaiementLabelPayeur: raw.LabelPayeur, 334 PaiementNomBanque: raw.NomBanque, 335 PaiementModePaiement: raw.ModePaiement.String(), 336 PaiementNumero: raw.Numero, 337 PaiementValeur: raw.Valeur, 338 PaiementDateReglement: raw.DateReglement, 339 PaiementDetails: raw.Details, 340 PaiementInBordereau: raw.InBordereau, 341 } 342 var color rd.Color 343 if raw.IsInvalide { 344 color = CouleurPaiementInvalide 345 } else if !raw.InBordereau.Time().IsZero() { 346 color = CouleurPaiementBordereau 347 } 348 colors := rd.ConstantColor{Color: color} 349 return rd.Item{Id: rd.Id(ac.Id), Fields: fields, BackgroundColors: colors} 350 } 351 352 func (ac AccesFacture) AsItem(cache1 LiensFactureParticipants, cache2 LiensFactureMessages, cache3 LiensFacturePaiements) rd.Item { 353 _, camps := ac.Camps(cache1) 354 355 fields := rd.F{ 356 PersonneIdentifie: (!ac.GetPersonne().RawData().IsTemporaire).String(), 357 PersonneNomPrenom: ac.GetPersonne().RawData().NomPrenom(), 358 PersonneMail: ac.GetPersonne().RawData().Mail, 359 FactureCamps: rd.String(camps), 360 FactureParticipants: rd.String(ac.participants(cache1)), 361 ParticipantCamp: nil, 362 InscriptionDateHeure: ac.GetEtat(cache2, cache3).InscriptionDateHeure(), 363 } 364 365 bgColor := rd.ConstantColor{Color: CouleurResponsable} 366 return rd.Item{Id: rd.IdFacture(ac.Id), Fields: fields, BackgroundColors: bgColor} 367 } 368 369 func (ac AccesParticipant) bgColor() rd.Color { 370 pers := ac.GetPersonne().RawData() 371 if pers.IsTemporaire { 372 return CouleurParticipantTmp 373 } 374 375 // on affiche l'âge invalide uniquement sur la liste d'attente 376 if !ac.RawData().ListeAttente.IsInscrit() && !ac.IsAgeValide() { 377 return CouleurAgeInvalide 378 } 379 switch ac.RawData().ListeAttente.Statut { 380 case rd.AttenteReponse: 381 return CouleurAttenteReponse 382 case rd.Attente: 383 return CouleurListeAttente 384 } 385 386 return nil 387 } 388 389 // AsItem accède aussi aux champx d'un éventuel responsable 390 func (ac AccesParticipant) AsItem(cache rd.LiensCampParticipants) rd.Item { 391 personne := ac.GetPersonne() 392 // on commence par les champs de la personne associée 393 fields := personne.AsItem(0).Fields 394 395 raw := ac.RawData() 396 397 // on ajoute ceux du participant ... 398 fields[ParticipantCamp] = ac.GetCamp().RawData().Label() 399 groupe, _ := ac.GetGroupe() 400 fields[ParticipantGroupe] = groupe.Nom // vide si aucun groupe 401 animateur, _ := ac.GetAnimateur() 402 fields[ParticipantAnimateur] = rd.String(animateur.Personne.FPrenom()) // vide si aucun groupe 403 fields[ParticipantBus] = raw.Options.Bus.String() 404 fields[ParticipantMaterielSki] = raw.Options.MaterielSki.String() 405 fields[ParticipantMaterielSkiType] = rd.String(raw.Options.MaterielSki.Need) 406 fields[ParticipantAgeDebutCamp] = ac.AgeDebutCamp() 407 fields[ParticipantRaisonAttente] = ac.HintsAttente(cache) 408 fields[ParticipantEtat] = nil 409 fields[ParticipantOptionPrix] = ac.AsParticipantCamp().AsOptionParticipantCamp().Description() 410 411 // ... puis ceux du responsable 412 var respoFields rd.F 413 if fac, hasFacture := ac.GetFacture(); hasFacture { 414 respoFields = fac.GetPersonne().AsItem(0).Fields 415 } 416 fields[ParticipantRespoNom] = respoFields[PersonneNom] 417 fields[ParticipantRespoPrenom] = respoFields[PersonnePrenom] 418 fields[ParticipantRespoNomPrenom] = respoFields[PersonneNomPrenom] 419 fields[ParticipantRespoMail] = respoFields[PersonneMail] 420 fields[ParticipantRespoTels] = respoFields[PersonneTels] 421 fields[ParticipantRespoTelsLines] = respoFields[PersonneTelsLines] 422 fields[ParticipantRespoAdresse] = respoFields[PersonneAdresse] 423 fields[ParticipantRespoCodePostal] = respoFields[PersonneCodePostal] 424 fields[ParticipantRespoVille] = respoFields[PersonneVille] 425 fields[ParticipantRespoCommune] = respoFields[PersonneCommune] 426 fields[ParticipantRespoPays] = respoFields[PersonnePays] 427 428 var fgColor rd.Colors 429 if ac.HasAnniversaire() { 430 fgColor = rd.ConstantColor{Color: CouleurAnniversaire} 431 } 432 433 var bgColor rd.Colors 434 if colorbg := ac.bgColor(); colorbg != nil { 435 bgColor = rd.ConstantColor{Color: colorbg} 436 } else { 437 bgColorM := rd.MapColors{} 438 switch personne.RawData().Sexe { 439 case "M": 440 bgColorM[PersonneSexe] = CouleurGarcon 441 case "F": 442 bgColorM[PersonneSexe] = CouleurFille 443 } 444 bgColorM[ParticipantGroupe] = rd.HexColor(groupe.Couleur) 445 bgColor = bgColorM 446 } 447 return rd.Item{Id: rd.IdParticipant(ac.Id), Fields: fields, BackgroundColors: bgColor, TextColors: fgColor} 448 } 449 450 func (ac AccesParticipantsimple) AsItem() rd.Item { 451 // on commence par les champs de la personne associée 452 fields := ac.GetPersonne().AsItem(0).Fields 453 454 raw := ac.RawData() 455 456 // on ajoute ceux du participant ... 457 fields[ParticipantCamp] = ac.GetCamp().RawData().Label() 458 fields[ParticipantAgeDebutCamp] = ac.AgeDebutCamp() 459 fields[InscriptionDateHeure] = raw.DateHeure 460 return rd.Item{Id: rd.IdParticipantsimple(ac.Id), Fields: fields} 461 } 462 463 func (ac AccesEquipier) AsItem() rd.Item { 464 // on commence par les champs de la personne associée 465 fields := ac.GetPersonne().AsItem(0).Fields 466 467 raw := ac.RawData() 468 fields[EquipierCamp] = ac.GetCamp().RawData().Label() 469 fields[EquipierRoles] = raw.Roles 470 fields[EquipierDiplome] = raw.Diplome.String() 471 fields[EquipierAppro] = raw.Appro.String() 472 fields[EquipierPresence] = ac.GetPresence() 473 474 return rd.Item{Id: rd.Id(ac.Id), Fields: fields} 475 } 476 477 func (ac AccesOrganisme) AsItem() rd.Item { 478 raw := ac.RawData() 479 fields := rd.F{ 480 PersonneNom: raw.Nom, 481 PersonneNomPrenom: raw.Nom, 482 PersonneTels: raw.Contact.Tels, 483 PersonneMail: raw.Contact.Mail, 484 PersonneAdresse: raw.Contact.Adresse, 485 PersonneCodePostal: raw.Contact.CodePostal, 486 PersonneVille: raw.Contact.Ville, 487 PersonnePays: raw.Contact.Pays, 488 } 489 return rd.Item{Id: rd.IdOrganisme(ac.Id), Fields: fields} 490 }