Fiscal Month-Day String, Create

Fiscal Month-Day String, Create
Fiscal Month-Day String, Create
Creates a date ID for sorting within a fiscal year. 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”.
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 (click to open)

// GraalJS Script (engine type: 2)
// 
// 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" );
}
const 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

2021-07-16 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/fiscal-month-day-string-create-2021/
The Add-on import feature is available with Professional edition.

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 you include it in the quote ID or slip ID, etc.

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".

See also

MoneyForward Journal, Create

2 thoughts on “Fiscal Month-Day String, Create”

  1. Pingback: Fiscal Month-Day String, Create – Questetra Support

  2. Pingback: MoneyForward Journal, Create – Questetra Support

Comments are closed.

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top