Пример #1
0
        private void ProcessLocalIncomeShift(WarehouseDocument document)
        {
            if (document.Status != BusinessObjectStatus.New && document.Status != BusinessObjectStatus.Modified)
            {
                return;
            }

            if (document.IsLocalShift()) //mamy MMke lokalna
            {
                Guid outcomeShiftId = new Guid(document.Attributes.Children.Where(aa => aa.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId).First().Value.Value);

                using (DocumentCoordinator c = new DocumentCoordinator(false, false))
                {
                    WarehouseDocument outcomeShift = (WarehouseDocument)c.LoadBusinessObject(BusinessObjectType.WarehouseDocument, outcomeShiftId);

                    var oppositeDocAttr = outcomeShift.Attributes.Children.Where(o => o.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId).FirstOrDefault();

                    if (oppositeDocAttr == null)
                    {
                        oppositeDocAttr = outcomeShift.Attributes.CreateNew();
                        oppositeDocAttr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId;
                        oppositeDocAttr.Value.Value       = document.Id.ToUpperString();
                    }

                    var oppositeStatusAttr = outcomeShift.Attributes.Children.Where(s => s.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus).FirstOrDefault();

                    if (oppositeStatusAttr == null)
                    {
                        oppositeStatusAttr = outcomeShift.Attributes.CreateNew();
                        oppositeStatusAttr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus;
                    }

                    oppositeStatusAttr.Value.Value = ((int)document.DocumentStatus).ToString(CultureInfo.InvariantCulture);

                    c.SaveBusinessObject(outcomeShift);
                }
            }
        }
Пример #2
0
 private static void UpdateDocumentStatus(XDocument commPkg)
 {
     using (DocumentCoordinator cord = new DocumentCoordinator(false, false))
     {
         Guid documentId = new Guid(commPkg.Root.Element("shiftDocumentStatus").Attribute("outcomeShiftId").Value);
         WarehouseDocument outcomeShiftDocument = (WarehouseDocument)cord.LoadBusinessObject(Makolab.Fractus.Kernel.Enums.BusinessObjectType.WarehouseDocument, documentId);
         DocumentAttrValue oppositeDocStatus    = outcomeShiftDocument.Attributes.Children.Where(attr => attr.DocumentFieldName == Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus).SingleOrDefault();
         if (oppositeDocStatus == null)
         {
             oppositeDocStatus = outcomeShiftDocument.Attributes.CreateNew();
             oppositeDocStatus.DocumentFieldName = Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus;
         }
         DocumentAttrValue oppositeDocId = outcomeShiftDocument.Attributes.Children.Where(attr => attr.DocumentFieldName == Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId).SingleOrDefault();
         if (oppositeDocId == null)
         {
             oppositeDocId = outcomeShiftDocument.Attributes.CreateNew();
             oppositeDocId.DocumentFieldName = Makolab.Fractus.Kernel.Enums.DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId;
             oppositeDocId.Value.Value       = commPkg.Root.Element("shiftDocumentStatus").Attribute("incomeShiftId").Value;
         }
         oppositeDocStatus.Value.Value = commPkg.Root.Element("shiftDocumentStatus").Attribute("status").Value;
         cord.SaveBusinessObject(outcomeShiftDocument);
     }
 }
Пример #3
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;
            }
        }
Пример #4
0
        public void ChangeDocumentStatus(Document document, DocumentStatus requestedStatus)
        {
            WarehouseDocument  warehouseDocument  = document as WarehouseDocument;
            FinancialDocument  financialDocument  = document as FinancialDocument;
            ServiceDocument    serviceDocument    = document as ServiceDocument;
            InventoryDocument  inventoryDocument  = document as InventoryDocument;
            ComplaintDocument  complaintDocument  = document as ComplaintDocument;
            CommercialDocument commercialDocument = document as CommercialDocument;

            DocumentStatus actualStatus = document.DocumentStatus;
            Guid           documentId   = document.Id.Value;

            bool useStandardCancelProcessing = false;

            #region MM+
            if (warehouseDocument != null && warehouseDocument.WarehouseDirection == WarehouseDirection.IncomeShift)             //MM+
            {
                if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Committed)
                {
                    warehouseDocument.DocumentStatus = DocumentStatus.Committed;
                    warehouseDocument.IssueDate      = SessionManager.VolatileElements.CurrentDateTime;

                    foreach (WarehouseDocumentLine line in warehouseDocument.Lines.Children)
                    {
                        line.Direction  = 1;
                        line.IncomeDate = SessionManager.VolatileElements.CurrentDateTime;
                    }

                    this.coordinator.SaveBusinessObject(warehouseDocument);
                }
                else if ((actualStatus == DocumentStatus.Committed || actualStatus == DocumentStatus.Saved) && requestedStatus == DocumentStatus.Canceled)
                {
                    useStandardCancelProcessing = true;
                }
            }
            #endregion
            #region MM-
            else if (warehouseDocument != null && warehouseDocument.WarehouseDirection == WarehouseDirection.OutcomeShift)             //MM-
            {
                if (actualStatus == DocumentStatus.Committed && requestedStatus == DocumentStatus.Canceled)
                {
                    useStandardCancelProcessing = true;

                    foreach (var line in warehouseDocument.Lines)
                    {
                        line.IncomeOutcomeRelations.RemoveAll();
                    }
                }
            }
            #endregion
            #region FinancialDocument
            else if (financialDocument != null)
            {
                if (actualStatus == DocumentStatus.Committed && requestedStatus == DocumentStatus.Canceled)
                {
                    DocumentStatusChangeLogic.CancelFinancialDocument(financialDocument);

                    this.coordinator.SaveBusinessObject(financialDocument);
                }
            }
            #endregion
            #region WarehouseDocumentCorrection
            else if (warehouseDocument != null && (warehouseDocument.DocumentType.DocumentCategory == DocumentCategory.IncomeWarehouseCorrection ||
                                                   warehouseDocument.DocumentType.DocumentCategory == DocumentCategory.OutcomeWarehouseCorrection))
            {
                SqlConnectionManager.Instance.BeginTransaction();

                try
                {
                    if (ConfigurationMapper.Instance.IsWmsEnabled)
                    {
                        DependencyContainerManager.Container.Get <WarehouseMapper>().DeleteShiftsForDocument(warehouseDocument.Id.Value);
                    }

                    this.mapper.CancelWarehouseDocument(warehouseDocument.Id.Value);
                    Coordinator.LogSaveBusinessObjectOperation();

                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }
                catch (SqlException sqle)
                {
                    RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:59");
                    Coordinator.ProcessSqlException(sqle, document.BOType, true);
                    throw;
                }
                catch (Exception)
                {
                    RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:60");
                    SqlConnectionManager.Instance.RollbackTransaction();
                    throw;
                }
            }
            #endregion
            #region ServiceDocument
            else if (serviceDocument != null)
            {
                if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Canceled)
                {
                    using (DocumentCoordinator c = new DocumentCoordinator(false, true))
                    {
                        c.CancelServiceDocument(serviceDocument);
                    }
                }
            }
            #endregion
            #region InventoryDocument
            else if (inventoryDocument != null)
            {
                if (actualStatus == DocumentStatus.Saved && (requestedStatus == DocumentStatus.Committed || requestedStatus == DocumentStatus.Canceled))
                {
                    inventoryDocument.DocumentStatus = requestedStatus;

                    using (DocumentCoordinator c = new DocumentCoordinator(false, true))
                    {
                        c.SaveBusinessObject(inventoryDocument);
                    }
                }
            }
            #endregion
            #region ComplaintDocument
            else if (complaintDocument != null)
            {
                if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Canceled)
                {
                    SqlConnectionManager.Instance.BeginTransaction();
                    this.coordinator.CanCommitTransaction = false;

                    foreach (DocumentRelation relation in complaintDocument.Relations)
                    {
                        if (relation.RelationType == DocumentRelationType.ComplaintToInternalIncome ||
                            relation.RelationType == DocumentRelationType.ComplaintToInternalOutcome)
                        {
                            using (DocumentCoordinator c = new DocumentCoordinator(false, false))
                            {
                                XDocument xml = new XDocument(new XElement("root"));
                                xml.Root.Add(new XElement("warehouseDocumentId", relation.RelatedDocument.Id.ToUpperString()));
                                xml.Root.Add(new XElement("status", "-20"));
                                c.ChangeDocumentStatus(xml);
                            }
                        }
                    }

                    complaintDocument.DocumentStatus = DocumentStatus.Canceled;
                    complaintDocument.Attributes[DocumentFieldName.Attribute_ProcessState].Value.Value = "closed";

                    try
                    {
                        this.coordinator.SaveBusinessObject(complaintDocument);

                        if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                        {
                            SqlConnectionManager.Instance.CommitTransaction();
                        }
                        else
                        {
                            SqlConnectionManager.Instance.RollbackTransaction();
                        }
                    }
                    catch (SqlException sqle)
                    {
                        RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:61");
                        Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                        throw;
                    }
                    catch (Exception)
                    {
                        RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:62");
                        SqlConnectionManager.Instance.RollbackTransaction();
                        throw;
                    }
                }
                else if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Committed)
                {
                    if (complaintDocument.DocumentOptions.Where(o => o is CloseProcessOption).FirstOrDefault() == null)
                    {
                        complaintDocument.DocumentOptions.Add(new CloseProcessOption());
                    }

                    this.coordinator.SaveBusinessObject(complaintDocument);
                }
            }
            #endregion
            #region SalesOrder
            else if (commercialDocument != null && commercialDocument.DocumentType.DocumentCategory == DocumentCategory.SalesOrder)
            {
                if (actualStatus == DocumentStatus.Committed && requestedStatus == DocumentStatus.Saved)                 //anulowanie rozliczenia
                {
                    SalesOrderFactory.OpenSalesOrder(commercialDocument);
                    commercialDocument.Attributes.Remove(commercialDocument.Attributes[DocumentFieldName.Attribute_SettlementDate]);
                    commercialDocument.DocumentStatus = DocumentStatus.Saved;
                }
                else if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Canceled)
                {
                    commercialDocument.Attributes[DocumentFieldName.Attribute_ProcessState].Value.Value = "canceled";
                    commercialDocument.DocumentStatus = DocumentStatus.Canceled;

                    foreach (CommercialDocumentLine line in commercialDocument.Lines.Children)
                    {
                        line.CommercialDirection = 0;
                        line.OrderDirection      = 0;
                        line.CommercialWarehouseRelations.RemoveAll();
                    }
                }
                else if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Committed)
                {
                    bool result = SalesOrderFactory.TryCloseSalesOrder(commercialDocument);

                    if (!result)
                    {
                        throw new ClientException(ClientExceptionId.ErrorClosingSalesOrder);
                    }
                }

                this.coordinator.SaveBusinessObject(document);
            }
            #endregion
            #region ProductionOrder
            else if (commercialDocument != null && commercialDocument.DocumentType.DocumentCategory == DocumentCategory.ProductionOrder)
            {
                if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Committed)
                {
                    commercialDocument.Attributes[DocumentFieldName.Attribute_ProcessState].Value.Value = "closed";
                    commercialDocument.DocumentStatus = DocumentStatus.Committed;
                }
                else if (actualStatus == DocumentStatus.Saved && requestedStatus == DocumentStatus.Canceled)
                {
                    commercialDocument.Attributes[DocumentFieldName.Attribute_ProcessState].Value.Value = "canceled";
                    commercialDocument.DocumentStatus = DocumentStatus.Canceled;
                }

                this.coordinator.SaveBusinessObject(document);
            }
            #endregion
            else if (actualStatus == DocumentStatus.Committed && requestedStatus == DocumentStatus.Canceled)
            {
                useStandardCancelProcessing = true;
            }

            //standardowa część anulowania dokumentu
            if (useStandardCancelProcessing)
            {
                SqlConnectionManager.Instance.BeginTransaction();
                this.coordinator.CanCommitTransaction = false;

                document.DocumentStatus = DocumentStatus.Canceled;

                if (document.BOType == BusinessObjectType.CommercialDocument)
                {
                    commercialDocument.ValidateSalesOrderRealizedLines(false);                    //muszę najpierw sprawdzić są pow. z ZS bo potem usuwam atrybut
                    this.ResetCommercialDocumentLinesFlags(commercialDocument);
                }
                else
                {
                    warehouseDocument.CheckDoesRealizeClosedSalesOrder(coordinator);                    //sprawdzenie przed usunięciem relacji
                    this.ResetWarehouseDocumentLinesFlags(warehouseDocument);
                }
                document.Relations.RemoveAll();

                try
                {
                    this.coordinator.SaveBusinessObject(document);

                    if (document.BOType == BusinessObjectType.CommercialDocument)
                    {
                        this.mapper.UnrelateCommercialDocumentFromWarehouseDocuments(documentId);
                    }
                    else
                    {
                        this.mapper.DeleteWarehouseDocumentRelations((WarehouseDocument)document);
                    }

                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }
                catch (SqlException sqle)
                {
                    RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:63");
                    Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                    throw;
                }
                catch (Exception)
                {
                    RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:64");
                    SqlConnectionManager.Instance.RollbackTransaction();
                    throw;
                }
            }
        }