예제 #1
0
        private void ExecuteCustomLogic(FinancialDocument document)
        {
            List <Guid> salesOrders = new List <Guid>();

            foreach (var payment in document.Payments)
            {
                if (payment.SalesOrderId != null)
                {
                    var relation = document.Relations.CreateNew(BusinessObjectStatus.New);
                    relation.RelationType    = DocumentRelationType.SalesOrderToOutcomeFinancialDocument;
                    relation.RelatedDocument = new CommercialDocument()
                    {
                        Id = payment.SalesOrderId.Value
                    };
                    relation.DecimalValue = payment.Amount;

                    if (!salesOrders.Contains(payment.SalesOrderId.Value))
                    {
                        salesOrders.Add(payment.SalesOrderId.Value);
                        CommercialDocument salesOrder = (CommercialDocument)this.mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, payment.SalesOrderId.Value);

                        DuplicableAttributeFactory.DuplicateAttributes(salesOrder, document);
                    }
                }
            }

            this.MergePayments(document);
            this.CreateOrUpdateNegativePayment(document);
        }
예제 #2
0
        private static void AddShiftPosition(ServiceDocument serviceDocument, Guid sourceWarehouseId, Guid destinationWarehouseId, List <WarehouseDocument> shiftDocumentsList, Guid itemId, decimal quantity, Guid unitId)
        {
            WarehouseDocument shift = (from doc in shiftDocumentsList
                                       where doc.WarehouseId == sourceWarehouseId &&
                                       doc.Attributes.Children.Where(a => a.DocumentFieldName == DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId)
                                       .First().Value.Value.ToUpperInvariant() == destinationWarehouseId.ToUpperString()
                                       select doc).FirstOrDefault();

            if (shift == null) //tworzymy takiego szifta
            {
                using (DocumentCoordinator c = new DocumentCoordinator(false, false))
                {
                    string processType = serviceDocument.Attributes[DocumentFieldName.Attribute_ProcessType].Value.Value;
                    string template    = ProcessManager.Instance.GetDocumentTemplate(serviceDocument, "outcomeShift");
                    shift = (WarehouseDocument)c.CreateNewBusinessObject(BusinessObjectType.WarehouseDocument, template, null);
                    ProcessManager.Instance.AppendProcessAttributes(shift, processType, "outcomeShift", serviceDocument.Id, DocumentRelationType.ServiceToOutcomeShift);
                    DuplicableAttributeFactory.DuplicateAttributes(serviceDocument, shift);
                    serviceDocument.AddRelatedObject(shift);
                    shiftDocumentsList.Add(shift);
                    shift.WarehouseId = sourceWarehouseId;
                    var dstWarehouseId = shift.Attributes[DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId];

                    if (dstWarehouseId == null)
                    {
                        dstWarehouseId = shift.Attributes.CreateNew();
                        dstWarehouseId.DocumentFieldName = DocumentFieldName.ShiftDocumentAttribute_OppositeWarehouseId;
                    }

                    dstWarehouseId.Value.Value = destinationWarehouseId.ToUpperString();
                }
            }

            //sprawdzamy czy moze juz jest pozycja na ten sam towar. jak jest to edytujemy quantity, jak nie to tworzymy nowa
            WarehouseDocumentLine line = shift.Lines.Children.Where(l => l.ItemId == itemId).FirstOrDefault();

            if (line == null)
            {
                line        = shift.Lines.CreateNew();
                line.ItemId = itemId;
                line.UnitId = unitId;
            }

            line.Quantity += quantity;
        }
예제 #3
0
        /// <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);
                }
            }
        }
예제 #4
0
        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;
                    }
                }
            }
        }