Hello,
I need to create a PDF report (invoice) and I am showing items. description field has usually more that two lines so I need to create it with TCPDF.
So far I understood the TCPDF, but I have a problem to show my items in the html table, they just don’t appear. I think I am doing something wrong with foreach, but I don’t know what, since the code looks right to me. The fields are not empty, since I am testing it with some code in TCPDF code. Can some one please help?
My code in TCPDF:
$pdf->SetFont('times', '', 10);
$pdf->SetXY(20,75);
$pdf->writeHTML($item_number[1], true, false, true, false, '');
$pdf->SetFont('times', '', 10);
$pdf->SetXY(20,80);
$pdf->writeHTML($item_number[2], true, false, true, false, '');
$pdf->SetXY(20,100);
// output items
$pdf->writeHTML($itemshtml, true, false, true, false, '');
My code in onRecord:
//itemsdata
sc_lookup(items,"SELECT item_number, pn, description, qty, price, tax FROM invoice_items WHERE invoice_id='[invoice_id]'");
$itemscount = 2;//{items} -> RecordCount(); doesn't work why????
for ($row = 0; $row < $itemscount; $row++)
{
$item_number[] = {items[$row][0]};
$pn[] = {items[$row][1]};
$description[] = {items[$row][2]};
$qty[] = {items[$row][3]};
$price[] = {items[$row][4]};
$tax[] = {items[$row][5]};
}
// items
$itemshtml = <<<EOD
<table class="GeneratedTable">
<thead>
<tr>
<th>[items_item_number_label]</th>
<th>[items_pn_label]</th>
<th>[items_description_label]</th>
<th>[items_price_label]</th>
<th>[items_price_total_net_label]</th>
</tr>
</thead>
<tbody>
<?php foreach($item_number as $ii){ ?>
<tr>
<td>$ii</td>
<td>$item_number[$ii]</td>
<td>$description[$ii]</td>
<td>$qty[$ii]</td>
<td>$price[$ii]</td>
<td>$totprice</td>
<td>tax[$ii]</td>
</tr>
<?php } ?>
</tbody>
</table>
EOD;