# Create a PDF Invoice with a Table of Detail Line Items

A great feature in **Workflow Automation** is the ability to create a **Detail Table** from a set of collected items within an **App**. This table can then be inserted into an **HTML** box found in the **Send Email** or **Make a PDF** actions. For this example, we are going to create a **PDF Invoice**, with a table of line items, that will be sent to clients.

**For example**: When a Customer has a new job request, we create a **Work Order**. While the job is in progress, we create **Time Sheets** to bill time to the **Work Order**. Once the job has been completed, we must create an invoice with a unique **ID** number. This invoice can then be sent to the customer and uploaded into our accounting system.

![PDF Invoice with Table](https://www.progress.com/podio/documentation/assets/a6aed56d4ee9d4374cd9d7ad0320b803/pdf-invoice1.png)

## Solution Explained

1. First a **Category** field called **Status** was placed on our **Work Orders App** which acts like an action button. This **Status** will be changed in order to create an **Invoice Item** within the Invoices app.

   ![PDF Invoice with Table](https://www.progress.com/podio/documentation/assets/2724a3d4216358e9de6b6cc7cef4a3d6/pdf-invoice1a.png)

2. Once the **Invoice Item** has been created, a PDF file can be generated using the data from all related timesheet items. The **Invoice Item** will have a unique **ID** which can be used for the **Invoice Number**. This can be set up in the **Advanced** tab of the **App Settings**. The field token associated with this number is called the **Podio App Item ID**. Using the (Formatted) choice will reflect this unique **ID** with the format chosen in the settings.

   ![PDF Invoice with Table](https://www.progress.com/podio/documentation/assets/b40f00f74599645f6dfb3114a22378c2/pdf-invoice1b.png)

## Flow Details

1. The first flow created is in the **Work Order App**. The filters state this flow will run when the **Status** category has changed and is equal to **Completed**. If so, we first need to collect the **Client Item** for data so that we can perform a calculation on the **Amount Due**. Then Invoice Item is then created with a relationship to the **Work Order** and **Client App**.

   ![PDF Invoice Flow](https://www.progress.com/podio/documentation/assets/993cca737fb4f6adafc01887ce976c69/pdf-invoice-flow1.png)

   ***Note**: Be sure all important fields for the PDF Invoice are filled out in this step*.

2. Now, set up a flow to run upon Item creation in the Invoice App. No filters are being set as we want this to run on every Invoice Item.
   1. The first step is to collect the referenced Time Sheets using the **Get Referenced Item(s)** collector. In our example, we have collected the **Time Sheets** that have a relationship to the **Work Order** that is being referenced by the Invoice. We have also added a collector to get the **Client data** to open up the field tokens to use on the **Invoice**.

      ![PDF Invoice Flow](https://www.progress.com/podio/documentation/assets/cede1ab7a5bab5a73692aefa2dc1818c/pdf-invoice-flow1a.png)
   2. Then create a **Detail Table** using these **Time Sheet Items**. Select which fields should be added for column headings.

      ![PDF Invoice Flow](https://www.progress.com/podio/documentation/assets/982d0d58adc6fb76c723e0a6f2a12731/pdf-invoice-flow1b.png)
   3. Finally, add the **Make a PDF** action. Create the PDF body and use the Field Token selector to add specific fields from the Apps and to add the **HTML Detail Table**.

      ![PDF Invoice Flow](https://www.progress.com/podio/documentation/assets/2e29cecc7b456216f9805bebd5663678/pdf-invoice-flow1c.png)

      ***Note**: You can use Custom Variables to re-format fields that don't come out of Podio the way you want them displayed*.

3. Once the **Work Order** status is set to *Complete*, the invoice record is created, triggering the flow to create the **PDF** file. This file is then attached to the invoice record and can be emailed in a **Send Email Action** if desired. Here's a sample resulting PDF invoice:

   ![PDF Invoice Result](https://www.progress.com/podio/documentation/assets/e39fd61325ba4fe09aacd64fbd0c2311/pdf-invoice-rslt1.png)
