-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAR-CustomerCard-Card-View.sql
51 lines (51 loc) · 2.02 KB
/
AR-CustomerCard-Card-View.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
SELECT gbkmut.datum,
gbkmut.ID,
gbkmut.bkstnr,
gbkmut.faktuurnr,
gbkmut.docnumber,
gbkmut.oms25,
(CASE WHEN gbkmut.documentID IS NULL THEN 0 ELSE 1 END) AS Note,
(CASE WHEN gbkmut.docattachmentID IS NULL THEN 0 ELSE 1 END) AS Attach,
ROUND(((CASE WHEN transsubtype NOT IN ('R','S') THEN CASE WHEN bdr_hfl >= 0 THEN bdr_hfl ELSE NULL END ELSE CASE WHEN bdr_hfl < 0 THEN bdr_hfl ELSE NULL END END)), 2) AS Debit,
ROUND(((CASE WHEN transsubtype NOT IN ('R','S') THEN CASE WHEN bdr_hfl >= 0 THEN NULL ELSE -bdr_hfl END ELSE CASE WHEN bdr_hfl < 0 THEN NULL ELSE -bdr_hfl END END)), 2) AS Credit,
gbkmut.transsubtype,
gbkmut.valcode,
gbkmut.bdr_val,
gbkmut.docdate,
grtbk.oms25_0 AS MyOms,
Dagbk.afk,
gbkmut.btw_code,
gbkmut.tegreknr,
gbkmut.betcond,
gbkmut.btwper,
gbkmut.artcode,
gbkmut.transtype,
gbkmut.bankacc,
gbkmut.project,
gbkmut.facode,
gbkmut.bkstnr_sub,
gbkmut.reknr,
humres.fullname,
(CASE WHEN reminderlayout = 0 THEN 1 ELSE reminderlayout END) AS Reminderlayout,
gbkmut.syscreated,
c1.debcode,
gbkmut.verwerknrl,
gbkmut.betaalref,
gbkmut.kstplcode,
gbkmut.kstdrcode,
(CASE WHEN gbkmut.koers = 0 THEN CONVERT(VARCHAR(20),ROUND(gbkmut.koers,5))
ELSE (CASE WHEN 1/gbkmut.koers > 10000 THEN '1/' + CONVERT(VARCHAR(20), ROUND(1/gbkmut.koers,5))
ELSE CONVERT(VARCHAR(20), ROUND(gbkmut.koers,5))
END)
END) AS Koers
FROM gbkmut INNER JOIN dagbk ON gbkmut.dagbknr = dagbk.dagbknr
INNER JOIN grtbk ON gbkmut.reknr = grtbk.reknr
LEFT OUTER JOIN humres ON gbkmut.res_id = humres.res_id AND gbkmut.res_id IS NOT NULL
LEFT OUTER JOIN cicmpy c1 ON gbkmut.debnr = c1.debnr AND gbkmut.debnr IS NOT NULL AND c1.debnr IS NOT NULL
WHERE gbkmut.debnr = ' 32409'
AND grtbk.omzrek = 'D'
AND gbkmut.transtype IN ('N', 'C', 'P')
AND gbkmut.datum >= {d '2012-02-01'}
AND gbkmut.datum <= {d '2012-05-01'}
AND remindercount <= 13
ORDER BY gbkmut.datum, gbkmut.id