function printFrontendPlanned($AccountID, $plannedTransactionId, $finishedTransactionId = null)
{
    global $pageTitle;
    global $tpl;
    global $am;
    global $redirectPage;
    $widgets = new WidgetEngine($tpl);
    $widgets->addToolTipJS();
    $widgets->addCalendarJS();
    $widgets->addJSValMessages();
    $tpl->addJavaScript("js/prototype.js");
    $tpl->addJavaScript('js/Transaction.js');
    $tpl->addOnLoadEvent("Form.focusFirstElement('mainform')");
    $now = new Date();
    $categoryExpenseJS = getCategoryExpense();
    $categoryExpenseWarning = getBadgerTranslation2('accountTransaction', 'categoryExpenseWarning');
    $transactionType = "planned";
    if ($plannedTransactionId != "new") {
        $acc = $am->getAccountById($AccountID);
        $transaction = $acc->getPlannedTransactionById($plannedTransactionId);
        $backToIdField = $widgets->createField('backToId', 0, $AccountID, '', false, 'hidden');
        if (is_null($transaction->getTransferalTransaction())) {
            $transferalAmountValue = new Amount($transaction->getAmount());
            $transferalAmountValue->mul(-1);
            $transferalAmountValue = $transferalAmountValue->getFormatted();
        } else {
            if ($transaction->getTransferalSource()) {
                $transferalAmountValue = $transaction->getTransferalTransaction()->getAmount()->getFormatted();
            } else {
                $transferalAmountValue = $transaction->getAmount()->getFormatted();
                $AccountID = $transaction->getTransferalTransaction()->getAccount()->getId();
                $plannedTransactionId = $transaction->getTransferalTransaction()->getId();
                $ID = $transaction->getTransferalTransaction()->getId();
                $transaction = $transaction->getTransferalTransaction();
            }
        }
        $titleValue = $transaction->getTitle();
        $descriptionValue = $transaction->getDescription();
        $beginDateValue = is_null($tmp = $transaction->getBeginDate()) ? '' : $tmp->getFormatted();
        $endDateValue = is_null($tmp = $transaction->getEndDate()) ? '' : $tmp->getFormatted();
        $amountValue = is_null($tmp = $transaction->getAmount()) ? '' : $tmp->getFormatted();
        $negativeAmountValue = new Amount($tmp);
        $negativeAmountValue->mul(-1);
        $negativeAmountValue = $negativeAmountValue->getFormatted();
        $outsideCapitalValue = is_null($tmp = $transaction->getOutsideCapital()) ? '' : $tmp;
        $transactionPartnerValue = $transaction->getTransactionPartner();
        $categoryValue = is_null($tmp = $transaction->getCategory()) ? '' : $tmp->getId();
        $repeatUnitValue = $transaction->getRepeatUnit();
        $repeatFrequencyValue = $transaction->getRepeatFrequency();
    } else {
        //new: empty values
        $titleValue = "";
        $descriptionValue = "";
        $beginDateValue = $now->getFormatted();
        $endDateValue = "";
        $amountValue = "";
        $negativeAmountValue = '';
        $outsideCapitalValue = "";
        $transactionPartnerValue = "";
        $categoryValue = "";
        $repeatUnitValue = "";
        $repeatFrequencyValue = "1";
        $transferalAmountValue = '';
        $backToIdField = '';
    }
    $tpl->addHeaderTag("<script type='text/javascript'>var previousAmount = '{$negativeAmountValue}';</script>");
    $widgets->addNavigationHead();
    echo $tpl->getHeader($pageTitle);
    echo $widgets->addToolTipLayer();
    if ($plannedTransactionId == 'new' || is_null($transaction->getTransferalTransaction())) {
        $transferalLabel = $widgets->createLabel('transferalEnabled', getBadgerTranslation2('accountTransaction', 'transferalEnabled'), false);
        $transferalField = $widgets->createField('transferalEnabled', 30, 'on', '', false, 'checkbox', "onclick='toggleTransferal();'");
        $transferalFieldStyle = 'display: none;';
        $transferalDataStyle = 'style="display: none;"';
        $transferalAccountField = $widgets->createSelectField('transferalAccountId', getAccountsSelectArray($AccountID), '', '', false, "style='width: 213px;'");
    } else {
        $transferalLabel = '';
        $transferalField = '';
        $transferalFieldStyle = '';
        $transferalDataStyle = '';
        $transferalAccountField = $transaction->getTransferalTransaction()->getAccount()->getTitle();
    }
    $transferalAccountLabel = $widgets->createLabel('transferalAccountId', getBadgerTranslation2('accountTransaction', 'transferalAccount'), false);
    $transferalAmountLabel = $widgets->createLabel('transferalAmount', getBadgerTranslation2('accountTransaction', 'transferalAmount'), false);
    $transferalAmountField = $widgets->createField('transferalAmount', 30, $transferalAmountValue, '', true, 'text', " onkeyup='adjustInputNumberClass(this);' onkeydown='adjustInputNumberClass(this);' onkeypress='adjustInputNumberClass(this);' style='width: 30ex;{$transferalFieldStyle}'");
    //set vars with values
    $FormAction = $_SERVER['PHP_SELF'];
    $backTo = $widgets->createField('backTo', 0, isset($_GET['backTo']) ? getGPC($_GET, 'backTo') : '', null, false, 'hidden');
    if ($AccountID == "choose") {
        $AccountLabel = $widgets->createLabel("hiddenAccID", getBadgerTranslation2('accountTransaction', 'Account'), true);
        $hiddenAccID = $widgets->createSelectField("hiddenAccID", getAccountsSelectArray(), $AccountID, "", false, "style='width: 31ex;'");
    } else {
        $AccountLabel = "";
        $hiddenAccID = $widgets->createField("hiddenAccID", 20, $AccountID, "", false, "hidden");
    }
    $hiddenID = $widgets->createField("hiddenID", 20, $plannedTransactionId, "", false, "hidden");
    $hiddenType = $widgets->createField("hiddenType", 20, $transactionType, "", false, "hidden");
    //Fields & Labels
    $titleLabel = $widgets->createLabel("title", getBadgerTranslation2('accountTransaction', 'title'), true);
    $titleField = $widgets->createField("title", 30, $titleValue, "", true, "text", "style='width: 30ex;'");
    $descriptionLabel = $widgets->createLabel("description", getBadgerTranslation2('accountTransaction', 'description'), false);
    $descriptionField = $widgets->createTextarea("description", $descriptionValue, "", false, "style='width: 30ex; height: 4em;'");
    $beginDateLabel = $widgets->createLabel("beginDate", getBadgerTranslation2('accountTransaction', 'beginDate'), true);
    $beginDateField = $widgets->addDateField("beginDate", $beginDateValue);
    $endDateLabel = $widgets->createLabel("endDate", getBadgerTranslation2('accountTransaction', 'endDate'), true);
    $endDateField = $widgets->addDateField("endDate", $endDateValue);
    $amountLabel = $widgets->createLabel("amount", getBadgerTranslation2('accountTransaction', 'amount'), true);
    $amountField = $widgets->createField("amount", 30, $amountValue, "", true, "text", "onchange='updateTransferalAmount();' onkeyup='adjustInputNumberClass(this);' onkeydown='adjustInputNumberClass(this);' onkeypress='adjustInputNumberClass(this);' style='width: 30ex;'");
    $transactionPartnerLabel = $widgets->createLabel("transactionPartner", getBadgerTranslation2('accountTransaction', 'transactionPartner'), false);
    $transactionPartnerField = $widgets->createField("transactionPartner", 30, $transactionPartnerValue, "", false, "text", "style='width: 30ex;'");
    $outsideCapitalLabel = $widgets->createLabel("outsideCapital", getBadgerTranslation2('accountTransaction', 'outsideCapital'), false);
    $outsideCapitalField = $widgets->createField("outsideCapital", 30, "on", "", false, "checkbox", $outsideCapitalValue);
    $outsideToolTip = $widgets->addToolTip(getBadgerTranslation2("importCsv", "outsideCapitalToolTip"));
    $categoryLabel = $widgets->createLabel("category", getBadgerTranslation2('accountTransaction', 'category'), false);
    $categoryField = $widgets->createSelectField("category", getCategorySelectArray(), $categoryValue, "", false, "style='width: 31ex;' onchange='updateExpenseWarning();'");
    $repeatUnitLabel = $widgets->createLabel("repeatUnit", getBadgerTranslation2('accountTransaction', 'repeatFrequency'), true);
    $repeatUnitField = $widgets->createSelectField("repeatUnit", getIntervalUnitsArray(), $repeatUnitValue, "", true, "style='width: 104px;'");
    $everyLabel = getBadgerTranslation2('intervalUnits', 'every');
    $repeatFrequencyField = $widgets->createField("repeatFrequency", 1, $repeatFrequencyValue, "", true, "text", "");
    if (!is_null($finishedTransactionId) && $finishedTransactionId != 'X') {
        $hiddenFinishedTransactionID = $widgets->createField('hiddenFinishedTransactionID', 20, $finishedTransactionId, '', false, 'hidden');
        $rangeLabel = getBadgerTranslation2('accountTransaction', 'range');
        $rangeUnit = getBadgerTranslation2('accountTransaction', 'rangeUnit');
        $rangeAllField = $widgets->createField('range', null, 'all', '', false, 'radio', 'checked="checked" onclick="checkBeginEndDate();"');
        $rangeAllLabel = $widgets->createLabel('range', getBadgerTranslation2('accountTransaction', 'rangeAll'));
        $rangeThisField = $widgets->createField('range', null, 'this', '', false, 'radio', 'onclick="checkBeginEndDate();"');
        $rangeThisLabel = $widgets->createLabel('range', getBadgerTranslation2('accountTransaction', 'rangeThis'));
        $rangePreviousField = $widgets->createField('range', null, 'previous', '', false, 'radio', 'onclick="checkBeginEndDate();"');
        $rangePreviousLabel = $widgets->createLabel('range', getBadgerTranslation2('accountTransaction', 'rangePrevious'));
        $rangeFollowingField = $widgets->createField('range', null, 'following', '', false, 'radio', 'onclick="checkBeginEndDate();"');
        $rangeFollowingLabel = $widgets->createLabel('range', getBadgerTranslation2('accountTransaction', 'rangeFollowing'));
        //$deleteBtn = $widgets->createButton('deleteBtn', getBadgerTranslation2('dataGrid', 'delete'), 'submit', 'Widgets/cancel.gif', "accesskey='d'");
        $deleteBtn = '';
    } else {
        $hiddenFinishedTransactionID = '';
        $rangeLabel = '';
        $rangeUnit = '';
        $rangeAllField = $widgets->createField('range', 20, 'all', '', false, 'hidden');
        $rangeAllLabel = '';
        $rangeThisField = '';
        $rangeThisLabel = '';
        $rangePreviousField = '';
        $rangePreviousLabel = '';
        $rangeFollowingField = '';
        $rangeFollowingLabel = '';
        $deleteBtn = '';
    }
    //Buttons
    $submitBtn = $widgets->createButton("submitBtn", getBadgerTranslation2('dataGrid', 'save'), "submit", "Widgets/accept.gif", "accesskey='s'");
    if ($redirectPage) {
        $backBtn = $widgets->createButton("backBtn", getBadgerTranslation2('dataGrid', 'back'), "location.href='{$redirectPage}';return false;", "Widgets/back.gif");
    } else {
        $backBtn = '';
    }
    //add vars to template, print site
    $pageHeading = getBadgerTranslation2('accountTransaction', 'headingTransactionPlanned');
    eval("echo \"" . $tpl->getTemplate("Account/PlannedTransaction") . "\";");
}
function printFrontendPlanned($AccountID, $ID)
{
    global $pageTitle;
    global $tpl;
    global $am;
    global $redirectPage;
    $widgets = new WidgetEngine($tpl);
    $widgets->addToolTipJS();
    $widgets->addCalendarJS();
    $widgets->addJSValMessages();
    $widgets->addNavigationHead();
    echo $tpl->getHeader($pageTitle);
    echo $widgets->addToolTipLayer();
    $transactionType = "planned";
    if ($ID != "new") {
        $acc = $am->getAccountById($AccountID);
        $transaction = $acc->getPlannedTransactionById($ID);
        $titleValue = $transaction->getTitle();
        $descriptionValue = $transaction->getDescription();
        $beginDateValue = is_null($tmp = $transaction->getBeginDate()) ? '' : $tmp->getFormatted();
        $endDateValue = is_null($tmp = $transaction->getEndDate()) ? '' : $tmp->getFormatted();
        $amountValue = is_null($tmp = $transaction->getAmount()) ? '' : $tmp->getFormatted();
        $outsideCapitalValue = is_null($tmp = $transaction->getOutsideCapital()) ? '' : $tmp;
        $transactionPartnerValue = $transaction->getTransactionPartner();
        $categoryValue = is_null($tmp = $transaction->getCategory()) ? '' : $tmp->getId();
        $repeatUnitValue = $transaction->getRepeatUnit();
        $repeatFrequencyValue = $transaction->getRepeatFrequency();
    } else {
        //new: empty values
        $titleValue = "";
        $descriptionValue = "";
        $beginDateValue = "";
        $endDateValue = "";
        $amountValue = "";
        $outsideCapitalValue = "";
        $transactionPartnerValue = "";
        $categoryValue = "";
        $repeatUnitValue = "";
        $repeatFrequencyValue = "1";
    }
    //set vars with values
    $FormAction = $_SERVER['PHP_SELF'];
    if ($AccountID == "choose") {
        $AccountLabel = $widgets->createLabel("hiddenAccID", getBadgerTranslation2('accountTransaction', 'Account'), true);
        $hiddenAccID = $widgets->createSelectField("hiddenAccID", getAccountsSelectArray(), $AccountID, "", false, "style='width: 213px;'");
    } else {
        $AccountLabel = "";
        $hiddenAccID = $widgets->createField("hiddenAccID", 20, $AccountID, "", false, "hidden");
    }
    $hiddenID = $widgets->createField("hiddenID", 20, $ID, "", false, "hidden");
    $hiddenType = $widgets->createField("hiddenType", 20, $transactionType, "", false, "hidden");
    //Fields & Labels
    $titleLabel = $widgets->createLabel("title", getBadgerTranslation2('accountTransaction', 'title'), true);
    $titleField = $widgets->createField("title", 30, $titleValue, "", true, "text", "");
    $descriptionLabel = $widgets->createLabel("description", getBadgerTranslation2('accountTransaction', 'description'), false);
    $descriptionField = $widgets->createField("description", 30, $descriptionValue, "", false, "text", "");
    $beginDateLabel = $widgets->createLabel("beginDate", getBadgerTranslation2('accountTransaction', 'beginDate'), true);
    $beginDateField = $widgets->addDateField("beginDate", $beginDateValue);
    $endDateLabel = $widgets->createLabel("endDate", getBadgerTranslation2('accountTransaction', 'endDate'), true);
    $endDateField = $widgets->addDateField("endDate", $endDateValue);
    $amountLabel = $widgets->createLabel("amount", getBadgerTranslation2('accountTransaction', 'amount'), true);
    $amountField = $widgets->createField("amount", 30, $amountValue, "", true, "text", "");
    $transactionPartnerLabel = $widgets->createLabel("transactionPartner", getBadgerTranslation2('accountTransaction', 'transactionPartner'), false);
    $transactionPartnerField = $widgets->createField("transactionPartner", 30, $transactionPartnerValue, "", false, "text", "");
    $outsideCapitalLabel = $widgets->createLabel("outsideCapital", getBadgerTranslation2('accountTransaction', 'outsideCapital'), false);
    $outsideCapitalField = $widgets->createField("outsideCapital", 30, "on", "", false, "checkbox", $outsideCapitalValue);
    $categoryLabel = $widgets->createLabel("category", getBadgerTranslation2('accountTransaction', 'category'), false);
    $categoryField = $widgets->createSelectField("category", getCategorySelectArray(), $categoryValue, "", false, "style='width: 213px;'");
    $repeatUnitLabel = $widgets->createLabel("repeatUnit", getBadgerTranslation2('accountTransaction', 'repeatFrequency'), true);
    $repeatUnitField = $widgets->createSelectField("repeatUnit", getIntervalUnitsArray(), $repeatUnitValue, "", true, "style='width: 104px;'");
    $everyLabel = getBadgerTranslation2('intervalUnits', 'every');
    $repeatFrequencyField = $widgets->createField("repeatFrequency", 1, $repeatFrequencyValue, "", true, "text", "");
    //Buttons
    $submitBtn = $widgets->createButton("submitBtn", getBadgerTranslation2('dataGrid', 'save'), "submit", "Widgets/accept.gif", "accesskey='s'");
    if ($redirectPage) {
        $backBtn = $widgets->createButton("backBtn", getBadgerTranslation2('dataGrid', 'back'), "location.href='{$redirectPage}';return false;", "Widgets/back.gif");
    } else {
        $backBtn = "";
    }
    //add vars to template, print site
    $pageHeading = getBadgerTranslation2('accountTransaction', 'headingTransactionPlanned');
    eval("echo \"" . $tpl->getTemplate("Account/PlannedTransaction") . "\";");
}