Exemplo n.º 1
0
        public static Document DeserializeRelatedDocument(DocumentRelation relation, XElement relatedDocument)
        {
            Document             parent       = (Document)relation.Parent;
            DocumentRelationType relationType = relation.RelationType;

            Document retDocument = null;

            if (relatedDocument == null)
            {
                throw new ClientException(ClientExceptionId.IncompleteRelation);
            }

            switch (relationType)
            {
            case DocumentRelationType.SalesDocumentToSimulatedInvoice:
            case DocumentRelationType.InvoiceToBill:
                retDocument = new CommercialDocument();
                retDocument.Deserialize(relatedDocument);
                break;

            case DocumentRelationType.ServiceToOutcomeShift:
                if (parent.BOType == BusinessObjectType.ServiceDocument)
                {
                    retDocument = new WarehouseDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new ServiceDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.ServiceToInvoice:
                if (parent.BOType == BusinessObjectType.ServiceDocument)
                {
                    retDocument = new CommercialDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new ServiceDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.ServiceToInternalOutcome:
                if (parent.BOType == BusinessObjectType.ServiceDocument)
                {
                    retDocument = new WarehouseDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new ServiceDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.ComplaintToInternalOutcome:
                if (parent.BOType == BusinessObjectType.ComplaintDocument)
                {
                    retDocument = new WarehouseDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new ComplaintDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.InventoryToWarehouse:
                if (parent.BOType == BusinessObjectType.InventoryDocument)
                {
                    retDocument = new WarehouseDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new InventoryDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.SalesOrderToInvoice:
            case DocumentRelationType.SalesOrderToCorrectiveCommercialDocument:
            case DocumentRelationType.SalesOrderToSimulatedInvoice:
                retDocument = new CommercialDocument();
                retDocument.Deserialize(relatedDocument);
                break;

            case DocumentRelationType.SalesOrderToWarehouseDocument:
                if (parent.BOType == BusinessObjectType.CommercialDocument)
                {
                    retDocument = new WarehouseDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new CommercialDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.SalesOrderToOutcomeFinancialDocument:
                if (parent.BOType == BusinessObjectType.CommercialDocument)
                {
                    retDocument = new FinancialDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new CommercialDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            case DocumentRelationType.ProductionOrderToIncome:
            case DocumentRelationType.ProductionOrderToOutcome:
                if (parent.BOType == BusinessObjectType.CommercialDocument)
                {
                    retDocument = new WarehouseDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                else
                {
                    retDocument = new CommercialDocument();
                    retDocument.Deserialize(relatedDocument);
                }
                break;

            default:
                throw new InvalidOperationException("Unknown DocumentRelationType");
            }

            return(retDocument);
        }