public async Task <FileStream> CreateAndStoreDepositInvoiceDocumentAsync(int depositInvoiceId, string language)
        {
            var includeQuery = new QuerySet();

            includeQuery.Include.Fields = new string[] {
                "customer", "contact", "building", "order", "vat-rate"
            };
            var depositInvoice = await _depositInvoiceDateProvider.GetByIdAsync(depositInvoiceId, includeQuery);

            string visitorInitials = null;

            if (depositInvoice.Order != null)
            {
                var offerIncludeQuery = new QuerySet();
                offerIncludeQuery.Include.Fields = new string[] { "offerlines", "offerlines.vat-rate" };
                var offer = await _offerDataProvider.GetByIdAsync(depositInvoice.Order.Id, offerIncludeQuery); // offer and order have the same id

                depositInvoice.Order.Offer = offer;

                visitorInitials = await GetVisitorInitialsByOfferIdAsync(offer.Id);

                // Remove duplicated nested data before sending
                depositInvoice.Order.Customer       = null; depositInvoice.Order.Contact = null; depositInvoice.Order.Building = null;
                depositInvoice.Order.Deposits       = null; depositInvoice.Order.DepositInvoices = null;
                depositInvoice.Order.Offer.Customer = null; depositInvoice.Order.Offer.Contact = null;
                depositInvoice.Order.Offer.Building = null; depositInvoice.Order.Offer.Order = null;
            }

            // Remove duplicated nested data before sending
            depositInvoice.Customer.Offers = Enumerable.Empty <Offer>();
            depositInvoice.Customer.Orders = Enumerable.Empty <Order>();

            await EmbedCustomerAndContactTelephonesAsync(depositInvoice);

            dynamic documentData = new ExpandoObject();

            documentData.Invoice  = depositInvoice;
            documentData.Visitor  = visitorInitials;
            documentData.language = language;

            var url      = $"{_documentGenerationConfig.BaseUrl}/documents/deposit-invoice";
            var filePath = ConstructInvoiceDocumentFilePath(depositInvoice);

            return(await GenerateAndStoreDocumentAsync(url, documentData, filePath));
        }
Exemple #2
0
 public async Task <DepositInvoice> GetByIdAsync(int id, QuerySet query)
 {
     return(await _depositInvoiceDataProvider.GetByIdAsync(id, query));
 }