/// <summary>
        /// Creates new <see cref="WarehouseDocumentLine"/> according to the WarehouseDocument's defaults and attaches it to the parent <see cref="WarehouseDocument"/>.
        /// </summary>
        /// <returns>A new <see cref="WarehouseDocumentLine"/>.</returns>
        public override WarehouseDocumentLine CreateNew()
        {
            WarehouseDocument parent = (WarehouseDocument)this.Parent;

            //create new object and attach it to the element
            WarehouseDocumentLine line = new WarehouseDocumentLine(parent);

            WarehouseDirection parentDirection = parent.DocumentType.WarehouseDocumentOptions.WarehouseDirection;

            if (!parent.IsBeforeSystemStart)
            {
                if (parentDirection == WarehouseDirection.Outcome || parentDirection == WarehouseDirection.OutcomeShift)
                {
                    line.Direction = -1;
                }
                else
                {
                    line.Direction = 1;
                }
            }

            if (parentDirection == WarehouseDirection.OutcomeShift || parentDirection == WarehouseDirection.IncomeShift)
            {
                line.IsDistributed = true;
            }

            line.Order = this.Children.Count + 1;

            //add object to the collection
            this.Children.Add(line);

            return(line);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WarehouseDocumentLine"/> class with a specified xml root element.
 /// </summary>
 /// <param name="parent">Parent <see cref="WarehouseDocument"/>.</param>
 public WarehouseDocumentLine(WarehouseDocument parent)
     : base(parent, BusinessObjectType.WarehouseDocumentLine)
 {
     this.IncomeOutcomeRelations        = new IncomeOutcomeRelations(this);
     this.CommercialWarehouseValuations = new CommercialWarehouseValuations(this);
     this.CommercialWarehouseRelations  = new CommercialWarehouseRelations(this);
     this.Attributes = new DocumentLineAttrValues(this);
 }
        /// <summary>
        /// Validates the <see cref="BusinessObject"/>.
        /// </summary>
        public override void Validate()
        {
            base.Validate();

            RelatedLinesChangePolicy relatedLinesChangePolicy = RelatedLinesChangePolicy.Unknown;
            WarehouseDocument        warehouseParent          = ((WarehouseDocument)this.Parent);

            if (warehouseParent != null)
            {
                relatedLinesChangePolicy = warehouseParent.DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy;
            }

            bool skipQuantityValidation = ((WarehouseDocument)this.Parent).SkipQuantityValidation;

            if (!skipQuantityValidation && relatedLinesChangePolicy != RelatedLinesChangePolicy.ValueOnly)
            {
                if (this.Quantity <= 0)
                {
                    throw new ClientException(ClientExceptionId.QuantityBelowOrEqualZero, null, "itemName:" + this.ItemName);
                }

                decimal quantityOnOrderRelation = this.CommercialWarehouseRelations.Children.Where(r => r.IsOrderRelation).Sum(rr => rr.Quantity);

                if (quantityOnOrderRelation > this.Quantity)
                {
                    throw new ClientException(ClientExceptionId.UnableToEditOutcomeWarehouseDocument3);
                }
            }

            WarehouseDirection direction = ((WarehouseDocument)this.Parent).WarehouseDirection;

            if (relatedLinesChangePolicy != RelatedLinesChangePolicy.ValueOnly && direction == WarehouseDirection.Income && this.Price < 0)
            {
                throw new ClientException(ClientExceptionId.LinePriceBelowOrEqualZero);
            }

            if (this.IncomeOutcomeRelations != null)
            {
                this.IncomeOutcomeRelations.Validate();
            }

            if (this.CommercialWarehouseValuations != null)
            {
                this.CommercialWarehouseValuations.Validate();
            }

            if (this.CommercialWarehouseRelations != null)
            {
                this.CommercialWarehouseRelations.Validate();
            }

            if (this.Attributes != null)
            {
                this.Attributes.Validate();
            }
        }
        /// <summary>
        /// Validates the collection.
        /// </summary>
        public override void Validate()
        {
            if (this.Children.Count == 0)
            {
                throw new ClientException(ClientExceptionId.NoLines);
            }

            WarehouseDocument parent = (WarehouseDocument)this.Parent;

            DependencyContainerManager.Container.Get <DocumentMapper>().AddItemsToItemTypesCache(parent);

            IDictionary <Guid, Guid> cache = SessionManager.VolatileElements.ItemTypesCache;

            foreach (WarehouseDocumentLine line in this.Children)
            {
                Guid     itemTypeId = cache[line.ItemId];
                ItemType itemType   = DictionaryMapper.Instance.GetItemType(itemTypeId);

                if (!itemType.IsWarehouseStorable)
                {
                    throw new ClientException(ClientExceptionId.NonStorableItemOnWarehouseDocument);
                }
            }

            if (parent.DocumentType.WarehouseDocumentOptions.WarehouseDirection == WarehouseDirection.Income)
            {
                //validation for incomes

                foreach (WarehouseDocumentLine line in this.Children)
                {
                    if (line.IncomeDate == null)
                    {
                        throw new ClientException(ClientExceptionId.FieldValidationError, null, "fieldName:incomeDate");
                    }
                }
            }
            else if (parent.DocumentType.WarehouseDocumentOptions.WarehouseDirection == WarehouseDirection.Outcome)
            {
                foreach (WarehouseDocumentLine line in this.Children)
                {
                    if (line.OutcomeDate == null)
                    {
                        throw new ClientException(ClientExceptionId.FieldValidationError, null, "fieldName:outcomeDate");
                    }
                }
            }

            base.Validate();
        }
Exemple #5
0
        /// <summary>
        /// Sets the alternate version of the <see cref="BusinessObject"/>.
        /// </summary>
        /// <param name="alternate"><see cref="BusinessObject"/> that is to be considered as the alternate one.</param>
        public override void SetAlternateVersion(IBusinessObject alternate)
        {
            base.SetAlternateVersion(alternate);

            WarehouseDocument alternateDocument = (WarehouseDocument)alternate;

            if (this.Lines != null)
            {
                this.Lines.SetAlternateVersion(alternateDocument.Lines);
            }

            if (this.ShiftTransaction != null)
            {
                this.ShiftTransaction.SetAlternateVersion(alternateDocument.ShiftTransaction);
            }
        }
        /// <summary>
        /// Checks if the object has changed against <see cref="BusinessObject.AlternateVersion"/> and updates its own <see cref="BusinessObject.Status"/>.
        /// </summary>
        /// <param name="isNew">Value indicating whether the <see cref="BusinessObject"/> should be considered as the new one or the old one.</param>
        public override void UpdateStatus(bool isNew)
        {
            base.UpdateStatus(isNew);

            WarehouseDocument parent = (WarehouseDocument)this.Parent;

            WarehouseDocumentLine alternateLine = this.AlternateVersion as WarehouseDocumentLine;

            if (this.IncomeOutcomeRelations != null)
            {
                if (this.Status == BusinessObjectStatus.Deleted)
                {
                    this.IncomeOutcomeRelations.SetChildrenStatus(BusinessObjectStatus.Deleted);

                    //wywalamy wszystkie shifty ktore byly powiazane z ta pozycja bo zostana one usuniete w
                    //procedurze p_deleteWarehouseDocumentLine

                    ShiftTransaction st = ((WarehouseDocument)this.Parent).ShiftTransaction;

                    List <Shift> shiftsToDelete = new List <Shift>();

                    if (st != null)
                    {
                        foreach (var shift in st.Shifts.Children.Where(s => s.RelatedWarehouseDocumentLine == this))
                        {
                            //shift.Status = BusinessObjectStatus.Deleted;
                            shiftsToDelete.Add(shift);
                        }

                        foreach (var shift in shiftsToDelete)
                        {
                            st.Shifts.Remove(shift);
                        }

                        shiftsToDelete.Clear();
                    }

                    if (alternateLine != null)
                    {
                        WarehouseDocument alternateDocument = (WarehouseDocument)alternateLine.Parent;

                        if (alternateDocument.ShiftTransaction != null)
                        {
                            foreach (var shift in alternateDocument.ShiftTransaction.Shifts.Children.Where(ss => ss.RelatedWarehouseDocumentLine == alternateLine))
                            {
                                shiftsToDelete.Add(shift);
                            }

                            foreach (var shift in shiftsToDelete)
                            {
                                st.Shifts.Remove(shift);
                            }

                            shiftsToDelete.Clear();
                        }
                    }

                    //wywalamy wszystkie commercialWarehouseValuation
                    this.CommercialWarehouseValuations.RemoveAll();
                }
                else if (this.Status == BusinessObjectStatus.Modified &&
                         parent.WarehouseDirection == WarehouseDirection.Outcome &&
                         DictionaryMapper.Instance.GetWarehouse(this.WarehouseId).ValuationMethod == ValuationMethod.Fifo)
                {
                    ((WarehouseDocumentLine)this.AlternateVersion).IncomeOutcomeRelations.SetChildrenStatus(BusinessObjectStatus.Deleted);
                    this.IncomeOutcomeRelations.RemoveAll();
                }
                else if (this.IncomeOutcomeRelations != null)
                {
                    this.IncomeOutcomeRelations.UpdateStatus(isNew);
                }
            }

            if (this.CommercialWarehouseValuations != null)
            {
                this.CommercialWarehouseValuations.UpdateStatus(isNew);
            }

            if (this.CommercialWarehouseRelations != null)
            {
                this.CommercialWarehouseRelations.UpdateStatus(isNew);
            }

            if (this.Attributes != null)
            {
                this.Attributes.UpdateStatus(isNew);
            }

            //If RelatedLinesChangedPolicy is valueOnly, quantity and item cannot be changed
            if (parent.DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy == RelatedLinesChangePolicy.ValueOnly)
            {
                bool throwException = false;

                if (alternateLine == null && !parent.IsNew && this.IsNew)
                {
                    throwException = true;
                }

                if (alternateLine != null &&
                    (this.Quantity != alternateLine.Quantity ||
                     this.ItemId != alternateLine.ItemId ||
                     this.ItemName != alternateLine.ItemName ||
                     this.ItemCode != alternateLine.ItemCode))
                {
                    throwException = true;
                }

                if (throwException)
                {
                    throw new ClientException(ClientExceptionId.OnlyLineValuesCanBeEdited);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WarehouseDocumentLines"/> class with a specified <see cref="WarehouseDocument"/> to attach to.
 /// </summary>
 /// <param name="parent"><see cref="WarehouseDocument"/> to attach to.</param>
 public WarehouseDocumentLines(WarehouseDocument parent)
     : base(parent, "line")
 {
 }