using EgwCoreLib.Lux.Data.DbModel.Items;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwCoreLib.Lux.Data.DbModel.Sales
{
//
// This is here so CodeMaid doesn't reorganize this document
//
[Table("sales_order_row")]
public class OrderRowModel
{
///
/// ID del record
///
[Key]
public int OrderRowID { get; set; }
///
/// Riferimento Ordine
///
public int OrderID { get; set; }
///
/// Riga Ordine
///
public int RowNum { get; set; } = 0;
///
/// Codice calcolato Ordine ANNO.NUMERO
/// inizia per PO = PurchaseOrder
///
[NotMapped]
public string OrderRowCode
{
get => $"PO{OrderRowID:000000}.{RowNum:000}";
}
///
/// ID dell'articolo di vendita Orderto
///
public int SellingItemID { get; set; }
///
/// Costo dei componeti BOM (RockBottom)
///
public double BomCost { get; set; } = 0;
///
/// Margine percentuale standard
///
public double Qty { get; set; } = 1;
///
/// Prezzo dei componeti BOM (scontabile)
///
public double BomPrice { get; set; } = 0;
///
/// Costo produzione Fase/Step (RockBottom)
///
public double StepCost { get; set; } = 0;
///
/// Prezzo produzione Fase/Step (scontabile)
///
public double StepPrice { get; set; } = 0;
///
/// Costo Totale Risorsa (BOM + Fase)
///
[NotMapped]
public double UnitCost
{
get => BomCost + StepCost;
}
///
/// Costo Totale Risorsa (BOM + Fase)
///
[NotMapped]
public double UnitPrice
{
get => BomPrice + StepPrice;
}
///
/// Sconto massimo applicabile
///
[NotMapped]
public double MaxDiscount
{
get => (UnitCost > 0 && UnitPrice > UnitCost) ? (UnitPrice - UnitCost) / UnitPrice : 0;
}
///
/// Costo Totale risorsa
///
[NotMapped]
public double TotalCost
{
get => UnitCost * Qty;
}
///
/// Costo Totale risorsa
///
[NotMapped]
public double TotalPrice
{
get => UnitPrice * Qty;
}
///
/// Valore serializzato della composizione articolo (in formato JWD x finestra)
///
public string SerStruct { get; set; } = "";
///
/// Elenco StepDTO (Fasi) per la stima tempi / costi
/// potrebbe contenere anche altre info accessorie x definire dati logistico/gestionali
///
public string ItemSteps { get; set; } = "";
///
/// Note libere
///
public string Note { get; set; } = "";
#if false
///
/// Stack degli ultimi item serializzati per Uno/Redo actions
///
[NotMapped]
public List UndoRedoSerStruct { get; set; } = new List();
#endif
///
/// DataOra inserimento
///
public DateTime Inserted { get; set; } = DateTime.Now;
///
/// DataOra ultima modifica
///
public DateTime Modified { get; set; } = DateTime.Now;
///
/// Navigazione Order
///
[ForeignKey("OrderID")]
public virtual OrderModel OrderNav { get; set; } = null!;
///
/// Navigazione Item
///
[ForeignKey("SellingItemID")]
public virtual SellingItemModel SellingItemNav { get; set; } = null!;
}
}