protected override void GenerateItems(IMaterialInventory forInventory, int year, int month, IInvoiceFormGenerationContext context, IReleasingFormsGenerationTask task, Action <DateTime, IMaterialBatch, Amount, ReturnedOrderDescriptor> itemCallback) { if (!forInventory.CanBeConnectedToTag) { context.Info($"Pro sklad \"{forInventory.Name}\" se výdejky typu \"VRACENE OBJEDNAVKY\" negenerují - přeskakuji"); return; } var returns = m_orderRepository.GetReturns(month, year).ToList(); DateUtil.GetMonthDt(year, month, out var dtFrom, out var dtTo); foreach (var order in returns) { var allOrderItems = new List <IOrderItem>(); foreach (var orderItem in order.Items) { if (orderItem.AssignedBatches.Any()) { allOrderItems.Add(orderItem); } foreach (var kitChild in orderItem.KitChildren) { if (kitChild.AssignedBatches.Any()) { allOrderItems.Add(kitChild); } } } foreach (var item in allOrderItems) { foreach (var assignment in item.AssignedBatches) { //todo: may be neccessary to filter by batch inventory in the future var batchMaterial = m_materialRepository.GetMaterialById(assignment.MaterialBatch.MaterialId); itemCallback(order.ReturnDt ?? order.BuyDate, assignment.MaterialBatch, m_amountProcessor.Neg(new Amount(assignment.Quantity, batchMaterial.NominalUnit)), new ReturnedOrderDescriptor { OrderNumber = order.OrderNumber }); } } foreach (var connectedEvent in m_stockEventRepository.GetEvents(dtFrom, dtTo, order.Id)) { itemCallback(order.ReturnDt ?? order.BuyDate, connectedEvent.Batch, m_amountProcessor.Neg(new Amount(connectedEvent.Delta, connectedEvent.Unit)), new ReturnedOrderDescriptor { OrderNumber = order.OrderNumber }); } } }
private void ProcessResolutions(ProductionRequest request, IRecipeComponent recipeComponent, ProductionComponent requestComponent, decimal multiplier, DateTime sourceBatchesMadeBefore) { if (TryProcessTransformationInput(request, recipeComponent, requestComponent) && (!requestComponent.IsValid)) { return; } var requiredAmount = new Amount(recipeComponent.Amount * multiplier, m_unitRepository.GetUnit(recipeComponent.UnitId)); ClearUserAllocationsIfQuantityChanged(requestComponent, requiredAmount); var requiredBatchNr = recipeComponent.IsTransformationInput ? request.ProducingBatchNumber : null; var resolutions = m_batchFacade.ResolveMaterialDemand( recipeComponent.MaterialId, requiredAmount, requiredBatchNr, false, true, sourceBatchesMadeBefore, request.SourceSegmentId); RemoveComponentsNotProposedBySystem(requestComponent, resolutions, requiredAmount); AddMissingComponents(requestComponent, resolutions, requiredAmount, request.SourceSegmentId != null && request.IsFirstRound); var userAllocatedAmount = m_amountProcessor.Sum(requestComponent.Resolutions.Where(r => r.GetAmount(m_unitRepository) != null) .Select(r => r.GetAmount(m_unitRepository))) ?? new Amount(0, requiredAmount.Unit); var remaining = m_amountProcessor.Subtract(requiredAmount, userAllocatedAmount); if (!resolutions.CompletelyAllocated) { requestComponent.Invalidate("Potřebné množství není dostupné"); } if (remaining.IsPositive) { //seems we allocated the requested amount requestComponent.Invalidate($"Zbývá vložit {remaining}"); } else if (remaining.IsNegative) { requestComponent.Invalidate($"Přebývá {m_amountProcessor.Neg(remaining)}"); } }