示例#1
0
        public void Execute(Document document)
        {
            if (document.IsBeforeSystemStart)
            {
                return;
            }

            if (document.Source != null &&
                (document.Source.Attribute("type").Value == "order" || document.CheckSourceType(SourceType.SalesOrderRealization)))
            {
                DocumentMapper     mapper = DependencyContainerManager.Container.Get <DocumentMapper>();
                CommercialDocument order  = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, new Guid(document.Source.Attribute("commercialDocumentId").Value));

                List <WarehouseDocument> warehouses = new List <WarehouseDocument>();
                warehouses.Add((WarehouseDocument)document);

                CommercialWarehouseDocumentFactory.RelateWarehousesLinesToOrderLines(warehouses, order, document.Source, true, false);

                /*if (SalesOrderFactory.TryCloseSalesOrder(order))
                 *  document.AddRelatedObject(order);*/
            }
            else if (document.Source != null && document.Source.Attribute("type").Value == "multipleReservations")
            {
                DocumentMapper            mapper       = DependencyContainerManager.Container.Get <DocumentMapper>();
                List <CommercialDocument> reservations = new List <CommercialDocument>();

                foreach (var orderXml in document.Source.Elements())
                {
                    CommercialDocument order = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, new Guid(orderXml.Value));
                    reservations.Add(order);
                }

                List <WarehouseDocument> warehouses = new List <WarehouseDocument>();
                warehouses.Add((WarehouseDocument)document);

                CommercialWarehouseDocumentFactory.RelateWarehousesLinesToMultipleOrdersLines(warehouses, reservations, true, false);
            }
        }
示例#2
0
        public void Execute(Document document)
        {
            if (document.IsBeforeSystemStart)
            {
                return;
            }

            CommercialDocument commercialDocument = document as CommercialDocument;

            #region Outcome From Sales

            if (this.method == OutcomeFromSalesMethod)
            {
                //Pobranie konfiguracji dla typu dokumentu
                XElement configurationSettings = commercialDocument.DocumentType.Options;
                String   templateName;
                try
                {
                    templateName = (string)configurationSettings.Descendants("generateDocument").Attributes("templateName").Single();
                }
                catch (Exception)
                {
                    //RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:4");
                    templateName = "externalOutcome";
                }

                ICollection <WarehouseDocument> warehouses = CommercialWarehouseDocumentFactory.Generate(commercialDocument, templateName, true, false);

                if (warehouses.Count > 0)
                {
                    CommercialWarehouseDocumentFactory.RelateCommercialLinesToWarehousesLines(commercialDocument, warehouses, false, false, true, false);

                    XElement source = document.Source;

                    if (source != null && (source.Attribute("type").Value == "order" || source.Attribute("type").Value == SourceType.SalesOrderRealization))
                    {
                        DocumentMapper     mapper = DependencyContainerManager.Container.Get <DocumentMapper>();
                        CommercialDocument order  = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, new Guid(source.Attribute("commercialDocumentId").Value));

                        CommercialWarehouseDocumentFactory.RelateWarehousesLinesToOrderLines(warehouses, order, commercialDocument.Source, true, false);

                        /*if (SalesOrderFactory.TryCloseSalesOrder(order))
                         *      commercialDocument.AddRelatedObject(order);*/
                    }
                    else if (source != null && source.Attribute("type").Value == "multipleReservations")
                    {
                        DocumentMapper            mapper       = DependencyContainerManager.Container.Get <DocumentMapper>();
                        List <CommercialDocument> reservations = new List <CommercialDocument>();

                        foreach (var orderXml in source.Elements().Where(e => e.Name != "extraParams"))
                        {
                            CommercialDocument order = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, new Guid(orderXml.Value));
                            reservations.Add(order);
                        }

                        CommercialWarehouseDocumentFactory.RelateWarehousesLinesToMultipleOrdersLines(warehouses, reservations, true, false);
                    }
                }
            }

            #endregion

            #region Income From Purchase

            else if (this.method == IncomeFromPurchaseMethod)
            {
                ICollection <WarehouseDocument> warehouses = CommercialWarehouseDocumentFactory.Generate(commercialDocument, "externalIncome", true, false);

                if (warehouses.Count > 0)
                {
                    CommercialWarehouseDocumentFactory.RelateCommercialLinesToWarehousesLines(commercialDocument, warehouses, true, false, true, false);

                    XElement source = document.Source;

                    if (source != null && source.Attribute("type").Value == "order")
                    {
                        DocumentMapper     mapper = DependencyContainerManager.Container.Get <DocumentMapper>();
                        CommercialDocument order  = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, new Guid(source.Attribute("commercialDocumentId").Value));

                        CommercialWarehouseDocumentFactory.RelateWarehousesLinesToOrderLines(warehouses, order, commercialDocument.Source, true, false);
                    }
                }
            }

            #endregion

            else if (this.method == FinancialFromCommercialMethod)
            {
                //Warunek na istnienie jakiego kolwiek settlementu, bez tego nie chciał się dogenerować dokument finansowy
                //Błąd mówił o niejednoznacznych relacjach uniemożliwiających zaktualizowanie dokumentu finansowego
                bool cos = commercialDocument.Payments.Any(p => p.Settlements.Children.Count > 0);
                if (document.IsNew || !cos)
                {
                    FinancialDocumentFactory.GenerateFinancialDocumentToCommercialDocument(commercialDocument);
                }
                else
                {
                    FinancialDocumentFactory.UpdateFinancialDocumentsInCommercialDocument(commercialDocument);
                }
            }
        }