Skip to content

Commit 8a61857

Browse files
committed
count unpaid invoices
1 parent e9e2ac3 commit 8a61857

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/Invoice.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,19 @@ public void update() {
234234
return new @NotNull Invoice[0];
235235
}
236236
}
237+
238+
public static int countUnpaid(final @NotNull OfflinePlayer player) {
239+
try (final @NotNull Connection conn = BankAccounts.getInstance().getDb().getConnection();
240+
final @NotNull PreparedStatement stmt = conn.prepareStatement("SELECT COUNT(`id`) as `count` FROM `bank_invoices` WHERE `buyer` = ? AND `transaction` IS NULL")) {
241+
stmt.setString(1, player.getUniqueId().toString());
242+
243+
final @NotNull ResultSet rs = stmt.executeQuery();
244+
if (rs.next()) return rs.getInt("count");
245+
return 0;
246+
}
247+
catch (final @NotNull SQLException e) {
248+
BankAccounts.getInstance().getLogger().log(Level.SEVERE, "Could not count unpaid invoices for player: " + player.getUniqueId(), e);
249+
return 0;
250+
}
251+
}
237252
}

0 commit comments

Comments
 (0)