Skip to content

Commit

Permalink
Add support for tax codes
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Dec 6, 2024
1 parent eb80c46 commit c4a67f7
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 1 deletion.
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;

private static void createVersionTable(Connection c, int version) throws SQLException {
Statement s2 = c.createStatement();
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?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ private fun parsePrice(json: JSONObject): BigDecimal? {
}
}

private fun parseTaxCode(json: JSONObject): String? {
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 (
?,
?,
?,
?,
?
);
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

0 comments on commit c4a67f7

Please sign in to comment.