示例#1
0
        public static void CreateInventorySheetToInventoryDocument(InventorySheet destination, XElement source)
        {
            Guid inventoryDocumentId = new Guid(source.Element("inventoryDocumentId").Value);

            destination.InventoryDocumentHeaderId = inventoryDocumentId;

            using (DocumentCoordinator c = new DocumentCoordinator(false, false))
            {
                InventoryDocument inventoryDocument = (InventoryDocument)c.LoadBusinessObject(BusinessObjectType.InventoryDocument, inventoryDocumentId);
                destination.Tag           = inventoryDocument.Version.ToUpperString();
                destination.OrdinalNumber = inventoryDocument.Sheets.Children.Count + 1;
                destination.InventoryDocumentFullNumber = inventoryDocument.Number.FullNumber;
                destination.WarehouseId = inventoryDocument.WarehouseId;
            }
        }
示例#2
0
        /// <summary>
        /// Saves the business object.
        /// </summary>
        /// <param name="document"><see cref="CommercialDocument"/> to save.</param>
        /// <returns>Xml containing result of oper</returns>
        public XDocument SaveBusinessObject(InventorySheet sheet)
        {
            DictionaryMapper.Instance.CheckForChanges();

            //load alternate version
            if (!sheet.IsNew)
            {
                IBusinessObject alternateBusinessObject = this.mapper.LoadBusinessObject(sheet.BOType, sheet.Id.Value);
                sheet.SetAlternateVersion(alternateBusinessObject);
            }

            //update status
            sheet.UpdateStatus(true);

            if (sheet.AlternateVersion != null)
            {
                sheet.AlternateVersion.UpdateStatus(false);
            }

            //validate
            sheet.Validate();

            if (sheet.DocumentStatus == DocumentStatus.Canceled)
            {
                foreach (var line in sheet.Lines) //jak anulujemy arkusz to zerujemy direction na pozycjach
                {
                    line.Direction = 0;
                }
            }

            //update status
            sheet.UpdateStatus(true);

            if (sheet.AlternateVersion != null)
            {
                sheet.AlternateVersion.UpdateStatus(false);
            }

            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();
                this.mapper.CheckBusinessObjectVersion(sheet);

                this.ProcessInventoryHeaderOperations(sheet);

                //Make operations list
                XDocument operations = XDocument.Parse("<root/>");

                sheet.SaveChanges(operations);

                if (sheet.AlternateVersion != null)
                {
                    sheet.AlternateVersion.SaveChanges(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                    //this.mapper.CreateCommunicationXml(sheet);
                    //this.mapper.UpdateDictionaryIndex(sheet);
                }

                if (!sheet.SkipItemsUnblock &&                                                                                                                         //jezeli nie mamy pominac odblokowywania bo np. dokument inwentaryzacji to zrobi za nas
                    sheet.Lines.Children.Where(l => l.Direction == 0 && (l.IsNew || ((InventorySheetLine)l.AlternateVersion).Direction > 0)).FirstOrDefault() != null) //jezeli jakas linia zostala anulowana
                {
                    itemMapper.UnblockItems();
                }

                Coordinator.LogSaveBusinessObjectOperation();

                operations = XDocument.Parse("<root/>");

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                }

                XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", sheet.Id.ToUpperString()));

                if (this.coordinator.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }

                return(returnXml);
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:76");
                Coordinator.ProcessSqlException(sqle, sheet.BOType, this.coordinator.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:77");
                if (this.coordinator.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }
示例#3
0
        private void ProcessInventoryHeaderOperations(InventorySheet sheet)
        {
            if (sheet.Status == BusinessObjectStatus.New) //sprawdzamy czy wersja sie zgadza
            {
                if (String.IsNullOrEmpty(sheet.Tag))
                {
                    throw new ClientException(ClientExceptionId.FieldValidationError, null, "fieldName:tag");
                }

                Guid previousVersion = new Guid(sheet.Tag);

                try
                {
                    this.mapper.CheckInventoryDocumentVersion(previousVersion);
                }
                catch (SqlException)
                {
                    RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:75");
                    throw new ClientException(ClientExceptionId.VersionMismatch, null, "objType:InventoryDocument");
                }
            }

            //InventorySheet alternateSheet = sheet.AlternateVersion as InventorySheet;

            //przeiterowanie po liniach nowych i zablokowanie ich i wpisanie stanu aktualnego
            //procka musi zwracac blad jezeli chceby blokowac towar ktory jest juz zablokowany i zwracac ich stan
            if (sheet.DocumentStatus == DocumentStatus.Saved)
            {
                XElement blockXml        = new XElement("root");
                DateTime currentDateTime = SessionManager.VolatileElements.CurrentDateTime;

                foreach (var line in sheet.Lines)
                {
                    if (line.IsNew)
                    {
                        line.SystemDate = currentDateTime;
                        blockXml.Add(new XElement("entry", new XAttribute("itemId", line.ItemId.ToUpperString()), new XAttribute("warehouseId", sheet.WarehouseId.ToUpperString())));
                    }
                }

                blockXml = this.itemMapper.BlockItems(blockXml);

                //przetwarzamy wynik
                if (blockXml != null)
                {
                    foreach (var entry in blockXml.Elements())
                    {
                        Guid itemId = new Guid(entry.Attribute("itemId").Value);
                        var  line   = sheet.Lines.Children.Where(l => l.ItemId == itemId && l.Direction > 0).First();

                        if (entry.Attribute("alreadyBlocked") != null && entry.Attribute("alreadyBlocked").Value == "1")
                        {
                            string whSymbol = DictionaryMapper.Instance.GetWarehouse(new Guid(entry.Attribute("warehouseId").Value)).Symbol;
                            throw new ClientException(ClientExceptionId.ItemBlockError, null, "itemName:" + line.ItemName, "whSymbol:" + whSymbol);
                        }
                        else
                        {
                            decimal quantity = Convert.ToDecimal(entry.Attribute("quantity").Value, CultureInfo.InvariantCulture);
                            line.SystemQuantity = quantity;
                        }
                    }
                }
            }
        }
示例#4
0
        private void ExecuteCustomLogic(InventoryDocument document)
        {
            InventoryDocument alternateDocument = document.AlternateVersion as InventoryDocument;

            if (alternateDocument != null)
            {
                if (alternateDocument.DocumentStatus == DocumentStatus.Saved &&
                    (document.DocumentStatus == DocumentStatus.Committed || document.DocumentStatus == DocumentStatus.Canceled))
                {
                    //wczytujemy wszystkie arkusze
                    foreach (InventorySheet s in document.Sheets)
                    {
                        InventorySheet sheet = (InventorySheet)this.mapper.LoadBusinessObject(BusinessObjectType.InventorySheet, s.Id.Value);

                        if (sheet.DocumentStatus == DocumentStatus.Saved)
                        {
                            sheet.DocumentStatus   = document.DocumentStatus;
                            sheet.SkipItemsUnblock = true;
                            document.SheetsToSave.Add(sheet);
                        }
                    }

                    document.UnblockItems = true;

                    if (document.DocumentStatus == DocumentStatus.Committed)
                    {
                        var whDocs = InventoryDocumentFactory.GenerateDifferentialDocuments(document, document.SheetsToSave);

                        foreach (var whDoc in whDocs)
                        {
                            //Wycena pozycji przychodowych na podstawie ceny ostatniego zakupu
                            //Zrobiłem tak bo nie znam kernela a nie mamy obecnie kernelowca
                            if (whDoc.WarehouseDirection == WarehouseDirection.Income)
                            {
                                XDocument par = new XDocument(new XElement("root",
                                                                           new XElement("warehouseId", whDoc.WarehouseId.ToString()),
                                                                           whDoc.Lines.Serialize()));
                                XDocument priceList      = null;
                                decimal   headerSumation = 0;
                                priceList = new XDocument(this.mapper.ExecuteCustomProcedure("document.p_getWarehouseStock", true, par, true, 120, "xml"));
                                foreach (var item in whDoc.Lines)
                                {
                                    decimal lastPrice;


                                    lastPrice = decimal.Parse(
                                        (from i in priceList.Descendants("line")
                                         where i.Element("itemId").Value.ToLower() == item.ItemId.ToString().ToLower()
                                         select i.Element("lastPurchaseNetPrice").Value).FirstOrDefault().Replace(".", ",")
                                        );

                                    item.Value     = lastPrice * item.Quantity;
                                    item.Price     = lastPrice;
                                    headerSumation = headerSumation + (lastPrice * item.Quantity);
                                }
                                whDoc.Value = headerSumation;
                            }

                            document.AddRelatedObject(whDoc);

                            DocumentRelation relation = document.Relations.CreateNew();
                            relation.RelationType    = DocumentRelationType.InventoryToWarehouse;
                            relation.RelatedDocument = whDoc;

                            relation = whDoc.Relations.CreateNew();
                            relation.RelationType    = DocumentRelationType.InventoryToWarehouse;
                            relation.RelatedDocument = document;
                            relation.DontSave        = true;
                        }
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Saves the business object.
        /// </summary>
        /// <param name="document"><see cref="CommercialDocument"/> to save.</param>
        /// <returns>Xml containing result of oper</returns>
        public XDocument SaveBusinessObject(InventoryDocument document)
        {
            DictionaryMapper.Instance.CheckForChanges();

            //load alternate version
            if (!document.IsNew)
            {
                IBusinessObject alternateBusinessObject = this.mapper.LoadBusinessObject(document.BOType, document.Id.Value);
                document.SetAlternateVersion(alternateBusinessObject);
            }

            foreach (var sheet in document.Sheets)
            {
                sheet.SkipLinesSave = true;

                InventorySheet alternateSheet = sheet.AlternateVersion as InventorySheet;

                if (alternateSheet != null && alternateSheet.DocumentStatus != sheet.DocumentStatus && sheet.DocumentStatus == DocumentStatus.Canceled)
                {
                    //jezeli anulowalismy arkusz z poziomu inwentaryzacji to nalezy caly arkusz wczytac, zmienic jego status i dodac do zapisu zeby
                    //wykonala sie tez inna jego logika zwiazana ze zmiana statusu
                    InventorySheet sh = (InventorySheet)this.mapper.LoadBusinessObject(BusinessObjectType.InventorySheet, sheet.Id.Value);
                    sh.DocumentStatus = DocumentStatus.Canceled;
                    document.AddRelatedObject(sh);
                }
            }

            //update status
            document.UpdateStatus(true);

            if (document.AlternateVersion != null)
            {
                document.AlternateVersion.UpdateStatus(false);
            }

            document.Validate();

            this.ExecuteCustomLogic(document);
            this.ExecuteDocumentOptions(document);

            //validate
            document.Validate();

            //update status
            document.UpdateStatus(true);

            if (document.AlternateVersion != null)
            {
                document.AlternateVersion.UpdateStatus(false);
            }

            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();
                this.mapper.CheckBusinessObjectVersion(document);

                DocumentLogicHelper.AssignNumber(document, this.mapper);

                //Make operations list
                XDocument operations = XDocument.Parse("<root/>");

                document.SaveChanges(operations);

                if (document.AlternateVersion != null)
                {
                    document.AlternateVersion.SaveChanges(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                    if (document.DocumentStatus == DocumentStatus.Committed)
                    {
                        this.mapper.CreateCommunicationXml(document);
                    }
                    this.mapper.UpdateDictionaryIndex(document);
                }

                Coordinator.LogSaveBusinessObjectOperation();

                foreach (var sheet in document.SheetsToSave)
                {
                    using (DocumentCoordinator c = new DocumentCoordinator(false, false))
                    {
                        c.SaveBusinessObject(sheet);
                    }
                }

                if (document.UnblockItems)
                {
                    this.itemMapper.UnblockItems();
                }

                document.SaveRelatedObjects();

                operations = XDocument.Parse("<root/>");

                document.SaveRelations(operations);

                if (document.AlternateVersion != null)
                {
                    ((InventoryDocument)document.AlternateVersion).SaveRelations(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                }


                if (operations.Root.HasElements)
                {
                    this.mapper.CreateCommunicationXmlForDocumentRelations(operations); //generowanie paczek dla relacji dokumentow
                }
                XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", document.Id.ToUpperString()));

                //Custom validation
                this.mapper.ExecuteOnCommitValidationCustomProcedure(document);

                if (this.coordinator.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }

                return(returnXml);
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:72");
                Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:73");
                if (this.coordinator.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }