use_class('elements_order');
use_class('elements_suppliers');
$oid = tep_db_prepare_input($_GET['id']);
$mode = tep_db_prepare_input($_GET['mode']);
$eo = new elements_order($oid);
$es = new elements_suppliers($eo->suppliers_id);
$po_number = $eo->detail['po_number'] == '' ? $oid : $eo->detail['po_number'];
$currency = $eo->detail['currency'];
//$order_date = ($eo->detail['date_submitted']=='') ? time() : strtotime($eo->detail['date_submitted']);
$order_date = $eo->detail['date_created'] == '' ? time() : 'Date: ' . date('j F Y', strtotime($eo->detail['date_created']));
//$pocode = 'PO '.$eo->detail['suppliers_name'].' '.date('d.m.Y', $order_date);
$is_topup = isset($_GET['print-topup']) && $_GET['print-topup'] == '1' ? true : false;
if ($is_topup) {
    $print_topup = true;
    $items2print = array();
    $receivedBad = $eo->getLastReceivedBad();
    foreach ($receivedBad as $eoi_id => $rb) {
        $item = $eo->items[$eoi_id];
        $item['quantity'] = $rb['quantity_bad'];
        $items2print[] = $item;
    }
    $pocode = 'PO ' . $po_number . ' TPP   (' . $eo->detail['suppliers_name'] . ')';
} else {
    $print_topup = false;
    $items2print = $eo->items;
    $pocode = 'PO ' . $po_number . ' (' . $eo->detail['suppliers_name'] . ')';
}
if (count($items2print) == 0) {
    echo "<h1>No Last Received Bad Elements in this PO.<br />There's no need to print Top Up List</h1>";
    exit;
}