Skip to content

Commit

Permalink
Included review comment in completereceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
akselsf committed Oct 12, 2024
1 parent 06909f6 commit 22ac994
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 47 deletions.
95 changes: 49 additions & 46 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ CREATE TABLE receipt
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
amount DECIMAL(10, 2) NOT NULL,
committee_id INT NOT NULL references committee (id),
committee_id INT NOT NULL references committee (id),
name VARCHAR(255) NOT NULL,
description VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
description VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
onlineuser_id INT NOT NULL references onlineuser (id),
);

CREATE TABLE attachment
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
receipt_id INT NOT NULL references receipt (id),
name VARCHAR(255) NOT NULL,
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
receipt_id INT NOT NULL references receipt (id),
name VARCHAR(255) NOT NULL,
);


Expand All @@ -53,10 +53,10 @@ CREATE TABLE economicrequest
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
subject VARCHAR(55) NOT NULL,
purpose VARCHAR(500) NOT NULL,
purpose VARCHAR(500) NOT NULL,
date DATE NOT NULL,
duration VARCHAR(255) NOT NULL,
description VARCHAR(500) NOT NULL,
description VARCHAR(500) NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
personcount INT NOT NULL,
names VARCHAR(500) NOT NULL,
Expand All @@ -68,45 +68,48 @@ CREATE TABLE economicrequest

CREATE TABLE receiptreview
(
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
receipt_id INT NOT NULL references receipt (id),
status VARCHAR(20) NOT NULL CHECK (status IN('APPROVED', 'DENIED')),
comment VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
onlineuser_id INT NOT NULL references onlineuser (id),
id INT NOT NULL PRIMARY KEY IDENTITY (1,1),
receipt_id INT NOT NULL references receipt (id),
status VARCHAR(20) NOT NULL CHECK (status IN ('APPROVED', 'DENIED')),
comment VARCHAR(500) NOT NULL,
createdat DATETIME NOT NULL,
onlineuser_id INT NOT NULL references onlineuser (id),
);

CREATE VIEW receipt_info AS
SELECT
r.id AS receipt_id,
r.amount,
MAX(r.name) AS receipt_name,
MAX(r.description) AS receipt_description,
MAX(r.createdat) AS receipt_created_at,
MAX(c.name) AS committee_name,
MAX(ou.fullname) AS user_fullname,

CASE
WHEN MAX(p.id) IS NOT NULL THEN 'Payment'
WHEN MAX(ca.id) IS NOT NULL THEN 'Card'
ELSE 'None'
END AS payment_or_card,

COUNT(a.id) AS attachment_count

FROM
receipt r
LEFT JOIN
committee c ON r.committee_id = c.id
LEFT JOIN
onlineuser ou ON r.onlineuser_id = ou.id
LEFT JOIN
payment p ON r.id = p.receipt_id
LEFT JOIN
card ca ON r.id = ca.receipt_id
LEFT JOIN
attachment a ON r.id = a.receipt_id
GROUP BY
r.id, r.amount;

SELECT r.id AS receipt_id,
r.amount,
MAX(r.name) AS receipt_name,
MAX(r.description) AS receipt_description,
MAX(r.createdat) AS receipt_created_at,
MAX(c.name) AS committee_name,
MAX(ou.fullname) AS user_fullname,

CASE
WHEN MAX(p.id) IS NOT NULL THEN 'Payment'
WHEN MAX(ca.id) IS NOT NULL THEN 'Card'
ELSE 'None'
END AS payment_or_card,

COUNT(a.id) AS attachment_count,

MAX(rr.status) AS latest_review_status,
MAX(rr.createdat) AS latest_review_created_at,
MAX(rr.comment) AS latest_review_comment

FROM receipt r
LEFT JOIN committee c ON r.committee_id = c.id
LEFT JOIN onlineuser ou ON r.onlineuser_id = ou.id
LEFT JOIN payment p ON r.id = p.receipt_id
LEFT JOIN card ca ON r.id = ca.receipt_id
LEFT JOIN attachment a ON r.id = a.receipt_id
LEFT JOIN receiptreview rr ON r.id = rr.receipt_id
LEFT JOIN (
SELECT receipt_id, MAX(createdat) AS max_createdat
FROM receiptreview
GROUP BY receipt_id
) latest_review ON rr.receipt_id = latest_review.receipt_id
AND rr.createdat = latest_review.max_createdat

GROUP BY r.id, r.amount;

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ data class CompleteReceipt(

val latestReviewCreatedAt: LocalDateTime?,

val latestReviewComment: String?,

val paymentAccountNumber: String,


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ class ReceiptInfo(
val latestReviewStatus: String,

@Column(name = "latest_review_created_at")
val latestReviewCreatedAt: LocalDateTime
val latestReviewCreatedAt: LocalDateTime,

@Column(name = "latest_review_comment")
val latestReviewComment: String,

)
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ReceiptAdminService {
receipt.attachmentCount,
receipt.latestReviewStatus,
receipt.latestReviewCreatedAt,
receipt.latestReviewComment,
payment.account_number,
card.card_number,
images
Expand Down

0 comments on commit 22ac994

Please sign in to comment.