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,144 @@
|
|
|
1
|
+
-- Ekwo OS — a foreign key without an index is a sequential scan waiting for
|
|
2
|
+
-- a big enough table.
|
|
3
|
+
--
|
|
4
|
+
-- Postgres indexes the *referenced* side of a foreign key, because that side
|
|
5
|
+
-- is a primary key. It indexes nothing on the referencing side. Two things
|
|
6
|
+
-- then read the whole table:
|
|
7
|
+
--
|
|
8
|
+
-- * every delete or key update of the parent, which has to prove no child
|
|
9
|
+
-- points at the row — deleting one contact scans `entry_lines`;
|
|
10
|
+
-- * every join written the natural way, which for an accounting core is
|
|
11
|
+
-- most of them: a document to its lines, an entry to its lines, a line to
|
|
12
|
+
-- its account, its tax, its contact.
|
|
13
|
+
--
|
|
14
|
+
-- On the demo company nothing is slow, which is exactly why this survived 49
|
|
15
|
+
-- migrations. On a company with four years of books it is the difference
|
|
16
|
+
-- between a report and a timeout.
|
|
17
|
+
--
|
|
18
|
+
-- 71 indexes: every foreign key of the socle that had none, and the
|
|
19
|
+
-- `company_id` of the tables that had none either — which the sweep covers,
|
|
20
|
+
-- because `company_id` is itself a foreign key everywhere it appears.
|
|
21
|
+
--
|
|
22
|
+
-- Where a table has both a single-column key and a composite one leading with
|
|
23
|
+
-- the same column — `(account_id)` and `(account_id, company_id)`, the shape
|
|
24
|
+
-- this schema uses to keep a child in its parent's company — one index on the
|
|
25
|
+
-- composite serves both, and that is the one created.
|
|
26
|
+
--
|
|
27
|
+
-- The list is not maintained by hand. `tests/schema.test.ts` asks the
|
|
28
|
+
-- catalogue the same question and fails when the answer is not empty, so a
|
|
29
|
+
-- foreign key added later arrives with its index or the build says so.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
-- public.accounts
|
|
33
|
+
create index if not exists accounts_currency_idx on accounts (currency_code);
|
|
34
|
+
|
|
35
|
+
-- public.analytic_values
|
|
36
|
+
create index if not exists analytic_values_axis_company_idx on analytic_values (axis_id, company_id);
|
|
37
|
+
create index if not exists analytic_values_company_idx on analytic_values (company_id);
|
|
38
|
+
|
|
39
|
+
-- public.bank_accounts
|
|
40
|
+
create index if not exists bank_accounts_account_company_idx on bank_accounts (account_id, company_id);
|
|
41
|
+
create index if not exists bank_accounts_currency_idx on bank_accounts (currency_code);
|
|
42
|
+
create index if not exists bank_accounts_journal_company_idx on bank_accounts (journal_id, company_id);
|
|
43
|
+
|
|
44
|
+
-- public.bank_statements
|
|
45
|
+
create index if not exists bank_statements_bank_account_company_idx on bank_statements (bank_account_id, company_id);
|
|
46
|
+
create index if not exists bank_statements_company_idx on bank_statements (company_id);
|
|
47
|
+
|
|
48
|
+
-- public.bank_transactions
|
|
49
|
+
create index if not exists bank_transactions_bank_account_company_idx on bank_transactions (bank_account_id, company_id);
|
|
50
|
+
create index if not exists bank_transactions_contact_company_idx on bank_transactions (contact_id, company_id);
|
|
51
|
+
create index if not exists bank_transactions_currency_idx on bank_transactions (currency_code);
|
|
52
|
+
create index if not exists bank_transactions_entry_company_idx on bank_transactions (entry_id, company_id);
|
|
53
|
+
create index if not exists bank_transactions_statement_company_idx on bank_transactions (statement_id, company_id);
|
|
54
|
+
|
|
55
|
+
-- public.companies
|
|
56
|
+
create index if not exists companies_default_bank_account_idx on companies (default_bank_account_id);
|
|
57
|
+
create index if not exists companies_default_purchase_account_idx on companies (default_purchase_account_id);
|
|
58
|
+
create index if not exists companies_default_sales_account_idx on companies (default_sales_account_id);
|
|
59
|
+
create index if not exists companies_miscellaneous_journal_idx on companies (miscellaneous_journal_id);
|
|
60
|
+
create index if not exists companies_payable_account_idx on companies (payable_account_id);
|
|
61
|
+
create index if not exists companies_purchase_journal_idx on companies (purchase_journal_id);
|
|
62
|
+
create index if not exists companies_receivable_account_idx on companies (receivable_account_id);
|
|
63
|
+
create index if not exists companies_retained_earnings_account_idx on companies (retained_earnings_account_id);
|
|
64
|
+
create index if not exists companies_rounding_account_idx on companies (rounding_account_id);
|
|
65
|
+
create index if not exists companies_sales_journal_idx on companies (sales_journal_id);
|
|
66
|
+
create index if not exists companies_share_capital_currency_idx on companies (share_capital_currency);
|
|
67
|
+
create index if not exists companies_suspense_account_idx on companies (suspense_account_id);
|
|
68
|
+
|
|
69
|
+
-- public.contacts
|
|
70
|
+
create index if not exists contacts_currency_idx on contacts (currency_code);
|
|
71
|
+
create index if not exists contacts_payable_account_idx on contacts (payable_account_id);
|
|
72
|
+
create index if not exists contacts_receivable_account_idx on contacts (receivable_account_id);
|
|
73
|
+
|
|
74
|
+
-- public.document_lines
|
|
75
|
+
create index if not exists document_lines_account_company_idx on document_lines (account_id, company_id);
|
|
76
|
+
create index if not exists document_lines_company_idx on document_lines (company_id);
|
|
77
|
+
create index if not exists document_lines_document_company_idx on document_lines (document_id, company_id);
|
|
78
|
+
create index if not exists document_lines_product_company_idx on document_lines (product_id, company_id);
|
|
79
|
+
create index if not exists document_lines_tax_company_idx on document_lines (tax_id, company_id);
|
|
80
|
+
|
|
81
|
+
-- public.documents
|
|
82
|
+
create index if not exists documents_contact_company_idx on documents (contact_id, company_id);
|
|
83
|
+
create index if not exists documents_currency_idx on documents (currency_code);
|
|
84
|
+
create index if not exists documents_entry_company_idx on documents (entry_id, company_id);
|
|
85
|
+
create index if not exists documents_journal_company_idx on documents (journal_id, company_id);
|
|
86
|
+
create index if not exists documents_reversed_document_idx on documents (reversed_document_id);
|
|
87
|
+
|
|
88
|
+
-- public.entries
|
|
89
|
+
create index if not exists entries_currency_idx on entries (currency_code);
|
|
90
|
+
create index if not exists entries_journal_company_idx on entries (journal_id, company_id);
|
|
91
|
+
-- `entries_module_idx` is taken, by `(company_id, module_code)` — which does
|
|
92
|
+
-- not lead with `module_code`, so it does not serve the foreign key to
|
|
93
|
+
-- `modules`.
|
|
94
|
+
create index if not exists entries_module_code_idx on entries (module_code);
|
|
95
|
+
create index if not exists entries_reversed_entry_idx on entries (reversed_entry_id);
|
|
96
|
+
|
|
97
|
+
-- public.entry_line_analytics
|
|
98
|
+
create index if not exists entry_line_analytics_analytic_value_company_idx on entry_line_analytics (analytic_value_id, company_id);
|
|
99
|
+
create index if not exists entry_line_analytics_company_idx on entry_line_analytics (company_id);
|
|
100
|
+
create index if not exists entry_line_analytics_entry_line_company_idx on entry_line_analytics (entry_line_id, company_id);
|
|
101
|
+
|
|
102
|
+
-- public.entry_lines
|
|
103
|
+
create index if not exists entry_lines_account_company_idx on entry_lines (account_id, company_id);
|
|
104
|
+
create index if not exists entry_lines_contact_company_idx on entry_lines (contact_id, company_id);
|
|
105
|
+
create index if not exists entry_lines_currency_idx on entry_lines (currency_code);
|
|
106
|
+
create index if not exists entry_lines_entry_company_idx on entry_lines (entry_id, company_id);
|
|
107
|
+
create index if not exists entry_lines_tax_company_idx on entry_lines (tax_id, company_id);
|
|
108
|
+
|
|
109
|
+
-- public.journals
|
|
110
|
+
create index if not exists journals_bank_account_idx on journals (bank_account_id);
|
|
111
|
+
create index if not exists journals_currency_idx on journals (currency_code);
|
|
112
|
+
create index if not exists journals_default_account_idx on journals (default_account_id);
|
|
113
|
+
create index if not exists journals_suspense_account_idx on journals (suspense_account_id);
|
|
114
|
+
|
|
115
|
+
-- public.payments
|
|
116
|
+
create index if not exists payments_bank_account_idx on payments (bank_account_id);
|
|
117
|
+
create index if not exists payments_contact_company_idx on payments (contact_id, company_id);
|
|
118
|
+
create index if not exists payments_currency_idx on payments (currency_code);
|
|
119
|
+
create index if not exists payments_entry_company_idx on payments (entry_id, company_id);
|
|
120
|
+
create index if not exists payments_journal_company_idx on payments (journal_id, company_id);
|
|
121
|
+
|
|
122
|
+
-- public.products
|
|
123
|
+
create index if not exists products_currency_idx on products (currency_code);
|
|
124
|
+
create index if not exists products_purchase_account_company_idx on products (purchase_account_id, company_id);
|
|
125
|
+
create index if not exists products_purchase_tax_company_idx on products (purchase_tax_id, company_id);
|
|
126
|
+
create index if not exists products_sale_account_company_idx on products (sale_account_id, company_id);
|
|
127
|
+
create index if not exists products_sale_tax_company_idx on products (sale_tax_id, company_id);
|
|
128
|
+
|
|
129
|
+
-- public.reconciliations
|
|
130
|
+
create index if not exists reconciliations_credit_line_company_idx on reconciliations (credit_line_id, company_id);
|
|
131
|
+
create index if not exists reconciliations_debit_line_company_idx on reconciliations (debit_line_id, company_id);
|
|
132
|
+
|
|
133
|
+
-- public.role_capabilities
|
|
134
|
+
create index if not exists role_capabilities_capability_idx on role_capabilities (capability);
|
|
135
|
+
|
|
136
|
+
-- public.tax_postings
|
|
137
|
+
create index if not exists tax_postings_account_company_idx on tax_postings (account_id, company_id);
|
|
138
|
+
create index if not exists tax_postings_tax_company_idx on tax_postings (tax_id, company_id);
|
|
139
|
+
|
|
140
|
+
-- public.taxes
|
|
141
|
+
create index if not exists taxes_cash_basis_transition_account_company_idx on taxes (cash_basis_transition_account_id, company_id);
|
|
142
|
+
|
|
143
|
+
-- public.user_preferences
|
|
144
|
+
create index if not exists user_preferences_preferred_company_idx on user_preferences (preferred_company_id);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Ekwo OS — five columns a pack fills and nothing reads yet, said out loud.
|
|
2
|
+
--
|
|
3
|
+
-- Each was added deliberately, with the same argument: the alternative is
|
|
4
|
+
-- migrating a table of years of rows a second time. That argument is sound and
|
|
5
|
+
-- none of them is removed here. What was missing is the sentence that tells a
|
|
6
|
+
-- reader of `docs/schema.md` which of them are load-bearing today and which
|
|
7
|
+
-- are a promise — because a column with a plausible name and no reader is read
|
|
8
|
+
-- as behaviour by whoever meets it next, and a pack author fills it expecting
|
|
9
|
+
-- something to happen.
|
|
10
|
+
--
|
|
11
|
+
-- Nothing changes but the comments, and `docs/schema.md` is generated from
|
|
12
|
+
-- them, so the doc says it too.
|
|
13
|
+
--
|
|
14
|
+
-- The one that has to become behaviour rather than stay documented is
|
|
15
|
+
-- `currencies.decimal_places`: "at the currency's decimals" is the rounding
|
|
16
|
+
-- rule this repository now states in `docs/decisions.md`, and every rounding
|
|
17
|
+
-- in the schema and in the three JavaScript copies is at two. That is right
|
|
18
|
+
-- for every currency the packs carry and wrong for the yen and the dinar. It
|
|
19
|
+
-- is its own sub-task and it is not this migration.
|
|
20
|
+
|
|
21
|
+
comment on column country_defaults.rounding_method is
|
|
22
|
+
'How a country rounds a tax amount, from the pack. **Declared, no reader yet**: every rounding in the schema is round(x, 2), which is half_up, which is what both packs declare — so the column is recorded and not consulted. It becomes behaviour with the sub-task that makes rounding read the currency''s decimals.';
|
|
23
|
+
|
|
24
|
+
comment on column country_defaults.cash_rounding_unit is
|
|
25
|
+
'The smallest coin a cash total is rounded to when it is not the cent — 0.05 in Switzerland, 0.05 in the Netherlands for cash. **Declared, no reader yet**: no cash-payment path exists in the socle, so nothing rounds a total to it. Zero means the cent, which is what both packs declare.';
|
|
26
|
+
|
|
27
|
+
comment on column country_defaults.bank_statement_formats is
|
|
28
|
+
'Statement formats a bank of this country sends — coda, camt.053, cfonb120 — from the pack. **Declared, no reader yet**: the socle has no statement importer; this is what one will dispatch on. A client that offers an import today reads it to know what to offer.';
|
|
29
|
+
|
|
30
|
+
comment on column country_defaults.payment_formats is
|
|
31
|
+
'Payment file formats a bank of this country accepts — pain.001, cfonb160 — from the pack. **Declared, no reader yet**: the socle writes no payment file. Same shape as bank_statement_formats, and it will be read by the same phase.';
|
|
32
|
+
|
|
33
|
+
comment on column currencies.decimal_places is
|
|
34
|
+
'Decimals this currency is written with: 2 for the euro, 0 for the yen, 3 for the dinar. **Declared, no reader yet**: every rounding in the schema and in the format packages is at two decimals, which is right for every currency the packs carry. Making the rounding rule read this column is a sub-task of its own; until it lands, a zero-decimal currency is held correctly and rounded as if it had two.';
|
|
35
|
+
|
|
36
|
+
-- These two are the opposite case and are recorded here so that nobody
|
|
37
|
+
-- mistakes them for the list above: `reconcile()` writes them, `unreconcile()`
|
|
38
|
+
-- reads `fx_entry_id` to reverse the entry it points at, and the MCP server
|
|
39
|
+
-- returns both on a matching. They are read.
|
|
40
|
+
comment on column reconciliations.fx_entry_id is
|
|
41
|
+
'The entry that booked the realised exchange difference this matching revealed, or null. Written by reconcile() and read by unreconcile(), which reverses it.';
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
-- Ekwo OS — every label a user reads is translatable, and a pack says which
|
|
2
|
+
-- languages it publishes.
|
|
3
|
+
--
|
|
4
|
+
-- The chart of accounts, the declaration boxes, the financial statements, the
|
|
5
|
+
-- legal mentions of an invoice and the fixed-asset categories already carried
|
|
6
|
+
-- `name_i18n` / `text_i18n`. Journals and taxes did not, so a company keeping
|
|
7
|
+
-- its books in Dutch read "Journal des ventes" and "TVA 21 %" next to a chart
|
|
8
|
+
-- of accounts in Dutch. A label without a translation column is a label that
|
|
9
|
+
-- can only ever be shown in the language whoever wrote the pack happened to
|
|
10
|
+
-- speak, so the two that were missing get theirs here, and the country's own
|
|
11
|
+
-- name gets one too.
|
|
12
|
+
--
|
|
13
|
+
-- The shape is the one the rest of the schema already uses: `name` holds the
|
|
14
|
+
-- label in the language of the pack, `name_i18n` is an object keyed by
|
|
15
|
+
-- language code, and `label_for(name, name_i18n, preferred_languages(company))`
|
|
16
|
+
-- is the only way either is read.
|
|
17
|
+
|
|
18
|
+
-- ---------------------------------------------------------------------------
|
|
19
|
+
-- The columns
|
|
20
|
+
-- ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
alter table journal_templates add column if not exists name_i18n jsonb not null default '{}'::jsonb;
|
|
23
|
+
alter table journals add column if not exists name_i18n jsonb not null default '{}'::jsonb;
|
|
24
|
+
alter table tax_templates add column if not exists name_i18n jsonb not null default '{}'::jsonb;
|
|
25
|
+
alter table taxes add column if not exists name_i18n jsonb not null default '{}'::jsonb;
|
|
26
|
+
alter table country_defaults add column if not exists name_i18n jsonb not null default '{}'::jsonb;
|
|
27
|
+
alter table country_defaults add column if not exists languages text[] not null default '{}'::text[];
|
|
28
|
+
|
|
29
|
+
comment on column journal_templates.name_i18n is
|
|
30
|
+
'Label by language, from packs/<cc>/i18n/. The language the pack itself is written in stays in `name`.';
|
|
31
|
+
comment on column journals.name_i18n is
|
|
32
|
+
'Label by language, copied from the template at install. `name` holds the language the company chose, and a company may rename a journal without losing the other languages.';
|
|
33
|
+
comment on column tax_templates.name_i18n is
|
|
34
|
+
'Label by language, from packs/<cc>/i18n/. A translation of the same tax, never a different rate or a different rule.';
|
|
35
|
+
comment on column taxes.name_i18n is
|
|
36
|
+
'Label by language, copied from the template at install. `name` holds the language the company chose.';
|
|
37
|
+
comment on column country_defaults.name_i18n is
|
|
38
|
+
'The country''s own name by language, from packs/<cc>/i18n/. `name` holds it in English, which is what a country pack manifest is written in.';
|
|
39
|
+
comment on column country_defaults.languages is
|
|
40
|
+
'Languages this country pack publishes every label in, the language of the pack itself first. An installer offers them; nothing in the schema restricts a company to them.';
|
|
41
|
+
|
|
42
|
+
-- ---------------------------------------------------------------------------
|
|
43
|
+
-- install_country_template, republished
|
|
44
|
+
--
|
|
45
|
+
-- Two statements change. Journals and taxes now copy `name_i18n` and pick the
|
|
46
|
+
-- language the company keeps its books in through `label_for()`, exactly as
|
|
47
|
+
-- the accounts above them already did. Everything else is the function as it
|
|
48
|
+
-- stood.
|
|
49
|
+
-- ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
create or replace function install_country_template(
|
|
52
|
+
p_company_id uuid,
|
|
53
|
+
p_country char(2),
|
|
54
|
+
p_language char(2) default null,
|
|
55
|
+
p_chart_code text default null
|
|
56
|
+
)
|
|
57
|
+
returns void
|
|
58
|
+
language plpgsql
|
|
59
|
+
as $$
|
|
60
|
+
declare
|
|
61
|
+
v_defaults country_defaults%rowtype;
|
|
62
|
+
r record;
|
|
63
|
+
v_tax_id uuid;
|
|
64
|
+
v_language char(2);
|
|
65
|
+
v_version text;
|
|
66
|
+
v_chart text;
|
|
67
|
+
v_charts text;
|
|
68
|
+
begin
|
|
69
|
+
if not exists (select 1 from companies where id = p_company_id) then
|
|
70
|
+
raise exception 'unknown_company: %', p_company_id;
|
|
71
|
+
end if;
|
|
72
|
+
|
|
73
|
+
-- Which chart. The caller names one, or the pack's default stands. A named
|
|
74
|
+
-- chart that does not exist is an error that lists what does: guessing here
|
|
75
|
+
-- would install the wrong plan of accounts and nobody would notice for a
|
|
76
|
+
-- year.
|
|
77
|
+
if p_chart_code is null then
|
|
78
|
+
select c.code into v_chart
|
|
79
|
+
from chart_templates c
|
|
80
|
+
where c.country = p_country and c.is_default;
|
|
81
|
+
if v_chart is null then
|
|
82
|
+
-- No pack for this country, or a pack that names no default chart.
|
|
83
|
+
raise exception 'unknown_country_template: no chart of accounts seeded for %', p_country;
|
|
84
|
+
end if;
|
|
85
|
+
else
|
|
86
|
+
select c.code into v_chart
|
|
87
|
+
from chart_templates c
|
|
88
|
+
where c.country = p_country and c.code = p_chart_code;
|
|
89
|
+
if v_chart is null then
|
|
90
|
+
select string_agg(c.code, ', ' order by c.code) into v_charts
|
|
91
|
+
from chart_templates c where c.country = p_country;
|
|
92
|
+
raise exception 'unknown_chart: % has no chart %. It has: %',
|
|
93
|
+
p_country, p_chart_code, coalesce(v_charts, 'none');
|
|
94
|
+
end if;
|
|
95
|
+
end if;
|
|
96
|
+
|
|
97
|
+
if not exists (
|
|
98
|
+
select 1 from account_templates
|
|
99
|
+
where country = p_country and chart_code = v_chart
|
|
100
|
+
) then
|
|
101
|
+
raise exception 'unknown_country_template: chart % of % holds no account', v_chart, p_country;
|
|
102
|
+
end if;
|
|
103
|
+
|
|
104
|
+
-- The language of the copy: what the caller asked for, else what the
|
|
105
|
+
-- company keeps its books in.
|
|
106
|
+
select coalesce(p_language, c.language) into v_language
|
|
107
|
+
from companies c where c.id = p_company_id;
|
|
108
|
+
|
|
109
|
+
-- 1. Accounts, without the hierarchy.
|
|
110
|
+
insert into accounts (company_id, code, name, name_i18n, statement_hint,
|
|
111
|
+
account_type, reconcilable)
|
|
112
|
+
select p_company_id, t.code,
|
|
113
|
+
label_for(t.name, t.name_i18n, array[v_language]),
|
|
114
|
+
t.name_i18n, t.statement_hint, t.account_type, t.reconcilable
|
|
115
|
+
from account_templates t
|
|
116
|
+
where t.country = p_country
|
|
117
|
+
and t.chart_code = v_chart
|
|
118
|
+
on conflict (company_id, code) do nothing;
|
|
119
|
+
|
|
120
|
+
-- 2. Hierarchy, now that every code exists.
|
|
121
|
+
update accounts a
|
|
122
|
+
set parent_id = p.id
|
|
123
|
+
from account_templates t
|
|
124
|
+
join accounts p on p.company_id = p_company_id and p.code = t.parent_code
|
|
125
|
+
where a.company_id = p_company_id
|
|
126
|
+
and a.code = t.code
|
|
127
|
+
and t.country = p_country
|
|
128
|
+
and t.chart_code = v_chart
|
|
129
|
+
and t.parent_code is not null
|
|
130
|
+
and a.parent_id is null;
|
|
131
|
+
|
|
132
|
+
-- 3. Journals. Common to every chart of the country.
|
|
133
|
+
insert into journals (company_id, code, name, name_i18n, journal_type)
|
|
134
|
+
select p_company_id, t.code,
|
|
135
|
+
label_for(t.name, t.name_i18n, array[v_language]),
|
|
136
|
+
t.name_i18n, t.journal_type
|
|
137
|
+
from journal_templates t
|
|
138
|
+
where t.country = p_country
|
|
139
|
+
on conflict (company_id, code) do nothing;
|
|
140
|
+
|
|
141
|
+
-- 4. Taxes and their postings. Also common: a chart changes how a company
|
|
142
|
+
-- presents itself, not what it owes.
|
|
143
|
+
for r in
|
|
144
|
+
select * from tax_templates where country = p_country order by sequence, code
|
|
145
|
+
loop
|
|
146
|
+
v_tax_id := null;
|
|
147
|
+
insert into taxes (company_id, code, name, name_i18n, description, amount_type, amount,
|
|
148
|
+
applies_to, treatment, country, valid_from, valid_to,
|
|
149
|
+
legal_reference, vat_category, exemption_code, sequence,
|
|
150
|
+
tax_kind, recoverable, jurisdiction, price_include,
|
|
151
|
+
cash_basis, cash_basis_transition_account_id)
|
|
152
|
+
values (p_company_id, r.code,
|
|
153
|
+
label_for(r.name, r.name_i18n, array[v_language]),
|
|
154
|
+
r.name_i18n, r.description, r.amount_type, r.amount,
|
|
155
|
+
r.applies_to, r.treatment, p_country, r.valid_from, r.valid_to,
|
|
156
|
+
r.legal_reference, r.vat_category, r.exemption_code, r.sequence,
|
|
157
|
+
r.tax_kind, r.recoverable, r.jurisdiction, r.price_include,
|
|
158
|
+
r.cash_basis, account_id_by_code(p_company_id, r.cash_basis_transition_account_code))
|
|
159
|
+
on conflict (company_id, code) do nothing
|
|
160
|
+
returning id into v_tax_id;
|
|
161
|
+
|
|
162
|
+
if v_tax_id is null then
|
|
163
|
+
continue;
|
|
164
|
+
end if;
|
|
165
|
+
|
|
166
|
+
insert into tax_postings (tax_id, company_id, document_kind, posting_type,
|
|
167
|
+
factor_percent, account_id, declaration_box,
|
|
168
|
+
box_factor_percent, report_code, sequence)
|
|
169
|
+
select v_tax_id, p_company_id, tp.document_kind, tp.posting_type,
|
|
170
|
+
tp.factor_percent, account_id_by_code(p_company_id, tp.account_code),
|
|
171
|
+
tp.declaration_box, tp.box_factor_percent, tp.report_code, tp.sequence
|
|
172
|
+
from tax_posting_templates tp
|
|
173
|
+
where tp.tax_template_id = r.id
|
|
174
|
+
order by tp.sequence;
|
|
175
|
+
end loop;
|
|
176
|
+
|
|
177
|
+
-- 5. Roles.
|
|
178
|
+
select * into v_defaults from country_defaults where country = p_country;
|
|
179
|
+
if found then
|
|
180
|
+
update companies c
|
|
181
|
+
set receivable_account_id = coalesce(c.receivable_account_id, account_id_by_code(p_company_id, v_defaults.receivable_code)),
|
|
182
|
+
payable_account_id = coalesce(c.payable_account_id, account_id_by_code(p_company_id, v_defaults.payable_code)),
|
|
183
|
+
suspense_account_id = coalesce(c.suspense_account_id, account_id_by_code(p_company_id, v_defaults.suspense_code)),
|
|
184
|
+
rounding_account_id = coalesce(c.rounding_account_id, account_id_by_code(p_company_id, v_defaults.rounding_code)),
|
|
185
|
+
retained_earnings_account_id = coalesce(c.retained_earnings_account_id, account_id_by_code(p_company_id, v_defaults.retained_earnings_code)),
|
|
186
|
+
default_sales_account_id = coalesce(c.default_sales_account_id, account_id_by_code(p_company_id, v_defaults.sales_account_code)),
|
|
187
|
+
default_purchase_account_id = coalesce(c.default_purchase_account_id, account_id_by_code(p_company_id, v_defaults.purchase_account_code)),
|
|
188
|
+
sales_journal_id = coalesce(c.sales_journal_id, (select id from journals where company_id = p_company_id and code = v_defaults.sales_journal_code)),
|
|
189
|
+
purchase_journal_id = coalesce(c.purchase_journal_id, (select id from journals where company_id = p_company_id and code = v_defaults.purchase_journal_code)),
|
|
190
|
+
miscellaneous_journal_id = coalesce(c.miscellaneous_journal_id, (select id from journals where company_id = p_company_id and code = v_defaults.misc_journal_code))
|
|
191
|
+
where c.id = p_company_id;
|
|
192
|
+
|
|
193
|
+
-- 6. The financial journals point at their account.
|
|
194
|
+
update journals j
|
|
195
|
+
set default_account_id = account_id_by_code(p_company_id, v_defaults.bank_account_code)
|
|
196
|
+
where j.company_id = p_company_id
|
|
197
|
+
and j.journal_type = 'bank'
|
|
198
|
+
and j.default_account_id is null
|
|
199
|
+
and v_defaults.bank_account_code is not null;
|
|
200
|
+
|
|
201
|
+
update journals j
|
|
202
|
+
set default_account_id = account_id_by_code(p_company_id, v_defaults.cash_account_code)
|
|
203
|
+
where j.company_id = p_company_id
|
|
204
|
+
and j.journal_type = 'cash'
|
|
205
|
+
and j.default_account_id is null
|
|
206
|
+
and v_defaults.cash_account_code is not null;
|
|
207
|
+
end if;
|
|
208
|
+
|
|
209
|
+
-- 7. What was copied, from which version, and on which chart.
|
|
210
|
+
v_version := coalesce((select version from country_packs where country = p_country), '1.0.0');
|
|
211
|
+
|
|
212
|
+
insert into company_packs (company_id, country, version, chart_code)
|
|
213
|
+
values (p_company_id, p_country, v_version, v_chart)
|
|
214
|
+
on conflict (company_id, country) do update
|
|
215
|
+
set version = excluded.version,
|
|
216
|
+
chart_code = excluded.chart_code,
|
|
217
|
+
upgraded_at = now()
|
|
218
|
+
where company_packs.version is distinct from excluded.version
|
|
219
|
+
or company_packs.chart_code is distinct from excluded.chart_code;
|
|
220
|
+
end;
|
|
221
|
+
$$;
|
|
222
|
+
|
|
223
|
+
revoke execute on all functions in schema public from public;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Ekwo OS — schema comments that a reader outside the project can read.
|
|
2
|
+
--
|
|
3
|
+
-- `comment on` is the schema's documentation: it is what `docs/schema.md` is
|
|
4
|
+
-- generated from and what an assistant reads over the API. Five of those
|
|
5
|
+
-- comments named a milestone of the project's own plan — "column only until
|
|
6
|
+
-- P0-6" — which tells somebody reading the schema for the first time nothing
|
|
7
|
+
-- at all, and which two of them had also outlived: cash-basis VAT has been
|
|
8
|
+
-- implemented since, so a comment saying a column had no reader was simply
|
|
9
|
+
-- false.
|
|
10
|
+
--
|
|
11
|
+
-- Nothing changes in the schema itself. A comment is replaced, not added, so
|
|
12
|
+
-- this migration is safe to apply to an installation of any age.
|
|
13
|
+
|
|
14
|
+
comment on column tax_postings.report_code is
|
|
15
|
+
'Declaration form the box belongs to. Copied from the template, and read by vat_return(company, from, to, report_code) to pick out the boxes of one form where a country files more than one.';
|
|
16
|
+
|
|
17
|
+
comment on column tax_templates.cash_basis is
|
|
18
|
+
'The tax falls due when the invoice is paid rather than when it is issued, which is how France taxes services. post_document() books it on the transition account below and on no declaration box; reconcile() moves the settled share to the account and the box it is declared on.';
|
|
19
|
+
|
|
20
|
+
comment on column tax_templates.cash_basis_transition_account_code is
|
|
21
|
+
'Account the tax waits on between the invoice and its payment, by code in the chart of this country. Only read when cash_basis is true.';
|
|
22
|
+
|
|
23
|
+
comment on column taxes.cash_basis is
|
|
24
|
+
'The tax falls due when the invoice is paid rather than when it is issued. The share that has been settled is what reaches the declaration.';
|
|
25
|
+
|
|
26
|
+
comment on column taxes.cash_basis_transition_account_id is
|
|
27
|
+
'Account the tax waits on between the invoice and its payment. Only read when cash_basis is true.';
|