Beispiel #1
0
        /// <summary>
        /// Validates the <see cref="BusinessObject"/>.
        /// </summary>
        public override void Validate()
        {
            base.Validate();

            Warehouse warehouse = DictionaryMapper.Instance.GetWarehouse(this.WarehouseId);

            if (this.AlternateVersion != null && ((WarehouseDocument)this.AlternateVersion).WarehouseId != this.WarehouseId)
            {
                throw new ClientException(ClientExceptionId.WarehouseChangeError);
            }

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

            if (ConfigurationMapper.Instance.IsWmsEnabled &&
                warehouse.ValuationMethod == ValuationMethod.DeliverySelection)
            {
                //sprawdzamy czy nie ma wiekszej ilosci na shiftach niz na pozycji

                foreach (WarehouseDocumentLine line in this.Lines.Children)
                {
                    decimal relatedQuantity = 0;

                    if (this.ShiftTransaction != null)
                    {
                        relatedQuantity = this.ShiftTransaction.Shifts.Children.Where(sh => sh.RelatedWarehouseDocumentLine == line).Sum(s => s.Quantity);
                    }

                    if (relatedQuantity > Math.Abs(line.Quantity))
                    {
                        ItemMapper mapper   = DependencyContainerManager.Container.Get <ItemMapper>();
                        string     itemName = mapper.GetItemName(line.ItemId);

                        if (this.WarehouseDirection == WarehouseDirection.Income || this.WarehouseDirection == WarehouseDirection.IncomeShift)
                        {
                            throw new ClientException(ClientExceptionId.TotalShiftQuantityError, null, "ordinalNumber:" + line.OrdinalNumber.ToString(CultureInfo.InvariantCulture), "itemName:" + itemName);
                        }
                        else
                        {
                            throw new ClientException(ClientExceptionId.TotalShiftQuantityError2, null, "ordinalNumber:" + line.OrdinalNumber.ToString(CultureInfo.InvariantCulture), "itemName:" + itemName);
                        }
                    }
                }
            }

            if (this.DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy != RelatedLinesChangePolicy.ValueOnly)
            {
                if (this.DisableLinesChange != null && this.DisableLinesChange.Contains(DisableDocumentChangeReason.LINES_RELATED_OUTCOMES) &&
                    (this.Lines.IsAnyChildNew() || this.Lines.IsAnyChildModified() || this.Lines.IsAnyChildDeleted()))
                {
                    throw new ClientException(ClientExceptionId.UnableToEditIncomeWarehouseDocument);
                }

                if (!this.IsNew && this.DisableLinesChange != null && this.DisableLinesChange.Contains(DisableDocumentChangeReason.LINES_RELATED_COMMERCIAL_DOCUMENT) &&
                    (this.Lines.IsAnyChildNew() || this.Lines.IsAnyChildModified() || this.Lines.IsAnyChildDeleted()))
                {
                    throw new ClientException(ClientExceptionId.UnableToEditOutcomeWarehouseDocument2);
                }

                if (this.DisableDocumentChange != null && this.DisableDocumentChange.Contains(DisableDocumentChangeReason.DOCUMENT_RELATED_CORRECTIVE_DOCUMENTS) &&
                    (this.Lines.IsAnyChildNew() || this.Lines.IsAnyChildModified() || this.Lines.IsAnyChildDeleted()))
                {
                    throw new ClientException(ClientExceptionId.UnableToEditDocumentBecauseOfCorrections);
                }
            }

            if (this.WarehouseDirection == WarehouseDirection.OutcomeShift ||
                this.WarehouseDirection == WarehouseDirection.IncomeShift)
            {
                //sprawdzenie czy dokument posiada wymagane atrybuty

                bool hasWarehouseAttribute = false;

                foreach (DocumentAttrValue attr in this.Attributes.Children)
                {
                    if (attr.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId && attr.Value.Value.Length != 0)
                    {
                        hasWarehouseAttribute = true;
                    }
                }

                if (!hasWarehouseAttribute)
                {
                    throw new ClientException(ClientExceptionId.FieldValidationError, null, "fieldName:oppositeWarehouse");
                }
            }

            //Sprawdzenie czy dokument jest wystawiany na magazyn lokalny
            if (!warehouse.IsLocal)
            {
                throw new ClientException(ClientExceptionId.WarehouseNotLocal, null, "warehouse:" + warehouse.Symbol);
            }
        }