Skip to content

Instantly share code, notes, and snippets.

@droganov
Last active September 7, 2023 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save droganov/b94c02dde3f6690caff4b3f5a31d7cac to your computer and use it in GitHub Desktop.
Save droganov/b94c02dde3f6690caff4b3f5a31d7cac to your computer and use it in GitHub Desktop.
Spreadsheets formula for calculating the tax base in Georgian Lari
function Larry(date, summ, currency) {
try {
var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "yyyy-MM-dd");
var apiUrl = "https://nbg.gov.ge/gw/api/ct/monetarypolicy/currencies/en/json/?currencies=" + currency + "&date=" + formattedDate;
var response = UrlFetchApp.fetch(apiUrl);
var data = JSON.parse(response.getContentText());
var rate = data[0].currencies[0].rate;
var summ = parseFloat(summ.toString().replace(",", "."));
var result = summ * rate;
return result;
} catch (error) {
return String(error);
}
}
@droganov
Copy link
Author

droganov commented Sep 7, 2023

Paste the code to Extensions > Apps Script
Run it and give permissions to fetch data.

Use as a formula:

=Larry(A2;B2;C2)

Example sheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment