private bool CheckForQuantityBelowRelated(WarehouseDocument document)
        {
            bool outcomeCorrectionNeeded = false;
            WarehouseItemQuantityDictionary whItemDict       = new WarehouseItemQuantityDictionary();
            List <DeliveryRequest>          deliveryRequests = new List <DeliveryRequest>();

            foreach (WarehouseDocumentLine line in document.Lines.Children)
            {
                decimal relatedQuantity = ((WarehouseDocumentLine)line.AlternateVersion).IncomeOutcomeRelations.Children.Sum(s => s.Quantity);

                if (relatedQuantity > 0)
                {
                    outcomeCorrectionNeeded = true;
                }

                /*
                 * if (line.Quantity < relatedQuantity)
                 * {
                 *  string unit = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetUnit(line.UnitId)).Attribute("symbol").Value;
                 *  throw new ClientException(ClientExceptionId.WarehouseCorrectionError4, null,
                 *      "itemName:" + line.ItemName,
                 *      "count:" + relatedQuantity.ToString("G", CultureInfo.CreateSpecificCulture("pl-PL")),
                 *      "unit:" + unit);
                 * }*///to byla dawna walidacja zeby nie moznabylo korygowac ponizej wartosci rozchodowanej. teraz jest ona inna bo mozna, ale nie mozna zejsc globalnie z towarem ponizej zera

                decimal differentialQuantity = line.Quantity - ((WarehouseDocumentLine)line.AlternateVersion).Quantity;

                whItemDict.Add(document.WarehouseId, line.ItemId, differentialQuantity);

                DeliveryRequest delivery = deliveryRequests.Where(d => d.ItemId == line.ItemId && d.WarehouseId == line.WarehouseId).FirstOrDefault();

                if (delivery == null)
                {
                    deliveryRequests.Add(new DeliveryRequest(line.ItemId, line.WarehouseId, line.UnitId));
                }
            }

            //pobieramy dostawy
            ICollection <DeliveryResponse> deliveryResponses = this.mapper.GetDeliveries(deliveryRequests);

            //iterujemy po naszym slowniku i sprawdzamy czy ilosci sa na stanie
            if (whItemDict.Dictionary.ContainsKey(document.WarehouseId))
            {
                var dctItemQuantity = whItemDict.Dictionary[document.WarehouseId];

                foreach (var key in dctItemQuantity.Keys)                 //iterujemy po itemId
                {
                    var delivery = deliveryResponses.Where(d => d.ItemId == key).First();

                    if (delivery.QuantityInStock - Math.Abs(dctItemQuantity[key]) < 0)
                    {
                        //wyciagamy nazwe towaru
                        string itemName      = document.Lines.Where(l => l.ItemId == delivery.ItemId).First().ItemName;
                        string warehouseName = BusinessObjectHelper.GetBusinessObjectLabelInUserLanguage(DictionaryMapper.Instance.GetWarehouse(document.WarehouseId)).Value;
                        throw new ClientException(ClientExceptionId.NoItemInStock, null, "itemName:" + itemName, "warehouseName:" + warehouseName);
                    }
                }
            }

            return(outcomeCorrectionNeeded);
        }
예제 #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);
        }