按顺序结算多笔现金应收
This commit is contained in:
@@ -778,25 +778,23 @@ impl PortfolioState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn settle_cash_receivables(&mut self, date: NaiveDate) -> Vec<CashReceivable> {
|
||||
let mut settled = Vec::new();
|
||||
pub fn take_due_cash_receivables(&mut self, date: NaiveDate) -> Vec<CashReceivable> {
|
||||
let mut due = Vec::new();
|
||||
let mut pending = Vec::new();
|
||||
for receivable in self.cash_receivables.drain(..) {
|
||||
if receivable.payable_date <= date {
|
||||
let amount = Self::fixed_money(receivable.amount, "cash receivable")
|
||||
.expect("cash receivable must be finite fixed-point money");
|
||||
self.cash = self
|
||||
.cash
|
||||
.checked_add(amount)
|
||||
.expect("fixed-point cash overflow while settling receivable");
|
||||
settled.push(receivable);
|
||||
due.push(receivable);
|
||||
} else {
|
||||
pending.push(receivable);
|
||||
}
|
||||
}
|
||||
self.cash_receivables = pending;
|
||||
self.refresh_dividend_receivables();
|
||||
settled
|
||||
due
|
||||
}
|
||||
|
||||
pub fn settle_cash_receivable(&mut self, receivable: &CashReceivable) -> Result<(), String> {
|
||||
self.apply_cash_delta(receivable.amount)
|
||||
}
|
||||
|
||||
pub fn cash_receivables(&self) -> &[CashReceivable] {
|
||||
|
||||
Reference in New Issue
Block a user