/** * O método precisa informar uma lista de produtos * @return {view} */ public function create() { $stocks = Stock::all(); $customers = Customer::all(); $employees = Employee::all(); return view('pages.new_sale', ['stocks' => $stocks, 'customers' => $customers, 'employees' => $employees]); }
/** * Execute the console command. * * @return mixed */ public function handle() { if ($this->confirm('This process may take several hours, do you wish to continue? [y|N]')) { $uniqueStockCodes = Stock::all()->lists('stock_code'); $numberOfStocks = count($uniqueStockCodes); foreach ($uniqueStockCodes as $stockKey => $stockCode) { $this->info("Processing Stock Code: " . $stockCode . " " . round(($stockKey + 1) * (100 / $numberOfStocks), 2) . "%"); if (!FillHistoricalMovingAveragesCommand::alreadyFilled($stockCode)) { foreach ([50, 200] as $timeFrame) { $historicalDates = Historicals::where('stock_code', $stockCode)->orderBy('date', 'desc')->lists('date'); $numberOfDates = count($historicalDates); foreach ($historicalDates as $dateKey => $date) { $recordsInTimeFrame = Historicals::where('stock_code', $stockCode)->orderBy('date', 'desc')->skip($dateKey)->take($timeFrame)->lists('close'); $averageOfRecordsInTimeFrame = $recordsInTimeFrame->sum() / $recordsInTimeFrame->count(); if ($timeFrame == 50) { Historicals::where(['stock_code' => $stockCode, 'date' => $date])->update(['fifty_day_moving_average' => $averageOfRecordsInTimeFrame]); } elseif ($timeFrame == 200) { Historicals::where(['stock_code' => $stockCode, 'date' => $date])->update(['two_hundred_day_moving_average' => $averageOfRecordsInTimeFrame]); } $this->line(round(($stockKey + 1) * (100 / $numberOfStocks), 2) . "% | Stock: " . $stockCode . " | " . $timeFrame . " Day | Date: " . $date . " " . round(($dateKey + 1) * (100 / $numberOfDates), 2) . "%"); } } } else { $this->info($stockCode . " was already filled, skipping..."); } } } }
public function save(Request $request) { $products = $request->get('product_id'); $stock = Stock::create($request->all()); foreach ($products as $product) { StockProducts::create(['product_id' => $product, 'stock_id' => $stock->id]); } return view('pages.stocks', ['stocks' => Stock::all()]); }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info("This process can take several minutes..."); $this->info("Getting daily financials..."); $stockCodes = Stock::all()->lists('stock_code'); $numberOfStocks = count($stockCodes); $iterationNumber = 1; $maxIterations = ceil($numberOfStocks / 100); if ($this->option('testMode') == 'true') { $maxIterations = 1; $this->info("[Test Mode]"); } while ($iterationNumber <= $maxIterations) { $stockCodeParameter = GetDailyFinancialsCommand::getStockCodeParameter($this->option('testMode')); $financialsURL = "http://finance.yahoo.com/d/quotes.csv?s=" . $stockCodeParameter . "&f=sohgl1v"; $dailyRecords = explode("\n", file_get_contents($financialsURL)); foreach ($dailyRecords as $record) { if ($record != null) { $individualRecord = explode(',', $record); $stockCode = substr(explode('.', $individualRecord[0])[0], 1); if (isTradingDay()) { Historicals::updateOrCreate(['stock_code' => $stockCode, 'date' => date("Y-m-d")], ["stock_code" => $stockCode, "date" => date("Y-m-d"), "open" => $individualRecord[1], "high" => $individualRecord[2], "low" => $individualRecord[3], "close" => $individualRecord[4], "volume" => $individualRecord[5], "adj_close" => $individualRecord[4], "fifty_day_moving_average" => Historicals::getMovingAverage($stockCode, 50), "two_hundred_day_moving_average" => Historicals::getMovingAverage($stockCode, 200), "updated_at" => date("Y-m-d H:i:s")]); } } } $this->info("Updating... " . round($iterationNumber * (100 / $maxIterations), 2) . "%"); $iterationNumber++; } if (isTradingDay() && $this->option('testMode') != 'true') { $this->info("Removing existing stock_code index in historicals"); \DB::statement("DROP INDEX `stock_code` ON historicals"); $this->info("Reapplying index to historicals table"); \DB::statement("ALTER TABLE `historicals` ADD INDEX (`stock_code`)"); $this->info("Finished getting daily financials for " . $numberOfStocks . " stocks."); } }
public function index() { return view('pages.stocks', ['stocks' => Stock::all()]); }
/** * O método precisa informar uma lista de produtos * @return {view} */ public function create() { $stocks = Stock::all(); return view('pages.new_purchase', ['stocks' => $stocks]); }