feat: document totals, VAT summary, stamp duty, withholding and installments (#48)
The engine now computes the totals of every document it saves: line amounts with cascaded discounts, footer discount on goods, VAT summary per tax code with the tax on the group total, prices with VAT split back once per group, split payment and cash-basis exigibility, stamp duty above the threshold of the fiscal pack, social security contribution, withholding (also on part of the amount) and ENASARCO taken off the amount to pay. Installments come from the payment terms with end of month, fixed day, the customer's excluded months and VAT on the first installment. The figures live in two shared tables keyed by family (ADR 0033) and are rewritten in the same transaction as the document. DocumentEditor serves the screens: radars, values proposed by party and item, totals preview without saving, linked documents and open documents to fulfil. The copy service can merge several documents of one party, the base of deferred invoicing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddd2273f7e
commit
f12848865d
21 files changed
+1916
-31
No files matched your search
@@ -5,7 +5,7 @@ namespace Khaemhat.Data.CompanyDatabase.Migrations;
|
||||
|
||||
/// <summary>
|
||||
/// The document engine (SPEC §11.3, ADR 0032, issue #47): six families of headers with their lines, the fulfilment
|
||||
/// links, the kind of each document type and the date of the last number of each numerator.
|
||||
/// links, the tax summaries and installments (#48), the kind of each document type and the date of the last number of each numerator.
|
||||
/// </summary>
|
||||
[Migration(20261112_003, "create_documents")]
|
||||
public sealed class M20261112_003_CreateDocuments : IMigration
|
||||
@@ -30,6 +30,12 @@ public sealed class M20261112_003_CreateDocuments : IMigration
|
||||
}
|
||||
|
||||
schema.AlterTable("document_numerators", t => t.Date("last_date"));
|
||||
schema.AlterTable("party_sales_terms", t =>
|
||||
{
|
||||
t.Int32("excluded_month1");
|
||||
t.Int32("excluded_month2");
|
||||
t.Int32("excluded_months_day");
|
||||
});
|
||||
|
||||
Family(schema, "sale_quotations", "sale_quotation_lines");
|
||||
Family(schema, "sale_orders", "sale_order_lines");
|
||||
@@ -53,6 +59,40 @@ public sealed class M20261112_003_CreateDocuments : IMigration
|
||||
t.Index("ix_document_links_source_document", "source_family", "source_document_id");
|
||||
t.Index("ix_document_links_target", "target_family", "target_document_id");
|
||||
});
|
||||
|
||||
schema.CreateTable("document_tax_summaries", t =>
|
||||
{
|
||||
t.Id();
|
||||
t.String("family", 40).NotNull();
|
||||
t.Int64("document_id").NotNull();
|
||||
t.Int64("tax_code_id");
|
||||
t.Decimal("rate").NotNull();
|
||||
t.String("nature", 10);
|
||||
t.String("exigibility", 40).NotNull();
|
||||
t.Decimal("non_deductible_percent").NotNull().Default(0m);
|
||||
t.String("legal_reference", 100);
|
||||
t.Decimal("taxable").NotNull();
|
||||
t.Decimal("tax").NotNull();
|
||||
t.Decimal("non_deductible_tax").NotNull().Default(0m);
|
||||
t.AuditColumns();
|
||||
t.Index("ix_document_tax_summaries_document", "family", "document_id");
|
||||
t.ForeignKey("fk_document_tax_summaries_tax_code", "tax_code_id", "tax_codes", ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
schema.CreateTable("document_installments", t =>
|
||||
{
|
||||
t.Id();
|
||||
t.String("family", 40).NotNull();
|
||||
t.Int64("document_id").NotNull();
|
||||
t.Int32("number").NotNull();
|
||||
t.Date("due_date").NotNull();
|
||||
t.Decimal("amount").NotNull();
|
||||
t.Int64("payment_method_id");
|
||||
t.AuditColumns();
|
||||
t.Index("ix_document_installments_document", "family", "document_id");
|
||||
t.Index("ix_document_installments_due", "due_date");
|
||||
t.ForeignKey("fk_document_installments_payment_method", "payment_method_id", "payment_methods", ReferentialAction.Restrict);
|
||||
});
|
||||
}
|
||||
|
||||
private static void Family(ISchemaBuilder schema, string headers, string lines)
|
||||
@@ -107,6 +147,27 @@ public sealed class M20261112_003_CreateDocuments : IMigration
|
||||
t.Decimal("withholding_amount").NotNull().Default(0m);
|
||||
t.Decimal("social_security_amount").NotNull().Default(0m);
|
||||
t.Decimal("net_amount").NotNull().Default(0m);
|
||||
t.Bool("prices_include_tax").NotNull().Default(false);
|
||||
t.Decimal("footer_discount_amount").NotNull().Default(0m);
|
||||
t.String("exigibility", 40);
|
||||
t.Bool("split_payment").NotNull().Default(false);
|
||||
t.Bool("stamp_duty_charged").NotNull().Default(false);
|
||||
t.Decimal("withholding_rate");
|
||||
t.Decimal("withholding_base_percent").NotNull().Default(100m);
|
||||
t.String("withholding_type", 4);
|
||||
t.String("withholding_reason", 2);
|
||||
t.String("social_security_fund", 4);
|
||||
t.Decimal("social_security_rate");
|
||||
t.Int64("social_security_tax_code_id");
|
||||
t.Bool("social_security_withheld").NotNull().Default(false);
|
||||
t.Decimal("enasarco_rate");
|
||||
t.Decimal("enasarco_amount").NotNull().Default(0m);
|
||||
t.String("cig", 15);
|
||||
t.String("cup", 15);
|
||||
t.String("transport_by", 40);
|
||||
t.Int64("related_document_id");
|
||||
t.String("related_number", 30);
|
||||
t.Date("related_date");
|
||||
t.Text("notes");
|
||||
t.Int64("gl_entry_id");
|
||||
t.Int64("vat_protocol");
|
||||
@@ -135,6 +196,8 @@ public sealed class M20261112_003_CreateDocuments : IMigration
|
||||
t.ForeignKey("fk_" + headers + "_shipping_term", "shipping_term_id", "shipping_terms", ReferentialAction.Restrict);
|
||||
t.ForeignKey("fk_" + headers + "_carrier", "carrier_id", "carriers", ReferentialAction.Restrict);
|
||||
t.ForeignKey("fk_" + headers + "_goods_appearance", "goods_appearance_id", "goods_appearances", ReferentialAction.Restrict);
|
||||
t.ForeignKey("fk_" + headers + "_social_security_tax_code", "social_security_tax_code_id", "tax_codes", ReferentialAction.Restrict);
|
||||
t.ForeignKey("fk_" + headers + "_related", "related_document_id", headers, ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
schema.CreateTable(lines, t =>
|
||||
@@ -158,6 +221,7 @@ public sealed class M20261112_003_CreateDocuments : IMigration
|
||||
t.Bool("fulfillment_closed").NotNull().Default(false);
|
||||
t.String("source_family", 40);
|
||||
t.Int64("source_line_id");
|
||||
t.Bool("withholding_excluded").NotNull().Default(false);
|
||||
t.String("account_code", 20);
|
||||
t.Int64("cost_center_id");
|
||||
t.Int64("job_id");
|
||||
|
||||
Reference in new issue
Block a user