function ingredient($id = 0)
 {
     $this->table = 'ingreds';
     $this->id = $id;
     $this->fields_names = array('id' => ucphr('ID'), 'name' => ucphr('NAME'), 'category' => ucphr('CATEGORY'), 'price' => ucphr('PRICE'), 'quantity' => ucphr('QUANTITY'), 'unit_type' => '', 'value' => ucphr('UNITARY_VALUE') . ' [' . country_conf_currency(true) . ']', 'override_autocalc', 'visible' => ucphr('VISIBLE'), 'sell_price' => ucphr('SELL_PRICE'));
     $this->fields_boolean = array('override_autocalc', 'visible');
     $this->fields_width = array('name' => '100%');
     $this->allow_single_update = array('override_autocalc', 'visible');
     $this->title = ucphr('INGREDIENTS');
     $this->file = ROOTDIR . '/admin/admin.php';
     $this->flag_delete = true;
     $this->show_category_list = true;
     $this->fetch_data();
 }
 function stock_object($id = 0)
 {
     $this->db = 'common';
     $this->table = 'stock_objects';
     $this->id = $id;
     $this->title = ucphr('STOCK');
     $this->referring_name = true;
     $this->flag_delete = true;
     $this->fields_names = array('id' => ucphr('ID'), 'name' => ucphr('NAME'), 'ref_type' => ucphr('TYPE'), 'ref_id' => ucphr('INGREDIENT'), 'unit_type' => '', 'quantity' => ucphr('QUANTITY'), 'value' => ucphr('VALUE') . ' [' . country_conf_currency(true) . ']');
     $this->fields_width = array('name' => '75%');
     $this->hide = array('ref_id');
     $this->file = ROOTDIR . '/include/stock/index.php';
     $this->disable_new = true;
     $this->fetch_data();
 }
 function stock_movement($id = 0)
 {
     $this->db = 'common';
     $this->table = 'stock_movements';
     $this->id = $id;
     $this->title = ucphr('STOCK_MOVEMENTS');
     $this->no_name = true;
     $this->disable_new = true;
     $this->file = ROOTDIR . '/include/stock/index.php';
     $this->main_list_item = 'obj_id';
     $this->hide = array('obj_id', 'dish_id');
     $this->default_orderby = 'timestamp';
     $this->default_sort = 'desc';
     $this->fields_width = array('name' => '40%', 'dish_name' => '40%', 'timestamp' => '20%');
     $this->fields_names = array('id' => ucphr('ID'), 'timestamp' => ucphr('TIME'), 'user_name' => ucphr('WHO'), 'name' => ucphr('NAME'), 'obj_id' => ucphr('OBJECT'), 'dish_name' => ucphr('DISH'), 'dish_quantity' => ucphr('DISH_QUANTITY'), 'quantity' => ucphr('QUANTITY'), 'unit_type' => '', 'value' => ucphr('VALUE') . ' [' . country_conf_currency(true) . ']', 'user' => ucphr('USER'));
     $this->fetch_data();
 }
function dishes_list_search($data)
{
    $output = '';
    $search = strtolower(trim($data['search']));
    if (empty($search)) {
        return '';
    }
    $query = "SELECT dishes.*\n\tFROM `dishes`\n\tWHERE (LCASE(`name`) LIKE '" . $search . "%'\n\t\tOR LCASE(`name`) LIKE '% " . $search . "%'\n\t\t)";
    if (!get_conf(__FILE__, __LINE__, "invisible_show")) {
        $query .= "AND `visible`='1'";
    }
    $query .= "\n\tAND dishes.deleted='0'\n\tORDER BY name ASC";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return '';
    }
    $output .= '<table bgcolor="' . COLOR_TABLE_GENERAL . '">
	<tr>
	<th scope=col>' . ucfirst(phr('ID')) . '</th>
	<th scope=col>' . ucfirst(phr('NAME')) . '</th>
	<th scope=col>' . country_conf_currency(true) . '</th>
	</tr>
	';
    // ascii letter A
    $i = 65;
    unset($GLOBALS['key_binds_letters']);
    while ($arr = mysql_fetch_array($res)) {
        $class = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], "categories", "htmlcolor", $arr['category']);
        $dishcat = $arr['category'];
        $dishid = $arr['id'];
        $dishobj = new dish($arr['id']);
        $dishname = $dishobj->name($_SESSION['language']);
        if ($dishname == null || strlen(trim($dishname)) == 0) {
            $dishname = $arr['name'];
        }
        $dishprice = $arr['price'];
        if ($dishcat > 0) {
            // letters array follows
            if ($i < 91) {
                $GLOBALS['key_binds_letters'][$i] = $dishid;
                $local_letter = chr($i);
                $i++;
            } else {
                $local_letter = '';
            }
            $output .= '<tr>
			<td bgcolor="' . $class . '">' . $local_letter . '</td>';
            $output .= '<td bgcolor="' . $class . '" onclick="order_select(' . $dishid . ',\'order_form\'); return false;"><a href="#" onclick="JavaScript:order_select(' . $dishid . ',\'order_form\'); return false;">' . $dishname . '</a></td>';
            $output .= '<td bgcolor="' . $class . '">' . $dishprice . '</td>
			</tr>';
        }
    }
    $output .= '
	</table>';
    return $output;
}
function discount_form_javascript($sourceid)
{
    $output = '';
    if (isset($_SESSION['discount'])) {
        $percent = $_SESSION['discount']['percent'];
        $amount = -1 * $_SESSION['discount']['amount'];
    } else {
        $percent = 0;
        $amount = 0;
    }
    if (!isset($_SESSION['discount']) || !isset($_SESSION['discount']['type'])) {
        $_SESSION['discount']['type'] = '';
    }
    switch ($_SESSION['discount']['type']) {
        case "percent":
            $dis[1] = "";
            $dis[2] = "disabled";
            $chk[0] = "";
            $chk[1] = "checked";
            $chk[2] = "";
            break;
        case "amount":
            $dis[1] = "disabled";
            $dis[2] = "";
            $chk[0] = "";
            $chk[1] = "";
            $chk[2] = "checked";
            break;
        default:
            $dis[1] = "disabled";
            $dis[2] = "disabled";
            $chk[0] = "checked";
            $chk[1] = "";
            $chk[2] = "";
            break;
    }
    // Next is a micro-form to set a discount in percent value
    $output .= '
		<FIELDSET>
			<LEGEND>' . ucfirst(phr('DISCOUNT')) . '</LEGEND>
			<FORM ACTION="orders.php" NAME="form_discount" METHOD="POST">
				<INPUT TYPE="HIDDEN" NAME="command" VALUE="bill_discount">
				<INPUT TYPE="HIDDEN" NAME="keep_separated" VALUE="1">
				<input type="radio" name="discount_type" value="none" onclick="JavaScript:discount_switch();" ' . $chk[0] . '>' . ucfirst(phr('NONE')) . '<br />
				<input type="radio" name="discount_type" value="percent" onclick="JavaScript:discount_switch();" ' . $chk[1] . '>
				' . ucfirst(phr('PERCENTUAL')) . ' <INPUT TYPE="text" name="percent" size="2" maxlength="2" value="' . $percent . '" ' . $dis[1] . '>% <br />
				<input type="radio" name="discount_type" value="amount" onclick="JavaScript:discount_switch();" ' . $chk[2] . '>' . ucfirst(phr('VALUE')) . ' 
				<INPUT TYPE="text" name="amount" size="4" maxlength="4" value="' . $amount . '" ' . $dis[2] . '>' . country_conf_currency(true) . '<br />
				<INPUT TYPE="button" onClick="applyDiscount(\'form_discount\')" value="' . ucfirst(phr('APPLY_DISCOUNT')) . '"><br />
			</FORM>
		</FIELDSET>
	';
    return $output;
}
function bill_print_taxes($receipt_id, $destid)
{
    $msg = "";
    $dest_language = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'dests', "language", $destid);
    $table = 'account_mgmt_main';
    $query = "SELECT * FROM {$table} WHERE `id`='{$receipt_id}'";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return 0;
    }
    $arr = mysql_fetch_array($res);
    $taxable = $arr['cash_taxable_amount'];
    $vat_total = $arr['cash_vat_amount'];
    $msg .= "\t\t" . ucfirst(lang_get($dest_language, 'PRINTS_TAXABLE')) . " \t" . country_conf_currency() . " {$taxable}";
    for (reset($_SESSION['vat']); list($key, $value) = each($_SESSION['vat']);) {
        $vat_rate_name = $_SESSION['vat'][$key]['name'];
        $vat_rate = $_SESSION['vat'][$key]['rate'] * 100;
        $vat_local = $_SESSION['vat'][$key]['tax'];
        $vat_local = sprintf("%0.2f", $vat_local);
        $msg .= "\n\t\t" . ucfirst(lang_get($dest_language, 'PRINTS_TAX')) . " " . $vat_rate_name . " (" . $vat_rate . "%) \t" . country_conf_currency() . " {$vat_local}";
    }
    $msg .= "\n\t\t" . ucfirst(lang_get($dest_language, 'PRINTS_TAX_TOTAL')) . " \t" . country_conf_currency() . " {$vat_total}";
    return $msg;
}
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;
}