diff --git a/crates/db/migrations/0027_stripe_checkouts.sql b/crates/db/migrations/0027_stripe_checkouts.sql index c26c0ff..bd5e4b0 100644 --- a/crates/db/migrations/0027_stripe_checkouts.sql +++ b/crates/db/migrations/0027_stripe_checkouts.sql @@ -48,12 +48,13 @@ CREATE TABLE invoices ( -- Billingo's partner tax type: HAS_TAX_NUMBER, NO_TAX_NUMBER or FOREIGN. buyer_tax_type text NOT NULL CHECK (buyer_tax_type IN ('HAS_TAX_NUMBER', 'NO_TAX_NUMBER', 'FOREIGN')), buyer_tax_number text, - -- The single item, gross price with 27% VAT. + -- The single item. vat_rate is Billingo's VAT value: AAM (alanyi + -- adómentes: net = gross, no VAT) or a rate like 27%. item_name text NOT NULL, gross_huf integer NOT NULL CHECK (gross_huf > 0), net_huf integer NOT NULL, vat_huf integer NOT NULL, - vat_rate text NOT NULL DEFAULT '27%', + vat_rate text NOT NULL DEFAULT 'AAM', payment_method text NOT NULL DEFAULT 'online_bankcard', -- From Billingo. billingo_partner_id bigint, diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 4f730fe..e2d30d2 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -91,6 +91,8 @@ services: # Stripe purchases for everyone (false: admins only, until the opening; # with a test key always admins only). PURCHASES_OPEN: ${PURCHASES_OPEN:-false} + # VAT on the invoices: AAM (alanyi adómentes) or a rate like 27%. + INVOICE_VAT: ${INVOICE_VAT:-AAM} # Users inviting others ("Meghívom"): shown but off until the launch. USER_INVITES: ${USER_INVITES:-false} # A new user from a shared link earns the sharer an analysis: off until sign-up opens. diff --git a/docker-compose.yml b/docker-compose.yml index 43267c0..f19fd64 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,6 +58,8 @@ services: # Stripe purchases for everyone (false: admins only, until the opening; # with a test key always admins only). PURCHASES_OPEN: ${PURCHASES_OPEN:-false} + # VAT on the invoices: AAM (alanyi adómentes) or a rate like 27%. + INVOICE_VAT: ${INVOICE_VAT:-AAM} FREE_PERSON_SLOTS: ${FREE_PERSON_SLOTS:-0} # invite: new accounts need an invitation (admin page "Meghívók"); open: anyone. SIGNUP_MODE: ${SIGNUP_MODE:-invite} diff --git a/docs/csomagok.md b/docs/csomagok.md index 71b7afe..1eaddc2 100644 --- a/docs/csomagok.md +++ b/docs/csomagok.md @@ -4,7 +4,7 @@ A katalógus a kódban van: `services/backend/src/packages.rs` (`CATALOG`). Ár- ## Költség -Egy részletes képletelemzés és egy kapcsolati elemzés is kb. **$0,21 (≈ 80 Ft)** Opus 5.5-tel, az éves előrejelzés a hosszabb adatsor miatt valamivel több; a rövid összefoglaló kb. $0,01. A fizetési szolgáltató díja kb. 1,5% + 85 Ft tranzakciónként. Az árak bruttók (27% áfa). +Egy részletes képletelemzés és egy kapcsolati elemzés is kb. **$0,21 (≈ 80 Ft)** Opus 5.5-tel, az éves előrejelzés a hosszabb adatsor miatt valamivel több; a rövid összefoglaló kb. $0,01. A fizetési szolgáltató díja kb. 1,5% + 85 Ft tranzakciónként. Az árak végső árak: alanyi adómentesek vagyunk (`INVOICE_VAT=AAM`), áfát nem számítunk fel; ha átlépjük az alanyi adómentesség határát, `INVOICE_VAT=27%`, és az árak bruttóként értendők. ## A lépcső diff --git a/docs/fizetes.md b/docs/fizetes.md index 0b7cc27..a21e9e6 100644 --- a/docs/fizetes.md +++ b/docs/fizetes.md @@ -26,7 +26,7 @@ A sorok a fiók törlése után is megmaradnak (`user_id` → NULL), mert a szá ## Számla -Fizetéskor a backend egy `invoices` sort is létrehoz a számla minden adatával: a vevő (név, e-mail, ország, irányítószám, város, cím, Billingo-adótípus: `HAS_TAX_NUMBER` / `NO_TAX_NUMBER` / `FOREIGN`, adószám) és a tétel (név, bruttó, nettó, áfa, 27%). Cégnél a `business_name` és a magyar adószám (`hu_tin`, ennek híján `eu_vat`) kerül a számlára. +Fizetéskor a backend egy `invoices` sort is létrehoz a számla minden adatával: a vevő (név, e-mail, ország, irányítószám, város, cím, Billingo-adótípus: `HAS_TAX_NUMBER` / `NO_TAX_NUMBER` / `FOREIGN`, adószám) és a tétel (név, végösszeg, nettó, áfa, áfakód). Az áfakód az `INVOICE_VAT` (a backend `.env`-je): alapból `AAM` (alanyi adómentes: nettó = végösszeg, áfa 0, a számla megjegyzésében „Alanyi adómentes.”), vagy egy kulcs, pl. `27%`. Cégnél a `business_name` és a magyar adószám (`hu_tin`, ennek híján `eu_vat`) kerül a számlára. A worker `invoices` feladata (`WORKER_TASKS`, prodon a `worker` konténerben) a Billingo API v3-mal: diff --git a/services/backend/src/config.rs b/services/backend/src/config.rs index 49163c4..1c76bb1 100644 --- a/services/backend/src/config.rs +++ b/services/backend/src/config.rs @@ -48,6 +48,8 @@ pub struct Config { /// Stripe Checkout, when `STRIPE_SECRET_KEY` is set (it wins over /// `MOCK_PAYMENTS`). pub stripe: Option, + /// `INVOICE_VAT` (default `AAM`, alanyi adómentes; or e.g. `27%`). + pub invoice_vat: crate::invoices::Vat, /// `BILLINGO_API_KEY`: downloading invoices (the worker issues them). pub billingo_api_key: Option, /// `BILLINGO_API_URL` (default `https://api.billingo.hu/v3`). @@ -174,6 +176,11 @@ impl Config { .trim_end_matches('/') .to_string(), }), + invoice_vat: match var("INVOICE_VAT") { + None => crate::invoices::Vat::Exempt, + Some(raw) => crate::invoices::Vat::parse(&raw) + .with_context(|| format!("invalid INVOICE_VAT '{raw}': use AAM or a rate like 27%"))?, + }, billingo_api_key: var("BILLINGO_API_KEY"), billingo_api_url: var("BILLINGO_API_URL") .unwrap_or_else(|| "https://api.billingo.hu/v3".into()) @@ -220,6 +227,7 @@ impl Config { password_login: true, mock_payments: true, stripe: None, + invoice_vat: crate::invoices::Vat::Exempt, billingo_api_key: Some("billingo-fake".into()), billingo_api_url: format!("{horoscope_api_url}/billingo"), purchases_open: true, diff --git a/services/backend/src/invoices.rs b/services/backend/src/invoices.rs index 66bf59f..ccba08d 100644 --- a/services/backend/src/invoices.rs +++ b/services/backend/src/invoices.rs @@ -9,8 +9,41 @@ use uuid::Uuid; use crate::error::ApiError; -/// VAT of every package, in percent. -pub const VAT_PERCENT: i64 = 27; +/// The VAT on the invoices (`INVOICE_VAT`): `AAM` (alanyi adómentes, subject +/// to the small business exemption: no VAT, net = gross) or a rate like `27%`. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Vat { + Exempt, + Percent(i64), +} + +impl Vat { + pub fn parse(raw: &str) -> Option { + match raw.trim() { + "AAM" => Some(Vat::Exempt), + rate => rate.strip_suffix('%')?.trim().parse().ok().filter(|p| (1..=27).contains(p)).map(Vat::Percent), + } + } + + /// Billingo's VAT value. + pub fn code(self) -> String { + match self { + Vat::Exempt => "AAM".into(), + Vat::Percent(p) => format!("{p}%"), + } + } + + /// Net and VAT parts of a gross price (rounded to forints, as Billingo does). + pub fn split(self, gross: i64) -> (i64, i64) { + match self { + Vat::Exempt => (gross, 0), + Vat::Percent(p) => { + let net = (gross * 200 + 100 + p) / (200 + 2 * p); + (net, gross - net) + } + } + } +} /// The buyer as invoiced, from Stripe's `customer_details`. #[derive(Debug, PartialEq, Eq)] @@ -61,12 +94,6 @@ impl Buyer { } } -/// Net and VAT parts of a gross price (rounded to forints, as Billingo does). -pub fn split_gross(gross: i64) -> (i64, i64) { - let net = (gross * 200 + 100 + VAT_PERCENT) / (200 + 2 * VAT_PERCENT); - (net, gross - net) -} - /// Queues the invoice of a paid checkout, inside the caller's transaction. pub async fn queue( tx: &mut PgConnection, @@ -75,9 +102,10 @@ pub async fn queue( buyer: &Buyer, item_name: &str, gross_huf: i64, + vat: Vat, ) -> Result { let id = Uuid::now_v7(); - let (net, vat) = split_gross(gross_huf); + let (net, vat_huf) = vat.split(gross_huf); sqlx::query( "INSERT INTO invoices (id, checkout_id, user_id, buyer_name, buyer_email, buyer_country, buyer_post_code, \ buyer_city, buyer_address, buyer_tax_type, buyer_tax_number, item_name, gross_huf, net_huf, vat_huf, vat_rate) \ @@ -98,8 +126,8 @@ pub async fn queue( .bind(item_name) .bind(gross_huf as i32) .bind(net as i32) - .bind(vat as i32) - .bind(format!("{VAT_PERCENT}%")) + .bind(vat_huf as i32) + .bind(vat.code()) .execute(&mut *tx) .await?; Ok(id) @@ -113,9 +141,16 @@ mod tests { #[test] fn gross_prices_split_into_net_and_vat() { - assert_eq!(split_gross(2000), (1575, 425)); - assert_eq!(split_gross(6000), (4724, 1276)); - assert_eq!(split_gross(127), (100, 27)); + let vat = Vat::parse("27%").unwrap(); + assert_eq!(vat.split(2000), (1575, 425)); + assert_eq!(vat.split(6000), (4724, 1276)); + assert_eq!(vat.split(127), (100, 27)); + assert_eq!(vat.code(), "27%"); + // Alanyi adómentes: no VAT at all. + assert_eq!(Vat::parse("AAM"), Some(Vat::Exempt)); + assert_eq!(Vat::Exempt.split(6000), (6000, 0)); + assert_eq!(Vat::parse("huszonhét"), None); + assert_eq!(Vat::parse("99%"), None); } #[test] diff --git a/services/backend/src/packages.rs b/services/backend/src/packages.rs index 8511eec..91f1341 100644 --- a/services/backend/src/packages.rs +++ b/services/backend/src/packages.rs @@ -37,7 +37,7 @@ pub struct Package { pub name: &'static str, pub tagline: &'static str, pub tier: Tier, - /// Gross price (27% VAT included). + /// The price paid (with VAT if `INVOICE_VAT` is a rate; none under AAM). pub price_huf: i64, pub natal: i64, pub synastry: i64, diff --git a/services/backend/src/routes/mod.rs b/services/backend/src/routes/mod.rs index fe3558d..64381c4 100644 --- a/services/backend/src/routes/mod.rs +++ b/services/backend/src/routes/mod.rs @@ -173,6 +173,8 @@ async fn public_config(State(state): St) -> Json { "payments": payments::method(c), "payments_admins_only": payments::admins_only(c), "payments_test": c.stripe.as_ref().is_some_and(|s| s.test_mode()), + // "AAM" (alanyi adómentes: the prices carry no VAT) or a rate like "27%". + "vat": c.invoice_vat.code(), "user_invites": c.user_invites, "referral_rewards": c.referral_rewards, "signup_mode": c.signup_mode.as_str(), diff --git a/services/backend/src/routes/payments.rs b/services/backend/src/routes/payments.rs index 79d76b0..e53d602 100644 --- a/services/backend/src/routes/payments.rs +++ b/services/backend/src/routes/payments.rs @@ -207,7 +207,8 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result ))} -

Az árak bruttó árak, az áfát tartalmazzák.

+

+ {config?.vat === "AAM" || !config + ? "Az árak végső árak: alanyi adómentesek vagyunk, áfát nem számítunk fel." + : `Az árak bruttó árak, a ${config.vat} áfát tartalmazzák.`} +

); diff --git a/services/frontend/src/lib/types.ts b/services/frontend/src/lib/types.ts index 19ca01e..aa5b334 100644 --- a/services/frontend/src/lib/types.ts +++ b/services/frontend/src/lib/types.ts @@ -100,6 +100,8 @@ export interface PublicConfig { payments_admins_only: boolean; /** Stripe has a test key (test cards work, no real money). */ payments_test: boolean; + /** "AAM": alanyi adómentes, the prices carry no VAT; otherwise the rate, e.g. "27%". */ + vat: string; /** "invite": new accounts need an invitation. */ signup_mode: "invite" | "open"; /** Users may invite others (off until the launch; admins always may). */ diff --git a/services/worker/src/invoices.rs b/services/worker/src/invoices.rs index 5fc8300..e263a39 100644 --- a/services/worker/src/invoices.rs +++ b/services/worker/src/invoices.rs @@ -243,7 +243,11 @@ async fn issue(db: &PgPool, billingo: &Billingo, due: &Due) -> Result