コード例 #1
0
 /**
  * Deletes the planned transaction identified by $plannedTransactionId.
  * 
  * @param $plannedTransactionId integer The id of the planned transaction to delete.
  * @throws BadgerException If $plannedTransactionId is unknown to the DB.
  */
 public function deletePlannedTransaction($plannedTransactionId)
 {
     $plannedTransactionId = PlannedTransaction::sanitizeId($plannedTransactionId);
     if (isset($this->plannedTransactions[$plannedTransactionId])) {
         unset($this->plannedTransactions[$plannedTransactionId]);
     }
     $sql = "DELETE FROM planned_transaction\n\t\t\t\tWHERE planned_transaction_id = {$plannedTransactionId}";
     $dbResult =& $this->badgerDb->query($sql);
     if (PEAR::isError($dbResult)) {
         //echo "SQL Error: " . $dbResult->getMessage();
         throw new BadgerException('Account', 'SQLError', $dbResult->getMessage());
     }
     if ($this->badgerDb->affectedRows() != 1) {
         throw new BadgerException('Account', 'UnknownPlannedTransactionId', $plannedTransactionId);
     }
 }
コード例 #2
0
 /**
  * Adds a new planned transaction to this account.
  * 
  * @param $title string Title of the new planned transaction.
  * @param $amount object Amount object with the amount of the new planned transaction.
  * @param $repeatUnit string The repeat unit (day, week, month, year) of the new planned transaction.
  * @param $repeatFrequency integer The repeat frequency of the new planned transaction.
  * @param $beginDate object Date object with the begin date of the new planned transaction.
  * @param $endDate object Date object with the end date of the new planned transaction.
  * @param $description string Description of the new planned transaction.
  * @param $transactionPartner string Transaction partner of the new planned transaction.
  * @param $category object Category object with the category of the new planned transaction.
  * @param $outsideCapital bool True if the new planned transaction is outside capital, false otherwise.
  * @throws BadgerException If an error occured while inserting.
  * @return object The new PlannedTransaction object.
  */
 public function addPlannedTransaction($title, $amount, $repeatUnit, $repeatFrequency, $beginDate, $endDate = null, $description = null, $transactionPartner = null, $category = null, $outsideCapital = null, $transferalAccount = null, $transferalAmount = null, $transferalTransaction = null)
 {
     $plannedTransactionId = $this->badgerDb->nextId('planned_transaction_ids');
     $sql = "INSERT INTO planned_transaction\n\t\t\t(planned_transaction_id, account_id, title, amount, repeat_unit, repeat_frequency, begin_date ";
     if ($endDate) {
         $sql .= ", end_date";
     }
     if ($description) {
         $sql .= ", description";
     }
     if ($transactionPartner) {
         $sql .= ", transaction_partner";
     }
     if ($category) {
         $sql .= ", category_id";
     }
     if ($outsideCapital) {
         $sql .= ", outside_capital";
     }
     $sql .= ")\n\t\t\tVALUES ({$plannedTransactionId}, " . $this->id . ", '" . $this->badgerDb->escapeSimple($title) . "', '" . $amount->get() . "', '" . $this->badgerDb->escapeSimple($repeatUnit) . "', " . $repeatFrequency . ", '" . $beginDate->getDate() . "'";
     if ($endDate) {
         $sql .= ", '" . $endDate->getDate() . "'";
     }
     if ($description) {
         $sql .= ", '" . $this->badgerDb->escapeSimple($description) . "'";
     }
     if ($transactionPartner) {
         $sql .= ", '" . $this->badgerDb->escapeSimple($transactionPartner) . "'";
     }
     if ($category) {
         $sql .= ", " . $category->getId();
     }
     if ($outsideCapital) {
         $sql .= ", " . $this->badgerDb->quoteSmart($outsideCapital);
     }
     $sql .= ")";
     $dbResult =& $this->badgerDb->query($sql);
     if (PEAR::isError($dbResult)) {
         throw new BadgerException('Account', 'SQLError', "SQL: {$sql}\n" . $dbResult->getMessage());
     }
     if ($this->badgerDb->affectedRows() != 1) {
         throw new BadgerException('Account', 'insertError', $dbResult->getMessage());
     }
     if (is_null($transferalAccount) && is_null($transferalTransaction)) {
         $type = 'PlannedTransaction';
     } else {
         $type = 'PlannedTransferalTransaction';
     }
     $newTransaction = new PlannedTransaction($this->badgerDb, $this, $plannedTransactionId, $repeatUnit, $repeatFrequency, $beginDate, $endDate, $title, $amount, $description, $transactionPartner, $category, $outsideCapital, $type);
     $this->plannedTransactions[$plannedTransactionId] = $newTransaction;
     if ($transferalTransaction) {
         $newTransaction->setTransferalTransaction($transferalTransaction);
     } else {
         if (!is_null($transferalAccount)) {
             $transferalTransaction = $transferalAccount->addPlannedTransaction($title, $transferalAmount, $repeatUnit, $repeatFrequency, $beginDate, $endDate, $description, $transactionPartner, $category, $outsideCapital, null, null, $newTransaction);
             $newTransaction->setTransferalTransaction($transferalTransaction);
             $newTransaction->setTransferalSource(true);
         }
     }
     return $newTransaction;
 }