core_invoice/validate.rs
1use crate::invoice::Invoice;
2use crate::report::Report;
3use crate::rules;
4
5/// Semantic checks on the in-memory invoice. Syntax (UBL/CII) lives in `core-invoice-formats`.
6pub fn validate(invoice: &Invoice) -> Report {
7 let core = rules::core_rules();
8 let extra = invoice.profile.extra_rules();
9 let mut report = Report {
10 profile_slug: invoice.profile.slug(),
11 rules_checked: core.len() + extra.len(),
12 ..Report::default()
13 };
14 for rule in core.iter().chain(extra) {
15 (rule.eval)(invoice, &mut report);
16 }
17 report.sort_stable();
18 report
19}