Fiscal Month-Day String, Create
Fiscal Month-Day String, Create

Creates a date ID for fiscal year sorting. The first day of the first month of the fiscal year will be “101”. The 25th day of the last month is “1225”. If the fiscal year starts in Jan, the string will be the same as the calendar format “Mdd”.

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

Configs
  • A: Select DATE DATA *
  • B: Set End Month ID of Fiscal Period (eg March: “3” ) * #{EL}
  • C: Select STR/NUM DATA that stores the Fiscal Month-Day (update) *
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

Creates a date ID for fiscal year sorting. The first day of the first month of the fiscal year will be "101". The 25th day of the last month is "1225". If the fiscal year starts in Jan, the string will be the same as the calendar format "Mdd".

Notes

  1. “Fiscal Month-Day” (date ID) is stored as a string.
  2. “Fiscal Month-Day” (date ID) can also be stored as a numerical value.
  3. Sorting by date becomes easier, if included in the quote ID, slip ID, etc.

See also

1 thought on “Fiscal Month-Day String, Create”

  1. Pingback: MoneyForward Journal, Create – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: