<?PHP

/**
* this is for private usage for every project by him self
*/
class Functions{

	var $get_object = array('Sql');

	function RandomString($length){

	    $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
	    return $randomString;
	}

	function RandomNumber($length){

	    $array2=array(1,2,3,4,5,6,7,8,9);

		if ($length>0) {

			$i=0;
		    while ($i<$length) {

			    srand((double)microtime()*10000000);
				$array=$array2;
	            $arrayrandom=array_rand($array, 2);
		        $string.=$array[$arrayrandom[0]];
				$i++;
	        }
		}
	    return (int)$string;
	}

	function calculate_amount($price, $vat, $discount){

		$bruto = ($price*$vat/100)+$price;

		$array = array(
			'neto_real'	 => round($price, 2),
			'bruto_real' => round($bruto, 2),
			'neto' => round($price-($price*$discount/100), 2),
			'bruto' => round($bruto-($bruto*$discount/100), 2)
		);
		return $array;
	}

	function reference($prime_number){

		$coefficient = 7;
		$ref = $prime_number;

		//731 meetodi rakendamine k�ikidele arvudele
		do {

				//Korrutised liidetakse
				$check_digits = $check_digits + (($ref % 10) * $coefficient);

				if ($coefficient == 7) $coefficient = 3;
				else if ($coefficient == 3) $coefficient = 1;
				else if ($coefficient == 1) $coefficient = 7;

		} while ((int)$ref /= 10);

		//L�him suurem k�mnekordne arv
		$check_digits = 10 - ($check_digits % 10);

		//Kui arv on 10, siis arv peab olema 0
		if ($check_digits == 10){$check_digits = 0;}

		return $prime_number.$check_digits;
	}

	function getMessage($name, $type, $language){

		$rows = $this->Sql->Query("SELECT * FROM templates WHERE name = '".$name."' and type = '".$type."' and language = '".$language."' and is_active=1 ", true);
		return $rows[0];
	}
}

?>