Ejemplo n.º 1
0
        public static void GenerateShifts(ServiceDocument document, WarehouseItemQuantityDictionary dctWarehouseItemIdQuantity)
        {
            ServiceDocument          alternateDocument  = document.AlternateVersion as ServiceDocument;
            Guid                     serviceWarehouseId = ProcessManager.Instance.GetServiceWarehouse(document);
            List <WarehouseDocument> shiftDocumentsList = new List <WarehouseDocument>();

            foreach (Guid warehouseId in dctWarehouseItemIdQuantity.Dictionary.Keys)
            {
                foreach (Guid itemId in dctWarehouseItemIdQuantity.Dictionary[warehouseId].Keys)
                {
                    decimal quantity = dctWarehouseItemIdQuantity.Dictionary[warehouseId][itemId];
                    var     line     = document.Lines.Children.Where(l => l.ItemId == itemId).FirstOrDefault();

                    if (line == null)
                    {
                        line = alternateDocument.Lines.Children.Where(l => l.ItemId == itemId).FirstOrDefault();
                    }

                    if (quantity > 0) //robimy przelew do serviceWarehouse
                    {
                        ServiceDocumentLogic.AddShiftPosition(document, warehouseId, serviceWarehouseId, shiftDocumentsList, itemId, quantity, line.UnitId);
                    }
                    else if (quantity < 0) //robimy przelew do magazynu wskazanego przez warehouseId
                    {
                        ServiceDocumentLogic.AddShiftPosition(document, serviceWarehouseId, warehouseId, shiftDocumentsList, itemId, -quantity, line.UnitId);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ProcessDocumentsGeneration(ServiceDocument document)
        {
            if (document.DocumentStatus == DocumentStatus.Canceled)
            {
                return;
            }

            //przelatujemy po liniach i porownujemy z alternate version co sie zmienilo
            //slowniki w ktorych bedziemy bilansowac
            WarehouseItemQuantityDictionary dctWarehouseItemIdQuantity = new WarehouseItemQuantityDictionary();

            this.mapper.AddItemsToItemTypesCache(document);
            IDictionary <Guid, Guid> cache = SessionManager.VolatileElements.ItemTypesCache;

            foreach (CommercialDocumentLine line in document.Lines.Children)
            {
                Guid     itemTypeId = cache[line.ItemId];
                ItemType itemType   = DictionaryMapper.Instance.GetItemType(itemTypeId);

                if (!itemType.IsWarehouseStorable)
                {
                    continue;
                }

                DocumentLineAttrValue attr = line.Attributes[DocumentFieldName.LineAttribute_GenerateDocumentOption];

                if (attr.Value.Value != "2" && attr.Value.Value != "4") //czyli opcja ze NIE generujemy MMki
                {
                    continue;
                }

                dctWarehouseItemIdQuantity.Add(line.WarehouseId.Value, line.ItemId, line.Quantity);
            }

            ServiceDocument alternateDocument = document.AlternateVersion as ServiceDocument;

            if (alternateDocument != null)
            {
                this.mapper.AddItemsToItemTypesCache(alternateDocument);
                cache = SessionManager.VolatileElements.ItemTypesCache;

                foreach (CommercialDocumentLine line in alternateDocument.Lines.Children)
                {
                    Guid     itemTypeId = cache[line.ItemId];
                    ItemType itemType   = DictionaryMapper.Instance.GetItemType(itemTypeId);

                    if (!itemType.IsWarehouseStorable)
                    {
                        continue;
                    }

                    DocumentLineAttrValue attr = line.Attributes[DocumentFieldName.LineAttribute_GenerateDocumentOption];

                    if (attr.Value.Value != "2" && attr.Value.Value != "4") //czyli opcja ze NIE generujemy MMki
                    {
                        continue;
                    }

                    dctWarehouseItemIdQuantity.Subtract(line.WarehouseId.Value, line.ItemId, line.Quantity);
                }
            }

            //teraz majac zbilansowane wszystko ladnie co sie zmienilo przystepujemy do generacji MMek.
            //jezeli cos sie zmienilo na plus to oznacza ze musimy z danego warehouseId przesunac na serviceWarehouse podana ilosc
            //jezeli cos sie zmienilo na minus to oznacza ze z serviceWarehouse musimy przesunac na ten magazyn

            ServiceDocumentLogic.GenerateShifts(document, dctWarehouseItemIdQuantity);
        }