Example #1
0
$outflow2 = new Outflow(200, new DateTime('-2 days'), $expense, $payment2);
$money = new MoneyFlow();
$money->addRevenue($revenue)->addExpense($expense);
// -- scenario 1: get balance and monthly vat
// echo $money->getBalance(new DateTime('-1 day'));  // 610
// echo $money->calculateMonthlyVAT(new DateTime('now'));  // 110
// -- scenario 2: same as scenario 1, but expense was created 4 months ago
// $expense->setDate(new DateTime('-4 months'));
// echo $money->getBalance(new DateTime('-1 day'));  // 610
// echo $money->calculateMonthlyVAT(new DateTime('now'));  // 220
// -- scenario 3: same as scenario 1, but revenue was created 4 months ago and is set to repeat every month
// $revenue->setDate(new DateTime('-4 months'));
// $revenue->setRepeating();
// echo $money->getBalance(new DateTime('now'));  // 5490
$revenue = new Revenue(800, 'Website development', 'Website development description', $category);
$revenue->setDate(new DateTime('+4 days'), true);
$inflow1 = new Inflow(500, new DateTime('+2 days'), $revenue, $payment1);
$inflow1->setProbability(0.8);
$inflow2 = new Inflow(300, new DateTime('+6 days'), $revenue, $payment2);
$inflow2->setProbability(0.8);
$expense = new Expense(300, 'WP theme purchase', 'WP theme purchase description', $category);
$expense->setDate(new DateTime('+4 days'), true);
$outflow1 = new Outflow(100, new DateTime('+2 days'), $expense, $payment1);
$outflow1->setProbability(0.8);
$outflow2 = new Outflow(200, new DateTime('+6 days'), $expense, $payment2);
$outflow2->setProbability(0.8);
$money = new MoneyFlow();
$money->addRevenue($revenue)->addExpense($expense);
// -- scenario 4: predictions
// echo $money->getBalancePrediction(new DateTime('+5 days')); // 280 - only inflow1 and outflow2 gets counted
// echo $money->getBalancePrediction(new DateTime('+7 days')); // 350
Example #2
0
 public function it_returns_predicted_balance_for_future_day(Revenue $revenue, Expense $expense, Inflow $inflow, Outflow $outflow, Expense $expense1)
 {
     $date = new DateTime('+15 days');
     $inflow->getProbability()->shouldBeCalled()->willReturn(0.73);
     $inflow->getDate()->shouldBeCalled()->willReturn(new DateTime('+2 days'));
     $inflow->getValue()->shouldBeCalled()->willReturn(120.0);
     $revenue->getInflows()->shouldBeCalled()->willReturn([$inflow]);
     $outflow->getProbability()->shouldBeCalled()->willReturn(0.83);
     $outflow->getDate()->shouldBeCalled()->willReturn(new DateTime('+3 days'));
     $outflow->getValue()->shouldBeCalled()->willReturn(50.0);
     $expense->getOutflows()->shouldBeCalled()->willReturn([$outflow]);
     $revenue->addInflow($inflow);
     $expense->addOutflow($outflow);
     $this->addRevenue($revenue)->addExpense($expense);
     $this->getBalancePrediction($date)->shouldReturn(49.0);
 }