How to generate a Consolidated Purchase Order Document with Sum of Prices

Hello, AppSheet Community!

I am working on an app that involves generating purchase order documents for suppliers. Here’s how my data is structured:

  • Order List: This table contains data about the supplier, order date, and our company information.
  • Related Order List Detailed: This table holds details about items and the amount for each order.
  • Supplier, Items, and Recipe: These are separate tables where each item can be associated with multiple recipes, but each recipe has only one supplier.

Other important details:

  • I use PDF generation with an HTML template for generating order documents.
  • The price is directly associated with each material in the recipe and they are static.

My goal is to generate a consolidated document for each supplier that lists all the items I intend to order from them, along with a total price. Considering the structure of my data, I am unsure about the best way to sum up the pricing for each order, especially since the materials for a given recipe can come from different suppliers.

Any advice or guidance on how I can achieve this would be greatly appreciated!

Thank you in advance for your assistance.

Show More

HTML Template:

Show More

    

<<Start: FILTER(data_supplier,in([supplier_id],[supplier]))>>

      
        

          # <<[_THISROW-1].[order_list_id]>>

        

         <<LOOKUP("1RLad602hAgB6aD_E_c1Ck7_QDuxEe2Xy", "Logo PT Timboel","_ID", "File")>>
          
        

      

      <table>

        
          <tr>

            <th>

Vendor

</th>

            <th>

Customer

</th>

            
            <th colspan="3">

Notes

</th>

          </tr>

        
        
          <tr>

            <td>

              **<<[nama]>>**
            

</td>

            <td>

              **PT. Timboel**
            

</td>

            
            <td>

              **Date**
            

</td>

            <td>

<<[tanggal]>>

</td>

          </tr>

          <tr>

            <td rowspan="6">

<<[supplier_id]>>  
 
              <<[alamat_1]>> 
 
              <<[alamat_2]>> 

              <<[alamat_3]>> 

              <<[no_telefon]>> 

              <<[email]>> 

            

</td>

            <td rowspan="6">

 PII removed by staff
            

</td>

            
            <td>

              **Deadline**
            

</td>

            <td>

<<[_THISROW-1].[deadline]>>

</td>

          </tr>

         
          <tr>

            <td>

              **Mentah Deadline**
              

            

</td>

            <td>

<<[_THISROW-1].[deadline_mentah]>>

</td>

          </tr>

          <tr>

            <td>

              **Rangkai Deadline**
              

            

</td>

            <td>

<<[_THISROW-1].[deadline_rangkai]>>

</td>

          </tr>

          <tr>

            <td>

              **Finishing Deadline**
              

            

</td>

            <td>

<<[_THISROW-1].[deadline_finishing]>>

</td>

          </tr>

          <tr>

            <td rowspan="3">

              <b>Comments 

              </b>
            

</td>

            <td rowspan="3">

<<[_THISROW-1].[komentar]>>

</td>

          </tr>

          <tr>
</tr>

          <tr>
</tr>

        
      </table>
      

<<Start: ORDERBY(
                      FILTER(
                        "order_list_detailed", 
                        AND(
                          [order_list_id] = [_THISROW].[order_list_id], 
                          IN([_THISROW-1].[supplier_id], [Supplier List]),
                          [quantity_bikin]>0
                        )
                      ), 
                      [barang_id].[Finishing]
                    )>>

<<End>>

| Item ID | Photo | Item Name | Material | Finishing | Size (cm) | QTY | Total | Notes |
| - | - | - | - | - | - | - | - | - |
| <<[barang_id]>> | <<[barang_id].[foto]>> | <<[barang_id].[nama_barang]>> | <<[barang_id].[kategori]>> | <<IF(SUM(<br>                SELECT(<br>                  Resep bukan packing[Value Rupiah],<br>                  AND(<br>                    [barang_id] = [_THISROW-1].[barang_id],<br>                    [supplier_id] = [_THISROW-2].[supplier_id],<br>                    [kategori] = "finishing"<br>                  )<br>                ))=0,"Unfinish",[barang_id].[Finishing])>> | <<[ukuran]>> | <<[quantity_bikin]>> | <br>                            <<[quantity_bikin]*<br>                (SUM(<br>                    SELECT(<br>                        Resep bukan packing[Value Rupiah],<br>                        AND(<br>                            [barang_id] = [_THISROW-1].[barang_id],<br>                            [supplier_id] = [_THISROW-2].[supplier_id],<br>                            [kategori] = "finishing"<br>                        )<br>                    )<br>                ) +<br>                SUM(<br>                    SELECT(<br>                        Resep bukan packing[Value Rupiah],<br>                        AND(<br>                            [barang_id] = [_THISROW-1].[barang_id],<br>                            [supplier_id] = [_THISROW-2].[supplier_id],<br>                            [kategori] = "rangkai"<br>                        )<br>                    )<br>                ) +<br>                SUM(<br>                    SELECT(<br>                        Resep bukan packing[Value Rupiah],<br>                        AND(<br>                            [barang_id] = [_THISROW-1].[barang_id],<br>                            [supplier_id] = [_THISROW-2].[supplier_id],<br>                            [kategori] = "mentah"<br>                        )<br>                    )<br>                ))>><br>             | <<[komentar]>> |

          
      

| Total QTY | <<SUM(SELECT(order_list_detailed[quantity_bikin],AND(IN([_THISROW-1].[supplier_id],[Supplier List]),<br>          [order_list_id] = [_THISROW].[order_list_id]),FALSE))>> Pcs |
| - | - |

       -->
      <table>

       
   
          <tr>
<th>

Deposit (30%)

</th>

          <td>

<<[Deposit]>>

</td>

          <td>

<<[Tanggal DP]>>

</td>

        </tr>

        <tr>

          <th>

Shipping Cost

</th>

          <td colspan="2">

<<[Shipping]>>

</td>

          <td>

</td>

        </tr>

        <tr>

          <th>

Balance

</th>

          <td>

<<[Balance]+[Shipping]>>

</td>

          <td>

<<[Tanggal Lunas]>>

</td>

        </tr>
</table>
    

     

<<End>>

   
   
  ​

Can you share some examples of the data, and a mockup of how you want the PDF output to look from those data examples?

1 Like

Sample Order List

Show More
order_list_id order_list_bot invoice_id customer_id tanggal deadline jenis_packing komentar deadline_finishing
OL-C5C3D944-PTT 4ddd8fd2 PI-0ADC7ED1-PTT PTT-3BCC2BA7 14/04/2023 26/05/2023 Standar export, pasahan halus, tanpa lubang Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 10/08/1996

Sample Order List Detailed

Show More
barang_id order_list_id quantity_stock quantity_bikin komentar pakai_stock tanggal_mentah tanggal_rangkai tanggal_finishing tanggal_packing selesai_mentah selesai_rangkai selesai_finishing selesai_packing
WTH-71841252-NS OL-C5C3D944-PTT 0 1 FALSE 14/04/2023 14/04/2023 14/04/2023 14/04/2023 1 1 1 1
AHB-A5DAFBED-BST OL-C5C3D944-PTT 0 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis FALSE 14/04/2023 14/04/2023 14/04/2023 14/04/2023 1 1 1 1
SBS-2D531B2A-WC OL-C5C3D944-PTT 0 1 FALSE 14/04/2023 14/04/2023 14/04/2023 14/04/2023 1 1 1 1

Sample Item Recipe

Show More
tanggal barang_id material_id supplier_id kategori quantity keterangan
19/04/2023 WTH-71841252-NS CA-PEKNV45C-T T-A1D117C2 Mentah 48
19/04/2023 WTH-71841252-NS TL-34F767EC-T T-A1D117C2 Rangkai 230
06/05/2023 WTH-71841252-NS WA-DF514547-TT TT-430D1B8F Finishing 1.5
06/05/2023 WTH-71841252-NS A-D8B1FB64-SGI SGI-3C2F3ABC Finishing 75
06/05/2023 WTH-71841252-NS O-F2490673-SGI SGI-3C2F3ABC Finishing 15
06/05/2023 WTH-71841252-NS A-793EAE63-SGI SGI-3C2F3ABC Finishing 0.3
06/05/2023 WTH-71841252-NS G/C-585254FA-RK RK-BE4D07B0 Finishing 1
06/05/2023 WTH-71841252-NS G/C-281BF5F4-RK RK-BE4D07B0 Finishing 1
06/05/2023 WTH-71841252-NS FDG-0AF4AB39-RK RK-BE4D07B0 Finishing 3
06/05/2023 WTH-71841252-NS GSK-E24F372D-RK RK-BE4D07B0 Finishing 1
06/05/2023 WTH-71841252-NS CBU-55BC76DB-RK RK-BE4D07B0 Finishing 1
06/05/2023 WTH-71841252-NS TNT-0AE17666-RK RK-BE4D07B0 Finishing 0.5
06/05/2023 WTH-71841252-NS CP-A2B945D3-RK RK-BE4D07B0 Finishing 0.2
06/05/2023 WTH-71841252-NS BO-CF651D09-PT PT-083ARFG45 Finishing 25
06/05/2023 WTH-71841252-NS SG-9C47FCE3-PT PT-083ARFG45 Finishing 25
06/05/2023 WTH-71841252-NS PA–70DC7640-KL KL-61FC8A48 Finishing 48
06/05/2023 WTH-71841252-NS TKL-A4BB7325-PT PT-083ARFG45 Finishing 20
19/04/2023 AHB-A5DAFBED-BST CA-PEKNV45C-T T-A1D117C2 Mentah 8.7
19/04/2023 AHB-A5DAFBED-BST TL-34F767EC-T T-A1D117C2 Rangkai 52
19/04/2023 AHB-A5DAFBED-BST TF-575DBF68-RHO RHO-D29A4A18 Finishing 3.2
19/04/2023 AHB-A5DAFBED-BST L-1C89B15B-PT PT-083ARFG45 Finishing 5
19/04/2023 AHB-A5DAFBED-BST SG-9C47FCE3-PT PT-083ARFG45 Finishing 1
19/04/2023 AHB-A5DAFBED-BST BO-CF651D09-PT PT-083ARFG45 Finishing 1.5
19/04/2023 SBS-2D531B2A-WC RS/-F948D1A2-CCP CCP-4312DE21 Mentah 1.5
19/04/2023 SBS-2D531B2A-WC KS3-512D919C-CMD CMD-A347B5ED Mentah 13
19/04/2023 SBS-2D531B2A-WC G/C-281BF5F4-RK RK-BE4D07B0 Mentah 2
19/04/2023 SBS-2D531B2A-WC G/C-585254FA-RK RK-BE4D07B0 Mentah 3
19/04/2023 SBS-2D531B2A-WC GSK-E24F372D-RK RK-BE4D07B0 Mentah 1
19/04/2023 SBS-2D531B2A-WC KPM-0489BA9F-TKS TKS-F602EDE2 Mentah 1
19/04/2023 SBS-2D531B2A-WC KPS-386F97CE-UKL UKL-C601602D Mentah 10
19/04/2023 SBS-2D531B2A-WC WI/L-4E92F26A-RK RK-BE4D07B0 Mentah 1
19/04/2023 SBS-2D531B2A-WC KP-BC0023F8-RK RK-BE4D07B0 Mentah 0.2
19/04/2023 SBS-2D531B2A-WC FDG-0AF4AB39-RK RK-BE4D07B0 Mentah 2
19/04/2023 SBS-2D531B2A-WC AD-7621C904-RK RK-BE4D07B0 Mentah 0.5
19/04/2023 SBS-2D531B2A-WC B-44B77D10-PSY PSY-6DFC57D7 Mentah 1
19/04/2023 SBS-2D531B2A-WC PS1-7068C2FE-PCL PCL-C216AA1D Mentah 1
19/04/2023 SBS-2D531B2A-WC SG-9C47FCE3-PT PT-083ARFG45 Mentah 20
19/04/2023 SBS-2D531B2A-WC BO-CF651D09-PT PT-083ARFG45 Mentah 20
19/04/2023 SBS-2D531B2A-WC TKL-A4BB7325-PT PT-083ARFG45 Mentah 132
19/04/2023 SBS-2D531B2A-WC PH/-783E21D5-PCL PCL-C216AA1D Mentah 2.5
19/04/2023 SBS-2D531B2A-WC C-FDD30072-MC MC-37FFFBD7 Finishing 39.12
06/05/2023 SBS-2D531B2A-WC PS1-71B4877D-CMD CMD-A347B5ED Mentah 0.25

This mockup contains red text representing specific data I’m trying to display. Essentially, I want to showcase the sum of the total. While I can accurately represent this when the quantity is 1, the value displayed is incorrect when the quantity is 2, as I haven’t incorporated the quantity into the total calculation.

Sample PDF Mockup

I think your examples contain a bit too much info, I’m lost in the details. Like you really included “lorem ipsum” sample text…

I don’t even see any price values anywhere. I’d expect a column in the “Item Recipe” table with price values, but no?

All in all, I’m not really sure where you’re having trouble. You say it’s with summing up the total price, but I’m not sure what could be causing the issue.

Assume these tables:

Item_Recipe:

id price
a 5
b 10

Order:

id
OL-C5C3D944-PTT

Order_Detail:

id order_id item_recipe_id qty total price (qty * item’s price)
1 OL-C5C3D944-PTT a 1 5
2 OL-C5C3D944-PTT b 2 20

You see I’m calculating the total price in the individual order_detail records? Maybe that’s what you’re missing? Then your template would be:

<<START:[Related order_details]>>
order detail info…
<>
Total: <<SUM([Related order_details][total_price])>>
Total Qty: <<SUM([related order_details][qty])>>