Sap BO Design Studio Tarih Fonksiyonları (Date Functions)

Sap BO Design Studio’da (1.x) tarih hesaplamaları veri kaynaklarında yapılması gerekiyor. Design Studio’da tarih fonksiyonları yer almıyor. Bu ihtiyaç için Karol Kalisz Design Studio Sdk ile ücretsiz ve açık kaynak Simple Date Object Component @github geliştirmiş.

Sap BO Lumira Designer’da (2.x) tarih hesaplamaları için Date (DateObject) dahili olarak yer alıyor. Global değişken tipi olarak seçilemiyor ama kod bloğunda var d1 = Date.createNow(); şeklinde kullanılabiliyor.

Bu Design Studio eklentisini kullanmadan tarih hesaplamalarını yapmak için yazdığım fonksiyonlar: (Burada en önemlisi get_previous_day ile önceki güne gitme fonksiyonu, n elemanlı dizi tanımlayıp n gün öncesine gidilebiliyor. WebI deki RelativeDate gibi)

design_studio_lib_date.txt

---------------------------------------
---------------------------------------

Global Variables
----------------

gv_date_current_month_array(String)(Array)
gv_date_current_month_concatenated_string(String)
gv_date_current_quarter_array(String)(Array)
gv_date_current_quarter_concatenated_string(String)
gv_date_current_year_array
gv_date_current_year_concatenated_string
gv_date_full_array
gv_date_full_concatenated_string
gv_date_full_not_concatenated_string
gv_date_last_month_array
gv_date_last_month_concatenated_string
gv_date_yesterday_array
gv_date_yesterday_concatenated_string

---------------------------------------
---------------------------------------

LIB_DATE
--------

---------------------------------------
---------------------------------------

LIB_DATE.get_current_month_start()

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_current_month_start_YYYYMMDD = lv_year_YYYY+lv_month_MM+"01";

return lv_current_month_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_current_quarter_start()

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_current_quarter_start_YYYYMMDD = "";

if (lv_month_MM =="01" || lv_month_MM =="02" || lv_month_MM =="03") {
	lv_current_quarter_start_YYYYMMDD = lv_year_YYYY + "01" + "01";
} else if (lv_month_MM =="04" || lv_month_MM =="05" || lv_month_MM =="06") {
	lv_current_quarter_start_YYYYMMDD = lv_year_YYYY + "04" + "01";
} else if (lv_month_MM =="07" || lv_month_MM =="08" || lv_month_MM =="09") {
	lv_current_quarter_start_YYYYMMDD = lv_year_YYYY + "07" + "01";
} else if (lv_month_MM =="10" || lv_month_MM =="11" || lv_month_MM =="12") {
	lv_current_quarter_start_YYYYMMDD = lv_year_YYYY + "10" + "01";
}

return lv_current_quarter_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_current_year_start()

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_current_year_start_YYYYMMDD = lv_year_YYYY+"01"+"01";

return lv_current_year_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_current_year_start()

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_current_year_start_YYYYMMDD = lv_year_YYYY+"01"+"01";

return lv_current_year_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_last_month_start()

var lv_today_YYYYMMDD = APPLICATION.getInfo().dateNowInternalFormat;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_last_month_start_YYYYMMDD = "";

var lv_year_int = Convert.stringToInt(lv_year_YYYY);
var lv_month_int = Convert.stringToInt(lv_month_MM);
var lv_day_int = Convert.stringToInt(lv_day_DD);

if (lv_month_int==1) {
	lv_last_month_start_YYYYMMDD = Convert.floatToString(lv_year_int-1,"###0")+"12"+"01";
} else {
	lv_last_month_start_YYYYMMDD = lv_year_YYYY+LIB_DATE.get_two_digit_month_or_day(lv_month_int-1)+"01";
}

return lv_last_month_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_previous_day(p_date(String))

var lv_today_YYYYMMDD = p_date;

var lv_year_YYYY = Convert.subString(lv_today_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_today_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_today_YYYYMMDD, 6, 8);

var lv_year_int = Convert.stringToInt(lv_year_YYYY);
var lv_month_int = Convert.stringToInt(lv_month_MM);
var lv_day_int = Convert.stringToInt(lv_day_DD);

var lv_previous_day = "";

if (lv_day_int != 1) {
	lv_previous_day = lv_year_YYYY + lv_month_MM + LIB_DATE.get_two_digit_month_or_day(lv_day_int-1);
} else {
	if (lv_month_int != 1) { // go previous month
		lv_previous_day = lv_year_YYYY + LIB_DATE.get_two_digit_month_or_day(lv_month_int-1) + LIB_DATE.get_two_digit_month_or_day(LIB_DATE.get_previous_month_days(p_date));
	} else { // go previous month and year
		lv_previous_day = Convert.floatToString(lv_year_int-1,"###0") + LIB_DATE.get_two_digit_month_or_day(12) + LIB_DATE.get_two_digit_month_or_day(LIB_DATE.get_previous_month_days(p_date));
	}
}

return lv_previous_day;

---------------------------------------
---------------------------------------

LIB_DATE.get_previous_month_days(p_date(String))

var lv_previous_month_start_YYYYMMDD = LIB_DATE.get_previous_month_start(p_date);

var lv_year_YYYY = Convert.subString(lv_previous_month_start_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_previous_month_start_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_previous_month_start_YYYYMMDD, 6, 8);

var lv_year_int_YYYY = Convert.stringToInt(lv_year_YYYY);
var lv_month_int_MM = Convert.stringToInt(lv_month_MM);
var lv_day_int_DD = Convert.stringToInt(lv_day_DD);

var lv_previous_month_days = 0;

if (lv_month_MM=="01" || lv_month_MM=="03" || lv_month_MM=="05" || lv_month_MM=="07" || lv_month_MM=="08" || lv_month_MM=="10" || lv_month_MM=="12") {
	lv_previous_month_days = 31;
} else if (lv_month_MM=="04" || lv_month_MM=="06" || lv_month_MM=="09" || lv_month_MM=="11") {
	lv_previous_month_days = 30;
} else  if (lv_month_MM=="02") {
	if ( Math.floor(lv_year_int_YYYY/4)*4 == lv_year_int_YYYY ) {
		// leap year
		lv_previous_month_days = 29;
	} else {
		lv_previous_month_days = 28;
	}
}

return lv_previous_month_days;

---------------------------------------
---------------------------------------

LIB_DATE.get_previous_month_start(p_date(String))

var lv_date_YYYYMMDD = p_date;

var lv_year_YYYY = Convert.subString(lv_date_YYYYMMDD, 0, 4);
var lv_month_MM = Convert.subString(lv_date_YYYYMMDD, 4, 6);
var lv_day_DD = Convert.subString(lv_date_YYYYMMDD, 6, 8);

var lv_previous_month_start_YYYYMMDD = "";

var lv_year_int = Convert.stringToInt(lv_year_YYYY);
var lv_month_int = Convert.stringToInt(lv_month_MM);
var lv_day_int = Convert.stringToInt(lv_day_DD);

if (lv_month_int==1) {
	lv_previous_month_start_YYYYMMDD = Convert.floatToString(lv_year_int-1,"###0")+"12"+"01";
} else {
	lv_previous_month_start_YYYYMMDD = lv_year_YYYY+LIB_DATE.get_two_digit_month_or_day(lv_month_int-1)+"01";
}

return lv_previous_month_start_YYYYMMDD;

---------------------------------------
---------------------------------------

LIB_DATE.get_today()

return APPLICATION.getInfo().dateNowInternalFormat;

---------------------------------------
---------------------------------------

LIB_DATE.get_two_digit_month_or_day(p_day_or_month(int))

if (p_day_or_month < 10) {
	return "0"+Convert.floatToString(p_day_or_month,"#0");
} else {
	return Convert.floatToString(p_day_or_month,"#0");
}

---------------------------------------
---------------------------------------

LIB_DATE.get_year(p_date(String))

return Convert.subString(p_date, 0, 4);

---------------------------------------
---------------------------------------

LIB_DATE.get_year_month(p_date(String))

return Convert.subString(p_date, 0, 6);

---------------------------------------
---------------------------------------

LIB_DATE.get_year_quarter(p_date(String))

var lv_year_YYYY = Convert.subString(p_date, 0, 4);
var lv_month_MM = Convert.subString(p_date, 4, 6);
var lv_day_DD = Convert.subString(p_date, 6, 8);

var lv_year_quarter_YYYYQN = "";

if (lv_month_MM == "01" || lv_month_MM == "02" || lv_month_MM == "03") {
	lv_year_quarter_YYYYQN = lv_year_YYYY + "Q1";
} else if (lv_month_MM == "04" || lv_month_MM == "05" || lv_month_MM == "06") {
	lv_year_quarter_YYYYQN = lv_year_YYYY + "Q2";
} else if (lv_month_MM == "07" || lv_month_MM == "08" || lv_month_MM == "09") {
	lv_year_quarter_YYYYQN = lv_year_YYYY + "Q3";
} else if (lv_month_MM == "10" || lv_month_MM == "11" || lv_month_MM == "12") {
	lv_year_quarter_YYYYQN = lv_year_YYYY + "Q4";
}

return lv_year_quarter_YYYYQN;

---------------------------------------
---------------------------------------

LIB_DATE.initialize_date_arrays_for_filtering()

var lv_date_temp = "";
var lv_date_temp_formatted = "";

var lv_today_YYYYMMDD = LIB_DATE.get_today();
var lv_current_month_start_YYYYMMDD = LIB_DATE.get_current_month_start();
var lv_current_month_YYYYMM = LIB_DATE.get_year_month(lv_today_YYYYMMDD);
var lv_last_month_start_YYYYMMDD = LIB_DATE.get_last_month_start();
var lv_last_month_YYYYMM = LIB_DATE.get_year_month(lv_last_month_start_YYYYMMDD);
var lv_current_quarter_start_YYYYMMDD = LIB_DATE.get_current_quarter_start();
var lv_current_quarter_YYYYQN = LIB_DATE.get_year_quarter(lv_today_YYYYMMDD);
var lv_current_year_start_YYYYMMDD = LIB_DATE.get_current_year_start();
var lv_current_year_YYYY = LIB_DATE.get_year(lv_today_YYYYMMDD);

gv_date_full_concatenated_string = "";
gv_date_full_not_concatenated_string = "";
gv_date_current_month_concatenated_string = "";
gv_date_last_month_concatenated_string = "";
gv_date_current_quarter_concatenated_string = "";
gv_date_current_year_concatenated_string = "";

var lv_caldays_array = DS_DAYS.getMembers("DAY", 2000);

lv_caldays_array.forEach(function(sel, ind) {
	lv_date_temp = sel.internalKey;
	lv_date_temp_formatted = Convert.subString(lv_date_temp,4,6)+"/"+Convert.subString(lv_date_temp,6,8)+"/"+Convert.subString(lv_date_temp,0,4);
	gv_date_full_array.push(lv_date_temp);
	gv_date_full_concatenated_string = gv_date_full_concatenated_string + ";" + lv_date_temp_formatted;
	gv_date_full_not_concatenated_string = gv_date_full_not_concatenated_string + ";!" + lv_date_temp_formatted;
	// current month
	if ( lv_current_month_YYYYMM == LIB_DATE.get_year_month(lv_date_temp) ) {
		gv_date_current_month_array.push(lv_date_temp);
		gv_date_current_month_concatenated_string = gv_date_current_month_concatenated_string + ";" + lv_date_temp_formatted;
	}
	// last month
	if ( lv_last_month_YYYYMM == LIB_DATE.get_year_month(lv_date_temp) ) {
		gv_date_last_month_array.push(lv_date_temp);
		gv_date_last_month_concatenated_string = gv_date_last_month_concatenated_string + ";" + lv_date_temp_formatted;
	}
	// current quarter
	if ( lv_current_quarter_YYYYQN == LIB_DATE.get_year_quarter(lv_date_temp) ) {
		gv_date_current_quarter_array.push(lv_date_temp);
		gv_date_current_quarter_concatenated_string = gv_date_current_quarter_concatenated_string + ";" + lv_date_temp_formatted;
	}
	// current year
	if ( lv_current_year_YYYY == LIB_DATE.get_year(lv_date_temp) ) {
		gv_date_current_year_array.push(lv_date_temp);
		gv_date_current_year_concatenated_string = gv_date_current_year_concatenated_string + ";" + lv_date_temp_formatted;
	}
});

gv_date_full_concatenated_string = Convert.subString(gv_date_full_concatenated_string, 1); // lv_date_concatenation.length
gv_date_full_not_concatenated_string = Convert.subString(gv_date_full_not_concatenated_string, 1);
gv_date_current_month_concatenated_string = Convert.subString(gv_date_current_month_concatenated_string, 1);
gv_date_last_month_concatenated_string = Convert.subString(gv_date_last_month_concatenated_string, 1);
gv_date_current_quarter_concatenated_string = Convert.subString(gv_date_current_quarter_concatenated_string, 1);
gv_date_current_year_concatenated_string = Convert.subString(gv_date_current_year_concatenated_string, 1);

/*
if (gv_date_full_concatenated_string == "") {
	gv_date_full_concatenated_string = gv_date_full_not_concatenated_string;
}
if (gv_date_current_month_concatenated_string == "") {
	gv_date_current_month_concatenated_string = gv_date_full_not_concatenated_string;
}
if (gv_date_last_month_concatenated_string == "") {
	gv_date_last_month_concatenated_string = gv_date_full_not_concatenated_string;
}
if (gv_date_current_quarter_concatenated_string == "") {
	gv_date_current_quarter_concatenated_string = gv_date_full_not_concatenated_string;
}
if (gv_date_current_year_concatenated_string == "") {
	gv_date_current_year_concatenated_string = gv_date_full_not_concatenated_string;
}
*/

if (gv_date_full_concatenated_string == "") {
	gv_date_full_concatenated_string = "01/01/2100";
}
if (gv_date_current_month_concatenated_string == "") {
	gv_date_current_month_concatenated_string = "01/01/2100";
}
if (gv_date_last_month_concatenated_string == "") {
	gv_date_last_month_concatenated_string = "01/01/2100";
}
if (gv_date_current_quarter_concatenated_string == "") {
	gv_date_current_quarter_concatenated_string = "01/01/2100";
}
if (gv_date_current_year_concatenated_string == "") {
	gv_date_current_year_concatenated_string = "01/01/2100";
}

---------------------------------------
---------------------------------------

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir