private function createOrUpdateLedgerAccount($p_name, $p_type, $p_id = NULL) { if (!SchemaDef::IsValidLedgerAccountName($p_name)) { throw new Exception("Invalid LedgerAccount name ({$p_name})"); } if ($this->doesExistAndNotThis($p_name, $p_type, $p_id)) { throw new Exception("LedgerAccount ({$p_name}, {$p_type}) already exists."); } $v_accountID = is_null($p_id) ? CloudBankServer::UUID() : $p_id; $v_bindArray = array(':id' => $v_accountID, ':name' => $p_name); if (is_null($p_id)) { $v_bindArray[':type'] = $p_type; } $this->r_cloudBankServer->execQuery(is_null($p_id) ? ' INSERT INTO ledger_account(id, name, type) VALUES ( :id, :name, :type ) ' : 'UPDATE ledger_account SET name = :name WHERE id = :id', $v_bindArray); return $v_accountID; }
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)); }