Exemplo n.º 1
0
        public BatchEventAmountSuggestions GetEventAmountSuggestions(int eventTypeId, int batchId)
        {
            var eventType = m_stockEventRepository.GetAllEventTypes().FirstOrDefault(e => e.Id == eventTypeId);

            if (eventType == null)
            {
                return(null);
            }

            var batch = m_batchRepository.GetBatchById(batchId);

            if (batch == null)
            {
                return(null);
            }

            var available = GetAvailableAmount(batchId);

            var suggestion = new BatchEventAmountSuggestions(batchId, eventTypeId, available.Value, batch.ComponentUnit.IntegerOnly);

            if (batch.ComponentUnit.IntegerOnly)
            {
                suggestion.AddSuggestion(new Amount(1, batch.ComponentUnit));
                suggestion.AddSuggestion(new Amount(5, batch.ComponentUnit));
                suggestion.AddSuggestion(new Amount(10, batch.ComponentUnit));
                suggestion.AddSuggestion(new Amount(100, batch.ComponentUnit));
            }

            suggestion.AddSuggestion(available);

            return(suggestion);
        }
Exemplo n.º 2
0
        private void PopulateStockEventSuggestions(BatchReportEntry batchReportEntry)
        {
            if (batchReportEntry.Available?.IsNotPositive ?? true)
            {
                return;
            }

            Func <IStockEventType, Amount, BatchStockEventSuggestion> addSuggestion = (type, amount) =>
            {
                var manipulationAmount = m_amountProcessor.ToSmallestUnit(amount);

                var sug = new BatchStockEventSuggestion()
                {
                    BatchNumber  = batchReportEntry.BatchNumber,
                    Amount       = manipulationAmount.Value,
                    EventTypeId  = type.Id,
                    MaterialId   = batchReportEntry.MaterialId,
                    MaterialName = batchReportEntry.MaterialName,
                    UnitSymbol   = manipulationAmount.Unit.Symbol,
                    Title        = $"{type.Name} {StringUtil.FormatDecimal(amount.Value)} {amount.Unit.Symbol}"
                };

                batchReportEntry.EventSuggestions.Add(sug);

                return(sug);
            };

            foreach (var eventType in m_stockEventRepository.GetAllEventTypes())
            {
                if (batchReportEntry.Available.Unit.IntegerOnly)
                {
                    addSuggestion(eventType, new Amount(1m, batchReportEntry.Available.Unit));
                }

                addSuggestion(eventType, batchReportEntry.Available);
            }
        }
Exemplo n.º 3
0
        private void ProcessReturns()
        {
            try
            {
                m_log.Info("Zacinam zpracovavat vracene objednavky");

                var ordids = new List <long>();
                m_database.Sql().ExecuteWithParams(@"select distinct po.Id
                                                          from PurchaseOrder po
                                                          inner join OrderItem     oi ON (oi.PurchaseOrderId = po.Id)
                                                          left join  OrderItem     ki ON (ki.KitParentId = oi.Id)
                                                          inner join OrderItemMaterialBatch omb ON (omb.OrderItemId = ISNULL(ki.Id, oi.Id))
                                                        where po.ProjectId = {0}
                                                          and po.ReturnDt is not null
                                                          and not exists(select top 1 1
                                                                           from MaterialStockEvent evt
				                                                           join StockEventType st on evt.TypeId = st.Id
				                                                           where evt.SourcePurchaseOrderId = po.Id)"                , m_session.Project.Id).ReadRows <long>(ordids.Add);

                if (!ordids.Any())
                {
                    m_log.Info("Zadne vratky");
                    return;
                }

                var targetEventType = m_stockEventRepository.GetAllEventTypes()
                                      .FirstOrDefault(e => e.GenerateForReturnedOrders == true);

                if (targetEventType == null)
                {
                    m_log.Info("Neni zadny StockEventType.GenerateForReturnedOrders");
                    return;
                }

                foreach (var ordid in ordids)
                {
                    try
                    {
                        using (var tx = m_database.OpenTransaction())
                        {
                            var order = m_purchaseOrderRepository.GetOrder(ordid);

                            m_log.Info($"Generuji odpis pro vracenou objednavku {order.OrderNumber}");

                            m_stockEventRepository.MoveOrderToEvent(ordid, targetEventType.Id,
                                                                    $"Vráceno z objednávky {order.OrderNumber}");

                            tx.Commit();
                        }

                        m_log.Info("Hotovo");
                    }
                    catch (Exception ex)
                    {
                        m_log.Error($"Chyba pri zpracovani vratky pro objednavku ID = {ordid}", ex);
                    }
                }
            }
            catch (Exception ex)
            {
                m_log.Error("Chyba pri zpracovani vratek", ex);
            }
        }
Exemplo n.º 4
0
 public IEnumerable <IStockEventType> GetEventTypes()
 {
     return(m_eventRepository.GetAllEventTypes());
 }