using Khaemhat.Data.Migrations;
using Khaemhat.Data.Schema;
namespace Khaemhat.Data.CompanyDatabase.Migrations;
/// VAT codes, payment methods and terms, bank accounts and salespeople (SPEC ยง11.1, mockup 076).
[Migration(20261111_012, "create_tax_and_payment_tables")]
public sealed class M20261111_012_CreateTaxAndPaymentTables : IMigration
{
///
public void Up(ISchemaBuilder schema)
{
ArgumentNullException.ThrowIfNull(schema);
schema.CreateTable("tax_codes", t =>
{
t.Id();
t.String("code", 10).NotNull();
t.String("description", 100).NotNull();
t.Bool("disabled").NotNull().Default(false);
t.Decimal("rate").NotNull();
t.String("nature", 5);
t.String("kind", 40).NotNull();
t.String("exigibility", 40).NotNull();
t.Decimal("non_deductible_percent").NotNull();
t.String("legal_reference", 200);
t.Date("valid_from");
t.Date("valid_to");
t.String("sales_account_code", 20);
t.String("purchase_account_code", 20);
t.DemoColumn();
t.AuditColumns();
t.Unique("ux_tax_codes_code", "code");
});
schema.CreateTable("payment_methods", t =>
{
t.Id();
t.String("code", 10).NotNull();
t.String("description", 100).NotNull();
t.Bool("disabled").NotNull().Default(false);
t.String("e_invoice_code", 4).NotNull();
t.Bool("needs_bank").NotNull().Default(false);
t.DemoColumn();
t.AuditColumns();
t.Unique("ux_payment_methods_code", "code");
});
schema.CreateTable("payment_terms", t =>
{
t.Id();
t.String("code", 10).NotNull();
t.String("description", 100).NotNull();
t.Bool("disabled").NotNull().Default(false);
t.Int64("payment_method_id");
t.String("condition", 4).NotNull();
t.Bool("vat_on_first_installment").NotNull().Default(false);
t.DemoColumn();
t.AuditColumns();
t.Unique("ux_payment_terms_code", "code");
t.ForeignKey("fk_payment_terms_payment_method", "payment_method_id", "payment_methods", ReferentialAction.Restrict);
});
schema.CreateTable("payment_term_lines", t =>
{
t.Id();
t.Int64("payment_term_id").NotNull();
t.Int32("number").NotNull();
t.Int32("days").NotNull();
t.Bool("end_of_month").NotNull().Default(false);
t.Int32("fixed_day");
t.Decimal("percent").NotNull();
t.AuditColumns();
t.Unique("ux_payment_term_lines_payment_term_id_number", "payment_term_id", "number");
t.ForeignKey("fk_payment_term_lines_payment_term", "payment_term_id", "payment_terms", ReferentialAction.Cascade);
});
schema.CreateTable("bank_accounts", t =>
{
t.Id();
t.String("code", 10).NotNull();
t.String("description", 100).NotNull();
t.Bool("disabled").NotNull().Default(false);
t.String("bank_name", 100);
t.String("iban", 34);
t.String("bic", 11);
t.String("sia_code", 5);
t.String("cuc_code", 8);
t.String("account_code", 20);
t.Bool("is_default").NotNull().Default(false);
t.DemoColumn();
t.AuditColumns();
t.Unique("ux_bank_accounts_code", "code");
});
schema.CreateTable("salespeople", t =>
{
t.Id();
t.String("code", 10).NotNull();
t.String("description", 100).NotNull();
t.Bool("disabled").NotNull().Default(false);
t.String("email", 254);
t.String("phone", 30);
t.Decimal("commission_percent").NotNull();
t.Bool("enasarco").NotNull().Default(false);
t.DemoColumn();
t.AuditColumns();
t.Unique("ux_salespeople_code", "code");
});
}
}