DROP VIEW LD0VAA0RHOFFERINFO
;
CREATE VIEW LD0VAA0RHOFFERINFO
AS 
SELECT  
OFFER.OFFERID,
OFFER.ACCEPTANCE,
OFFER.NOTE,
OFFER.REJECTIONREASON,
OFFER.ACCOMODATIONID,
OFFER.APPLICATIONID,
OFFER.CREATEDDATE,
OFFER.UPDATEDDATE,
OFFER.UPDATEDSIGNATURE, 
OFFER.ACCEPTANCE ACCEPTANCE_T,
P.NAMN APPLICANTNAME_T, 
P.KUNDNUMMER APPLICANTPERSONKEY_T,
C.NAMN COAPPLICANTNAME_T,
T1.KLARTEXT ACCOMODATIONTYPE_T ,
T2.KLARTEXT REJECTIONREASON_T,
T3.KLARTEXT APPLICATIONENDREASON_T,
APP.ENDREASON APPLICATIONENDREASONID_T, 
APP.ENDDATE APPLICATIONENDDATE_T, 
APP.APPLICANTID APPLICANTID_T
FROM LD0PAA0RHOFFER OFFER  
INNER JOIN LD0VAA0RHACCOMODATION ACC 
ON ACC.ACCOMODATIONID = OFFER.ACCOMODATIONID  
INNER JOIN LD0VAA0RHAPPLICATION APP 
ON APP.APPLICATIONID = OFFER.APPLICATIONID    
INNER JOIN LD0P0A P 
ON APP.APPLICANTID = P.PNR    
LEFT JOIN LD0P0A C 
ON APP.COAPPLICANTID = C.PNR   
LEFT JOIN LD0V0Q01 T1 
ON T1.KODTYP ='RHACCTYP' 
AND T1.KOD = ACC.APARTMENTSIZE 
LEFT JOIN LD0V0Q01 T2 
ON T2.KODTYP ='RHOFFREJ' 
AND T2.KOD = OFFER.REJECTIONREASON 
LEFT JOIN LD0V0Q01 T3 
ON T3.KODTYP ='RHENDAPP' 
AND T3.KOD = APP.ENDREASON
;