function createBill()
 {
     $bill = new Bill();
     $customer = new Customer();
     $tour = new Tour();
     $bill_product = new Bill_Product();
     $customer_data = $customer->get($this->customer_id);
     if (count($customer_data) == 0) {
         echo "<div class=\"error\">Fehler in Session, bitte neu anmelden</div><br>\n";
         return -1;
     }
     $tour_data = $tour->getByAssistant($customer_data[0][12]);
     $bill_id = $bill->create("", array($this->customer_id, $customer_data[0][12], "", $tour_data[0][2], -2, time()));
     $list = $this->getItems();
     for ($i = 0; $i < count($list); $i++) {
         if ($list[$i][2] > 0) {
             $bill_product->create(array($bill_id, $list[$i][0], $list[$i][2], $list[$i][5], "", 0, 0, time()));
         }
     }
     return 0;
 }
<?php

require_once "DataBase_Net/Bill_Net.php";
require_once "DataBase_Net/Bill_Product_Net.php";
require_once "DataBase/Bill.php";
require_once "DataBase/Bill_Product.php";
// sync Bill database
$bill = new Bill();
$bill_net = new Bill_Net();
$bill_product = new Bill_Product();
$bill_product_net = new Bill_Product_Net();
$new_bills_count = 0;
$new_position_count = 0;
// fetch all remote bills
$remote_bills = $bill_net->getPlainBills();
foreach ($remote_bills as $tmp) {
    $new_bill_id = $bill->create("", array_slice($tmp, 1));
    $new_bills_count++;
    // check for bill_products
    $remote_bill_products = $bill_product_net->getByBillId($tmp[0]);
    foreach ($remote_bill_products as $tmp1) {
        $tmp1[1] = $new_bill_id;
        $bill_product->create(array_slice($tmp1, 1));
        $new_position_count++;
    }
}
$main_box->add(new NTKLabel("", "neue Rechnungen: " . $new_bills_count), 200, 0, "background-color: #dfe7f3;");
$main_box->add(new NTKLabel("", "neue Positionen: " . $new_position_count), 200, 0, "background-color: #dfe7f3;");
// now we should have added all bills let's delete them remote
$bill_net->clearTable();
$bill_product_net->clearTable();
require_once "DataBase/Assistant.php";
require_once "DataBase/Bill_Product.php";
$db_action = var_get_post("db_action", "");
$tour = new Tour();
$bill = new Bill();
$assistant = new Assistant();
switch ($db_action) {
    case "new":
        $tour->create(array(var_post("name", ""), var_post("assistant_id", "")));
        break;
    case "edit":
        $tour->update(var_post("tour_id", ""), array(var_post("name", ""), var_post("assistant_id", "")));
        break;
    case "delete":
        $tour->delete(var_get("tour_id", ""));
        break;
    case "tour_to_bill":
        $tour = new Tour();
        $tmp = $tour->get(var_get("tour_id", ""));
        $tour_data = $tmp[0];
        $bill = new Bill();
        $new_bill_id = $bill->create('', array(var_post("customer_id", ""), var_post("tour_id", ""), var_post("date", ""), var_post("assistant_id", ""), -1, 0));
        $bill_product = new Bill_Product();
        $product = new Product();
        $product_data = $product->get();
        $result = $bill_product->getTourZusammenfassung(var_post("current_tour_id", ""), var_post("date", ""));
        for ($i = 0; $i < count($result); $i++) {
            $bill_product->create(array($new_bill_id, $result[$i][0], $result[$i][2], '', '', '', ''));
        }
        break;
}
    if ($bill_import->import("mysql_import/bill.csv") == 0 && $bill_product_import->import("mysql_import/bill_product.csv") == 0) {
        /* import bills from bill_import and products from bill_product_import */
        $bills = $bill_import->get();
        for ($i = 0; $i < count($bills); $i++) {
            if (!$bill->hasTimestamp($bills[$i][6])) {
                $customer_data = $customer->get($bills[$i][1]);
                if (count($customer_data) == 0) {
                    echo "Fehler: websync.php import bills from bill_import no customer data";
                    continue;
                }
                $tour_data = $tour->get($customer_data[0][12]);
                $date = getdate(time());
                $new_bill_id = $bill->create("", array($bills[$i][1], $customer_data[0][12], $date['year'] . "-" . $date['mon'] . "-" . $date['mday'], $tour_data[0][2], -2, $bills[$i][6]));
                $bill_products = $bill_product_import->getByBillId($bills[$i][0]);
                for ($j = 0; $j < count($bill_products); $j++) {
                    $bill_product->create(array($new_bill_id, $bill_products[$j][2], $bill_products[$j][3], $bill_products[$j][4], 0, 0, 0));
                }
            }
        }
        $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
        $main_box->add(new NTKLabel("", "Fertig"), False, False, "font-style: bold; background-color: #dfe7f3;");
        $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
    } else {
        $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
        $main_box->add(new NTKLabel("", "neue Bestellungen laden schlug fehl.<br>In ein paar Minuten nochmal versuchen."), False, False, "color: #ff0000; font-style: bold; background-color: #dfe7f3;");
        $main_box->add($spacer, True, True, "background-color: #dfe7f3;");
    }
} else {
    // small Toolbar
    include "Modules/Websync/toolbar.php";
    // main content
    case "delete":
        $bill->delete(var_get("bill_id", ""));
        if ($fp_tour_id != "") {
            $onload .= "location.href = 'tour.php?action=list_tour&tour_id=" . $fp_tour_id . "&date=" . $fp_date . "';";
        }
        break;
    case "position_add":
        $bill_data = $bill->get(var_post("bill_id", ""));
        /* autoset anmerkung vom produkt, wenn nichts als anmerkung gegeben */
        $details = var_post("details", "");
        if ($details == "") {
            $product_data = $product->get(var_post("product_id", ""));
            $details = $product_data[0][8];
        }
        if ($bill_data[0][5] == -1) {
            $bill_product->create(array(var_post("bill_id", ""), var_post("product_id", ""), var_post("amount", ""), $details, var_post("rabatt", ""), 0, 0));
        } else {
            $customer_data = $customer->get($bill_data[0][1]);
            $price_data = $price->getPrice($customer_data[0][11], var_post("product_id", ""));
            $product_data = $product->get(var_post("product_id", ""));
            $tax_data = $tax->get($product_data[0][4]);
            $bill_product->create(array(var_post("bill_id", ""), var_post("product_id", ""), var_post("amount", ""), $details, var_post("rabatt", ""), $price_data[0][3], $tax_data[0][2]));
        }
        break;
    case "position_delete":
        $bill_product->delete(var_get("bill_product_id", ""));
        break;
    case "position_edit":
        $bill_product->update(var_post("bill_product_id", ""), array(var_post("bill_id", ""), var_post("product_id", ""), var_post("amount", ""), var_post("details", ""), var_post("rabatt", ""), var_post("price", ""), var_post("tax", "")));
        break;
}