private void ProcessLocalOutcomeShift(WarehouseDocument document)
        {
            if (document.Status != BusinessObjectStatus.New && document.Status != BusinessObjectStatus.Modified &&
                !document.Attributes.IsAnyChildNew() && !document.Attributes.IsAnyChildModified())
            {
                return;
            }

            if (document.IsLocalShift()) //mamy MMke lokalna
            {
                XElement outcomeShiftDbXml = this.mapper.LoadWarehouseDocumentDbXml(document.Id.Value);

                //zeby xml byl zgodny z takim jaki uzywa komunikacja (bo ja bedziemy "emulowac") to musimy na wycenach poustawiac
                //ordinal number pozycji ktorych dotycza
                foreach (XElement valuation in outcomeShiftDbXml.Element("warehouseDocumentValuation").Elements())
                {
                    string outcomeWarehouseDocumentLineId = valuation.Element("outcomeWarehouseDocumentLineId").Value;
                    string ordinalNumber = outcomeShiftDbXml.Element("warehouseDocumentLine").Elements().Where(l => l.Element("id").Value == outcomeWarehouseDocumentLineId).First().Element("ordinalNumber").Value;
                    valuation.Add(new XAttribute("outcomeShiftOrdinalNumber", ordinalNumber));
                }

                outcomeShiftDbXml.Element("warehouseDocumentValuation").Add(new XAttribute("outcomeShiftId", document.Id.ToUpperString()));

                using (DocumentCoordinator c = new DocumentCoordinator(false, false))
                {
                    c.CreateOrUpdateIncomeShiftDocumentFromOutcomeShift(outcomeShiftDbXml);
                    c.ValuateIncomeShiftDocument(outcomeShiftDbXml);
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        public static void CreateIncomeShiftDocumentFromOutcomeShift(XElement source, WarehouseDocument destination)
        {
            //TODO: tutaj powinno byc odczytywanie z MM- jaki jest typ dokumentu lustrzanego
            destination.DocumentTypeId = DictionaryMapper.Instance.GetDocumentType("MM+").Id.Value;

            if (source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("contractorId") != null)
            {
                ContractorMapper contractorMapper = DependencyContainerManager.Container.Get <ContractorMapper>();
                Contractor       contractor       = (Contractor)contractorMapper.CreateNewBusinessObject(BusinessObjectType.Contractor, null);
                contractor.Id          = new Guid(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("contractorId").Value);
                destination.Contractor = contractor;
            }

            destination.Number.FullNumber = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("fullNumber").Value;
            destination.Number.Number     = Convert.ToInt32(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("number").Value, CultureInfo.InvariantCulture);
            destination.Number.SeriesId   = new Guid(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("seriesId").Value);
            destination.Value             = Convert.ToDecimal(source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("value").Value, CultureInfo.InvariantCulture);
            destination.DocumentStatus    = DocumentStatus.Saved;

            //set warehouse as destination wh in the source
            Guid whDocumentFieldId = DictionaryMapper.Instance.GetDocumentField(DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId).Id.Value;

            string warehouseId = (from node in source.Element("root").Element("documentAttrValue").Elements()
                                  where node.Element("documentFieldId").Value == whDocumentFieldId.ToUpperString()
                                  select node).ElementAt(0).Element("textValue").Value;

            destination.WarehouseId = new Guid(warehouseId);

            //create attributes
            DocumentAttrValue attr = null;

            var attrs = destination.Attributes.Children.Where(a => a.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId);

            if (attrs.Count() == 1)
            {
                attr = attrs.ElementAt(0);
            }
            else
            {
                attr = destination.Attributes.CreateNew();
                attr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId;
            }

            attr.Value.Value = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("warehouseId").Value;

            attr = destination.Attributes.CreateNew();
            attr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentStatus;
            attr.Value.Value       = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("status").Value;

            attr = destination.Attributes.CreateNew();
            attr.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeDocumentId;
            attr.Value.Value       = source.Element("root").Element("warehouseDocumentHeader").Element("entry").Element("id").Value;

            DocumentField df = DictionaryMapper.Instance.GetDocumentField(DocumentFieldName.Attribute_IncomeShiftOrderId);

            if (df != null)
            {
                var srcAttr = source.Element("root").Element("documentAttrValue").Elements("entry").Where(e => e.Element("documentFieldId").Value == df.Id.ToUpperString()).FirstOrDefault();

                if (srcAttr != null)
                {
                    attr = destination.Attributes.CreateNew();
                    attr.DocumentFieldName = DocumentFieldName.Attribute_IncomeShiftOrderId;
                    attr.Value.Value       = srcAttr.Element("textValue").Value;
                }
            }
            //

            bool isLocalShift = destination.IsLocalShift();

            if (isLocalShift)
            {
                destination.DocumentStatus = DocumentStatus.Committed;
            }

            //create lines
            foreach (XElement entry in source.Element("root").Element("warehouseDocumentLine").Elements().OrderBy(e => Convert.ToInt32(e.Element("ordinalNumber").Value, CultureInfo.InvariantCulture)))
            {
                WarehouseDocumentLine line = destination.Lines.CreateNew();

                if (!isLocalShift)
                {
                    line.Direction = 0;
                }

                line.ItemId      = new Guid(entry.Element("itemId").Value);
                line.IncomeDate  = DateTime.Parse(entry.Element("outcomeDate").Value, CultureInfo.InvariantCulture);
                line.Quantity    = Convert.ToDecimal(entry.Element("quantity").Value, CultureInfo.InvariantCulture);
                line.Price       = Convert.ToDecimal(entry.Element("price").Value, CultureInfo.InvariantCulture);
                line.Value       = Convert.ToDecimal(entry.Element("value").Value, CultureInfo.InvariantCulture);
                line.UnitId      = new Guid(entry.Element("unitId").Value);
                line.WarehouseId = destination.WarehouseId;
            }
            //
        }