using Khaemhat.Core.Entities;
using Khaemhat.Core.Tax;
namespace Khaemhat.Core.Tables;
/// A row of a company table with a code the users type and a description (SPEC §11.1).
public interface ICodedRecord : IEntity
{
/// The code, unique in the table.
string Code { get; set; }
/// The description (or the name).
string Description { get; set; }
/// Hidden from choices on new records; kept for old ones.
bool Disabled { get; set; }
}
/// Base class of the coded tables.
public abstract class CodedEntity : Entity, ICodedRecord, IDemoMarkable
{
///
public string Code { get; set; } = string.Empty;
///
public string Description { get; set; } = string.Empty;
///
public bool Disabled { get; set; }
///
public bool IsDemo { get; set; }
}
/// A country (ISO 3166-1).
public sealed class Country : CodedEntity
{
/// ISO 3166-1 alpha-3 code.
public string? Iso3 { get; set; }
/// Member of the European Union (VIES, Intrastat, intra-EU VAT).
public bool EuMember { get; set; }
/// The prefix of VAT numbers, when different from the code (Greece: EL).
public string? VatPrefix { get; set; }
/// The usual currency (ISO 4217).
public string? CurrencyCode { get; set; }
}
/// An Italian province (code = the two-letter abbreviation).
public sealed class Province : CodedEntity
{
/// The region.
public string? Region { get; set; }
}
/// An Italian municipality (code = cadastral code, used by the fiscal code).
public sealed class Municipality : CodedEntity
{
/// The province abbreviation.
public string ProvinceCode { get; set; } = string.Empty;
/// The region.
public string? Region { get; set; }
/// The ISTAT code (6 digits).
public string? IstatCode { get; set; }
/// The postal codes, comma separated (one for most municipalities, a range for large cities).
public string? PostalCodes { get; set; }
}
/// A currency (ISO 4217).
public sealed class Currency : CodedEntity
{
/// The symbol, such as €.
public string? Symbol { get; set; }
/// Decimals of amounts.
public int Decimals { get; set; } = 2;
}
/// An exchange rate: units of the currency for one euro on a day (ECB reference rate or manual).
public sealed class ExchangeRate : Entity
{
/// The currency (ISO 4217).
public string CurrencyCode { get; set; } = string.Empty;
/// The day.
public DateOnly RateDate { get; set; }
/// Units of the currency for one euro.
public decimal Rate { get; set; }
/// Where the rate comes from: ECB or MANUAL.
public string Source { get; set; } = "MANUAL";
}
/// A unit of measure.
public sealed class UnitOfMeasure : CodedEntity
{
/// Decimals allowed in quantities.
public int Decimals { get; set; }
/// The text written in UnitaMisura of the e-invoice, when different from the code.
public string? EInvoiceCode { get; set; }
}
/// A VAT code (mockup 076).
public sealed class TaxCode : CodedEntity
{
/// The rate in percent.
public decimal Rate { get; set; }
/// The nature for zero-rate operations (N1...N7).
public string? Nature { get; set; }
/// The kind of operation, from rate and nature.
public TaxCodeKind Kind { get; set; }
/// When the tax becomes due.
public TaxExigibility Exigibility { get; set; }
/// Share of the purchase tax that cannot be deducted.
public decimal NonDeductiblePercent { get; set; }
/// The law printed on the invoice.
public string? LegalReference { get; set; }
/// First day of validity.
public DateOnly? ValidFrom { get; set; }
/// Last day of validity.
public DateOnly? ValidTo { get; set; }
/// The VAT account for sales (ledger, M7).
public string? SalesAccountCode { get; set; }
/// The VAT account for purchases (ledger, M7).
public string? PurchaseAccountCode { get; set; }
}
/// A payment method (MP01...MP23).
public sealed class PaymentMethod : CodedEntity
{
/// The FatturaPA code, such as MP05.
public string EInvoiceCode { get; set; } = "MP05";
/// Whether a bank of the customer (RiBa, direct debit) or of the company (transfer) is needed.
public bool NeedsBank { get; set; }
}
/// Payment terms with their installments (lines).
public sealed class PaymentTerm : CodedEntity
{
/// The payment method.
public long? PaymentMethodId { get; set; }
/// The FatturaPA condition: TP01 installments, TP02 full, TP03 advance.
public string Condition { get; set; } = "TP02";
/// All the VAT on the first installment.
public bool VatOnFirstInstallment { get; set; }
}
/// An installment of payment terms.
public sealed class PaymentTermLine : Entity
{
/// The payment terms.
public long PaymentTermId { get; set; }
/// The order of the installment, from 1.
public int Number { get; set; }
/// Days from the document date.
public int Days { get; set; }
/// Move the due date to the end of the month.
public bool EndOfMonth { get; set; }
/// A fixed day of the month after the end-of-month move, such as 10.
public int? FixedDay { get; set; }
/// Share of the amount, in percent.
public decimal Percent { get; set; }
}
/// A bank account of the company.
public sealed class BankAccount : CodedEntity
{
/// The bank.
public string? BankName { get; set; }
/// The IBAN, compact.
public string? Iban { get; set; }
/// The BIC.
public string? Bic { get; set; }
/// The SIA code for RiBa files.
public string? SiaCode { get; set; }
/// The CBI CUC code.
public string? CucCode { get; set; }
/// The ledger account (M7).
public string? AccountCode { get; set; }
/// The account proposed on documents.
public bool IsDefault { get; set; }
}
/// A sales agent (code + name in ).
public sealed class Salesperson : CodedEntity
{
/// The e-mail address.
public string? Email { get; set; }
/// The phone.
public string? Phone { get; set; }
/// The usual commission, in percent.
public decimal CommissionPercent { get; set; }
/// Subject to ENASARCO contributions.
public bool Enasarco { get; set; }
}
/// A carrier (code + name).
public sealed class Carrier : CodedEntity
{
/// The VAT number.
public string? VatNumber { get; set; }
/// The address.
public string? Address { get; set; }
/// The town.
public string? City { get; set; }
/// The phone.
public string? Phone { get; set; }
/// The e-mail address.
public string? Email { get; set; }
/// The registration number in the haulage register.
public string? RegisterNumber { get; set; }
}
/// Who pays the transport (porto: franco, assegnato...).
public sealed class ShippingTerm : CodedEntity;
/// Who carries the goods (mittente, destinatario, vettore).
public sealed class TransportMean : CodedEntity;
/// The appearance of the goods on the delivery note (cartoni, bancali...).
public sealed class GoodsAppearance : CodedEntity;
/// An Incoterms rule.
public sealed class DeliveryTerm : CodedEntity;
/// The reason of the transport (vendita, conto visione...).
public sealed class TransportReason : CodedEntity;
/// What a stock movement does to the quantity on hand.
public enum StockEffect
{
/// No effect on quantities.
None = 0,
/// Increases the stock (load).
Load = 1,
/// Decreases the stock (unload).
Unload = 2,
}
/// A warehouse movement reason.
public sealed class InventoryReason : CodedEntity
{
/// The effect on the quantity.
public StockEffect Effect { get; set; }
/// Whether it changes the stock value (purchases, sales) or only quantities (transfers).
public bool AffectsValue { get; set; } = true;
/// Whether it is a transfer between warehouses (needs a destination).
public bool IsTransfer { get; set; }
}
/// A warehouse.
public sealed class Warehouse : CodedEntity
{
/// The address.
public string? Address { get; set; }
/// The town.
public string? City { get; set; }
/// The province abbreviation.
public string? ProvinceCode { get; set; }
/// The warehouse proposed on documents.
public bool IsDefault { get; set; }
}
/// A category of items, on up to three levels.
public sealed class ItemCategory : CodedEntity
{
/// The parent category.
public long? ParentId { get; set; }
/// The level, 1 to 3.
public int Level { get; set; } = 1;
}
/// A category of customers and suppliers.
public sealed class PartyCategory : CodedEntity;
/// A price list (the prices are in item_prices, mockup 018).
public sealed class PriceList : CodedEntity
{
/// The currency (ISO 4217).
public string CurrencyCode { get; set; } = "EUR";
/// Prices include VAT (retail).
public bool VatIncluded { get; set; }
/// First day of validity.
public DateOnly? ValidFrom { get; set; }
/// Last day of validity.
public DateOnly? ValidTo { get; set; }
/// The list this one derives from.
public long? BasePriceListId { get; set; }
/// Change applied to the base list, in percent (negative for a discount).
public decimal MarkupPercent { get; set; }
/// Rounding step of derived prices, such as 0.05; zero for none.
public decimal RoundingStep { get; set; }
}
/// A discount policy: a chain of discounts such as 10+5.
public sealed class DiscountPolicy : CodedEntity
{
/// The chain of discounts in percent, separated by +.
public string Formula { get; set; } = string.Empty;
}
/// The family of a document numerator.
public enum NumeratorKind
{
/// Quotations.
Quotation = 0,
/// Customer orders.
SalesOrder = 1,
/// Delivery notes.
DeliveryNote = 2,
/// Sales invoices and credit notes (no gaps).
SalesInvoice = 3,
/// Supplier orders.
PurchaseOrder = 4,
/// Purchase protocol.
PurchaseInvoice = 5,
/// Warehouse movements.
Inventory = 6,
/// Journal entries (no gaps).
Journal = 7,
/// Anything else.
Other = 8,
}
/// A document numerator for a year (assignment at confirmation arrives with the documents, M5).
public sealed class DocumentNumerator : CodedEntity
{
/// The family.
public NumeratorKind Kind { get; set; }
/// The section (sezionale), such as A; empty for the main one.
public string? Section { get; set; }
/// The year.
public int Year { get; set; }
/// The prefix.
public string? Prefix { get; set; }
/// The format, such as {prefix}/{year}/{number:D6}.
public string Format { get; set; } = "{number}/{year}";
/// The last number assigned.
public long LastNumber { get; set; }
/// Whether gaps are allowed (never for invoices, credit notes and final entries).
public bool GapsAllowed { get; set; }
}
/// A type of document: the links between a document and its numerator, warehouse reason and SDI type.
public sealed class DocumentType : CodedEntity
{
/// The family of document.
public NumeratorKind Kind { get; set; }
/// The numerator.
public long? NumeratorId { get; set; }
/// The warehouse reason.
public long? InventoryReasonId { get; set; }
/// The SDI document type (TD01...).
public string? EInvoiceType { get; set; }
/// The journal template (ledger, M7).
public string? JournalTemplateCode { get; set; }
/// The VAT register (ledger, M7).
public string? VatRegisterCode { get; set; }
/// The print template.
public string? PrintTemplate { get; set; }
}
/// A cost centre.
public sealed class CostCenter : CodedEntity
{
/// The parent cost centre.
public long? ParentId { get; set; }
}
/// The state of a job.
public enum JobStatus
{
/// Open.
Open = 0,
/// Suspended.
Suspended = 1,
/// Closed.
Closed = 2,
}
/// A job (commessa).
public sealed class Job : CodedEntity
{
/// The customer, when the job is for one.
public long? PartyId { get; set; }
/// The start.
public DateOnly? StartDate { get; set; }
/// The end.
public DateOnly? EndDate { get; set; }
/// The state.
public JobStatus Status { get; set; }
}