Ejemplo n.º 1
0
        public override bool ExecutePackage(ICommunicationPackage communicationPackage)
        {
            SessionManager.VolatileElements.DeferredTransactionId = communicationPackage.XmlData.DeferredTransactionId;
            SessionManager.VolatileElements.LocalTransactionId    = this.LocalTransactionId;

            try
            {
                if (this.IsHeadquarter == true)
                {
                    if (base.ExecutePackage(communicationPackage) == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    this.CurrentPackage = new DBXml(XDocument.Parse(communicationPackage.XmlData.Content));
                }

                if (this.CurrentPackage.Table("documentAttrValue") == null)
                {
                    throw new Exception("CommercialDocumentExScript: Brak atrybutu Attribute_TargetBranchId");
                }

                string targetBranch = PackageExecutionHelper.GetDocumentAttrValue(this.CurrentPackage.Table("documentAttrValue").Xml,
                                                                                  Makolab.Fractus.Kernel.Enums.DocumentFieldName.Attribute_TargetBranchId,
                                                                                  "textValue");
                if (targetBranch == null)
                {
                    throw new Exception("CommercialDocumentExScript: Brak atrybutu Attribute_TargetBranchId");
                }

                Guid targetBranchId = new Guid(targetBranch);
                if (PackageExecutionHelper.IsSameDatabase(Makolab.Fractus.Kernel.Mappers.ConfigurationMapper.Instance.DatabaseId, targetBranchId) == true)
                {
                    using (Kernel.Coordinators.DocumentCoordinator coordinator = new Makolab.Fractus.Kernel.Coordinators.DocumentCoordinator(false, false))
                    {
                        coordinator.CreateOrUpdateReservationFromOrder(this.CurrentPackage.Xml.Root);
                    }
                }
                else if (this.IsHeadquarter == true && MustForwardPackage())
                {
                    ForwardPackage(communicationPackage, targetBranchId);
                }
            }
            catch (SqlException e)
            {
                if (e.Number == 50012) // Conflict detection
                {
                    throw new ConflictException("Conflict detected while changing " + this.MainObjectTag + " id: " + this.CurrentPackage.Table(this.MainObjectTag).FirstRow().Element("id").Value);
                }
                else
                {
                    this.Log.Error("CommercialDocumentExScript:ExecutePackage " + e.ToString());
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void ExecuteOutcomeShift()
        {
            var valuationsData = this.CurrentPackage.Table("warehouseDocumentValuation");

            if (valuationsData != null && valuationsData.HasRows == true)
            {
                valuationsData.Xml.Add(new XAttribute("outcomeShiftId", this.CurrentPackage.Table("warehouseDocumentHeader").FirstRow().Element("id").Value));
                foreach (DBRow valuationRow in valuationsData.Rows)
                {
                    var docLine = this.CurrentPackage.Table("warehouseDocumentLine").Rows.Where(row => row.Element("id").Value.Equals(valuationRow.Element("outcomeWarehouseDocumentLineId").Value)).SingleOrDefault();
                    valuationRow.Xml.Add(new XAttribute("outcomeShiftOrdinalNumber", docLine.Element("ordinalNumber").Value));
                }
            }

            using (Kernel.Coordinators.DocumentCoordinator coordinator = new Makolab.Fractus.Kernel.Coordinators.DocumentCoordinator(false, false))
            {
                coordinator.CreateOrUpdateIncomeShiftDocumentFromOutcomeShift(this.CurrentPackage.Xml.Root);
                if (valuationsData != null && valuationsData.HasRows == true)
                {
                    coordinator.ValuateIncomeShiftDocument(this.CurrentPackage.Xml.Root);
                }
            }
        }