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; }
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); }
/** * 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]); } }
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', 'Ошибка обновления'); }
/** * 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; }
*/ $items = [['label' => BackLink::widget(['title' => Yii::t('app', 'Orders'), 'textOnly' => true]), 'url' => Url::to(['/admin/order/list'])]]; if (!$model->isNewRecord) { $items[] = ['label' => Yii::t('app', 'View items'), 'url' => Url::to(['/admin/order-items/list', 'node' => $model->id])]; } $items[count($items) - 1]['active'] = true; echo Nav::widget(['encodeLabels' => false, 'items' => $items, 'options' => ['class' => 'nav-pills']]); ?> <div class="order-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'currency_code')->widget(EntityDropDown::className(), ['items' => ArrayHelper::map(Currency::find()->all(), 'code', 'name')]); ?> <?php echo $form->field($model, 'country_id')->widget(EntityDropDown::className(), array('items' => ArrayHelper::map(Country::find()->all(), 'id', 'name'))); ?> <?php echo $form->field($model, 'user_id')->widget(EntityDropDown::className(), ['items' => ArrayHelper::map(User::find()->all(), 'id', 'name')]); ?> <?php echo $form->field($model, 'status')->widget(EntityDropDown::className(), ['items' => [Yii::t('app', 'New'), Yii::t('app', 'Closed'), Yii::t('app', 'Canceled')]]); ?> <?php
?> <div class="operation-update"> <h1><?php echo Html::encode($this->title); ?> </h1> <div class="operation-form"> <?php $form = ActiveForm::begin(['id' => 'operation-form', 'options' => ['class' => 'form-horizontal col-lg-5'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-lg-8\">{input}</div>\n<div class=\"col-lg-1\"></div><div class=\"col-lg-12\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-4 control-label']]]); ?> <?php $currencies = Currency::find()->all(); $currency_items = ArrayHelper::map($currencies, 'id', 'iso'); $operation_type = $t === 'income' ? 0 : 1; $categories = Category::findAll(['type' => $operation_type]); $category_items = ArrayHelper::map($categories, 'id', 'name'); $category_label = $t === 'income' ? 'Статья доходов' : 'Статья расходов'; ?> <?php echo $form->field($model, 'currency_id')->dropDownList($currency_items)->label('Валюта'); ?> <?php echo $form->field($model, 'summ'); ?> <?php echo $form->field($model, 'category_id')->dropDownList($category_items)->label($category_label);
<?php use app\models\Advert; use app\models\AdvertSearch; use app\models\Bookmark; use app\models\Currency; use yii\data\ActiveDataProvider; use yii\helpers\Html; use yii\helpers\Url; $columns = [['attribute' => 'price', 'format' => 'html', 'value' => function ($searchModel) { $currency = Currency::find()->where(['>', 'date', time()])->asArray()->one(); $dropDownItems = ['uan' => 'грн.', 'rur' => 'руб.', 'usd' => 'USD', 'eur' => 'EURO']; if (isset($_GET['currency']) && $_GET['currency'] !== 'default') { $cur = $_GET['currency']; } else { $cur = $searchModel->currency; } $price = round($searchModel->price * ($currency[$searchModel->currency] / $currency[$cur]), 2); return '<h4><strong>' . $price . ' ' . $dropDownItems[$cur] . '</strong></h4>'; }, 'options' => ['style' => 'width: 130px; max-width: 130px;']], ['attribute' => 'price', 'format' => 'html', 'value' => function ($searchModel) { $span = '<span class="glyphicon glyphicon-trash"></span>'; $url = Url::toRoute(['bookmark/delete-bm', 'advert_id' => $searchModel->id]); return Html::a($span, [$url]); }]]; $searchModel = new AdvertSearch(); $book = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId()])->asArray()->all(); $n = count($book); $arr = [0]; for ($i = 0; $i < $n; $i++) { $arr[$i] = $book[$i]['advert_id']; }
public function get($id, $elequent) { $cacheKey = self::CACHE . $id; if ($elequent) { return Currency::find($id); } $cachedData = \Cache::has($cacheKey); if (empty($cachedData)) { $currency = Currency::find($id); if (!empty($currency)) { $currency = $currency->toArray(); // if(!empty($country['pic_path'])) // $country['profile_pic'] = env('STORAGE_URL').'app/user_images/'.$country['pic_path']; // else // $country['profile_pic'] = ''; $currency['updated_at'] = date('Y-m-d', strtotime($currency['updated_at'])); $currency['created_at_formatted'] = date('Y-m-d', strtotime($currency['created_at'])); $currency['updated_at_formatted'] = date('Y-m-d', strtotime($currency['updated_at'])); // unset($country['password']); //unset($country['code']); // Set data in cache \Cache::forever($cacheKey, $currency); return $currency; } else { return false; } } else { return \Cache::get($cacheKey); } }
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]); }
/** * creates an advert */ public function createAdvert() { $currency = Currency::find()->where(['date' => 0])->asArray()->one(); if ($this->validate()) { $advert = new Advert(); $advert->user_id = Yii::$app->user->identity->getId(); $advert->category_id = $this->category_id; $advert->subcategory_id = $this->subcategory_id; $advert->region_id = $this->region_id; $advert->city_id = $this->city_id; $advert->title = $this->title; $advert->text = $this->text; $advert->price = $this->price; $advert->currency = $this->currency; $advert->u_price = $this->price * $currency[$this->currency]; $advert->created_at = time(); $advert->updated_at = time(); $advert->views = 0; if ($advert->save()) { return $advert; } } return null; }
/** * @return string */ protected function getListView() { $dataProvider = new ActiveDataProvider(['query' => Currency::find()]); return $this->render('list', ['dataProvider' => $dataProvider]); }
/** * Delete a currency. * * @param string $id * * @return Redirect */ public function destroy($id) { // delete $currency = Currency::find($id); $currency->delete(); // redirect $request->session()->flash('success', trans('currencies.currency') . ' ' . trans('crud.deleted')); return redirect('admin/currencies'); }
/** * Lists all Currency models. * @return mixed */ public function actionIndex() { $searchModel = new Currency(); $dataProvider = new ActiveDataProvider(['query' => $searchModel->find()->where(['user_id' => Yii::$app->user->id])]); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
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]); }
/** * @throws InvalidConfigException */ public static function refreshRates() { /** @var Currency $defaultCurrency */ $defaultCurrency = Currency::findOne(['is_default' => 1]); if (!$defaultCurrency) { throw new InvalidConfigException('Default currency is not set.'); } /** @var Currency[] $currencies */ $currencies = Currency::find()->all(); foreach ($currencies as $currency) { if ($currency->code == $defaultCurrency->code) { $currency->rate = 1; } else { $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=' . $defaultCurrency->code . $currency->code . '=X'; $handle = @fopen($url, 'r'); if ($handle === false) { throw new Exception('Can not connect to exchange rates provider service.'); } $result = fgets($handle, 4096); fclose($handle); $currencyData = explode(',', $result); $currency->rate = $currencyData[1]; } $currency->save(); } }
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); }
/** * Lists all Currency models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Currency::find()->with('billing')]); return $this->render('index', ['dataProvider' => $dataProvider]); }
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); }
/** * Заполняет поле валюты значениями из базы */ public function getCurrencyList() { if (!$this->currencyList) { $this->currencyList = Currency::find()->asArray()->all(); } return $this->currencyList; }