Exemple #1
0
        public static bool TryCloseSalesOrder(CommercialDocument salesOrder)
        {
            if (salesOrder.DocumentType.DocumentCategory != DocumentCategory.SalesOrder)
            {
                return(false);
            }
            DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>();

            mapper.AddItemsToItemTypesCache(salesOrder);
            var dict = SessionManager.VolatileElements.ItemTypesCache;

            //sprawdzamy czy zamowienie ma wszelkie wz-ty i rw na pozycjach z towarami (pomijamy uslugi)
            foreach (var line in salesOrder.Lines)
            {
                if (!DictionaryMapper.Instance.GetItemType(dict[line.ItemId]).IsWarehouseStorable)
                {
                    continue;
                }

                decimal relQuantity = line.CommercialWarehouseRelations.Sum(r => r.Quantity);

                if (line.Quantity != relQuantity)
                {
                    return(false);
                }
            }

            SalesOrderFactory.CloseSalesOrder(salesOrder);
            salesOrder.DocumentStatus = DocumentStatus.Committed;

            return(true);
        }