/**
  * Creates an Account.
  * 
  * @param $badgerDb object The DB object.
  * @param $accountManager mixed The AccountManager object who created this Account OR the qp part out of getDataGridXML.php.
  * @param $data mixed An associative array with the values out of the DB OR the id of the Account.
  * @param $title string The title of the Account.
  * @param $description string The description of the Account.
  * @param $lowerLimit object An Amount object with the lower limit of the Account.
  * @param $upperLimit object An Amount object with the upper limit of the Account.
  * @param $currency object An Currency object with the currency of the Account.
  */
 function __construct(&$badgerDb, &$accountManager, $data = null, $title = null, $description = null, $lowerLimit = null, $upperLimit = null, $currency = null)
 {
     $this->badgerDb = $badgerDb;
     $this->targetFutureCalcDate = new Date();
     //Standard: One Year
     $this->targetFutureCalcDate->addSeconds(1 * 365 * 24 * 60 * 60);
     $this->type = 'transaction';
     if (!is_string($accountManager)) {
         //called with data array or all parameters
         $this->accountManager = $accountManager;
         if (is_array($data)) {
             //called with data array
             $this->id = $data['account_id'];
             $this->title = $data['title'];
             $this->description = $data['description'];
             $this->lowerLimit = new Amount($data['lower_limit']);
             $this->upperLimit = new Amount($data['upper_limit']);
             $this->balance = new Amount($data['balance']);
             if ($data['currency_id']) {
                 $currencyManager = new CurrencyManager($badgerDb);
                 $this->currency = $currencyManager->getCurrencyById($data['currency_id']);
             }
         } else {
             //called with all parameters
             $this->id = $data;
             $this->title = $title;
             $this->description = $description;
             $this->lowerLimit = $lowerLimit;
             $this->upperLimit = $upperLimit;
             $this->currency = $currency;
             $this->balance = new Amount(0);
         }
     } else {
         //called from getDataGridXML.php
         $this->accountManager = new AccountManager(&$badgerDb);
         //Filter out given parameters
         list($selectedId, $type, $targetDays) = explode(';', $accountManager . ';;');
         settype($selectedId, 'integer');
         if (in_array($type, array('transaction', 'finished', 'planned'), true)) {
             $this->type = $type;
         }
         settype($targetDays, 'integer');
         if ($targetDays) {
             $this->targetFutureCalcDate = new Date();
             $this->targetFutureCalcDate->addSeconds($targetDays * 24 * 60 * 60);
         }
         //copy account data
         $tmpAccount = $this->accountManager->getAccountById($selectedId);
         $this->id = $tmpAccount->getId();
         $this->title = $tmpAccount->getTitle();
         $this->description = $tmpAccount->getDescription();
         $this->lowerLimit = $tmpAccount->getLowerLimit();
         $this->upperLimit = $tmpAccount->getUpperLimit();
         $this->balance = $tmpAccount->getBalance();
         $this->currency = $tmpAccount->getCurrency();
     }
     //Get all properties
     $sql = "SELECT prop_key, prop_value\n\t\t\tFROM account_property\n\t\t\tWHERE account_id = " . $this->id;
     $res =& $badgerDb->query($sql);
     $this->properties = array();
     $row = array();
     while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
         $this->properties[$row['prop_key']] = $row['prop_value'];
     }
 }
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* 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;
/*
* ____          _____   _____ ______ _____  
*|  _ \   /\   |  __ \ / ____|  ____|  __ \ 
*| |_) | /  \  | |  | | |  __| |__  | |__) |
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* 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/CurrencyManager.class.php';
header('Content-Type: text/plain');
define('endl', "\n");
$cm = new CurrencyManager($badgerDb);
while ($curr = $cm->getNextCurrency()) {
    echo 'Currency Symbol: ' . $curr->getSymbol() . endl;
}
$curr1 = $cm->getCurrencyById(1);
echo 'Currency Id: ' . $curr1->getId() . endl;
$curr2 = $cm->addCurrency('SY' . rand(0, 9), 'Langer Titel');
echo 'New Currency Symbol: ' . $curr2->getSymbol() . endl;
$curr3 = $cm->addCurrency('tmp', 'temporär');
$tmpId = $curr3->getId();
echo 'Temporary Currency Id: ' . $tmpId . endl;
$cm->deleteCurrency($tmpId);
$curr4 = $cm->getCurrencyById($tmpId);
echo 'Temporary Currency Symbol (never shown): ' . $curr4->getSymbol() . endl;