Showing posts with label Property Management. Show all posts
Showing posts with label Property Management. Show all posts

Monday, 24 September 2018

Script to get Normalized Exp Amount from Property Manager

CREATE OR REPLACE FUNCTION APPS.PN_NORM_EXP(p_payment_item_id number, p_ccid number)
RETURN NUMBER
IS
l_accrued_amount    number;
l_cash_amount       number;
l_norm_exp       number;
l_max_item_id       number;
l_ps_id             number;
BEGIN
--
select payment_schedule_id
  into l_ps_id
  from pn_payment_items_all where payment_item_id = p_payment_item_id;
--
select max(i.payment_item_id)
  into l_max_item_id
  from pn_payment_items_all i, pn_payment_terms_all t, pn_distributions_all d
 where i.payment_schedule_id = l_ps_id
   and i.payment_term_id = t.payment_term_id   
   and d.payment_term_id = t.payment_term_id
   and t.normalize = 'Y'
   and account_class = 'EXP'
   and payment_item_type_lookup_code = 'NORMALIZED'
   and account_id = p_ccid;
-- 
IF p_payment_item_id != l_max_item_id
THEN
l_norm_exp := 0;
ELSE
--
select NVL(SUM(i.actual_amount),0)
  into l_accrued_amount
  from pn_payment_items_all i, pn_payment_terms_all t, pn_distributions_all d
 where i.payment_schedule_id = l_ps_id
   and i.payment_term_id = t.payment_term_id
   and d.payment_term_id = t.payment_term_id
   and t.normalize = 'Y'
   and account_class = 'EXP'
   and payment_item_type_lookup_code = 'NORMALIZED'
   and account_id = p_ccid;
--
select NVL(SUM(actual_amount),0)
  into l_cash_amount
  from pn_payment_items_all ci
 where payment_schedule_id = l_ps_id
   and payment_item_type_lookup_code = 'CASH'
   and exists (select 1
              from pn_payment_items_all i, pn_payment_terms_all t, pn_distributions_all d
      where i.payment_schedule_id = l_ps_id
         and i.payment_term_id = t.payment_term_id
         and d.payment_term_id = t.payment_term_id
         and t.normalize = 'Y'
         and account_class = 'EXP'
         and payment_item_type_lookup_code = 'NORMALIZED'
         and account_id = p_ccid
      and ci.payment_term_id = i.payment_term_id);
--     
l_norm_exp := l_accrued_amount - l_cash_amount;     
--
END IF;
 
  RETURN l_norm_exp;

EXCEPTION
WHEN NO_DATA_FOUND THEN
  RETURN 0;
WHEN OTHERS THEN
  RETURN 0;
END PN_NORM_EXP;

Script to get Cash from Property Manager

CREATE OR REPLACE FUNCTION APPS.PN_CASH(p_payment_item_id number, p_ccid number)
RETURN NUMBER
IS
l_cash_amount       number;
l_max_item_id       number;
l_ps_id             number;
BEGIN
--
select payment_schedule_id
  into l_ps_id
  from pn_payment_items_all where payment_item_id = p_payment_item_id;
--
select max(i.payment_item_id)
  into l_max_item_id
  from pn_payment_items_all i, pn_payment_terms_all t, pn_distributions_all d
  where i.payment_schedule_id = l_ps_id
    and i.payment_term_id = t.payment_term_id
    and d.payment_term_id = t.payment_term_id
    and t.normalize = 'Y'
    and account_class = 'EXP'
    and account_id = p_ccid;
-- 
IF p_payment_item_id != l_max_item_id
THEN
l_cash_amount := 0;
ELSE
--
select NVL(SUM(i.actual_amount),0)
  into l_cash_amount
  from pn_payment_items_all i, pn_payment_terms_all t, pn_distributions_all d
 where i.payment_item_type_lookup_code = 'CASH'
   and i.payment_term_id = t.payment_term_id
   and d.payment_term_id = t.payment_term_id
   and t.normalize = 'Y'
   and account_class = 'EXP'
   and payment_schedule_id = l_ps_id
   and account_id = p_ccid;
--
END IF;
 
  RETURN l_cash_amount;

EXCEPTION
WHEN NO_DATA_FOUND THEN
  RETURN 0;
WHEN OTHERS THEN
  RETURN 0;
END PN_CASH;
/


Friday, 21 September 2018

Leases which are expiring 15,30,60,180 days before respectively

This query fetches those leases which are going to expiry within 15,30,60,90,180 days respectively
based on the parameter.


 SELECT GCC.segment4  SOL_ID
      ,gl_flexfields_pkg.get_description_SQL(GCC.chart_of_accounts_id ,4,GCC.segment4) BRANCH_NAME
      ,PLA.lease_id Lease_number
      ,PLDA.attribute7 Agreement_no
      ,PAA.address_line1||','||PAA.address_line2||','||PAA.address_line3||','||PAA.address_line4||','||PAA.city||','||PAA.state
                             ||','||PAA.zip_code  Address
      ,APS.vendor_name       Landlord_name
      ,ASSA.vendor_site_code Landlord_Site
      ,PLDA.attribute4       Emp_No
      ,TO_CHAR(PPTA.end_date, 'DD-MON-YYYY')    Expiry_date
      ,PPTA.frequency_code   Payment_Freq
      ,PLA.lease_type_code   Category_of_premises
      ,PPTA.attribute9       Station_id
      ,PPTA.attribute8       SITE_ID
 from  pn_leases_all            PLA
      ,pn_lease_details_all     PLDA
      ,pn_tenancies_all         PTA
      ,pn_locations_all         PNLA
      ,pn_addresses_all         PAA
      ,fnd_territories_tl       FTT
      ,pn_payment_terms_all     PPTA
      ,pn_payment_items_all     PPIA
      ,pn_payment_schedules_all PPSA
      ,pn_distributions_all     PDA
      ,gl_code_combinations     GCC
      ,ap_suppliers             APS
      ,ap_supplier_sites_all    ASSA
WHERE 1=1
  AND PLA.lease_id              = PLDA.lease_id
  AND PLA.lease_id              = PPTA.lease_id
  AND PLA.lease_id              = PTA.lease_id
  AND PTA.location_id           = PNLA.location_id
  AND PNLA.address_id           = PAA.address_id
  AND FTT.territory_code        = PAA.country
  AND PPTA.payment_term_id      = PPIA.payment_term_id
  AND PPIA.payment_schedule_id  = PPSA.payment_schedule_id
  AND PPSA.lease_id             = PLA.lease_id
  AND PPTA.payment_term_id      = PDA.payment_term_id
  AND GCC.code_combination_id   = PDA.account_id
  AND PPIA.vendor_id            = APS.vendor_id
  AND PPIA.vendor_site_id       = ASSA.vendor_site_id
  AND PPTA.payment_purpose_code = 'RENT'
  AND PDA.account_class         = 'EXP'
 -- AND PLA.lease_status          =  'ACT'
 -- AND PLA.lease_id = 11000
  and payment_status_lookup_code = 'APPROVED'
  HAVING TRUNC(Max(PPTA.end_date)) = TRUNC(sysdate+:P_NO_DAYS)
 GROUP BY GCC.segment4 
      ,GCC.chart_of_accounts_id
      ,GCC.segment4
      ,PLA.lease_id
      ,PLDA.attribute7
      ,PAA.address_line1
      ,PAA.address_line2
      ,PAA.address_line3
      ,PAA.address_line4
      ,PAA.city
      ,PAA.state
      ,PAA.zip_code 
      ,APS.vendor_name
      ,ASSA.vendor_site_code
      ,PLDA.attribute4
      ,PPTA.end_date
      ,PPTA.frequency_code
      ,PLA.lease_type_code
      ,PPTA.attribute9
      ,PPTA.attribute8

Thursday, 20 September 2018

Lease Expired But Not Terminated

Query to Fetch Leases which are expired but not terminated.



 SELECT
       GCC.segment4  SOL_ID
      ,PLA.lease_id Lease_number
      ,PLDA.attribute7 Agreement_no
      ,PAA.address_line1||','||PAA.address_line2||','||PAA.address_line3||','||PAA.address_line4||','||PAA.city||','||PAA.state
                             ||','||PAA.zip_code  Address
      ,APS.vendor_name       Landlord_name
      ,ASSA.vendor_site_code Landlord_Site
      ,to_char(MAX(PPTA.end_date),'DD-MON-YYYY') Expiry_date
      ,DECODE(PPTA.frequency_code ,
              'OT', 'One Time',
              'QTR', 'Quarterly',
              'MON', 'Monthly') payment_frequency
      ,PLA.lease_type_code   Category_of_premises 
 FROM  pn_leases_all            PLA
      ,pn_lease_details_all     PLDA
      ,pn_tenancies_all         PTA
      ,pn_locations_all         PNLA
      ,pn_addresses_all         PAA
      ,fnd_territories_tl       FTT
      ,pn_payment_terms_all     PPTA
      ,pn_payment_items_all     PPIA
      ,pn_payment_schedules_all PPSA
      ,pn_distributions_all     PDA
      ,gl_code_combinations     GCC
      ,ap_suppliers             APS
      ,ap_supplier_sites_all    ASSA
WHERE 1=1
  AND PLA.lease_id              = PLDA.lease_id
  AND PLA.lease_id              = PPTA.lease_id
  AND PLA.lease_id              = PTA.lease_id
  AND PTA.location_id           = PNLA.location_id
  AND PNLA.address_id           = PAA.address_id
  AND FTT.territory_code        = PAA.country
  AND PPTA.payment_term_id      = PPIA.payment_term_id(+)
  AND PPIA.payment_schedule_id  = PPSA.payment_schedule_id(+)
  AND PPSA.lease_id             = PLA.lease_id
  AND PPTA.payment_term_id      = PDA.payment_term_id (+)
  AND GCC.code_combination_id   = PDA.account_id
  AND PPIA.vendor_id            = APS.vendor_id
  AND PPIA.vendor_site_id       = ASSA.vendor_site_id
  AND PPTA.payment_purpose_code = 'RENT'
  AND PDA.account_class         = 'EXP'
  AND PLA.lease_status          <>  'TER'
  HAVING MAX(PPTA.end_date) BETWEEN ADD_MONTHS(SYSDATE,-1) AND SYSDATE
 -- AND PLA.lease_id = 16004
  --and payment_status_lookup_code = 'APPROVED'
 GROUP BY  GCC.segment4 
      ,PLA.lease_id ,PPTA.end_date
      ,PLDA.attribute7
      ,PAA.address_line1
      ,PAA.address_line2
      ,PAA.address_line3
      ,PAA.address_line4
      ,PAA.city
      ,PAA.state
      ,PAA.zip_code 
      ,APS.vendor_name     
      ,ASSA.vendor_site_code
      ,PPTA.end_date
      ,PPTA.frequency_code
      ,PLA.lease_type_code   
UNION ALL
SELECT
       GCC.segment4  SOL_ID
      ,PLA.lease_id Lease_number
      ,PLDA.attribute7 Agreement_no
      ,PAA.address_line1||','||PAA.address_line2||','||PAA.address_line3||','||PAA.address_line4||','||PAA.city||','||PAA.state
                             ||','||PAA.zip_code  Address
      ,APS.vendor_name       Landlord_name
      ,ASSA.vendor_site_code Landlord_Site
      ,TO_CHAR(MAX(PPTA.end_date),'DD-MON-YYYY') Expiry_date
      ,DECODE(PPTA.frequency_code ,
              'OT', 'One Time',
              'QTR', 'Quarterly',
              'MON', 'Monthly') payment_frequency
      ,PLA.lease_type_code   Category_of_premises 
 FROM  pn_leases_all            PLA
      ,pn_lease_details_all     PLDA
      ,pn_tenancies_all         PTA
      ,pn_locations_all         PNLA
      ,pn_addresses_all         PAA
      ,fnd_territories_tl       FTT
      ,pn_payment_terms_all     PPTA
      ,pn_payment_items_all     PPIA
      ,pn_payment_schedules_all PPSA
      ,pn_distributions_all     PDA
      ,gl_code_combinations     GCC
      ,ap_suppliers             APS
      ,ap_supplier_sites_all    ASSA
WHERE 1                         = 1
  AND pla.lease_id       NOT IN (SELECT ppta.lease_id FROM pn_payment_terms_all ppta)
  AND PLA.lease_id              = PLDA.lease_id
  AND PLA.lease_id              = PPTA.lease_id
  AND PLA.lease_id              = PTA.lease_id
  AND PTA.location_id           = PNLA.location_id
  AND PNLA.address_id           = PAA.address_id
  AND FTT.territory_code        = PAA.country
  AND PPTA.payment_term_id      = PPIA.payment_term_id(+)
  AND PPIA.payment_schedule_id  = PPSA.payment_schedule_id(+)
  AND PPSA.lease_id             = PLA.lease_id
  AND PPTA.payment_term_id      = PDA.payment_term_id (+)
  AND GCC.code_combination_id   = PDA.account_id
  AND PPIA.vendor_id            = APS.vendor_id
  AND PPIA.vendor_site_id       = ASSA.vendor_site_id
  AND PPTA.payment_purpose_code = 'RENT'
  AND PDA.account_class         = 'EXP'
  AND PLA.lease_status          <>  'TER'
  HAVING MAX(PPTA.end_date) BETWEEN ADD_MONTHS(SYSDATE,-1) AND SYSDATE
 -- AND PLA.lease_id = 16004
  --and payment_status_lookup_code = 'APPROVED'
 GROUP BY  GCC.segment4 
      ,PLA.lease_id
      ,PPTA.end_date
      ,PLDA.attribute7
      ,PAA.address_line1
      ,PAA.address_line2
      ,PAA.address_line3
      ,PAA.address_line4
      ,PAA.city
      ,PAA.state
      ,PAA.zip_code 
      ,APS.vendor_name     
      ,ASSA.vendor_site_code
      ,PPTA.end_date
      ,PPTA.frequency_code
      ,PLA.lease_type_code