Jump to content

Loop screen print overlap


sraidr69

Recommended Posts

I am encountering something I've never seen before.  I have a foreach loop where I print out an invoice, it's a loop because there are weekly recurring invoices and I am using the webpage to print them.  The issue is that once the loop repeats the screen output does not continue where the printout ends, it reprints over itself. 

 

I used "<div style='page-break-before:always;'>" at the end of the loop but that did nothing until I moved it up 1 </div> which screws up the top of the invoice.  I have also used "flush()" with no effect.

 

I originally wanted to use libreoffice writer but could not get any connection to work.  Any ideas on why this is happening?

</div>

<div style='page-break-before:always;'>

</div>


<?php flush();
}
?>
<!-- End Invoice Loop -->

Keith

Link to comment
Share on other sites

<link rel="stylesheet" type="text/css" href="style_invoice.css">
<?php
    session_start();
    //ini_set('display_errors', 1);
    //ini_set('display_startup_errors', 1);
    //error_reporting(E_ALL);
    include_once "db.php";
    
    if(!empty($_GET['pg'])) {$pg=$_GET['pg'];}
    if(!empty($_POST['pg']))  {$pg=$_POST['pg'];}
    //echo $_GET['rec'];
?>

<style>


</style>



<!-- Start Invoice Loop -->
<?php
$str="Select * From orders Where delivery_date = '0000-00-00' Order by `idorders`";
$qry = $pdo->prepare($str);
$qry -> execute();
$rst = $qry->fetchAll();
//echo "ROWCOUNT='" . $qry ->rowCount() . "'";
//echo "TRAYS=" . $rst['order_date'];

$cnt=1;
foreach( $rst as $row ){
    $str="Select * From customers Where idcustomers = " . $row['idcustomers'];
    $qry = $pdo->prepare($str);
   $qry -> execute();
   $cst = $qry->fetch();
   //echo "ROWCOUNT='" . $qry ->rowCount() . "'";
   //echo "CST=" . $qry->rowCount() . "<br>";
   //echo "CNT=" . $cnt; $cnt++;


?>

<div class="logo">logo</div>

<div class="gu">
Greens Unlimited <br>
1138 N Chestnut Ave. <br>
Arlington Heights, Il 60004<br>
(866) 512-2979
</div>

<div class="container">
<div class="tbl_inv_list_hr"></div>
<div style="text-align: right"></div>

<div class="bill_to">
<span class="grays"><b>Bill To</b></span>
  <table class="tbl_bill_to">
    <tr><td><?php echo $cst['business']; ?></td></tr>
    <tr><td><?php echo $cst['baddr']; ?></td></tr>
    <tr><td><?php echo $cst['bcity'] . ", " . $cst['bstate'] . " " . $cst['bzip']; ?></td></tr>
    <tr><td><?php echo "(" . substr($cst['bphone'],0,3) . ") " . substr($cst['bphone'],3,3) . " - " . substr($cst['bphone'],6,4); ?></td></tr>
    <tr><td><?php echo $cst['bemail']; ?></td></tr>
    
  </table>
</div>

<div class="invoice">
  <table class="tbl_invoice">
    <tr><td class="tbl_invoice_h">Invoice #:</td>
        <td class="tbl_invoice_l">123456789</td></tr>  
    <tr><td class="tbl_invoice_h">Order Date:</td>
        <td class="tbl_invoice_l"><?php echo $row['order_date']; ?></td></tr>  
    <tr><td class="tbl_invoice_h">Delivery Date:</td>
        <td class="tbl_invoice_l"><?php echo $row['delivery_date']; ?></td></tr>  
    <tr><td class="tbl_invoice_h">Paid Date:</td>
        <td class="tbl_invoice_l"><?php echo $row['paid_date']; ?></td></tr>  
    <tr><td class="tbl_invoice_h">Amount Due:</td>
        <td class="tbl_invoice_l">$<?php echo number_format($row['amount_due'],2); ?></td></tr>  
  </table>

</div>

<div class="inv_list">
  <table class="tbl_inv_list">
    <tr><th class="inv_list_1" align=left >Items</th>
        <th class="inv_list_c">Quantity</th>
        <th class="inv_list_r">Price</th>
        <th class="inv_list_r">Amount</th></tr>
    
    <?php
    $total=0;
    if ($row['bibblettuce'] > 0) {?>
    <tr><td class="inv_list_1">Bibb Lettuce</td>
        <td class="inv_list_c"><?php echo $row['bibblettuce']; ?></td>
        <td class="inv_list_r">$<?php echo number_format($row['price_bibblettuce'],2); ?></td>
        <td class="inv_list_r">$<?php echo number_format($row['price_bibblettuce']*$row['bibblettuce'],2); ?></td></tr>
    <?php
    $total=$total + ($row['price_bibblettuce']*$row['bibblettuce']);
    }
    
    if ($row['wheatgrass'] > 0) {?>
    <tr><td class="inv_list_1">Wheatgrass</td>
        <td class="inv_list_c"><?php echo $row['wheatgrass']; ?></td>
        <td class="inv_list_r">$<?php echo number_format($row['price_wheatgrass'],2); ?></td>
        <td class="inv_list_r">$<?php echo number_format($row['price_wheatgrass']*$row['wheatgrass'],2); ?></td></tr>
    <?php
    $total=$total + ($row['price_wheatgrass']*$row['wheatgrass']);
    }
       
    if ($row['mg_hotandspicy'] > 0) {?>
    <tr><td class="inv_list_1">Microgreens: Hot & Spicy</td>
        <td class="inv_list_c"><?php echo $row['mg_hotandspicy']; ?></td>
        <td class="inv_list_r">$<?php echo number_format($row['price_mg_hotandspicy'],2); ?></td>
        <td class="inv_list_r">$<?php echo number_format($row['price_mg_hotandspicy']*$row['mg_hotandspicy'],2); ?></td></tr>
    <?php
    $total=$total + ($row['price_mg_hotandspicy']*$row['mg_hotandspicy']);
    }?>    
        
    <tr><td colspan="4" class="tbl_inv_list_hr"></td></tr>
    
    
    
    <tr><td></td>
        <td class="inv_list_r">Tray Return:</td>
        <td class="inv_list_r"><?php echo $row['tray_returned']; ?></td>
        <td class="inv_list_r">$<?php echo $row['tray_returned']; ?>     </td></tr>
        <?php $total = $total - $row['tray_returned']; ?>
    
    <tr><td colspan="3"></td><td class="tbl_inv_list_hr"></td></tr>
    
    <tr><td></td>
        <td class="inv_list_r"><b>Total Due:</b></td>
        <td></td>
        <td class="inv_list_r"><b>$<?php echo number_format($total, 2); ?></b></td></tr>
    
  </table>

</div>

<div style='page-break-before:always;'>

</div>


<?php flush();
}
?>
<!-- End Invoice Loop -->
 

Link to comment
Share on other sites

The PHP code is irrelevant: it happens on the server and your problem is on the client.

 

What is the full HTML of an example invoice? If you don't want to include the CSS then fine, but when I can't reproduce the problem with just the HTML then I'm going to ask for it too.

Link to comment
Share on other sites

Sorry, I forgot that I split it out.  Here is the CSS...

 

body {margin-left: 0px; margin-right: 0px;}
.container {
    position: absolute;
    margin-top: 100px;
    width: 100%;
}

#hdr {

}

.logo {
    \\background-color: red;
    height: 75px;
    position: absolute;
    left: 0px;
    margin-bottom: 100px;   
}

.gu {
    position: absolute;
    right: 0px;
    height: 75px;
    width: 300px;
    //background-color: #b0e0e6;
    text-align: right;
}

.bill_to {
    position: absolute;
    left: 0px;
    height: 125px;
    width: 300px;
    \\background-color: blue;
}

.invoice {
    position: absolute;
    right: 0px;
    height: 125px;
    width: 250px;
    \\background-color: blue;
}

.tbl_bill_to {
    font-size: 85%;
}
.tbl_invoice {
    font-size: 85%;
}
.tbl_invoice_h {
    text-align: right;
    color: #848484;}
.tbl_invoice_l {
     text-align: left;
}

.grays {color: #848484; font-size: 77%;}
hr { width:100%; height:3px; background: #848484; }

.inv_list {margin-top: 150px;}
.inv_list_1 {width: 50%;}
.inv_list_c {text-align: center;}
.inv_list_r {text-align: right;}

.tbl_inv_list {
    border-collapse: collapse;
    width: 100%;
}
.tbl_inv_list th {
    background-color: #0B2161;
    color: #848484;
}
.tbl_inv_list_hr {height: 3px; background-color: #848484;}

Link to comment
Share on other sites

Still wanted the full HTML but at least I see the problem:

 

You're using a bunch of position:absolutes everywhere and that can easily mess everything up. Specifically, you've done it on the .container and aren't positioning those relative to a parent, which means they'll all observe the implied left:0 top:0 and move to the top of the document/page.

 

Looks like you want to use that to position the child elements? Do position:relative instead: it allows you to position children absolutely (relative to the container) while keeping the element in its original location.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.