IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0VAA0SearchCancelledPayments')
BEGIN
DROP VIEW LD0VAA0SearchCancelledPayments
END
GO

CREATE VIEW LD0VAA0SearchCancelledPayments AS 
SELECT
F.BETALNR,
F.KONTONR,
F.BELOPP,
F.NAMN AS BETNAMN,
F.ADRESS AS BETADRESS,
F.ORT AS BETORT,
F.POSTNR AS BETPOSTNR,
F.COADR AS BETCOADR,
F.LOKBET,
F.FEL,
F.STATUS AS BETSTATUS,
F.BETTYP,
Q01_1.KLARTEXT AS BETTYP_T,
F.BETSATT,
Q01.KLARTEXT AS BETSATT_T,
F.CLEAR,
F.BESFATT,
F.OCR,
F.UPDSIGN,
F.UPDDAT,
F.INTDAT,
F.MAKDAT,
F.MAKSIGN,
F.AVSERMANAD,
F.BETDAT AS BETALDATUM,
F.BETMED,
F.VERNR AS VERIFIKAT,
F.RAKNNR AS RAKNINGSNR,
F.BOKDAT AS BOKDATUM,
F.EJINT AS BOKFORING
FROM LD0VYF F 
LEFT OUTER JOIN LD0V0Q01 Q01 ON Q01.KODTYP = 'BETALSATT' AND Q01.KOD = F.BETSATT 
LEFT OUTER JOIN LD0V0Q01 Q01_1 ON Q01_1.KODTYP = 'BETALTYP' AND Q01_1.KOD = F.BETTYP 
WHERE (F.BETTYP <> 90) AND (F.BETSATT > 0) AND (F.BETSATT < 90) AND (F.STATUS = 9) 
GO

GRANT SELECT ON LD0VAA0SearchCancelledPayments TO LD0ROANV
GO

IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0VAA0SearchCancelledRequisitions')
BEGIN
DROP VIEW LD0VAA0SearchCancelledRequisitions
END
GO
CREATE VIEW LD0VAA0SearchCancelledRequisitions
AS
SELECT G.REKVID, G.REKVVEM, G.REKVHOS, G.DATUM, G.BELOPP, G.MAKDAT, G.MAKSIGN, G.UPDDAT, G.UPDSIGN,
G04.FAKTNR, G04.FAKTDAT, G04.FAKTBEL 
FROM 
LD0VYG G 
LEFT JOIN LD0V0G04 G04 ON G.REKVNR = G04.ReKVNR
where G.MAKULERAD = 1
GO
GRANT ALL ON LD0VAA0SearchCancelledRequisitions TO LD0ROANV
GO

IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0VAA0SEARCHSALARY')
BEGIN
DROP VIEW LD0VAA0SEARCHSALARY
END
GO

CREATE VIEW LD0VAA0SEARCHSALARY
AS SELECT
L50.*
,L.PNR as RESOURCEPERSONID
,L.RESURSBEN as RESOURCENAME
,L01.RESURSTYP_T as ASRESURSTYP_T
,C20.AKTPNR as CLIENTPERSONID
,C20.FOMDAT as SERVICE_FOMDAT
,C20.INSTYP_T
,N70.RESURSTYP_T
,N70.LOENID
,A.NAMN
,PER.KUNDNUMMER
,Q01.KLARTEXT as ARVODERING_T
FROM LD0V0L50 L50
LEFT OUTER JOIN LD0VAAYRESOURCEALLOCATION N70 ON N70.RESTILLDNR = L50.RESTILLDNR
LEFT OUTER JOIN LD0VAAYSERVICES AS C20 ON C20.INSNR = N70.INSNR
LEFT OUTER JOIN LD0P0L AS L ON L.RESURSNR = L50.RESURSNR
LEFT OUTER JOIN LD0VAA0RESOURCEAS AS L01 ON L01.RESURSSOMNR = L50.RESURSSOMNR
LEFT OUTER JOIN LD0P0A AS A ON A.PNR = C20.AKTPNR
LEFT OUTER JOIN LD0P0A AS PER ON PER.PNR = L50.PNR
LEFT OUTER JOIN LD0V0Q01 Q01 ON Q01.KODTYP = 'ARVODERING' AND Q01.KOD = L50.ARVODERING
GO

GRANT SELECT ON LD0VAA0SEARCHSALARY TO LD0ROANV
GO

IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0VAA0SearchCancelledInpayments')
BEGIN
DROP VIEW LD0VAA0SearchCancelledInpayments
END
GO

CREATE VIEW LD0VAA0SearchCancelledInpayments AS
SELECT 
F.BETALNR,                      --Betalnummer
F.BELOPP,                       --Belopp
F.FEL,                          --Fel
Q01.KLARTEXT AS BETTYP_T,       --Betaltyp
F.INBTYP,                       --Inbetalningstyp
F.UPDSIGN,                      --Uppdaterings signatur
F.UPDDAT,                       --Uppdaterings datum
F.INTDAT,                       --Intdatum (Integrationsdatum)
F.BETDAT AS BETALDATUM,         --Betaldatum
F.BETMED,                       --Meddelande
F.VERNR AS VERIFIKAT,           --Verifikat (verifikationsnummer)
F.BOKDAT AS BOKDATUM,           --Bokföringsdatum
F.EJINT AS BOKFORING,           --Bokföring
F.MAKDAT,                       --Makuleringsdatum
F.MAKSIGN                       --Makuleringssignatur
FROM LD0VYF AS F 
LEFT OUTER JOIN LD0V0Q01 AS Q01 
ON Q01.KODTYP = 'BETALTYP' 
AND Q01.KOD = F.BETTYP 
WHERE (F.BETTYP <> 90) AND (F.BETSATT = 90) AND (F.STATUS = 9) 
GO

GRANT ALL ON LD0VAA0SearchCancelledInpayments TO LD0ROANV
GO
