示例#1
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Postings();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configuração
     $persistence->setServiceLocator($serviceLocator);
     // Banco de Dados
     $db = Application::getApplication()->getServiceManager()->get('db');
     // Configuração
     $serviceLocator->setService('db', $db);
     // Tabelas
     $tbAccounts = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Accounts');
     $tbPostings = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Postings');
     $tbEntries = Application::getApplication()->getServiceManager()->get('Balance\\Db\\TableGateway\\Entries');
     // Formatador de Datas
     $formatter = new IntlDateFormatter(null, IntlDateFormatter::MEDIUM, IntlDateFormatter::MEDIUM);
     // Configuração
     $serviceLocator->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts)->setService('Balance\\Db\\TableGateway\\Postings', $tbPostings)->setService('Balance\\Db\\TableGateway\\Entries', $tbEntries);
     // Limpeza
     $tbPostings->delete(function () {
         // Remover Todos
     });
     $tbAccounts->delete(function () {
         // Remover Todos
     });
     // Chaves Primárias
     $primaries = ['postings' => [], 'accounts' => []];
     // Inserir Conta 1
     $tbAccounts->insert(['name' => 'Account AA', 'type' => AccountType::ACTIVE, 'description' => 'Account AA Description', 'position' => 0, 'accumulate' => 0]);
     // Captura de Chave Primária
     $primaries['accounts']['aa'] = (int) $tbAccounts->getLastInsertValue();
     // Inserir Conta 2
     $tbAccounts->insert(['name' => 'Account BB', 'type' => AccountType::ACTIVE, 'description' => 'Account BB Description', 'position' => 1, 'accumulate' => 0]);
     // Captura de Chave Primária
     $primaries['accounts']['bb'] = (int) $tbAccounts->getLastInsertValue();
     // Inserir Lançamento 1
     $tbPostings->insert(['datetime' => date('c', $formatter->parse('10/10/2010 09:10:10')), 'description' => 'Posting XX']);
     // Captura de Chave Primária
     $primaries['postings']['xx'] = (int) $tbPostings->getLastInsertValue();
     // Inserir Lançamento 2
     $tbPostings->insert(['datetime' => date('c', $formatter->parse('10/10/2010 10:10:10')), 'description' => 'Posting YY']);
     // Captura de Chave Primária
     $primaries['postings']['yy'] = (int) $tbPostings->getLastInsertValue();
     // Relacionamento 0-0
     $tbEntries->insert(['posting_id' => $primaries['postings']['xx'], 'account_id' => $primaries['accounts']['aa'], 'type' => EntryType::CREDIT, 'value' => 100, 'position' => 0]);
     // Relacionamento 0-1
     $tbEntries->insert(['posting_id' => $primaries['postings']['xx'], 'account_id' => $primaries['accounts']['bb'], 'type' => EntryType::DEBIT, 'value' => 100, 'position' => 1]);
     // Relacionamento 1-0
     $tbEntries->insert(['posting_id' => $primaries['postings']['yy'], 'account_id' => $primaries['accounts']['aa'], 'type' => EntryType::CREDIT, 'value' => 200, 'position' => 0]);
     // Relacionamento 1-1
     $tbEntries->insert(['posting_id' => $primaries['postings']['yy'], 'account_id' => $primaries['accounts']['bb'], 'type' => EntryType::DEBIT, 'value' => 200, 'position' => 1]);
     // Configuração
     $this->primaries = $primaries;
     // Apresentação
     return $persistence;
 }
示例#2
0
 protected function getPersistence()
 {
     // Inicialização
     $persistence = new Postings();
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Localizador de Serviços
     $serviceLocator = new ServiceManager();
     // Configurações
     $persistence->setServiceLocator($serviceLocator);
     // Tabelas
     $tbPostings = $serviceManager->get('Balance\\Db\\TableGateway\\Postings');
     $tbAccounts = $serviceManager->get('Balance\\Db\\TableGateway\\Accounts');
     $tbEntries = $serviceManager->get('Balance\\Db\\TableGateway\\Entries');
     // Configurações
     $serviceLocator->setService('db', $serviceManager->get('db'))->setService('Balance\\Db\\TableGateway\\Postings', $tbPostings)->setService('Balance\\Db\\TableGateway\\Accounts', $tbAccounts)->setService('Balance\\Db\\TableGateway\\Entries', $tbEntries);
     // Limpeza
     $tbPostings->delete(function () {
         // Remover Todos
     });
     $tbAccounts->delete(function () {
         // Remover Todos
     });
     // Criar um Lançamento
     $tbPostings->insert(['datetime' => '2010-10-10 10:10:10', 'description' => 'Posting Description']);
     // Chave Primária
     $this->primary = (int) $tbPostings->getLastInsertValue();
     // Inserir Conta A
     $tbAccounts->insert(['name' => 'Account A', 'type' => AccountType::ACTIVE, 'description' => 'Account A Description', 'position' => 0, 'accumulate' => 0]);
     // Chave Primária
     $accountA = (int) $tbAccounts->getLastInsertValue();
     // Inserir Conta B
     $tbAccounts->insert(['name' => 'Account B', 'type' => AccountType::ACTIVE, 'description' => 'Account B Description', 'position' => 1, 'accumulate' => 0]);
     // Chave Primária
     $accountB = (int) $tbAccounts->getLastInsertValue();
     // Entrada 0
     $tbEntries->insert(['posting_id' => $this->primary, 'account_id' => $accountA, 'type' => EntryType::CREDIT, 'value' => 9999999.99, 'position' => 0]);
     // Entrada 1
     $tbEntries->insert(['posting_id' => $this->primary, 'account_id' => $accountB, 'type' => EntryType::DEBIT, 'value' => 9999999.99, 'position' => 1]);
     // Apresentação
     return $persistence;
 }