Exemplo n.º 1
0
        protected ProductViewModel(Product product)
        {
            IDs = new List<int>{product.ID};
            SerialNumber = product.SerialNumber;
            ModelName = product.Model.Name;
            CategoryName = product.Model.Category.Name;
            Notes = product.Notes;
            SellingPrice = product.SellingPrice;
            DateSellTo = product.DateSellTo;
            ModelID = product.ModelID;

            Origin = TranType.Zero;
            MoneySpentForProduct = 0;

            var orderedTransactions = product.Transactions.OrderBy(x => x.Date);

            if (orderedTransactions.FirstOrDefault() != null && orderedTransactions.FirstOrDefault().Operator != null) SalesmanBought = new SalesmanViewModel(orderedTransactions.FirstOrDefault().Operator.Salesman);

            foreach (var transaction in orderedTransactions)
            {
                if (transaction.TypeID != (int)TranType.Bought && transaction.TypeID != (int)TranType.Repaired &&
                    transaction.TypeID != (int)TranType.ToPawn && transaction.TypeID != (int)TranType.ToRepair) continue;

                if (transaction.TypeID != (int)TranType.ToRepair && transaction.Price != null) MoneySpentForProduct += transaction.Price.Value;

                if (transaction.TypeID != (int)TranType.Repaired) Origin = (TranType)transaction.TypeID;
            }

            Status = orderedTransactions.LastOrDefault() == null ? TranType.Zero : (TranType) orderedTransactions.LastOrDefault().TypeID;
        }
Exemplo n.º 2
0
        public TransactionViewModel(Transaction transaction)
        {
            ID    = transaction.ID;
            Type  = (TranType)transaction.TypeID;
            Price = transaction.Price;
            Date  = transaction.Date;

            var product = transaction.Product;

            if (product != null)
            {
                ProductID    = product.ID;
                ModelName    = product.Model.Name;
                CategoryName = product.Model.Category.Name;
                SerialNumber = product.SerialNumber;
            }

            if (transaction.Operator != null)
            {
                Salesman = new SalesmanViewModel(transaction.Operator.Salesman);
            }
            if (transaction.Contragent != null)
            {
                ContragentLastName = new ContragentViewModel(transaction.Contragent);
            }
        }
Exemplo n.º 3
0
 public CashTransactionViewModel(Transaction transaction)
 {
     ID = transaction.ID;
     Date = transaction.Date;
     CashTranType = (TranType) transaction.TypeID;
     Salesman = new SalesmanViewModel(transaction.Operator.Salesman);
     if (transaction.Contragent != null) Contragent = new ContragentViewModel(transaction.Contragent);
     if (transaction.Price != null) Price = transaction.Price.Value;
     Notes = transaction.Notes;
 }
Exemplo n.º 4
0
 public CashTransactionViewModel(Transaction transaction)
 {
     ID           = transaction.ID;
     Date         = transaction.Date;
     CashTranType = (TranType)transaction.TypeID;
     Salesman     = new SalesmanViewModel(transaction.Operator.Salesman);
     if (transaction.Contragent != null)
     {
         Contragent = new ContragentViewModel(transaction.Contragent);
     }
     if (transaction.Price != null)
     {
         Price = transaction.Price.Value;
     }
     Notes = transaction.Notes;
 }
Exemplo n.º 5
0
        public SoldProductViewModel(Product product)
            : base(product)
        {
            var ordered = product.Transactions.OrderBy(x => x.Date);

            var transactionSold = ordered.LastOrDefault(x => x.TypeID == (int)TranType.Sold);
            if (transactionSold != null)
            {
                if (transactionSold.Price != null) PriceSold = transactionSold.Price.Value;
                SalesmanSold = new SalesmanViewModel(transactionSold.Operator.Salesman);
                DateSold = transactionSold.Date;
            }

            SalesmanWithProfit = Origin == TranType.Bought ? SalesmanSold : SalesmanBought;

            Profit = PriceSold - MoneySpentForProduct;
            SalesmanProfit = Profit*((decimal) SalesmanWithProfit.ProfitPercentage/(decimal) 100);
        }
Exemplo n.º 6
0
        protected ProductViewModel(Product product)
        {
            IDs = new List <int> {
                product.ID
            };
            SerialNumber = product.SerialNumber;
            ModelName    = product.Model.Name;
            CategoryName = product.Model.Category.Name;
            Notes        = product.Notes;
            SellingPrice = product.SellingPrice;
            DateSellTo   = product.DateSellTo;
            ModelID      = product.ModelID;

            Origin = TranType.Zero;
            MoneySpentForProduct = 0;

            var orderedTransactions = product.Transactions.OrderBy(x => x.Date);

            if (orderedTransactions.FirstOrDefault() != null && orderedTransactions.FirstOrDefault().Operator != null)
            {
                SalesmanBought = new SalesmanViewModel(orderedTransactions.FirstOrDefault().Operator.Salesman);
            }

            foreach (var transaction in orderedTransactions)
            {
                if (transaction.TypeID != (int)TranType.Bought && transaction.TypeID != (int)TranType.Repaired &&
                    transaction.TypeID != (int)TranType.ToPawn && transaction.TypeID != (int)TranType.ToRepair)
                {
                    continue;
                }

                if (transaction.TypeID != (int)TranType.ToRepair && transaction.Price != null)
                {
                    MoneySpentForProduct += transaction.Price.Value;
                }

                if (transaction.TypeID != (int)TranType.Repaired)
                {
                    Origin = (TranType)transaction.TypeID;
                }
            }

            Status = orderedTransactions.LastOrDefault() == null ? TranType.Zero : (TranType)orderedTransactions.LastOrDefault().TypeID;
        }
Exemplo n.º 7
0
        public TransactionViewModel(Transaction transaction)
        {
            ID = transaction.ID;
            Type = (TranType)transaction.TypeID;
            Price = transaction.Price;
            Date = transaction.Date;

            var product = transaction.Product;
            if (product != null)
            {
                ProductID = product.ID;
                ModelName = product.Model.Name;
                CategoryName = product.Model.Category.Name;
                SerialNumber = product.SerialNumber;
            }

            if (transaction.Operator != null) Salesman = new SalesmanViewModel(transaction.Operator.Salesman);
            if (transaction.Contragent != null) ContragentLastName = new ContragentViewModel(transaction.Contragent);
        }
Exemplo n.º 8
0
        public SoldProductViewModel(Product product) : base(product)
        {
            var ordered = product.Transactions.OrderBy(x => x.Date);

            var transactionSold = ordered.LastOrDefault(x => x.TypeID == (int)TranType.Sold);

            if (transactionSold != null)
            {
                if (transactionSold.Price != null)
                {
                    PriceSold = transactionSold.Price.Value;
                }
                SalesmanSold = new SalesmanViewModel(transactionSold.Operator.Salesman);
                DateSold     = transactionSold.Date;
            }

            SalesmanWithProfit = Origin == TranType.Bought ? SalesmanSold : SalesmanBought;

            Profit         = PriceSold - MoneySpentForProduct;
            SalesmanProfit = Profit * ((decimal)SalesmanWithProfit.ProfitPercentage / (decimal)100);
        }