require_once "DataBase/Bill.php";
require_once "DataBase/Assistant.php";
require_once "DataBase/Customer.php";
require_once "DataBase/Product.php";
require_once "DataBase/Bill_Product.php";
require_once "DataBase/Price.php";
require_once "DataBase/Priceset.php";
require_once "DataBase/Tax.php";
$bill_id = var_get_post("bill_id", "");
$bill = new Bill();
$tmp = $bill->get($bill_id);
$bill_data = $tmp[0];
$customer = new Customer();
$tmp = $customer->get($bill_data[1]);
$customer_data = $tmp[0];
$assistant = new Assistant();
$tmp = $assistant->get($bill_data[4]);
$assistant_data = $tmp[0];
$priceset = new Priceset();
$tmp = $priceset->get($customer_data[11]);
$priceset_data = $tmp[0];
$bill_product = new Bill_Product();
$bill_product_data = $bill_product->getByBillId($bill_id);
$product = new Product();
$price = new Price();
$tax = new Tax();
include "Druckvorlagen/zeilen.php";
include "Druckvorlagen/rechnung.php";
?>

    $data = $tour->get($tour_id);
    include "Modules/Tour/edit_form.php";
} elseif ($action == "search" && var_post("search_entry", "") != "") {
    $search = var_post("search_entry", "");
    $list_view = new NTKListView("list_view", array('Tournummer', 'Bezeichner'), "location.href = 'tour.php?action=edit&tour_id=%0%';");
    $list_view->addLines($tour->get('', array('tour_id', 'name'), "tour_id LIKE '%{$search}%' OR name LIKE'%{$search}%'"));
    $main_box->add($list_view, -1, -1, "background-color: #dfe7f3; vertical-align: top;");
} elseif ($action == "list_tour") {
    $assistant = new Assistant();
    $tour = new Tour();
    $bill_box = new NTKHBox("bill_box", 0, 0);
    $bill_box->add(new NTKLabel("", "<b>Tournummer: " . $tour_id . " - Datum: " . $datum . "</b>"), False, False, "background-color: #dfe7f3;");
    $bill_box->add(new NTKLabel("", "Kundennummer:"), 150);
    $bill_box->add(new NTKEntry("customer_id", ""), 120);
    $bill_box->add(new NTKLabel("", "Mitarbeiter:"), 120);
    $bill_box->add(new NTKComboBox("assistant_id", $assistant->get()), 120);
    $bill_box->add(new NTKLabel("", "Tour:"), 80);
    $bill_box->add(new NTKComboBox("tour_id", $tour->get()), 120);
    $bill_box->add(new NTKButton("bill_button", "Erstelle Rechnung", "document.forms['bill_form'].submit();"), 200);
    $bill_form = new NTKForm("bill_form", "tour.php", $bill_box);
    $bill_form->addAttribute("db_action", "tour_to_bill");
    $bill_form->addAttribute("date", $datum);
    $bill_form->addAttribute("current_tour_id", $tour_id);
    $main_box->add($bill_form, 0, 0, "background-color: #dfe7f3; vertical-align: top;");
    $list_view = new NTKListView("list_view", array('Rechnungsnummer', 'Kunde'), "location.href = 'bill.php?from_page=tour&fp_tour_id={$tour_id}&fp_date=" . $datum . "&action=edit&bill_id=%0%';");
    $list_view->addLines($bill->get('', array('bill_id', 'bill.customer_id'), "bill.tour_id='{$tour_id}' AND date='" . $datum . "'"));
    $main_box->add($list_view, -1, -1, "background-color: #dfe7f3; vertical-align: top;");
} else {
    $list_view = new NTKListView("list_view", array('Tournummer', 'Bezeichner'), "location.href = 'tour.php?action=edit&tour_id=%0%';");
    $list_view->addLines($tour->get('', array('tour_id', 'name')));
    $main_box->add($list_view, -1, -1, "background-color: #dfe7f3; vertical-align: top;");
    if ($var_product_id_from) {
        if ($search) {
            $search .= " AND (product_id >=" . $var_product_id_from . ") ";
        } else {
            $search .= "(product_id >=" . $var_product_id_from . ") ";
        }
    }
    if ($var_product_id_to) {
        if ($search) {
            $search .= " AND (product_id <=" . $var_product_id_to . ") ";
        } else {
            $search .= "(product_id <=" . $var_product_id_to . ") ";
        }
    }
    $product_data = $product->get('', array(), $search);
    $assistant_data = $assistant->get($var_assistant);
    $priceset = new Priceset();
    $tmp = $priceset->get($var_priceset);
    $priceset_data = $tmp[0];
    include "Druckvorlagen/zeilen.php";
    include "Druckvorlagen/list.php";
} elseif ($var_print == "print_re") {
    $search = "";
    if ($var_product_id) {
        if ($search) {
            $search .= " AND (product_id >=" . $var_product_id . ") ";
        } else {
            $search .= "(product_id >=" . $var_product_id . ") ";
        }
    }
    if ($var_date_from) {