Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tax codes #50

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public BigDecimal getPrice() {
}
}

public String getTaxCode() {
try {
return getJSON().optString("tax_code", null);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}

public BigDecimal getTaxRate() {
try {
return new BigDecimal(getJSON().getString("tax_rate"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class AbstractReceiptLine implements LocalObject {

public Long tax_rule;

public String tax_code;

public BigDecimal tax_value;

@Nullable
Expand Down Expand Up @@ -196,6 +198,7 @@ public JSONObject toJSON() throws JSONException {
jo.put("tax_rate", tax_rate != null ? tax_rate.setScale(2, RoundingMode.HALF_UP) : "0.00");
jo.put("tax_value", tax_value != null ? tax_value.setScale(2, RoundingMode.HALF_UP) : "0.00");
jo.put("tax_rule", tax_rule != null ? tax_rule : JSONObject.NULL);
jo.put("tax_code", tax_code != null ? tax_code : JSONObject.NULL);
jo.put("secret", secret);
jo.put("seat", seat_guid != null ? seat_guid : JSONObject.NULL);
jo.put("subevent", subevent_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ public boolean includesTax() {
}
}

public String getCode() {
try {
if (!getJSON().has("code") || getJSON().isNull("code")) {
return null;
}
return getJSON().getString("code");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}

public BigDecimal getRate() {
try {
return new BigDecimal(getJSON().getString("rate"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class Migrations {
private static EntityModel model = Models.DEFAULT;
public static int CURRENT_VERSION = 105;
public static int CURRENT_VERSION = 106;
robbi5 marked this conversation as resolved.
Show resolved Hide resolved

private static void createVersionTable(Connection c, int version) throws SQLException {
Statement s2 = c.createStatement();
Expand Down Expand Up @@ -430,6 +430,10 @@ public static void migrate(DataSource dataSource, boolean dbIsNew) throws SQLExc
execIgnore(c, "ALTER TABLE settings DROP COLUMN covid_certificates_allow_vaccinated_products;", new String[] {"no such column", "existiert", "syntax error"});
updateVersionTable(c, 105);
}
if (db_version < 106) {
execIgnore(c, "ALTER TABLE receiptline ADD tax_code TEXT NULL;", new String[] {"duplicate column name", "already exists", "existiert bereits"});
updateVersionTable(c, 106);
}

// Note that the Android app currently does not use these queries!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class OrderPosition(
val price: BigDecimal? = null,
val taxRate: BigDecimal? = null,
val taxValue: BigDecimal? = null,
val taxCode: String? = null,
val seatName: String? = null,
val addonToServerId: Long? = null,
val blocked: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data class ReceiptLine(
val taxRate: BigDecimal? = null,
val taxRule: Long? = null,
val taxValue: BigDecimal? = null,
val taxCode: String? = null,
val eventDateFrom: OffsetDateTime? = null,
val eventDateTo: OffsetDateTime? = null,
val subEventServerId: Long? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ data class TaxRule(
val serverId: Long,
val rate: BigDecimal = BigDecimal("0.00"),
val includesTax: Boolean = false,
val code: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fun OrderPosition.toModel(): OrderPositionModel {
zipcode = json.optString("zipcode", null),
price = parsePrice(json),
taxRate = parseTaxRate(json),
taxCode = parseTaxCode(json),
taxValue = parseTaxValue(json),
seatName = parseSeatName(json),
addonToServerId = parseAddonToServerId(json),
Expand All @@ -50,6 +51,15 @@ private fun parsePrice(json: JSONObject): BigDecimal? {
}
}

private fun parseTaxCode(json: JSONObject): String? {
robbi5 marked this conversation as resolved.
Show resolved Hide resolved
try {
return json.optString("tax_code", null)
} catch (e: JSONException) {
e.printStackTrace()
return null
}
}

private fun parseTaxRate(json: JSONObject): BigDecimal? {
try {
return BigDecimal(json.getString("tax_rate"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun ReceiptLine.toModel() =
voucherCode = voucher_code,
useReusableMedium = use_reusable_medium,
taxRate = tax_rate,
taxCode = tax_code,
taxRule = tax_rule,
taxValue = tax_value,
eventDateFrom = SafeOffsetDateTimeMapper.decode(event_date_from),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fun TaxRule.toModel(): TaxRuleModel {
serverId = this.server_id!!,
rate = parseRate(json),
includesTax = parseIncludesTax(json),
code = parseCode(json),
)
}

Expand All @@ -34,3 +35,15 @@ private fun parseIncludesTax(json: JSONObject): Boolean {
return false
}
}

private fun parseCode(json: JSONObject): String? {
try {
if (!json.has("code") or json.isNull("code")) {
return null
}
return json.getString("code")
} catch (e: JSONException) {
e.printStackTrace()
return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fun ReceiptLine.toJSON(): JSONObject {
jo.put("tax_rate", tax_rate?.setScale(2, RoundingMode.HALF_UP))
jo.put("tax_value", tax_value?.setScale(2, RoundingMode.HALF_UP) ?: "0.00")
jo.put("tax_rule", tax_rule ?: JSONObject.NULL)
jo.put("tax_code", tax_code ?: JSONObject.NULL)
jo.put("secret", secret)
jo.put("seat", seat_guid ?: JSONObject.NULL)
jo.put("subevent", subevent_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ INSERT INTO ReceiptLine (
tax_rate,
tax_rule,
tax_value,
tax_code,
type,
use_reusable_medium,
variation_id,
Expand Down Expand Up @@ -97,5 +98,6 @@ VALUES (
?,
?,
?,
?,
?
);
1 change: 1 addition & 0 deletions libpretixsync/src/main/sqldelight/migrations/105.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Empty migration to set database version to 106
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CREATE TABLE ReceiptLine (
tax_rate numeric,
tax_rule bigint,
tax_value numeric,
tax_code character varying(255),
type character varying(255),
use_reusable_medium bigint,
variation_id bigint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ CREATE TABLE ReceiptLine (
tax_rate REAL AS BigDecimal,
tax_rule INTEGER,
tax_value REAL AS BigDecimal,
tax_code TEXT,
type TEXT,
use_reusable_medium INTEGER,
variation_id INTEGER,
Expand Down