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)); }
private function assertStatementItemIsValid($p_statement_item_arr, $p_line_no, $p_statement_line) { if (count($p_statement_item_arr) < 6) { throw new Exception("Statement file: line #{$p_line_no} is incomplete (" . "{$p_statement_line})"); } if (!SchemaDef::IsValidStatementItemID($p_statement_item_arr[0])) { throw new Exception("Statement file: line #{$p_line_no}: invalid item ID (" . "{$p_statement_item_arr['0']})"); } if (!$this->r_ledgerAccountService->doesExistAndNotThis($p_statement_item_arr[1], CloudBankConsts::LedgerAccountType_Account)) { throw new Exception("Statement file: line #{$p_line_no}: account (" . "{$p_statement_item_arr['1']}) does not exist"); } if (!SchemaDef::IsValidStatementItemType($p_statement_item_arr[2])) { throw new Exception("Statement file: line #{$p_line_no}: invalid item type (" . "{$p_statement_item_arr['2']})"); } if (!SchemaDef::IsValidDate($p_statement_item_arr[3])) { throw new Exception("Statement file: line #{$p_line_no}: invalid date (" . "{$p_statement_item_arr['3']})"); } if (!SchemaDef::IsValidStatementItemDescription($p_statement_item_arr[4])) { throw new Exception("Statement file: line #{$p_line_no}: invalid description (" . "{$p_statement_item_arr['4']})"); } if (!SchemaDef::IsValidAmount($p_statement_item_arr[5])) { throw new Exception("Statement file: line #{$p_line_no}: invalid amount (" . "{$p_statement_item_arr['4']})"); } }