会計月日文字列, 生成

会計月日文字列, 生成
会計月日文字列, 生成 (Fiscal Month-Day String, Create)

会計年度内ソート用の日付IDを生成します。会計年度の開始月の初日は “101” に、最終月の25日は “1225” となります。決算月が12月(会計年度の開始月が1月)の場合は、カレンダー日付の “Mdd” フォーマットと同じ文字列になります。

2020-04-21 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/fiscal-month-day-string-create/

Configs
  • A: 日付型データ項目を選択してください *
  • B: 決算月をセットしてください (例 3月決算の場合 “3” ) * #{EL}
  • C: 会計月日が格納される文字列型or数値型データ項目を選択してください (更新) *
Script
// Nashorn Script (engine type: 1)
// 
// Notes:
// "Fiscal Month-Day" (date ID) is stored as a string.
// "Fiscal Month-Day" (date ID) can also be stored as a numerical value.
// Sorting by date becomes easier, if included in the quote ID, slip ID, etc.
// 
// Notes (ja):
// "会計月日"(日付ID)は文字列として文字型データに格納されます。
// "会計月日"(日付ID)は数値として数値型データに格納することも可能です。
// 見積書や伝票などの管理IDに含めると、日付順ソートが容易になります。
//
//  [M] numMonthSerial (Serial Number, 1 means the first month of the fiscal year.)
//               01 02 03 04 05 06 07 08 09 10 11 12
//  EndMonth= 1: 12  1  2  3  4  5  6  7  8  9 10 11
//  EndMonth= 3: 10 11 12  1  2  3  4  5  6  7  8  9
//  EndMonth=12:  1  2  3  4  5  6  7  8  9 10 11 12


//////// START "main()" ////////////////////////////////////////////////////////////////
main();
function main(){

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA     = configs.get( "conf_DataIdA" )  + ""; // required
const strEndMonth = configs.get( "conf_EndMonth" ) + ""; // required
const dataIdC     = configs.get( "conf_DataIdC" )  + ""; // required

let numEndMonth = 0;
const regMonthInt = /^([1-9]|1[0-2])$/; // RegExp: 1,2,,,11,12
if( regMonthInt.test( strEndMonth ) ){
  numEndMonth = parseInt(strEndMonth, 10);
}else{
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {B:EndMonth} must be 1 to 12 \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
if( engine.findDataByNumber( dataIdA ) === null ){
  throw new Error( "\n AutomatedTask UnexpectedDateError:" +
                   " Date {A} is null \n" );
}
strDateA = engine.findDataByNumber( dataIdA ) + ""; // e.g. 2020-04-30


//// == Calculating / 演算 ==
let year       = 0;
let monthIndex = 0;
let day        = 0;
let arrDateParts = strDateA.split("-");
    year       = parseInt(arrDateParts[0], 10);
    monthIndex = parseInt(arrDateParts[1], 10) - 1; // 3
    day        = parseInt(arrDateParts[2], 10);     // 30

let numMdd     = monthIndex * 100 + day; // e.g. 330
    numMdd     = (numMdd + 1200 - (numEndMonth * 100) ) % 1200 + 100;


//// == Data Updating / ワークフローデータへの代入 ==
if( engine.findDataDefinitionByNumber( dataIdC ).matchDataType("DECIMAL") ){
  engine.setDataByNumber( dataIdC, new java.math.BigDecimal(numMdd) );
}else{
  engine.setDataByNumber( dataIdC, (numMdd + "") );
}


} //////// END "main()" ////////////////////////////////////////////////////////////////

Download

Capture

会計年度内ソート用の日付IDを生成します。会計年度の開始月の初日は "101" に、最終月の25日は "1225" となります。決算月が12月(会計年度の開始月が1月)の場合は、カレンダー日付の "Mdd" フォーマットと同じ文字列になります。

Notes

  1. “会計月日”(日付ID)は文字列として文字型データに格納されます。
  2. “会計月日”(日付ID)は数値として数値型データに格納することも可能です。
  3. 見積書や伝票などの管理IDに含めると、日付順ソートが容易になります。

See also

マネーフォワード仕訳伝票, 生成

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

上部へスクロール