mht_brerp10
.adempiere
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
previousbusinessday(timestamp with time zone, numeric)
Parameters
Name
Type
Mode
p_date
timestamp with time zone
IN
p_ad_client_id
numeric
IN
Definition
DECLARE v_previousDate date := trunc(p_Date); v_offset numeric := 0; v_Saturday numeric := TO_CHAR(TO_DATE('2000-01-01', 'YYYY-MM-DD'), 'D'); v_Sunday numeric := (case when v_Saturday = 7 then 1 else v_Saturday + 1 end); v_isHoliday boolean := true; v_country c_country.c_country_id%type; nbd C_NonBusinessDay%ROWTYPE; begin v_isHoliday := true; loop SELECT CASE TO_CHAR(v_previousDate,'D')::numeric WHEN v_Saturday THEN -1 WHEN v_Sunday THEN -2 ELSE 0 END INTO v_offset; v_previousDate := v_previousDate + v_offset::integer; v_isHoliday := false; SELECT COALESCE(MAX(co.c_country_id), 100) INTO v_country FROM ad_client cl JOIN ad_language l ON cl.ad_language = l.ad_language JOIN c_country co ON l.countrycode = co.countrycode WHERE cl.ad_client_id = p_ad_client_id; FOR nbd IN SELECT * FROM C_NonBusinessDay WHERE AD_Client_ID=p_AD_Client_ID and IsActive ='Y' and Date1 >= v_previousDate AND COALESCE(C_Country_ID,0) IN (0, v_country) ORDER BY Date1 LOOP exit when v_previousDate <> trunc(nbd.Date1); v_previousDate := v_previousDate - 1; v_isHoliday := true; end loop; exit when v_isHoliday=false; end loop; -- return v_previousDate::timestamp with time zone; end;