Exemplo n.º 1
0
 protected override void CustomizeFormItemCreation(ItemReleaseModel releaseModel, IInvoiceFormItem item)
 {
     if (!string.IsNullOrWhiteSpace(releaseModel.Descriptor.Event.Note))
     {
         item.Note = releaseModel.Descriptor.Event.Note;
     }
 }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
 protected abstract string GetGroupingKey(ItemReleaseModel item);
Exemplo n.º 4
0
 protected virtual Tuple <decimal, BatchPrice> GetPrice(ItemReleaseModel item, IInvoiceFormGenerationContext context)
 {
     return(m_batchFacade.GetPriceOfAmount(item.TookFromBatch, item.TookAmount, context));
 }
Exemplo n.º 5
0
 protected virtual void OnAfterItemSaved(IInvoiceForm form, IInvoiceFormItem item, ItemReleaseModel releaseModel)
 {
 }
Exemplo n.º 6
0
 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}");
 }
Exemplo n.º 9
0
 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;
     }));
 }
Exemplo n.º 10
0
 protected override string GetGroupingKey(ItemReleaseModel item)
 {
     return($"{item.Date}:{item.Descriptor.StockEventTypeName}:{item.Descriptor.Event.Batch.Id}");
 }
Exemplo n.º 11
0
 protected override string GetGroupingKey(ItemReleaseModel item)
 {
     return(item.Descriptor.Event.Id.ToString());
 }
Exemplo n.º 12
0
 protected override string GetGroupingKey(ItemReleaseModel item)
 {
     return(item.Descriptor.OrderNumber);
 }
Exemplo n.º 13
0
 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;
     }));
 }
Exemplo n.º 14
0
 protected override string GetGroupingKey(ItemReleaseModel item)
 {
     return(item.Descriptor.OrderIdentifierText);
 }