public Invoice( InvoiceNumber number, DateTime issueDate, DateTime paymentDate, SupplierInfo supplierInfo, CustomerInfo customerInfo, CurrencyCode currencyCode, ISequentialEnumerable <InvoiceItem> items, bool isSelfBilling = false, bool isCashAccounting = false) { Number = number; IssueDate = issueDate; PaymentDate = paymentDate; SupplierInfo = supplierInfo; CustomerInfo = customerInfo; CurrencyCode = currencyCode; Items = items; DeliveryDate = Items.Max(i => i.Item.ConsumptionDate); ExchangeRate = GetExchangeRate(items); TaxSummary = GetTaxSummary(items); IsSelfBilling = isSelfBilling; IsCashAccounting = isCashAccounting; CheckConsistency(this); }
private static IEnumerable <Dto.LineType> MapItems(ISequentialEnumerable <InvoiceItem> items, int?modificationIndexOffset = null) { return(items.Select(i => new Dto.LineType { lineNumber = i.Index.ToString(), lineDescription = i.Item.Description.Value, quantity = i.Item.Quantity, unitOfMeasureOwn = i.Item.MeasurementUnit.ToString(), unitPrice = i.Item.UnitAmounts.Amount.Net.Value, unitPriceHUF = i.Item.UnitAmounts.AmountHUF.Net.Value, quantitySpecified = true, unitOfMeasureSpecified = true, unitPriceSpecified = true, unitPriceHUFSpecified = true, depositIndicator = i.Item.IsDeposit, Item = MapLineAmounts(i.Item), aggregateInvoiceLineData = new Dto.AggregateInvoiceLineDataType { lineExchangeRateSpecified = true, lineExchangeRate = i.Item.ExchangeRate?.Value ?? 0m, lineDeliveryDate = i.Item.ConsumptionDate }, lineModificationReference = modificationIndexOffset.HasValue ? GetLineModificationReference(i, modificationIndexOffset.Value) : null })); }
public static Dto.Xsd.InvoicesDoc GetInvoiceDoc(ISequentialEnumerable <Invoice> invoices) { return(new Dto.Xsd.InvoicesDoc { Invoices = invoices.Values.Select(invoice => GetInvoice(invoice)).ToArray() }); }
public InvoiceDocument(ISequentialEnumerable <Invoice> invoices) { Invoices = invoices ?? throw new ArgumentNullException(nameof(invoices)); if (invoices.Count() == 0) { throw new ArgumentException($"Minimal count of {nameof(invoices)} is 1."); } }
private List <TaxSummaryItem> GetTaxSummary(ISequentialEnumerable <InvoiceItem> indexedItems) { var itemsByTaxRate = indexedItems.Items.GroupBy(i => i.TotalAmounts.TaxRatePercentage); var taxSummaryItems = itemsByTaxRate.Select(g => new TaxSummaryItem( taxRatePercentage: g.Key, amount: Amount.Sum(g.Select(i => i.TotalAmounts.Amount)), amountHUF: Amount.Sum(g.Select(i => i.TotalAmounts.AmountHUF)) )); return(taxSummaryItems.AsList()); }
private ExchangeRate GetExchangeRate(ISequentialEnumerable <InvoiceItem> indexedItems) { var totalGrossHuf = indexedItems.Items.Sum(i => Math.Abs(i.TotalAmounts.AmountHUF.Gross.Value)); var totalGross = indexedItems.Items.Sum(i => Math.Abs(i.TotalAmounts.Amount.Gross.Value)); if (totalGross != 0) { return(ExchangeRate.Rounded(totalGrossHuf / totalGross)); } return(new ExchangeRate(1)); }
public ModificationInvoice( InvoiceNumber number, int modificationIndex, int itemIndexOffset, InvoiceNumber originalDocumentNumber, DateTime issueDate, DateTime paymentDate, SupplierInfo supplierInfo, CustomerInfo customerInfo, CurrencyCode currencyCode, ISequentialEnumerable <InvoiceItem> items, bool isSelfBilling = false, bool isCashAccounting = false, bool modifyWithoutMaster = false) : base(number, issueDate, paymentDate, supplierInfo, customerInfo, currencyCode, items, isSelfBilling, isCashAccounting) { OriginalDocumentNumber = originalDocumentNumber; ModificationIndex = modificationIndex; ItemIndexOffset = itemIndexOffset; ModifyWithoutMaster = modifyWithoutMaster; }
private async Task <ResponseResult <string, ResultErrorCode> > ManageInvoicesAsync <TDocument>(Dto.ManageInvoiceRequest request, ISequentialEnumerable <TDocument> invoices) { if (invoices.Count > ServiceInfo.MaxInvoiceBatchSize) { throw new ArgumentException($"Max invoice batch size ({ServiceInfo.MaxInvoiceBatchSize}) exceeded.", nameof(invoices)); } if (invoices.StartIndex != 1) { throw new ArgumentException("Items need to be indexed from 1.", nameof(invoices)); } return(await Client.ProcessRequestAsync <Dto.ManageInvoiceRequest, Dto.ManageInvoiceResponse, string, ResultErrorCode>( endpoint : "manageInvoice", request : request, successFunc : response => ModelMapper.MapManageInvoice(response) ).ConfigureAwait(continueOnCapturedContext: false)); }
public async Task <ResponseResult <string, ResultErrorCode> > SendModificationDocumentsAsync(ExchangeToken token, ISequentialEnumerable <ModificationInvoice> invoices) { var request = RequestCreator.CreateManageInvoicesRequest(TechnicalUser, SoftwareIdentification, token, invoices); return(await ManageInvoicesAsync(request, invoices)); }
private static Dto.ManageInvoiceRequest CreateManageInvoicesRequest <T>(TechnicalUser user, SoftwareIdentification software, ExchangeToken token, Dto.ManageInvoiceOperationType operation, ISequentialEnumerable <T> invoices, Func <T, Dto.InvoiceData> mapper) { var operations = invoices.Select(item => new Dto.InvoiceOperationType { index = item.Index, invoiceData = Encoding.UTF8.GetBytes(XmlManipulator.Serialize(mapper(item.Item))), invoiceOperation = operation }); var invoiceHashes = operations.Select(t => Sha512.GetSha3Hash($"{t.invoiceOperation}{Convert.ToBase64String(t.invoiceData)}")); var invoiceSignatureData = string.Join("", invoiceHashes); var request = CreateRequest <Dto.ManageInvoiceRequest>(user, software, invoiceSignatureData); request.exchangeToken = Encoding.UTF8.GetString(token.Value); request.invoiceOperations = new Dto.InvoiceOperationListType { compressedContent = false, invoiceOperation = operations.ToArray() }; return(request); }
internal static Dto.ManageInvoiceRequest CreateManageInvoicesRequest(TechnicalUser user, SoftwareIdentification software, ExchangeToken token, ISequentialEnumerable <ModificationInvoice> invoices) { return(CreateManageInvoicesRequest(user, software, token, Dto.ManageInvoiceOperationType.MODIFY, invoices, d => RequestMapper.MapModificationInvoice(d))); }