/** * Renders the entity form for the given attributes. * * @return \Illuminate\View\View|null */ protected function renderForm($entity, $view = null) { $view = $view ?: 'sanatorium/shoppricing::widgets/form'; // @todo make dynamic $types = ['vat' => 'S daní', 'plain' => 'Bez daně']; $currencies = Currency::all(); $primary_currency = Currency::where('unit', 1)->first(); return view($view, compact('entity', 'types', 'currencies', 'primary_currency')); }
public function history(\Illuminate\Http\Request $request, $days = 30) { for ($i = 0; $i < $days; $i++) { $day = Carbon::now()->subDays($i); $service_provider = get_called_class(); $data = $service_provider::getSourceDataByDate($day->format('j.n.Y')); foreach ($data as $code => $course) { $currency = Currency::where('code', $code)->first(); if ($currency) { CurrenciesHistory::create(['currency_id' => $currency->id, 'rate' => $course['rate'], 'created_at' => $day->format('Y-m-d H:i:s')]); } } } if ($request->ajax()) { return ['success' => true]; } return redirect()->back()->withMessage(); }
public function getPriceObject($currency, $type = 'plain') { if (is_object($currency)) { $currency_id = $currency->id; } else { if (is_numeric($currency)) { $currency_id = $currency; } else { if (is_string($currency)) { $currency_id = Currency::where('code', $currency)->first()->id; } } } // Find price data $price = $this->price()->where('shop_money.type', $type)->where('shop_money.currency_id', $currency_id); if ($price->count() == 0) { return new Money(['type' => $type, 'currency_id' => $currency_id]); } return $price->first(); }
public function history($days = 30) { $histories = []; $day = 24 * 60 * 60; $now = Carbon::now()->timestamp; $start = $now - $days * $day; foreach (Currency::where('unit', '!=', '1')->get() as $currency) { $values = []; for ($i = 0; $i < $days; $i++) { $day_before = $start + $i * $day; $day_after = $start + ($i + 1) * $day; $history = CurrenciesHistory::where('currency_id', $currency->id)->where('created_at', '>', \Carbon\Carbon::createFromTimeStamp($day_before)->format('Y-m-d H:i:s'))->where('created_at', '<', \Carbon\Carbon::createFromTimeStamp($day_after)->format('Y-m-d H:i:s'))->first(); if ($history) { $values[] = [$day_before, $history->rate]; } else { $values[] = [$day_before, 1]; } } $histories[] = ['key' => $currency->name, 'values' => $values]; } return $histories; }