/// <summary> /// Creates object responsible for processing package of specified type. /// </summary> /// <param name="packageType">Type of the package to processed.</param> /// <param name="xmlPackage">The XML package to process.</param> /// <returns>Created package processing object.</returns> public IExecutingScript CreateScript(string packageType, XDocument xmlPackage) { if (packageType == null) { throw new ArgumentNullException("packageType"); } CommunicationPackageType packageTypeVal; try { packageTypeVal = (CommunicationPackageType)Enum.Parse(typeof(CommunicationPackageType), packageType); } catch (ArgumentException) { packageTypeVal = CommunicationPackageType.Unknown; } IExecutingScript script = null; switch (packageTypeVal) { case CommunicationPackageType.ComplaintDocumentSnapshot: script = new ComplaintDocumentSnapshot(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Configuration: script = new ConfigurationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ContractorSnapshot: script = new ContractorScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ContractorRelations: script = new ContractorRelationsScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ContractorGroupMembership: script = new ContractorGroupMembershipScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.DictionaryPackage: script = new DictionarySnapshotScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.FileDescriptor: script = new FileDescriptorScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.FinancialReport: script = new FinancialReportScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.FinancialDocumentSnapshot: script = new FinancialDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.InventoryDocumentSnapshot: script = new InventoryDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemSnapshot: script = new ItemSnapshotScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemRelation: script = new ItemRelationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemUnitRelation: script = new ItemUnitRelationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemGroupMembership: script = new ItemGroupMembershipScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialDocumentSnapshot: script = new CommercialDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialDocumentSnapshotEx: script = new CommercialDocumentExScript(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); break; case CommunicationPackageType.Series: script = new SeriesScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialWarehouseValuation: script = new CommercialWarehouseValuation(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialWarehouseRelation: script = new CommercialWarehouseRelation(UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.DocumentRelation: script = new DocumentRelationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.IncomeOutcomeRelation: script = new IncomeOutcomeRelation(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Payment: script = new PaymentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.WarehouseDocumentValuation: script = new WarehouseDocumentValuation(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); break; //TODO !! aktualnie WZk dotykajaca mmki bedzie traktowana jak by nie miala nic wspolnego z mmka // czyli nie zostanie przeslana do oddzialu docelowego case CommunicationPackageType.WarehouseDocumentSnapshot: if (xmlPackage.Root.Element("warehouseDocumentLine").Elements("entry").All(row => row.Element("isDistributed").Value.Equals("1"))) { DocumentType docType = DictionaryMapper.Instance.GetDocumentType(new Guid(xmlPackage.Root.Element("warehouseDocumentHeader") .Element("entry").Element("documentTypeId").Value)); if (docType.DocumentCategory != Makolab.Fractus.Kernel.Enums.DocumentCategory.IncomeWarehouseCorrection && docType.DocumentCategory != Makolab.Fractus.Kernel.Enums.DocumentCategory.OutcomeWarehouseCorrection) { script = new ShiftDocumentSnapshot(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); } else { script = new WarehouseDocumentSnapshot(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); } } else { script = new WarehouseDocumentSnapshot(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); } break; case CommunicationPackageType.WarehouseStock: script = new WarehouseStockScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.UnrelateCommercialDocument: script = new UnrelateCommercialDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.UnrelateWarehouseDocumentForOutcome: script = new UnrelateWarehouseDocumentForOutcomeScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.UnrelateWarehouseDocumentForIncome: script = new UnrelateWarehouseDocumentForIncomeScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ShiftDocumentStatus: script = new ShiftDocumentStatusScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.PriceRule: script = new PriceRuleScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.PriceRuleList: script = new PriceRuleListScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Custom: script = new CustomScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Unknown: case CommunicationPackageType.Other: default: script = new NullScript(); break; } script.LocalTransactionId = this.LocalTransactionId; return(script); }
public void CreateLinesForOutcomeShiftDocument(ICollection <WarehouseDocumentLine> sourceLines, ICollection <DeliveryResponse> deliveryResponses, WarehouseDocument destinationDocument) { foreach (WarehouseDocumentLine line in sourceLines) { WarehouseDocument warehouseDocument = line.Parent as WarehouseDocument; var deliveryResponse = (from del in deliveryResponses where del.ItemId == line.ItemId && del.WarehouseId == line.WarehouseId select del).FirstOrDefault(); var validDeliveries = deliveryResponse.Deliveries.Where(d => this.IsValidDelivery(d.IssueDate, warehouseDocument.IssueDate)); decimal originalAvailableQuantity = deliveryResponse.AvailableQuantity; //tutaj zliczam wszystkie nowe na wypadek edycji bo wtedy powinny zostac wszystkie relacje usuniete i na nowo utworzone decimal lineDeliveriesSelected = line.IncomeOutcomeRelations.Children.Where(rr => rr.IsNew).Sum(r => r.Quantity); if (lineDeliveriesSelected != line.Quantity) { throw new ClientException(ClientExceptionId.NotEnoughDeliveriesSelected, null, "itemName:" + line.ItemName); } foreach (IncomeOutcomeRelation relation in line.IncomeOutcomeRelations.Children.Where(c => c.IsNew)) { //odszukujemy dostawe var del = validDeliveries.Where(d => d.IncomeWarehouseDocumentLineId == relation.RelatedLine.Id.Value).FirstOrDefault(); if (del == null || del.Quantity == 0 || del.Quantity < relation.Quantity) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(line.ItemId); throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + this.warehouseName); } WarehouseDocumentLine dstLine = destinationDocument.Lines.CreateNew(); dstLine.SourceOutcomeShiftLine = line; //ustawiamy income date na relacji dstLine.ItemId = line.ItemId; dstLine.OutcomeDate = destinationDocument.IssueDate; dstLine.Price = line.Price; dstLine.Quantity = relation.Quantity; dstLine.UnitId = line.UnitId; dstLine.WarehouseId = destinationDocument.WarehouseId; dstLine.IncomeDate = del.IncomeDate; IncomeOutcomeRelation rel = dstLine.IncomeOutcomeRelations.CreateNew(BusinessObjectStatus.New, WarehouseDirection.Outcome); if (relation.Quantity == del.Quantity) { rel.OutcomeDate = dstLine.OutcomeDate; } rel.IncomeDate = del.IncomeDate; rel.Quantity = relation.Quantity; rel.RelatedLine.Id = del.IncomeWarehouseDocumentLineId; deliveryResponse.AvailableQuantity -= relation.Quantity; del.Quantity -= relation.Quantity; } //dla wz-tow realizujacych rezerwacje pomijamy ilosci zarezerwowane. bierzemy pod uwage tylko ilosc na stanie i koniec if (!line.CommercialWarehouseRelations.Children.Any(r => r.IsOrderRelation) && deliveryResponse.AvailableQuantity < 0) { WarehouseDocumentLine altLine = line.AlternateVersion as WarehouseDocumentLine; /* * tutaj ten if jest w celu obsluzenia takiego przypadku: * Mamy na magazynie 0 sztuk, a zarezerwowane 2 * Edytujemy dokument, ktory ma 3 szt. wiec zwalniamy powiazania i tworzymy je na nowo * W tej sytuacji bez tego if'a wyskoczy nam ze mozemy tylko 1 szt. zabrac, a mozemy w praktyce wziasc * wszystkie 3 bo te 3 zostaly przez naz zwolnione */ if (altLine == null || altLine.Quantity - originalAvailableQuantity < deliveryResponse.AvailableQuantity) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(line.ItemId); throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + this.warehouseName); } } } //przepinamy shifty do nowo podzielonych linii if (destinationDocument.ShiftTransaction != null) { foreach (Shift shift in destinationDocument.ShiftTransaction.Shifts.Children) { var foundLine = destinationDocument.Lines.Children.Where(l => l.IncomeOutcomeRelations.Children.First().RelatedLine.Id.Value == shift.IncomeWarehouseDocumentLineId && shift.LineOrdinalNumber.Value == l.SourceOutcomeShiftLine.OrdinalNumber).FirstOrDefault(); shift.RelatedWarehouseDocumentLine = foundLine; } } }
/// <summary> /// Creates the outcomes for the specifies lines using specified deliveries. /// </summary> /// <param name="lines">The lines for which to create the outcomes. They have to be from the same warehouse.</param> /// <param name="deliveryResponses">Collection of delivery responses. Can contain deliveries from other warehouses too.</param> public void CreateOutcomes(ICollection <WarehouseDocumentLine> lines, ICollection <DeliveryResponse> deliveryResponses) { foreach (WarehouseDocumentLine line in lines) { WarehouseDocument warehouseDocument = line.Parent as WarehouseDocument; var deliveryResponse = (from del in deliveryResponses where del.ItemId == line.ItemId && del.WarehouseId == line.WarehouseId select del).FirstOrDefault(); var sortedDeliveries = from del in deliveryResponse.Deliveries where IsValidDelivery(del.IssueDate, warehouseDocument.IssueDate) == true orderby del.IncomeDate ascending, del.OrdinalNumber ascending select del; decimal originalAvailableQuantity = deliveryResponse.AvailableQuantity; decimal quantityToGo = Math.Abs(line.Quantity); while (quantityToGo > 0) { if (sortedDeliveries.Count() == 0) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(line.ItemId); throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + this.warehouseName); } else { DeliveryResponse.SingleDelivery del = sortedDeliveries.First(); if (del.Quantity >= quantityToGo) { IncomeOutcomeRelation rel = line.IncomeOutcomeRelations.CreateNew(BusinessObjectStatus.New, WarehouseDirection.Outcome); rel.Quantity = quantityToGo; rel.RelatedLine.Id = del.IncomeWarehouseDocumentLineId; rel.IncomeDate = del.IncomeDate; line.IncomeDate = rel.IncomeDate; del.Quantity -= quantityToGo; deliveryResponse.AvailableQuantity -= quantityToGo; quantityToGo = 0; if (del.Quantity == 0) { rel.OutcomeDate = line.OutcomeDate; deliveryResponse.Deliveries.Remove(del); } } else //del.Quantity < quantityToGo { IncomeOutcomeRelation rel = line.IncomeOutcomeRelations.CreateNew(BusinessObjectStatus.New, WarehouseDirection.Outcome); rel.OutcomeDate = line.OutcomeDate; rel.IncomeDate = del.IncomeDate; line.IncomeDate = rel.IncomeDate; rel.Quantity = del.Quantity; deliveryResponse.AvailableQuantity -= del.Quantity;; rel.RelatedLine.Id = del.IncomeWarehouseDocumentLineId; quantityToGo -= del.Quantity; deliveryResponse.Deliveries.Remove(del); } } } //dla wz-tow realizujacych rezerwacje pomijamy ilosci zarezerwowane. bierzemy pod uwage tylko ilosc na stanie i koniec if ((!line.CommercialWarehouseRelations.Children.Any(r => r.IsOrderRelation) || warehouseDocument.SkipReservedQuantityCheck) && deliveryResponse.AvailableQuantity < 0) { WarehouseDocumentLine altLine = line.AlternateVersion as WarehouseDocumentLine; /* * tutaj ten if jest w celu obsluzenia takiego przypadku: * Mamy na magazynie 0 sztuk, a zarezerwowane 2 * Edytujemy dokument, ktory ma 3 szt. wiec zwalniamy powiazania i tworzymy je na nowo * W tej sytuacji bez tego if'a wyskoczy nam ze mozemy tylko 1 szt. zabrac, a mozemy w praktyce wziasc * wszystkie 3 bo te 3 zostaly przez naz zwolnione */ if (altLine == null || altLine.Quantity - originalAvailableQuantity < deliveryResponse.AvailableQuantity) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(line.ItemId); throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + this.warehouseName); } } } }
private void AddPositionToWarehouseDocument(ComplaintDocument complaintDocument, Guid warehouseId, List <WarehouseDocument> generatedWhDocs, Guid itemId, decimal quantity, Guid unitId, WarehouseDirection direction) { WarehouseDocument document = (from whDoc in generatedWhDocs where whDoc.WarehouseId == warehouseId && whDoc.WarehouseDirection == direction select whDoc).FirstOrDefault(); if (document == null) { string documentName = null; if (direction == WarehouseDirection.Outcome) { documentName = "internalOutcome"; } else { documentName = "internalIncome"; } string template = ProcessManager.Instance.GetDocumentTemplate(complaintDocument, documentName); using (DocumentCoordinator c = new DocumentCoordinator(false, false)) { document = (WarehouseDocument)c.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, template, null); document.WarehouseId = warehouseId; string processType = complaintDocument.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value; ProcessManager.Instance.AppendProcessAttributes(document, processType, documentName, null, null); document.Contractor = complaintDocument.Contractor; DuplicableAttributeFactory.DuplicateAttributes(complaintDocument, document); complaintDocument.AddRelatedObject(document); generatedWhDocs.Add(document); var relation = complaintDocument.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ComplaintToInternalOutcome; relation.RelatedDocument = document; relation = document.Relations.CreateNew(); relation.RelationType = DocumentRelationType.ComplaintToInternalOutcome; relation.RelatedDocument = complaintDocument; relation.DontSave = true; } } WarehouseDocumentLine line = document.Lines.Children.Where(l => l.ItemId == itemId).FirstOrDefault(); if (line == null) { line = document.Lines.CreateNew(); line.ItemId = itemId; line.UnitId = unitId; } line.Quantity += quantity; /* sprawdzamy czy jest to rozchod z magazynu wmsowego. jezeli tak to tworzymy shift transaction * dodajemy nowego shifta zgodnie z tym co jest w complaintDocument.Shifts, potem * shifta wiazemy z pozycja */ if (DictionaryMapper.Instance.GetWarehouse(document.WarehouseId).ValuationMethod == ValuationMethod.DeliverySelection) { ShiftTransaction shiftTransaction = document.ShiftTransaction; if (shiftTransaction == null) { shiftTransaction = new ShiftTransaction(null); document.ShiftTransaction = shiftTransaction; } //wyciagamy shifty z complaintDocumenta var shifts = complaintDocument.AllocationCollection.Allocations.Where(s => s.ItemId == itemId && s.WarehouseId == warehouseId).Select(x => x.AllocationShifts).FirstOrDefault(); decimal quantityToGo = quantity; //kopiujemy shifty na ilosc niewieksza niz na pozycji jest wybrane foreach (var shift in shifts) { if (shift.Quantity == 0) { continue; } decimal quantityTaken = 0; if (quantityToGo > shift.Quantity) { quantityTaken = shift.Quantity; } else //quantityToGo <= shift.Quantity { quantityTaken = quantityToGo; } shift.Quantity -= quantityTaken; quantityToGo -= quantityTaken; if (shift.SourceShiftId != null) //te ktore nie maja sourceShiftId pomijamy bo tutaj takie luzem w ogole nie maja shifta { var newShift = shiftTransaction.Shifts.CreateNew(); newShift.ItemId = itemId; newShift.WarehouseId = warehouseId; newShift.SourceShiftId = shift.SourceShiftId.Value; newShift.IncomeWarehouseDocumentLineId = shift.IncomeWarehouseDocumentLineId; newShift.Quantity = quantityTaken; newShift.RelatedWarehouseDocumentLine = line; newShift.LineOrdinalNumber = line.OrdinalNumber; } //teraz incomeOutcomeRelation dodajemy IncomeOutcomeRelation relation = line.IncomeOutcomeRelations.Children.Where(i => i.RelatedLine.Id.Value == shift.IncomeWarehouseDocumentLineId).FirstOrDefault(); if (relation == null) { relation = line.IncomeOutcomeRelations.CreateNew(); var incLine = new WarehouseDocumentLine(null); incLine.Id = shift.IncomeWarehouseDocumentLineId; relation.RelatedLine = incLine; } relation.Quantity += quantityTaken; if (quantityToGo == 0) { break; } } } }
public void CreateLinesForOutcomeShiftDocument(ICollection <WarehouseDocumentLine> sourceLines, ICollection <DeliveryResponse> deliveryResponses, WarehouseDocument destinationDocument) { foreach (WarehouseDocumentLine line in sourceLines) { var deliveryResponse = (from del in deliveryResponses where del.ItemId == line.ItemId && del.WarehouseId == line.WarehouseId select del).FirstOrDefault(); var sortedDeliveries = from del in deliveryResponse.Deliveries where IsValidDelivery(del.IssueDate, destinationDocument.IssueDate) == true orderby del.IncomeDate ascending select del; decimal originalAvailableQuantity = deliveryResponse.AvailableQuantity; decimal quantityToGo = line.Quantity; while (quantityToGo > 0) { if (sortedDeliveries.Count() == 0) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(line.ItemId); throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + this.warehouseName); } else { DeliveryResponse.SingleDelivery del = sortedDeliveries.First(); if (del.Quantity >= quantityToGo) { //tworzymy linie na dokumencie docelowym WarehouseDocumentLine dstLine = destinationDocument.Lines.CreateNew(); dstLine.ItemId = line.ItemId; dstLine.OutcomeDate = destinationDocument.IssueDate; dstLine.Price = line.Price; dstLine.Quantity = quantityToGo; dstLine.UnitId = line.UnitId; dstLine.WarehouseId = destinationDocument.WarehouseId; IncomeOutcomeRelation rel = dstLine.IncomeOutcomeRelations.CreateNew(BusinessObjectStatus.New, WarehouseDirection.Outcome); rel.Quantity = quantityToGo; rel.RelatedLine.Id = del.IncomeWarehouseDocumentLineId; rel.IncomeDate = del.IncomeDate; dstLine.IncomeDate = rel.IncomeDate; del.Quantity -= quantityToGo; deliveryResponse.AvailableQuantity -= quantityToGo; quantityToGo = 0; if (del.Quantity == 0) { rel.OutcomeDate = line.OutcomeDate; deliveryResponse.Deliveries.Remove(del); } } else //del.Quantity < quantityToGo { //tworzymy linie na dokumencie docelowym WarehouseDocumentLine dstLine = destinationDocument.Lines.CreateNew(); dstLine.ItemId = line.ItemId; dstLine.OutcomeDate = destinationDocument.IssueDate; dstLine.Price = line.Price; dstLine.Quantity = del.Quantity; dstLine.UnitId = line.UnitId; dstLine.WarehouseId = destinationDocument.WarehouseId; IncomeOutcomeRelation rel = dstLine.IncomeOutcomeRelations.CreateNew(BusinessObjectStatus.New, WarehouseDirection.Outcome); rel.OutcomeDate = dstLine.OutcomeDate; rel.IncomeDate = del.IncomeDate; dstLine.IncomeDate = rel.IncomeDate; rel.Quantity = del.Quantity; deliveryResponse.AvailableQuantity -= del.Quantity; rel.RelatedLine.Id = del.IncomeWarehouseDocumentLineId; quantityToGo -= del.Quantity; deliveryResponse.Deliveries.Remove(del); } } } //W sytuacji gdy MM- realizuje zamówienie, opcja, która nada odpowiednie powiązanie jest wykonywana po tej metodzie. Dlatego sprawdzane jest tu czy taka opcja jest xml zawarta a potem relacja zostanie dodana if ((!destinationDocument.DoesRealizeOrder || destinationDocument.SkipReservedQuantityCheck) && deliveryResponse.AvailableQuantity < 0) { WarehouseDocumentLine altLine = line.AlternateVersion as WarehouseDocumentLine; if (altLine == null || altLine.Quantity - originalAvailableQuantity < deliveryResponse.AvailableQuantity) { string itemName = DependencyContainerManager.Container.Get <ItemMapper>().GetItemName(line.ItemId); throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + this.warehouseName); } } } }