public function index()
 {
     $this->load->view('layout/header');
     $error = $this->session->flashdata('message');
     $this->load->view('element/message', ['success' => $error]);
     $filter = $this->input->get(['from', 'till', 'groups']);
     $from = $filter['from'] ?: date('Y-m-01', strtotime('-1 month'));
     $till = $filter['till'] ?: date('Y-m-t');
     $responseData = [];
     $step = 500;
     $offset = 0;
     do {
         $response = $this->moneyzaurus->transactionsList($offset, $step, $from, $till, null, null, null);
         if ($response['code'] == 200 && $response['data']['success']) {
             $count = $response['data']['count'];
             $responseData = array_merge($responseData, $response['data']['data']);
             $offset += $step;
         } else {
             break;
         }
     } while ($count >= $step);
     $filterGroups = $filter['groups'] ?: [];
     $data = $this->prepareChartData($responseData, $filterGroups, $from, $till);
     $this->load->view('page/chart', ['data' => $data, 'from' => $from, 'till' => $till]);
     $this->load->view('layout/footer');
 }
 public function predictPrice()
 {
     $item = $this->input->get('item');
     $group = $this->input->get('group');
     $response = $this->moneyzaurus->predictPrice($item, $group);
     $this->processResponseData($response);
 }
 public function logout()
 {
     $response = $this->moneyzaurus->authenticateLogout();
     if ($response['code'] == 200) {
         if ($response['data']['success']) {
             $this->session->set_flashdata('success', 'Bye!');
         }
     }
     redirect('');
 }
 public function index()
 {
     $this->load->view('layout/header');
     $error = $this->session->flashdata('message');
     $this->load->view('element/message', ['success' => $error]);
     $offset = 0;
     $limit = 100;
     $filter = $this->input->get(['item', 'group', 'price', 'from', 'till']);
     $response = $this->moneyzaurus->transactionsList($offset, $limit, $filter['from'], $filter['till'], $filter['item'], $filter['group'], $filter['price'] * 100);
     if ($response['code'] == 200) {
         if ($response['data']['success']) {
             $this->load->view('page/data', ['count' => $response['data']['count'], 'data' => $response['data']['data'], 'filter' => $filter]);
         }
     }
     $this->load->view('layout/footer');
 }
 private function getAllTransactions($months)
 {
     $filter = $this->input->get(['from', 'till', 'groups']);
     $from = $filter['from'] ?: date('Y-m-01', strtotime('-' . (int) $months . ' month'));
     $till = $filter['till'] ?: date('Y-m-t');
     $responseData = [];
     $step = 500;
     $offset = 0;
     do {
         $response = $this->moneyzaurus->transactionsList($offset, $step, $from, $till, null, null, null);
         if ($response['code'] == 200 && $response['data']['success']) {
             $count = $response['data']['count'];
             $responseData = array_merge($responseData, $response['data']['data']);
             $offset += $step;
         } else {
             break;
         }
     } while ($count >= $step);
     return $responseData;
 }
 public function index()
 {
     $this->load->view('layout/header');
     $token = $this->user->findToken();
     if (!empty($token)) {
         $this->moneyzaurus->setToken($token);
         $data = $this->moneyzaurus->userData();
         if ($data['code'] == 200) {
             if (!empty($data['data']['data']['id'])) {
                 $this->load->helper('url');
                 redirect('/transaction');
             }
         }
     }
     $error = $this->session->flashdata('message');
     $success = $this->session->flashdata('success');
     $this->load->view('element/message', ['errors' => $error, 'success' => $success]);
     $this->load->view('page/welcome');
     $this->load->view('layout/footer');
 }
 public function delete()
 {
     $id = $this->input->get('id');
     $response = $this->moneyzaurus->transactionsRemove($id);
     if ($response['code'] == 200) {
         if (!$response['data']['success']) {
             $this->session->set_flashdata('message', $response['data']['message']);
         } else {
             $this->session->set_flashdata('message', 'Deleted');
         }
     }
     redirect('/data');
 }
 public function declineConnection()
 {
     $id = $this->input->post('id');
     $response = $this->moneyzaurus->connectionReject($id);
     if ($response['code'] == 200) {
         if (!$response['data']['success']) {
             $this->session->set_flashdata('message', $response['data']['message']);
         } else {
             $this->session->set_flashdata('message', 'Connection rejected');
         }
     }
     redirect('/profile');
 }