Example #1
0
    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;
    }
#!/usr/bin/php
<?php 
require_once dirname(__FILE__) . '/../server/CloudBankServer.php';
require_once dirname(__FILE__) . '/../server/SchemaDef.php';
//   require_once('SCA/SCA.php');
CloudBankServer::Singleton()->tryQuery('
      ALTER TABLE event ADD statement_item_id VARCHAR(16)
   ');
CloudBankServer::Singleton()->tryQuery('
      ALTER TABLE event ADD is_cleared BOOLEAN DEFAULT 0
   ');
CloudBankServer::Singleton()->tryQuery('DROP VIEW account_events');
$g_createSchemaStatements = SchemaDef::CreateSchemaStatements();
foreach (array('account_events', 'statement_item', 'statement_item_unmatched', 'event_statement_item_match', 'event_matched') as $v_dBObject) {
    CloudBankServer::Singleton()->tryQuery($g_createSchemaStatements[$v_dBObject]);
}
Example #3
0
 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']})");
     }
 }
Example #4
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));
    }
Example #5
0
#!/usr/bin/php
<?php 
require_once dirname(__FILE__) . '/../server/CloudBankServer.php';
require_once dirname(__FILE__) . '/../server/SchemaDef.php';
require_once 'SCA/SCA.php';
foreach (SchemaDef::CreateSchemaStatements() as $v_dBObject => $v_sQLStatement) {
    CloudBankServer::Singleton()->tryQuery($v_sQLStatement);
}
$v_ledgerAccountService = SCA::getService(dirname(__FILE__) . '/../server/LedgerAccountService.php');
$v_ledgerAccountService->createBeginningAccount();