Inheritance: extends Eloquen\Eloquent
Example #1
1
 /**
  * Prepare global variables.
  * @return array
  */
 public static function globalData()
 {
     if (!Auth::check()) {
         $rows = null;
         $cart = null;
         $grandTotal = null;
     } else {
         $rows = Cart::instance(auth()->id())->count(false);
         $cart = Cart::instance(auth()->id())->content();
         $grandTotal = Cart::instance(auth()->id())->total();
     }
     $data = array('menu' => self::getMenuData(self::$parent_id), 'header' => Setting::findOrFail(1), 'rows' => $rows, 'cart' => $cart, 'grand_total' => $grandTotal, 'currencies' => Currency::all());
     return $data;
 }
Example #2
0
 protected function fakeCurrency()
 {
     $fakeCurrency = new Currency();
     $fakeCurrency->currency_code = "USD";
     $fakeCurrency->currency_name = "Dollar";
     $fakeCurrency->save();
     return $fakeCurrency;
 }
Example #3
0
 public function __construct(Currency $currencyModel, Note $noteModel)
 {
     $notes = $noteModel->getLastNote();
     if (count($notes) < 1) {
         $notes = false;
     }
     //GLOBAL SETTINGS
     $this->_glob = array('_note' => $notes, '_curr' => $currencyModel->getRate(), '_baseCurrency' => 'RUB', '_precision' => 2, '_countProductsOfPage' => Auth::User() ? Auth::User()->count_products : 100, '_maxCountProductsOfPage' => 500, '_alerts' => AbsentController::shortView());
     View::share('_glob', $this->_glob);
 }
Example #4
0
 private function initCurrenciesToDb()
 {
     for ($day = 3000; $day > 0; $day--) {
         $currency = new Currency();
         $date = date('Y-m-d', strtotime('-' . $day . ' day'));
         $currency->date = $date;
         $currency->usd = $this->getCurrencyForDate($date);
         $currency->save();
         echo $day . PHP_EOL;
     }
 }
 public function actionGetCurrencies()
 {
     $billing_id = Yii::$app->request->post('billing_id');
     $currencies = ArrayHelper::map(Currency::find()->where("billing_id = :billing_id", [':billing_id' => $billing_id])->with('billing')->asArray()->all(), 'id', 'name');
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return $currencies;
 }
 /**
  * Change the currency.
  *
  * @return Redirect
  */
 public function show(Request $request, string $currency)
 {
     $request->session()->put('currency', $currency);
     $currency = Currency::where('currency', $currency)->first()->toArray();
     $request->session()->put('currency_rate', $currency['rate']);
     // we need to update the basket
     $basket = $request->session()->get('basket');
     foreach ($basket['items'] as $id => $item) {
         if (isset($item['parent_sku'])) {
             // its an option
             $product = Product::where('sku', $item['parent_sku'])->first();
             $price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
             foreach ($product->option_values as $option) {
                 if ($option['sku'] == $id) {
                     $price = number_format($option['price'] * $request->session()->get('currency_rate'), 2, '.', '');
                 }
             }
         } else {
             $product = Product::find($id);
             $price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
         }
         $basket['items'][$id]['price'] = $price;
     }
     $request->session()->put('basket', $basket);
     return redirect()->back();
 }
Example #7
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('course')->delete();
     Model::unguard();
     $faker = Faker\Factory::create();
     $currencies = Currency::all()->toArray();
     DB::table('course')->insert([['currency_id' => $currencies[0]['id'], 'course_purchase' => 5.4, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[1]['id'], 'course_purchase' => 5.0, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[2]['id'], 'course_purchase' => 1.03, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[3]['id'], 'course_purchase' => 1.7, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[4]['id'], 'course_purchase' => 1.7, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[5]['id'], 'course_purchase' => 1.0, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[6]['id'], 'course_purchase' => 0.1, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[7]['id'], 'course_purchase' => 0.3, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[8]['id'], 'course_purchase' => 0.1, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[9]['id'], 'course_purchase' => 0.00014, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[10]['id'], 'course_purchase' => 0.0, 'wallet' => $faker->creditCardNumber]]);
     Model::reguard();
 }
Example #8
0
 public function exchangeRates()
 {
     $currency = new Currency();
     $url = 'https://api.privatbank.ua/p24api/pubinfo?exchange&coursid=3';
     $xml = new SimpleXMLElement($url, NULL, true);
     $eur = (array) $xml->row[0]->exchangerate['sale'];
     $rur = (array) $xml->row[1]->exchangerate['sale'];
     $usd = (array) $xml->row[2]->exchangerate['sale'];
     $currency->uan = 1;
     $currency->eur = $eur[0];
     $currency->rur = $rur[0];
     $currency->usd = $usd[0];
     $currency->date = 86400 * ceil(time() / 86400);
     if ($currency->save()) {
         return false;
     }
     return true;
 }
Example #9
0
 public static function getActiveCurrency($chCode = false)
 {
     $attr = 'name';
     $query = Currency::find()->andWhere(['active' => true])->all();
     if ($chCode) {
         $attr = 'chCode';
     }
     return ArrayHelper::map($query, 'id', $attr);
 }
 /**
  * Updates an existing Rate model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $currency_list = Currency::getCurrencyList();
         return $this->render('update', ['model' => $model, 'currency' => $currency_list]);
     }
 }
Example #11
0
 /**
  *
  * Helper Currency Class
  *
  * @package ecommerce-cms
  * @category Helper Class
  * @author Tihomir Blazhev <*****@*****.**>
  * @link https://raylight75@bitbucket.org/raylight75/ecommerce-cms.git
  */
 public static function currency($input)
 {
     $var = session('currency');
     if (isset($var)) {
         $currency = Currency::where('name', '=', $var)->first();
         $rate = $currency->rate;
     } else {
         $rate = 1;
     }
     $total = (double) $input * (double) $rate;
     return number_format((double) $total, 2);
 }
Example #12
0
 /**
  * Creates a new Account model.
  * If creation is successful, the browser will be redirected to the 'index' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Account();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash("Account-success", Yii::t("app", "Account successfully created"));
         return $this->redirect(['index']);
     } else {
         $currencyItems = Currency::find()->select(['id', 'name'])->where(['user_id' => Yii::$app->user->id])->asArray()->all();
         $currencyItems = ArrayHelper::map($currencyItems, 'id', 'name');
         return $this->render('create', ['model' => $model, 'currencyItems' => $currencyItems]);
     }
 }
Example #13
0
 public function postSetActive()
 {
     $id = Input::get('id');
     Currency::where('active', 1)->update(['active' => 0]);
     $currency = Currency::find($id);
     if ($currency) {
         $currency->active = 1;
         $currency->save();
         return Redirect::back()->with('message', "Курс валюты '{$currency->title}' обновлён");
     }
     return Redirect::back()->with('message', 'Ошибка обновления');
 }
Example #14
0
 public function price()
 {
     $active_currency = Currency::active();
     $price = $this->price * $active_currency->rate_ue * $active_currency->rate_rub;
     if ($this->is_default_discount > 0) {
         $default_discount_sum = $price / 100 * $this->default_discount;
         $price -= $default_discount_sum;
     }
     if (Auth::check()) {
         $price -= $this->personal_discount($price);
     }
     return $price;
 }
Example #15
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Currency::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'iso', $this->iso])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #16
0
 public function __construct(Route $route)
 {
     $this->middleware(function ($request, $next) {
         // if session is not set get it from .env SHOP_CODE
         if (!$request->session()->has('shop')) {
             $shop = Shop::where('code', config('app.shop_code'))->first();
             $request->session()->put('shop', $shop->id);
         }
         // if limit is not set default pagination limit
         if (!$request->session()->has('limit')) {
             $request->session()->put('limit', 102);
         }
         // if session is not set reset the session for the language
         if (!$request->session()->has('language')) {
             $request->session()->put('language', config('app.locale'));
         }
         // if session is not set reset the session for the currency
         if (!$request->session()->has('currency')) {
             $request->session()->put('currency', config('app.currency'));
         }
         if (!$request->session()->has('currency_rate')) {
             $currency = Currency::where('currency', config('app.currency'))->first();
             $request->session()->put('currency_rate', $currency->rate);
         }
         // if session is not set reset the session for the basket
         if (!$request->session()->has('basket')) {
             $request->session()->put('basket', ['subtotal' => 0, 'count' => 0, 'items' => []]);
         }
         // global list of categories
         if (!$request->session()->has('categories')) {
             $categories = Category::where('shop_id', $request->session()->get('shop'))->orderBy('order', 'asc')->get()->toArray();
             $request->session()->put('categories', $categories);
         }
         // global list of product filters
         if (!$request->session()->has('filters')) {
             $options = Option::all()->toArray();
             // Serialization of 'MongoDB\BSON\ObjectID' is not allowed
             $request->session()->put('filters', $options);
         }
         // share globals
         view()->share('language', $request->session()->get('language'));
         return $next($request);
     });
     // add controller & action to the body class
     $currentAction = $route->getActionName();
     list($controller, $method) = explode('@', $currentAction);
     $controller = preg_replace('/.*\\\\/', '', $controller);
     $action = preg_replace('/.*\\\\/', '', $method);
     view()->share('body_class', $controller . '-' . $action);
 }
 private function createPaymentTerms()
 {
     $paymentTerms = [['num_days' => -1, 'name' => 'Net 0']];
     foreach ($paymentTerms as $paymentTerm) {
         if (!DB::table('payment_terms')->where('name', '=', $paymentTerm['name'])->get()) {
             PaymentTerm::create($paymentTerm);
         }
     }
     $currencies = [['name' => 'US Dollar', 'code' => 'USD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Pound Sterling', 'code' => 'GBP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Euro', 'code' => 'EUR', 'symbol' => '€', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Rand', 'code' => 'ZAR', 'symbol' => 'R', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Danish Krone', 'code' => 'DKK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Israeli Shekel', 'code' => 'ILS', 'symbol' => 'NIS ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Swedish Krona', 'code' => 'SEK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Kenyan Shilling', 'code' => 'KES', 'symbol' => 'KSh ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Canadian Dollar', 'code' => 'CAD', 'symbol' => 'C$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Philippine Peso', 'code' => 'PHP', 'symbol' => 'P ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Indian Rupee', 'code' => 'INR', 'symbol' => 'Rs. ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Australian Dollar', 'code' => 'AUD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Singapore Dollar', 'code' => 'SGD', 'symbol' => 'SGD ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Norske Kroner', 'code' => 'NOK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'New Zealand Dollar', 'code' => 'NZD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Vietnamese Dong', 'code' => 'VND', 'symbol' => 'VND ', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Swiss Franc', 'code' => 'CHF', 'symbol' => 'CHF ', 'precision' => '2', 'thousand_separator' => '\'', 'decimal_separator' => '.'], ['name' => 'Guatemalan Quetzal', 'code' => 'GTQ', 'symbol' => 'Q', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Malaysian Ringgit', 'code' => 'MYR', 'symbol' => 'RM', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Brazilian Real', 'code' => 'BRL', 'symbol' => 'R$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Thai baht', 'code' => 'THB', 'symbol' => 'THB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.']];
     foreach ($currencies as $currency) {
         if (!DB::table('currencies')->whereName($currency['name'])->get()) {
             Currency::create($currency);
         }
     }
 }
 public function run()
 {
     Eloquent::unguard();
     $currencies = [['name' => 'US Dollar', 'code' => 'USD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Pound Sterling', 'code' => 'GBP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Euro', 'code' => 'EUR', 'symbol' => '€', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'South African Rand', 'code' => 'ZAR', 'symbol' => 'R', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Danish Krone', 'code' => 'DKK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Israeli Shekel', 'code' => 'ILS', 'symbol' => 'NIS ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Swedish Krona', 'code' => 'SEK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Kenyan Shilling', 'code' => 'KES', 'symbol' => 'KSh ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Canadian Dollar', 'code' => 'CAD', 'symbol' => 'C$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Philippine Peso', 'code' => 'PHP', 'symbol' => 'P ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Indian Rupee', 'code' => 'INR', 'symbol' => 'Rs. ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Australian Dollar', 'code' => 'AUD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Singapore Dollar', 'code' => 'SGD', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Norske Kroner', 'code' => 'NOK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'New Zealand Dollar', 'code' => 'NZD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Vietnamese Dong', 'code' => 'VND', 'symbol' => '', 'precision' => '0', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Swiss Franc', 'code' => 'CHF', 'symbol' => '', 'precision' => '2', 'thousand_separator' => '\'', 'decimal_separator' => '.'], ['name' => 'Guatemalan Quetzal', 'code' => 'GTQ', 'symbol' => 'Q', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Malaysian Ringgit', 'code' => 'MYR', 'symbol' => 'RM', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Brazilian Real', 'code' => 'BRL', 'symbol' => 'R$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Thai Baht', 'code' => 'THB', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Nigerian Naira', 'code' => 'NGN', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Argentine Peso', 'code' => 'ARS', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Bangladeshi Taka', 'code' => 'BDT', 'symbol' => 'Tk', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'United Arab Emirates Dirham', 'code' => 'AED', 'symbol' => 'DH ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Hong Kong Dollar', 'code' => 'HKD', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Indonesian Rupiah', 'code' => 'IDR', 'symbol' => 'Rp', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Mexican Peso', 'code' => 'MXN', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Egyptian Pound', 'code' => 'EGP', 'symbol' => 'E£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Colombian Peso', 'code' => 'COP', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'West African Franc', 'code' => 'XOF', 'symbol' => 'CFA ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Chinese Renminbi', 'code' => 'CNY', 'symbol' => 'RMB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Rwandan Franc', 'code' => 'RWF', 'symbol' => 'RF ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Tanzanian Shilling', 'code' => 'TZS', 'symbol' => 'TSh ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Netherlands Antillean Guilder', 'code' => 'ANG', 'symbol' => '', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Trinidad and Tobago Dollar', 'code' => 'TTD', 'symbol' => 'TT$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'East Caribbean Dollar', 'code' => 'XCD', 'symbol' => 'EC$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Ghanaian Cedi', 'code' => 'GHS', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Bulgarian Lev', 'code' => 'BGN', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ' ', 'decimal_separator' => '.'], ['name' => 'Aruban Florin', 'code' => 'AWG', 'symbol' => 'Afl. ', 'precision' => '2', 'thousand_separator' => ' ', 'decimal_separator' => '.'], ['name' => 'Turkish Lira', 'code' => 'TRY', 'symbol' => 'TL ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Romanian New Leu', 'code' => 'RON', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Croatian Kuna', 'code' => 'HKR', 'symbol' => 'kn', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Saudi Riyal', 'code' => 'SAR', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Japanese Yen', 'code' => 'JPY', 'symbol' => '¥', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Maldivian Rufiyaa', 'code' => 'MVR', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.']];
     foreach ($currencies as $currency) {
         $record = Currency::whereCode($currency['code'])->first();
         if ($record) {
             $record->name = $currency['name'];
             $record->symbol = $currency['symbol'];
             $record->thousand_separator = $currency['thousand_separator'];
             $record->decimal_separator = $currency['decimal_separator'];
             $record->save();
         } else {
             Currency::create($currency);
         }
     }
 }
 private function createPaymentTerms()
 {
     $paymentTerms = [['num_days' => -1, 'name' => 'Net 0']];
     foreach ($paymentTerms as $paymentTerm) {
         if (!DB::table('payment_terms')->where('name', '=', $paymentTerm['name'])->get()) {
             PaymentTerm::create($paymentTerm);
         }
     }
     $currencies = [['name' => 'US Dollar', 'code' => 'USD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Pound Sterling', 'code' => 'GBP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Euro', 'code' => 'EUR', 'symbol' => '€', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'South African Rand', 'code' => 'ZAR', 'symbol' => 'R', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Danish Krone', 'code' => 'DKK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Israeli Shekel', 'code' => 'ILS', 'symbol' => 'NIS ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Swedish Krona', 'code' => 'SEK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Kenyan Shilling', 'code' => 'KES', 'symbol' => 'KSh ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Canadian Dollar', 'code' => 'CAD', 'symbol' => 'C$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Philippine Peso', 'code' => 'PHP', 'symbol' => 'P ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Indian Rupee', 'code' => 'INR', 'symbol' => 'Rs. ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Australian Dollar', 'code' => 'AUD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Singapore Dollar', 'code' => 'SGD', 'symbol' => 'SGD ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Norske Kroner', 'code' => 'NOK', 'symbol' => 'kr ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'New Zealand Dollar', 'code' => 'NZD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Vietnamese Dong', 'code' => 'VND', 'symbol' => 'VND ', 'precision' => '0', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Swiss Franc', 'code' => 'CHF', 'symbol' => 'CHF ', 'precision' => '2', 'thousand_separator' => '\'', 'decimal_separator' => '.'], ['name' => 'Guatemalan Quetzal', 'code' => 'GTQ', 'symbol' => 'Q', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Malaysian Ringgit', 'code' => 'MYR', 'symbol' => 'RM', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Brazilian Real', 'code' => 'BRL', 'symbol' => 'R$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Thai Baht', 'code' => 'THB', 'symbol' => 'THB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Nigerian Naira', 'code' => 'NGN', 'symbol' => 'NGN ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Argentine Peso', 'code' => 'ARS', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'Bangladeshi Taka', 'code' => 'BDT', 'symbol' => 'Tk', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'United Arab Emirates Dirham', 'code' => 'AED', 'symbol' => 'DH ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Hong Kong Dollar', 'code' => 'HKD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Indonesian Rupiah', 'code' => 'IDR', 'symbol' => 'Rp', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Mexican Peso', 'code' => 'MXN', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Egyptian Pound', 'code' => 'EGP', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Colombian Peso', 'code' => 'COP', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','], ['name' => 'West African Franc', 'code' => 'XOF', 'symbol' => 'CFA ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'], ['name' => 'Chinese Renminbi', 'code' => 'CNY', 'symbol' => 'RMB ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.']];
     foreach ($currencies as $currency) {
         $record = Currency::whereCode($currency['code'])->first();
         if ($record) {
             $record->name = $currency['name'];
             $record->thousand_separator = $currency['thousand_separator'];
             $record->decimal_separator = $currency['decimal_separator'];
             $record->save();
         } else {
             Currency::create($currency);
         }
     }
 }
Example #20
0
 public function addOperation()
 {
     if ($this->currency_id != '1') {
         $course = new Course();
         if (!$course->checkCourse($this->currency_id)) {
             $course->currency_id = $this->currency_id;
             $currency = Currency::findOne($this->currency_id);
             $course->course = $course->getCourse($currency->iso);
             if (!$course->save()) {
                 throw new ErrorException('Курс не обновлен' . var_dump($course));
             }
         }
     }
     $operation = new Operation();
     $operation->user_id = Yii::$app->getUser()->id;
     $operation->category_id = $this->category_id === '' ? 1 : $this->category_id;
     $operation->currency_id = $this->currency_id === '' ? 1 : $this->currency_id;
     $operation->summ = $this->operation_type == 'income' ? $this->summ * 100 : $this->summ * -100;
     $operation->description = $this->description;
     return $operation->save() ? $operation : null;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $url = 'http://api.fixer.io/latest?base=' . env('APP_CURRENCY');
     $rates = json_decode(file_get_contents($url), true);
     if ($rates) {
         Currency::truncate();
         $currency = Currency::firstOrNew(['currency' => env('APP_CURRENCY'), 'rate' => '1']);
         $currency->currency = env('APP_CURRENCY');
         $currency->rate = 1;
         $currency->save();
         foreach ($rates['rates'] as $code => $rate) {
             $currency = Currency::firstOrNew(['currency' => $code]);
             $currency->currency = $code;
             $currency->rate = $rate;
             $currency->save();
         }
         return $this->line(trans('currencies.currencies') . ' ' . trans('crud.updated'));
     } else {
         return $this->error(trans('currencies.currencies') . ' ' . trans('crud.failed'));
     }
 }
Example #22
0
 public static function formatMoney($value, $currencyId = false)
 {
     if (!$currencyId) {
         $currencyId = Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY);
     }
     foreach (Cache::get('currencies') as $currency) {
         if ($currency->id == $currencyId) {
             break;
         }
     }
     if (!$currency) {
         $currency = Currency::find(1);
     }
     if (!$value) {
         $value = 0;
     }
     Cache::add('currency', $currency, DEFAULT_QUERY_CACHE);
     return $currency->symbol . number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
 }
Example #23
0
 public function actionMyAdverts()
 {
     if (Currency::find()->where(['>', 'date', time()])->orderBy(['date' => SORT_DESC])->asArray()->one() == null) {
         $currency = new Currency();
         if ($currency->exchangeRates()) {
             Yii::$app->session->setFlash('warning', 'Exchange rates might differ from actual ones');
         }
     }
     $searchModel = new AdvertSearch();
     $dataProvider = $searchModel->getMyAdverts();
     return $this->render('my-adverts', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Example #24
0
 public static function formatMoney($value, $currencyId = false, $showSymbol = true)
 {
     if (!$currencyId) {
         $currencyId = Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY);
     }
     foreach (Cache::get('currencies') as $currency) {
         if ($currency->id == $currencyId) {
             break;
         }
     }
     if (!$currency) {
         $currency = Currency::find(1);
     }
     if (!$value) {
         $value = 0;
     }
     $str = '';
     if ($showSymbol) {
         $str .= $currency->symbol;
     }
     return $str . number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
 }
Example #25
0
 public function actionMyBookmarks()
 {
     if (Currency::find()->where(['>', 'date', time()])->orderBy(['date' => SORT_DESC])->asArray()->one() == null) {
         $currency = new Currency();
         if ($currency->exchangeRates()) {
             Yii::$app->session->setFlash('warning', 'Exchange rates might differ from actual ones');
         }
     }
     $disabled_subcat = 'disabled';
     $disabled_city = 'disabled';
     $catList = ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'name');
     $regionList = ArrayHelper::map(Region::find()->asArray()->all(), 'id', 'name');
     $subcatList = [];
     $cityList = [];
     $searchModel = new BookmarkSearch();
     $dataProvider = $searchModel->getMyBookmarks();
     $advert = new Advert();
     return $this->render('my-bookmarks', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'catList' => $catList, 'subcatList' => $subcatList, 'regionList' => $regionList, 'cityList' => $cityList, 'disabled_subcat' => $disabled_subcat, 'disabled_city' => $disabled_city, 'advert' => $advert]);
 }
 public function index()
 {
     return Currency::all();
 }
Example #27
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getToCurrency()
 {
     return $this->hasOne(Currency::className(), ['id' => 'to_currency_id']);
 }
Example #28
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\Category;
use app\models\Supplier;
use app\models\Product;
use app\models\Currency;
use yii\helpers\ArrayHelper;
use zxbodya\yii2\galleryManager\GalleryManager;
/* @var $this yii\web\View */
/* @var $model app\models\Product */
/* @var $form yii\widgets\ActiveForm */
$categories = Category::find()->active()->orderBy(['title' => SORT_ASC])->all();
$suppliers = Supplier::find()->active()->orderBy(['name' => SORT_ASC])->all();
$currencies = Currency::labels();
?>

<div class="product-form">

	<?php 
$form = ActiveForm::begin(['enableClientValidation' => false, 'options' => ['enctype' => 'multipart/form-data']]);
?>

	<?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map($categories, 'id', 'title'));
?>

	<?php 
echo $form->field($model, 'supplier_id')->dropDownList(ArrayHelper::map($suppliers, 'id', 'name'));
?>
Example #29
0
 /**
  * @GET("/purchase/create", as="purchase.create")
  * @param Purchase $purchase
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function create(Purchase $purchase)
 {
     $user = \Auth::user();
     $currencies = Currency::all();
     return view('balance.create', compact('purchase', 'user', 'currencies'));
 }
Example #30
0
        $country = $result->country['Name'];
    }
    return $country;
}], ['attribute' => 'ContactID', 'label' => 'Туристы', 'content' => function ($data) {
    $mainContact = $data->contact;
    $list = "<ul>";
    $list .= "<li>" . $mainContact['Name'] . " " . $mainContact['SurName'] . "</li>";
    foreach ($data->participants as $value) {
        $contact = Contact::findOne($value['ContactID']);
        $list .= "<li>" . $contact->Name . " " . $contact->SurName . "</li>";
    }
    $list .= "</ul>";
    return $list;
}], ['attribute' => 'CurrencyID', 'label' => 'Валюта', 'content' => function ($data) {
    $currency = '';
    $result = Currency::findOne($data->orderCalc['CurrencyID']);
    if (is_object($result)) {
        $currency = $result->Currency;
    }
    return $currency;
}], ['attribute' => 'Price', 'label' => 'Стоимость', 'content' => function ($data) {
    return $data->orderCalc['Price'];
}], ['attribute' => 'Charges', 'label' => 'Комиссия', 'content' => function ($data) {
    return $data->Charges;
}], ['attribute' => 'Sum', 'label' => 'Долг', 'content' => function ($data) {
    return $data->Sum - $data->Charges;
}, 'contentOptions' => function ($model, $key, $index, $column) {
    $status = '';
    $debt = $model->Sum - $model->Charges;
    if ($debt > 0) {
        $status = 'text-danger';