Ejemplo n.º 1
0
 public static function quantita_history($isin, $username, $month_from)
 {
     $conn = Db::get_connection();
     $transaction_factory = new Transaction();
     $transactions = $transaction_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($username)}' " . "AND `isin` = '{$conn->escape($isin)}' " . "AND `data` >= '{$conn->escape($month_from)}' ", 'order_by' => '`data` DESC'));
     // print_r($transactions);
     $portfolio_stock_factory = new PortfolioStock();
     $portfolio_stock = $portfolio_stock_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($username)}' " . "AND `isin` = '{$conn->escape($isin)}' "))[0];
     // print_r($portfolio_stock);
     $quantita_history = array();
     $quantita_history[date('Y-m-d')] = $q = $portfolio_stock->quantita;
     $i = 0;
     do {
         if ($transactions[$i]->azione == 'acquisto') {
             $q -= $transactions[$i]->quantita;
         } else {
             $q += $transactions[$i]->quantita;
         }
         $quantita_history[$transactions[$i]->data] = $q;
         $i++;
     } while ($transactions[$i]->data > $_REQUEST['month-from']);
     // print_r($quantita_history);
     Db::close_connection($conn);
     return $quantita_history;
 }
Ejemplo n.º 2
0
 function by_date()
 {
     $conn = $this->get_connection();
     $this->totale = 0;
     $this->bilancio = 0;
     $transaction_factory = new Transaction();
     $this->transactions = $transaction_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($_COOKIE['username'])}' " . "AND `data` = '{$conn->escape($_GET['id'])}' ", 'order_by' => sprintf('`%s` %s', $this->get_sort('data'), $this->get_dir(TRUE)), 'limit' => $this->get_limit()));
     foreach ($this->transactions as $transaction) {
         $transaction->stock = new Stock();
         $transaction->stock->find_by_id($transaction->isin);
     }
     $this->render(array('action' => 'index'));
 }
Ejemplo n.º 3
0
 private function backfill_with_historical_data($portfolio_stock)
 {
     $conn = $this->get_connection();
     $transaction_factory = new Transaction();
     $transactions = $transaction_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($_COOKIE['username'])}' " . "AND `isin` = '{$conn->escape($portfolio_stock->isin)}' " . "AND `data` >= '{$conn->escape($_REQUEST['month-from'])}' ", 'order_by' => '`data` DESC'));
     $quantita_history = array();
     $quantita_history[date('Y-m-d')] = $q = $portfolio_stock->quantita;
     $i = 0;
     do {
         if ($transactions[$i]->azione == 'acquisto') {
             $q -= $transactions[$i]->quantita;
         } else {
             $q += $transactions[$i]->quantita;
         }
         $quantita_history[$transactions[$i]->data] = $q;
         $i++;
     } while ($transactions[$i]->data > $_REQUEST['month-from']);
     return $quantita_history;
 }
Ejemplo n.º 4
0
 private function get_stock_deltas($date)
 {
     $conn = $this->get_connection();
     $transaction_factory = new Transaction();
     $transactions = $transaction_factory->find_all(array('where_clause' => "`data` >= '{$conn->escape($date)}'" . "AND `utente` = '{$conn->escape($_COOKIE['username'])}'", 'limit' => 9999999));
     // print_r($transactions);
     $deltas = array();
     foreach ($transactions as $transaction) {
         $sign = $transaction->azione == 'acquisto' ? -1 : +1;
         $current = isset($deltas[$transaction->isin]) ? $deltas[$transaction->isin] : 0;
         $deltas[$transaction->isin] = $current + $sign * $transaction->quantita;
     }
     // print_r($deltas);
     foreach ($deltas as $isin => $value) {
         if ($value == 0) {
             unset($deltas[$isin]);
         }
     }
     // print_r($deltas);
     return $deltas;
 }