feat: implement global pricing model, optional equipment contribution, and bulk save for dotations
This commit is contained in:
@@ -27,6 +27,12 @@ public class Dotation {
|
||||
@Column(nullable = false)
|
||||
private Boolean fourni = false;
|
||||
|
||||
@Column(length = 10)
|
||||
private String numero;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Boolean choisi = false;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Long getId() { return id; }
|
||||
@@ -46,4 +52,10 @@ public class Dotation {
|
||||
|
||||
public Boolean getFourni() { return fourni; }
|
||||
public void setFourni(Boolean fourni) { this.fourni = fourni; }
|
||||
|
||||
public String getNumero() { return numero; }
|
||||
public void setNumero(String numero) { this.numero = numero; }
|
||||
|
||||
public Boolean getChoisi() { return choisi; }
|
||||
public void setChoisi(Boolean choisi) { this.choisi = choisi; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.astalange.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "educateur")
|
||||
public class Educateur {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, length = 100)
|
||||
private String nom;
|
||||
|
||||
@Column(nullable = false, length = 100)
|
||||
private String prenom;
|
||||
|
||||
@Column(length = 100)
|
||||
private String email;
|
||||
|
||||
@Column(length = 20)
|
||||
private String telephone;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "categorie_id")
|
||||
private Categorie categorie;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public String getNom() { return nom; }
|
||||
public void setNom(String nom) { this.nom = nom; }
|
||||
|
||||
public String getPrenom() { return prenom; }
|
||||
public void setPrenom(String prenom) { this.prenom = prenom; }
|
||||
|
||||
public String getEmail() { return email; }
|
||||
public void setEmail(String email) { this.email = email; }
|
||||
|
||||
public String getTelephone() { return telephone; }
|
||||
public void setTelephone(String telephone) { this.telephone = telephone; }
|
||||
|
||||
public Categorie getCategorie() { return categorie; }
|
||||
public void setCategorie(Categorie categorie) { this.categorie = categorie; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.astalange.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Entity
|
||||
@Table(name = "equipement")
|
||||
@@ -19,6 +20,9 @@ public class Equipement {
|
||||
@Column(nullable = false)
|
||||
private Boolean obligatoire = false;
|
||||
|
||||
@Column(name = "prix_contribution", nullable = false, precision = 10, scale = 2)
|
||||
private BigDecimal prixContribution = BigDecimal.ZERO;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Long getId() { return id; }
|
||||
@@ -32,4 +36,7 @@ public class Equipement {
|
||||
|
||||
public Boolean getObligatoire() { return obligatoire; }
|
||||
public void setObligatoire(Boolean obligatoire) { this.obligatoire = obligatoire; }
|
||||
|
||||
public BigDecimal getPrixContribution() { return prixContribution; }
|
||||
public void setPrixContribution(BigDecimal prixContribution) { this.prixContribution = prixContribution; }
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ public class Licence {
|
||||
@OneToMany(mappedBy = "licence", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Dotation> dotations = new ArrayList<>();
|
||||
|
||||
// Logic for Reste A Payer
|
||||
// Logic for Global Total Price
|
||||
@Transient
|
||||
public BigDecimal getResteAPayer() {
|
||||
public BigDecimal getPrixTotal() {
|
||||
if (categorie == null) return BigDecimal.ZERO;
|
||||
|
||||
BigDecimal prixTotal = (adherent != null && adherent.isResidentTalange())
|
||||
@@ -47,6 +47,25 @@ public class Licence {
|
||||
|
||||
if (prixTotal == null) prixTotal = BigDecimal.ZERO;
|
||||
|
||||
if (dotations != null) {
|
||||
for (Dotation dot : dotations) {
|
||||
if (dot.getChoisi() && dot.getEquipement() != null) {
|
||||
BigDecimal price = dot.getEquipement().getPrixContribution();
|
||||
if (price != null) {
|
||||
prixTotal = prixTotal.add(price);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prixTotal;
|
||||
}
|
||||
|
||||
// Logic for Reste A Payer
|
||||
@Transient
|
||||
public BigDecimal getResteAPayer() {
|
||||
BigDecimal prixTotal = getPrixTotal();
|
||||
|
||||
if (paiements == null || paiements.isEmpty()) {
|
||||
return prixTotal;
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
ALTER TABLE dotation ADD COLUMN IF NOT EXISTS numero VARCHAR(10);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS educateur (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
nom VARCHAR(100) NOT NULL,
|
||||
prenom VARCHAR(100) NOT NULL,
|
||||
email VARCHAR(100),
|
||||
telephone VARCHAR(20),
|
||||
categorie_id BIGINT,
|
||||
CONSTRAINT fk_educateur_categorie FOREIGN KEY (categorie_id) REFERENCES categorie(id) ON DELETE SET NULL
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
-- Ajouter la colonne prix_contribution à la table equipement (avec valeur par défaut 0)
|
||||
ALTER TABLE equipement ADD COLUMN IF NOT EXISTS prix_contribution DECIMAL(10,2) NOT NULL DEFAULT 0.00;
|
||||
|
||||
-- Ajouter la colonne choisi à la table dotation (avec valeur par défaut false)
|
||||
ALTER TABLE dotation ADD COLUMN IF NOT EXISTS choisi BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
-- Mettre choisi à true pour tous les équipements obligatoires existants
|
||||
UPDATE dotation d
|
||||
SET choisi = TRUE
|
||||
FROM equipement e
|
||||
WHERE d.equipement_id = e.id AND e.obligatoire = TRUE;
|
||||
|
||||
-- Mettre à jour le prix de contribution du Survêtement à 30.00 € à titre d'exemple
|
||||
UPDATE equipement SET prix_contribution = 30.00 WHERE nom = 'Survêtement';
|
||||
Reference in New Issue
Block a user