/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // $faker = Faker::create();
     DB::table('shop_currencies')->truncate();
     Currency::create(['name' => 'Czech koruna', 'code' => 'czk', 'unit' => 1, 'symbol' => ',-', 'format' => '0,0.00 Kč', 'short_format' => '0!0 Kč', 'locale' => 'cs']);
     Currency::create(['name' => 'Dollar', 'code' => 'usd', 'unit' => 24.11, 'symbol' => '$', 'format' => '0,0.00 $', 'short_format' => '0!0 $', 'locale' => 'en_US']);
     Currency::create(['name' => 'Euro', 'code' => 'eur', 'unit' => 27.06, 'symbol' => '€', 'format' => '0,0.00 €', 'short_format' => '0!0 €', 'locale' => 'eu']);
 }
Example #2
0
 /**
  * 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'));
 }
 /**
  * {@inheritDoc}
  */
 public function boot()
 {
     // Register the attributes namespace
     $this->app['platform.attributes.manager']->registerNamespace($this->app['Sanatorium\\Shoppricing\\Models\\Currency']);
     // Subscribe the registered event handler
     $this->app['events']->subscribe('sanatorium.shoppricing.currency.handler.event');
     $this->registerCartalystConverterPackage();
     // Set the measurements
     $measurements = ['currency' => []];
     foreach (Currency::all() as $currency) {
         $measurements['currency'][$currency->code] = ['format' => $currency->format, 'unit' => $currency->unit];
     }
     Converter::setMeasurements($measurements);
     // Register the Blade @pricing widget
     $this->registerBladePricingWidget();
 }
 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 short_format($value, $currency_id)
 {
     $currency = Currency::find($currency_id);
     if (!$currency) {
         return $value;
     }
     return $this->makeFormat('currency.' . $currency->code, $value, $currency->short_format);
 }
 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;
 }