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:

<body>
    <p class="startifend">&lt;&lt;Start: FILTER(data_supplier,in([supplier_id],[supplier]))&gt;&gt;</p>
      <div class="container company-data">
        <div class="company text">
          <h1 class="title">&lt;&lt;[_THISROW-1].[order_list_id]&gt;&gt;</h1>
        </div>
        <div class="timboel-logo"> &lt;&lt;LOOKUP("1RLad602hAgB6aD_E_c1Ck7_QDuxEe2Xy", "Logo PT Timboel","_ID", "File")&gt;&gt;
          <!--<img src="" 
                  alt="Logo PT. Timboel" 
                  width="100">-->
        </div>
      </div>
      <table class="header">
        <thead>
          <tr>
            <th>Vendor</th>
            <th>Customer</th>
            <!-- <th>Vendor Bank</th> -->
            <th colspan="3">Notes</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>
              <b>&lt;&lt;[nama]&gt;&gt;</b>
            </td>
            <td>
              <b>PT. Timboel</b>
            </td>
            <!-- <td>
              <b>&lt;&lt;[bank_id].[bank_des]&gt;&gt;</b>
            </td> -->
            <td>
              <b>Date</b>
            </td>
            <td>&lt;&lt;[tanggal]&gt;&gt;</td>
          </tr>
          <tr>
            <td rowspan="6">&lt;&lt;[supplier_id]&gt;&gt;  <br> 
              &lt;&lt;[alamat_1]&gt;&gt; <br> 
              &lt;&lt;[alamat_2]&gt;&gt; <br>
              &lt;&lt;[alamat_3]&gt;&gt; <br>
              &lt;&lt;[no_telefon]&gt;&gt; <br>
              &lt;&lt;[email]&gt;&gt; <br>
            </td>
            <td rowspan="6"> PII removed by staff
            </td>
            <!-- <td rowspan="5"> &lt;&lt;[bank_id].[atas_nama]&gt;&gt; <br> &lt;&lt;[bank_id].[nomor_account]&gt;&gt; <br> &lt;&lt;[bank_id].[nama]&gt;&gt; <br> &lt;&lt;[bank_id].[alamat]&gt;&gt; <br> &lt;&lt;[bank_id].[no_telfon]&gt;&gt; <br> 
            </td>-->
            <td class="deadline">
              <b >Deadline</b>
            </td>
            <td class="deadline">&lt;&lt;[_THISROW-1].[deadline]&gt;&gt;</td>
          </tr>
         <!-- <tr>
            <td>
              <b>Packing</b>
              <br>
            </td>
            <td>&lt;&lt;[_THISROW-1].[jenis_packing]&gt;&gt;</td>
          </tr> -->
          <tr>
            <td>
              <b>Mentah Deadline</b>
              <br>
            </td>
            <td>&lt;&lt;[_THISROW-1].[deadline_mentah]&gt;&gt;</td>
          </tr>
          <tr>
            <td>
              <b>Rangkai Deadline</b>
              <br>
            </td>
            <td>&lt;&lt;[_THISROW-1].[deadline_rangkai]&gt;&gt;</td>
          </tr>
          <tr>
            <td>
              <b>Finishing Deadline</b>
              <br>
            </td>
            <td>&lt;&lt;[_THISROW-1].[deadline_finishing]&gt;&gt;</td>
          </tr>
          <tr>
            <td rowspan="3">
              <b>Comments <br>
              </b>
            </td>
            <td rowspan="3" style="width: 30%;">&lt;&lt;[_THISROW-1].[komentar]&gt;&gt;</td>
          </tr>
          <tr></tr>
          <tr></tr>
        </tbody>
      </table>
      <table class="order_list_id-items">
        <thead>
          <tr>
            <th class="idcolumn">Item ID</th>
            <th>Photo</th>
            <th class="idcolumn">Item Name</th>
            <th>Material</th>
            <th class="smallcolumn">Finishing</th>
            <th class="smallcolumn">Size (cm)</th>
            <th >QTY</th>
            <!--<th>Mentah</th>-->
            <!--<th>Rangkai</th>-->
            <!--<th>Finishing</th>-->
            <th>Total</th>
            <th style="width: 4cm;">Notes</th>
          </tr>
        </thead>
        <tbody>
          <p class="startifend">&lt;&lt;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]
                    )&gt;&gt;</p>
          <tr>
            <td class="idcolumn">&lt;&lt;[barang_id]&gt;&gt;</td>
            <td>&lt;&lt;[barang_id].[foto]&gt;&gt;</td>
            <td class="idcolumn">&lt;&lt;[barang_id].[nama_barang]&gt;&gt;</td>
            <td>&lt;&lt;[barang_id].[kategori]&gt;&gt;</td>
            <td class="smallcolumn">&lt;&lt;IF(SUM(
                SELECT(
                  Resep bukan packing[Value Rupiah],
                  AND(
                    [barang_id] = [_THISROW-1].[barang_id],
                    [supplier_id] = [_THISROW-2].[supplier_id],
                    [kategori] = "finishing"
                  )
                ))=0,"Unfinish",[barang_id].[Finishing])&gt;&gt;</td>
            <td class="smallcolumn">&lt;&lt;[ukuran]&gt;&gt;</td>
            <td>&lt;&lt;[quantity_bikin]&gt;&gt;</td>
   
            <td>
                            &lt;&lt;[quantity_bikin]*
                (SUM(
                    SELECT(
                        Resep bukan packing[Value Rupiah],
                        AND(
                            [barang_id] = [_THISROW-1].[barang_id],
                            [supplier_id] = [_THISROW-2].[supplier_id],
                            [kategori] = "finishing"
                        )
                    )
                ) +
                SUM(
                    SELECT(
                        Resep bukan packing[Value Rupiah],
                        AND(
                            [barang_id] = [_THISROW-1].[barang_id],
                            [supplier_id] = [_THISROW-2].[supplier_id],
                            [kategori] = "rangkai"
                        )
                    )
                ) +
                SUM(
                    SELECT(
                        Resep bukan packing[Value Rupiah],
                        AND(
                            [barang_id] = [_THISROW-1].[barang_id],
                            [supplier_id] = [_THISROW-2].[supplier_id],
                            [kategori] = "mentah"
                        )
                    )
                ))&gt;&gt;
            </td>
            <td style="width: 4cm;">&lt;&lt;[komentar]&gt;&gt;</td>
          </tr>
          <p class="startifend">&lt;&lt;End&gt;&gt;</p>
        </tbody>
      </table>
          <div class="post-table-info">
      <table class="items-totals">
       <!-- <tr>
          <th>Total CBM</th>
          <td colspan="2">&lt;&lt;[Total CBM]&gt;&gt; m&#179;</td>
        </tr> -->
        <tr>
          <th>Total QTY</th>
          <td colspan="2">&lt;&lt;SUM(SELECT(order_list_detailed[quantity_bikin],AND(IN([_THISROW-1].[supplier_id],[Supplier List]),
          [order_list_id] = [_THISROW].[order_list_id]),FALSE))&gt;&gt; Pcs</td>
        </tr>
      </table>
      <table class="items-totals">
       <!-- <tr>
          <th>Subtotal</th>
          <td colspan="2">&lt;&lt;[Subtotal]&gt;&gt;</td>
        </tr>
        <tr>
          <th>Discount (&lt;&lt;[discount_percent]*100&gt;&gt; %)</th>
          <td colspan="2">&lt;&lt;[Diskon Persen Amount]&gt;&gt;</td>
          <td></td>
        </tr>
        <tr>
          <th>Discount Amount</th>
          <td colspan="2">&lt;&lt;[discount_amount]&gt;&gt;</td>
          <td></td>
        </tr> -->
   
          <th>Deposit (30%)</th>
          <td>&lt;&lt;[Deposit]&gt;&gt;</td>
          <td>&lt;&lt;[Tanggal DP]&gt;&gt;</td>
        </tr>
        <tr>
          <th>Shipping Cost</th>
          <td colspan="2">&lt;&lt;[Shipping]&gt;&gt;</td>
          <td></td>
        </tr>
        <tr>
          <th>Balance</th>
          <td>&lt;&lt;[Balance]+[Shipping]&gt;&gt;</td>
          <td>&lt;&lt;[Tanggal Lunas]&gt;&gt;</td>
        </tr> -->
      </table>
    </div>
     <p class="startifend">&lt;&lt;End&gt;&gt;</p>
   
   
  </body>โ€‹
0 3 346
3 REPLIES 3

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

Sample Order List

Show More
order_list_idorder_list_botinvoice_idcustomer_idtanggaldeadlinejenis_packingkomentardeadline_finishing
OL-C5C3D944-PTT4ddd8fd2PI-0ADC7ED1-PTTPTT-3BCC2BA714/04/202326/05/2023Standar export, pasahan halus, tanpa lubangLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis10/08/1996

Sample Order List Detailed

Show More
barang_idorder_list_idquantity_stockquantity_bikinkomentarpakai_stocktanggal_mentahtanggal_rangkaitanggal_finishingtanggal_packingselesai_mentahselesai_rangkaiselesai_finishingselesai_packing
WTH-71841252-NSOL-C5C3D944-PTT01 FALSE14/04/202314/04/202314/04/202314/04/20231111
AHB-A5DAFBED-BSTOL-C5C3D944-PTT01Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quisFALSE14/04/202314/04/202314/04/202314/04/20231111
SBS-2D531B2A-WCOL-C5C3D944-PTT01 FALSE14/04/202314/04/202314/04/202314/04/20231111


Sample Item Recipe

Show More
tanggalbarang_idmaterial_idsupplier_idkategoriquantityketerangan
19/04/2023WTH-71841252-NSCA-PEKNV45C-TT-A1D117C2Mentah48 
19/04/2023WTH-71841252-NSTL-34F767EC-TT-A1D117C2Rangkai230 
06/05/2023WTH-71841252-NSWA-DF514547-TTTT-430D1B8FFinishing1.5 
06/05/2023WTH-71841252-NSA-D8B1FB64-SGISGI-3C2F3ABCFinishing75 
06/05/2023WTH-71841252-NSO-F2490673-SGISGI-3C2F3ABCFinishing15 
06/05/2023WTH-71841252-NSA-793EAE63-SGISGI-3C2F3ABCFinishing0.3 
06/05/2023WTH-71841252-NSG/C-585254FA-RKRK-BE4D07B0Finishing1 
06/05/2023WTH-71841252-NSG/C-281BF5F4-RKRK-BE4D07B0Finishing1 
06/05/2023WTH-71841252-NSFDG-0AF4AB39-RKRK-BE4D07B0Finishing3 
06/05/2023WTH-71841252-NSGSK-E24F372D-RKRK-BE4D07B0Finishing1 
06/05/2023WTH-71841252-NSCBU-55BC76DB-RKRK-BE4D07B0Finishing1 
06/05/2023WTH-71841252-NSTNT-0AE17666-RKRK-BE4D07B0Finishing0.5 
06/05/2023WTH-71841252-NSCP-A2B945D3-RKRK-BE4D07B0Finishing0.2 
06/05/2023WTH-71841252-NSBO-CF651D09-PTPT-083ARFG45Finishing25 
06/05/2023WTH-71841252-NSSG-9C47FCE3-PTPT-083ARFG45Finishing25 
06/05/2023WTH-71841252-NSPA--70DC7640-KLKL-61FC8A48Finishing48 
06/05/2023WTH-71841252-NSTKL-A4BB7325-PTPT-083ARFG45Finishing20 
19/04/2023AHB-A5DAFBED-BSTCA-PEKNV45C-TT-A1D117C2Mentah8.7 
19/04/2023AHB-A5DAFBED-BSTTL-34F767EC-TT-A1D117C2Rangkai52 
19/04/2023AHB-A5DAFBED-BSTTF-575DBF68-RHORHO-D29A4A18Finishing3.2 
19/04/2023AHB-A5DAFBED-BSTL-1C89B15B-PTPT-083ARFG45Finishing5 
19/04/2023AHB-A5DAFBED-BSTSG-9C47FCE3-PTPT-083ARFG45Finishing1 
19/04/2023AHB-A5DAFBED-BSTBO-CF651D09-PTPT-083ARFG45Finishing1.5 
19/04/2023SBS-2D531B2A-WCRS/-F948D1A2-CCPCCP-4312DE21Mentah1.5 
19/04/2023SBS-2D531B2A-WCKS3-512D919C-CMDCMD-A347B5EDMentah13 
19/04/2023SBS-2D531B2A-WCG/C-281BF5F4-RKRK-BE4D07B0Mentah2 
19/04/2023SBS-2D531B2A-WCG/C-585254FA-RKRK-BE4D07B0Mentah3 
19/04/2023SBS-2D531B2A-WCGSK-E24F372D-RKRK-BE4D07B0Mentah1 
19/04/2023SBS-2D531B2A-WCKPM-0489BA9F-TKSTKS-F602EDE2Mentah1 
19/04/2023SBS-2D531B2A-WCKPS-386F97CE-UKLUKL-C601602DMentah10 
19/04/2023SBS-2D531B2A-WCWI/L-4E92F26A-RKRK-BE4D07B0Mentah1 
19/04/2023SBS-2D531B2A-WCKP-BC0023F8-RKRK-BE4D07B0Mentah0.2 
19/04/2023SBS-2D531B2A-WCFDG-0AF4AB39-RKRK-BE4D07B0Mentah2 
19/04/2023SBS-2D531B2A-WCAD-7621C904-RKRK-BE4D07B0Mentah0.5 
19/04/2023SBS-2D531B2A-WCB-44B77D10-PSYPSY-6DFC57D7Mentah1 
19/04/2023SBS-2D531B2A-WCPS1-7068C2FE-PCLPCL-C216AA1DMentah1 
19/04/2023SBS-2D531B2A-WCSG-9C47FCE3-PTPT-083ARFG45Mentah20 
19/04/2023SBS-2D531B2A-WCBO-CF651D09-PTPT-083ARFG45Mentah20 
19/04/2023SBS-2D531B2A-WCTKL-A4BB7325-PTPT-083ARFG45Mentah132 
19/04/2023SBS-2D531B2A-WCPH/-783E21D5-PCLPCL-C216AA1DMentah2.5 
19/04/2023SBS-2D531B2A-WCC-FDD30072-MCMC-37FFFBD7Finishing39.12 
06/05/2023SBS-2D531B2A-WCPS1-71B4877D-CMDCMD-A347B5EDMentah0.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...
<<END>>
Total: <<SUM([Related order_details][total_price])>>
Total Qty: <<SUM([related order_details][qty])>>