示例#1
0
 public static function roi_with_timeline($isin, $username, $month_from, $month_to)
 {
     $conn = Db::get_connection();
     $stock = new Stock();
     if (!$stock->find_by_id($isin)) {
         return;
     }
     $portfolio_stock_factory = new PortfolioStock();
     $portfolio_stocks = $portfolio_stock_factory->find_all(array('where_clause' => "`isin` = '{$conn->escape($isin)}' " . "AND `utente` = '{$conn->escape($username)}'"));
     if (count($portfolio_stocks) == 0) {
         return;
     }
     $portfolio_stock = $portfolio_stocks[0];
     $quantita = self::quantita_history($isin, $username, $month_from);
     switch ($stock->tipo) {
         case 'obbligazione':
             $investito = $portfolio_stock->prezzo * $portfolio_stock->quantita / 100;
             break;
         default:
             $investito = $portfolio_stock->prezzo * $portfolio_stock->quantita;
     }
     $investito = Change::convert($investito, $stock->divisa);
     $roi = PianificatoreHelper::roi_with_timeline($isin, $quantita, $month_from, $month_to, $investito);
     foreach ($roi->payments as $payment) {
         $payment->portfolio_stock = $portfolio_stock;
     }
     // print_r($roi);
     return $roi;
 }
示例#2
0
 public function refund($id)
 {
     $compra = new Compra();
     $usuario = new Usuario();
     $stock = new Stock();
     $info = $this->joinCompra($id);
     /**
      * @internal Resto de la compra
      * @param num
      * @param user
      * @param id
      */
     $newTotal = $info->total - $info->pagado;
     try {
         $compra->setTotal($newTotal, $info->user, $info->compra);
         $usuario->sumarCredito($info->pagado, $info->user);
         $stock->sumStock($info->talle, $info->color, $info->cantidad, $info->producto);
         $this->delete($id);
         if ($compra->isEmpty($info->compra)) {
             $compra->delete($info->compra);
         }
         header('location: ' . $_SESSION['last_page']);
     } catch (PDOException $e) {
         echo $e->getMessage();
     }
 }
 /**
  * Creates a new Stock model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Stock();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#4
0
 public static function removeStock($item, $location, $quantity, $date)
 {
     $stock = new Stock();
     $stock->date = $date;
     $stock->item()->associate($item);
     $stock->location()->associate($location);
     $stock->quantity_out = $quantity;
     $stock->save();
 }
示例#5
0
 function _titoli($mercato)
 {
     $conn = $this->get_connection();
     $stock_factory = new Stock();
     $stocks = $stock_factory->find_all(array('where_clause' => "`attivo` = 1 " . ($mercato !== NULL ? " AND `mercato` = '{$conn->escape($mercato)}' " : ''), 'order_by' => '`title` ASC ', 'limit' => 99999999));
     if (count($stocks) > 0) {
         $this->stocks = array_map(function ($t) {
             return "\t{\n\t\t\"isin\": \"" . $t->isin . "\",\n\t\t\"title\": \"" . $t->title . "\"\n\t}";
         }, $stocks);
     }
     $this->render(array('action' => 'titoli', 'layout' => FALSE));
 }
示例#6
0
function update_all_daily_data()
{
    $status = '';
    $query = mysql_query("SELECT * FROM stocks");
    while ($array = mysql_fetch_array($query)) {
        $stock = new Stock($array);
        if (update_stock_daily($stock->getTicker())) {
            $status .= 'Successfully Updated all stock info for ' . $stock->getTicker() . '<br />';
        } else {
            $status .= 'Failed to update stock ' . $stock->getTicker() . '<br />';
        }
    }
    return $status;
}
示例#7
0
 /**
  *  @fn preferiti
  *  @short Lists favorite instruments
  *  @details Action to list favorite instruments for the current user,
  *  filtered by attributes like market, type, currency, and sorted by any of
  *  the columns (defaults to <code>title</code>).
  */
 public function preferiti()
 {
     $conn = $this->get_connection();
     $stock_factory = new Stock();
     $query = 'SELECT * FROM `creso_titoli` LEFT JOIN `creso_preferiti` ON `creso_titoli`.`isin` = `creso_preferiti`.`isin` ' . "WHERE " . (is_numeric($_REQUEST['attivo']) ? "`attivo` = {$conn->escape($_REQUEST['attivo'])} " : '`attivo` = 1 ') . "AND `utente` = '{$conn->escape($_COOKIE['username'])}' " . (!empty($_REQUEST['mercato']) ? "AND `mercato` = '{$conn->escape($_REQUEST['mercato'])}' " : '') . (!empty($_REQUEST['tipo']) ? "AND `tipo` = '{$conn->escape($_REQUEST['tipo'])}' " : '') . (!empty($_REQUEST['divisa']) ? "AND `divisa` = '{$conn->escape($_REQUEST['divisa'])}' " : '') . "ORDER BY `{$conn->escape($this->get_sort('title'))}` {$conn->escape($this->get_dir())} " . "LIMIT {$conn->escape($this->get_start())}, {$conn->escape($this->get_limit())}";
     $this->stocks = $stock_factory->find_by_query($query);
     $query = 'SELECT COUNT(*) FROM `creso_titoli` LEFT JOIN `creso_preferiti` ON `creso_titoli`.`isin` = `creso_preferiti`.`isin` ' . "WHERE " . (is_numeric($_REQUEST['attivo']) ? "`attivo` = {$conn->escape($_REQUEST['attivo'])} " : '`attivo` = 1 ') . "AND `utente` = '{$conn->escape($_COOKIE['username'])}' " . (!empty($_REQUEST['mercato']) ? "AND `mercato` = '{$conn->escape($_REQUEST['mercato'])}' " : '') . (!empty($_REQUEST['tipo']) ? "AND `tipo` = '{$conn->escape($_REQUEST['tipo'])}' " : '') . (!empty($_REQUEST['divisa']) ? "AND `divisa` = '{$conn->escape($_REQUEST['divisa'])}' " : '');
     $conn->prepare($query);
     $conn->exec();
     $this->count = $conn->fetch_array()[0];
     $conn->free_result();
     $this->is_favorite = TRUE;
     $this->render(array('action' => 'index'));
 }
示例#8
0
 function add()
 {
     if ($this->request->is_post()) {
         $item = new Dividend($_POST);
         $item->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         $stock_factory = new Stock();
         $stocks = $stock_factory->find_all(array('where_clause' => '`attivo` = 1', 'order_by' => '`title` ASC'));
         $this->stocks = array('-1' => 'Scegli...');
         foreach ($stocks as $stock) {
             $this->stocks[$stock->isin] = $stock->title;
         }
     }
 }
示例#9
0
 public static function refunds($isin, $month_from, $month_to)
 {
     $payments = array();
     $conn = Db::get_connection();
     $stock = new Stock();
     if (!$stock->find_by_id($isin)) {
         return;
     }
     switch ($stock->tipo) {
         case 'azione':
             break;
         case 'obbligazione':
             $bond_factory = new Bond();
             $bonds = $bond_factory->find_all(array('where_clause' => "`isin` = '{$conn->escape($isin)}' " . "AND `scadenza` >= '{$conn->escape($month_from)}' " . "AND `scadenza` <= '{$conn->escape($month_to)}' "));
             if (count($bonds) > 0) {
                 $bond = $bonds[0];
                 $payment = new Payment();
                 $payment->stock = $stock;
                 $payment->bond = $bond;
                 $payment->timestamp = strtotime($bond->scadenza);
                 $payment->importo = $payment->bond->prezzo_rimborso;
                 $payment->tipo = 'rimborso';
                 $payments[] = $payment;
             }
             break;
     }
     return $payments;
 }
示例#10
0
 function add()
 {
     if ($this->request->is_post()) {
         $transaction = new Transaction($_POST);
         // Salvo la transazione
         $transaction->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         $stock_factory = new Stock();
         $stocks = $stock_factory->find_all(array('where_clause' => "`attivo` = 1 ", 'order_by' => '`title` ASC', 'limit' => 9999));
         $this->stocks = array('' => 'Scegli...');
         foreach ($stocks as $stock) {
             $this->stocks[$stock->isin] = $stock->title;
         }
     }
 }
 public function run($context)
 {
     $stock_factory = new Stock();
     $stocks = $stock_factory->find_by_query('SELECT * FROM `creso_titoli` ' . 'LEFT JOIN `creso_obbligazioni` ON `creso_titoli`.`isin` = `creso_obbligazioni`.`isin` ' . 'WHERE ' . "`creso_titoli`.`tipo` = 'obbligazione' " . 'AND ' . "`creso_obbligazioni`.`emissione` = '0000-00-00' " . 'AND ' . '`creso_titoli`.`attivo` = 1 ' . 'LIMIT 1500');
     $updated_count = 0;
     foreach ($stocks as $stock) {
         $bond = new Bond();
         $bond->find_by_id($stock->isin);
         $bond->emissione = isin2emissione_ariva($stock->isin);
         if ($bond->emissione != '0000-00-00') {
             $bond->save();
             $updated_count++;
         }
     }
     printf("%s updated %d bonds\n", get_called_class(), $updated_count);
 }
示例#12
0
 public static function inventory()
 {
     return function ($request, $response) {
         if ($request->session('admin')) {
             try {
                 $response->header('Content-Type', 'application/pdf');
                 $stocks_report = Zend_Pdf::load('../pdf/inv.pdf');
                 $page = $stocks_report->pages[0];
                 $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER);
                 $page->setFont($font, 10);
                 $page->drawText(Time::unixToDate(time()), 290, 818);
                 $row = 765;
                 $stocks = Stock::all();
                 foreach ($stocks as $stock) {
                     $page->drawText(sprintf("%10.39s", $stock->product->name), 32, $row);
                     $page->drawText($stock->product->description, 280, $row);
                     $page->drawText(sprintf("%4u", $stock->quantity), 550, $row);
                     $row -= 15;
                 }
                 $page->drawText("Prepared by:", 300, 80);
                 $page->drawText("________________________________", 300, 50);
                 echo $stocks_report->render();
             } catch (Exception $e) {
                 $response->header('Content-Type', 'text/plain');
                 echo $e->getMessage();
             }
         } else {
             $response->code(403);
         }
     };
 }
 public function test_aroundLockProductsStock_process()
 {
     /** === Test Data === */
     $PROD_IDS = [[]];
     $STOCK_ID = 1;
     $TAB_STOCK = 'table 01';
     $TAB_PROD = 'table 02';
     $RESULT = 'result';
     /** === Setup Mocks === */
     $mProceed = function () {
     };
     // $conn = $subject->getConnection();
     $mConn = $this->_mockConn();
     $this->mSubject->shouldReceive('getConnection')->once()->andReturn($mConn);
     // $itemTable = $subject->getTable('cataloginventory_stock_item');
     $this->mSubject->shouldReceive('getTable')->once()->with('cataloginventory_stock_item')->andReturn($TAB_STOCK);
     // $productTable = $subject->getTable('catalog_product_entity');
     $this->mSubject->shouldReceive('getTable')->once()->with('catalog_product_entity')->andReturn($TAB_PROD);
     // $select = $conn->select();
     $mSelect = $this->_mockDbSelect(['from', 'join', 'where', 'forUpdate']);
     $mConn->shouldReceive('select')->once()->andReturn($mSelect);
     // $result = $conn->fetchAll($select);
     $mConn->shouldReceive('fetchAll')->once()->andReturn($RESULT);
     /** === Call and asserts  === */
     $res = $this->obj->aroundLockProductsStock($this->mSubject, $mProceed, $PROD_IDS, $STOCK_ID);
     $this->assertEquals($RESULT, $res);
 }
示例#14
0
 public function __construct()
 {
     parent::__construct();
     $this->load->model('stock_model');
     $this->load->model('product_model');
     $this->load->library('form_validation');
 }
示例#15
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Stock::create([]);
     }
 }
示例#16
0
 public function run()
 {
     $object = [["ID_PRODUCTO" => "10", "CANTIDAD" => "101", "ID_BODEGA" => "1"], ["ID_PRODUCTO" => "20", "CANTIDAD" => "10", "ID_BODEGA" => "1"], ["ID_PRODUCTO" => "1", "CANTIDAD" => "55", "ID_BODEGA" => "1"]];
     DB::unprepared('ALTER TABLE ' . $this->table . ' AUTO_INCREMENT = 1');
     foreach ($object as $detail) {
         Stock::create($detail);
     }
 }
 public function run($context)
 {
     $stock_count = 0;
     foreach (self::$URLS as $url) {
         $handle = fopen($url, 'r');
         if ($handle) {
             $i = 0;
             while (($buffer = fgets($handle, 4096)) !== false) {
                 if ($i++ == 0) {
                     // Skip header
                     // ISIN;Tipologia;Emittente;Descrizione;"Data di scadenza";"Valuta di negoziazione";S&P;"Q.tà Acquisto";"Prezzo Acquisto";"Prezzo Vendita";"Q.tà Vendita";"Prezzo ultimo contratto";"Rendimento effettivo a scadenza lordo";Sospeso
                     continue;
                 }
                 $details = explode(';', $buffer);
                 // print_r($details);
                 $stock = new Stock();
                 if (!$stock->find_by_id($details[0])) {
                     echo 'New stock';
                     $stock->isin = $details[0];
                     $stock->tipo = 'obbligazione';
                     $stock->title = $this->unwrap($details[3]);
                     $stock->divisa = $details[5];
                     $stock->rating = $this->unwrap($details[6]);
                     $stock->mercato = 'eurotlx';
                     $stock->_force_create = TRUE;
                     print_r($stock);
                     $stock->save();
                     $stock_count++;
                 } else {
                     if ($stock->mercato == 'ita') {
                         echo "Updating mercato for {$stock->isin}";
                         $stock->mercato = 'eurotlx';
                         $stock->save();
                         $stock_count++;
                     }
                 }
             }
             if (!feof($handle)) {
                 echo "Error: unexpected fgets() fail\n";
             }
             fclose($handle);
         }
     }
     printf("%s updated %d stocks\n", get_called_class(), $stock_count);
 }
示例#18
0
 public function __construct()
 {
     parent::__construct();
     $this->load->model('stock_model');
     $this->load->model('product_model');
     $this->load->model('product_shelf_code_model');
     $this->load->library('excel');
     $this->load->helper('product_permission');
 }
示例#19
0
文件: stock.php 项目: Niqpue/zippyerp
 /**
  * Возвращает запись  со  склада по  цене (партии  для  оптового)  товара.
  *
  * @param mixed $store_id  Склад
  * @param mixed $tovar_id  Товар
  * @param mixed $price     Цена
  * @param mixed $create    Создать  если  не   существует
  */
 public static function getStock($store_id, $item_id, $price, $create = false)
 {
     $stock = self::findOne("store_id = {$store_id} and item_id = {$item_id} and price = {$price} ");
     if ($stock == null && $create == true) {
         $stock = new Stock();
         $stock->store_id = $store_id;
         $stock->item_id = $item_id;
         $stock->price = $price;
         $stock->partion = $price;
         $stock->Save();
     }
     if ($stock->closed == 1) {
         $stock->closed == 0;
         $stock->Save();
         //enable partion
     }
     return $stock;
 }
示例#20
0
 function search()
 {
     $qtData = FileCache::get($this->keyword);
     if (!$qtData) {
         $url = $this->queryUrl . urlencode($this->keyword);
         $request_result = $this->request($url);
         $json = json_decode($request_result);
         $qtData = $json->data;
     }
     if (count($qtData) > 0) {
         FileCache::set($this->keyword, $qtData);
         foreach ($qtData as $key => $value) {
             $stock = new Stock($value);
             $this->result($key, $stock->getLink(), $stock->getTitle(), $stock->getSubTitle(), null);
         }
     } else {
         $this->lastPlaceholder();
     }
 }
示例#21
0
 public function create($data)
 {
     $currentUser = parent::authenticateUser();
     $stock = new Stock();
     if (isset($data->total) && isset($data->date)) {
         $stock->setDate($data->date);
         $stock->setTotal($data->total);
         $stock->setOwner($currentUser->getLogin());
         try {
             $idStock = $this->stockDAO->save($stock);
             header($this->server->getServerProtocol() . ' 201 Created');
             header('Location: ' . $this->server->getRequestUri() . "/" . $idStock);
             header('Content-Type: application/json');
         } catch (ValidationException $e) {
             header($this->server->getServerProtocol() . ' 400 Bad request');
             echo json_encode($e->getErrors());
         }
     }
 }
示例#22
0
 public static function timeline($isin, $quantita, $month_from, $month_to)
 {
     $payments = array();
     $conn = Db::get_connection();
     $stock = new Stock();
     if (!$stock->find_by_id($isin)) {
         return;
     }
     $yields = PaymentsHelper::yields($isin, $month_from, $month_to);
     $refunds = PaymentsHelper::refunds($isin, $month_from, $month_to);
     $events = array_merge($yields, $refunds);
     $payments = array();
     foreach ($events as $event) {
         if (is_array($quantita)) {
             // reset() rewinds array's internal pointer to the first element and returns the value of the first array element, or FALSE if the array is empty.
             $q = reset($quantita);
             foreach ($quantita as $date => $value) {
                 if (strtotime($date) < $event->timestamp) {
                     break;
                 }
                 $q = $value;
             }
         } else {
             $q = $quantita;
         }
         if ($event->tipo == 'rimborso') {
             switch ($event->stock->tipo) {
                 case 'obbligazione':
                     $event->importo *= $q / 100;
                     break;
                 default:
                     $event->importo *= $q;
             }
         } else {
             $event->importo *= $q;
         }
         $event->quantita = $q;
         $payments[] = $event;
     }
     // print_r($payments);
     Db::close_connection($conn);
     return $payments;
 }
示例#23
0
 function search()
 {
     $cacheData = FileCache::get('__cache__' . $this->keyword);
     if (!$cacheData) {
         $url = $this->queryUrl . urlencode($this->keyword);
         $request_result = $this->request($url);
         $json = json_decode($request_result);
         $searchData = $json->data;
         if (count($searchData) > 0) {
             FileCache::set('__cache__' . $this->keyword, $searchData, 24 * 60 * 60);
         }
     } else {
         $searchData = $cacheData;
     }
     if (count($searchData) > 0) {
         $codeArray = array();
         foreach ($searchData as $value) {
             $d = explode('~', $value);
             if (preg_match('/(\\..*)$/', $d[1], $re)) {
                 $d[1] = str_replace($re[1], "", $d[1]);
             }
             if ($d[0] == 'us') {
                 $d[1] = strtoupper($d[1]);
             }
             $dCode = $d[0] . $d[1];
             if ($d[0] == 'hk') {
                 $dCode = 'r_' . $dCode;
             }
             if ($d[0] == 'jj') {
                 $dCode = 's_' . $dCode;
             }
             array_push($codeArray, $dCode);
         }
         $qt = new StockQt();
         $qt->fetchQt(implode(',', $codeArray));
         foreach ($searchData as $key => $value) {
             $stock = new Stock($value, $qt);
             $this->result($key, $stock->getLink(), $stock->getTitle(), $stock->getSubTitle(), null);
         }
     } else {
         $this->lastPlaceholder();
     }
 }
示例#24
0
 function get_row_class()
 {
     $classes = array(Stock::row_class());
     if ($this->removed) {
         $classes[] = 'row-removed';
     }
     if ($this->changed) {
         $classes[] = 'row-changed';
     }
     return implode(' ', $classes);
 }
示例#25
0
 private function saveInStockTable($idBranch, $idArticle, $amount)
 {
     try {
         $articleStock = Stock::where('article_id', $idArticle)->where('branch_id', $idBranch)->first();
         if (!empty($articleStock)) {
             $articleStock->stock += $amount;
             $articleStock->save();
         } else {
             $stockTable = new Stock();
             $stockTable->branch_id = $idBranch;
             $stockTable->article_id = $idArticle;
             $stockTable->stock = $amount;
             $stockTable->minstock = 0;
             $stockTable->save();
         }
         #if !empty($ArticleStock)
     } catch (Exception $e) {
         die('No se pudo modificar el stock del artículo' . $idArticle . ' en la sucursal ' . $idBranch);
     }
 }
示例#26
0
 public function __construct()
 {
     parent::__construct();
     $this->load->model('abroad_stock_model');
     $this->load->model('product_model');
     $this->load->library('form_validation');
     $this->load->library('chukouyi/CKY_Product');
     $this->load->library('chukouyi/CKY_Order');
     $this->load->helper('validation_helper');
     $this->load->helper('solr_helper');
 }
示例#27
0
 public function __construct()
 {
     parent::__construct();
     $this->load->model('stock_model');
     $this->load->model('product_model');
     $this->load->model('ebay_model');
     $this->load->model('order_model');
     $this->load->model('paypal_model');
     $this->load->model('user_model');
     $this->config->load('config_ebay');
 }
示例#28
0
 public function __construct()
 {
     parent::__construct();
     $this->load->model('abroad_stock_model');
     $this->load->model('product_model');
     $this->load->model('order_model');
     $this->load->model('sale_model');
     $this->load->model('product_makeup_sku_model');
     $this->load->model('shipping_code_model');
     $this->load->library('form_validation');
     $this->load->helper('validation_helper');
 }
 public function actionStock()
 {
     $criteria = new CDbCriteria();
     $criteria->order = "id DESC";
     $count = Stock::model()->count($criteria);
     $pages = new CPagination($count);
     // элементов на страницу
     $pages->pageSize = 20;
     $pages->applyLimit($criteria);
     $stock = Stock::model()->findAll($criteria);
     $this->render('stock', array('stock' => $stock, 'pages' => $pages));
 }
示例#30
0
 function add()
 {
     if ($this->request->is_post()) {
         $item = new WatchlistItem($_POST);
         $item->utente = $_COOKIE['username'];
         $item->save();
         $this->redirect_to(array('action' => 'index'));
     } else {
         if (!empty($_GET['id'])) {
             $this->stock = new Stock();
             $this->stock->find_by_id($_GET['id']);
             $this->render(array('action' => 'add_by_isin'));
         } else {
             $stock_factory = new Stock();
             $stocks = $stock_factory->find_all(array('where_clause' => '`attivo` = 1', 'order_by' => '`title` ASC'));
             $this->stocks = array('-1' => 'Scegli...');
             foreach ($stocks as $stock) {
                 $this->stocks[$stock->isin] = $stock->title;
             }
         }
     }
 }