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; }
$dailyPocketMoney = new Amount($freeMoney->div($countDay)); //calculate daily pocket money = free money / count of Days $day = 0; $pocketMoney1EndValue = ""; $pocketMoney2EndValue = ""; foreach ($totals as $key => $val) { $tmp = new Date($key); $PocketMoney1Loop = new Amount($pocketMoney1); $val2 = new Amount($val->get()); if ($showPocketMoney1 == 1) { $pocketMoney1EndValue = $val2->sub($PocketMoney1Loop->mul($day))->get(); } $PocketMoney2Loop = new Amount($pocketMoney2); $val3 = new Amount($val->get()); if ($showPocketMoney2 == 1) { $pocketMoney2EndValue = $val3->sub($PocketMoney2Loop->mul($day))->get(); } $day++; } //foreach($totals as $key => $val) { echo '<forecastData>'; $insertChart = urlencode($insertChart); echo "<insertChart>{$insertChart}</insertChart>"; if ($showSavingTarget == 1) { $dailyPocketMoneyValue = $dailyPocketMoney->getFormatted(); echo "<dailyPocketMoneyValue>{$dailyPocketMoneyValue}</dailyPocketMoneyValue>"; } if ($pocketMoney1EndValue) { $printedPocketMoney1EndValue = new Amount($pocketMoney1EndValue); $balancedEndDate1 = $printedPocketMoney1EndValue->getFormatted(); echo "<balancedEndDate1>{$balancedEndDate1}</balancedEndDate1>";
$dailyPocketMoneyLoop = new Amount($dailyPocketMoney->get()); $val1 = new Amount($val->get()); if ($showSavingTarget == 1) { $chart['chart_data'][$numberOfGraph][] = $val1->sub($dailyPocketMoneyLoop->mul($day))->get(); $numberOfGraph++; } $PocketMoney1Loop = new Amount($pocketMoney1->get()); $val2 = new Amount($val->get()); if ($showPocketMoney1 == 1) { $chart['chart_data'][$numberOfGraph][] = $val2->sub($PocketMoney1Loop->mul($day))->get(); $numberOfGraph++; } $PocketMoney2Loop = new Amount($pocketMoney2->get()); $val3 = new Amount($val->get()); if ($showPocketMoney2 == 1) { $chart['chart_data'][$numberOfGraph][] = $val3->sub($PocketMoney2Loop->mul($day))->get(); $numberOfGraph++; } $day++; } //for documentation for the following code see: http://www.maani.us/charts/index.php?menu=Reference $chart['chart_type'] = "line"; $chart['axis_category'] = array('skip' => $countDay / 12, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 100, 'orientation' => "horizontal"); $chart['axis_ticks'] = array('value_ticks' => true, 'category_ticks' => true, 'position' => "centered", 'major_thickness' => 2, 'major_color' => "000000", 'minor_thickness' => 1, 'minor_color' => "000000", 'minor_count' => 4); $chart['axis_value'] = array('min' => 0, 'max' => 0, 'steps' => 10, 'prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'show_min' => true, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 75, 'orientation' => "horizontal"); $chart['chart_border'] = array('top_thickness' => 1, 'bottom_thickness' => 1, 'left_thickness' => 1, 'right_thickness' => 1, 'color' => "000000"); $chart['chart_pref'] = array('line_thickness' => 1, 'point_shape' => "none", 'fill_shape' => false); $chart['chart_grid_h'] = array('thickness' => 1, 'color' => "000000", 'alpha' => 15, 'type' => "solid"); $chart['chart_grid_v'] = array('thickness' => 1, 'color' => "000000", 'alpha' => 5, 'type' => "dashed"); $chart['chart_rect'] = array('x' => 50, 'y' => 50, 'width' => 700, 'height' => 300, 'positive_color' => "ffffff", 'negative_color' => "000000", 'positive_alpha' => 100, 'negative_alpha' => 10); $chart['chart_value'] = array('prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'position' => "cursor", 'hide_zero' => true, 'as_percentage' => false, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 90);
function parseToArray($fp, $accountId) { $headerParsed = false; $continueField = false; $validFile = false; $title = ''; $importedTransactions = array(); while (!feof($fp)) { $currentLine = fgets($fp); if (!$headerParsed) { if ($currentLine == VOLKSBANK_START_DATA_MARKER) { $headerParsed = true; $validFile = true; } continue; } $currentLine = str_replace("\n", '', $currentLine); $offset = 0; if (!$continueField) { if ($currentLine == '') { break; } if (!preg_match('/^"[0-9.]+?";"([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})";/', $currentLine, $matches, PREG_OFFSET_CAPTURE)) { fclose($fp); throw new badgerException('importCsv', 'wrongSeperatorNumber'); } $offset = $matches[0][1] + strlen($matches[0][0]); $day = $matches[1][0]; $month = $matches[2][0]; $year = $matches[3][0]; $valutaDate = new Date("{$year}-{$month}-{$day}"); if (!preg_match('/"(.+?)"{0,1}$/', $currentLine, $matches, PREG_OFFSET_CAPTURE, $offset)) { fclose($fp); throw new badgerException('importCsv', 'wrongSeperatorNumber'); } $offset = $matches[0][1] + strlen($matches[0][0]); $description = $matches[1][0]; if (substr($currentLine, -1, 1) != '"') { $continueField = true; continue; } } if ($continueField) { if (!preg_match('/(^([^"]*)(";){0,1}).*$/', $currentLine, $matches, PREG_OFFSET_CAPTURE, $offset)) { fclose($fp); throw new badgerException('importCsv', 'wrongSeperatorNumber'); } $offset = $matches[1][1] + strlen($matches[1][0]); $title .= ' ' . $matches[2][0]; if (substr($matches[1][0], -1, 1) != ';') { continue; } } if (!preg_match('/"([A-Z]{1,3})";"([0-9.,]+)";"(S|H)"$/', $currentLine, $matches, PREG_OFFSET_CAPTURE)) { fclose($fp); throw new badgerException('importCsv', 'wrongSeperatorNumber'); } $currency = $matches[1][0]; $amountStr = $matches[2][0]; $amountStr = str_replace('.', '', $amountStr); $amountStr = str_replace(',', '.', $amountStr); $amount = new Amount($amountStr); $posNeg = $matches[3][0]; if ($posNeg == 'S') { $amount->mul(-1); } $importedTransactions[] = array('categoryId' => '', 'accountId' => $accountId, 'title' => substr(trim($title), 0, 99), 'description' => trim($description), 'valutaDate' => $valutaDate, 'amount' => $amount, 'transactionPartner' => ''); $continueField = false; $title = ''; $description = ''; $valutaDate = null; $amount = null; } if (!$validFile) { fclose($fp); throw new badgerException('importCsv', 'noSeperator'); } return $importedTransactions; }
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") . "\";"); }