예제 #1
0
파일: Stock.class.php 프로젝트: ciplpj/vsm
 public function buy($sh_id, $qty = 0)
 {
     global $session;
     $database = new Database();
     $sh_id = $database->escape_value($sh_id);
     $qty = (int) $qty;
     if ($this->found) {
         $StockCompany = new StockCompany($this->sc_id);
         /*
         Check if the user has enough money to buy the stocks
         */
         $holder = new StockHolder($sh_id);
         if ($holder->found) {
             $stock_cur_price = Stock::getCurPrice($this->sc_id);
             if ($holder->cur_amt > $stock_cur_price * $qty) {
                 if ($StockCompany->leftStocks() > $qty) {
                     $holder_stocks = new HolderStocks($sh_id);
                     //this adds the stock to holder list and also creates a transaction for it
                     $success = $holder_stocks->addStock($this->sc_id, $qty, $stock_cur_price);
                     //Updates the amount of money holder has
                     $success = $holder->amtUpdate($holder->cur_amt - $stock_cur_price * $qty);
                     return true;
                 } else {
                     $session->message("Stocks of {$StockCompany->c_name} are unavailable in the marketplace");
                     return false;
                 }
             } else {
                 $session->message('You Don\'t have enough money to buy ' . $qty . ' stocks of ' . $StockCompany->c_name);
                 return false;
             }
         }
     } else {
         //check this!
         $session->message('Stock Unavailable');
         return false;
     }
 }
예제 #2
0
파일: company.php 프로젝트: ciplpj/vsm
?>
</strong></p>
					 <p style="font-family:sans-serif;font-size:2em;margin-top:0.8em;"> 
						Company Information: <strong><?php 
echo $company->getInfo();
?>
</strong></p>
					<p style="font-family:sans-serif;font-size:2em;margin-top:0.8em;"> 
					 Day's Opening : <strong><?php 
echo $company->day_open;
?>
</strong></p>
					<p style="font-family:sans-serif;font-size:2em;margin-top:0.8em;"> 
					 Total Company's Bought Stocks : <strong>
							<?php 
$company->leftStocks();
echo $company->bought_stocks;
?>
							</strong>
					</p>
					<p style="font-family:sans-serif;font-size:2em;margin-top:0.8em;">
					 Present Stock Value : <i class="icon-arrow-<?php 
echo $direction . ' i' . $color;
?>
 fr inc_size" style="float:none;">
					 <strong><?php 
echo $cur_val;
?>
</i></strong></p>
				</div>