LoginSignup
2
2

More than 3 years have passed since last update.

BSの二期増減分析を自動で作ってみる

Last updated at Posted at 2019-05-26

目的

  • 資料自動化のため
  • 情報のこえだめとして
code.ts
/**
* @autour @kabanyasu 
*/


/**
 * APIを叩いて月次試算表を取得し、オブジェクト形式に変換する
 * @return {object} resBss
 */
function postApi() {
  let accessToken = getService().getAccessToken();
  let baseUrl = 'https://api.freee.co.jp/api/1/reports/trial_bs_two_years';
  let companyId = 9999999;
  let fiscalYear = 2019;
  let startMonth = 1;
  let endMonth = 12;
  let postUrl = baseUrl + `?company_id=${companyId}&fiscal_year=${fiscalYear}&start_month=${startMonth}&end_month=${endMonth}`;
  let options = {
    'method': 'get',
    'headers': {
      'Authorization': 'Bearer ' + accessToken
    },
  };
  let resBss = JSON.parse(UrlFetchApp.fetch(postUrl, options)).trial_bs_two_years.balances;
  return resBss;
}

/**
 * オブジェクトを二次配列に整形する。
 * @param {any} object
 * @return {any} array
 */
function createArray(object: any) {
  const array = object.map(account => {
    const level = account.hierarchy_level;
    const close = account.closing_balance;
    const last = account.last_year_closing_balance;
    if (!account.total_line) {
    //[勘定科目ID, 勘定科目名, 階層, 前期末残高, 当期末残高, 増減率, 増減額]
      return [account.account_item_id, account.account_item_name, level, last, close, close / last, close - last];
    } else {
    //[勘定カテゴリID, 勘定カテゴリ名, 階層, 前期末残高, 当期末残高, 増減率, 増減額]
      return [account.account_category_id, account.account_category_name, level, last, close, close / last, close - last];
    }
  });
  return array;
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2