function updateRecord($accountID, $ID, $transactionType) { global $redirectPage; global $am; global $catm; $account = $am->getAccountById($accountID); if (isset($_POST['category']) && $_POST['category'] != "NULL") { $category = $catm->getCategoryById($_POST['category']); } else { $category = NULL; } switch ($ID) { case 'new': //add new record switch ($transactionType) { case 'planned': $tmp = trim($_POST['endDate']); $endDate = empty($tmp) ? null : new Date($tmp, true); $newPlannedTransaction = $account->addPlannedTransaction($_POST['title'], new Amount($_POST['amount'], true), $_POST['repeatUnit'], $_POST['repeatFrequency'], new Date($_POST['beginDate'], true), $endDate, $_POST['description'], $_POST['transactionPartner'], $category, isset($_POST['outsideCapital']) && $_POST['outsideCapital'] == "on" ? true : false); // = null transferFinishedTransactions($account, $newPlannedTransaction); break; case 'finished': $ID = $account->addFinishedTransaction(new Amount($_POST['amount'], true), $_POST['title'], $_POST['description'], new Date($_POST['valutaDate'], true), $_POST['transactionPartner'], $category, isset($_POST['outsideCapital']) && $_POST['outsideCapital'] == "on" ? true : false, isset($_POST['exceptional']) && $_POST['exceptional'] == "on" ? true : false, isset($_POST['periodical']) && $_POST['periodical'] == "on" ? true : false); //= null break; } break; default: //update record switch ($transactionType) { case 'planned': $transaction = $account->getPlannedTransactionById($ID); $transaction->setTitle($_POST['title']); $transaction->setDescription($_POST['description']); $transaction->setBeginDate(new Date($_POST['beginDate'], true)); $transaction->setEndDate(new Date($_POST['endDate'], true)); $transaction->setAmount(new Amount($_POST['amount'], true)); $transaction->setOutsideCapital(isset($_POST['outsideCapital']) && $_POST['outsideCapital'] == "on" ? true : false); $transaction->setTransactionPartner($_POST['transactionPartner']); $transaction->setCategory($category); $transaction->setRepeatUnit($_POST['repeatUnit']); $transaction->setRepeatFrequency($_POST['repeatFrequency']); break; case 'finished': $transaction = $account->getFinishedTransactionById($ID); $transaction->setTitle($_POST['title']); $transaction->setDescription($_POST['description']); $transaction->setValutaDate(new Date($_POST['valutaDate'], true)); $transaction->setAmount(new Amount($_POST['amount'], true)); $transaction->setOutsideCapital(isset($_POST['outsideCapital']) && $_POST['outsideCapital'] == "on" ? true : false); $transaction->setTransactionPartner($_POST['transactionPartner']); $transaction->setCategory($category); $transaction->setExceptional(isset($_POST['exceptional']) && $_POST['exceptional'] == "on" ? true : false); //checkbox $transaction->setPeriodical(isset($_POST['periodical']) && $_POST['periodical'] == "on" ? true : false); //checkbox break; } } //REDIRECT header("Location: {$redirectPage}"); }
function transferFormerFinishedTransactions($account) { global $us; if ($us->getProperty('autoExpandPlannedTransactions') == false) { return; } $now = new Date(); $now->setHour(0); $now->setMinute(0); $now->setSecond(0); $account->setType('planned'); $account->setFilter(array(array('key' => 'beginDate', 'op' => 'le', 'val' => $now))); try { $lastInsertDate = $us->getProperty('Account_' . $account->getId() . '_LastTransferFormerFinishedTransactions'); } catch (BadgerException $ex) { $lastInsertDate = new Date('1000-01-01'); } $us->setProperty('Account_' . $account->getId() . '_LastTransferFormerFinishedTransactions', $now); if (!$lastInsertDate->before($now)) { return; } while ($currentTransaction = $account->getNextPlannedTransaction()) { transferFinishedTransactions($account, $currentTransaction, $lastInsertDate); } }