using Bp.Sync.Domain.Elastics.BaseEntities;
using System;
using System.ComponentModel.DataAnnotations;

namespace Bp.Sync.Domain.Elastics.FcBusinesses
{
    public class OutboundStatisticElastic : ElasticBaseEntityWithKey<long>
    {
        public long UUID { get; set; }
        public string InventoryCode { get; set; }
        public long ProductOutboundId { get; set; }
        public long ProductStorageId { get; set; }
        public long ProductId { get; set; }
        public long BillId { get; set; }
        public long ShipmentId { get; set; }
        public long PositionId { get; set; }
        public int BranchId { get; set; }
        public decimal OutboundBaseUnitQuantity { get; set; }
        public decimal OutboundQuantity { get; set; }
        public int OutboundUnitId { get; set; }
        public decimal OutboundCost { get; set; }
        public decimal OutboundBaseUnitCost { get; set; }
        public decimal OutboundTotalCost => OutboundQuantity * OutboundCost;
        public decimal OutboundPrice { get; set; }

        public decimal OutboundBaseUnitPrice { get; set; }

        public decimal OutboundTotalPrice
        {
            get
            {
                var a = OutboundPrice * OutboundQuantity;
                if (OutboundDiscount > 0) a *= 1 - (decimal)OutboundDiscount / 100m;
                if (OutboundTax > 0) a *= 1 + (decimal)OutboundTax / 100m;
                return a;
            }
        }

        //Lợi nhuận dự kiến
        public decimal OutboundRevenue => OutboundTotalPrice - OutboundTotalCost;

        public float OutboundDiscount { get; set; }
        public float OutboundTax { get; set; }

        //them vao bao cao
        public Entities.FcBusinesses.Bills.OutboundBillStatus? BillStatus { get; set; }

        public Entities.FcBusinesses.Bills.BillType? BillType { get; set; }
        public DateTimeOffset? BillCreatedTime { get; set; }
        public DateTimeOffset? BillCompletedDate { get; set; }
        public bool? BillIsDeleted { get; set; }
        public int? BillOriginBranchId { get; set; }
        public int? BillDestinationBranchId { get; set; }
        public int? BillPartnerId { get; set; }
    }
}