ekwo-os 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +873 -0
- package/dist/args.d.ts +57 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +134 -0
- package/dist/args.js.map +1 -0
- package/dist/assets/expected-objects.json +9432 -0
- package/dist/assets/migrations/20260911120000_core_companies.sql +260 -0
- package/dist/assets/migrations/20260911120100_accounts_journals.sql +211 -0
- package/dist/assets/migrations/20260911120200_contacts.sql +90 -0
- package/dist/assets/migrations/20260911120300_taxes.sql +146 -0
- package/dist/assets/migrations/20260911120400_entries.sql +338 -0
- package/dist/assets/migrations/20260911120500_documents.sql +279 -0
- package/dist/assets/migrations/20260911120600_payments_reconciliation.sql +251 -0
- package/dist/assets/migrations/20260911120700_bank.sql +178 -0
- package/dist/assets/migrations/20260911120800_analytics_attachments.sql +128 -0
- package/dist/assets/migrations/20260911120900_post_document.sql +279 -0
- package/dist/assets/migrations/20260911121000_reporting.sql +235 -0
- package/dist/assets/migrations/20260911121100_country_templates.sql +226 -0
- package/dist/assets/migrations/20260911121200_fec.sql +71 -0
- package/dist/assets/migrations/20260911130000_instance.sql +77 -0
- package/dist/assets/migrations/20260911130100_instance_members.sql +224 -0
- package/dist/assets/migrations/20260911140000_instance_admins.sql +112 -0
- package/dist/assets/migrations/20260911160000_tax_posting_templates_unique.sql +17 -0
- package/dist/assets/migrations/20260911170000_document_amount_paid.sql +82 -0
- package/dist/assets/migrations/20260911173000_post_payment.sql +122 -0
- package/dist/assets/migrations/20260911173100_sequence_counters_under_rls.sql +84 -0
- package/dist/assets/migrations/20260911183000_country_journal_defaults.sql +143 -0
- package/dist/assets/migrations/20260911193853_line_account_defaults.sql +274 -0
- package/dist/assets/migrations/20260911195054_products.sql +221 -0
- package/dist/assets/migrations/20260911210131_anon_surface.sql +85 -0
- package/dist/assets/migrations/20260912074712_country_packs.sql +318 -0
- package/dist/assets/migrations/20260912080311_report_code_and_region.sql +198 -0
- package/dist/assets/migrations/20260912081014_pack_certification_maintained.sql +31 -0
- package/dist/assets/migrations/20260912081015_pack_certification_backfill.sql +16 -0
- package/dist/assets/migrations/20260912090407_tax_report_boxes.sql +329 -0
- package/dist/assets/migrations/20260912091917_tax_on_base_value.sql +25 -0
- package/dist/assets/migrations/20260912091918_tax_engine_columns.sql +776 -0
- package/dist/assets/migrations/20260912094412_opening_and_closing.sql +759 -0
- package/dist/assets/migrations/20260912095825_charts_of_accounts.sql +326 -0
- package/dist/assets/migrations/20260912100412_financial_statements.sql +632 -0
- package/dist/assets/migrations/20260912104719_one_formula_evaluator.sql +209 -0
- package/dist/assets/migrations/20260912105720_entry_kind_appropriation.sql +26 -0
- package/dist/assets/migrations/20260912105721_appropriation_entry_kind.sql +444 -0
- package/dist/assets/migrations/20260912111751_document_rules.sql +274 -0
- package/dist/assets/migrations/20260912112132_cash_basis_vat_and_fx.sql +1189 -0
- package/dist/assets/migrations/20260913074512_modules.sql +493 -0
- package/dist/assets/migrations/20260913075903_asset_disposal_roles.sql +47 -0
- package/dist/assets/migrations/20260913083216_capabilities.sql +637 -0
- package/dist/assets/migrations/20260913083901_company_invitations.sql +262 -0
- package/dist/assets/migrations/20260913084402_user_preferences.sql +376 -0
- package/dist/assets/migrations/20260913084847_company_profile.sql +261 -0
- package/dist/assets/migrations/20260913085436_numbering_reads_the_pack.sql +235 -0
- package/dist/assets/migrations/20260913085932_api_keys.sql +303 -0
- package/dist/assets/migrations/20260913090216_fiscal_year_bounds.sql +159 -0
- package/dist/assets/migrations/20260913092527_entries_import.sql +219 -0
- package/dist/assets/migrations/20260913101536_null_safe_guards.sql +188 -0
- package/dist/assets/migrations/20260913102115_installer_is_named.sql +462 -0
- package/dist/assets/migrations/20260913102758_no_currency_default.sql +138 -0
- package/dist/assets/migrations/20260913103355_cash_basis_needs_a_box.sql +453 -0
- package/dist/assets/migrations/20260913104014_aged_balance_named_group.sql +79 -0
- package/dist/assets/migrations/20260913104232_foreign_key_indexes.sql +144 -0
- package/dist/assets/migrations/20260913105120_declared_no_reader.sql +41 -0
- package/dist/assets/migrations/20260913111407_pack_languages.sql +223 -0
- package/dist/assets/migrations/20260913112233_schema_comments_for_a_reader.sql +27 -0
- package/dist/assets/migrations/20260913114535_fec_opening_balances.sql +307 -0
- package/dist/assets/migrations/20260914103412_audit_log.sql +509 -0
- package/dist/assets/migrations/20260914111907_pack_upgrade.sql +428 -0
- package/dist/assets/migrations/20260914120500_rounding_reads_the_currency.sql +206 -0
- package/dist/assets/migrations/20260914121200_amounts_round_at_the_currency.sql +2403 -0
- package/dist/assets/migrations/20260914134325_schema_version_0_2_0.sql +36 -0
- package/dist/assets/migrations/20260914143915_accounts_in_use.sql +428 -0
- package/dist/assets/migrations/20260914144731_account_code_frozen.sql +99 -0
- package/dist/assets/migrations/20260914151207_schema_grants_its_own_rights.sql +284 -0
- package/dist/assets/migrations/20260914152840_pack_upgrade_records_its_own_line.sql +237 -0
- package/dist/assets/migrations/20260914163943_declaration_periodicity.sql +349 -0
- package/dist/assets/migrations/20260915094000_foreign_services_received.sql +37 -0
- package/dist/assets/migrations/20260915094500_mentions_read_a_foreign_service.sql +72 -0
- package/dist/assets/migrations/20260915153000_document_shares.sql +568 -0
- package/dist/assets/migrations/20260915160000_ec_sales_list.sql +181 -0
- package/dist/assets/migrations/20260915161842_pack_sources.sql +56 -0
- package/dist/assets/migrations/20260915170500_schema_version_0_3_0.sql +45 -0
- package/dist/assets/migrations/20260915174500_a_vat_category_is_a_code.sql +177 -0
- package/dist/assets/migrations/20260915180000_document_rule_references.sql +85 -0
- package/dist/assets/migrations/20260915181000_territories.sql +342 -0
- package/dist/assets/migrations/20260915181500_ec_sales_list_reads_the_territories.sql +222 -0
- package/dist/assets/migrations/20260915182000_intracom_triangular.sql +53 -0
- package/dist/assets/migrations/20260915182500_a_triangular_supply_says_reverse_charge.sql +99 -0
- package/dist/assets/migrations/20260915191200_a_document_knows_its_language.sql +633 -0
- package/dist/assets/migrations/20260915195000_a_price_that_holds_its_tax.sql +649 -0
- package/dist/assets/migrations/20260915200000_a_posting_names_its_boxes.sql +1004 -0
- package/dist/assets/migrations/20260916094500_a_company_files_more_than_one_declaration.sql +795 -0
- package/dist/assets/migrations/20260916103000_a_ledger_line_names_its_posting.sql +902 -0
- package/dist/assets/migrations/20260916123000_a_vocabulary_for_a_tax_that_is_not_a_vat.sql +144 -0
- package/dist/assets/migrations/20260916124000_a_box_can_be_a_rate_of_a_box.sql +525 -0
- package/dist/assets/migrations/20260916125000_a_tax_follows_the_territory.sql +1318 -0
- package/dist/assets/migrations/20260916126000_a_tax_point_and_its_exception.sql +1211 -0
- package/dist/assets/migrations/20260917090000_a_counterparty_that_learns.sql +561 -0
- package/dist/assets/migrations/20260917120000_what_the_money_pays.sql +545 -0
- package/dist/assets/migrations/20260917150000_a_filing_is_a_row.sql +488 -0
- package/dist/assets/migrations/20260917170000_when_it_is_due.sql +194 -0
- package/dist/assets/migrations/20260917180000_a_box_is_a_number_and_a_kind.sql +213 -0
- package/dist/assets/migrations/20260917190000_what_a_declaration_owes.sql +486 -0
- package/dist/assets/migrations/20260917200000_what_moved_after_it_went.sql +227 -0
- package/dist/assets/migrations/20260918090000_a_form_names_its_file.sql +27 -0
- package/dist/assets/migrations/20260918110000_a_deposit_and_what_came_back.sql +286 -0
- package/dist/assets/migrations/20260918113741_a_fourth_preset_is_named.sql +9 -0
- package/dist/assets/migrations/20260918113807_a_client_reads_and_hands_over.sql +96 -0
- package/dist/assets/migrations/20260918114322_two_definer_functions_check_their_caller.sql +75 -0
- package/dist/assets/migrations/20260918130000_every_company_somebody_keeps.sql +177 -0
- package/dist/assets/migrations/20260918140000_a_session_nobody_prepared.sql +40 -0
- package/dist/assets/migrations/20260918141107_a_line_keeps_the_tax_it_was_posted_with.sql +256 -0
- package/dist/assets/migrations/20260918141342_a_company_has_an_electronic_address.sql +66 -0
- package/dist/assets/migrations/20260918141605_an_invoice_reads_whole_from_the_views.sql +313 -0
- package/dist/assets/migrations/20260918141627_a_policy_asks_once.sql +132 -0
- package/dist/assets/migrations/20260918143352_a_suggestion_reads_the_words_once.sql +204 -0
- package/dist/assets/migrations/20260918143417_a_reference_of_the_caller_and_a_rehearsal.sql +115 -0
- package/dist/assets/migrations/20260918150712_a_company_leaves_with_its_books.sql +1119 -0
- package/dist/assets/migrations/20260918150931_a_statement_is_imported_once.sql +654 -0
- package/dist/assets/migrations/20260918161204_a_posted_document_does_not_move.sql +437 -0
- package/dist/assets/migrations/20260918161538_a_posted_entry_does_not_move.sql +252 -0
- package/dist/assets/migrations/20260918171946_an_entry_is_posted_by_post_entry.sql +289 -0
- package/dist/assets/migrations/20260918174312_schema_version_0_4_0.sql +53 -0
- package/dist/assets/modules/assets/module.json +13 -0
- package/dist/assets/modules/assets/supabase/migrations/20260913081447_assets.sql +1190 -0
- package/dist/assets/modules/assets/supabase/migrations/20260913104234_foreign_key_indexes.sql +47 -0
- package/dist/assets/modules/assets/supabase/migrations/20260913104500_assets_capabilities.sql +145 -0
- package/dist/assets/modules/assets/supabase/migrations/20260914122100_assets_round_at_the_currency.sql +564 -0
- package/dist/assets/modules/assets/supabase/migrations/20260914145012_assets_accounts_in_use.sql +37 -0
- package/dist/assets/modules/assets/supabase/migrations/20260914151530_assets_grants_its_own_rights.sql +63 -0
- package/dist/assets/modules/assets/supabase/migrations/20260918113912_assets_client_reads.sql +20 -0
- package/dist/assets/modules/assets/supabase/migrations/20260918150801_assets_leave_with_the_company.sql +41 -0
- package/dist/assets/modules/budgets/module.json +12 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260913083012_budgets.sql +210 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260913104233_foreign_key_indexes.sql +37 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260913104501_budgets_capabilities.sql +72 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260914122400_budgets_round_at_the_currency.sql +68 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260914145048_budgets_accounts_in_use.sql +30 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260914151812_budgets_grants_its_own_rights.sql +31 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260918113954_budgets_client_reads.sql +20 -0
- package/dist/assets/modules/budgets/supabase/migrations/20260918150823_budgets_leave_with_the_company.sql +37 -0
- package/dist/assets/modules/schema/module.1.json +69 -0
- package/dist/assets/seed/00_currencies.sql +15 -0
- package/dist/assets/seed/00_territories.sql +280 -0
- package/dist/assets/seed/05_framework_generic.sql +110 -0
- package/dist/assets/seed/10_pack_be.sql +1284 -0
- package/dist/assets/seed/11_pack_fr.sql +1112 -0
- package/dist/assets/seed/12_pack_lu.sql +2484 -0
- package/dist/assets/seed/13_pack_ee.sql +733 -0
- package/dist/assets/seed/14_pack_gb.sql +796 -0
- package/dist/assets/seed/15_pack_us.sql +751 -0
- package/dist/assets/seed/90_demo_company.sql +368 -0
- package/dist/assets/seed/modules/assets/10_pack_be.sql +58 -0
- package/dist/assets/seed/modules/assets/11_pack_fr.sql +57 -0
- package/dist/assets/seed/modules/assets/14_pack_gb.sql +58 -0
- package/dist/assets/seed/modules/assets/15_pack_us.sql +60 -0
- package/dist/auth.d.ts +59 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +134 -0
- package/dist/auth.js.map +1 -0
- package/dist/bin.d.ts +6 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +8 -0
- package/dist/bin.js.map +1 -0
- package/dist/books.d.ts +60 -0
- package/dist/books.d.ts.map +1 -0
- package/dist/books.js +168 -0
- package/dist/books.js.map +1 -0
- package/dist/bootstrap.d.ts +236 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +459 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/bundle.d.ts +27 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +47 -0
- package/dist/bundle.js.map +1 -0
- package/dist/checklist.d.ts +35 -0
- package/dist/checklist.d.ts.map +1 -0
- package/dist/checklist.js +64 -0
- package/dist/checklist.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +318 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/company.d.ts +59 -0
- package/dist/commands/company.d.ts.map +1 -0
- package/dist/commands/company.js +287 -0
- package/dist/commands/company.js.map +1 -0
- package/dist/commands/contact.d.ts +9 -0
- package/dist/commands/contact.d.ts.map +1 -0
- package/dist/commands/contact.js +82 -0
- package/dist/commands/contact.js.map +1 -0
- package/dist/commands/demo.d.ts +19 -0
- package/dist/commands/demo.d.ts.map +1 -0
- package/dist/commands/demo.js +72 -0
- package/dist/commands/demo.js.map +1 -0
- package/dist/commands/doctor.d.ts +12 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/document.d.ts +17 -0
- package/dist/commands/document.d.ts.map +1 -0
- package/dist/commands/document.js +217 -0
- package/dist/commands/document.js.map +1 -0
- package/dist/commands/init.d.ts +31 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +535 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/login.d.ts +24 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +128 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/migrate.d.ts +30 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +115 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/module.d.ts +32 -0
- package/dist/commands/module.d.ts.map +1 -0
- package/dist/commands/module.js +285 -0
- package/dist/commands/module.js.map +1 -0
- package/dist/commands/pack.d.ts +22 -0
- package/dist/commands/pack.d.ts.map +1 -0
- package/dist/commands/pack.js +481 -0
- package/dist/commands/pack.js.map +1 -0
- package/dist/commands/payment.d.ts +15 -0
- package/dist/commands/payment.d.ts.map +1 -0
- package/dist/commands/payment.js +97 -0
- package/dist/commands/payment.js.map +1 -0
- package/dist/commands/register.d.ts +20 -0
- package/dist/commands/register.d.ts.map +1 -0
- package/dist/commands/register.js +134 -0
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +134 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/whoami.d.ts +21 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +133 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/company.d.ts +16 -0
- package/dist/company.d.ts.map +1 -0
- package/dist/company.js +26 -0
- package/dist/company.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +50 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +79 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +116 -0
- package/dist/connection.js.map +1 -0
- package/dist/context.d.ts +47 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +93 -0
- package/dist/context.js.map +1 -0
- package/dist/doctor.d.ts +45 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +448 -0
- package/dist/doctor.js.map +1 -0
- package/dist/grants.d.ts +88 -0
- package/dist/grants.d.ts.map +1 -0
- package/dist/grants.js +174 -0
- package/dist/grants.js.map +1 -0
- package/dist/identity.d.ts +54 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +132 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory.d.ts +155 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +303 -0
- package/dist/inventory.js.map +1 -0
- package/dist/migrations.d.ts +76 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +226 -0
- package/dist/migrations.js.map +1 -0
- package/dist/module/read.d.ts +91 -0
- package/dist/module/read.d.ts.map +1 -0
- package/dist/module/read.js +172 -0
- package/dist/module/read.js.map +1 -0
- package/dist/output.d.ts +110 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +173 -0
- package/dist/output.js.map +1 -0
- package/dist/pack/certification.d.ts +27 -0
- package/dist/pack/certification.d.ts.map +1 -0
- package/dist/pack/certification.js +38 -0
- package/dist/pack/certification.js.map +1 -0
- package/dist/pack/compile.d.ts +75 -0
- package/dist/pack/compile.d.ts.map +1 -0
- package/dist/pack/compile.js +801 -0
- package/dist/pack/compile.js.map +1 -0
- package/dist/pack/filing.d.ts +48 -0
- package/dist/pack/filing.d.ts.map +1 -0
- package/dist/pack/filing.js +56 -0
- package/dist/pack/filing.js.map +1 -0
- package/dist/pack/read.d.ts +766 -0
- package/dist/pack/read.d.ts.map +1 -0
- package/dist/pack/read.js +2336 -0
- package/dist/pack/read.js.map +1 -0
- package/dist/pack/schema.d.ts +26 -0
- package/dist/pack/schema.d.ts.map +1 -0
- package/dist/pack/schema.js +181 -0
- package/dist/pack/schema.js.map +1 -0
- package/dist/pack/territories.d.ts +98 -0
- package/dist/pack/territories.d.ts.map +1 -0
- package/dist/pack/territories.js +0 -0
- package/dist/pack/territories.js.map +1 -0
- package/dist/pack/upgrade.d.ts +86 -0
- package/dist/pack/upgrade.d.ts.map +1 -0
- package/dist/pack/upgrade.js +76 -0
- package/dist/pack/upgrade.js.map +1 -0
- package/dist/pack/vat-codes.d.ts +273 -0
- package/dist/pack/vat-codes.d.ts.map +1 -0
- package/dist/pack/vat-codes.js +513 -0
- package/dist/pack/vat-codes.js.map +1 -0
- package/dist/profiles.d.ts +67 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +187 -0
- package/dist/profiles.js.map +1 -0
- package/dist/prompt.d.ts +40 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +120 -0
- package/dist/prompt.js.map +1 -0
- package/dist/registry.d.ts +84 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +104 -0
- package/dist/registry.js.map +1 -0
- package/dist/rest.d.ts +81 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/rest.js +245 -0
- package/dist/rest.js.map +1 -0
- package/dist/schema.d.ts +15 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +15 -0
- package/dist/schema.js.map +1 -0
- package/dist/seeds.d.ts +27 -0
- package/dist/seeds.d.ts.map +1 -0
- package/dist/seeds.js +47 -0
- package/dist/seeds.js.map +1 -0
- package/dist/session.d.ts +39 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +92 -0
- package/dist/session.js.map +1 -0
- package/dist/sql.d.ts +48 -0
- package/dist/sql.d.ts.map +1 -0
- package/dist/sql.js +112 -0
- package/dist/sql.js.map +1 -0
- package/dist/status.d.ts +94 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +120 -0
- package/dist/status.js.map +1 -0
- package/dist/ui.d.ts +55 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +114 -0
- package/dist/ui.js.map +1 -0
- package/package.json +29 -0
- package/schema/output.1.json +613 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
-- Ekwo OS — the FEC carries its opening balances.
|
|
2
|
+
--
|
|
3
|
+
-- `fec_lines()` returned the movements of a period and nothing else, so the
|
|
4
|
+
-- file of a financial year could not rebuild a balance sheet: every account
|
|
5
|
+
-- started the year at nil. A tax inspector reads the *à-nouveaux* first, and a
|
|
6
|
+
-- file without them is a file that does not tie to the accounts it belongs to.
|
|
7
|
+
--
|
|
8
|
+
-- The reports of this schema read the ledger from the beginning — that is the
|
|
9
|
+
-- decision behind `close_fiscal_year`, which writes no opening entry at all —
|
|
10
|
+
-- so the opening balances are not in the books to be selected. They are
|
|
11
|
+
-- **computed here and never posted**, which is the only way to add them
|
|
12
|
+
-- without counting every carried balance twice.
|
|
13
|
+
--
|
|
14
|
+
-- Three things make the file balance.
|
|
15
|
+
--
|
|
16
|
+
-- 1. **One line per account that carries forward**, at the cumulative
|
|
17
|
+
-- balance of the day before the period starts. Which accounts those are
|
|
18
|
+
-- comes from `accounts.carries_forward`, derived from `account_type`, so
|
|
19
|
+
-- nothing here reads a code prefix: a chart that numbers its assets
|
|
20
|
+
-- differently is still read correctly.
|
|
21
|
+
--
|
|
22
|
+
-- 2. **One line for the result of the years that are not closed yet.** The
|
|
23
|
+
-- balances of the accounts that do *not* carry forward are the mirror
|
|
24
|
+
-- image of the balance-sheet ones, so leaving them out leaves the
|
|
25
|
+
-- opening lines short by exactly the accumulated result. That amount
|
|
26
|
+
-- goes on the balance-sheet account the close would have left it on —
|
|
27
|
+
-- which is what the pack's `closing_style` says, and the reason this is
|
|
28
|
+
-- not a refusal: an accountant exports the file of a year long before
|
|
29
|
+
-- the meeting that closes the one before it, and a file that refuses to
|
|
30
|
+
-- exist until then is a file nobody can produce.
|
|
31
|
+
--
|
|
32
|
+
-- 3. **The entries the close wrote are left out of the movements.** A
|
|
33
|
+
-- closing entry books the mirror image of every income and expense
|
|
34
|
+
-- account, and an appropriation entry moves the result to retained
|
|
35
|
+
-- earnings; both inside the year being exported. Kept, they would show
|
|
36
|
+
-- the result twice — once in the ordinary movements of the year, once on
|
|
37
|
+
-- the balance sheet — and the income statement read from the file would
|
|
38
|
+
-- be nil. Left out, the file of a closed year reads exactly like the
|
|
39
|
+
-- file of an open one, and the result reaches the balance sheet in the
|
|
40
|
+
-- opening lines of the year that follows, which is where a French or
|
|
41
|
+
-- Belgian package prints it too.
|
|
42
|
+
--
|
|
43
|
+
-- `financial_statement()` leaves out `closing` and keeps `appropriation`,
|
|
44
|
+
-- because an appropriation account is part of the statutory income statement
|
|
45
|
+
-- of the countries that have one and the section that shows it would read nil
|
|
46
|
+
-- without it. The FEC is not a statement: it is the movements themselves, and
|
|
47
|
+
-- it already carries the whole income statement in its ordinary lines. So the
|
|
48
|
+
-- two readers ask different questions of the same column, deliberately, and
|
|
49
|
+
-- `docs/decisions.md` says why.
|
|
50
|
+
--
|
|
51
|
+
-- Only a whole financial year gets opening lines. The FEC is a file per
|
|
52
|
+
-- financial year — `fecFileName` is built from the year end — and an extract
|
|
53
|
+
-- of a quarter is an extract of movements, which is what it was before this
|
|
54
|
+
-- migration. A period that starts or ends anywhere but on the bounds of a
|
|
55
|
+
-- year gets what it always got.
|
|
56
|
+
|
|
57
|
+
-- ---------------------------------------------------------------------------
|
|
58
|
+
-- The label those lines carry, from the pack
|
|
59
|
+
-- ---------------------------------------------------------------------------
|
|
60
|
+
--
|
|
61
|
+
-- The specification fixes eighteen columns and the format of each; it fixes no
|
|
62
|
+
-- wording for `EcritureLib`, and an administration reads the file in its own
|
|
63
|
+
-- language. So the label is a value of the country model, filled by the pack,
|
|
64
|
+
-- and the schema keeps one neutral fallback rather than a refusal: a missing
|
|
65
|
+
-- label is not a reason to hold an export back, and unlike an account code
|
|
66
|
+
-- there is no wrong answer it could silently give.
|
|
67
|
+
--
|
|
68
|
+
-- It is `defaults.opening_entry_label` in the pack, next to `closing_style`
|
|
69
|
+
-- and the account roles the close reads. Not an i18n key: this label is
|
|
70
|
+
-- addressed to an administration, in the language of the country whose file it
|
|
71
|
+
-- is, and not to whoever happens to be signed in.
|
|
72
|
+
|
|
73
|
+
alter table country_defaults
|
|
74
|
+
add column if not exists opening_entry_label text;
|
|
75
|
+
|
|
76
|
+
comment on column country_defaults.opening_entry_label is
|
|
77
|
+
'Wording the computed opening lines of an export carry, from the pack, in the language the administration of this country reads. Null falls back to a neutral English label: the format fixes no wording, so there is no wrong answer to guess at.';
|
|
78
|
+
|
|
79
|
+
-- ---------------------------------------------------------------------------
|
|
80
|
+
-- fec_lines
|
|
81
|
+
--
|
|
82
|
+
-- Same signature, same eighteen columns, same row shape: the format package
|
|
83
|
+
-- and the MCP tool that read it need no change. What is new comes first in
|
|
84
|
+
-- the result, as an *à-nouveaux* does in the file.
|
|
85
|
+
-- ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
create or replace function fec_lines(
|
|
88
|
+
p_company_id uuid,
|
|
89
|
+
p_from date,
|
|
90
|
+
p_to date
|
|
91
|
+
)
|
|
92
|
+
returns table (
|
|
93
|
+
journal_code text,
|
|
94
|
+
journal_lib text,
|
|
95
|
+
ecriture_num text,
|
|
96
|
+
ecriture_date date,
|
|
97
|
+
compte_num text,
|
|
98
|
+
compte_lib text,
|
|
99
|
+
comp_aux_num text,
|
|
100
|
+
comp_aux_lib text,
|
|
101
|
+
piece_ref text,
|
|
102
|
+
piece_date date,
|
|
103
|
+
ecriture_lib text,
|
|
104
|
+
debit numeric,
|
|
105
|
+
credit numeric,
|
|
106
|
+
ecriture_let text,
|
|
107
|
+
date_let date,
|
|
108
|
+
valid_date date,
|
|
109
|
+
montant_devise numeric,
|
|
110
|
+
idevise text
|
|
111
|
+
)
|
|
112
|
+
language plpgsql
|
|
113
|
+
stable
|
|
114
|
+
as $$
|
|
115
|
+
declare
|
|
116
|
+
v_year fiscal_years%rowtype;
|
|
117
|
+
v_defaults country_defaults%rowtype;
|
|
118
|
+
v_journal journals%rowtype;
|
|
119
|
+
v_label text;
|
|
120
|
+
v_number text;
|
|
121
|
+
v_result numeric(16, 2) := 0;
|
|
122
|
+
v_carried integer := 0;
|
|
123
|
+
v_role text;
|
|
124
|
+
v_account uuid;
|
|
125
|
+
v_result_code text;
|
|
126
|
+
v_result_name text;
|
|
127
|
+
v_carries boolean;
|
|
128
|
+
begin
|
|
129
|
+
-- 1. Is this the file of a whole financial year? Only then are there
|
|
130
|
+
-- opening balances to carry.
|
|
131
|
+
|
|
132
|
+
select f.* into v_year
|
|
133
|
+
from fiscal_years f
|
|
134
|
+
where f.company_id = p_company_id
|
|
135
|
+
and f.start_date = p_from
|
|
136
|
+
and f.end_date = p_to;
|
|
137
|
+
|
|
138
|
+
if found then
|
|
139
|
+
-- What stands on the day before the year opens. `trial_balance` is where
|
|
140
|
+
-- this repository computes a cumulative balance, and computing it a
|
|
141
|
+
-- second time here is how the two would start to disagree.
|
|
142
|
+
select coalesce(round(sum(t.opening_balance) filter (where not a.carries_forward), 2), 0),
|
|
143
|
+
count(*) filter (where a.carries_forward and round(t.opening_balance, 2) <> 0)
|
|
144
|
+
into v_result, v_carried
|
|
145
|
+
from trial_balance(p_company_id, p_from, p_to) t
|
|
146
|
+
join accounts a on a.id = t.account_id;
|
|
147
|
+
|
|
148
|
+
-- A first set of books has nothing to carry, and asks the pack for
|
|
149
|
+
-- nothing. Everything below is needed only when there is a balance.
|
|
150
|
+
if v_carried > 0 or v_result <> 0 then
|
|
151
|
+
select d.* into v_defaults
|
|
152
|
+
from companies c
|
|
153
|
+
join country_defaults d on d.country = c.country
|
|
154
|
+
where c.id = p_company_id;
|
|
155
|
+
|
|
156
|
+
select j.* into v_journal from journals j where j.id = opening_journal_id(p_company_id);
|
|
157
|
+
if not found then
|
|
158
|
+
raise exception 'no_opening_journal: the pack of this company names no journal of type opening, and the opening balances of a financial year are booked on one. Set defaults.journal_roles.opening in the pack, which fills country_defaults.opening_journal_code.'
|
|
159
|
+
using errcode = '55006';
|
|
160
|
+
end if;
|
|
161
|
+
|
|
162
|
+
v_label := coalesce(v_defaults.opening_entry_label, 'Opening balance');
|
|
163
|
+
|
|
164
|
+
-- One entry, so the file has one balanced *à-nouveaux* rather than as
|
|
165
|
+
-- many single-sided entries as there are accounts. The number is built
|
|
166
|
+
-- from the journal the pack names and the day the year opens, which
|
|
167
|
+
-- makes it stable across two exports of the same year and distinct
|
|
168
|
+
-- between years — including two short years inside one calendar year.
|
|
169
|
+
v_number := v_journal.code || '-' || to_char(v_year.start_date, 'YYYYMMDD');
|
|
170
|
+
|
|
171
|
+
-- 2. The result of the years that are not closed yet, on the account
|
|
172
|
+
-- the close would have left it on. `result_accounts` keeps it on a
|
|
173
|
+
-- balance-sheet account of its own until a meeting allocates it;
|
|
174
|
+
-- the other two styles have already reached retained earnings by the
|
|
175
|
+
-- time the year is over — an appropriation account is inside the
|
|
176
|
+
-- income statement and the closing entry empties it, so it is never
|
|
177
|
+
-- what a balance sheet carries forward.
|
|
178
|
+
if v_result <> 0 then
|
|
179
|
+
v_role := case v_defaults.closing_style
|
|
180
|
+
when 'result_accounts' then
|
|
181
|
+
case when v_result < 0 then v_defaults.current_year_result_profit_code
|
|
182
|
+
else v_defaults.current_year_result_loss_code end
|
|
183
|
+
when 'appropriation_accounts' then
|
|
184
|
+
case when v_result < 0 then v_defaults.retained_earnings_code
|
|
185
|
+
else coalesce(v_defaults.retained_earnings_loss_code,
|
|
186
|
+
v_defaults.retained_earnings_code) end
|
|
187
|
+
when 'retained_earnings' then
|
|
188
|
+
case when v_result < 0 then v_defaults.retained_earnings_code
|
|
189
|
+
else coalesce(v_defaults.retained_earnings_loss_code,
|
|
190
|
+
v_defaults.retained_earnings_code) end
|
|
191
|
+
end;
|
|
192
|
+
|
|
193
|
+
-- A company may name its own retained earnings account, and
|
|
194
|
+
-- `close_fiscal_year` prefers it for a profit. The same preference
|
|
195
|
+
-- here, or the two would carry the result to two different places.
|
|
196
|
+
if v_result < 0 and v_defaults.closing_style is distinct from 'result_accounts' then
|
|
197
|
+
select c.retained_earnings_account_id into v_account
|
|
198
|
+
from companies c where c.id = p_company_id;
|
|
199
|
+
end if;
|
|
200
|
+
v_account := coalesce(v_account, account_id_by_code(p_company_id, v_role));
|
|
201
|
+
|
|
202
|
+
if v_account is null then
|
|
203
|
+
raise exception 'no_result_account: the books hold a result of % that no year has closed, and the country model of this company names no balance-sheet account to carry it to. Set defaults.closing_style and the account roles it needs in the pack.',
|
|
204
|
+
to_char(-v_result, 'FM9999999999999990.00')
|
|
205
|
+
using errcode = '55006';
|
|
206
|
+
end if;
|
|
207
|
+
|
|
208
|
+
select a.code, a.name, a.carries_forward
|
|
209
|
+
into v_result_code, v_result_name, v_carries
|
|
210
|
+
from accounts a where a.id = v_account;
|
|
211
|
+
|
|
212
|
+
if not v_carries then
|
|
213
|
+
raise exception 'no_result_account: % is an income or expense account, and an opening balance is made of the balance sheet. The country model names it for a result that no year has closed; name an account that carries forward.',
|
|
214
|
+
v_result_code
|
|
215
|
+
using errcode = '55006';
|
|
216
|
+
end if;
|
|
217
|
+
end if;
|
|
218
|
+
|
|
219
|
+
-- 3. The lines themselves. The account rows and the result row share
|
|
220
|
+
-- one shape, so the side is chosen once: a positive balance is a
|
|
221
|
+
-- debit, and a sign never reaches the file.
|
|
222
|
+
return query
|
|
223
|
+
with opening as (
|
|
224
|
+
select t.account_code as code,
|
|
225
|
+
t.account_name as name,
|
|
226
|
+
round(t.opening_balance, 2) as balance
|
|
227
|
+
from trial_balance(p_company_id, p_from, p_to) t
|
|
228
|
+
join accounts a on a.id = t.account_id
|
|
229
|
+
where a.carries_forward
|
|
230
|
+
and round(t.opening_balance, 2) <> 0
|
|
231
|
+
union all
|
|
232
|
+
select v_result_code, v_result_name, v_result
|
|
233
|
+
where v_result <> 0
|
|
234
|
+
)
|
|
235
|
+
select v_journal.code,
|
|
236
|
+
v_journal.name,
|
|
237
|
+
v_number,
|
|
238
|
+
p_from,
|
|
239
|
+
o.code,
|
|
240
|
+
o.name,
|
|
241
|
+
null::text,
|
|
242
|
+
null::text,
|
|
243
|
+
v_number,
|
|
244
|
+
p_from,
|
|
245
|
+
v_label,
|
|
246
|
+
-- Down to the scale the ledger keeps, so an opening line and a
|
|
247
|
+
-- movement line come back in the same shape.
|
|
248
|
+
(case when o.balance > 0 then o.balance else 0 end)::numeric(16, 2),
|
|
249
|
+
(case when o.balance < 0 then -o.balance else 0 end)::numeric(16, 2),
|
|
250
|
+
null::text,
|
|
251
|
+
null::date,
|
|
252
|
+
p_from,
|
|
253
|
+
null::numeric,
|
|
254
|
+
null::text
|
|
255
|
+
from opening o
|
|
256
|
+
order by o.code;
|
|
257
|
+
end if;
|
|
258
|
+
end if;
|
|
259
|
+
|
|
260
|
+
-- 4. The movements of the period, as before, less the entries the close
|
|
261
|
+
-- wrote inside it.
|
|
262
|
+
|
|
263
|
+
return query
|
|
264
|
+
select j.code,
|
|
265
|
+
j.name,
|
|
266
|
+
e.number,
|
|
267
|
+
e.entry_date,
|
|
268
|
+
a.code,
|
|
269
|
+
a.name,
|
|
270
|
+
c.auxiliary_code,
|
|
271
|
+
case when c.auxiliary_code is not null then c.name end,
|
|
272
|
+
coalesce(d.number, d.supplier_reference, e.reference, e.number),
|
|
273
|
+
coalesce(d.document_date, e.entry_date),
|
|
274
|
+
coalesce(nullif(l.name, ''), e.description, a.name),
|
|
275
|
+
l.debit,
|
|
276
|
+
l.credit,
|
|
277
|
+
l.matching_number,
|
|
278
|
+
(select max(r.matched_at) from reconciliations r
|
|
279
|
+
where r.debit_line_id = l.id or r.credit_line_id = l.id),
|
|
280
|
+
coalesce(e.posted_at::date, e.entry_date),
|
|
281
|
+
case when l.currency_code is not null and l.currency_code <> co.currency_code
|
|
282
|
+
then l.amount_currency end,
|
|
283
|
+
-- `char(3)` where the column of this function is `text`: RETURN
|
|
284
|
+
-- QUERY matches types exactly, where the SQL body this replaces
|
|
285
|
+
-- coerced them on the way out.
|
|
286
|
+
case when l.currency_code is not null and l.currency_code <> co.currency_code
|
|
287
|
+
then l.currency_code::text end
|
|
288
|
+
from entry_lines l
|
|
289
|
+
join entries e on e.id = l.entry_id
|
|
290
|
+
join journals j on j.id = e.journal_id
|
|
291
|
+
join accounts a on a.id = l.account_id
|
|
292
|
+
join companies co on co.id = l.company_id
|
|
293
|
+
left join contacts c on c.id = l.contact_id
|
|
294
|
+
left join documents d on d.id = e.document_id
|
|
295
|
+
where l.company_id = p_company_id
|
|
296
|
+
and e.state = 'posted'
|
|
297
|
+
and e.entry_date between p_from and p_to
|
|
298
|
+
and e.kind not in ('closing', 'appropriation')
|
|
299
|
+
order by e.entry_date, e.number, l.sequence, l.id;
|
|
300
|
+
end;
|
|
301
|
+
$$;
|
|
302
|
+
|
|
303
|
+
comment on function fec_lines(uuid, date, date) is
|
|
304
|
+
'The eighteen columns of the French FEC for a period: the opening balances of the financial year first, computed and never posted, then its movements in chronological order. The entries the close wrote are left out — the file carries the income statement in its ordinary lines, and the result reaches the balance sheet in the opening lines of the year that follows.';
|
|
305
|
+
|
|
306
|
+
-- Rule 6 of supabase/migrations/README.md.
|
|
307
|
+
revoke execute on all functions in schema public from public;
|