github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/client/GUI/common/fiches.go (about) 1 package common 2 3 import ( 4 "strings" 5 6 dm "github.com/benoitkugler/goACVE/server/core/datamodel" 7 8 "errors" 9 10 "github.com/benoitkugler/goACVE/client/GUI/basic" 11 "github.com/benoitkugler/goACVE/client/GUI/fields" 12 rd "github.com/benoitkugler/goACVE/server/core/rawdata" 13 "github.com/therecipe/qt/widgets" 14 ) 15 16 type Fiche interface { 17 widgets.QFrame_ITF 18 Reset() 19 SetLayout() 20 Valid() error 21 } 22 23 type Details struct { 24 *widgets.QDialog 25 26 fiche Fiche 27 } 28 29 func NewDetails(fiche Fiche, editable bool) *widgets.QDialog { 30 d := basic.Dialog2("Détails") 31 lay := widgets.NewQVBoxLayout2(d) 32 33 buttons := widgets.NewQHBoxLayout() 34 reset := widgets.NewQPushButton3(basic.Icons.Reset, "Ré-initialiser", nil) 35 valid := basic.ButtonEnregistrer() 36 valid.SetObjectName(basic.ONAction) 37 38 reset.ConnectClicked(func(checked bool) { 39 fiche.Reset() 40 }) 41 valid.ConnectClicked(func(checked bool) { 42 if err := fiche.Valid(); err != nil { 43 if err.Error() != "" { 44 basic.ShowError(err) 45 } 46 return 47 } 48 d.Accept() 49 }) 50 51 buttons.AddWidget(reset, 1, 0) 52 buttons.AddStretch(2) 53 buttons.AddWidget(valid, 1, 0) 54 55 fiche.SetLayout() 56 lay.AddWidget(fiche, 2, 0) 57 if editable { 58 lay.AddLayout(buttons, 0) 59 } 60 return d 61 } 62 63 type WidgetsBasePersonne struct { 64 nom fields.String 65 nomJeuneFille fields.String 66 prenom fields.String 67 dateNaissance fields.Date 68 villeNaissance fields.String 69 departementNaissance fields.Departement 70 sexe fields.Sexe 71 72 Coordonnees 73 74 securiteSociale fields.String 75 profession fields.String 76 etudiant fields.Bool 77 fonctionnaire fields.Bool 78 } 79 80 type FichePersonne struct { 81 *widgets.QFrame 82 WidgetsBasePersonne 83 84 initialPersonne rd.Personne 85 86 quotientFamilial fields.Int 87 88 rangMembreAsso fields.RangMembreAsso 89 cotisation fields.Cotisation 90 echoRocher fields.Bool 91 eonews fields.Bool 92 pubEte fields.Bool 93 pubHiver fields.Bool 94 versionPapier fields.Bool 95 } 96 97 func (f FichePersonne) Valid() error { 98 msg := "" 99 if f.nom.GetData() == "" { 100 msg = "Veuillez choisir un <b>nom</b> !" 101 } 102 if f.prenom.GetData() == "" { 103 msg = "Veuillez choisir un <b>prénom</b>" 104 } 105 if msg == "" { 106 return nil 107 } 108 return errors.New(msg) 109 } 110 111 type FicheOrganisme struct { 112 *widgets.QFrame 113 114 initialOrganisme rd.Organisme 115 116 nom fields.String 117 contactPropre fields.Bool 118 contact Coordonnees 119 idContact *fields.BoutonId 120 idContactDon *fields.BoutonId 121 exemplaires fields.Exemplaires 122 } 123 124 func (f FicheOrganisme) Valid() error { 125 if f.nom.GetData() == "" { 126 return errors.New("Merci d'indiquer un <b>nom</b>.") 127 } 128 if !bool(f.contactPropre.GetData()) && f.idContact.GetData() == nil { 129 return errors.New("Merci de choisir un contact <b>ou</b> des coordonnées propres.") 130 } 131 if bool(f.contactPropre.GetData()) && f.idContact.GetData() != nil { 132 return errors.New("Merci de ne pas cumuler un contact et des coordonnées propres.") 133 } 134 // il n'y a pas interêt à dupliquer l'info 135 if ic := f.idContact.GetData(); ic != nil && ic == f.idContactDon.GetData() { 136 return errors.New("Il est inutile de déclarer le même contact pour les dons.") 137 } 138 return nil 139 } 140 141 type FicheAide struct { 142 *widgets.QFrame 143 initialAide rd.Aide 144 initialIdParticipant, initialIdStructureaide rd.OptionnalId 145 146 valeur fields.Euros 147 parJour fields.Bool 148 nbJoursMax fields.Int 149 valide fields.Bool 150 151 idParticipant *fields.BoutonId 152 idStructureaide *fields.BoutonId 153 } 154 155 func (f FicheAide) Valid() error { 156 msg := "" 157 if f.idStructureaide.GetData() == nil { 158 msg = "Veuillez choisir une <b>structure d'aide</b> !<br/>" 159 } 160 if f.idParticipant.GetData() == nil { 161 msg += "Veuillez choisir un <b>participant</b> !<br/>" 162 } 163 if f.valeur.GetData() <= 0 { 164 msg += "Veuillez attribuer un <b>montant</b> !" 165 } 166 if msg == "" { 167 return nil 168 } 169 return errors.New(msg) 170 } 171 172 type FicheStructureaide struct { 173 *widgets.QFrame 174 175 initialStructureaide rd.Structureaide 176 177 nom fields.String 178 immatriculation fields.String 179 adresse fields.String 180 codePostal fields.String 181 ville fields.String 182 telephone fields.String 183 info fields.MultiLineString 184 } 185 186 func (f FicheStructureaide) Valid() error { 187 msg := "" 188 if f.nom.GetData() == "" { 189 msg = "Veuillez choisir un <b>nom</b> !" 190 } 191 if msg == "" { 192 return nil 193 } 194 return errors.New(msg) 195 } 196 197 type FicheParticipant struct { 198 *widgets.QFrame 199 200 base *dm.BaseLocale 201 202 initialParticipant rd.Participant 203 initialIdPersonne rd.OptionnalId 204 205 idPersonne *fields.BoutonId 206 idCamp *fields.BoutonId // read-only 207 208 statutAttente fields.StatutAttente 209 raisonAttente fields.MultiLineString 210 optionsParticipant fields.OptionsParticipant 211 optionsPrix *fields.OptionsFinanceParticipant 212 } 213 214 func (f FicheParticipant) Valid() error { 215 msg := "" 216 if f.idPersonne.GetData() == nil { 217 msg = "Veuillez choisir une <b>personne</b> !<br/>" 218 } 219 if f.idCamp.GetData() == nil { 220 msg += "Veuillez choisir un <b>camp</b> !" 221 } 222 if msg == "" { 223 return nil 224 } 225 return errors.New(msg) 226 } 227 228 type ficheParticipantsimple struct { 229 *widgets.QFrame 230 231 initialIdPersonne rd.OptionnalId 232 initialIdCamp rd.OptionnalId 233 234 idPersonne *fields.BoutonId 235 idCamp *fields.BoutonId 236 } 237 238 func (f ficheParticipantsimple) Valid() error { 239 msg := "" 240 if f.idPersonne.GetData() == nil { 241 msg = "Veuillez choisir une <b>personne</b> !<br/>" 242 } 243 if f.idCamp.GetData() == nil { 244 msg += "Veuillez choisir un <b>camp</b> !" 245 } 246 if msg == "" { 247 return nil 248 } 249 return errors.New(msg) 250 } 251 252 type FicheParticipantsimple struct { 253 ficheParticipantsimple 254 255 initialParticipantsimple rd.Participantsimple 256 257 info fields.MultiLineString 258 } 259 260 type FicheEquipier struct { 261 ficheParticipantsimple 262 263 initialEquipier rd.Equipier 264 265 roles *fields.Roles 266 diplome fields.Diplome 267 approfondissement fields.Approfondissement 268 } 269 270 func (f FicheEquipier) Valid() error { 271 if err := f.ficheParticipantsimple.Valid(); err != nil { 272 return err 273 } 274 if len(f.roles.GetData()) == 0 { 275 return errors.New("Merci d'attribuer au moins un <b>rôle</b>.") 276 } 277 return nil 278 } 279 280 type FicheCamp struct { 281 *widgets.QFrame 282 minimalEdit bool 283 284 initialCamp rd.Camp 285 286 lieu fields.String 287 nom fields.String 288 prix fields.Euros 289 nbPlaces fields.Int 290 password fields.String 291 ouvert fields.Bool 292 nbPlacesReservees fields.Int 293 numeroJs fields.String 294 inscriptionSimple fields.Bool 295 needEquilibreGf fields.Bool 296 ageMin fields.Int 297 ageMax fields.Int 298 options fields.OptionsCamp 299 dateDebut fields.Date 300 dateFin fields.Date 301 schemaPaiement fields.SchemaPaiement 302 lienCompta fields.MultiLineString 303 optionPrix *fields.OptionsPrixCamp 304 infos fields.MultiLineString 305 306 envois *widgets.QLabel 307 } 308 309 func (f FicheCamp) Valid() error { 310 var msg string 311 if f.nom.GetData() == "" { 312 msg += "Veuillez choisir un <b>nom</b> !<br/>" 313 } 314 if f.dateDebut.GetData().Time().IsZero() || f.dateFin.GetData().Time().IsZero() || f.dateDebut.GetData().Time().After(f.dateFin.GetData().Time()) { 315 msg = "Veuillez choisir une <b>plage de date</b> valide !<br/>" 316 } 317 if f.prix.GetData() == 0 { 318 msg += "Veuillez définir un <b>prix</b> !" 319 } 320 if msg == "" { 321 return nil 322 } 323 return errors.New(msg) 324 } 325 326 // SetMinimalEdit désactive l'édition des champs 327 328 func (f FicheCamp) setMinimalEdit() { 329 f.nom.SetReadOnly(true) 330 f.lieu.SetReadOnly(true) 331 f.dateDebut.SetEditable(false) 332 f.dateFin.SetEditable(false) 333 f.ouvert.SetEnabled(false) 334 f.prix.SetReadOnly(true) 335 f.options.SetEditable(false) 336 f.schemaPaiement.SetEnabled(false) 337 f.optionPrix.SetEditable(false) 338 f.infos.SetEnabled(false) 339 f.inscriptionSimple.SetEnabled(false) 340 } 341 342 // FicheFacture est destinée à faire partie du panel 343 // facture + participants + aides 344 type FicheFacture struct { 345 *widgets.QFrame 346 347 initialFacture rd.Facture 348 initialIdResponsable rd.OptionnalId 349 350 destinataires *fields.Destinataires 351 copiesMails fields.Mails 352 353 idPersonne *fields.BoutonId 354 } 355 356 func (f FicheFacture) Valid() error { 357 if idRespo := f.idPersonne.GetData(); idRespo == nil { 358 return errors.New("Veuillez attribuer un <b>responsable</b> au dossier !") 359 } 360 return nil 361 } 362 363 type FichePaiement struct { 364 *widgets.QFrame 365 base *dm.BaseLocale 366 367 initialPaiement rd.Paiement 368 initialIdFacture rd.OptionnalId 369 370 labelPayeur fields.String 371 modePaiement fields.ModePaiment 372 numero fields.String 373 nomBanque fields.String 374 valeur fields.Euros 375 dateReglement *widgets.QLabel 376 details fields.String 377 isAcompte fields.Bool 378 isRemboursement fields.Bool 379 isInvalide fields.Bool 380 381 idFacture *fields.BoutonId 382 } 383 384 func (f FichePaiement) Valid() error { 385 msg := "" 386 idFac := f.idFacture.GetData() 387 if idFac == nil { 388 msg = "Veuillez attribuer ce paiement à un <b>dossier</b> !<br/>" 389 } 390 if f.labelPayeur.GetData() == "" { 391 msg += "Veuillez déclarer un <b>payeur</b> ! <br/>" 392 } 393 if f.valeur.GetData() <= 0 { 394 msg += "Veuillez remplir le <b>montant</b> du paiement !" 395 } 396 if msg != "" { 397 return errors.New(msg) 398 } 399 400 // entre autre, le dossier est bien rempli 401 fac := f.base.NewFacture(idFac.Int64()) 402 bilan := fac.EtatFinancier(dm.CacheEtatFinancier{}, false) 403 var info string 404 // on s'intéresse à la différence entre le paiment initial et la nouvelle 405 // valeur 406 // dans le cas d'un nouveau paiement, la valeur initial est nulle 407 newTotal := bilan.Recu + f.valeur.GetData() - f.initialPaiement.Valeur 408 if !newTotal.IsLess(bilan.Demande) { 409 info = "Attention, le règlement <i>dépasse</i> maintenant le montant demandé." 410 } else if !newTotal.IsEqual(bilan.Demande) { 411 info = "Attention, le montant du règlement est toujours <b>insuffisant</b> !" 412 } else { 413 return nil // tout est OK 414 } 415 if basic.Confirmation(info, "Ok", basic.ONAdd) { 416 return nil 417 } 418 // annule la validation mais n'affiche pas d'erreur 419 return errors.New("") 420 } 421 422 type ficheDocument struct { 423 *widgets.QFrame 424 425 base *dm.BaseLocale // pour le propriétaire 426 initialDocument rd.Document 427 428 initialIdTarget rd.OptionnalId 429 idTarget *fields.BoutonId 430 431 description fields.String 432 nomClient fields.String 433 434 //lecture seule 435 taille *widgets.QLabel 436 dateHeureModif *widgets.QLabel 437 } 438 439 func (f ficheDocument) Valid() error { 440 msg := "" 441 if strings.TrimSpace(string(f.nomClient.GetData())) == "" { 442 msg = "Veuillez <b>nommer</b> le document !</b><br/>" 443 } 444 if f.idTarget.GetData() == nil { 445 msg += "Veuillez <b>attribuer</b> le document à un propriétaire !" 446 } 447 if msg == "" { 448 return nil 449 } 450 return errors.New(msg) 451 } 452 453 type FicheDocumentPersonne struct { 454 ficheDocument 455 456 categorie fields.CategorieDocument 457 initialCategorie rd.BuiltinContrainte 458 } 459 460 func (f FicheDocumentPersonne) Valid() error { 461 if err := f.ficheDocument.Valid(); err != nil { 462 return err 463 } 464 if f.categorie.GetData() == "" { 465 return errors.New("Veuillez <b>attribuer</b> une catégorie au document !</b><br/>") 466 } 467 return nil 468 } 469 470 type FicheDocumentAide struct { 471 ficheDocument 472 } 473 474 type FicheDon struct { 475 *widgets.QFrame 476 477 initialDon rd.Don 478 initialDonateur rd.DonDonateur 479 480 valeur fields.Euros 481 modePaiement fields.ModePaiment 482 dateReception fields.Date 483 remercie fields.Bool 484 details fields.String 485 affectation fields.String 486 487 idDonateur *fields.BoutonId 488 } 489 490 func (f FicheDon) Valid() error { 491 if f.valeur.GetData() <= 0 { 492 return errors.New("Veuillez fournir un <b>montant</b> !") 493 } 494 return nil 495 }