diff --git a/common/proto/accounting.proto b/common/proto/accounting.proto index 10fc82a..78c30a4 100644 --- a/common/proto/accounting.proto +++ b/common/proto/accounting.proto @@ -63,6 +63,22 @@ enum AccountingPeriodStatus { ACCOUNTING_PERIOD_STATUS_APPROVED = 3; } +// How long one accounting period lasts. MONTH and YEAR span whole months, so +// the caller states only the start and the end is derived. PARTIAL is the +// exception for periods real life cut short. +enum AccountingPeriodType { + ACCOUNTING_PERIOD_TYPE_UNSPECIFIED = 0; + // One calendar month. + ACCOUNTING_PERIOD_TYPE_MONTH = 1; + // Twelve consecutive months, aligned to the profile's fiscal year. Starting + // in January gives the calendar year; any other start month gives a business + // year (hospodársky rok). + ACCOUNTING_PERIOD_TYPE_YEAR = 2; + // Neither a whole month nor a whole year, because the entity was formed or + // terminated part-way through one. The only type carrying an explicit end. + ACCOUNTING_PERIOD_TYPE_PARTIAL = 3; +} + message PostJournalRequest { string profile_name = 1; @@ -244,11 +260,16 @@ message Journal { message ConfigureAccountingPeriodRequest { string profile_name = 1; - // Inclusive range in YYYY-MM-DD. + // First day of the period, YYYY-MM-DD. Must be the first day of a month. string period_start = 2; - string period_end = 3; + reserved 3; // Optional link to the preceding period in a carry chain. optional int64 previous_period_id = 4; + // Required. Decides the length of the period. + AccountingPeriodType period_type = 5; + // Last day of the period, YYYY-MM-DD. Required for PARTIAL and rejected for + // every other type, whose end follows from the start. + string period_end = 6; } message CloseAccountingPeriodRequest { @@ -286,6 +307,7 @@ message AccountingPeriod { string closed_by_user_id = 8; string approved_at = 9; string approved_by_user_id = 10; + AccountingPeriodType period_type = 11; } message ListPeriodBalancesRequest { diff --git a/common/proto/table_definition.proto b/common/proto/table_definition.proto index ec65284..ec44c56 100644 --- a/common/proto/table_definition.proto +++ b/common/proto/table_definition.proto @@ -89,6 +89,20 @@ message PostTableDefinitionRequest { // Column whose value identifies a row to users in pickers. "id" is always // valid; otherwise this must name one of the user-defined columns above. string row_display_column = 7; + + // ISO-4217 currency the profile keeps its accounting in. A profile is one + // accounting entity and keeps one set of books, so this is required only when + // the request creates the profile, and is ignored afterwards. It is unrelated + // to base_currency: tables may hold money in any currency, and amounts convert + // to this one when they reach the ledger. + string accounting_currency = 8; + + // Month the profile's fiscal year begins, 1-12. Like accounting_currency, + // this describes the entity rather than the table, so it is required only + // when the request creates the profile and ignored afterwards. January means + // the calendar year; any other month means a business year (hospodársky + // rok), which may be used only after notifying the tax office. + uint32 fiscal_year_start_month = 9; } // Defines the input for explicitly creating a table backed by one invoice diff --git a/common/src/proto/descriptor.bin b/common/src/proto/descriptor.bin index 2c09d32..1b1555e 100644 Binary files a/common/src/proto/descriptor.bin and b/common/src/proto/descriptor.bin differ diff --git a/common/src/proto/komp_ac.accounting.rs b/common/src/proto/komp_ac.accounting.rs index d92a5e7..247f35c 100644 --- a/common/src/proto/komp_ac.accounting.rs +++ b/common/src/proto/komp_ac.accounting.rs @@ -256,14 +256,19 @@ pub struct Journal { pub struct ConfigureAccountingPeriodRequest { #[prost(string, tag = "1")] pub profile_name: ::prost::alloc::string::String, - /// Inclusive range in YYYY-MM-DD. + /// First day of the period, YYYY-MM-DD. Must be the first day of a month. #[prost(string, tag = "2")] pub period_start: ::prost::alloc::string::String, - #[prost(string, tag = "3")] - pub period_end: ::prost::alloc::string::String, /// Optional link to the preceding period in a carry chain. #[prost(int64, optional, tag = "4")] pub previous_period_id: ::core::option::Option, + /// Required. Decides the length of the period. + #[prost(enumeration = "AccountingPeriodType", tag = "5")] + pub period_type: i32, + /// Last day of the period, YYYY-MM-DD. Required for PARTIAL and rejected for + /// every other type, whose end follows from the start. + #[prost(string, tag = "6")] + pub period_end: ::prost::alloc::string::String, } #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)] pub struct CloseAccountingPeriodRequest { @@ -317,6 +322,8 @@ pub struct AccountingPeriod { pub approved_at: ::prost::alloc::string::String, #[prost(string, tag = "10")] pub approved_by_user_id: ::prost::alloc::string::String, + #[prost(enumeration = "AccountingPeriodType", tag = "11")] + pub period_type: i32, } #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)] pub struct ListPeriodBalancesRequest { @@ -407,6 +414,47 @@ impl AccountingPeriodStatus { } } } +/// How long one accounting period lasts. MONTH and YEAR span whole months, so +/// the caller states only the start and the end is derived. PARTIAL is the +/// exception for periods real life cut short. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum AccountingPeriodType { + Unspecified = 0, + /// One calendar month. + Month = 1, + /// Twelve consecutive months, aligned to the profile's fiscal year. Starting + /// in January gives the calendar year; any other start month gives a business + /// year (hospodársky rok). + Year = 2, + /// Neither a whole month nor a whole year, because the entity was formed or + /// terminated part-way through one. The only type carrying an explicit end. + Partial = 3, +} +impl AccountingPeriodType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Unspecified => "ACCOUNTING_PERIOD_TYPE_UNSPECIFIED", + Self::Month => "ACCOUNTING_PERIOD_TYPE_MONTH", + Self::Year => "ACCOUNTING_PERIOD_TYPE_YEAR", + Self::Partial => "ACCOUNTING_PERIOD_TYPE_PARTIAL", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "ACCOUNTING_PERIOD_TYPE_UNSPECIFIED" => Some(Self::Unspecified), + "ACCOUNTING_PERIOD_TYPE_MONTH" => Some(Self::Month), + "ACCOUNTING_PERIOD_TYPE_YEAR" => Some(Self::Year), + "ACCOUNTING_PERIOD_TYPE_PARTIAL" => Some(Self::Partial), + _ => None, + } + } +} /// Generated client implementations. pub mod accounting_client { #![allow( diff --git a/common/src/proto/komp_ac.table_definition.rs b/common/src/proto/komp_ac.table_definition.rs index 4c4be5a..2b45fe2 100644 --- a/common/src/proto/komp_ac.table_definition.rs +++ b/common/src/proto/komp_ac.table_definition.rs @@ -49,6 +49,20 @@ pub struct PostTableDefinitionRequest { /// valid; otherwise this must name one of the user-defined columns above. #[prost(string, tag = "7")] pub row_display_column: ::prost::alloc::string::String, + /// ISO-4217 currency the profile keeps its accounting in. A profile is one + /// accounting entity and keeps one set of books, so this is required only when + /// the request creates the profile, and is ignored afterwards. It is unrelated + /// to base_currency: tables may hold money in any currency, and amounts convert + /// to this one when they reach the ledger. + #[prost(string, tag = "8")] + pub accounting_currency: ::prost::alloc::string::String, + /// Month the profile's fiscal year begins, 1-12. Like accounting_currency, + /// this describes the entity rather than the table, so it is required only + /// when the request creates the profile and ignored afterwards. January means + /// the calendar year; any other month means a business year (hospodársky + /// rok), which may be used only after notifying the tax office. + #[prost(uint32, tag = "9")] + pub fiscal_year_start_month: u32, } /// Defines the input for explicitly creating a table backed by one invoice /// template. typst_source must contain exactly one declaration of the form: diff --git a/graphs/src/pages/add_table/state.rs b/graphs/src/pages/add_table/state.rs index d6fe457..173f952 100644 --- a/graphs/src/pages/add_table/state.rs +++ b/graphs/src/pages/add_table/state.rs @@ -114,6 +114,8 @@ impl CreateTableForm { } Ok(PostTableDefinitionRequest { + accounting_currency: String::new(), + fiscal_year_start_month: 0, table_name, links, columns, diff --git a/server b/server index 454acc6..14346db 160000 --- a/server +++ b/server @@ -1 +1 @@ -Subproject commit 454acc6f2b0286b165188236f64b436dfa4a5555 +Subproject commit 14346dbc36b29731c01d0be631e156f456bb82a5