function showOrderOrder($order, $page_id, $oid, $edit, $showEditButton)
{
    global $SETTINGS;
    $retval = "";
    $retval .= "<tr><th style=\"text-align:center\">QTY</th>";
    $retval .= "<th>Item</th>";
    $retval .= "<th>Personality</th>";
    $retval .= "<th style=\"text-align:right\">Price</th></tr>";
    $items = dbGetItems($oid);
    $packages = dbGetPackages();
    $pieces = dbGetPieces();
    $total = 0;
    $totalItems = 0;
    foreach ($items as $item) {
        $qty = $item["Quantity"];
        $retval .= "<tr><td style=\"text-align:center\"><strong>" . $qty . "</strong></td>";
        $retval .= "<td><strong>" . findPackageName($item["PKID"], $packages) . "</strong></td>";
        $retval .= "<td><strong>" . findPieceName($item["Personality"], $pieces) . "</strong></td>";
        $price = findPackagePrice($item["PKID"], $packages) * $qty;
        $retval .= "<td style=\"text-align:right\"><strong>" . number_format($price, 2) . "</strong></td>";
        $total += $price;
        $totalItems += $qty;
    }
    $totalTotal = $total;
    $retval .= "</tr>\n";
    $retval .= "<tr class=\"total\"><td></td><td></td>" . "<td style=\"text-align:right;\">ITEMS TOTAL</td>" . "<td style=\"text-align:right\">\$ <strong>" . number_format($total, 2) . "</strong></td></tr>\n";
    // note that the shipping calculation is very simple here -
    // and should really be based upon some kind of "weight" or something
    // Note, by-the-way, that this doesn't SET the shipping in the data record
    // that is only "locked in" when the order is invoiced.
    $shipping = $order["ShippingFee"];
    if ($shipping === null) {
        $shipping = $totalItems * $SETTINGS["ShippingPerChapR"];
    }
    $retval .= "<tr><td></td><td></td><td style=\"text-align:right;\">Shipping";
    if ($order["ShippingFee"] == null) {
        $retval .= " (default)";
    }
    $retval .= "</td><td style=\"text-align:right\"><strong>" . number_format($shipping, 2) . "</strong></td></tr>\n";
    $totalTotal += $shipping;
    if ($order["IsExpedited"]) {
        // expedite is much like shipping, although it is just a static figure
        // it is "locked in" when the order is invoiced.
        $expedite = $order["ExpediteFee"];
        if ($expedite === null) {
            $expedite = $SETTINGS["ExpediteFeeDefault"];
        }
        $retval .= "<tr><td></td><td></td><td style=\"text-align:right;\">Expedite Fee";
        if ($order["ExpediteFee"] == null) {
            $retval .= " (default)";
        }
        $retval .= "</td><td style=\"text-align:right\"><strong>" . number_format($expedite, 2) . "</strong></td></tr>\n";
        $totalTotal += $expedite;
    }
    if ($order["Discount"]) {
        // discounts only show up if they exist
        $discount = $order["Discount"];
        $retval .= "<tr><td></td><td></td><td style=\"text-align:right;\">Discount";
        $retval .= "</td><td style=\"text-align:right\"><strong>-" . number_format($discount, 2) . "</strong></td></tr>\n";
        $totalTotal -= $discount;
    }
    $retval .= "<tr><td></td><td></td><td style=\"text-align:right;\"><strong>TOTAL</strong></td><td style=\"text-align:right\">\$ <strong>" . number_format($totalTotal, 2) . "</strong></td></tr>\n";
    $retval .= "<tr><td>&nbsp;</td></tr>";
    $retval .= "<tr><td style=\"vertical-align:top;text-align:right;\">Notes:</td>\n";
    $retval .= "<td colspan=3><strong>" . htmlNotesFormat($order["CustomerONotes"]) . "</strong></td></tr>\n";
    $retval .= "<tr><td style=\"vertical-align:top;text-align:right;\">Admin Notes:</td>\n";
    $retval .= "<td colspan=3><strong>" . htmlNotesFormat($order["AdminONotes"]) . "</strong></td></tr>\n";
    $retval .= "<tr><td>&nbsp;</td></tr>";
    $retval .= "<tr><td colspan=\"4\" style=\"text-align:right\">";
    if ($showEditButton) {
        $retval .= "<a href=\"{$edit}&OID={$oid}\">Edit</a>";
    } else {
        $retval .= "<em>Payment requested, editing not allowed</em>";
    }
    $retval .= "</td></tr>";
    return $retval;
}
function main($oid)
{
    // a packing list has all of the standard stuff on it, including
    // the order number, customer, address, but no price information.
    // it combines multiple items into one NUMBERED item along with the
    // stuff that should go into it.  It also includes a field for
    // notes that then need to be transcribed to shipping.
    $order = dbGetOrder($oid);
    $items = getItems($oid);
    $mapping = dbGetPVP();
    $pieces = dbGetPieces();
    if (!$order) {
        echo "Can't find order {$oid}\n";
        return;
    }
    $customer = dbGetCustomer($order["CID"]);
    if (!$customer) {
        echo "Can't find customer for order {$oid}\n";
        return;
    }
    // set-up the PDF output mechanism
    $pdf = pdfSetup();
    // and craft the coordinates of the different areas on the page
    $layout = layout();
    // draw the little boxes around the different areas
    plBoxes($pdf, $layout);
    // the go for all of the data
    titleArea($pdf, $layout["title"], $oid, $order, $customer, $items, $mapping, $pieces);
    customerArea($pdf, $layout["customer"], $oid, $order, $customer, $items, $mapping, $pieces);
    statusArea($pdf, $layout["status"], $oid, $order, $customer, $items, $mapping, $pieces);
    itemsArea($pdf, $layout["items"], $oid, $order, $customer, $items, $mapping, $pieces);
    shippingArea($pdf, $layout["shipping"], $oid, $order, $customer, $items, $mapping, $pieces);
    dateArea($pdf, $layout["date"], $oid, $order, $customer, $items, $mapping, $pieces);
    $pdf->lastPage();
    $pdf->Output('Order-$oid.pdf', 'I');
}
function getItems($oid)
{
    $items = dbGetItems($oid);
    $packages = dbGetPackages();
    $pieces = dbGetPieces();
    $retarray = array();
    foreach ($items as $item) {
        $row = array();
        $row["Quantity"] = $item["Quantity"];
        $row["Name"] = findPackageName($item["PKID"], $packages);
        $row["Personality"] = findPieceName($item["Personality"], $pieces);
        $row["Price"] = findPackagePrice($item["PKID"], $packages);
        $retarray[] = $row;
    }
    return $retarray;
}
function dbGetPersonalities()
{
    return dbGetPieces(true);
}
function main($oid, $pdflink)
{
    // a packing list has all of the standard stuff on it, including
    // the order number, customer, address, but no price information.
    // it combines multiple items into one NUMBERED item along with the
    // stuff that should go into it.  It also includes a field for
    // notes that then need to be transcribed to shipping.
    $order = dbGetOrder($oid);
    $items = getItems($oid);
    $mapping = dbGetPVP();
    $pieces = dbGetPieces();
    if (!$order) {
        echo "Can't find order {$oid}\n";
        return;
    }
    $customer = dbGetCustomer($order["CID"]);
    if (!$customer) {
        echo "Can't find customer for order {$oid}\n";
        return;
    }
    echo "<div align=\"right\"><font size=\"-2\"><a href=\"{$pdflink}?oid={$oid}\">PDF Version</a></font></div>\n";
    // the whole thing is one big table
    echo "<table class=\"packinglist\">\n";
    // first, the header with "Order: XXX"
    echo "<tr><td class=\"ordertitle\" colspan=\"3\">";
    if ($order["IsExpedited"]) {
        echo standardIcon("expedite") . "&nbsp;&nbsp;";
    }
    if ($order["Charity"]) {
        echo standardIcon("charity") . "&nbsp;&nbsp;";
    }
    echo "Order: <strong>{$oid}</strong>";
    if ($order["Charity"]) {
        echo "&nbsp;&nbsp;" . standardIcon("charity");
    }
    if ($order["IsExpedited"]) {
        echo "&nbsp;&nbsp;" . standardIcon("expedite");
    }
    echo "</td></tr>\n";
    // now paint the "To:" and "Status"
    echo "<tr><td width=\"50%\">\n";
    echo "<table><tr><td class=\"title\" colspan=\"2\"><strong>Customer</strong></td></tr>\n";
    echo htmlCustomerAddress($customer);
    echo "</table></td>\n";
    echo "<td width=\"50%\">\n";
    echo "<table><tr><td class=\"title\" colspan=\"3\"><strong>Status</strong></td></tr>\n";
    //     echo("<tr><td>");
    echo htmlOrderStatus($order);
    //     echo("</td></tr>");
    echo "<tr><td class=\"title\" colspan=\"3\"><strong>Order Notes</strong></td></tr>\n";
    echo "<tr><td colspan=\"3\">" . htmlNotesFormat($order["CustomerONotes"]) . "</td></tr>\n";
    echo "<tr><td colspan=\"3\"><em>" . htmlNotesFormat($order["AdminONotes"]) . "</em></td></tr>\n";
    echo "</table></td>\n";
    echo "</tr>\n";
    // the middle part of the packing list is the actual list of items and components
    echo "<tr><td colspan=2>\n";
    echo "<table class=\"packingItems\">\n";
    echo "<tr><td class=\"title\" colspan=\"3\"><strong>Shipment Items</strong></td></tr>\n";
    echo "<tr><td style=\"border-bottom:1px solid; text-align:center;\"><strong>Count</strong></td>";
    echo "<td style=\"border-bottom:1px solid;\" width=\"50%\"><strong>Item</strong></td>";
    echo "<td style=\"border-bottom:1px solid;\" ><strong>Notes</strong> <em><font size=-1>(include ChapR number(s) if applicable)</font></em></td</tr>\n";
    echo "<tr><td>&nbsp;</td></tr>\n";
    foreach ($items as $item) {
        echo "<tr>";
        echo "<td class=\"qty\">" . $item["Quantity"] . " x</td>";
        echo "<td><p class=\"itemtitle\">" . $item["Name"] . "</p>";
        echo "<UL>";
        if ($item["Personality"]) {
            echo "<LI>" . $item["Personality"] . "</LI>";
        }
        // now get all of the pieces in the package
        foreach ($mapping as $map) {
            if ($map["PKID"] == $item["PKID"]) {
                echo "<LI>" . findPieceName($map["PID"], $pieces) . "</LI>\n";
            }
        }
        echo "</UL></td>";
        echo "<td></td>";
        echo "</tr>";
    }
    echo "</table></td></tr>\n";
    // the bottom part of the packing list is the shipment note section
    echo "<tr><td colspan=2>\n";
    echo "<table class=\"packingShipping\">\n";
    echo "<tr><td class=\"title\" colspan=\"6\"><strong>Shipment Details</strong></td></tr>\n";
    echo "<tr>";
    echo "<td class=\"fieldName\">Date Shipped: </td><td class=\"field\"></td>\n";
    echo "<td class=\"fieldName\">Carrier: </td><td class=\"field\"></td>\n";
    echo "<td class=\"fieldName\">Tracking #: </td><td class=\"field\"></td>\n";
    echo "</tr>";
    echo "</table></td></tr>\n";
    echo "</table>\n";
}