/**
  * Get income for current month from begin to current datetime
  * @param $accountId
  *
  * @return int
  */
 public static function getIncomeForCurrentMonth($accountId)
 {
     $transactions = AccountsHistoryContainer::getTransactionsByInterval($accountId, DateFormatter::getCurrentMonthInterval());
     $money = 0;
     foreach ($transactions as $transaction) {
         $money += $transaction->money;
     }
     return $money;
 }
示例#2
0
 /**
  * Fill dates without transactions with values of previous dates or zero if there no previous data
  *
  * @param GraphBuilder $object
  *
  * @return array
  */
 private function fillDatesWithoutTransactions(GraphBuilder $object)
 {
     $diffMethod = $object->differenceInDatesMethod;
     $nextDateMethod = $object->nextDateMethod;
     $objectData = $object->data;
     $currentDate = Carbon::parse($object->interval['from']);
     $to = Carbon::parse($object->interval['to']);
     while ($currentDate->{$diffMethod}($to) != 0) {
         if (!array_key_exists($currentDate->format($object->dateFormat), $objectData)) {
             $objectData[$currentDate->format($object->dateFormat)] = empty($objectData[DateFormatter::getPreviousDate($currentDate, $nextDateMethod)->format($object->dateFormat)]) ? 0 : $objectData[DateFormatter::getPreviousDate($currentDate, $nextDateMethod)->format($object->dateFormat)];
         }
         $currentDate->{$nextDateMethod}(DateFormatter::NEXT_DATE);
     }
     ksort($objectData);
     $object->data = $objectData;
     return $object;
 }