Пример #1
0
        public virtual void AddItem(ExpenseItem expenseFromItem, int count)
        {
            if(Items.Any (p => DomainHelper.EqualDomainObjects (p.IssuedOn, expenseFromItem)))
            {
                logger.Warn ("Номенклатура из этой выдачи уже добавлена. Пропускаем...");
                return;
            }

            var newItem = new WriteoffItem () {
                Amount = count,
                Nomenclature = expenseFromItem.Nomenclature,
                IssuedOn = expenseFromItem,
            };

            ObservableItems.Add (newItem);
        }
Пример #2
0
        public virtual void AddItem(ExpenseItem expenseFromItem, int count)
        {
            if(Items.Any (p => DomainHelper.EqualDomainObjects (p.IssuedOn, expenseFromItem)))
            {
                logger.Warn ("Номенклатура из этой выдачи уже добавлена. Пропускаем...");
                return;
            }
            decimal life = expenseFromItem.IncomeOn.LifePercent;
            decimal cost = expenseFromItem.IncomeOn.Cost;
            if(expenseFromItem.AutoWriteoffDate.HasValue)
            {
                double multiplier = (expenseFromItem.AutoWriteoffDate.Value - DateTime.Today).TotalDays / (expenseFromItem.AutoWriteoffDate.Value - expenseFromItem.ExpenseDoc.Date).TotalDays;
                life = (life * (decimal)multiplier);
                cost = (cost * (decimal)multiplier);
            }

            var newItem = new IncomeItem () {
                Amount = count,
                Nomenclature = expenseFromItem.Nomenclature,
                IssuedOn = expenseFromItem,
                Cost = cost,
                LifePercent = life
            };

            ObservableItems.Add (newItem);
        }
Пример #3
0
        public virtual void AddItem(IncomeItem fromIncomeItem, int amount)
        {
            if(Items.Any (p => QSOrmProject.DomainHelper.EqualDomainObjects (p.IncomeOn, fromIncomeItem)))
            {
                logger.Warn ("Номенклатура из этого поступления уже добавлена. Пропускаем...");
                return;
            }
            var newItem = new ExpenseItem () {
                ExpenseDoc = this,
                Amount = amount,
                Nomenclature = fromIncomeItem.Nomenclature,
                IncomeOn = fromIncomeItem
            };

            ObservableItems.Add (newItem);
        }
Пример #4
0
 public virtual void RemoveItem(ExpenseItem item)
 {
     ObservableItems.Remove (item);
 }
Пример #5
0
        public virtual void UpdateNextIssue(IUnitOfWork uow, ExpenseItem[] resaveItems)
        {
            ExpenseItem expenseItemAlias = null;
            Nomenclature nomenclatureAlias = null;

            var expenseItems = uow.Session.QueryOver<ExpenseItem> (() => expenseItemAlias)
                .JoinQueryOver (ei => ei.ExpenseDoc)
                .Where (e => e.EmployeeCard == EmployeeCard)
                .JoinAlias (() => expenseItemAlias.Nomenclature, () => nomenclatureAlias)
                .Where (() => nomenclatureAlias.Type.Id == Item.Id)
                .OrderBy (e => e.Date).Asc
                .List ();

            var lastExpire = new DateTime();

            foreach(var expenseItem in expenseItems)
            {
                bool noChange = expenseItem.AutoWriteoffDate.HasValue && expenseItem.AutoWriteoffDate.Value < DateTime.Today && !resaveItems.Contains (expenseItem);

                var returned = uow.Session.QueryOver<IncomeItem> ()
                    .Where (i => i.IssuedOn == expenseItem).List ();
                var writeoff = uow.Session.QueryOver<WriteoffItem> ()
                    .Where (w => w.IssuedOn == expenseItem).List ();

                int realAmount = expenseItem.Amount - returned.Sum (r => r.Amount) - writeoff.Sum (w => w.Amount);

                DateTime virtualIssue = lastExpire > expenseItem.ExpenseDoc.Date ? lastExpire : expenseItem.ExpenseDoc.Date;

                DateTime newExpireDate = ActiveNormItem.CalculateExpireDate (virtualIssue, realAmount);

                if (newExpireDate > DateTime.Today)
                    noChange = false;

                lastExpire = newExpireDate;
                if(!noChange && expenseItem.AutoWriteoffDate != (DateTime?)newExpireDate)
                {
                    expenseItem.AutoWriteoffDate = newExpireDate;
                    uow.Save (expenseItem);
                }
            }
            if(lastExpire != default(DateTime) && NextIssue != lastExpire)
            {
                NextIssue = lastExpire;
                uow.Save (this);
            }
        }