Prvi commit
This commit is contained in:
143
EveryThing/Models/Invoice/Invoice.cs
Normal file
143
EveryThing/Models/Invoice/Invoice.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
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";
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
[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 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}";
|
||||
|
||||
// ForeignKey
|
||||
public CodeTableCompany Company { get; set; }
|
||||
|
||||
public CodeTablePartner Partner { get; set; }
|
||||
|
||||
// InvoicePart
|
||||
[InverseProperty("Invoice")]
|
||||
public virtual ICollection<InvoiceItem> InvoiceInvoiceItem { get; set; }
|
||||
}
|
||||
}
|
||||
80
EveryThing/Models/Invoice/InvoiceItem.cs
Normal file
80
EveryThing/Models/Invoice/InvoiceItem.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using static EveryThing.Models.Invoice.Invoice;
|
||||
|
||||
namespace EveryThing.Models.Invoice
|
||||
{
|
||||
public class InvoiceItem
|
||||
{
|
||||
public enum InvoiceItemState
|
||||
{
|
||||
[Display(Name = "Novo")]
|
||||
New = 0,
|
||||
[Display(Name = "Potrjeno")]
|
||||
Confirmed = 10,
|
||||
[Display(Name = "Zaprto")]
|
||||
Closed = 50
|
||||
}
|
||||
|
||||
[Key]
|
||||
public int IdInvoiceItem { get; set; }
|
||||
|
||||
[Required]
|
||||
[ForeignKey("Invoice")]
|
||||
public int IdInvoiceFk { get; set; }
|
||||
|
||||
[ForeignKey("ProjectPartItem")]
|
||||
public int? IdProjectPartItem { get; set; }
|
||||
|
||||
[ForeignKey("Item")]
|
||||
[Display(Name = "Artikel")]
|
||||
public int? IdItemFk { get; set; }
|
||||
|
||||
[ForeignKey("InvoiceItemJoin")]
|
||||
[Display(Name = "Pozicija")]
|
||||
public int? IdInvoiceItemJoinFk { get; set; }
|
||||
|
||||
[Display(Name = "Opis pozicije")]
|
||||
public string ItemDescription { get; set; }
|
||||
|
||||
[Display(Name = "Opomba")]
|
||||
public string Note { get; set; }
|
||||
|
||||
[Display(Name = "Količina")]
|
||||
[DisplayFormat(DataFormatString = "{0:#,###,##0.00}", ApplyFormatInEditMode = true)]
|
||||
public double Quantity { get; set; }
|
||||
|
||||
[Display(Name = "Cena")]
|
||||
[DisplayFormat(DataFormatString = "{0:#,###,##0.00}", ApplyFormatInEditMode = true)]
|
||||
public double Price { get; set; }
|
||||
|
||||
[Display(Name = "Rabat")]
|
||||
[DisplayFormat(DataFormatString = "{0:#,###,##0.00}", ApplyFormatInEditMode = true)]
|
||||
public double Discount { get; set; }
|
||||
|
||||
[Display(Name = "DDV")]
|
||||
public double Tax { get; set; }
|
||||
|
||||
[Required]
|
||||
[Display(Name = "Status")]
|
||||
public InvoiceItemState State { get; set; } = InvoiceItemState.New;
|
||||
|
||||
[NotMapped]
|
||||
[Display(Name = "Skupaj")]
|
||||
[DisplayFormat(DataFormatString = "{0:#,###,##0.00}", ApplyFormatInEditMode = true)]
|
||||
public double TotalValue => Math.Round((Price * (100 - Discount) / 100) * Quantity, 2);
|
||||
|
||||
// ForeignKey
|
||||
public Invoice Invoice { get; set; }
|
||||
|
||||
public Project.ProjectPartItem ProjectPartItem { get; set; }
|
||||
|
||||
public CodeTable.CodeTableItem Item { get; set; }
|
||||
/// <summary>
|
||||
/// Povezana pozicija fakture, npr ko se iz dob naredi racun
|
||||
/// </summary>
|
||||
public InvoiceItem InvoiceItemJoin { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user