function getSpendingMoney($accountId, $startDate)
{
    global $badgerDb;
    $accountManager = new AccountManager($badgerDb);
    $account = $accountManager->getAccountById($accountId);
    $account->setType('finished');
    $account->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc')));
    $account->setFilter(array(array('key' => 'valutaDate', 'op' => 'ge', 'val' => $startDate), array('key' => 'periodical', 'op' => 'eq', 'val' => false), array('key' => 'exceptional', 'op' => 'eq', 'val' => false)));
    $sum = new Amount();
    $realStartDate = false;
    while ($currentTransaction = $account->getNextFinishedTransaction()) {
        if (!$realStartDate) {
            $realStartDate = $currentTransaction->getValutaDate();
        }
        $sum->add($currentTransaction->getAmount());
    }
    $span = new Date_Span($realStartDate, new Date());
    $count = $span->toDays();
    if ($count > 0) {
        $sum->div($count);
    }
    return $sum;
}
require_once BADGER_ROOT . '/modules/csvImport/csvImportCommon.php';
$redirectPageAfterSave = "AccountManagerOverview.php";
$am = new AccountManager($badgerDb);
$curMan = new CurrencyManager($badgerDb);
if (isset($_GET['action'])) {
    switch (getGPC($_GET, 'action')) {
        case 'delete':
            //background delete
            //called by dataGrid
            if (isset($_GET['ID'])) {
                $IDs = getGPC($_GET, 'ID', 'integerList');
                //check if we can delete this item
                foreach ($IDs as $ID) {
                    $am = new AccountManager($badgerDb);
                    //workaround, because of twice calling 'getAccountById'
                    $acc = $am->getAccountById($ID);
                    //delete all transactions in this account
                    $acc->deleteAllTransactions();
                    //delete account
                    $am->deleteAccount($ID);
                    //delete entry in navigation
                    deleteFromNavi($us->getProperty("accountNaviId_{$ID}"));
                }
            } else {
                echo "no ID was transmitted!";
            }
            break;
        case 'save':
            //add record, update record
            if (isset($_POST['hiddenID'])) {
                updateRecord();
* Open Source Financial Management
* Visit http://www.badger-finance.org 
*
**/
define("BADGER_ROOT", "../..");
require_once BADGER_ROOT . "/includes/fileHeaderFrontEnd.inc.php";
require_once BADGER_ROOT . "/core/widgets/DataGrid.class.php";
require_once BADGER_ROOT . '/modules/account/AccountManager.class.php';
require_once BADGER_ROOT . '/modules/account/accountCommon.php';
if (isset($_GET['accountID'])) {
    $accountID = getGPC($_GET, 'accountID', 'integer');
} else {
    throw new badgerException('accountOverview', 'noAccountID', '');
}
$am = new AccountManager($badgerDb);
$account = $am->getAccountById($accountID);
$pageTitle = getBadgerTranslation2('accountOverview', 'pageTitle');
$pageTitle .= ": " . $account->getTitle();
$widgets = new WidgetEngine($tpl);
$widgets->addToolTipJS();
$widgets->addCalendarJS();
$widgets->addTwistieSectionJS();
$dataGrid = new DataGrid($tpl, "Account{$accountID}");
$dataGrid->sourceXML = BADGER_ROOT . "/core/XML/getDataGridXML.php?q=Account&qp={$accountID}";
$dataGrid->headerName = array(getBadgerTranslation2('accountOverview', 'colValutaDate'), getBadgerTranslation2('accountOverview', 'colTitle'), getBadgerTranslation2('accountOverview', 'colType'), getBadgerTranslation2('accountOverview', 'colAmount'), getBadgerTranslation2('accountOverview', 'colBalance'), getBadgerTranslation2('accountOverview', 'colCategoryTitle'));
$dataGrid->columnOrder = array("valutaDate", "title", "type", "amount", "balance", "concatCategoryTitle");
$dataGrid->height = "350px";
$dataGrid->headerSize = array(90, 350, 39, 80, 120, 200);
$dataGrid->cellAlign = array("left", "left", "center", "right", "right", "left");
$dataGrid->deleteRefreshType = "refreshDataGrid";
$dataGrid->deleteAction = "Transaction.php?action=delete&accountID={$accountID}&ID=";
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* Open Source Financial Management
* Visit http://www.badger-finance.org 
*
**/
define('BADGER_ROOT', '../..');
require_once BADGER_ROOT . '/includes/fileHeaderFrontEnd.inc.php';
require_once BADGER_ROOT . '/modules/account/AccountManager.class.php';
require_once BADGER_ROOT . '/modules/account/CurrencyManager.class.php';
header('Content-Type: text/plain');
define('endl', "\n");
$am = new AccountManager($badgerDb);
while ($acc = $am->getNextAccount()) {
    echo 'Account Title: ' . $acc->getTitle() . endl;
}
$acc1 = $am->getAccountById(1);
echo 'Account Id: ' . $acc1->getId() . endl;
$cm = new CurrencyManager($badgerDb);
$curr = $cm->getCurrencyById(1);
$lowerLimit = new Amount(rand(-100, 100));
$upperLimit = new Amount(rand(1000, 3000));
$acc2 = $am->addAccount('Neues Konto ' . rand(0, 100), $curr, 'Bähschraipunk', $lowerLimit, $upperLimit);
echo 'New Account Title: ' . $acc2->getTitle() . endl;
$acc3 = $am->addAccount('Temporäres Konto', $curr);
$tmpId = $acc3->getId();
echo 'Temporary Account Id: ' . $tmpId . endl;
$am->deleteAccount($tmpId);
$acc4 = $am->getAccountById($tmpId);
echo 'Temporary Account Title (never shown): ' . $acc4->getTitle() . endl;
Esempio n. 5
0
function importMatching($importedTransaction, $accountId)
{
    global $us;
    global $badgerDb;
    static $dateDelta = null;
    static $amountDelta = null;
    static $textSimilarity = null;
    static $categories = null;
    if (is_null($dateDelta)) {
        try {
            $dateDelta = $us->getProperty('matchingDateDelta');
        } catch (BadgerException $ex) {
            $dateDelta = 5;
        }
        try {
            $amountDelta = $us->getProperty('matchingAmountDelta');
        } catch (BadgerException $ex) {
            $amountDelta = 0.1;
        }
        try {
            $textSimilarity = $us->getProperty('matchingTextSimilarity');
        } catch (BadgerException $ex) {
            $textSimilarity = 0.25;
        }
        $categoryManager = new CategoryManager($badgerDb);
        while ($currentCategory = $categoryManager->getNextCategory()) {
            $categories[$currentCategory->getId()] = preg_split('/[\\n]+/', $currentCategory->getKeywords(), -1, PREG_SPLIT_NO_EMPTY);
        }
    }
    if (!$importedTransaction['valutaDate']) {
        return $importedTransaction;
    }
    $minDate = new Date($importedTransaction['valutaDate']);
    $minDate->subtractSeconds($dateDelta * 24 * 60 * 60);
    $maxDate = new Date($importedTransaction['valutaDate']);
    $maxDate->addSeconds($dateDelta * 24 * 60 * 60);
    if (!$importedTransaction['amount']) {
        return $importedTransaction;
    }
    $minAmount = new Amount($importedTransaction['amount']);
    $minAmount->mul(1 - $amountDelta);
    $maxAmount = new Amount($importedTransaction['amount']);
    $maxAmount->mul(1 + $amountDelta);
    $accountManager = new AccountManager($badgerDb);
    $account = $accountManager->getAccountById($accountId);
    $account->setFilter(array(array('key' => 'valutaDate', 'op' => 'ge', 'val' => $minDate), array('key' => 'valutaDate', 'op' => 'le', 'val' => $maxDate), array('key' => 'amount', 'op' => 'ge', 'val' => $minAmount), array('key' => 'amount', 'op' => 'le', 'val' => $maxAmount)));
    $similarTransactions = array();
    while ($currentTransaction = $account->getNextTransaction()) {
        $titleSimilarity = getSimilarity($importedTransaction['title'], $currentTransaction->getTitle(), $textSimilarity);
        $descriptionSimilarity = getSimilarity($importedTransaction['description'], $currentTransaction->getDescription(), $textSimilarity);
        $transactionPartnerSimilarity = getSimilarity($importedTransaction['transactionPartner'], $currentTransaction->getTransactionPartner(), $textSimilarity);
        $currDate = $currentTransaction->getValutaDate();
        $impDate = $importedTransaction['valutaDate'];
        $dateSimilarity = 1 - abs(Date_Calc::dateDiff($currDate->getDay(), $currDate->getMonth(), $currDate->getYear(), $impDate->getDay(), $impDate->getMonth(), $impDate->getYear())) / $dateDelta;
        $cmpAmount = new Amount($currentTransaction->getAmount());
        $impAmount = new Amount($importedTransaction['amount']);
        $cmpAmount->sub($impAmount);
        $cmpAmount->abs();
        $impAmount->mul($amountDelta);
        $impAmount->abs();
        $amountSimilarity = 1 - $cmpAmount->div($impAmount)->get();
        $currentTextSimilarity = ($titleSimilarity + $descriptionSimilarity + $transactionPartnerSimilarity) / 3;
        //		if ($currentTextSimilarity >= $textSimilarity) {
        $overallSimilarity = ($titleSimilarity + $descriptionSimilarity + $transactionPartnerSimilarity + $dateSimilarity + $amountSimilarity) / 5;
        //$similarTransactions["$overallSimilarity t:$titleSimilarity d:$descriptionSimilarity tp:$transactionPartnerSimilarity vd:$dateSimilarity a:$amountSimilarity"] = $currentTransaction;
        $similarTransactions[$overallSimilarity] = $currentTransaction;
        //		}
    }
    krsort($similarTransactions);
    if (count($similarTransactions)) {
        $importedTransaction['similarTransactions'] = $similarTransactions;
        return $importedTransaction;
    }
    if ($importedTransaction['categoryId']) {
        return $importedTransaction;
    }
    $transactionStrings = array($importedTransaction['title'], $importedTransaction['description'], $importedTransaction['transactionPartner']);
    foreach ($transactionStrings as $currentTransactionString) {
        foreach ($categories as $currentCategoryId => $keywords) {
            foreach ($keywords as $keyword) {
                if (stripos($currentTransactionString, trim($keyword)) !== false) {
                    $importedTransaction['categoryId'] = $currentCategoryId;
                    break 3;
                }
                //if keyword found
            }
            //foreach keywords
        }
        //foreach categories
    }
    //foreach transactionStrings
    return $importedTransaction;
}
Esempio n. 6
0
function gatherCategories($accountIds, $startDate, $endDate, $type, $summarize)
{
    global $badgerDb;
    $accountManager = new AccountManager($badgerDb);
    $categories = array('none' => array('title' => getBadgerTranslation2('statistics', 'noCategoryAssigned'), 'count' => 0, 'amount' => new Amount(0)));
    foreach ($accountIds as $currentAccountId) {
        $currentAccount = $accountManager->getAccountById($currentAccountId);
        //echo 'Account: ' . $currentAccount->getTitle() . '<br />';
        $currentAccount->setFilter(array(array('key' => 'valutaDate', 'op' => 'ge', 'val' => $startDate), array('key' => 'valutaDate', 'op' => 'le', 'val' => $endDate)));
        while ($currentTransaction = $currentAccount->getNextFinishedTransaction()) {
            if ($type == 'i') {
                if ($currentTransaction->getAmount()->compare(0) < 0) {
                    continue;
                }
            } else {
                if ($currentTransaction->getAmount()->compare(0) > 0) {
                    continue;
                }
            }
            if (!is_null($category = $currentTransaction->getCategory())) {
                if ($summarize && $category->getParent()) {
                    $category = $category->getParent();
                }
                if (isset($categories[$category->getId()])) {
                    $categories[$category->getId()]['count']++;
                    $categories[$category->getId()]['amount']->add($currentTransaction->getAmount());
                } else {
                    $categories[$category->getId()] = array('title' => $category->getTitle(), 'count' => 1, 'amount' => $currentTransaction->getAmount());
                }
            } else {
                $categories['none']['count']++;
                $categories['none']['amount']->add($currentTransaction->getAmount());
            }
        }
    }
    //uasort($categories, 'compareCategories');
    if ($categories['none']['count'] == 0) {
        unset($categories['none']);
    }
    return $categories;
}
     $showPocketMoney2 = 1;
 } else {
     $showPocketMoney2 = 0;
 }
 if (count($errors) != 0) {
     echo '<errors>';
     foreach ($errors as $error) {
         echo "<error>{$error}</error>";
     }
     echo '</errors>';
 }
 //create the chart
 $insertChart = InsertChart(BADGER_ROOT . "/includes/charts/charts.swf", BADGER_ROOT . "/includes/charts/charts_library", BADGER_ROOT . "/modules/forecast/forecastChart.php?endDate={$endDate}&account={$account}&savingTarget={$savingTarget}&pocketMoney1={$pocketMoney1}&pocketMoney2={$pocketMoney2}&showLowerLimit={$showLowerLimit}&showUpperLimit={$showUpperLimit}&showPlannedTransactions={$showPlannedTransactions}&showSavingTarget={$showSavingTarget}&showPocketMoney1={$showPocketMoney1}&showPocketMoney2={$showPocketMoney2}", 800, 400, "ECE9D8", true);
 $am = new AccountManager($badgerDb);
 $totals = array();
 $currentAccount = $am->getAccountById($account);
 $startDate = new Date();
 $currentBalances = getDailyAmount($currentAccount, $startDate, $selectedDate);
 $accountCurrency = $currentAccount->getCurrency()->getSymbol();
 foreach ($currentBalances as $balanceKey => $balanceVal) {
     if (isset($totals[$balanceKey])) {
         $totals[$balanceKey]->add($balanceVal);
     } else {
         $totals[$balanceKey] = $balanceVal;
     }
 }
 //calculate spending money, if saving target should be reached
 $countDay = count($totals) - 1;
 //get numbers of days between today & endDate
 $laststanding = new Amount($totals[$selectedDate->getDate()]);
 $endDateBalance = $laststanding;
Esempio n. 8
0
$accountManager = new AccountManager($badgerDb);
$type = getGPC($_GET, 'type');
if ($type !== 'o') {
    $type = 'i';
}
if (getGPC($_GET, 'summarize') !== 't') {
    $summarize = false;
} else {
    $summarize = true;
}
$amounts = array();
$amounts['none'] = new Amount(0);
$labels = array();
$labels['none'] = getBadgerTranslation2('statistics', 'noCategoryAssigned');
foreach ($accountIds as $currentAccountId) {
    $currentAccount = $accountManager->getAccountById($currentAccountId);
    $filter = getDataGridFilter($currentAccount);
    $currentAccount->setFilter($filter);
    while ($currentTransaction = $currentAccount->getNextTransaction()) {
        if ($type == 'i') {
            if ($currentTransaction->getAmount()->compare(0) < 0) {
                continue;
            }
        } else {
            if ($currentTransaction->getAmount()->compare(0) > 0) {
                continue;
            }
        }
        if (!is_null($category = $currentTransaction->getCategory())) {
            if ($summarize && $category->getParent()) {
                $category = $category->getParent();
*| |_) | /  \  | |  | | |  __| |__  | |__) |
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* Open Source Financial Management
* Visit http://www.badger-finance.org 
*
**/
define('BADGER_ROOT', '../..');
require_once BADGER_ROOT . '/includes/fileHeaderFrontEnd.inc.php';
require_once BADGER_ROOT . '/modules/account/AccountManager.class.php';
require_once BADGER_ROOT . '/modules/account/CategoryManager.class.php';
$am = new AccountManager($badgerDb);
header('Content-Type: text/plain');
define('endl', "\n");
$acc = $am->getAccountById(1);
echo 'Account Id: ' . $acc->getId() . endl;
echo 'Account Title: ' . $acc->getTitle() . endl;
try {
    echo 'Property notExistent: ' . $acc->getProperty('notExistent') . endl;
} catch (BadgerException $ex) {
    echo "Exception!" . endl;
}
// set test 2
$acc->setProperty('password', 'Hans');
echo 'Property password: '******'password') . endl;
$acc->setProperty('password', 'Paul');
echo 'Property password (2): ' . $acc->getProperty('password') . endl;
// set
$acc->setProperty('123', 'Haus');
echo 'Property 123: ' . $acc->getProperty('123') . endl;
 private function updateExpandedDates($start, $end, $updateTransferal = true)
 {
     if ($this->beginDate->equals($this->originalBeginDate)) {
         return;
     }
     $accountManager = new AccountManager($this->badgerDb);
     $compareAccount = $accountManager->getAccountById($this->account->getId());
     $compareAccount->setFilter(array(array('key' => 'plannedTransactionId', 'op' => 'eq', 'val' => $this->id), array('key' => 'valutaDate', 'op' => 'ge', 'val' => new Date($start)), array('key' => 'valutaDate', 'op' => 'le', 'val' => new Date($end))));
     $compareAccount->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc')));
     $date = new Date($this->beginDate);
     $originalDate = new Date($this->originalBeginDate);
     $windowStart = $this->previousOccurence(new Date($originalDate), $this->originalBeginDate);
     $windowEnd = $this->nextOccurence(new Date($originalDate), $this->originalBeginDate);
     while (!$date->after($windowStart)) {
         $date = $this->nextOccurence($date);
     }
     while ($currentCompareTransaction = $compareAccount->getNextTransaction()) {
         while ($originalDate->before($currentCompareTransaction->getValutaDate())) {
             $originalDate = $this->nextOccurence($originalDate, $this->originalBeginDate);
             $date = $this->nextOccurence($date);
         }
         if ($originalDate->equals($currentCompareTransaction->getValutaDate())) {
             $currentCompareTransaction->setValutaDate(new Date($date));
         }
     }
     //while compareTransactions
     if ($updateTransferal && $this->transferalTransaction) {
         $this->transferalTransaction->updateExpandedDates($start, $end, false);
     }
 }
Esempio n. 11
0
         #echo $transactionCategory;
         $tableRowArray = array("categoryId" => $transactionCategory, "account" => $_POST['account2Select' . $selectedTransactionNumber], "title" => $_POST['title' . $selectedTransactionNumber], "description" => $_POST['description' . $selectedTransactionNumber], "valutaDate" => $valutaDate1, "amount" => $amount1, "transactionPartner" => $_POST['transactionPartner' . $selectedTransactionNumber], "periodical" => $periodical, "exceptional" => $exceptional, "outside" => $outside);
     }
     //if a array with one transaction exist
     if ($tableRowArray) {
         //add the transaction to the multidimensional array
         $writeToDbArray[$selectedTransaction] = $tableRowArray;
         //increment number of selected transactions
         $selectedTransaction++;
     }
 }
 //write array to db
 if ($writeToDbArray) {
     for ($arrayRow = 0; $arrayRow < count($writeToDbArray); $arrayRow++) {
         $am3 = new AccountManager($badgerDb);
         $account3 = $am3->getAccountById($writeToDbArray[$arrayRow]['account']);
         $writeCategory = $writeToDbArray[$arrayRow]['categoryId'];
         $writeTitle = $writeToDbArray[$arrayRow]['title'];
         $writeDescription = $writeToDbArray[$arrayRow]['description'];
         $writeValutaDate = $writeToDbArray[$arrayRow]['valutaDate'];
         $writeAmount = $writeToDbArray[$arrayRow]['amount'];
         $writeTransactionPartner = $writeToDbArray[$arrayRow]['transactionPartner'];
         $writePeriodical = $writeToDbArray[$arrayRow]['periodical'];
         $writeExceptional = $writeToDbArray[$arrayRow]['exceptional'];
         $writeOutside = $writeToDbArray[$arrayRow]['outside'];
         $account3->addFinishedTransaction($writeAmount, $writeTitle, $writeDescription, $writeValutaDate, $writeTransactionPartner, $writeCategory, $writeOutside, $writeExceptional, $writePeriodical);
     }
     // echo success message & number of written transactions
     echo "<br/>" . count($writeToDbArray) . " " . getBadgerTranslation2("importCsv", "successfullyWritten");
 } else {
     //echo no transactions selected
 /**
  * Expands the planned transactions.
  * 
  * All occurences of planned transactions between now and the targetFutureCalcDate will be inserted
  * in finishedTransactions. For distinction the planned transactions will have a 'p' as first character
  * in their id.
  * 
  * @throws BadgerException If an illegal repeat unit is used.
  */
 public function expandPlannedTransactions($startDate = null)
 {
     if (!isset(self::$plannedTransactionsExpanded[$this->id]) || self::$plannedTransactionsExpanded[$this->id] === false) {
         self::$plannedTransactionsExpanded[$this->id] = true;
         $now = new Date();
         $now->setHour(0);
         $now->setMinute(0);
         $now->setSecond(0);
         if ($this->lastCalcDate->before($now) || !is_null($startDate)) {
             $accountManager = new AccountManager($this->badgerDb);
             $plannedAccount = $accountManager->getAccountById($this->id);
             while ($currentPlannedTransaction = $plannedAccount->getNextPlannedTransaction()) {
                 if (is_null($startDate)) {
                     $startDate = $this->lastCalcDate;
                 }
                 $currentPlannedTransaction->expand($startDate, $this->targetFutureCalcDate);
                 $currentPlannedTransaction->deletePlannedTransactions(new Date('1000-01-01'), $now);
             }
             $this->setLastCalcDate($now);
         }
         self::$plannedTransactionsExpanded[$this->id] = false;
     }
 }