protected override void CustomizeFormItemCreation(ItemReleaseModel releaseModel, IInvoiceFormItem item) { if (!string.IsNullOrWhiteSpace(releaseModel.Descriptor.Event.Note)) { item.Note = releaseModel.Descriptor.Event.Note; } }
public void Generate(IMaterialInventory forInventory, int year, int month, IInvoiceFormGenerationContext context, IReleasingFormsGenerationTask task = null) { var index = new Dictionary <string, List <ItemReleaseModel> >(); GenerateItems(forInventory, year, month, context, task, (time, batch, amount, descriptor) => { if (batch.IsHiddenForAccounting == true) { return; } var item = new ItemReleaseModel(time, batch, amount, descriptor); var key = GetGroupingKey(item); if (!index.TryGetValue(key, out var items)) { items = new List <ItemReleaseModel>(); index.Add(key, items); } item.Price = GetPrice(item, context); if (item.Price.Item2.HasWarning) { context.Warning($"Výpocet ceny šarže \"{item.TookFromBatch.GetTextInfo()}\" není konečný: {item.Price.Item2.Text}"); } items.Add(item); }); foreach (var key in index.Keys) { var list = index[key]; var totalPriceModel = BatchPrice.Combine(list.Select(i => i.Price.Item2)); var form = context.NewInvoiceForm(f => { f.InvoiceFormNumber = $"NESCHVALENO_{Guid.NewGuid():N}"; f.IssueDate = list[0].Date.Date; f.MaterialInventoryId = forInventory.Id; f.FormTypeId = FormType.Id; f.Text = task?.FormText ?? "?"; f.PriceCalculationLog = totalPriceModel.Text; f.PriceHasWarning = totalPriceModel.HasWarning; f.SourceTaskId = task?.Id; f.Explanation = GetExplanation(list, f); CustomizeFormCreation(list, f); }); foreach (var item in list) { var material = item.TookFromBatch.Material ?? m_materialRepository.GetMaterialById(item.TookFromBatch.MaterialId).Adaptee; var formItem = context.NewFormItem(form, item.TookFromBatch, i => { i.MaterialName = material.Name; i.Quantity = item.TookAmount.Value; i.UnitId = item.TookAmount.Unit.Id; i.PrimaryCurrencyPrice = item.Price.Item1; CustomizeFormItemCreation(item, i); }); OnAfterItemSaved(form, formItem, item); } } }
protected abstract string GetGroupingKey(ItemReleaseModel item);
protected virtual Tuple <decimal, BatchPrice> GetPrice(ItemReleaseModel item, IInvoiceFormGenerationContext context) { return(m_batchFacade.GetPriceOfAmount(item.TookFromBatch, item.TookAmount, context)); }
protected virtual void OnAfterItemSaved(IInvoiceForm form, IInvoiceFormItem item, ItemReleaseModel releaseModel) { }
protected virtual void CustomizeFormItemCreation(ItemReleaseModel releaseModel, IInvoiceFormItem item) { }
protected override void OnAfterItemSaved(IInvoiceForm form, IInvoiceFormItem item, ItemReleaseModel releaseModel) { if (releaseModel.Descriptor.BatchCompositionRecordId != null) { m_database.Save(m_database.New <IMaterialBatchCompositionFormItem>(i => { i.InvoiceFormItemId = item.Id; i.MaterialBatchCompositionId = releaseModel.Descriptor.BatchCompositionRecordId.Value; })); } }
protected override string GetGroupingKey(ItemReleaseModel item) { return($"{item.Date.Date}:{item.Descriptor.CompositionBatchText}"); }
protected override void OnAfterItemSaved(IInvoiceForm form, IInvoiceFormItem item, ItemReleaseModel releaseModel) { m_database.Save(m_database.New <IStockEventInvoiceFormItem>(b => { b.MaterialStockEventId = releaseModel.Descriptor.StockEventId; b.InvoiceFormItemId = item.Id; })); }
protected override string GetGroupingKey(ItemReleaseModel item) { return($"{item.Date}:{item.Descriptor.StockEventTypeName}:{item.Descriptor.Event.Batch.Id}"); }
protected override string GetGroupingKey(ItemReleaseModel item) { return(item.Descriptor.Event.Id.ToString()); }
protected override string GetGroupingKey(ItemReleaseModel item) { return(item.Descriptor.OrderNumber); }
protected override void OnAfterItemSaved(IInvoiceForm form, IInvoiceFormItem item, ItemReleaseModel releaseModel) { m_database.Save(m_database.New <IOrderItemInvoiceFormItem>(i => { i.InvoiceFormItemId = item.Id; i.BatchAssignmentId = releaseModel.Descriptor.OrderItemBatchAssignmentId; })); }
protected override string GetGroupingKey(ItemReleaseModel item) { return(item.Descriptor.OrderIdentifierText); }