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; } }
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); } } }
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); } }
private static void ForwardValuations(ICommunicationPackage communicationPackage, XDocument commPkg, ICommunicationPackageRepository repository) { var distributedLines = commPkg.Root.Element("warehouseDocumentValuation").Elements("entry") .Where( row => row.Element("isDistributed") != null && row.Element("isDistributed").Value.Equals("True", StringComparison.OrdinalIgnoreCase) && row.Element("warehouseDocumentHeaderId") != null && (row.Attribute("action") == null || row.Attribute("action").Value.Equals("delete", StringComparison.OrdinalIgnoreCase) == false)) .GroupBy(row => row.Element("warehouseDocumentHeaderId").Value); //this valuation is not for shift document, so we don't forward it if (distributedLines.Count() == 0) { return; } XDocument valuationTemplate = XDocument.Parse("<root><warehouseDocumentValuation /></root>"); Guid localTransactionId = Guid.NewGuid(); using (var wrapper = repository.Context.ConnectionManager.SynchronizeConnection()) { SqlConnectionManager.Instance.SetConnection(wrapper.Connection, (SqlTransaction)repository.Context.Transaction); } using (var whDocCoord = new DocumentCoordinator(false, false)) { foreach (var warehouseDocGroup in distributedLines) { WarehouseDocument shift = null; try { shift = (WarehouseDocument)whDocCoord.LoadBusinessObject(Makolab.Fractus.Kernel.Enums.BusinessObjectType.WarehouseDocument, new Guid(warehouseDocGroup.Key)); } catch (ClientException) { } //there is a valuated document in database so we can forward valuation - no document = skip valuations for this doc if (shift != null) { string oppositeWarehouseId = (shift.Attributes.Count() > 0 && shift.Attributes.Children.Any(attr => attr.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId)) ? shift.Attributes[DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId].Value.Value : null; if (oppositeWarehouseId != null) { Warehouse oppositeWarehouse = DictionaryMapper.Instance.GetWarehouse(new Guid(oppositeWarehouseId)); Warehouse warehouse = DictionaryMapper.Instance.GetWarehouse(shift.WarehouseId); //skip local shift document valuations if (warehouse.BranchId == oppositeWarehouse.BranchId) { continue; } foreach (var valuation in warehouseDocGroup) { var whDocLine = shift.Lines.Children.Where(line => line.Id.ToString() .Equals(valuation.Element("outcomeWarehouseDocumentLineId").Value, StringComparison.OrdinalIgnoreCase)) .SingleOrDefault(); valuation.Add(new XAttribute("outcomeShiftOrdinalNumber", whDocLine.OrdinalNumber)); } var valuationPkg = new XDocument(valuationTemplate); valuationPkg.Root.Element("warehouseDocumentValuation").Add(new XAttribute("outcomeShiftId", shift.Id)); valuationPkg.Root.Element("warehouseDocumentValuation").Add(warehouseDocGroup); XmlTransferObject valuationData = new XmlTransferObject { DeferredTransactionId = communicationPackage.XmlData.DeferredTransactionId, Id = Guid.NewGuid(), LocalTransactionId = localTransactionId, XmlType = "WarehouseDocumentValuation", Content = valuationPkg.ToString(SaveOptions.DisableFormatting) }; ICommunicationPackage pkg = new CommunicationPackage(valuationData); pkg.DatabaseId = DictionaryMapper.Instance.GetBranch(oppositeWarehouse.BranchId).DatabaseId; repository.PutToOutgoingQueue(pkg); } } } } }
private void ValuateIncomeFromOutcome(IEnumerable <IGrouping <string, DBRow> > shiftLines) { XDocument valuationTemplate = XDocument.Parse("<root><warehouseDocumentValuation /></root>"); using (var whDocCoord = new DocumentCoordinator(false, false)) { foreach (var warehouseDocGroup in shiftLines) { WarehouseDocument shift = null; try { shift = (WarehouseDocument)whDocCoord.LoadBusinessObject(Makolab.Fractus.Kernel.Enums.BusinessObjectType.WarehouseDocument, new Guid(warehouseDocGroup.Key)); } catch (ClientException) { } //there is a valuated document in database so we can forward valuation - no document = skip income valuation for this doc if (shift != null) { DocumentAttrValue oppositeWarehouseIdAttr = shift.Attributes.Children.Where(attr => attr.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId).SingleOrDefault(); string oppositeWarehouseId = oppositeWarehouseIdAttr != null ? oppositeWarehouseIdAttr.Value.Value : null; if (oppositeWarehouseId != null) { Warehouse oppositeWarehouse = DictionaryMapper.Instance.GetWarehouse(new Guid(oppositeWarehouseId)); Warehouse warehouse = DictionaryMapper.Instance.GetWarehouse(shift.WarehouseId); //skip local shift document valuations if (warehouse.BranchId == oppositeWarehouse.BranchId) { continue; } // skip valuation in headquarter if not a target branch if (this.IsHeadquarter == true && DictionaryMapper.Instance.GetBranch(oppositeWarehouse.BranchId).DatabaseId != Makolab.Fractus.Kernel.Mappers.ConfigurationMapper.Instance.DatabaseId) { continue; } foreach (var valuation in warehouseDocGroup) { var whDocLine = shift.Lines.Children.Where(line => line.Id.ToString() .Equals(valuation.Element("outcomeWarehouseDocumentLineId").Value, StringComparison.OrdinalIgnoreCase)) .SingleOrDefault(); valuation.Xml.Add(new XAttribute("outcomeShiftOrdinalNumber", whDocLine.OrdinalNumber)); } var valuationPkg = new XDocument(valuationTemplate); valuationPkg.Root.Element("warehouseDocumentValuation").Add(new XAttribute("outcomeShiftId", shift.Id)); valuationPkg.Root.Element("warehouseDocumentValuation").Add(warehouseDocGroup); try { whDocCoord.ValuateIncomeShiftDocument(valuationPkg.Root); } catch (ClientException e) { if (e.Id != Makolab.Fractus.Kernel.Enums.ClientExceptionId.ObjectNotFound) { throw; } } } } } } }