This is a migrated thread and some comments may be shown as answers.

Create invoice using Telerik Reporting

9 Answers 751 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sandrino
Top achievements
Rank 1
Sandrino asked on 02 Nov 2008, 05:28 PM
Dear,

We are currently generating invoices using MS Word and filling in fields.We would like to move to a cleaner way of generating invoices using reports.

Let's say we have the following class (not our actual class, just quick example):

class Invoice
{
        int InvoiceID { get; set; }
        string ClientName { get; set; }
        string InvoiceReference { get; set; }
        DateTime InvoiceDate { get; set; }
        List<Task> InvoicedTasks { get; set; }
}

Is it possible to generate a report, based on this class (the header would show the ID, ClientName, InvoiceReference, InvoiceDate)? In detail we would get a list of tasks. And give as parameter something like the InvoiceID?

We don't want to use a database as source, because our class includes alot business logic.

Regards

9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 03 Nov 2008, 01:28 PM
Hello Sandrino,

There should be no problems to generate a report based on your business objects. Here is a forum thread that elaborates on the matter, including a sample application. Give it a spin and let us know if further help is needed.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sandrino
Top achievements
Rank 1
answered on 05 Nov 2008, 09:46 AM
Dear,

I tested the example and it works perfectly. But I have one question.
Let's use your example. It lists all the books from the bookstore.

But I would like to change the report (invoice a bit). In the header I would want to write the name and address of the bookstore, then a list of all the books (with a title "Books") and a list of authors (with a title "Authors").

Is that possible?

Regards
0
Steve
Telerik team
answered on 05 Nov 2008, 10:16 AM
Hello Sandrino,

The answer to your questions are contained in the "Understanding Report Sections" help article explaining what are the PageHeader and ReportHeader sections used for.

Kind regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sandrino
Top achievements
Rank 1
answered on 05 Nov 2008, 10:29 AM
Well I understand the report sections.
I just don't understand how to use different datasources for different sections (is this even needed?).

Imagine:

- Report header: I want to display bookstore name and address. How do I pass an object to the report header to fill in the fields?
- Report detail: Here I want to display all the books of the bookstore

Am I thinking right? Can I use multiple data sources? Should I work with subreports to achieve this?

0
Steve
Telerik team
answered on 05 Nov 2008, 11:16 AM
Hi Sandrino,

Here is a quote from the documentation:
This section is printed just once, at the beginning of the report. In the Report Header section all data fields must be aggregated, even if the data source returns only one row. Typically you should use the FIRST() function for character and date data and the SUM() function for numeric data. When you place a databound report item that uses an aggregate function in the report header, it is calculated for the entire report data.

There is no way to use multiple datasources in different sections, unless it is a subreport.

Kind regards,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sandrino
Top achievements
Rank 1
answered on 05 Nov 2008, 11:25 AM
Thanks Steve, but could you explain in an example?
I don't get where and how to use FIRST() and how I should create my datasource.

Kind regards
0
Sandrino
Top achievements
Rank 1
answered on 11 Nov 2008, 05:42 PM
Hello,

I have been testing out the reporting a bit more, using this code:

            Address a = new Address()   
                { City = "brussels", Country = "belgium", Street = "mainstreet" };  
            Client c = new Client()   
                { Name = "MyClient", Sector = "Informatica", Type = "Important" };  
            List<Task> t = new List<Task>()  
            {  
                new Task() { Start = DateTime.Now, End = DateTime.Now.AddDays(2), Minutes = 5, Name = "issue 1", Type = "support" },  
                new Task() { Start = DateTime.Now, End = DateTime.Now.AddDays(3), Minutes = 33, Name = "issue 3", Type = "support" },  
                new Task() { Start = DateTime.Now, End = DateTime.Now.AddDays(4), Minutes = 44, Name = "prj 4", Type = "project" },  
              };  
 
            DataTable table = new DataTable();  
            table.Columns.Add("client");  
            table.Columns.Add("sector");  
            table.Columns.Add("type");  
            table.Columns.Add("city");  
            table.Columns.Add("country");  
            table.Columns.Add("street");  
            table.Columns.Add("taskstart");  
            table.Columns.Add("taskend");  
            table.Columns.Add("minutes");  
            table.Columns.Add("name");  
            table.Columns.Add("tasktype");  
 
            foreach (Task task in t)  
                table.Rows.Add(new object[] { c.Name, c.Sector, c.Type, a.City, a.Country, a.Street,  
                    task.Start, task.End, task.Minutes, task.Name, task.Type });  
 
            Report1 rpt = new Report1();  
            rpt.DataSource = table;  
            reportViewer1.Report = rpt; 

What i do then in the report is put client, sector, type, city, country, street in the header.
All the rest goes in the detail.

Could you give a cleaner solution to this?

 

Kind regards

0
James
Top achievements
Rank 2
answered on 11 Nov 2008, 09:47 PM

Sandrino,

I would suggest something like the following. Create 2 datatables, load the data into each, and set the datasource for the main report and then the subreport.  I added the client as a key to the Address and Tasks so you could have multiple clients each with an address and 0 to many Tasks.

 

            List<Client> c = new List<Client>  
            {  
                new Client() {Name="MyClient1", Sector = "Information", Type = "Important"},  
                new Client() {Name="MyClient2", Sector = "Finance", Type = "Important"}  
            };  
 
            List<Address> a = new List<Address>   
            {  
                new Address() {Client = "MyClient1", City="brussels", Country="Belgium", Street="mainstreet"},  
                new Address() {Client = "MyClient2", City="Nashville", Country="US", Street="Elm Street"}  
            };  
            List<Tasks> t = new List<Tasks>  
                {  
                    new Tasks() {Client = "MyClient1",Start = DateTime.Now, End = DateTime.Now.AddDays(2),Minutes=5,Name="issue 1",Type="support"},  
                    new Tasks() {Client = "MyClient1",Start = DateTime.Now, End = DateTime.Now.AddDays(3),Minutes=5,Name="issue 2",Type="project"},  
                    new Tasks() {Client = "MyClient2",Start = DateTime.Now, End = DateTime.Now.AddDays(4),Minutes=5,Name="issue 1",Type="support"},  
                };  
 
            DataTable Clients = new DataTable();  
            Clients.Columns.Add("client");  
            Clients.Columns.Add("sector");  
            Clients.Columns.Add("type");  
            Clients.Columns.Add("city");  
            Clients.Columns.Add("country");  
            Clients.Columns.Add("street");  
 
            DataTable Task = new DataTable();  
            Task.Columns.Add("client");  
            Task.Columns.Add("taskstart");  
            Task.Columns.Add("taskend");  
            Task.Columns.Add("minutes");  
            Task.Columns.Add("name");  
            Task.Columns.Add("tasktype");  
 
            foreach (Client cli in c)  
            {  
                Address add = a.Find(delegate(Address addr) {return addr.Client == cli.Name;});  
                Clients.Rows.Add(new object[] {cli.Name,cli.Sector,cli.Type,add.City,add.Country,add.Street});  
 
                List<Tasks> tas = t.FindAll(delegate(Tasks t1) {return t1.Client == cli.Name;});  
                foreach (Tasks t2 in tas)  
                {  
                    Task.Rows.Add(new object[] {cli.Name,t2.Start,t2.End,t2.Minutes,t2.Name,t2.Type });  
                }  
            }  
 
            this.ReportViewer1.Report = new Report1();  
 
            // Find the subreport whose name is the value of "SubReport" within the Master Report     
            SubReport subRpt1 = this.ReportViewer1.Report.Items.Find( "SubReport1",true)[0] as SubReport;  
 
            Report mainRpt = this.ReportViewer1.Report as Report;  
            mainRpt.DataSource = Clients;  
            Report subReport = subRpt1.ReportSource as Report;  
            subReport.DataSource = Task; 

 Use the parameters and filters to tie the subreport to the mainreport based on this example from Telerik Report Documentation.

0
Andy
Top achievements
Rank 1
answered on 21 Feb 2009, 05:00 PM
Hello,

I think what you are trying to do is very similar to me. I am producing Invoices from a Database. I understand how your doing it but maybe you could give some thought to what I need and see if you have any ideas?

I need to make three runs through a MySQL Database table of Invoices:

1. Get all Invoices marked for Post and create one big report with One page per invoice with at least one other page for each for a timesheet. I have the database setup like:

- invoice table - one row per invoice
- invoice_element table - one row per item on invoice
- timesheet table - one row per timesheet
- timesheet_element table - one row per day

2. Get all Invoices for E-mail and create one Invoice page and one page for each timesheet and e-mail it to.

3. Get all Invoices set for both - do point 1 then point 2.

If you can offer any advice/examples to expand on what you've done here I'd really appreciate it. I can happily build the DataTables but I'm not sure I understand how you make one record one page and then list another DataTable as items on each page.

Thanks!

Andy
Tags
General Discussions
Asked by
Sandrino
Top achievements
Rank 1
Answers by
Steve
Telerik team
Sandrino
Top achievements
Rank 1
James
Top achievements
Rank 2
Andy
Top achievements
Rank 1
Share this question
or