function bill_select_pos()
{
    /*
    name:
    bill_select_pos()
    returns:
    0 - no error
    1 - generic dish with no price found
    2 - internal error clearing prices
    3 - 
    other - mysql error number
    */
    global $tpl;
    if (!bill_orders_to_print($_SESSION['sourceid'])) {
        printing_choose_pos(true);
        return 0;
    }
    $tpl->set_waiter_template_file('bill_select_pos');
    $script = "<script language=\"JavaScript\" type=\"text/javascript\">\r\n\t\t\$(document).ready(function(){\r\n\t\t\t\$('#tabContent>li:gt(0)').hide();\r\n\t\t\t\$('#tabsNav li:first').addClass('active');\r\n\t\t\t\$('#tabsAndContent #tabsNav li').bind('click', function() {\r\n\t\t\t\t\$('li.active').removeClass('active');\r\n\t\t\t\t\$(this).addClass('active');\r\n\t\t\t\tvar target = \$('a', this).attr('href');\r\n\t\t\t\t\$(target).slideDown(\"fast\").siblings().slideUp(\"fast\");\r\n\t\t\t\treturn false;\r\n\t\t\t});\r\n\t\t});\t\r\n\t</script>";
    $tpl->assign('script', $script);
    $_SESSION['bill_printed'] = 0;
    if (order_found_generic_not_priced($_SESSION['sourceid'])) {
        return ERR_GENERIC_ORDER_NOT_PRICED_FOUND;
    }
    $keep_separated = bill_check_keep_separated();
    if ($keep_separated == 1) {
        $tmp = navbar_separatebills_pos('form_type', 'orders.php?command=printing_choose');
        $tpl->assign('navbar', $tmp);
    } else {
        $tmp = navbar_form_pos('form_type', 'orders.php?command=printing_choose');
        $tpl->assign('navbar', $tmp);
    }
    if ($err = bill_clear_prices($_SESSION['sourceid'])) {
        return $err;
    }
    if ($err = bill_save_session($_SESSION['sourceid'])) {
        return $err;
    }
    $tmp = bill_method_selector();
    $tpl->assign('method', $tmp);
    $tmp = bill_type_selection_pos($_SESSION['sourceid']);
    $tpl->assign('type', $tmp);
    $tmp = discount_form_javascript($_SESSION['sourceid']);
    $tpl->assign('discount', $tmp);
    $tmp = bill_show_list();
    $tpl->assign('orders', $tmp);
    return 0;
}
function printing_commands()
{
    $output = '';
    $sourceid = $_SESSION['sourceid'];
    if (printing_orders_to_print($sourceid)) {
        $output .= '<a href="orders.php?command=print_orders">' . ucfirst(phr('PRINT_ORDERS')) . '</a><br />' . "\n";
        $output .= '<br />';
    }
    if (printing_orders_printed_category(2)) {
        $output .= '<a href="orders.php?command=print_category&amp;data[category]=2">' . ucfirst(phr('PRINT_GO_2')) . '</a><br />' . "\n";
        $output .= '<br />';
    }
    if (printing_orders_printed_category(3)) {
        $output .= '<a href="orders.php?command=print_category&amp;data[category]=3">' . ucfirst(phr('PRINT_GO_3')) . '</a><br />' . "\n";
        $output .= '<br />';
    }
    if (bill_orders_to_print($_SESSION['sourceid'])) {
        $output .= "<a href=\"orders.php?command=bill_select\">" . ucfirst(phr('PRINT_SEPARATED_BILLS')) . "</a><br />\n";
    }
    $user = new user($_SESSION['userid']);
    if ($user->level[USER_BIT_CASHIER]) {
        $output .= '
	<br />
	<a href="orders.php?command=bill_reset">(' . ucfirst(phr('RESET_SEPARATED')) . ')</a><br />
	<br />
	';
        if (bill_orders_to_print($_SESSION['sourceid'])) {
            $output .= '
	<a href="orders.php?command=bill_select_all">' . ucfirst(phr('PRINT_BILL')) . '</a><br />
	';
        }
    }
    return $output;
}
function table_closed_interface_pos()
{
    global $tpl;
    date_default_timezone_set(get_conf(__FILE__, __LINE__, "default_timezone"));
    if (bill_orders_to_print($_SESSION['sourceid'])) {
        $_SESSION['select_all'] = 1;
        $err = bill_select_pos();
        if ($err) {
            error_display($err);
        }
        return 0;
    }
    $tpl->set_waiter_template_file('closed_table_pos');
    $paid = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'sources', "paid", $_SESSION['sourceid']);
    $total = table_total($_SESSION['sourceid']);
    $discount = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'sources', 'discount', $_SESSION['sourceid']);
    if ($total == 0 && $paid == 0) {
        $err = table_pay(1);
        status_report('PAYMENT', $err);
        $paid = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'sources', "paid", $_SESSION['sourceid']);
    }
    $tmp = navbar_tables_only_pos();
    $user = new user($_SESSION['userid']);
    if ($user->level[USER_BIT_CASHIER]) {
        $tmp = navbar_empty_pos();
    }
    $tpl->assign('navbar', $tmp);
    $tmp = '
		' . ucfirst(phr('TABLE_TOTAL_DISCOUNTED')) . ': <b>' . country_conf_currency(true) . ' ' . $total . '</b>
	';
    if ($discount != 0) {
        $discount = sprintf("%01.2f", abs($discount));
        $tmp .= '
		 (' . ucfirst(phr('DISCOUNT')) . ': ' . country_conf_currency(true) . ' ' . $discount . ')';
    }
    $tmp .= '<br />' . "\n";
    $tpl->assign('total', $tmp);
    if ($paid) {
        $tmp = '
		<FORM ACTION="orders.php" METHOD=POST>
		<INPUT TYPE="HIDDEN" NAME="command" VALUE="clear">
		' . ucfirst(phr('PAID_ALREADY')) . '<br/>
		' . ucfirst(phr('EMPTY_TABLE_EXPLAIN')) . '
		<INPUT TYPE="submit" value="' . ucfirst(phr('EMPTY_TABLE_BUTTON')) . '">
		</FORM>
		';
        $tmp .= '<br />' . "\n";
        $tpl->assign('clear', $tmp);
    }
    // user is not allowed to pay, so don't display the button
    if (!access_allowed(USER_BIT_MONEY)) {
        return 0;
    }
    $tmp = '
		<FORM ACTION="orders.php" METHOD=POST>
		<INPUT TYPE="HIDDEN" NAME="command" VALUE="pay">
		' . ucfirst(phr('PAID_ASK')) . '<br/>
		';
    if ($paid) {
        $tmp .= '
		<INPUT TYPE="hidden" name="data[paid]" value="0">
		<INPUT TYPE="submit" value="' . ucfirst(phr('NOT_PAID_BUTTON')) . '">
		<br/><br/>';
    } else {
        $tmp .= '
		<INPUT TYPE="hidden" name="data[paid]" value="1">
		<INPUT TYPE="submit" value="' . ucfirst(phr('PAID_BUTTON')) . '">
		<br/><br/>';
    }
    $tmp .= '
		</FORM>';
    $tmp .= '<br />' . "\n";
    $tpl->assign('pay', $tmp);
    return 0;
}