Skip to content
Draft
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 @@ -29,6 +29,7 @@ data class Receipt(
val closing: Long? = null,
val additionalText: String? = null,
val webSecret: String? = null,
val taxRoundingMode: String = "line",
) {
enum class PaymentType(val value: String) {
CASH("cash"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class ReceiptLine(
val positionId: Long,
val type: Type,
val price: BigDecimal,
val priceIncludesRoundingCorrection: BigDecimal = BigDecimal("0.00"),
val listedPrice: BigDecimal? = null,
val priceAfterVoucher: BigDecimal? = null,
val customPriceInput: BigDecimal? = null,
Expand All @@ -28,6 +29,7 @@ data class ReceiptLine(
val taxRate: BigDecimal? = null,
val taxRule: Long? = null,
val taxValue: BigDecimal? = null,
val taxValueIncludesRoundingCorrection: BigDecimal = BigDecimal("0.00"),
val taxCode: String? = null,
val eventDateFrom: OffsetDateTime? = null,
val eventDateTo: OffsetDateTime? = null,
Expand Down Expand Up @@ -82,6 +84,10 @@ data class ReceiptLine(
}
}

val grossPriceBeforeRounding = price - priceIncludesRoundingCorrection
val taxValueBeforeRounding = (taxValue ?: BigDecimal.ZERO) - taxValueIncludesRoundingCorrection
val netPriceBeforeRounding = grossPriceBeforeRounding - (taxValueBeforeRounding ?: BigDecimal.ZERO)

val hasAttendeeData: Boolean
get() = !attendeeName.isNullOrEmpty() ||
!attendeeEmail.isNullOrEmpty() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ fun Receipt.toModel() =
orderEmail = order_email,
orderPhone = order_phone,
webSecret = websecret,
taxRoundingMode = tax_rounding_mode,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fun ReceiptLine.toModel() =
positionId = positionid!!,
type = ReceiptLineModel.Type.valueOf(type!!),
price = price!!,
priceIncludesRoundingCorrection = price_includes_rounding_correction!!,
listedPrice = listed_price,
priceAfterVoucher = price_after_voucher,
customPriceInput = custom_price_input,
Expand All @@ -28,6 +29,7 @@ fun ReceiptLine.toModel() =
taxCode = tax_code,
taxRule = tax_rule,
taxValue = tax_value,
taxValueIncludesRoundingCorrection = tax_value_includes_rounding_correction,
eventDateFrom = SafeOffsetDateTimeMapper.decode(event_date_from),
eventDateTo = SafeOffsetDateTimeMapper.decode(event_date_to),
subEventServerId = subevent_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fun Receipt.toJSON(): JSONObject {
jo.put("training", training)
jo.put("additional_text", additional_text)
jo.put("web_secret", if (websecret != null) websecret else JSONObject.NULL)
jo.put("tax_rounding_mode", if (tax_rounding_mode != null) tax_rounding_mode else JSONObject.NULL)

// the following columns are not persisted on the server,
// but only used locally to act as holders of data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ fun ReceiptLine.toJSON(): JSONObject {
jo.put("custom_price_input", custom_price_input?.setScale(2, RoundingMode.HALF_UP))
jo.put("voucher_code", voucher_code)
jo.put("price", price?.setScale(2, RoundingMode.HALF_UP))
jo.put("price_includes_rounding_correction", price_includes_rounding_correction?.setScale(2, RoundingMode.HALF_UP))
jo.put("tax_rate", tax_rate?.setScale(4, RoundingMode.HALF_UP))
jo.put("tax_value", tax_value?.setScale(2, RoundingMode.HALF_UP) ?: "0.00")
jo.put("tax_value_includes_rounding_correction", tax_value_includes_rounding_correction?.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ INSERT INTO Receipt (
server_id,
started,
training,
websecret
websecret,
tax_rounding_mode
)
VALUES (
?,
Expand Down Expand Up @@ -69,6 +70,7 @@ VALUES (
?,
?,
?,
?,
?

);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ INSERT INTO ReceiptLine (
listed_price,
positionid,
price,
price_includes_rounding_correction,
price_after_voucher,
price_calculated_from_net,
receipt,
Expand All @@ -54,6 +55,7 @@ INSERT INTO ReceiptLine (
tax_rate,
tax_rule,
tax_value,
tax_value_includes_rounding_correction,
tax_code,
type,
use_reusable_medium,
Expand Down Expand Up @@ -110,5 +112,7 @@ VALUES (
?,
?,
?,
?,
?,
?
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CREATE TABLE Receipt (
started boolean DEFAULT FALSE,
training boolean DEFAULT FALSE NOT NULL,
closing bigint REFERENCES Closing (id) ON DELETE CASCADE,
websecret character varying(255)
websecret character varying(255),
tax_rounding_mode character varying(255) DEFAULT 'line' NOT NULL
);

CREATE INDEX Receipt_closing_index ON Receipt (closing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CREATE TABLE ReceiptLine (
listed_price numeric,
positionid bigint,
price numeric,
price_includes_rounding_correction numeric DEFAULT 0 NOT NULL,
price_after_voucher numeric,
price_calculated_from_net boolean DEFAULT FALSE,
remote_error character varying(255),
Expand All @@ -40,6 +41,7 @@ CREATE TABLE ReceiptLine (
tax_rate numeric,
tax_rule bigint,
tax_value numeric,
tax_value_includes_rounding_correction numeric DEFAULT 0 NOT NULL,
tax_code character varying(255),
type character varying(255),
use_reusable_medium bigint,
Expand Down
3 changes: 3 additions & 0 deletions libpretixsync/src/main/sqldelight/postgres/migrations/121.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE ReceiptLine ADD price_includes_rounding_correction numeric DEFAULT 0 NOT NULL;
ALTER TABLE ReceiptLine ADD tax_value_includes_rounding_correction numeric DEFAULT 0 NOT NULL;
ALTER TABLE Receipt ADD tax_rounding_mode character varying(255) DEFAULT 'line' NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CREATE TABLE Receipt (
server_id INTEGER,
started INTEGER AS Boolean DEFAULT 0,
training INTEGER AS Boolean DEFAULT 0 NOT NULL,
websecret TEXT
websecret TEXT,
tax_rounding_mode TEXT DEFAULT 'line' NOT NULL
);

CREATE INDEX Receipt_closing_index ON Receipt (closing);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import eu.pretix.libpretixsync.sqldelight.BigDecimalAdapter;
import java.math.BigDecimal;
import java.util.Date;
import kotlin.Boolean;
Expand Down Expand Up @@ -29,6 +30,7 @@ CREATE TABLE ReceiptLine (
listed_price REAL AS BigDecimal,
positionid INTEGER,
price REAL AS BigDecimal,
price_includes_rounding_correction REAL AS BigDecimal DEFAULT 0 NOT NULL,
price_after_voucher REAL AS BigDecimal,
price_calculated_from_net INTEGER AS Boolean DEFAULT 0,
receipt INTEGER REFERENCES Receipt (id) ON DELETE CASCADE,
Expand All @@ -43,6 +45,7 @@ CREATE TABLE ReceiptLine (
tax_rate REAL AS BigDecimal,
tax_rule INTEGER,
tax_value REAL AS BigDecimal,
tax_value_includes_rounding_correction REAL AS BigDecimal DEFAULT 0 NOT NULL,
tax_code TEXT,
type TEXT,
use_reusable_medium INTEGER,
Expand Down
5 changes: 5 additions & 0 deletions libpretixsync/src/main/sqldelight/sqlite/migrations/121.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import java.math.BigDecimal;

ALTER TABLE ReceiptLine ADD price_includes_rounding_correction REAL AS BigDecimal DEFAULT 0 NOT NULL;
ALTER TABLE ReceiptLine ADD tax_value_includes_rounding_correction REAL AS BigDecimal DEFAULT 0 NOT NULL;
ALTER TABLE Receipt ADD tax_rounding_mode TEXT DEFAULT 'line' NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public void setUpDb() throws NoSuchAlgorithmException {
bigDecimalAdapter,
bigDecimalAdapter,
bigDecimalAdapter,
bigDecimalAdapter,
bigDecimalAdapter,
bigDecimalAdapter
),
new ReceiptPayment.Adapter(
Expand Down
Loading