-function getDemandAsmQty($stockid, $location)
-{
- $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity)
- AS Dem
- FROM ".TB_PREF."sales_order_details,
- ".TB_PREF."sales_orders,
- ".TB_PREF."bom,
- ".TB_PREF."stock_master
- WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND
- ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND ";
- if ($location != "")
- $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND ";
- $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
- ".TB_PREF."bom.component='$stockid' AND
- ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND
- ".TB_PREF."stock_master.mb_flag='A'";
-
- $TransResult = db_query($sql,"No transactions were returned");
- if (db_num_rows($TransResult)==1)
- {
- $DemandRow = db_fetch_row($TransResult);
- $DemandQty = $DemandRow[0];
+ if (!is_string($code))
+ $code = strval($code);
+ $code = trim($code);
+ $length = strlen($code);
+ if(($length > 11 && $length <= 14) || $length == 8)
+ {
+ $zeroes = 18 - $length;
+ $fill = "";
+ for ($i = 0; $i < $zeroes; $i++)
+ $fill .= "0";
+ $code = $fill . $code;
+
+ $calc = 0;
+ for ($i = 0; $i < (strlen($code) - 1); $i++)
+ $calc += ($i % 2 ? $code[$i] * 1 : $code[$i] * 3);
+
+ if (substr(10 - (substr($calc, -1)), -1) != substr($code, -1))
+ return false;
+ elseif (substr($code, 5, 1) > 2)
+ {
+ //EAN / JAN / EAN-13 code
+ if ($get_type)
+ return 'EAN';
+ else
+ return (string)substr($code, ($return_value ? -14 : -13));
+ }
+ elseif (substr($code, 6, 1) == 0 && substr($code, 0, 10) == 0)
+ {
+ //EAN-8 / GTIN-8 code
+ if ($get_type)
+ return 'EAN-8';
+ else
+ return (string)substr($code, ($return_value ? -14 : -8));
+ }
+ elseif (substr($code, 5, 1) <= 0)
+ {
+ //UPC / UCC-12 GTIN-12 code
+ if ($get_type)
+ {
+ if (substr($code, 6, 1) == 5)
+ return 'UPC coupon code';
+ else
+ return 'UPC';
+ }
+ else
+ {
+ if ($skip_coupon_codes && substr($code, 6, 1) == 5)
+ return false;
+ return (string)substr($code, ($return_value ? -14 : -12));
+ }
+ }
+ elseif (substr($code, 0, 6) == 0)
+ {
+ //GTIN-14
+ if ($get_type)
+ return 'GTIN-14';
+ else
+ return (string)substr($code, -14);
+ }
+ else
+ {
+ //EAN code
+ if ($get_type)
+ return 'EAN';
+ else
+ return (string)substr($code,($return_value ? -14 : -13));
+ }