Ejemplo n.º 1
0
 /**
  * Get VAT from revenue/expense based on a date of interest and revenue/expense repeat status
  *
  * @param  Expense|Revenue $moneyType
  * @param  DateTime        $date
  * @return double
  */
 public function getVAT($moneyType, DateTime $date)
 {
     if ($moneyType->getVATCalculationMonth() != $date->format('n')) {
         return 0;
     }
     $moneyTypeDate = $moneyType->getDate() ?: $moneyType->getDate(true);
     if (!$moneyType->isRepeating() && $moneyTypeDate->format('Y') != $date->format('Y')) {
         return 0;
     }
     return $moneyType->getVAT();
 }
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 public function it_sets_expense_to_which_it_belong_and_adds_itself_to_that_expense_outflows(Expense $expense1)
 {
     $expense1->addOutflow($this)->shouldBeCalled();
     $this->setExpense($expense1);
     $this->getExpense()->shouldReturnAnInstanceOf('\\MoneyFlow\\Expense\\Expense');
 }
Ejemplo n.º 4
0
 /**
  * Sets outflow expense
  *
  * @return Outflow
  */
 public function setExpense($expense)
 {
     $this->expense = $expense;
     $this->expense->addOutflow($this);
     return $this;
 }
Ejemplo n.º 5
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);
 }