rails ajax currency - ruby-on-rails-3

How to create the following:
I want make ajax currency switcher with rails
[usd|rub|eur]
In db I have only usd value
What gem suitable for this purpose? Or maybe browser-side solution is better?
Who has experience please give me advise

we use the Money Gem you can specify a Money column in your model to make the handling easier.
# Get exchange rates
Money.default_bank = ExchangeBankWhichScrapesXeDotCom.new
# new money object in USD
usd = Money.new(1000, "USD")
# exchange to rubel
rub = usd.exchange_to("RUB")

Related

CO currency for settlement process in CJ88

We have an issue with settlement in SAP.
If we post 1000CAD in settlement rule (cj02) for an asset #123456 to a project then it get settled 1000USD after settlement run.
But my question is why the CAD allocation is settling as USD? How can we solve this issue?
All transactions (incl. settlements) in CO-PA are done in Controlling Area currency that couldn't be changed. It seems that your CA currency is USD.
Check if flag All currencies is set in tcode OKKP, node Activate component indicators
If this is the case then your company uses different currencies for documents which are:
controlling area currency
object currency (=company code currency)
transaction currency (specified for each transaction).
By default all settlements are reconciled in company code currency so check if it is USD and change to desired value.
By and large, currency determination in CO-PA is very complex, check SAP note 1320586 for more details.

Coinbase work with ethereum in stead of bitcoin

I am trying to create an ether buy and sell bot on coinbase. They have a truly wonderfull description on their developer page. There is one thing I am missing.
Somehow all functions automatically refer to bitcoin and not to ether. I assume there is a setting to change that in the code but I am not finding or succeeding in this. All examples on their developer page are with bitcoin. For example:
buy_price = client.get_buy_price(currency = 'EUR')
This returns: amount, base and currency. So I noticed I can change the currency. Now I tried to change the base with
buy_price = client.get_buy_price(currency = 'EUR', base = 'ETH')
It still returns BTC (bitcoin) as base.
Hope someone can help me out here.
Try this:
buy_price = client.get_buy_price(currency_pair = 'ETH-USD')
From https://developers.coinbase.com/api/v2#get-exchange-rates
EDIT: the Python API seems not to work. But the raw GET request works, so here's a replacement function for you:
import urllib.request
import json
def myGetBuyPrice(crypto, fiat):
ret = (urllib.request.urlopen("https://api.coinbase.com/v2/prices/"+crypto+"-"+fiat+"/buy").read()).decode("utf-8")
return json.loads(ret)["data"]
print myGetBuyPrice("ETH", "USD")

assign currency in invoice using quickbook online api in rails

I am creating rails app which are integrate with Quick book account.
My problem is when i am create invoice that same invoice need to create in quick book account but how to pass currency for quick book using API.
I tried to found solutions but not success yet.
Any one have a idea?
Please refer Invoice entity doc - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice
Invoice entity has an attribute with name CurrencyRef ( DataType - CurrencyRef).
Ex -
<Invoice>
...
<CurrencyRef name="Canadian Dollar">CAD</CurrencyRef>
...
</Invoice>
Thanks
In your comment you mentioned you are using the quickbooks-ruby gem.
I recently added this feature to the gem for invoices via this PR.
In short do this:
invoice = Quickbooks::Model::Invoice.new
invoice.currency_id = 'CAD'
invoice.currency_ref.name = 'Canadian Dollar'

How to store users' location?

I am working on a new project and whole day thinking & looking for the best way, how to save users' location to database.
I need to save their city, country. Here is a bit problem, because for example for Europeans this means city=Berlin, country=Germany.
But for US users it's like city=Los Angeles, country=California (state=USA).
So this is the problem with which I ma facing whole today.
My goal in this app is to find all users in the city according to their location. And also find the people, which are in their area of let's say 15 km/miles.
I plan to implement the app in RoR, PostgreSQL, the app will run probably on Heroku.
What is the best way to solve this "problem"? Could you give me please some advices, tips, whatever?
Thank you
You can use the geokit and geokit-rails gems to achieve that. See here for documentation: https://github.com/imajes/geokit-rails
Basically, it works like this: you save address data of your users and that address is looked up and mapped to a point in space (lat/lng) using a geocoding service (e.g. Google Maps or Yahoo Placefinder). These points can then be used to calculate distances etc.
An example:
class User < ActiveRecord::Base
# has the following db fields:
# - city
# - state
# - country
# - latitude
# - longitude
acts_as_mappable :default_units => :miles,
:default_formula => :sphere,
:lat_column_name => :latitude,
:lng_column_name => :longitude,
:auto_geocode => {:field => :full_address}
def full_address
[city, state, country].reject(&:blank).join(', ')
end
end
Then you can do the following:
# find all users in a city (this has nothing to do with geokit but is just a normal db lookup)
User.where(:city => 'New York')
# find all users that are within X miles of a place
User.find_within(300, 'Denver')
and much more, just see the documentation...
This example shows you how to use the geokit gem. This gem does no longer seem to be under active development. So maybe it would be worthwile to check out geocoder: https://github.com/alexreisner/geocoder

basic modification of default model output with scope

I find myself doing the same things over and over again just to make one small modification to standard model output. I have a series of tables that I store information about products, etc. and all of which store prices. The prices are stored in US dollars but the output depends on the currency the user wants which is stored in a their session.
Examples:
Product Detail Blah Price
Hammer Red More 5.00
Nail Blue Stuff 3.99
Is there a simple robust way to modify the output so that when i call:
Product.all
I could attach something like
Product.all.currency('EUR')
Product.find(22).currency('EUR')
Product.find(:all, :conditions => 'etc etc').currency('EUR')
or
Product.all.currency(0.69)
and simply multiply all of the items in the Price column? Could named_scope do this?
try reordering your chaining like:
Product.currency(0.69).all
I have not tested that, but you may have issue with other arbitrary conditions since your :select contains *
Nevermind...
named_scope :currency, :select => '*, price * 0.63 AS price'
seemed to work except I can't chain it to normal finds as I would like.