Esempio n. 1
0
 public function my_ledcoin()
 {
     auth_redirect_if_not_authentificated('errormessage/no_auth');
     $this->load->helper('filter');
     $post = $this->input->post();
     if ($post !== FALSE) {
         $post_filter = $this->input->post('filter');
         if ($post_filter !== FALSE) {
             filter_store_filter(self::FILTER_MY_LEDCOIN_TABLE, $post_filter);
         }
         redirect('ledcoin/my_ledcoin');
     }
     $filter = filter_get_filter(self::FILTER_MY_LEDCOIN_TABLE, array('page' => 1));
     $operations_addition = new Operation();
     $operations_addition->where('type', Operation::TYPE_ADDITION);
     $operations_addition->select_sum('amount', 'amount_sum');
     $operations_addition->where_related_person('id', '${parent}.id');
     $operations_mining = new Operation();
     $operations_mining->where('type', Operation::TYPE_ADDITION);
     $operations_mining->where('addition_type', Operation::ADDITION_TYPE_MINING);
     $operations_mining->select_sum('amount', 'amount_sum');
     $operations_mining->where_related_person('id', '${parent}.id');
     $operations_subtraction_direct = new Operation();
     $operations_subtraction_direct->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_direct->where('subtraction_type', Operation::SUBTRACTION_TYPE_DIRECT);
     $operations_subtraction_direct->select_sum('amount', 'amount_sum');
     $operations_subtraction_direct->where_related_person('id', '${parent}.id');
     $operations_subtraction_products = new Operation();
     $operations_subtraction_products->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_products->where('subtraction_type', Operation::SUBTRACTION_TYPE_PRODUCTS);
     $operations_subtraction_products->where_related('product_quantity', 'price >', 0);
     $operations_subtraction_products->group_start(' NOT', 'AND');
     $operations_subtraction_products->where_related('product_quantity', 'product_id', NULL);
     $operations_subtraction_products->group_end();
     unset($operations_subtraction_products->db->ar_select[0]);
     $operations_subtraction_products->select_func('SUM', array('@product_quantities.quantity', '*', '@product_quantities.price', '*', '@product_quantities.multiplier'), 'amount_sum');
     $operations_subtraction_products->where_related_person('id', '${parent}.id');
     $operations_subtraction_services = new Operation();
     $operations_subtraction_services->where('type', Operation::TYPE_SUBTRACTION);
     $operations_subtraction_services->where('subtraction_type', Operation::SUBTRACTION_TYPE_SERVICES);
     $operations_subtraction_services->where_related('service_usage', 'price >', 0);
     $operations_subtraction_services->group_start(' NOT', 'AND');
     $operations_subtraction_services->where_related('service_usage', 'service_id', NULL);
     $operations_subtraction_services->group_end();
     unset($operations_subtraction_services->db->ar_select[0]);
     $operations_subtraction_services->select_func('SUM', array('@service_usages.quantity', '*', '@service_usages.price', '*', '@service_usages.multiplier'), 'amount_sum');
     $operations_subtraction_services->where_related_person('id', '${parent}.id');
     $person = new Person();
     $person->where('admin', 0);
     $person->select('*');
     $person->select_subquery($operations_addition, 'plus_amount');
     $person->select_subquery($operations_mining, 'plus_mined');
     $person->select_subquery($operations_subtraction_direct, 'minus_amount_direct');
     $person->select_subquery($operations_subtraction_products, 'minus_amount_products');
     $person->select_subquery($operations_subtraction_services, 'minus_amount_services');
     $person->include_related('group', 'title');
     $person->get_by_id(auth_get_id());
     if (!$person->exists()) {
         add_error_flash_message('Nenašla sa informácia o prihlásenom používateľovi. Nemôžete si pozrieť svoj LEDCOIN.');
         redirect(site_url('ledcoin'));
     }
     $operations = new Operation();
     $operations->select('id, created, amount, type, subtraction_type, addition_type, comment');
     $operations->include_related('admin', array('name', 'surname'));
     $operations->include_related('workplace', 'title');
     $operations->where_related_person($person);
     $operations->order_by('created', 'asc');
     $operations->get_paged_iterated($filter['page'], self::MY_LEDCOIN_TABLE_ROWS_PER_PAGE);
     $this->parser->parse('web/controllers/ledcoin/my_ledcoin.tpl', array('title' => 'Môj LEDCOIN', 'operations' => $operations, 'person' => $person, 'form' => $this->get_my_ledcoin_filter_form($filter, $operations->paged)));
 }
Esempio n. 2
0
 public function transactions($person_id = NULL, $page_size = 20, $page = 1)
 {
     if (is_null($person_id)) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('operations'));
     }
     $person = new Person();
     $person->where('admin', 0);
     $person->get_by_id((int) $person_id);
     if (!$person->exists()) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('operations'));
     }
     $operations = new Operation();
     $operations->where_related_person($person);
     $operations->include_related('admin', array('name', 'surname'));
     $operations->include_related('workplace', 'title');
     $operations->order_by('created', 'desc');
     $operations->get_paged_iterated($page, $page_size);
     $this->parser->parse('web/controllers/operations/transactions.tpl', array('person' => $person, 'operations' => $operations, 'title' => 'Administrácia / LEDCOIN / Prehľad transakcií / ' . $person->name . ' ' . $person->surname, 'back_url' => site_url('operations'), 'form' => $this->get_transaction_pagination_form($operations->paged)));
 }