
PK 
<?php
//include '../settings/constant.php';
//include('Mail.php');
//include('Mail/mime.php');
//include 'mimetype.php';
require("class.phpmailer.php");
class FUNCTIONS {
/////////////////////////////////////////////////////////////////////////////////////////
//GENERAL FUNCTIONS//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//Function to get current page url============================================
public function getpageurl(){
$relative_path = $_SERVER['PHP_SELF'];
$relative_path_arr = explode('/', $relative_path);
$page_uri = $relative_path_arr[count($relative_path_arr)-1];
return $page_uri;
}
public function curPageURL() {
$pageURL = 'http';
if(isset($_SERVER["HTTPS"]))
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
//============================================================================
//Function to get the clients IP Address======================================
public function getClientIP() {
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
if (isset($_SERVER["HTTP_CLIENT_IP"]))
return $_SERVER["HTTP_CLIENT_IP"];
return $_SERVER["REMOTE_ADDR"];
}
if (getenv('HTTP_X_FORWARDED_FOR'))
return getenv('HTTP_X_FORWARDED_FOR');
if (getenv('HTTP_CLIENT_IP'))
return getenv('HTTP_CLIENT_IP');
return getenv('REMOTE_ADDR');
}
//============================================================================
//Function to upload the file=================================================
public function uploadFile($newfilename, $foldername, $id){
$allowedExts = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES[$id]["name"]);
$extension = end($temp);
//$rand = uniqid('CHILD-',true);
if (in_array($extension, $allowedExts)) {
move_uploaded_file($_FILES[$id]["tmp_name"], $foldername.$newfilename.'.'.$extension);
$flag[0] = 1;
$flag[1] = $foldername.$newfilename.'.'.$extension;
$flag[2] = $newfilename.'.'.$extension;
$flag[3] = $extension;
} else {
$msg = "Invalid file type";
$flag[0] = 0;
}
return $flag;
}
//============================================================================
//Function to upload the MS-Excel file========================================
public function uploadExcelFile($newfilename, $foldername, $id){
$allowedExts = array("xls", "xlsx");
$temp = explode(".", $_FILES[$id]["name"]);
$extension = end($temp);
//$rand = uniqid('CHILD-',true);
if (in_array($extension, $allowedExts)) {
move_uploaded_file($_FILES[$id]["tmp_name"], $foldername.$newfilename.'.'.$extension);
$flag[0] = 1;
$flag[1] = $foldername.$newfilename.'.'.$extension;
$flag[2] = $newfilename.'.'.$extension;
$flag[3] = $extension;
} else {
$msg = "Invalid file type";
$flag[0] = 0;
}
return $flag;
}
//============================================================================
public function generateOTP($digit){
$x = $digit-1; // Amount of digits
$min = pow(10,$x);
$max = (pow(10,$x+1)-1);
$otp = rand($min, $max);
$_SESSION['otpAuth'] =$otp;
return $otp;
}
public function String2Stars($string='',$first=0,$last=0,$rep='*'){
$begin = substr($string,0,$first);
$middle = str_repeat($rep,strlen(substr($string,$first,$last)));
$end = substr($string,$last);
$stars = $begin.$middle.$end;
return $stars;
}
/////////////////////////////////////////////////////////////////////////////////////////
//END GENERAL FUNCTIONS//////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//ADMIN RELATED FUNCTIONS////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
public function getInventory($id=NULL,$itemCode=NULL,$itemType=NULL,$isActive=NULL,$orderBy='ASC'){
$condition = "";
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY id $orderBy";
}else{
$orderBy='';
}
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($itemCode)){
$condition.=empty($condition)?" itemCode='$itemCode' ":" AND itemCode='$itemCode' ";
}
if(!empty($itemType)){
$condition.=empty($condition)?" itemType='$itemType' ":" AND itemType='$itemType' ";
}
if($isActive !== NULL){
$condition.=empty($condition)?" isActive='$isActive' ":" AND isActive='$isActive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `inventory` WHERE $condition $orderBy":
"SELECT * FROM `inventory` $orderBy";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
$result = Array();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result); exit;
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getStateList($id=NULL,$isActive=NULL){
$condition = "";
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if($isActive !== NULL){
$condition.=empty($condition)?" isActive='$isActive' ":" AND isActive='$isActive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `state_list` WHERE $condition ":
"SELECT * FROM `state_list`";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
$result = Array();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result); exit;
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getPurchase($pId=NULL,$customer_contactno=NULL,$isActive=NULL,$orderBy='ASC'){
$condition = "";
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY pId $orderBy";
}else{
$orderBy='';
}
if(!empty($pId)){
$condition.=empty($condition)?" pId='$pId' ":" AND pId='$pId' ";
}
if(!empty($customer_contactno)){
$condition.=empty($condition)?" customer_contactno='$customer_contactno' ":" AND customer_contactno='$customer_contactno' ";
}
if($isActive !== NULL){
$condition.=empty($condition)?" isActive='$isActive' ":" AND isActive='$isActive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `purchase` WHERE $condition $orderBy":
"SELECT * FROM `purchase` $orderBy";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
$result = Array();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result); exit;
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getPurchaseItems($id=NULL,$purchaseId=NULL,$inventoryId=NULL,$isActive=NULL,$orderBy='ASC'){
$condition = "";
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($purchaseId)){
$condition.=empty($condition)?" purchaseId='$purchaseId' ":" AND purchaseId='$purchaseId' ";
}
if(!empty($inventoryId)){
$condition.=empty($condition)?" inventoryId='$inventoryId' ":" AND inventoryId='$inventoryId' ";
}
if($isActive !== NULL){
$condition.=empty($condition)?" isActive='$isActive' ":" AND isActive='$isActive' ";
}
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY `purchase_items`.`invoiceDate` $orderBy";
}else{
$orderBy='';
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `purchase_items` WHERE $condition $orderBy":
"SELECT * FROM `purchase_items` $orderBy";
//exit();
$pdodb = PDODB::getInstance();
$result = Array();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result); exit;
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function groupByInventoryId($results) {
$groupedData = [];
foreach ($results as $row) {
$inventoryId = $row['inventoryId'];
if (!isset($groupedData[$inventoryId])) {
$groupedData[$inventoryId] = [];
}
$groupedData[$inventoryId][] = $row;
}
return $groupedData;
}
public function getAllOrderDetails($pId=NULL,$paymentMode=NULL,$isActive=NULL,$from_date=NULL,$to_date=NULL,$orderBy='ASC'){
$condition = "";
if(!empty($pId)){
$condition.=empty($condition)?" pId='$pId' ":" AND pId='$pId' ";
}
if(isset($paymentMode)){
$condition.=empty($condition)?" paymentMode='$paymentMode' ":" AND paymentMode='$paymentMode' ";
}
if($isActive !== NULL){
$condition.=empty($condition)?" isActive='$isActive' ":" AND isActive='$isActive' ";
}
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY `purchase`.`invoiceDate` $orderBy";
}else{
$orderBy='';
}
if(!empty($from_date) && !empty($to_date)){
$from_date =date('Y-m-d', strtotime($from_date));
$to_date =date('Y-m-d', strtotime($to_date));
$condition.=empty($condition)?" DATE(invoiceDate) BETWEEN '$from_date' AND '$to_date' ":" AND DATE(invoiceDate) BETWEEN '$from_date' AND '$to_date' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `purchase` WHERE $condition $orderBy":
"SELECT * FROM `purchase` $orderBy";
//exit;
$pdodb = PDODB::getInstance(); //print_r($pdodb); exit();
$result = Array();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function numbertoWords($number=null){
// Number to Words
$no = floor($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$words = array('0' => '', '1' => 'one', '2' => 'two',
'3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
'7' => 'seven', '8' => 'eight', '9' => 'nine',
'10' => 'ten', '11' => 'eleven', '12' => 'twelve',
'13' => 'thirteen', '14' => 'fourteen',
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
'18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
'30' => 'thirty', '40' => 'forty', '50' => 'fifty',
'60' => 'sixty', '70' => 'seventy',
'80' => 'eighty', '90' => 'ninety');
$digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ?
"." . $words[$point / 10] . " " .
$words[$point = $point % 10] : '';
//echo $result . "Rupees " . $points . " Paise";
//echo $result . "Rupees Only";
// End Number to Words
if (empty($result))
{
$result = "zero";
}
//echo $result; exit;
return ucwords($result);
}
public function toJsAlert($location = null, $message = '')
{
echo "<script LANGUAGE='JavaScript'>
window.alert('$message');
window.location.href='$location';
</script>";
//echo "<script>alwindow.location.href='$location';</script>";
exit();
}
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}
?>


PK 99