function dispingredients_names()
 {
     $output = array();
     $ingreds = $this->get('dispingreds');
     $ingreds = trim($ingreds);
     if (empty($ingreds)) {
         return $output;
     }
     $ingreds = explode(" ", $ingreds);
     for (reset($ingreds); list($key, $value) = each($ingreds);) {
         $local = new ingredient($value);
         if ($local->data['deleted']) {
             continue;
         }
         $output[$value] = $local->name($_SESSION['language']);
     }
     return $output;
 }
function show_receipt($id)
{
    if (!$id) {
        return 1;
    }
    $table = 'account_mgmt_main';
    $query = "SELECT * FROM {$table} WHERE `id`='{$id}'";
    $res = mysql_db_query($_SESSION['common_db'], $query);
    $row = mysql_fetch_array($res);
    if ($row['annulled']) {
        switch ($row['type']) {
            case 4:
                echo ucphr('RECEIPT_ANNULLED_OK') . ".<br>\n";
                break;
            case 3:
                echo ucphr('INVOICE_ANNULLED_OK') . ".<br>\n";
                break;
            case 5:
                echo ucphr('BILL_ANNULLED_OK') . ".<br>\n";
                break;
        }
        echo GLOBALMSG_RECORD_DELETE_OK_FROM_LOG_MANY_2 . ".<br><br>";
        echo "<form name=\"form1\" action=\"receipt.php\" method=\"post\">\n";
        echo "<input type=\"hidden\" name=\"command\" value=\"delete\">\n";
        echo "<input type=\"hidden\" name=\"delete[" . $id . "]\" value=\"1\">\n";
        echo "<input type=\"submit\" value=\"" . GLOBALMSG_RECORD_DELETE . "\">";
        echo "</form>\n";
        return 0;
    }
    $table = 'account_log';
    $query = "SELECT * FROM {$table} WHERE `payment`='{$id}'";
    $res = mysql_db_query($_SESSION['common_db'], $query);
    if (!mysql_num_rows($res)) {
        return 2;
    }
    echo "<table bgcolor=\"" . color(-1) . "\">\n";
    echo "<thead ><tr>\n\t<td>" . ucfirst(phr('QUANTITY')) . "</a></td>\n\t<td>" . ucfirst(phr('DESCRIPTION')) . "</td>\n\t<td>" . ucfirst(phr('AMOUNT')) . "</td>\n\t</tr></thead>\n\t<tbody>\n";
    $i = 0;
    while ($row = mysql_fetch_array($res)) {
        if ($row['operation'] == 1) {
            $ingred = new ingredient($row['ingredient']);
            $description = "    " . ucphr('PLUS') . " " . $ingred->name($_SESSION['language']);
            unset($ingred);
        } elseif ($row['operation'] == -1) {
            $ingred = new ingredient($row['ingredient']);
            $description = "    " . ucphr('MINUS') . " " . $ingred->name($_SESSION['language']);
            unset($ingred);
        } else {
            $dish = new dish($row['dish']);
            $description = $dish->name($_SESSION['language']);
            unset($dish);
        }
        $total += $row['price'];
        $color = color($i);
        echo '<tr bgcolor="', $color, '">
		<td>', $row['quantity'], '</td>
		<td>', $description, '</td>
		<td align="right">', $row['price'], '</td>
		</tr>
		';
        $i++;
    }
    echo '<tr bgcolor="', color(-1), '">
	<td></td>
	<td>' . ucfirst(phr('TOTAL')) . '</td>
	<td align="right">', sprintf("%0.2f", $total), '</td>
	</tr>
	';
    echo "</tbody></table>";
    echo "<form name=\"form1\" action=\"receipt.php\" method=\"post\">\n";
    echo "<input type=\"hidden\" name=\"command\" value=\"delete\">\n";
    echo "<input type=\"hidden\" name=\"delete[" . $id . "]\" value=\"1\">\n";
    echo "<input type=\"submit\" value=\"" . GLOBALMSG_RECORD_DELETE . "\">";
    echo "</form>\n";
    echo "<form name=\"form1\" action=\"receipt.php\" method=\"post\">\n";
    echo "<input type=\"hidden\" name=\"command\" value=\"annul\">\n";
    echo "<input type=\"hidden\" name=\"annul[" . $id . "]\" value=\"1\">\n";
    echo "<input type=\"submit\" value=\"" . ucphr('ANNULL') . "\">";
    echo "</form>\n";
}
 function list_rows($arr, $row)
 {
     global $tpl;
     global $display;
     $col = 0;
     if (!$this->disable_mass_delete) {
         $display->rows[$row][$col] = '<input type="checkbox" name="delete[]" value="' . $arr['id'] . '">';
         $display->width[$row][$col] = '1%';
         $col++;
     }
     foreach ($arr as $field => $value) {
         if (isset($this->allow_single_update) && in_array($field, $this->allow_single_update)) {
             $link = $this->link_base . '&amp;command=update_field&amp;data[id]=' . $arr['id'] . '&amp;data[field]=' . $field;
             if ($this->limit_start) {
                 $link .= '&amp;data[limit_start]=' . $this->limit_start;
             }
             if ($this->orderby) {
                 $link .= '&amp;data[orderby]=' . $this->orderby;
             }
             if ($this->sort) {
                 $link .= '&amp;data[sort]=' . $this->sort;
             }
             $display->links[$row][$col] = $link;
         } elseif (method_exists($this, 'form')) {
             $link = $this->file . '?class=' . get_class($this) . '&amp;command=edit&amp;data[id]=' . $arr['id'];
         } else {
             $link = '';
         }
         if ($field == 'name' && CONF_SHOW_SUMMARY_ON_LIST) {
             $ingred = new ingredient($arr['id']);
             $value .= '<span class="admin_ingreds_list">';
             $dishes = $ingred->find_connected_dishes();
             if (!empty($dishes['included']) && is_array($dishes['included'])) {
                 $value .= '<br/>' . ucphr('INCLUDED') . ': ';
                 foreach ($dishes['included'] as $key2 => $value2) {
                     $value .= ucfirst($value2) . ", ";
                 }
                 $value = substr($value, 0, -2);
                 $value .= '';
             }
             if (!empty($dishes['available']) && is_array($dishes['available'])) {
                 $value .= '<br/>' . ucphr('AVAILABLE') . ': ';
                 foreach ($dishes['available'] as $key2 => $value2) {
                     $value .= ucfirst($value2) . ", ";
                 }
                 $value = substr($value, 0, -2);
                 $value .= '';
             }
             $value .= '</span>';
         } elseif ($field == 'unit_type') {
             $value = get_user_unit($arr['unit_type']);
         } elseif ($field == 'quantity') {
             $unit = get_user_unit($arr['unit_type']);
             $default_unit = get_default_unit($arr['unit_type']);
             $value = convert_units($value . ' ' . $default_unit, $unit);
         }
         $display->rows[$row][$col] = $value;
         if ($link && $field == 'name') {
             $display->links[$row][$col] = $link;
         }
         if ($link) {
             $display->clicks[$row][$col] = 'redir(\'' . $link . '\');';
         }
         $col++;
     }
 }
function printer_print_row($arr, $destid)
{
    $msg = '';
    $dest_language = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], 'dests', "language", $destid);
    if ($arr['dishid'] == MOD_ID) {
        $modingred = $arr['ingredid'];
        $modingrednumber = $modingred;
        $query = "SELECT * FROM `ingreds` WHERE id='{$modingrednumber}'\r\n\t\tAND ingreds.deleted = '0'";
        $res2 = common_query($query, __FILE__, __LINE__);
        if (!$res2) {
            return '';
        }
        $arr2 = mysql_fetch_array($res2);
        if ($arr2 != FALSE) {
            $ingredobj = new ingredient($modingrednumber);
            $moddeddishname = $ingredobj->name($dest_language);
        }
        if ($arr['operation'] == 1) {
            $dishname = "+";
        } elseif ($arr['operation'] == -1) {
            $dishname = "-";
        }
        $dishname .= " " . $moddeddishname;
        if ($arr['ingred_qty'] == 1) {
            $dishname .= " " . lang_get($dest_language, 'PRINTS_LOT');
        } elseif ($arr['ingred_qty'] == -1) {
            $dishname .= " " . lang_get($dest_language, 'PRINTS_FEW');
        }
    } else {
        $dishobj = new dish($arr['dishid']);
        $dishname = $dishobj->name($dest_language);
    }
    $extra = "";
    if ($arr['extra_care']) {
        $extra .= '{size_double}';
        $extra .= '{highlight}';
        $extra .= lang_get($dest_language, 'PRINTS_ATTENTION') . " - " . lang_get($dest_language, 'PRINTS_WAIT');
        $extra .= '{/highlight}';
        $extra .= '{/size_double}';
    }
    if ($arr['dishid'] == MOD_ID) {
        $msg .= '{size_double}';
        $msg .= "\n    " . $dishname;
        $msg .= '{/size_double}';
    } else {
        if ($extra != "") {
            $msg .= '{align_center}';
            $msg .= "{$extra}\n";
        }
        $msg .= "\n" . '{size_double}';
        $msg .= sprintf("%-30s", $dishname) . $arr['quantity'] . "x" . $arr['price'] / $arr['quantity'];
        $msg .= '{/size_double}';
    }
    $msg = str_replace("'", "", $msg);
    return $msg;
}
Esempio n. 5
0
<?php

session_start();
require_once '../../../bootstrap.php';
require '../../../services/UserService.php';
require '../../../services/ItemService.php';
require '../../../utils/Exceptions.php';
UserService::withRole(UserService::$CONTRIBUTOR, function () {
    $ingredient = new ingredient();
    $ingredient->setquantity($_POST["quantity"]);
    if (array_key_exists("unitId", $_POST)) {
        $unitId = $_POST["unitId"];
        if ($unitId != "-1") {
            $ingredient->setunitId($_POST["unitId"]);
        }
    }
    $ingredient->setingredientId($_POST["ingredientId"]);
    $recipeId = $_GET["recipeId"];
    $recipe = RecipeQuery::create()->findPk($recipeId);
    if (isset($recipe)) {
        $recipe->addingredient($ingredient);
        $saved = ItemService::saveWithValidation($ingredient, 200);
        if ($saved == true) {
            $id = $ingredient->getId();
            $result = array("id" => $id);
            echo json_encode($result);
        }
    } else {
        http_response_code(404);
    }
});
 function create_from_external($obj_id, $obj_type)
 {
     if ($obj_type == TYPE_DISH) {
         $obj = new dish($obj_id);
         foreach ($obj->ingredients() as $ingredid) {
             $err = $this->create_from_external($ingredid, TYPE_INGREDIENT);
             if ($err && $err != ERR_OBJECT_ALREADY_EXISTS) {
                 return $err;
             }
         }
         foreach ($obj->dispingredients() as $ingredid) {
             $err = $this->create_from_external($ingredid, TYPE_INGREDIENT);
             if ($err && $err != ERR_OBJECT_ALREADY_EXISTS) {
                 return $err;
             }
         }
     } elseif ($obj_type == TYPE_INGREDIENT) {
         $obj = new ingredient($obj_id);
     } else {
         return ERR_NO_TYPE_SPECIFIED;
     }
     if ($this->find_external($obj_id, $obj_type)) {
         return ERR_OBJECT_ALREADY_EXISTS;
     }
     $input_data['name'] = $obj->name();
     $input_data['ref_type'] = $obj_type;
     $input_data['ref_id'] = $obj_id;
     $err = $this->insert($input_data);
     return $err;
 }
function bill_save_session($sourceid)
{
    /*
    Takes every single dish and saves the following info in the waiter session
    saved data:
    price 	(in case of mod adds the price to the associated dish
    		and sets 0 to the actual dish)
    name
    special (1 if mod, 0 if not mod)
    quantity
    max_quantity (the max available to pay quantity)
    extra_care
    topay 	(the quantity that the customers asks to pay
    		it is set to max_quantity if the customer pays the full bill)
    */
    $query = "SELECT * FROM `orders` WHERE `sourceid`='{$sourceid}' AND `deleted`=0 AND `printed` IS NOT NULL ORDER BY `associated_id` ASC";
    $res = common_query($query, __FILE__, __LINE__);
    if (!$res) {
        return ERR_MYSQL;
    }
    if (!mysql_num_rows($res)) {
        return ERR_NO_ORDER_FOUND;
    }
    while ($arr = mysql_fetch_array($res)) {
        $id = $arr['id'];
        $associated_id = $arr['associated_id'];
        debug_msg(__FILE__, __LINE__, "separated order select - associated id (associated_id): " . $arr['associated_id']);
        if (!isset($_SESSION['separated'][$id]['topay'])) {
            $_SESSION['separated'][$id]['topay'] = 0;
        }
        $_SESSION['separated'][$id]['quantity'] = $arr['quantity'];
        if (order_is_mod($id) == 2) {
            $_SESSION['separated'][$associated_id]['price'] += $arr['price'];
            $_SESSION['separated'][$id]['price'] = 0;
            $ingredobj = new ingredient($arr['ingredid']);
            $modname = $ingredobj->name($_SESSION['language']);
            $_SESSION['separated'][$id]['name'] = "&nbsp;&nbsp;&nbsp;" . ucfirst($modname);
            $_SESSION['separated'][$id]['special'] = true;
            debug_msg(__FILE__, __LINE__, "separated order select - found mod: " . $_SESSION['separated'][$id]['name']);
            debug_msg(__FILE__, __LINE__, "separated order select -    added price: " . $arr['price']);
        } else {
            $_SESSION['separated'][$id]['max_quantity'] = $arr['quantity'] - $arr['paid'];
            $_SESSION['separated'][$id]['price'] += $arr['price'];
            $_SESSION['separated'][$id]['dishid'] = $arr['dishid'];
            $dishobj = new dish($arr['dishid']);
            $_SESSION['separated'][$id]['name'] = ucfirst($dishobj->name($_SESSION['language']));
            $_SESSION['separated'][$id]['extra_care'] = $arr['extra_care'];
            $_SESSION['separated'][$id]['special'] = false;
            if ($_SESSION['select_all']) {
                $_SESSION['separated'][$id]['topay'] = $_SESSION['separated'][$id]['max_quantity'];
            }
        }
        if (order_is_mod($id) == 1) {
            $_SESSION['separated'][$id]['name'] = ucfirst(phr('SERVICE_FEE'));
        }
    }
    return 0;
}
Esempio n. 8
0
function mods_letter_array($ord)
{
    $ord->ingredients_arrays();
    $letters = array();
    foreach ($ord->ingredients['available'] as $name => $ingredid) {
        $ingr = new ingredient($ingredid);
        if (!$ingr->get('visible') && !get_conf(__FILE__, __LINE__, "invisible_show")) {
            continue;
        }
        $char = ucfirst($name[0]);
        if (!in_array($char, $letters)) {
            $letters[] = $char;
        }
    }
    return $letters;
}
 function name($lang = '', $newname = '')
 {
     if ($this->id == SERVICE_ID) {
         return phr('SERVICE_FEE');
     }
     if (isset($this->no_name) && $this->no_name) {
         return '';
     }
     if (isset($this->referring_name) && $this->referring_name) {
         $this->fetch_data();
         $obj_type = $this->data['ref_type'];
         if ($obj_type == TYPE_DISH) {
             $obj = new dish($this->data['ref_id']);
         } elseif ($obj_type == TYPE_INGREDIENT) {
             $obj = new ingredient($this->data['ref_id']);
         } else {
             return $this->data['name'];
         }
         return $obj->name($lang);
     }
     if ($newname) {
         $this->set_name($lang, $newname);
     }
     $lang_table_found = false;
     if ($lang) {
         $lang_table = $this->table . "_" . $lang;
         $tables = common_list_tables();
         if (in_array($lang_table, $tables)) {
             $lang_table_found = true;
         }
     }
     if ($lang_table_found) {
         $cache = new cache();
         $query = "SELECT `name` FROM `" . $this->table . "` WHERE `id`='" . $this->id . "'";
         if ($this->db == 'common') {
             $res = common_query($query, __FILE__, __LINE__);
         } else {
             $res = accounting_query($query, __FILE__, __LINE__);
         }
         if (!$res) {
             return '';
         }
         $arr = mysql_fetch_array($res);
         if (!empty($arr['name']) || $this->show_empty_name) {
             $ret = $arr['name'];
             $ret = stripslashes($ret);
             $charset = lang_get($lang, 'CHARSET');
             if ($charset == 'CHARSET' || empty($charset)) {
                 $charset = 'iso-8859-1';
             }
             $ret = html_entity_decode($ret, ENT_QUOTES, $charset);
             $cache->set($lang_table, $this->id, 'name', $ret);
             return $ret;
         }
     }
     $cache = new cache();
     if ($this->db == 'common' && ($cache_out = $cache->get($this->table, $this->id, 'name'))) {
         return $cache_out;
     }
     /* RTG: if this object has a name column on table, we already have if in data array
     		I have seen this is not always true: for example, when construct a generic vat rate
     		(without data), so I put this like a conditional */
     if ($data && $this->data['name']) {
         $ret = $this->data['name'];
     } else {
         $query = "SELECT `name` FROM `" . $this->table . "` WHERE `id`='" . $this->id . "'";
         if ($this->db == 'common') {
             $res = common_query($query, __FILE__, __LINE__);
         } else {
             $res = accounting_query($query, __FILE__, __LINE__);
         }
         if (!$res) {
             return '';
         }
         $arr = mysql_fetch_array($res);
         $ret = $arr['name'];
     }
     $ret = stripslashes($ret);
     $cache->set($this->table, $this->id, 'name', $ret);
     return $ret;
 }
 function table_row_name($arr)
 {
     $dish = new dish($arr['dishid']);
     $dishname = $dish->name($_SESSION['language']);
     $deleted = $arr['deleted'];
     $orderid = $arr['id'];
     if ($arr['dishid'] == MOD_ID) {
         $modingred = $arr['ingredid'];
         $ingr = new ingredient($modingred);
         $moddeddishname = $ingr->name($_SESSION['language']);
         // say if it's added or subtracted
         if ($arr['operation'] == 1) {
             $dishname = "    " . ucfirst(phr('PLUS'));
         } elseif ($arr['operation'] == -1) {
             $dishname = "    " . ucfirst(phr('MINUS'));
         }
         $dishname .= " " . $moddeddishname;
         // and finally consider any optional info (lot/few)
         if ($arr['ingred_qty'] == 1) {
             $dishname .= " " . ucfirst(phr('LOT'));
         } elseif ($arr['ingred_qty'] == -1) {
             $dishname .= " " . ucfirst(phr('FEW'));
         }
         // gets the original ingred price (from ingreds table)
         // if the original price is 0 and the actual price is 0
         // then it means that the ingred has passed through the autocalc system
         // and we let the waiter know this, so he could check the prices.
         $modingredprice = $ingr->get('price');
         //$modingredprice=get_db_data(__FILE__,__LINE__,$_SESSION['common_db'],"ingreds","price",$modingred);
         if ($modingredprice == 0 && $arr['price'] != 0) {
             $dishname .= " (auto)";
         }
     }
     if ($arr['dishid'] == SERVICE_ID) {
         $dishname = ucfirst(phr('SERVICE_FEE'));
     }
     return $dishname;
 }