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; } } } } }
public XElement GetDocumentOperations(Document document) { var processTypeAttr = document.Attributes.Children.Where(a => a.DocumentFieldName == DocumentFieldName.Attribute_ProcessType).FirstOrDefault(); if (processTypeAttr == null) { return(null); } var processObjectAttr = document.Attributes.Children.Where(a => a.DocumentFieldName == DocumentFieldName.Attribute_ProcessObject).FirstOrDefault(); string processObject = processObjectAttr.Value.Value; var processStateAttr = document.Attributes.Children.Where(a => a.DocumentFieldName == DocumentFieldName.Attribute_ProcessState).FirstOrDefault(); DocumentRelation processMainObjectRelation = null; DocumentRelationType?drt = this.GetRelationTypeToMainObject(document); if (drt != null) { processMainObjectRelation = document.Relations.Children.Where(r => r.RelationType == drt.Value).FirstOrDefault(); } XElement process = ConfigurationMapper.Instance.Processes[processTypeAttr.Value.Value]; string processState = null; Document mainObject = null; if (processStateAttr != null) // jestesmy w glownym obiekcie { processState = processStateAttr.Value.Value.ToLowerInvariant(); } else //wczytujemy glowny obiekt i z niego odczytujemy stan { if (processMainObjectRelation == null) { //throw new InvalidOperationException("Relation to the main object not found in the given document."); return(null); //zmienione bo w przypadku SERWIS->FVS->WZ to wz nie ma powiazania z serwisem i narazie upraszczamy } var moElement = process.Element("objects").Elements().Where(o => o.Attribute("mainObject") != null && o.Attribute("mainObject").Value.ToUpperInvariant() == "TRUE").First(); string typeSymbol = moElement.Attribute("typeSymbol").Value; DocumentType dt = DictionaryMapper.Instance.GetDocumentType(typeSymbol); using (Coordinator c = Coordinator.GetCoordinatorForSpecifiedType(dt.BusinessObjectType, false, false)) { mainObject = (Document)c.LoadBusinessObject(dt.BusinessObjectType, processMainObjectRelation.RelatedDocument.Id.Value); } processState = mainObject.Attributes.Children.Where(aa => aa.DocumentFieldName == DocumentFieldName.Attribute_ProcessState).First().Value.Value.ToLowerInvariant(); } //mamy stan procesu, mamy role jaka odgrywa biezacy dokument (processObject), wiec teraz sprawdzamy jakie operacje moze miec var operationsResult = from node in process.Element("states").Elements("state") where node.Attribute("name").Value == processState from operation in node.Elements() where operation.Attribute("object").Value == processObject select operation; XElement operations = new XElement("operations"); operations.Add(operationsResult); if (document.DocumentType.DocumentCategory == DocumentCategory.SalesOrder) { CommercialDocument comDoc = document as CommercialDocument; if (comDoc.SalesOrderSettlements == null) //na wszelki wypadek tylko jak w pozniejszym developmencie zdarzy sie inny przypadek { SalesOrderSettlements settlements = new SalesOrderSettlements(); settlements.LoadSalesOrder(comDoc); XElement prepaidsXml = DependencyContainerManager.Container.Get <DocumentMapper>().GetSalesOrderSettledAmount(comDoc.Id.Value); settlements.LoadPrepaids(prepaidsXml); comDoc.SalesOrderSettlements = settlements; } } this.FilterOperations(document, operations); return(operations); }
public static void GetColumnNames(DocumentRelation relation, ref string parentColumnName, ref string relatedDocumentColumnName) { Document parent = (Document)relation.Parent; DocumentRelationType relationType = relation.RelationType; switch (relationType) { case DocumentRelationType.SalesDocumentToSimulatedInvoice: if (parent.DocumentType.CommercialDocumentOptions.SimulatedInvoice != null) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondCommercialDocumentHeaderId"; } else { parentColumnName = "secondCommercialDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.InvoiceToBill: if (parent.DocumentType.CommercialDocumentOptions.IsInvoiceAppendable) //parent relacji to paragon { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondCommercialDocumentHeaderId"; } else { parentColumnName = "secondCommercialDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.ServiceToOutcomeShift: if (parent.BOType == BusinessObjectType.ServiceDocument) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondWarehouseDocumentHeaderId"; } else { parentColumnName = "secondWarehouseDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.ServiceToInvoice: if (parent.BOType == BusinessObjectType.ServiceDocument) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondCommercialDocumentHeaderId"; } else { parentColumnName = "secondCommercialDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.ServiceToInternalOutcome: if (parent.BOType == BusinessObjectType.ServiceDocument) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondWarehouseDocumentHeaderId"; } else { parentColumnName = "secondWarehouseDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.ComplaintToInternalOutcome: if (parent.BOType == BusinessObjectType.ComplaintDocument) { parentColumnName = "firstComplaintDocumentHeaderId"; relatedDocumentColumnName = "secondWarehouseDocumentHeaderId"; } else { parentColumnName = "secondWarehouseDocumentHeaderId"; relatedDocumentColumnName = "firstComplaintDocumentHeaderId"; } break; case DocumentRelationType.InventoryToWarehouse: if (parent.BOType == BusinessObjectType.InventoryDocument) { parentColumnName = "firstInventoryDocumentHeaderId"; relatedDocumentColumnName = "secondWarehouseDocumentHeaderId"; } else { parentColumnName = "secondWarehouseDocumentHeaderId"; relatedDocumentColumnName = "firstInventoryDocumentHeaderId"; } break; case DocumentRelationType.SalesOrderToInvoice: case DocumentRelationType.SalesOrderToCorrectiveCommercialDocument: case DocumentRelationType.SalesOrderToSimulatedInvoice: if (parent.Attributes[DocumentFieldName.Attribute_ProcessObject] != null && parent.Attributes[DocumentFieldName.Attribute_ProcessObject].Value.Value == ProcessObjectName.SalesOrder) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondCommercialDocumentHeaderId"; } else { parentColumnName = "secondCommercialDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.SalesOrderToWarehouseDocument: if (parent.BOType == BusinessObjectType.CommercialDocument) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondWarehouseDocumentHeaderId"; } else { parentColumnName = "secondWarehouseDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.SalesOrderToOutcomeFinancialDocument: if (parent.BOType == BusinessObjectType.CommercialDocument) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondFinancialDocumentHeaderId"; } else { parentColumnName = "secondFinancialDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; case DocumentRelationType.ProductionOrderToIncome: case DocumentRelationType.ProductionOrderToOutcome: if (parent.BOType == BusinessObjectType.CommercialDocument) { parentColumnName = "firstCommercialDocumentHeaderId"; relatedDocumentColumnName = "secondWarehouseDocumentHeaderId"; } else { parentColumnName = "secondWarehouseDocumentHeaderId"; relatedDocumentColumnName = "firstCommercialDocumentHeaderId"; } break; default: throw new InvalidOperationException("Unknown DocumentRelationType"); } }
public static Document DeserializeRelatedDocument(DocumentRelation relation, XElement relatedDocument) { Document parent = (Document)relation.Parent; DocumentRelationType relationType = relation.RelationType; Document retDocument = null; if (relatedDocument == null) { throw new ClientException(ClientExceptionId.IncompleteRelation); } switch (relationType) { case DocumentRelationType.SalesDocumentToSimulatedInvoice: case DocumentRelationType.InvoiceToBill: retDocument = new CommercialDocument(); retDocument.Deserialize(relatedDocument); break; case DocumentRelationType.ServiceToOutcomeShift: if (parent.BOType == BusinessObjectType.ServiceDocument) { retDocument = new WarehouseDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new ServiceDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.ServiceToInvoice: if (parent.BOType == BusinessObjectType.ServiceDocument) { retDocument = new CommercialDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new ServiceDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.ServiceToInternalOutcome: if (parent.BOType == BusinessObjectType.ServiceDocument) { retDocument = new WarehouseDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new ServiceDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.ComplaintToInternalOutcome: if (parent.BOType == BusinessObjectType.ComplaintDocument) { retDocument = new WarehouseDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new ComplaintDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.InventoryToWarehouse: if (parent.BOType == BusinessObjectType.InventoryDocument) { retDocument = new WarehouseDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new InventoryDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.SalesOrderToInvoice: case DocumentRelationType.SalesOrderToCorrectiveCommercialDocument: case DocumentRelationType.SalesOrderToSimulatedInvoice: retDocument = new CommercialDocument(); retDocument.Deserialize(relatedDocument); break; case DocumentRelationType.SalesOrderToWarehouseDocument: if (parent.BOType == BusinessObjectType.CommercialDocument) { retDocument = new WarehouseDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new CommercialDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.SalesOrderToOutcomeFinancialDocument: if (parent.BOType == BusinessObjectType.CommercialDocument) { retDocument = new FinancialDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new CommercialDocument(); retDocument.Deserialize(relatedDocument); } break; case DocumentRelationType.ProductionOrderToIncome: case DocumentRelationType.ProductionOrderToOutcome: if (parent.BOType == BusinessObjectType.CommercialDocument) { retDocument = new WarehouseDocument(); retDocument.Deserialize(relatedDocument); } else { retDocument = new CommercialDocument(); retDocument.Deserialize(relatedDocument); } break; default: throw new InvalidOperationException("Unknown DocumentRelationType"); } return(retDocument); }
/// <summary> /// Executes the custom logic. /// </summary> /// <param name="document">The document to execute custom logic for.</param> private void ExecuteCustomLogic(CommercialDocument document) { //sprawdzamy czy zlecenie/technologia nie posiada pozycji uslugowych this.mapper.AddItemsToItemTypesCache(document); var cache = SessionManager.VolatileElements.ItemTypesCache; //foreach (var line in document.Lines) //{ // Guid itemTypeId = cache[line.ItemId]; // // Tutaj jest walidacja typów produktów ale nie potrzebnie, usługa w kontekście robocizny, powinna dać się zapisać w // // procesie produkcyjnym // if (!DictionaryMapper.Instance.GetItemType(itemTypeId).IsWarehouseStorable) // throw new ClientException(ClientExceptionId.InvalidItemType); //} CommercialDocument alternateDocument = document.AlternateVersion as CommercialDocument; //zamykanie ZP if (alternateDocument != null && alternateDocument.DocumentStatus == DocumentStatus.Saved && document.DocumentStatus == DocumentStatus.Committed && document.DocumentType.DocumentCategory == DocumentCategory.ProductionOrder) { Dictionary <Guid, CommercialDocument> technologies = new Dictionary <Guid, CommercialDocument>(); WarehouseDocument internalOutcome = null; WarehouseDocument internalIncome = null; WarehouseDocument internalIncomeByproduct = null; using (DocumentCoordinator c = new DocumentCoordinator(false, false)) { internalOutcome = (WarehouseDocument)c.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, ProcessManager.Instance.GetDocumentTemplate(document, "internalOutcome"), null); internalIncome = (WarehouseDocument)c.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, ProcessManager.Instance.GetDocumentTemplate(document, "internalIncome"), null); internalIncomeByproduct = (WarehouseDocument)c.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, ProcessManager.Instance.GetDocumentTemplate(document, "internalIncomeByproduct"), null); } ProcessManager.Instance.AppendProcessAttributes(internalIncome, document.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value, "internalIncome", null, null); internalIncome.WarehouseId = ProcessManager.Instance.GetProductWarehouse(document); ProcessManager.Instance.AppendProcessAttributes(internalOutcome, document.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value, "internalOutcome", null, null); internalOutcome.WarehouseId = ProcessManager.Instance.GetMaterialWarehouse(document); ProcessManager.Instance.AppendProcessAttributes(internalIncomeByproduct, document.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value, "internalIncomeByproduct", null, null); internalIncomeByproduct.WarehouseId = ProcessManager.Instance.GetByproductWarehouse(document); //wczytujemy wszystkie technologie //generujemy jeden wielki RW i PW dla wzsystkich technologii i podczepiamy go do zlecenia produkcyjnego foreach (CommercialDocumentLine line in document.Lines) { var attr = line.Attributes[DocumentFieldName.LineAttribute_ProductionTechnologyName]; Guid technologyId = new Guid(attr.Value.Value); if (!technologies.ContainsKey(technologyId)) { CommercialDocument t = (CommercialDocument)this.mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, technologyId); technologies.Add(technologyId, t); } this.ProcessTechnology(technologies[technologyId], line.Quantity, internalIncome, internalOutcome, internalIncomeByproduct, line.OrdinalNumber); } DocumentRelation relation = null; relation = internalOutcome.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ProductionOrderToOutcome; relation.RelatedDocument = document; relation = document.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ProductionOrderToOutcome; relation.RelatedDocument = internalOutcome; relation.DontSave = true; DuplicableAttributeFactory.DuplicateAttributes(document, internalOutcome); document.AddRelatedObject(internalOutcome); relation = internalIncome.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ProductionOrderToIncome; relation.RelatedDocument = document; relation = document.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ProductionOrderToIncome; relation.RelatedDocument = internalIncome; relation.DontSave = true; DuplicableAttributeFactory.DuplicateAttributes(document, internalIncome); document.AddRelatedObject(internalIncome); if (internalIncomeByproduct.Lines.Children.Count > 0) { relation = internalIncomeByproduct.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ProductionOrderToIncome; relation.RelatedDocument = document; relation = document.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ProductionOrderToIncome; relation.RelatedDocument = internalIncomeByproduct; relation.DontSave = true; DuplicableAttributeFactory.DuplicateAttributes(document, internalIncomeByproduct); document.AddRelatedObject(internalIncomeByproduct); } } }