public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         $repository = new TRepository('Customer');
         $count = $repository->where('name', 'like', 'Rafael%', TExpression::OR_OPERATOR)->where('name', 'like', 'Ana%', TExpression::OR_OPERATOR)->count();
         new TMessage('info', "Total of found customers: {$count} <br>\n");
         TTransaction::close();
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
 public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         $repository = new TRepository('Customer');
         $repository->where('address', 'like', 'Rua Porto%')->where('gender', '=', 'M')->delete();
         new TMessage('info', 'Records Deleted');
         TTransaction::close();
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
예제 #3
0
 public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         $repository = new TRepository('Customer');
         $customers = $repository->where('gender', '=', 'M')->where('name', 'like', 'A%')->load();
         foreach ($customers as $customer) {
             echo $customer->id . ' - ' . $customer->name . '<br>';
         }
         TTransaction::close();
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
 public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         // abre uma transação
         // inicia o repositório
         $repository = new TRepository('Customer');
         // conta os clientes
         $count = $repository->where('name', 'like', 'Rafael%', TExpression::OR_OPERATOR)->where('name', 'like', 'Ana%', TExpression::OR_OPERATOR)->count();
         new TMessage('info', "Total de clientes encontrados: {$count} <br>\n");
         TTransaction::close();
         // fecha a transação.
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
 public function __construct()
 {
     parent::__construct();
     try {
         TTransaction::open('samples');
         // abre uma transação
         // inicia o repositório
         $repository = new TRepository('Customer');
         // deleta os clientes
         $repository->where('address', 'like', 'Rua Porto%')->where('gender', '=', 'M')->delete();
         new TMessage('info', 'Registros excluídos');
         TTransaction::close();
         // fecha a transação.
     } catch (Exception $e) {
         new TMessage('error', $e->getMessage());
     }
 }
 /**
  * method onReload()
  * Load the datagrid with the database objects
  */
 function onReload($param = NULL)
 {
     try {
         // open a transaction with database 'atividade'
         TTransaction::open('atividade');
         // creates a repository for Atividade
         $repository = new TRepository('Atividade');
         $limit = 15;
         // creates a criteria
         $criteria = new TCriteria();
         $criHoras = new TCriteria();
         $criteria2 = new TCriteria();
         $criHoras2 = new TCriteria();
         $calculaHoras = null;
         $pesquisaNormal = null;
         $newparam = $param;
         // define new parameters
         if (isset($newparam['order']) and $newparam['order'] == 'ticket->titulo') {
             $newparam['order'] = '(select titulo from ticket where ticket_id = id)';
         }
         if (isset($newparam['order']) and $newparam['order'] == 'pessoa->pessoa_nome') {
             $newparam['order'] = '(select pessoa_nome from tbz_pessoas where pessoa_codigo = colaborador_id)';
         }
         if (isset($newparam['order']) and $newparam['order'] == 'tipo_atividade->nome') {
             $newparam['order'] = '(select nome from tipo_atividade where tipo_atividade_id = id)';
         }
         if (isset($newparam['order']) and $newparam['order'] == 'sistema->nome') {
             $newparam['order'] = '(select nome from sistema where sistema_id = id)';
         }
         // default order
         if (empty($newparam['order'])) {
             $newparam['order'] = 'data_atividade desc, id ';
             $newparam['direction'] = 'desc';
         }
         $criteria->setProperties($newparam);
         // order, offset
         $criteria->setProperty('limit', $limit);
         if (TSession::getValue('AtividadeList_filter_id')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_id'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_id'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_data_atividade_inicial')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_data_atividade_inicial'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_data_atividade_inicial'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_data_atividade_final')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_data_atividade_final'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_data_atividade_final'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_solicitante_id')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_solicitante_id'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_solicitante_id'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_colaborador_id')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_colaborador_id'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_colaborador_id'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_tipo_atividade_id')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_tipo_atividade_id'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_tipo_atividade_id'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_ticket_id')) {
             $criteria->add(TSession::getValue('AtividadeList_filter_ticket_id'));
             // add the session filter
             $criHoras->add(TSession::getValue('AtividadeList_filter_ticket_id'));
             // add the session filter
             $calculaHoras = true;
             $pesquisaNormal = true;
         }
         if (TSession::getValue('AtividadeList_filter_pesquisa_master')) {
             try {
                 TTransaction::open('atividade');
                 $pesquisa_master = TSession::getValue('AtividadeList_filter_pesquisa_master');
                 $repo = new TRepository('Ticket');
                 $tickets = $repo->where('titulo', 'ilike', "%{$pesquisa_master}%")->load();
                 $clausula[] = '0';
                 foreach ($tickets as $ticket) {
                     $clausula[] = $ticket->id;
                 }
                 TTransaction::close();
             } catch (Exception $e) {
                 new TMessage('error', $e->getMessage());
             }
             $criteria2->add(new TFilter('ticket_id', 'IN', $clausula), TExpression::OR_OPERATOR);
             $criteria2->add(new TFilter('descricao', 'ilike', "%{$pesquisa_master}%"), TExpression::OR_OPERATOR);
             $criHoras2->add(new TFilter('ticket_id', 'IN', $clausula), TExpression::OR_OPERATOR);
             $criHoras2->add(new TFilter('descricao', 'ilike', "%{$pesquisa_master}%"), TExpression::OR_OPERATOR);
             $calculaHoras = true;
         }
         if (TSession::getValue('AtividadeList_filter_pesquisa_master')) {
             if (!$pesquisaNormal) {
                 $criteriaFinal = $criteria2;
                 $criteriaHorasFinal = $criHoras2;
                 $criteriaFinal->setProperties($newparam);
                 // order, offset
                 $criteriaFinal->setProperty('limit', $limit);
             } else {
                 $criteriaFinal = new TCriteria();
                 $criteriaFinal->add($criteria);
                 $criteriaFinal->add($criteria2);
                 $criteriaFinal->setProperties($newparam);
                 // order, offset
                 $criteriaFinal->setProperty('limit', $limit);
                 $criteriaHorasFinal = new TCriteria();
                 $criteriaHorasFinal->add($criHoras);
                 $criteriaHorasFinal->add($criHoras2);
             }
         } else {
             $criteriaFinal = $criteria;
             $criteriaHorasFinal = $criHoras;
         }
         if ($calculaHoras) {
             $repo = new TRepository('Atividade');
             $horas = $repo->load($criteriaHorasFinal, FALSE);
             $totalHoras = null;
             if ($horas) {
                 foreach ($horas as $hora) {
                     $HoraEntrada = new DateTime($hora->hora_inicio);
                     $HoraSaida = new DateTime($hora->hora_fim);
                     $diferenca = $HoraSaida->diff($HoraEntrada)->format('%H:%I:%S');
                     $totalHoras += $this->string->time_to_sec($diferenca);
                 }
             }
             $this->onTotalAtividades(substr($this->string->sec_to_time($totalHoras), 0, -3));
         }
         // load the objects according to criteria
         $objects = $repository->load($criteriaFinal, FALSE);
         $this->datagrid->clear();
         try {
             if ($objects) {
                 // iterate the collection of active records
                 foreach ($objects as $object) {
                     // add the object inside the datagrid
                     $this->datagrid->addItem($object);
                 }
             }
         } catch (Exception $e) {
             new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         }
         // reset the criteria for record count
         $criteriaFinal->resetProperties();
         $count = $repository->count($criteriaFinal);
         $this->pageNavigation->setCount($count);
         // count of records
         $this->pageNavigation->setProperties($param);
         // order, page
         $this->pageNavigation->setLimit($limit);
         // limit
         // close the transaction
         TTransaction::close();
         $this->loaded = true;
     } catch (Exception $e) {
         // shows the exception error message
         new TMessage('error', '<b>Error</b> ' . $e->getMessage());
         // undo all pending operations
         TTransaction::rollback();
     }
 }
예제 #7
0
 public static function getCustomerSales($customer_id)
 {
     $repository = new TRepository('Sale');
     return $repository->where('customer_id', '=', $customer_id)->load();
 }