I am working on invoice printout.
I am facing a problem in printing the invoice. let's say there is an invoice that consist of items that are exactly in 1 page. The problem is there are subtotal, tax, and grandtotal after all the items.
In this case these 3 would be on the second page(new page), while the items are on 1st page.
I have done checking the row that one page can hold in tcpdf(after all my layout format, etc) and found out 1 page will consist of 28 items. This will work well if all the item consists of 1 row. However, if some of the items consist of 2 or more rows, the calculation will face a problem, and the whole structure will be a mess.
How can i automatically move some items to second page if the total items are 28 items, so the second page will not only consist of the subtotal, tax, and grand total?
here is my code
$count = 0;
$i = 0;
if(count($finalProduct)>0){
foreach($finalProduct as $product){
foreach($product['product'] as $prod){
if($prod['qty'] > 0){
/* check the row */
if($count >= 27){
$PDFCONTENT .= '<tr style="page-break-after:initial"><td colspan="6"></td></tr>';
$PDFCONTENT .= '<tr><td colspan="6"></td></tr>';
$count = 0;
}
$PDFCONTENT .= '
<tr nobr="true">';
$PDFCONTENT .= '<td align="center" width="7%">'.$prod['index_number'].'</td>';
</tr>';
}
$count++;
}
$PDFCONTENT .= '<tr><td></td></tr>';
}
}
$PDFCONTENT .= '<tfoot>
<tr> <td> </td> </tr>
<tr>
<th align="right" colspan="6">SUB TOTAL $:-</th>
<th style="border-top: 1px solid black;border-bottom: 1px solid black;" align="center">'.number_format($data['total'],2).'</th>
</tr>
<tr>
<th align="right" colspan="6">ADD '.number_format($data['transaction_tax_percentage']).'% $:-</th>
<th style="border-top: 1px solid black;border-bottom: 1px solid black;" align="center">'.number_format($data['transaction_tax_amount'],2).'</th>
</tr>
<tr>
<th align="right" colspan="6">TOTAL $:-</th>
<th style="border-top: 1px solid black;border-bottom: 1px solid black;" align="center">'.number_format($data['grand_total'],2).'</th>
</tr>
</tfoot>';
I remember that this was a real problem with tables. so we calculatet if there is a pagebreak to be set. If so, we closed the tabel, added a new site and reopened the table and put the rest of the table in it.
To force the pagebreak we used <br pagebreak="true"/>
if you don't close the table it leads to other problems.
A good threat is also here on SO: Manual Page Break in TCPDF
Related
I have the following code for the output:
<?php
function HailstoneNumbers($x){
echo '<tbody>';
static $c=0;
echo '<tr style="border-bottom:1px solid black; border-width: medium;"> <tr:last-child style="border-bottom:0;">';
echo '<td>'.$c.'</td>'.'<td>'.$x.'</td>';
echo '</tr>';
if ($x == 1 && $c == 0){
// N is initially 1.
return $c;
}
else if ($x == 1 && $c != 0){
// N is reduced to 1.
$c++;
}
else if ($x % 2 == 0){
// If N is Even.
$c++;
HailstoneNumbers((int)($x / 2));
}
else if ($x % 2 != 0){
// N is Odd.
$c++;
HailstoneNumbers(3 * $x + 1);
}
return $c;
}
$x = $_GET['x'];
if(isset($_GET['x'])){
echo '<table style="border-collapse:collapse; border-width:medium;">
<thead>
<tr style="border-bottom:1px solid black; border-width:medium;">
<th>Iteration</th><th>x</th>
</tr>
</thead>';
HailstoneNumbers($x);
echo '</tbody>'.'</table>';
}
?>
But I want the table that looks something like:
I want border between columns in header and entries, and bottom borders on all rows except for the last row. However, I am stuck on how to do that in php file without writing a css file.
You can use CSS property "border-style:hidden" on table and instead of applying CSS on TR or TH tag you can apply CSS directly on TD, something like:
https://jsfiddle.net/kht8mnLc/6/
<table style="border-collapse:collapse; border-width:medium; border-style:hidden;">
<thead>
<tr>
<th style="border:1px solid black;">Iteration</th>
<th style="border:1px solid black;">x</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border:1px solid black;">aaa</td>
<td style="border:1px solid black;">bbb</td>
</tr>
<tr>
<td style="border:1px solid black;">aaa</td>
<td style="border:1px solid black;">bbb</td>
</tr>
<tr>
<td style="border:1px solid black;">aaa</td>
<td style="border:1px solid black;">bbb</td>
</tr>
</tbody>
</table>
I tried to write the table inside a loop by 1 table/loop by using 1 table equal to 1 row.
However, I got a space between 2 tables like attached image below. I try to remove by using css properties like margin,padding are not worked.
Data is generated in each loop
How can I remove the space between there table? this is my example code.
for ($j=0;$j<count($ins_englishDescriptionOfGoods);$j++){
$html = <<<EOD
<table width="100%;" border="1" align="center" style="padding: 5px 1px 5px 2px; border-collapse: collapse;">
<tr nobr="true">
<td width="6%">$ORDER</td>
<td width="16%" style="text-align:center;">$GCL_NO</td>
<td width="13%" style="text-align:center;">$CONTAINER_NO</td>
<td width="23%" style="text-align:left; font-size:12px; line-height:7px;">$ENG_DESC</td>
<td width="10%" style="text-align:right;" >$NETWEIGTH</td>
<td width="10%" style="text-align:right;">$QTY</td>
<td width="10%" style="text-align:right;">$PACKAGE</td>
<td width="12%" style="text-align:right;">$FOB</td>
</tr>
</table>
EOD;
$pdf->writeHTML(iconv('TIS-620','UTF-8' ,$html), true, false, false, false, '');
}
I was having this exact same problem just now.
I was able to remove the space between two tables by adding line-height: -0.8 to the table and adding line-height: 1.5 to all of the rows in the table:
$pdf->html('<p>These two tables are touching each other:</p>');
$pdf->html('<table class="table-border" style="line-height: -0.8"><tbody><tr style="line-height: 1.5"><td>Hello</td></tr></tbody></table>');
$pdf->html('<table class="table-border"><tbody><tr><td>Goodbye!</td></tr></tbody></table>');
$pdf->html('<p>These two tables are not:</p>');
$pdf->html('<table class="table-border" ><tbody><tr><td>Hello</td></tr></tbody></table>');
$pdf->html('<table class="table-border"><tbody><tr><td>Goodbye!</td></tr></tbody></table>');
TCPDF doesn't support setting a margin with CSS, so you have to fake it with line-height :(
I have created a table with TCPDF. The header, which has a black background, has been positioned slightly to the right as though there is some padding on the left hand side. I cannot get it to line up correctly.
The code below is the HTML I have written to form the table.
$tbl ='<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
<th width="1px"></th>
<th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;"> <strong>Product or Service</strong></th>
<th width="1px"></th>
<th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
<th width="1px"></th>
<th width="84px"><strong>Total</strong></th>
</tr>
<tr>
<td height="267px">';
while($i <= $a) {
$tbl .= '<table height="267px" width="60px"><tr><td>' . $productsArray['product_quantity'][$i] . '</td></tr></table>';
$i++;
}
$tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($j <= $a) {
$tbl .= '<table height="267px" width="388px"><tr><td class="tal"> ' . $productsArray['product_name'][$j] . '</td></tr></table>';
$j++;
}
$tbl .= '</td><td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($k <= $a) {
$tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_price'][$k] . '</td></tr></table>';
$k++;
}
$tbl .= '</td><td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td><td height="267px">';
while($l <= $a) {
$tbl .= '<table height="267px" width="84px"><tr><td>' . $productsArray['product_sub'][$l] . '</td></tr></table>';
$l++;
}
$tbl .= '</td>
</tr>
</table>';
}
The below code is the PHP I have used to show the table on the page.
$pdf->writeHTMLCell(175, 80, 20, 100, $tbl, 1, 1, 0, true, 'C', true);
Using tables within cells of another table is generally a really bad idea and is likely contributing to the problem you are having. Since it looks like your productsArray already has all of the data you need I would simply loop through it outputting each row as you go.
It's also worth pointing out that the empty header rows that are defined with a width of 1px conflict with your actual data rows which are defined with a width of 0.5px.
<style>
th {background-color: black;color: white;float:left;}
.tal {text-align: left;float:left;}
</style>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="60px" style="border-right: 1px solid white;"><strong>Qty</strong></th>
<th width="1px"></th>
<th class="tal" width="388px" style="padding:10px 0; border-right: 1px solid white;"> <strong>Product or Service</strong></th>
<th width="1px"></th>
<th width="84px" style="border-right: 1px solid white;"><strong>Price Each</strong></th>
<th width="1px"></th>
<th width="84px"><strong>Total</strong></th>
</tr>
<?php
while($i <= $a) {
?>
<tr>
<td height="267px"><?php echo $productsArray['product_quantity'][$i]; ?></td>
<td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_name'][$i]; ?></td>
<td width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_price'][$i]; ?></td>
<td border="1" width="0.5px" height="267px" style="background:url(images/bars-black.jpg) bottom right no-repeat"></td>
<td height="267px"><?php echo $productsArray['product_sub'][$l]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
The code at the virtumart is:
<th align="center" bgcolor="#EEEEEE" style="border: 1px solid #CCCCCC;"><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_QTY') ?></th>
What I need is the following:
When the COM_VIRTUEMART_ORDER_PRINT_QTY is bigger than 1, the font color to be somehtinge else, for example red (the format I will do it later, now I just want the "if" code).
Thanks
Please try
<?php
$quantity = JText::_('COM_VIRTUEMART_ORDER_PRINT_QTY');
if($quantity > 1){
echo '<th align="center" bgcolor="#EEEEEE" style="border: 1px solid #CCCCC; color:#FF0000">'.$quantity.'</th>';
}else{
echo '<th align="center" bgcolor="#EEEEEE" style="border: 1px solid #CCCCCC;">'.$quantity.'</th>';
}
?>
I am using TCPDF stuff, I have created a PDF page with some Information. But i need to show some data to next page deliberately.
pdf -> AddPage();
above code is used to create a new page which i know. But i wanna add specific data to this particular page would be the problem.
Help me to come out on this issue.
I have written my code like this
while($row = mysql_fetch_array($query)){
$inv = $row["INVNUM"];
$weight = $row["WEIGHT"];
if($i<4){
if($row["SIZECODE"] == "02"){
$temp .= '<tr nobr="true">
<td class="size1" style="border:1px solid #000">'.$json_a[$i]["S"].'</td>
<td class="size2" style="border:1px solid #000">'.$json_a[$i]["M"].'</td>
<td class="size3" style="border:1px solid #000">'.$json_a[$i]["L"].'</td>
<td class="size4" style="border:1px solid #000">'.$json_a[$i]["XL"].'</td>
<td class="size5" style="border:1px solid #000">'.$json_a[$i]["2X"].'</td>
<td class="size6" style="border:1px solid #000">'.$json_a[$i]["3X"].'</td>
</tr>';
}
else if($row["SIZECODE"] == "03"){
$temp .= '<tr>
<td style="border:1px solid #000">'.$json_a[$i]["32"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["34"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["36"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["38"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["40"].'</td>
<td style="border:1px solid #000">'.$json_a[$i]["42"].'</td>
</tr>';
}
$i = $i+1;
}
else{
$pdf ->AddPage();
$i = 0;
$temp.='<tr nobr="true">
<td colspan="18" style="border:1px solid #000">All sales are Final.</td>
<td colspan="2" style="border:1px solid #000">SUB TOTAL:</td>
<td style="border:1px solid #000"></td>
<td style="border:1px solid #000"></td>
</tr>
<tr>
<td colspan="18" rowspan="2" style="border:1px solid #000">Number # : '.$rowFix["Num"].' </td>
</tr>
<tr>
<td colspan="2">TOTAL DUE: $</td>
<td style="border:1px solid #000"></td>
<td style="border:1px solid #000"></td>
</tr>';
}
}
I have to bring the table rows to the next page when the $i value greater than 4.
$pdf->AddPage('P', 'A4');
$pdf->Cell(0, 0, 'A4 PORTRAIT', 1, 1, 'C');
First, output the content for the first page. Then:
pdf -> AddPage();
Then, output for the second page. Anything sent after this command will be outputted onto the second page.