public function expandUpdate() { $targetFutureCalcDate = getTargetFutureCalcDate(); if ($this->updateMode != self::UPDATE_MODE_ALL) { return; } if ($this->originalRepeatUnit == $this->repeatUnit && $this->originalRepeatFrequency == $this->repeatFrequency) { if (!is_null($this->originalEndDate)) { $originalEndDate = $this->originalEndDate; } else { $originalEndDate = new Date('9999-01-01'); } if (!is_null($this->endDate)) { $endDate = $this->endDate; } else { $endDate = new Date('9999-01-01'); } $this->updateExpandedDates($this->originalBeginDate, $originalEndDate); if ($this->originalBeginDate->before($this->beginDate)) { $end = new Date($this->beginDate); $end->subtractSeconds(24 * 60 * 60); $this->deletePlannedTransactions($this->originalBeginDate, $end, true); } else { if ($this->originalBeginDate->after($this->beginDate)) { $this->expand($this->beginDate, $this->originalBeginDate); } } if ($originalEndDate->before($endDate)) { if ($endDate->before($targetFutureCalcDate)) { $this->expand($originalEndDate, $endDate); } else { $this->expand($originalEndDate, $targetFutureCalcDate); } } else { if ($originalEndDate->after($endDate)) { $start = new Date($endDate); $start->addSeconds(24 * 60 * 60); $this->deletePlannedTransactions($start, $originalEndDate, true); } } } else { //repeat unit or frequency changed, discard all old entries and create from scratch $this->deletePlannedTransactions(new Date('1000-01-01'), new Date('9999-12-31'), true); $this->expand(new Date('1000-01-01'), $targetFutureCalcDate); } }
function updateRecord($accountID, $ID, $transactionType) { global $am; global $catm; global $us; $account = $am->getAccountById($accountID); if (isset($_POST['category']) && getGPC($_POST, 'category') != "NULL") { $category = $catm->getCategoryById(getGPC($_POST, 'category', 'integer')); } else { $category = NULL; } switch ($ID) { case 'new': //add new record switch ($transactionType) { case 'planned': $tmp = trim(getGPC($_POST, 'endDate')); $endDate = empty($tmp) ? null : new Date($tmp, true); if (getGPC($_POST, 'transferalEnabled', 'checkbox')) { $transferalAccount = $am->getAccountById(getGPC($_POST, 'transferalAccountId', 'integer')); $transferalAmount = getGPC($_POST, 'transferalAmount', 'AmountFormatted'); } else { $transferalAccount = null; $transferalAmount = null; } $newPlannedTransaction = $account->addPlannedTransaction(getGPC($_POST, 'title'), getGPC($_POST, 'amount', 'AmountFormatted'), getGPC($_POST, 'repeatUnit'), getGPC($_POST, 'repeatFrequency', 'integer'), getGPC($_POST, 'beginDate', 'DateFormatted'), $endDate, getGPC($_POST, 'description'), getGPC($_POST, 'transactionPartner'), $category, getGPC($_POST, 'outsideCapital', 'checkbox'), $transferalAccount, $transferalAmount); $newPlannedTransaction->expand(new Date('1000-01-01'), getTargetFutureCalcDate()); break; case 'finished': if (getGPC($_POST, 'transferalEnabled', 'checkbox')) { $transferalAccount = $am->getAccountById(getGPC($_POST, 'transferalAccountId', 'integer')); $transferalAmount = getGPC($_POST, 'transferalAmount', 'AmountFormatted'); } else { $transferalAccount = null; $transferalAmount = null; } $ID = $account->addFinishedTransaction(getGPC($_POST, 'amount', 'AmountFormatted'), getGPC($_POST, 'title'), getGPC($_POST, 'description'), getGPC($_POST, 'valutaDate', 'DateFormatted'), getGPC($_POST, 'transactionPartner'), $category, getGPC($_POST, 'outsideCapital', 'checkbox'), getGPC($_POST, 'exceptional', 'checkbox'), getGPC($_POST, 'periodical', 'checkbox'), null, $transferalAccount, $transferalAmount); break; } break; default: //update record settype($ID, 'integer'); switch ($transactionType) { case 'planned': $transaction = $account->getPlannedTransactionById($ID); $range = getGPC($_POST, 'range'); if ($range == 'previous') { $finishedTransaction = $account->getFinishedTransactionById(getGPC($_POST, 'hiddenFinishedTransactionID', 'integer')); $transaction->setUpdateMode(PlannedTransaction::UPDATE_MODE_PREVIOUS, $finishedTransaction->getValutaDate()); } else { if ($range == 'following') { $finishedTransaction = $account->getFinishedTransactionById(getGPC($_POST, 'hiddenFinishedTransactionID', 'integer')); $transaction->setUpdateMode(PlannedTransaction::UPDATE_MODE_FOLLOWING, $finishedTransaction->getValutaDate()); } } if ($range != 'this') { $transaction->setTitle(getGPC($_POST, 'title')); $transaction->setDescription(getGPC($_POST, 'description')); if ($range == 'all' && isset($_POST['beginDate'])) { $transaction->setBeginDate(getGPC($_POST, 'beginDate', 'DateFormatted')); } if ($range == 'all' && isset($_POST['endDate']) && ($tmp = getGPC($_POST, 'endDate'))) { $transaction->setEndDate(new Date($tmp, true)); } $transaction->setAmount(getGPC($_POST, 'amount', 'AmountFormatted')); $transaction->setOutsideCapital(getGPC($_POST, 'outsideCapital', 'checkbox')); $transaction->setTransactionPartner(getGPC($_POST, 'transactionPartner')); $transaction->setCategory($category); $transaction->setRepeatUnit(getGPC($_POST, 'repeatUnit')); $transaction->setRepeatFrequency(getGPC($_POST, 'repeatFrequency', 'integer')); if (getGPC($_POST, 'transferalEnabled', 'checkbox')) { $transferalAccount = $am->getAccountById(getGPC($_POST, 'transferalAccountId', 'integer')); $transaction->addTransferalTransaction($transferalAccount, getGPC($_POST, 'transferalAmount', 'AmountFormatted')); } if (!is_null($tmp = $transaction->getTransferalTransaction())) { $tmp->setAmount(getGPC($_POST, 'transferalAmount', 'AmountFormatted')); } $transaction->expandUpdate(); } else { $transaction = $account->getFinishedTransactionById(getGPC($_POST, 'hiddenFinishedTransactionID', 'integer')); $transaction->setTitle(getGPC($_POST, 'title')); $transaction->setDescription(getGPC($_POST, 'description')); $transaction->setAmount(getGPC($_POST, 'amount', 'AmountFormatted')); $transaction->setOutsideCapital(getGPC($_POST, 'outsideCapital', 'checkbox')); $transaction->setTransactionPartner(getGPC($_POST, 'transactionPartner')); $transaction->setCategory($category); $transaction->setPeriodical(false); $transaction->setPlannedTransaction(null); if (getGPC($_POST, 'transferalEnabled', 'checkbox')) { $transferalAccount = $am->getAccountById(getGPC($_POST, 'transferalAccountId', 'integer')); $transaction->addTransferalTransaction($transferalAccount, getGPC($_POST, 'transferalAmount', 'AmountFormatted')); } if (!is_null($tmp = $transaction->getTransferalTransaction())) { $tmp->setAmount(getGPC($_POST, 'transferalAmount', 'AmountFormatted')); } } break; case 'finished': $transaction = $account->getFinishedTransactionById($ID); $transaction->setTitle(getGPC($_POST, 'title')); $transaction->setDescription(getGPC($_POST, 'description')); $transaction->setValutaDate(getGPC($_POST, 'valutaDate', 'DateFormatted')); $transaction->setAmount(getGPC($_POST, 'amount', 'AmountFormatted')); $transaction->setOutsideCapital(getGPC($_POST, 'outsideCapital', 'checkbox')); $transaction->setTransactionPartner(getGPC($_POST, 'transactionPartner')); $transaction->setCategory($category); $transaction->setExceptional(getGPC($_POST, 'exceptional', 'checkbox')); //checkbox $transaction->setPeriodical(getGPC($_POST, 'periodical', 'checkbox')); //checkbox if (getGPC($_POST, 'transferalEnabled', 'checkbox')) { $transferalAccount = $am->getAccountById(getGPC($_POST, 'transferalAccountId', 'integer')); $transaction->addTransferalTransaction($transferalAccount, getGPC($_POST, 'transferalAmount', 'AmountFormatted')); } if (!is_null($tmp = $transaction->getTransferalTransaction())) { $tmp->setAmount(getGPC($_POST, 'transferalAmount', 'AmountFormatted')); } break; } } }
/** * 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, $csvParser = null, $deleteOldPlannedTransactions = null, $expandPlannedTransactions = true) { global $us; $this->badgerDb = $badgerDb; $this->targetFutureCalcDate = getTargetFutureCalcDate(); $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']); $this->lastCalcDate = new Date($data['last_calc_date']); $this->csvParser = $data['csv_parser']; $this->deleteOldPlannedTransactions = $data['delete_old_planned_transactions']; if ($data['currency_id']) { $currencyManager = new CurrencyManager($badgerDb); $this->currency = $currencyManager->getCurrencyById($data['currency_id']); } $expandPlannedTransactions = $title; } 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); $this->lastCalcDate = new Date('1000-01-01'); $this->csvParser = $csvParser; $this->deleteOldPlannedTransactions = $deleteOldPlannedTransactions; } } 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(); $this->lastCalcDate = $tmpAccount->getLastCalcDate(); $this->csvParser = $tmpAccount->getCsvParser(); $this->deleteOldPlannedTransactions = $tmpAccount->getDeleteOldPlannedTransactions(); } //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']; } if ($expandPlannedTransactions) { $this->expandPlannedTransactions(); } }