pub struct ChargeDistribution {
pub id: Uuid,
pub expense_id: Uuid,
pub unit_id: Uuid,
pub owner_id: Uuid,
pub quota_percentage: f64,
pub amount_due: f64,
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: f64§amount_due: f64§created_at: DateTime<Utc>Implementations§
Source§impl ChargeDistribution
impl ChargeDistribution
pub fn new( expense_id: Uuid, unit_id: Uuid, owner_id: Uuid, quota_percentage: f64, total_amount: f64, ) -> Result<Self, String>
Sourcepub fn recalculate(&mut self, total_amount: f64) -> Result<(), String>
pub fn recalculate(&mut self, total_amount: f64) -> Result<(), String>
Recalcule le montant dû si la quote-part ou le total change
Sourcepub fn calculate_distributions(
expense_id: Uuid,
total_amount: f64,
unit_ownerships: Vec<(Uuid, Uuid, f64)>,
) -> Result<Vec<ChargeDistribution>, String>
pub fn calculate_distributions( expense_id: Uuid, total_amount: f64, unit_ownerships: Vec<(Uuid, Uuid, f64)>, ) -> Result<Vec<ChargeDistribution>, String>
Calcule la distribution pour une facture donnée et une liste de quotes-parts Retourne une distribution pour chaque (unit, owner, quota)
Sourcepub fn total_distributed(distributions: &[ChargeDistribution]) -> f64
pub fn total_distributed(distributions: &[ChargeDistribution]) -> f64
Calcule le montant total distribué (somme des amount_due)
Sourcepub fn verify_distribution(
distributions: &[ChargeDistribution],
expected_total: f64,
) -> bool
pub fn verify_distribution( distributions: &[ChargeDistribution], expected_total: f64, ) -> 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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for ChargeDistribution
impl PartialEq for ChargeDistribution
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 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
Mutably borrows from an owned value. Read more
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.