public function service()
 {
     $categoryManager = new CategoryManager($this->config, $this->args);
     $categoryId = $this->secure($_REQUEST["category_id"]);
     $display_name = $this->secure($_REQUEST["display_name"]);
     $last_clickable = $this->secure($_REQUEST["last_clickable"]);
     $adminManager = new AdminManager($this->config, $this->args);
     $adminId = $this->sessionManager->getUser()->getId();
     $adminDto = $adminManager->selectByPK($adminId);
     if ($adminDto) {
         $categoryDto = $categoryManager->getCategoryById($categoryId);
         if (!$categoryDto) {
             $jsonArr = array('status' => "err", "errText" => "System Error: Category doesn't exist!");
             echo json_encode($jsonArr);
             return false;
         }
         $categoryManager->updateCategoryAttributes($categoryId, $display_name, $last_clickable);
         $jsonArr = array('status' => "ok", "message" => "ok");
         echo json_encode($jsonArr);
         return true;
     } else {
         $jsonArr = array('status' => "err", "errText" => "System Error: You are not Admin!");
         echo json_encode($jsonArr);
         return false;
     }
 }
Ejemplo n.º 2
0
 $cm1 = new CategoryManager($badgerDb);
 $targetAccounts = array();
 $targetAccounts["x{$baseAccountId}"] = $baseAccount;
 //for all rows
 for ($selectedTransactionNumber = 0; $selectedTransactionNumber < getGPC($_POST, 'tableRows', 'integer'); $selectedTransactionNumber++) {
     //reset tableRowArray
     $tableRowArray = NULL;
     // if the transaction was selected
     if (getGPC($_POST, "select{$selectedTransactionNumber}", 'checkbox')) {
         if (getGPC($_POST, 'matchingTransactionSelect' . $selectedTransactionNumber) == 'none') {
             $account3 = $am3->getAccountById(getGPC($_POST, 'account2Select' . $selectedTransactionNumber, 'integer'));
             $targetAccounts['x' . $account3->getId()] = $account3;
             $transactionCategory = NULL;
             if (!getGPC($_POST, 'categorySelect' . $selectedTransactionNumber) == NULL) {
                 if (getGPC($_POST, 'categorySelect' . $selectedTransactionNumber) != "NULL") {
                     $transactionCategory = $cm1->getCategoryById(getGPC($_POST, 'categorySelect' . $selectedTransactionNumber, 'integer'));
                 }
             }
             $account3->addFinishedTransaction(getGPC($_POST, 'amount' . $selectedTransactionNumber, 'AmountFormatted'), getGPC($_POST, 'title' . $selectedTransactionNumber), getGPC($_POST, 'description' . $selectedTransactionNumber), getGPC($_POST, 'valutaDate' . $selectedTransactionNumber, 'DateFormatted'), getGPC($_POST, 'transactionPartner' . $selectedTransactionNumber), $transactionCategory, getGPC($_POST, "outside" . $selectedTransactionNumber, 'checkbox'), getGPC($_POST, "exceptional" . $selectedTransactionNumber, 'checkbox'), getGPC($_POST, 'periodical' . $selectedTransactionNumber, 'checkbox'));
         } else {
             //Update existing transaction
             $transaction = $baseAccount->getFinishedTransactionById(getGPC($_POST, 'matchingTransactionSelect' . $selectedTransactionNumber, 'integer'));
             $transaction->setTitle($transaction->getTitle() . ' - ' . getGPC($_POST, 'title' . $selectedTransactionNumber));
             $transaction->setDescription($transaction->getDescription() . "\n" . getGPC($_POST, 'description' . $selectedTransactionNumber) . "\n" . getBadgerTranslation2('importCsv', 'descriptionFieldImportedPartner') . getGPC($_POST, 'transactionPartner' . $selectedTransactionNumber) . "\n" . getBadgerTranslation2('importCsv', 'descriptionFieldOrigValutaDate') . $transaction->getValutaDate()->getFormatted() . "\n" . getBadgerTranslation2('importCsv', 'descriptionFieldOrigAmount') . $transaction->getAmount()->getFormatted());
             $transaction->setValutaDate(getGPC($_POST, 'valutaDate' . $selectedTransactionNumber, 'DateFormatted'));
             $transaction->setAmount(getGPC($_POST, 'amount' . $selectedTransactionNumber, 'AmountFormatted'));
             if (strpos($transaction->getType(), 'Planned') !== false) {
                 $transaction->setPlannedTransaction(null);
             }
         }
     }
/*
* ____          _____   _____ ______ _____  
*|  _ \   /\   |  __ \ / ____|  ____|  __ \ 
*| |_) | /  \  | |  | | |  __| |__  | |__) |
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* 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/CategoryManager.class.php';
header('Content-Type: text/plain');
define('endl', "\n");
$cm = new CategoryManager($badgerDb);
while ($cat = $cm->getNextCategory()) {
    echo 'Category Title: ' . $cat->getTitle() . endl;
}
$cat1 = $cm->getCategoryById(1);
echo 'Category Id: ' . $cat1->getId() . endl;
$cat2 = $cm->addCategory('Neue Kategorie ' . rand(0, 100), 'Bähschraipunk');
echo 'New Category Title: ' . $cat2->getTitle() . endl;
$cat3 = $cm->addCategory('Temporäre Kategorie');
$tmpId = $cat3->getId();
echo 'Temporary Category Id: ' . $tmpId . endl;
$cm->deleteCategory($tmpId);
$cat4 = $cm->getCategoryById($tmpId);
echo 'Temporary Category Title (never shown): ' . $cat4->getTitle() . endl;
 /**
  * Creates a Planned Transaction.
  * 
  * @param $badgerDb object The DB object.
  * @param $account object The Account object who created this Transaction.
  * @param $data mixed An associative array with the values out of the DB OR the id of the Transaction.
  * @param $repeatUnit string The repeat unit of the Transaction.
  * @param $repeatFrequency string The repeat frequency of the Transaction.
  * @param $beginDate object The Date object with the begin date of the Transaction.
  * @param $endDate object The Date object with the end date of the Transaction.
  * @param $title string The title of the Transaction.
  * @param $amount object The Amount object with the amount of this Transaction.
  * @param $description string The description of the Transaction.
  * @param $transactionPartner string The transaction partner of the Transaction
  * @param $outsideCapital boolean The origin of the Transaction.
  */
 function __construct(&$badgerDb, &$account, $data, $repeatUnit = null, $repeatFrequency = null, $beginDate = null, $endDate = null, $title = null, $amount = null, $description = null, $transactionPartner = null, $category = null, $outsideCapital = null, $type = 'PlannedTransaction')
 {
     $CategoryManager = new CategoryManager($badgerDb);
     $this->badgerDb = $badgerDb;
     $this->account = $account;
     if (is_array($data)) {
         $this->id = $data['planned_transaction_id'];
         $this->title = $data['title'];
         $this->description = $data['description'];
         $this->amount = new Amount($data['amount']);
         $this->outsideCapital = $data['outside_capital'];
         $this->transactionPartner = $data['transaction_partner'];
         if ($data['category_id']) {
             $this->category = $CategoryManager->getCategoryById($data['category_id']);
         }
         $this->beginDate = new Date($data['begin_date']);
         if ($data['end_date']) {
             $this->endDate = new Date($data['end_date']);
         }
         $this->repeatUnit = $data['repeat_unit'];
         $this->repeatFrequency = $data['repeat_frequency'];
         $this->type = 'PlannedTransaction';
     } else {
         $this->id = $data;
         $this->title = $title;
         $this->description = $description;
         $this->amount = $amount;
         $this->outsideCapital = $outsideCapital;
         $this->transactionPartner = $transactionPartner;
         $this->category = $category;
         $this->beginDate = $beginDate;
         $this->endDate = $endDate;
         $this->repeatUnit = $repeatUnit;
         $this->repeatFrequency = $repeatFrequency;
         $this->type = $type;
     }
 }
 /**
  * Creates a Finished Transaction.
  * 
  * @param $badgerDb object The DB object.
  * @param $account object The Account object who created this Transaction.
  * @param $data mixed An associative array with the values out of the DB OR the id of the Transaction.
  * @param $title string The title of the Transaction.
  * @param $amount object The Amount object with the amount of this Transaction.
  * @param $description string The description of the Transaction.
  * @param $valutaDate object The Date object with the valuta date of the Transaction.
  * @param $transactionPartner string The transaction partner of the Transaction
  * @param $outsideCapital boolean The origin of the Transaction.
  * @param $type string The type of the Transaction.
  */
 function __construct(&$badgerDb, &$account, $data, $title = null, $amount = null, $description = null, $valutaDate = null, $transactionPartner = null, $category = null, $outsideCapital = null, $exceptional = null, $periodical = null, $sourcePlannedTransaction = null, $type = 'FinishedTransaction')
 {
     $this->badgerDb = $badgerDb;
     $this->account = $account;
     if (is_array($data)) {
         $this->id = $data['finished_transaction_id'];
         $this->title = $data['title'];
         $this->description = $data['description'];
         $this->amount = new Amount($data['amount']);
         $this->outsideCapital = $data['outside_capital'];
         $this->transactionPartner = $data['transaction_partner'];
         if ($data['category_id']) {
             $cm = new CategoryManager($badgerDb);
             $this->category = $cm->getCategoryById($data['category_id']);
         }
         if ($data['valuta_date']) {
             $this->valutaDate = new Date($data['valuta_date']);
         }
         $this->exceptional = $data['exceptional'];
         $this->periodical = $data['periodical'];
         if ($data['planned_transaction_id']) {
             $this->sourcePlannedTransaction = $account->getPlannedTransactionById($data['planned_transaction_id']);
         }
         $this->type = 'FinishedTransaction';
     } else {
         $this->id = $data;
         $this->title = $title;
         $this->description = $description;
         $this->valutaDate = $valutaDate;
         $this->amount = $amount;
         $this->outsideCapital = $outsideCapital;
         $this->transactionPartner = $transactionPartner;
         $this->category = $category;
         $this->exceptional = $exceptional;
         $this->periodical = $periodical;
         $this->sourcePlannedTransaction = $sourcePlannedTransaction;
         $this->type = $type;
     }
 }
 /**
  * Creates a Planned Transaction.
  * 
  * @param $badgerDb object The DB object.
  * @param $account object The Account object who created this Transaction.
  * @param $data mixed An associative array with the values out of the DB OR the id of the Transaction.
  * @param $repeatUnit string The repeat unit of the Transaction.
  * @param $repeatFrequency string The repeat frequency of the Transaction.
  * @param $beginDate object The Date object with the begin date of the Transaction.
  * @param $endDate object The Date object with the end date of the Transaction.
  * @param $title string The title of the Transaction.
  * @param $amount object The Amount object with the amount of this Transaction.
  * @param $description string The description of the Transaction.
  * @param $transactionPartner string The transaction partner of the Transaction
  * @param $outsideCapital boolean The origin of the Transaction.
  */
 function __construct(&$badgerDb, &$account, $data, $repeatUnit = null, $repeatFrequency = null, $beginDate = null, $endDate = null, $title = null, $amount = null, $description = null, $transactionPartner = null, $category = null, $outsideCapital = null, $type = 'PlannedTransaction', $transferalTransaction = null)
 {
     $CategoryManager = new CategoryManager($badgerDb);
     $this->badgerDb = $badgerDb;
     $this->account = $account;
     if (is_array($data)) {
         $this->id = $data['planned_transaction_id'];
         $this->title = $data['title'];
         $this->description = $data['description'];
         $this->amount = new Amount($data['amount']);
         $this->outsideCapital = $data['outside_capital'];
         $this->transactionPartner = $data['transaction_partner'];
         if ($data['category_id']) {
             $this->category = $CategoryManager->getCategoryById($data['category_id']);
         }
         $this->beginDate = new Date($data['begin_date']);
         if ($data['end_date']) {
             $this->endDate = new Date($data['end_date']);
         }
         $this->repeatUnit = $data['repeat_unit'];
         $this->repeatFrequency = $data['repeat_frequency'];
         $this->transferalSource = $data['transferal_source'];
         if (!$data['transferal_transaction_id']) {
             $this->type = 'FinishedTransaction';
         } else {
             $this->type = 'FinishedTransferalTransaction';
         }
         if ($data['transferal_transaction_id']) {
             if (!is_null($repeatUnit) && $data['transferal_transaction_id'] == $repeatUnit->getId()) {
                 $this->transferalTransaction = $repeatUnit;
             } else {
                 $accountManager = new AccountManager($badgerDb);
                 try {
                     $transferalAccount = $accountManager->getAccountByPlannedTransactionId($data['transferal_transaction_id']);
                     $this->transferalTransaction = $transferalAccount->getPlannedTransactionById($data['transferal_transaction_id'], $this);
                 } catch (BadgerException $ex) {
                     $this->transferalTransaction = null;
                 }
             }
         }
     } else {
         $this->id = $data;
         $this->title = $title;
         $this->description = $description;
         $this->amount = $amount;
         $this->outsideCapital = $outsideCapital;
         $this->transactionPartner = $transactionPartner;
         $this->category = $category;
         $this->beginDate = $beginDate;
         $this->endDate = $endDate;
         $this->repeatUnit = $repeatUnit;
         $this->repeatFrequency = $repeatFrequency;
         $this->type = $type;
         $this->transferalTransaction = $transferalTransaction;
         $this->transferalSource = null;
     }
     $this->updateMode = self::UPDATE_MODE_ALL;
     $this->otherPlannedTransaction = null;
     $this->beginDateLocked = false;
     $this->endDateLocked = false;
     $this->originalTitle = $this->title;
     $this->originalBeginDate = new Date($this->beginDate);
     if (!is_null($this->endDate)) {
         $this->originalEndDate = new Date($this->endDate);
     } else {
         $this->originalEndDate = null;
     }
     $this->originalRepeatUnit = $this->repeatUnit;
     $this->originalRepeatFrequency = $this->repeatFrequency;
 }
Ejemplo n.º 7
0
             $exceptional = false;
         }
         if (isset($_POST["outside" . $selectedTransactionNumber])) {
             $outside = true;
         } else {
             $outside = false;
         }
         //create array with one transaction
         $amount1 = new Amount($_POST['amount' . $selectedTransactionNumber], true);
         $valutaDate1 = new Date($_POST['valutaDate' . $selectedTransactionNumber], true);
         $cm1 = new CategoryManager($badgerDb);
         $transactionCategory = NULL;
         #echo $_POST['categorySelect' . $selectedTransactionNumber];
         if (!$_POST['categorySelect' . $selectedTransactionNumber] == NULL) {
             if ($_POST['categorySelect' . $selectedTransactionNumber] != "NULL") {
                 $transactionCategory = $cm1->getCategoryById($_POST['categorySelect' . $selectedTransactionNumber]);
                 #echo $transactionCategory;
             }
         }
         #echo $transactionCategory;
         $tableRowArray = array("categoryId" => $transactionCategory, "account" => $_POST['account2Select' . $selectedTransactionNumber], "title" => $_POST['title' . $selectedTransactionNumber], "description" => $_POST['description' . $selectedTransactionNumber], "valutaDate" => $valutaDate1, "amount" => $amount1, "transactionPartner" => $_POST['transactionPartner' . $selectedTransactionNumber], "periodical" => $periodical, "exceptional" => $exceptional, "outside" => $outside);
     }
     //if a array with one transaction exist
     if ($tableRowArray) {
         //add the transaction to the multidimensional array
         $writeToDbArray[$selectedTransaction] = $tableRowArray;
         //increment number of selected transactions
         $selectedTransaction++;
     }
 }
 //write array to db
 /**
  * Creates a Finished Transaction.
  * 
  * @param $badgerDb object The DB object.
  * @param $account object The Account object who created this Transaction.
  * @param $data mixed An associative array with the values out of the DB OR the id of the Transaction.
  * @param $title string The title of the Transaction.
  * @param $amount object The Amount object with the amount of this Transaction.
  * @param $description string The description of the Transaction.
  * @param $valutaDate object The Date object with the valuta date of the Transaction.
  * @param $transactionPartner string The transaction partner of the Transaction
  * @param $outsideCapital boolean The origin of the Transaction.
  * @param $type string The type of the Transaction.
  */
 function __construct(&$badgerDb, &$account, $data, $title = null, $amount = null, $description = null, $valutaDate = null, $transactionPartner = null, $category = null, $outsideCapital = null, $exceptional = null, $periodical = null, $sourcePlannedTransaction = null, $type = 'FinishedTransaction', $transferalTransaction = null)
 {
     $this->badgerDb = $badgerDb;
     $this->account = $account;
     if (is_array($data)) {
         $this->id = $data['finished_transaction_id'];
         $this->title = $data['title'];
         $this->description = $data['description'];
         $this->amount = new Amount($data['amount']);
         $this->outsideCapital = $data['outside_capital'];
         $this->transactionPartner = $data['transaction_partner'];
         if ($data['category_id']) {
             $cm = new CategoryManager($badgerDb);
             $this->category = $cm->getCategoryById($data['category_id']);
         }
         if ($data['valuta_date']) {
             $this->valutaDate = new Date($data['valuta_date']);
         }
         $this->exceptional = $data['exceptional'];
         $this->periodical = $data['periodical'];
         $this->balance = new Amount($data['balance']);
         $this->transferalSource = $data['transferal_source'];
         $planned = false;
         if ($data['planned_transaction_id']) {
             try {
                 $this->sourcePlannedTransaction = $account->getPlannedTransactionById($data['planned_transaction_id']);
                 $planned = true;
             } catch (BadgerException $ex) {
                 $this->sourcePlannedTransaction = null;
             }
         }
         $transferal = false;
         if ($data['transferal_transaction_id']) {
             if (!is_null($title) && $data['transferal_transaction_id'] == $title->getId()) {
                 $this->transferalTransaction = $title;
                 $transferl = true;
             } else {
                 $accountManager = new AccountManager($badgerDb);
                 try {
                     $transferalAccount = $accountManager->getAccountByFinishedTransactionId($data['transferal_transaction_id']);
                     $this->transferalTransaction = $transferalAccount->getFinishedTransactionById($data['transferal_transaction_id'], $this);
                     $transferal = true;
                 } catch (BadgerException $ex) {
                     $this->transferalTransaction = null;
                 }
             }
         }
         $this->type = ($planned ? 'Planned' : 'Finished') . ($transferal ? 'Transferal' : '') . 'Transaction';
     } else {
         $this->id = $data;
         $this->title = $title;
         $this->description = $description;
         $this->valutaDate = $valutaDate;
         $this->amount = $amount;
         $this->outsideCapital = $outsideCapital;
         $this->transactionPartner = $transactionPartner;
         $this->category = $category;
         $this->exceptional = $exceptional;
         $this->periodical = $periodical;
         $this->sourcePlannedTransaction = $sourcePlannedTransaction;
         $this->balance = null;
         $this->type = $type;
         $this->transferalTransaction = $transferalTransaction;
         $this->transferalSource = null;
     }
     //if database output given
 }