Uniconta Report print offer/order PDF

Date: 2022-01-13
public async Task<UserDocsClient> CreateOfferReport(CrudAPI api, GiftProject giftProject)
{
    var order = ConvertProjectToOrder(giftProject);

    var invoiceParams = new InvoiceParameters()
    {
        Date = DateTime.Now,
        InvoiceNumber = order.Name,
        order = order,
        lines = order.OfferLines,
        ReturnPDF = true,
        SendByOutlook = false,
        SendXML = false,
        DocumentType = CompanyLayoutType.Offer,
        ShowInvoice = false,
        Simulate = false
    };
    var invoice = await invoiceParams.PostInvoice(new InvoiceAPI(api));
    var data = invoice.pdf;

    var fileName = "Offerte 123";
    var attachment = new UserDocsClient()
    {
        _Data = data,
        _Text = fileName,
        _DocumentType = FileextensionsTypes.PDF
    };
    return attachment;
}

Custom report:

public async Task<UserDocsClient> CreateCustomOfferReport(CrudAPI api, GiftProject giftProject)
{
    var reportName = "Offerte 3";
    var report = await LoadReport(api, reportName);

    var order = ConvertProjectToOrder(giftProject);

    report.DataSource = new List<UnicontaMasterDetail>()
    {
        new UnicontaMasterDetail()
        {
            Master = order,
            Details = order.OfferLines.ToArray()
        }
    };

    var stream = new MemoryStream();
    var pdfOptions = new PdfExportOptions();
    await report.ExportToPdfAsync(stream, pdfOptions);
    stream.Position = 0;
    var data = stream.ToArray();
    var fileName = "Offerte 123";
    var attachment = new UserDocsClient()
    {
        _Data = data,
        _Text = fileName,
        _DocumentType = FileextensionsTypes.PDF
    };
    return attachment;
}

private static async Task<XtraReport> LoadReport(CrudAPI api, string reportName)
{
    var apiWrapper = new ApiWrapper<StandardQuotationReportClient>(api);

    var reports = await apiWrapper.Filter()
        .WhereEqual(x => x.Name, reportName)
        .Run();
    var reportRow = reports.FirstOrDefault();
    if (reportRow == null)
        throw new Exception($"Kon rapport '{reportName}' niet vinden!");
    // Load Layout bytes in repord
    _ = await api.Read(reportRow);
    var reportLayout = reportRow.Layout;
    if (reportLayout == null)
        throw new Exception($"Kon rapport '{reportName}' layout niet laden!");

    XtraReport report;
    try
    {
        report = ReportUtil.GetXtraReportFromLayout(reportLayout);
    }
    catch (Exception)
    {
        report = null;
    }
    if (report == null)
        throw new Exception($"Kon rapport '{reportName}' niet laden! (error while loading layout)");
    return report;
}
59260cookie-checkUniconta Report print offer/order PDF