pub struct ChargeDistribution {
pub id: Uuid,
pub expense_id: Uuid,
pub unit_id: Uuid,
pub owner_id: Uuid,
pub quota_percentage: Decimal,
pub amount_due: Decimal,
pub distribution_criteria: DistributionCriteria,
pub created_at: DateTime<Utc>,
}Expand description
Représente la répartition d’une charge/facture par lot et propriétaire Calculée automatiquement lors de l’approbation d’une facture Basée sur les quotes-parts (ownership percentages) des copropriétaires
Fields§
§id: Uuid§expense_id: Uuid§unit_id: Uuid§owner_id: Uuid§quota_percentage: Decimal§amount_due: Decimal§distribution_criteria: DistributionCriteriaStory H12 — critère légal sous lequel cette ligne a été calculée
(valeur / utilité / mixte, Art. 3.84/3.86). Défaut : Value.
created_at: DateTime<Utc>Implementations§
Source§impl ChargeDistribution
impl ChargeDistribution
pub fn new( expense_id: Uuid, unit_id: Uuid, owner_id: Uuid, quota_percentage: Decimal, total_amount: Decimal, ) -> Result<Self, ChargeDistributionError>
Sourcepub fn new_with_criteria(
expense_id: Uuid,
unit_id: Uuid,
owner_id: Uuid,
quota_percentage: Decimal,
total_amount: Decimal,
distribution_criteria: DistributionCriteria,
) -> Result<Self, ChargeDistributionError>
pub fn new_with_criteria( expense_id: Uuid, unit_id: Uuid, owner_id: Uuid, quota_percentage: Decimal, total_amount: Decimal, distribution_criteria: DistributionCriteria, ) -> Result<Self, ChargeDistributionError>
Story H12 — constructeur avec critère de répartition explicite.
Sourcepub fn resolve_owner_quota(
unit_quota: Decimal,
total_tantiemes: Decimal,
ownership_percentage: Decimal,
) -> Result<Decimal, ChargeDistributionError>
pub fn resolve_owner_quota( unit_quota: Decimal, total_tantiemes: Decimal, ownership_percentage: Decimal, ) -> Result<Decimal, ChargeDistributionError>
Story H12 — quote-part effective d’un copropriétaire pour une charge.
Clarifie les DEUX niveaux de répartition (DoD H12) :
unit_quota / total_tantiemes= part du lot dans les communs (valeur respective, acte de base — Art. 3.84) ;× ownership_percentage= part du copropriétaire dans le lot (indivision / démembrement —unit_owners).
Retourne la fraction [0, 1] à appliquer au montant total de la charge.
Sourcepub fn recalculate(
&mut self,
total_amount: Decimal,
) -> Result<(), ChargeDistributionError>
pub fn recalculate( &mut self, total_amount: Decimal, ) -> Result<(), ChargeDistributionError>
Recalcule le montant dû si la quote-part ou le total change
Sourcepub fn calculate_distributions(
expense_id: Uuid,
total_amount: Decimal,
unit_ownerships: Vec<(Uuid, Uuid, Decimal)>,
) -> Result<Vec<ChargeDistribution>, ChargeDistributionError>
pub fn calculate_distributions( expense_id: Uuid, total_amount: Decimal, unit_ownerships: Vec<(Uuid, Uuid, Decimal)>, ) -> Result<Vec<ChargeDistribution>, ChargeDistributionError>
Calcule la distribution pour une facture donnée et une liste de quotes-parts Retourne une distribution pour chaque (unit, owner, quota)
Sourcepub fn calculate_distributions_with_criteria(
expense_id: Uuid,
total_amount: Decimal,
unit_ownerships: Vec<(Uuid, Uuid, Decimal)>,
criteria: DistributionCriteria,
) -> Result<Vec<ChargeDistribution>, ChargeDistributionError>
pub fn calculate_distributions_with_criteria( expense_id: Uuid, total_amount: Decimal, unit_ownerships: Vec<(Uuid, Uuid, Decimal)>, criteria: DistributionCriteria, ) -> Result<Vec<ChargeDistribution>, ChargeDistributionError>
Story H12 — répartition avec critère explicite (valeur / utilité / mixte).
Sous Value, les quotités proviennent de l’acte de base ; sous Utility,
elles proviennent d’une base d’utilité (coefficients alternatifs). Le
critère est enregistré sur chaque ligne pour la traçabilité.
Sourcepub fn total_distributed(distributions: &[ChargeDistribution]) -> Decimal
pub fn total_distributed(distributions: &[ChargeDistribution]) -> Decimal
Calcule le montant total distribué (somme des amount_due)
Sourcepub fn verify_distribution(
distributions: &[ChargeDistribution],
expected_total: Decimal,
) -> bool
pub fn verify_distribution( distributions: &[ChargeDistribution], expected_total: Decimal, ) -> bool
Vérifie que la distribution est complète (somme = total_amount à 0.01€ près)
Trait Implementations§
Source§impl Clone for ChargeDistribution
impl Clone for ChargeDistribution
Source§fn clone(&self) -> ChargeDistribution
fn clone(&self) -> ChargeDistribution
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChargeDistribution
impl Debug for ChargeDistribution
Source§impl<'de> Deserialize<'de> for ChargeDistribution
impl<'de> Deserialize<'de> for ChargeDistribution
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ChargeDistribution
impl PartialEq for ChargeDistribution
Source§fn eq(&self, other: &ChargeDistribution) -> bool
fn eq(&self, other: &ChargeDistribution) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ChargeDistribution
impl Serialize for ChargeDistribution
impl StructuralPartialEq for ChargeDistribution
Auto Trait Implementations§
impl Freeze for ChargeDistribution
impl RefUnwindSafe for ChargeDistribution
impl Send for ChargeDistribution
impl Sync for ChargeDistribution
impl Unpin for ChargeDistribution
impl UnsafeUnpin for ChargeDistribution
impl UnwindSafe for ChargeDistribution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more