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 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 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 GetExplanation(List <ItemReleaseModel> item, IInvoiceForm invoiceForm) { var notes = string.Join("; ", item.Where(it => !string.IsNullOrWhiteSpace(it.Descriptor.StockEventNote)) .Select(it => it.Descriptor.StockEventNote).Distinct()); if (!string.IsNullOrWhiteSpace(notes)) { notes = $" ({notes})"; } return($"{item[0].Descriptor.StockEventTypeName} ze šarže {item[0].Descriptor.Event.Batch.GetUnid()}{notes}"); }
public Form GetRenderer(IInvoiceForm form) { var rendererName = form.FormType.GeneratorName; if (rendererName.Equals("ReceivingInvoice", StringComparison.InvariantCultureIgnoreCase)) { return(new ReceivingInvoiceFormRenderer(form, m_culture)); } else if (rendererName.Equals("ReleasingForm", StringComparison.InvariantCultureIgnoreCase)) { return(new ReleasingInvoiceFormRenderer(form, m_culture)); } throw new InvalidOperationException($"Cannot find renderer by InvoiceFormType.GeneratorName = '{rendererName}'"); }
private void ManageSourceCurrency <T>(T itemModel, IInvoiceForm form) where T : InvoiceFormModelBase { ICurrency sourceCurrency = null; ICurrencyRate rateInfo = null; foreach (var item in form.Items) { if (sourceCurrency == null) { sourceCurrency = item.SourceCurrency; } if ((sourceCurrency?.Id ?? -1) != (item.SourceCurrencyId ?? -1)) { throw new InvalidOperationException($"Faktura {form.InvoiceNumber} má položky v různých měnách, nelze zpracovat"); } if (rateInfo == null) { rateInfo = item.Conversion?.CurrencyRate; } if ((rateInfo?.Id ?? -1) != (item.Conversion?.CurrencyRate?.Id ?? -1)) { throw new InvalidOperationException($"Faktura {form.InvoiceNumber} má položky v cizí měně, které byly převedeny za použití různých měnových kurzů, nelze zpracovat"); } } if (sourceCurrency == null) { return; } if (rateInfo == null) { throw new InvalidOperationException($"Pro fakturu {form.InvoiceNumber} chybi informace o prevodnim kurzu, nelze zpracovat"); } var sum = form.Items.Sum(i => i.SourceCurrencyPrice ?? 0); itemModel.OriginalCurrencyPriceValue = sum; itemModel.OriginalCurrencyPrice = StringUtil.FormatDecimal(sum); itemModel.ConversionRateValue = rateInfo.Rate; itemModel.ConversionRate = StringUtil.FormatDecimal(rateInfo.Rate); itemModel.ConversionRateLink = rateInfo.SourceLink; itemModel.OriginalCurrencySymbol = sourceCurrency.Symbol; }
public IInvoiceFormItem NewItem(IInvoiceForm form, int materialBatchId, Action <IInvoiceFormItem> setup) { using (var tx = m_database.OpenTransaction()) { var item = m_database.New <IInvoiceFormItem>(); item.InvoiceFormId = form.Id; setup(item); m_database.Save(item); var bridge = m_database.New <IInvoiceFormItemMaterialBatch>(); bridge.MaterialBatchId = materialBatchId; bridge.InvoiceFormItemId = item.Id; m_database.Save(bridge); tx.Commit(); return(item); } }
protected virtual void CustomizeFormCreation(List <ItemReleaseModel> formItems, IInvoiceForm form) { }
protected abstract string GetExplanation(List <ItemReleaseModel> item, IInvoiceForm invoiceForm);
protected override string GetExplanation(List <ItemReleaseModel> item, IInvoiceForm invoiceForm) { return($"Objednávka č.: {item[0].Descriptor.OrderIdentifierText}"); }
protected override string GetExplanation(List <ItemReleaseModel> item, IInvoiceForm invoiceForm) { return($"Výroba šarže {item[0].Descriptor.CompositionBatchText}"); }
protected abstract void CustomizeFormMapping(IMaterialBatch referenceBatch, IInvoiceForm form, IInvoiceFormGenerationContext context);
protected abstract void CustomizeItemMapping(IInvoiceForm form, IInvoiceFormItem item, IMaterialBatch batch, IInvoiceFormGenerationContext context);
protected override void CustomizeFormMapping(IMaterialBatch referenceBatch, IInvoiceForm form, IInvoiceFormGenerationContext context) { }
public ReceivingInvoiceFormRenderer(IInvoiceForm form, CultureInfo culture) { m_form = form; m_culture = culture; }
protected override void CustomizeFormCreation(List <ItemReleaseModel> formItems, IInvoiceForm form) { form.InvoiceVarSymbol = formItems.Select(fi => fi.Descriptor.OrderInvoiceVarSymbol) .FirstOrDefault(vs => !string.IsNullOrWhiteSpace(vs)) ?? string.Empty; }
protected virtual void OnAfterItemSaved(IInvoiceForm form, IInvoiceFormItem item, ItemReleaseModel releaseModel) { }
protected override string GetExplanation(List <ItemReleaseModel> item, IInvoiceForm invoiceForm) { return(item[0].Descriptor.Event.Name); }
protected override string GetExplanation(List <ItemReleaseModel> item, IInvoiceForm invoiceForm) { return($"Vratka objednávky č.: {item[0].Descriptor.OrderNumber}"); }
public IInvoiceForm SaveInvoiceForm(IInvoiceForm invoice, List <IInvoiceFormItem> items, List <KeyValuePair <IInvoiceFormItem, int> > itemBatchId) { int invoiceId = 0; using (var tx = m_database.OpenTransaction()) { var it = GetInvoiceFormType(invoice.FormTypeId); if (it == null) { throw new InvalidOperationException("Cannot save InvoiceForm without type"); } if (it.SystemCounterId == null) { throw new InvalidOperationException("Cannot save InvoiceForm of type without reference to counter"); } invoice.ProjectId = m_session.Project.Id; if (string.IsNullOrWhiteSpace(invoice.InvoiceFormNumber)) { m_countersManager.WithCounter(it.SystemCounterId.Value, ifnr => { invoice.InvoiceFormNumber = ifnr; m_database.Save(invoice); }); } else { m_database.Save(invoice); } invoiceId = invoice.Id; var existingItemBatches = m_database.SelectFrom <IInvoiceFormItem>().Join(i => i.Batches) .Where(i => i.InvoiceFormId == invoice.Id).Execute().ToList(); foreach (var invoiceFormItem in items) { invoiceFormItem.InvoiceFormId = invoice.Id; m_database.Save(invoiceFormItem); var batches = itemBatchId.Where(ib => ib.Key == invoiceFormItem).ToList(); foreach (var batch in batches) { var alreadyExists = existingItemBatches.Any(itm => (itm.Id == invoiceFormItem.Id) && itm.Batches.Any(itb => itb.MaterialBatchId == batch.Value)); if (alreadyExists) { continue; } var bridge = m_database.New <IInvoiceFormItemMaterialBatch>(b => { b.InvoiceFormItemId = invoiceFormItem.Id; b.MaterialBatchId = batch.Value; }); m_database.Save(bridge); } } tx.Commit(); } return(GetInvoiceFormById(invoiceId)); }
public IInvoiceFormItem NewFormItem(IInvoiceForm form, IMaterialBatch batch, Action <IInvoiceFormItem> setup) { return(m_invoiceFormsRepository.NewItem(form, batch.Id, setup)); }
protected override void CustomizeFormCreation(List <ItemReleaseModel> formItems, IInvoiceForm form) { if (formItems[0].Descriptor.Event.Type.InvoiceFormNumberCounterId == null) { throw new InvalidOperationException($"No InvoiceFormNumberCounterId defined for StockEventType = {formItems[0].Descriptor.Event.Type.Name}"); } form.Text = formItems[0].Descriptor.StockEventTypeName; form.CounterId = formItems[0].Descriptor.Event.Type.InvoiceFormNumberCounterId; }