Beispiel #1
0
    public function createOrUpdateEvent($p_date, $p_description, $p_accountID, $p_otherAccountID, $p_amount, $p_statement_item_id, $p_is_cleared, $p_id = NULL)
    {
        if (!SchemaDef::IsValidDate($p_date)) {
            throw new Exception("Invalid Event date ({$p_date})");
        }
        if (!SchemaDef::IsValidEventDescription($p_description)) {
            throw new Exception("Invalid Event description ({$p_description})");
        }
        if (!SchemaDef::IsValidAmount($p_amount)) {
            throw new Exception("Invalid amount ({$p_amount}). Must be a floating point number.");
        }
        $this->prepareRelatedAccounts($p_accountID, $p_otherAccountID, $p_amount, $v_debitLedgerAccountID, $v_creditLedgerAccountID, $v_amount);
        if (!SchemaDef::IsValidLedgerAccountPair($v_debitLedgerAccountID, $v_creditLedgerAccountID)) {
            throw new Exception("Referenced LedgerAccounts ({$v_debitLedgerAccountID}) must not " . "be the same");
        }
        if (!SchemaDef::IsValidStatementItemIDInEvent($p_statement_item_id)) {
            throw new Exception("Invalid statement reference ({$p_statement_item_id})");
        }
        $this->r_cloudBankServer->execQuery(is_null($p_id) ? '
		  INSERT 
		     INTO event(
		     	id, date, description, credit_ledger_account_id,
		       	debit_ledger_account_id, amount, statement_item_id,
			is_cleared
		     ) VALUES (
		      	:id, :date, :description, :credit_ledger_account_id,
			:debit_ledger_account_id, :amount, :statement_item_id,
			:is_cleared
		     )
	       ' : '
		  UPDATE event
		  SET
		     date = :date, description = :description,
		     credit_ledger_account_id = :credit_ledger_account_id,
		     debit_ledger_account_id = :debit_ledger_account_id,
		     amount = :amount, statement_item_id = :statement_item_id,
		     is_cleared = :is_cleared
		  WHERE id = :id
	       ', array(':id' => is_null($p_id) ? CloudBankServer::UUID() : $p_id, ':date' => $p_date, ':description' => $p_description, ':credit_ledger_account_id' => $v_creditLedgerAccountID, ':debit_ledger_account_id' => $v_debitLedgerAccountID, ':amount' => $v_amount, ':statement_item_id' => $p_statement_item_id, ':is_cleared' => $p_is_cleared));
    }