Пример #1
0
/**
 *@author:gjergj
 * converted quantity
 */
function convert_units($eq, $dest_unit = '')
{
    if (CONF_DEBUG_DISABLE_FUNCTION_INSERT) {
        return $eq;
    }
    global $convertion_constants;
    $eq = trim($eq);
    if ($eq === '') {
        return 0;
    }
    list($eq, $unit, $garbage) = explode(' ', $eq, 3);
    $num = eq_to_number($eq);
    $unit = strtolower($unit);
    $dest_unit = strtolower($dest_unit);
    $type = get_unit_type($unit);
    // defaults
    if ($type == UNIT_TYPE_MASS) {
        if ($dest_unit === '') {
            $dest_unit = 'kg';
        }
        $intermediate_unit = 'kg';
    } elseif ($type == UNIT_TYPE_VOLUME) {
        if ($dest_unit === '') {
            $dest_unit = 'l';
        }
        $intermediate_unit = 'l';
    }
    if (isset($unit)) {
        $conv = $unit . '-' . $dest_unit;
        $convinv = $dest_unit . '-' . $unit;
        $convtrans0 = $unit . '-' . $intermediate_unit;
        $convtrans1 = $dest_unit . '-' . $intermediate_unit;
        if (array_key_exists($conv, $convertion_constants)) {
            $num = $num * $convertion_constants[$conv];
        } elseif (array_key_exists($convinv, $convertion_constants)) {
            $num = $num / $convertion_constants[$convinv];
        } elseif (array_key_exists($convtrans0, $convertion_constants) && array_key_exists($convtrans1, $convertion_constants)) {
            $num = $num * $convertion_constants[$convtrans0];
            $num = $num / $convertion_constants[$convtrans1];
        }
    }
    return $num;
}
Пример #2
0
function orders_update($start_data)
{
    global $tpl;
    $id = (int) $start_data['id'];
    $ord = new order($id);
    if (!isset($start_data['suspend'])) {
        $start_data['suspend'] = 0;
    }
    if (!isset($start_data['extra_care'])) {
        $start_data['extra_care'] = 0;
    }
    if (isset($start_data['price'])) {
        $start_data['price'] = eq_to_number($start_data['price']);
    }
    // forces extra_care = 1 for generic dishes
    $dishid = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], "orders", "dishid", $start_data['id']);
    $generic = get_db_data(__FILE__, __LINE__, $_SESSION['common_db'], "dishes", "generic", $dishid);
    if ($generic && $start_data['price'] == 0) {
        $start_data['extra_care'] = '1';
    } elseif ($generic && $start_data['price']) {
        $start_data['extra_care'] = '0';
    }
    // toplist update code
    if (!isset($start_data['quantity'])) {
        $start_data['quantity'] = 0;
    }
    // insert all the modules interfaces for order creation here
    toplist_update($ord->data['dishid'], $ord->data['quantity'], $start_data['quantity']);
    if (class_exists('stock_object')) {
        $stock = new stock_object();
        $stock->silent = true;
        $stock->remove_from_waiter($id, $start_data['quantity']);
    }
    // end interfaces
    // real update
    $ord->data = $start_data;
    $err = $ord->set();
    unset($ord);
    return $err;
}
Пример #3
0
 function check_values($input_data)
 {
     $msg = "";
     if ($input_data['value'] === "") {
         $msg = ucphr('CHECK_VALUE');
     }
     $input_data['value'] = eq_to_number($input_data['value']);
     if ($input_data['quantity'] === "") {
         $msg = ucphr('CHECK_QUANTITY');
     }
     if (!isset($input_data['unit_type'])) {
         $input_data['unit_type'] = get_unit_from_eq($input_data['quantity']);
     }
     // should before modification of quantity
     $input_data['quantity'] = convert_units($input_data['quantity']);
     $stock = new stock_object($input_data['obj_id']);
     if ($stock->data['quantity'] + $input_data['quantity'] < 0 && $stock->data['quantity'] >= 0) {
         $msg = ucphr('CHECK_QUANTITY');
     }
     $input_data['user'] = $_SESSION['userid'];
     if ($msg) {
         echo "<script language=\"javascript\">\n\t\t\t\twindow.alert(\"" . $msg . "\");\n\t\t\t</script>\n";
         return -2;
     }
     return $input_data;
 }