Files
David Štaleker 9d0fb30bf0 - Dodati operacije na pozicijo dela projekta
- Dodatna tabela z operacijami in stanjem (končano/nekončano)
  - šifrant operacij - možnost določevanje privzetih operacij

- Opombe na pozicij dela projekta

- Pogled kooperacij na poziciji dela projekta
  - Izpisano številka kooperacije in kooperant
2026-02-28 09:37:13 +01:00

169 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using EveryThing.Models.CodeTable;
namespace EveryThing.Models.Invoice
{
public class Invoice
{
public class InvoiceStateAttribute : Attribute
{
public string AllowedTypes { get; set; } = "0,1,2,3,4";
}
public enum InvoiceType
{
[Display(Name = "Račun", ShortName = "Racun")]
Invoice = 0,
[Display(Name = "Naročilo", ShortName = "Narocilo")]
Order = 1,
[Display(Name = "Dobavnica", ShortName = "Dobavnica")]
DeliveryNote = 2,
[Display(Name = "Naročilo kupca", ShortName = "Narocilo")]
BuyersOrder = 3,
[Display(Name = "Kooperacija", ShortName = "Kooperacija")]
Cooperation = 4,
}
public enum InvoiceState
{
[Display(Name = "Nov")]
[InvoiceState]
New = 0,
[Display(Name = "Povpraševanje")]
[InvoiceState(AllowedTypes = "1")]
Inquiry = 1,
[Display(Name = "Ponudba")]
[InvoiceState(AllowedTypes = "3")]
Offer = 2,
[Display(Name = "Potrjen")]
[InvoiceState]
Confirmed = 10,
[Display(Name = "Potrditev naročila")]
[InvoiceState(AllowedTypes = "3")]
OfferConfirmation = 15,
[Display(Name = "Zaprt")]
[InvoiceState]
Closed = 20
}
[Key]
public int IdInvoice { get; set; }
[Required]
[ForeignKey("Company")]
public int IdCompanyFk { get; set; }
[Required]
[Display(Name = "Datum")]
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true)]
public DateTime Date { get; set; }
[Required]
[Display(Name = "Tip")]
public InvoiceType Type { get; set; }
[Required]
[Display(Name = "Status")]
public InvoiceState State { get; set; } = InvoiceState.New;
[Required]
[ForeignKey("Partner")]
[Display(Name = "Partner")]
public int? IdPartnerFk { get; set; }
[ForeignKey("Project")]
[Display(Name = "Projekt")]
public int? IdProjectFk { get; set; }
[Required]
public int InvoiceNumber { get; set; }
[Required]
public int InvoiceYear { get; set; }
[Display(Name = "Uvodno besedilo")]
public string PreText { get; set; }
[Display(Name = "Zaključno besedilo")]
public string PostText { get; set; }
[Display(Name = "Opomba")]
public string Note { get; set; }
[Display(Name = "Številka naročila kupca")]
public string BuyersOrderNumber { get; set; }
/// <summary>
/// Dobavnica/racun => datum odpreme
/// Narocilo => dobavni rok
/// </summary>
[Display(Name = "Datum odpreme")]
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateOfDispatch { get; set; }
[NotMapped]
public string InvoiceNumberFormatted => $"{InvoiceYear}-{InvoiceNumber}";
[NotMapped]
public string InvoiceNumberFormattedLong => $"{InvoiceNumberFormatted}-{Partner?.Title ?? ""}";
[NotMapped]
public string InvoiceTypeString
{
get
{
if (Type == InvoiceType.BuyersOrder && State == InvoiceState.Offer)
{
return "Ponudba";
}
if (Type == InvoiceType.BuyersOrder && State == InvoiceState.OfferConfirmation)
{
return "Potrditev_narocila";
}
if (Type == InvoiceType.Order && State == InvoiceState.Inquiry)
{
return "Povprasevanje";
}
return Type.GetType().GetMember(Type.ToString()).First().GetCustomAttribute<DisplayAttribute>()?.ShortName;
}
}
[NotMapped]
public string InvoiceNumberFull => $"{InvoiceTypeString}-{InvoiceNumberFormatted}";
[NotMapped] public string InvoiceTypeHeaderString => GetInvoiceTypeHeaderString(Type);
// ForeignKey
public CodeTableCompany Company { get; set; }
public CodeTablePartner Partner { get; set; }
public Project.Project Project { get; set; }
// InvoicePart
[InverseProperty("Invoice")]
public virtual ICollection<InvoiceItem> InvoiceInvoiceItem { get; set; }
public static string GetInvoiceTypeHeaderString(InvoiceType iType)
{
return iType switch
{
InvoiceType.Order => "Naročila dobaviteljem",
0 => "Računi",
InvoiceType.DeliveryNote => "Dobavnice",
InvoiceType.BuyersOrder => "Naročila kupcev",
InvoiceType.Cooperation => "Kooperacije",
_ => "Fakture"
};
}
}
}