我正在使用php中的发票。我只想在发票中有任何到期日时显示DUE部分,否则应保留为隐藏状态。在我的printOrder.php中,代码如下:
这是printOrder.php文件的总代码:
<?php
require_once 'core.php';
$orderId = $_POST['orderId'];
$sql = "SELECT order_date, client_name, client_address, client_contact, sub_total, vat, total_amount, discount, grand_total, paid, due, invoice_no FROM orders WHERE order_id = $orderId";
$orderResult = $connect->query($sql);
$orderData = $orderResult->fetch_array();
$orderDate = $orderData[0];
$clientName = $orderData[1];
$clientAddress = $orderData[2];
$clientContact = $orderData[3];
$subTotal = $orderData[4];
$vat = $orderData[5];
$totalAmount = $orderData[6];
$discount = $orderData[7];
$grandTotal = $orderData[8];
$paid = $orderData[9];
$due = $orderData[10];
$invoiceNo = $orderData[11];
$orderItemSql = "SELECT order_item.product_id, order_item.rate, order_item.quantity, order_item.total,
product.product_name, order_item.categories_name, order_item.subcategory_name, order_item.brand_name FROM order_item
INNER JOIN product ON order_item.product_id = product.product_id
WHERE order_item.order_id = $orderId";
$orderItemResult = $connect->query($orderItemSql);
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
?>
<table border="0" cellpadding="5" style="width:100%;font-size:10px;border:0px solid black;text-align:center;margin-bottom:15px;">
<thead>
<tr>
<th colspan="2">
<img style="float:left" src="assests/images/logo.jpg" width="80"/>
</th>
<th></th>
<th colspan="5">
<div>
<div style="font-size:14px; text-align:right; font-weight:bold">Sylhet Gym Supplements & Online Store</div>
<div style="font-size:8px; text-align:right; font-weight:normal; line-height:10px; padding:4px 0 4px 30px">One of the best UK and USA suppliers in Gym Food Supplements to support A healthy lifestyle. We supply To retailer Bodybuilding.com supplement Online Market, Sylhet, Bangladesh</div>
<div style="font-size:9px; text-align:right; font-weight:normal">R.B Complex (Level-4), East Zindabazar, Sylhet</div>
<div style="font-size:9px; text-align:right; font-weight:normal; line-height:18px">Cell: 01725-275252</div>
</div>
</th>
</tr>
<tr>
<th colspan="8" style="text-align:left;margin-left:0;padding-left:0"><span style="font-size:10px;background-color:#000;color:#fff;padding:2px 15px 4px">Invoice Details</span></th>
</tr>
<tr>
<th colspan="4" bgcolor="#f4f4f4" style="padding:5px 15px; text-align:left"><b>Mr. <?php echo $clientName; ?><b><br><p style="font-weight:normal;line-height:14px;"><?php echo $clientAddress; ?><br><?php echo $clientContact; ?></p></th>
<th colspan="4" bgcolor="#f4f4f4" style="line-height:14px;padding:5px 15px; font-weight:normal;text-align:right">Invoice No : <b><?php echo $invoiceNo; ?></b><br>Invoice Date : <b><?php echo $orderDate; ?></b><br><br>Paid Amount : Tk <span style="font-size:12px;font-weight:bold"><?php echo $paid; ?></span> Only</th>
</tr>
<tr>
<th colspan="8"></th>
</tr>
</thead>
<tbody>
<tr>
<th bgcolor="#f4f4f4">Sl.</th>
<th bgcolor="#f4f4f4" colspan="4" style="text-align:center">Product Description</th>
<th bgcolor="#f4f4f4" style="width:80px">Rate</th>
<th bgcolor="#f4f4f4" style="width:80px">Qty</th>
<th bgcolor="#f4f4f4" style="text-align:right;width:80px">Total</th>
</tr>
<?php
$x = 1;
while($row = $orderItemResult->fetch_array()) {
?>
<tr>
<th style="font-size:9px; font-weight:normal;"><?php echo $x; ?></th>
<th colspan="2" style="font-size:10px; font-weight:bold; text-transform:uppercase; text-align:left"><?php echo $row[4]; ?></th>
<th colspan="2" style="font-size:9px; font-weight:normal; text-align:left">A Product of <b><?php echo $row[7]; ?></b><br>It\'s Flavor is <b><?php echo $row[5]; ?></b> (<?php echo $row[6]; ?>)</th>
<th style="font-size:9px; font-weight:normal;"><?php echo $row[1]; ?></th>
<th style="font-size:9px; font-weight:normal;"><?php echo $row[2]; ?></th>
<th style="font-size:9px; font-weight:normal;text-align:right"><?php echo $row[3]; ?></th>
</tr>
<?php
$x++;
} // /while
?>
<tr>
<th></th>
</tr>
<tr>
<th colspan="8" style="border-top:1px solid #eee"></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th colspan="3" style="font-size:9px; font-weight:bold; line-height:8px; text-align:right">Total Amount</th>
<th style="font-size:9px; font-weight:normal; line-height:8px; text-align:right"><?php echo $totalAmount; ?></th>
</tr>
<tr>
<?php
if ($due > 0) {
echo '<th colspan="3" style="border:1px solid #ccc">Condition : '.$due.' Tk will be T.T</th>';
} else {
echo '<th colspan="3"></th>';
}
?>
<th></th>
<th colspan="3" style="font-size:9px; font-weight:bold; line-height:8px; text-align:right">Discount</th>
<th style="font-size:9px; font-weight:normal; line-height:8px; text-align:right"><?php echo $discount; ?></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th colspan="3" style="font-size:9px; font-weight:bold; line-height:8px; text-align:right">Grand Total</th>
<th style="font-size:9px; font-weight:normal; line-height:8px; text-align:right"><?php echo $grandTotal; ?></th>
</tr>
<tr>
<th colspan="8" bgcolor="#f4f4f4" style="text-align:right;text-transform:capitalize">Amount (In Words) : <?php echo $f->format($grandTotal); ?> Taka Only.</th>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="8" style="position:absolute; width:100%; bottom:50px;"><span style="float:left;border-top:1px solid #ccc"> Customer Signature </span><span style="float:right;border-top:1px solid #ccc;margin-right:20px"> For Sylhet Gym Supplements </span></th>
</tr>
<tr>
<th colspan="8" style="background-color: #eee; color: #555; position:absolute; width:100%; height:9px; line-height:9px; bottom:0; font-size: 7px">Powered By 7CoderIT. For assistance call on 01744-123456</th>
</tr>
</tfoot>
</table>
<?php
$connect->close();
?>
我已经完成了几件事来实现自己的愿望。之后,代码如上。
答案 0 :(得分:0)
只需检查正确的到期值,我假设您得到到期金额0或为null或某个值
<?php
if($due>0&&$due!=""){
?>
<tr>
<th colspan="2"><?php echo $due; ?></th>
</tr>
<?php
}
?>
如果您的$ due变量不能帮助您确定,则检查确定该到期部分的变量,将到期部分包括在if条件中,例如以下内容(通用PHP)
if(condition){ //this tr will be printed only if your condition will be true.
echo '<tr>.....</tr>';
}
更新:在表中显示条件行的示例
单个PHP文件
<?php
$total_amount = 100;
$due = 20;
$data = array();
?>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach($data as $d){
?>
<tr>
<td></td>
<td></td>
</tr>
<?php
}
?>
<tr>
<th colspan="2"><?php echo $total_amount ?></th>
</tr>
<?php
if($due>0&&$due!=""){
?>
<tr>
<th colspan="2"><?php echo $due; ?></th>
</tr>
<?php
}
?>
</tbody>
</table>
使用td和th的colspan属性来匹配表中的列数。