Invoice items say what the service is
'Sorsfonalak – Páros' does not identify the service, as the VAT act (169. § e) asks. The item is now e.g. 'Asztrológiai elemzéscsomag – Páros', unit 'csomag', with the package's contents as its comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
-- The invoice item must identify the service (Áfa tv. 169. § e): what the
|
||||||
|
-- package contains goes under the item, and the unit is "csomag".
|
||||||
|
ALTER TABLE invoices
|
||||||
|
ADD COLUMN item_comment text,
|
||||||
|
ADD COLUMN item_unit text NOT NULL DEFAULT 'csomag';
|
||||||
+1
-1
@@ -26,7 +26,7 @@ A sorok a fiók törlése után is megmaradnak (`user_id` → NULL), mert a szá
|
|||||||
|
|
||||||
## Számla
|
## 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, 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.
|
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%`. A tétel a törvény szerint azonosítja a szolgáltatást (Áfa tv. 169. § e): megnevezése pl. „Asztrológiai elemzéscsomag – Páros”, egysége `csomag`, megjegyzése a tartalom („Tartalma: 2 részletes képletelemzés, … Online elérhető digitális szolgáltatás (sorsfonalak.hu).”; `Package::invoice_item`). 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.
|
||||||
|
|
||||||
**Teszt módú fizetéshez (`sk_test_…`) nem készül számla**, mert a Billingo számlái valódiak (a NAV-hoz is bekerülnek); a csomagot ilyenkor is megkapja az admin.
|
**Teszt módú fizetéshez (`sk_test_…`) nem készül számla**, mert a Billingo számlái valódiak (a NAV-hoz is bekerülnek); a csomagot ilyenkor is megkapja az admin.
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ pub async fn queue(
|
|||||||
checkout_id: &str,
|
checkout_id: &str,
|
||||||
user_id: Option<Uuid>,
|
user_id: Option<Uuid>,
|
||||||
buyer: &Buyer,
|
buyer: &Buyer,
|
||||||
item_name: &str,
|
(item_name, item_comment): (&str, &str),
|
||||||
gross_huf: i64,
|
gross_huf: i64,
|
||||||
vat: Vat,
|
vat: Vat,
|
||||||
) -> Result<Uuid, ApiError> {
|
) -> Result<Uuid, ApiError> {
|
||||||
@@ -108,8 +108,8 @@ pub async fn queue(
|
|||||||
let (net, vat_huf) = vat.split(gross_huf);
|
let (net, vat_huf) = vat.split(gross_huf);
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO invoices (id, checkout_id, user_id, buyer_name, buyer_email, buyer_country, buyer_post_code, \
|
"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) \
|
buyer_city, buyer_address, buyer_tax_type, buyer_tax_number, item_name, gross_huf, net_huf, vat_huf, vat_rate, \
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) \
|
item_comment) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) \
|
||||||
ON CONFLICT (checkout_id) DO NOTHING",
|
ON CONFLICT (checkout_id) DO NOTHING",
|
||||||
)
|
)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
@@ -128,6 +128,7 @@ pub async fn queue(
|
|||||||
.bind(net as i32)
|
.bind(net as i32)
|
||||||
.bind(vat_huf as i32)
|
.bind(vat_huf as i32)
|
||||||
.bind(vat.code())
|
.bind(vat.code())
|
||||||
|
.bind(item_comment)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(id)
|
Ok(id)
|
||||||
|
|||||||
@@ -202,6 +202,29 @@ impl Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Package {
|
impl Package {
|
||||||
|
/// The invoice item: a name that says what the service is, and what the
|
||||||
|
/// package contains (Áfa tv. 169. § e).
|
||||||
|
pub fn invoice_item(&self) -> (String, String) {
|
||||||
|
let name = match self.tier {
|
||||||
|
Tier::Main => format!("Asztrológiai elemzéscsomag – {}", self.name),
|
||||||
|
Tier::Addon => format!("Asztrológiai kiegészítő – {}", self.name),
|
||||||
|
};
|
||||||
|
let lines: Vec<String> = [
|
||||||
|
(self.natal, "részletes képletelemzés"),
|
||||||
|
(self.synastry, "kapcsolati elemzés"),
|
||||||
|
(self.forecast, "éves előrejelzés"),
|
||||||
|
(self.persons, "személy felvétele"),
|
||||||
|
(self.questions, "kérdés az elemzésekről"),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.filter(|&(n, _)| n > 0)
|
||||||
|
.map(|(n, what)| format!("{n} {what}"))
|
||||||
|
.collect();
|
||||||
|
let comment =
|
||||||
|
format!("Tartalma: {}. Online elérhető digitális szolgáltatás (sorsfonalak.hu).", lines.join(", "));
|
||||||
|
(name, comment)
|
||||||
|
}
|
||||||
|
|
||||||
/// What the package gives, unit by unit.
|
/// What the package gives, unit by unit.
|
||||||
pub fn contents(&self) -> [(Unit, i64); 5] {
|
pub fn contents(&self) -> [(Unit, i64); 5] {
|
||||||
[
|
[
|
||||||
@@ -341,4 +364,18 @@ mod tests {
|
|||||||
assert!(CATALOG.iter().filter(|p| p.tier == Tier::Main).all(|p| p.questions == QUESTIONS_INCLUDED));
|
assert!(CATALOG.iter().filter(|p| p.tier == Tier::Main).all(|p| p.questions == QUESTIONS_INCLUDED));
|
||||||
assert_eq!(find("addon_questions").unwrap().questions, 5);
|
assert_eq!(find("addon_questions").unwrap().questions, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invoice_items_say_what_was_bought() {
|
||||||
|
let (name, comment) = find("couple").unwrap().invoice_item();
|
||||||
|
assert_eq!(name, "Asztrológiai elemzéscsomag – Páros");
|
||||||
|
assert!(
|
||||||
|
comment.starts_with("Tartalma: 2 részletes képletelemzés, 1 kapcsolati elemzés, 2 éves előrejelzés"),
|
||||||
|
"{comment}"
|
||||||
|
);
|
||||||
|
assert!(comment.ends_with("Online elérhető digitális szolgáltatás (sorsfonalak.hu)."));
|
||||||
|
let (name, comment) = find("addon_persons").unwrap().invoice_item();
|
||||||
|
assert_eq!(name, "Asztrológiai kiegészítő – +5 személy");
|
||||||
|
assert!(comment.starts_with("Tartalma: 5 személy felvétele."), "{comment}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,9 +210,10 @@ async fn complete(state: &AppState, session: &stripe::Session) -> Result<bool, A
|
|||||||
// to the tax authority).
|
// to the tax authority).
|
||||||
if live {
|
if live {
|
||||||
let buyer = invoices::Buyer::from_stripe(session.customer_details.as_ref().unwrap_or(&Value::Null), None);
|
let buyer = invoices::Buyer::from_stripe(session.customer_details.as_ref().unwrap_or(&Value::Null), None);
|
||||||
let item = format!("Sorsfonalak – {}", package.name);
|
let (item, comment) = package.invoice_item();
|
||||||
let gross = amount_huf.unwrap_or(i64::from(price_huf));
|
let gross = amount_huf.unwrap_or(i64::from(price_huf));
|
||||||
invoices::queue(&mut tx, &session.id, user_id, &buyer, &item, gross, state.config.invoice_vat).await?;
|
invoices::queue(&mut tx, &session.id, user_id, &buyer, (&item, &comment), gross, state.config.invoice_vat)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
tracing::info!(user = ?user_id, package = %package_id, session = %session.id, "package paid");
|
tracing::info!(user = ?user_id, package = %package_id, session = %session.id, "package paid");
|
||||||
|
|||||||
@@ -2404,7 +2404,7 @@ async fn stripe_checkout_grants_the_paid_package_once(pool: PgPool) {
|
|||||||
(invoice.buyer_tax_type.as_str(), invoice.buyer_tax_number.as_deref()),
|
(invoice.buyer_tax_type.as_str(), invoice.buyer_tax_number.as_deref()),
|
||||||
("HAS_TAX_NUMBER", Some("12345678-1-23"))
|
("HAS_TAX_NUMBER", Some("12345678-1-23"))
|
||||||
);
|
);
|
||||||
assert_eq!(invoice.item_name, "Sorsfonalak – Páros");
|
assert_eq!(invoice.item_name, "Asztrológiai elemzéscsomag – Páros");
|
||||||
// Alanyi adómentes (the default): no VAT.
|
// Alanyi adómentes (the default): no VAT.
|
||||||
assert_eq!((invoice.gross_huf, invoice.net_huf, invoice.vat_huf), (6000, 6000, 0));
|
assert_eq!((invoice.gross_huf, invoice.net_huf, invoice.vat_huf), (6000, 6000, 0));
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ struct Due {
|
|||||||
buyer_tax_type: String,
|
buyer_tax_type: String,
|
||||||
buyer_tax_number: Option<String>,
|
buyer_tax_number: Option<String>,
|
||||||
item_name: String,
|
item_name: String,
|
||||||
|
item_comment: Option<String>,
|
||||||
|
item_unit: String,
|
||||||
gross_huf: i32,
|
gross_huf: i32,
|
||||||
vat_rate: String,
|
vat_rate: String,
|
||||||
payment_method: String,
|
payment_method: String,
|
||||||
@@ -128,7 +130,7 @@ pub async fn run_once(db: &PgPool, billingo: &Billingo, max_attempts: i32) -> Re
|
|||||||
WHERE c.id = i.checkout_id AND i.id = (SELECT id FROM invoices WHERE status = 'pending' \
|
WHERE c.id = i.checkout_id AND i.id = (SELECT id FROM invoices WHERE status = 'pending' \
|
||||||
AND next_attempt_at <= now() ORDER BY next_attempt_at FOR UPDATE SKIP LOCKED LIMIT 1) \
|
AND next_attempt_at <= now() ORDER BY next_attempt_at FOR UPDATE SKIP LOCKED LIMIT 1) \
|
||||||
RETURNING i.id, i.attempts, i.buyer_name, i.buyer_email, i.buyer_country, i.buyer_post_code, \
|
RETURNING i.id, i.attempts, i.buyer_name, i.buyer_email, i.buyer_country, i.buyer_post_code, \
|
||||||
i.buyer_city, i.buyer_address, i.buyer_tax_type, i.buyer_tax_number, i.item_name, i.gross_huf, \
|
i.buyer_city, i.buyer_address, i.buyer_tax_type, i.buyer_tax_number, i.item_name, i.item_comment, i.item_unit, i.gross_huf, \
|
||||||
i.vat_rate, i.payment_method, i.billingo_partner_id, i.billingo_document_id, i.sent_at, \
|
i.vat_rate, i.payment_method, i.billingo_partner_id, i.billingo_document_id, i.sent_at, \
|
||||||
coalesce(c.completed_at, i.created_at) AS paid_at"
|
coalesce(c.completed_at, i.created_at) AS paid_at"
|
||||||
))
|
))
|
||||||
@@ -240,8 +242,9 @@ async fn issue(db: &PgPool, billingo: &Billingo, due: &Due) -> Result<String, Fa
|
|||||||
"unit_price": due.gross_huf,
|
"unit_price": due.gross_huf,
|
||||||
"unit_price_type": "gross",
|
"unit_price_type": "gross",
|
||||||
"quantity": 1,
|
"quantity": 1,
|
||||||
"unit": "db",
|
"unit": due.item_unit,
|
||||||
"vat": due.vat_rate,
|
"vat": due.vat_rate,
|
||||||
|
"comment": due.item_comment.clone().unwrap_or_default(),
|
||||||
}],
|
}],
|
||||||
"comment": if due.vat_rate == "AAM" {
|
"comment": if due.vat_rate == "AAM" {
|
||||||
"Bankkártyával kifizetve (Stripe). Alanyi adómentes."
|
"Bankkártyával kifizetve (Stripe). Alanyi adómentes."
|
||||||
@@ -399,7 +402,7 @@ mod tests {
|
|||||||
"INSERT INTO invoices (id, checkout_id, buyer_name, buyer_email, buyer_country, buyer_post_code, \
|
"INSERT INTO invoices (id, checkout_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) \
|
buyer_city, buyer_address, buyer_tax_type, buyer_tax_number, item_name, gross_huf, net_huf, vat_huf) \
|
||||||
VALUES ($1, $2, 'Csillag Kft.', 'anna@example.com', 'HU', '6720', 'Szeged', 'Fő utca 1.', $3, $4, \
|
VALUES ($1, $2, 'Csillag Kft.', 'anna@example.com', 'HU', '6720', 'Szeged', 'Fő utca 1.', $3, $4, \
|
||||||
'Sorsfonalak – Páros', 6000, 6000, 0)",
|
'Asztrológiai elemzéscsomag – Páros', 6000, 6000, 0)",
|
||||||
)
|
)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.bind(&checkout)
|
.bind(&checkout)
|
||||||
@@ -449,6 +452,10 @@ mod tests {
|
|||||||
(&json!(true), &json!("online_bankcard"), &json!("HUF"))
|
(&json!(true), &json!("online_bankcard"), &json!("HUF"))
|
||||||
);
|
);
|
||||||
assert_eq!(doc["items"][0]["unit_price"], 6000);
|
assert_eq!(doc["items"][0]["unit_price"], 6000);
|
||||||
|
assert_eq!(
|
||||||
|
(&doc["items"][0]["name"], &doc["items"][0]["unit"]),
|
||||||
|
(&json!("Asztrológiai elemzéscsomag – Páros"), &json!("csomag"))
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(&doc["items"][0]["unit_price_type"], &doc["items"][0]["vat"]),
|
(&doc["items"][0]["unit_price_type"], &doc["items"][0]["vat"]),
|
||||||
(&json!("gross"), &json!("AAM"))
|
(&json!("gross"), &json!("AAM"))
|
||||||
|
|||||||
Reference in New Issue
Block a user