RecordController.php 8.36 KB
<?php namespace App\Http\Controllers;


use Auth;
use Input;
use Response;
use App\Models\Notification;
use App\Jobs\KHRMSLib;
use App\Models\User;
use DB;
use App\Models\CRMCall;
use App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use Log;

class RecordController extends Controller {


	public function __construct()
	{
	  $this->middleware('auth');
	  $this->middleware('module_access');
	}

	public function index()
	{
	  return view('layout.module.record.index',array());
	}
	public function create()
	{
		//
	}
	public function store()
	{
		$data=array();
		$data['wakka'] = new KHRMSLib();
		$action=Input::get("action")!=""?Input::get("action"):$_SESSION['fapiRequest'];
		$client=Input::get("client");
		$data['wakka']->HRFillNames($client);
		if($action=="show")
		{
			return view('layout.module.record.show',$data);
		}
		if($action=="save")
		{
			return view('layout.module.record.save',$data);
		}
		if($action=="quicksearch")
		{
			return view('layout.module.record.quicksearch',$data);
		}
		if($action=="textsearch")
		{
			return view('layout.module.record.textsearch',$data);
		}
		if($action=="addkey")
		{
			$wakka = new KHRMSLib();

			$varid=Input::get("varid");
			$keys=explode(",",Input::get("keys"));
			$record=$wakka->getPerson($varid);
			if(!empty($keys))foreach($keys as $key)
			{
				$val=Input::get($key);
				$record["peopledata"][$key]=$val;
			}
			
			$wakka->setPerson($varid,$record);
			
			return Response::make("");
		}
		if($action=="delaltphone")
		{
			$wakka = new KHRMSLib();
			
			$varid=Input::get("varid");
			$i=Input::get("i");
			
			$record=$wakka->getPerson($varid);
			for($k=$i+1;$k<=10;$k++,$i++)
			{
				$record["peopledata"]["altphone$i"]=$record["peopledata"]["altphone$k"];
				$record["peopledata"]["altphone_lbl_$i"]=$record["peopledata"]["altphone_lbl_$k"];
			}
			$record["peopledata"]["altphone10"]="";
			$record["peopledata"]["altphone_lbl_10"]="";
			
			$wakka->setPerson($varid,$record);
		}
		if($action=="bulkupload")
		{
			return view('layout.module.record.bulkupload',$data);
		}
		if($action=="Appointment")
		{
			$wakka = new KHRMSLib();

			$CustomerName=Input::get("CustomerName");
			$AppntLocation=Input::get("AppntLocation");
			$AppntTime=Input::get("AppntTime");
			$Address=Input::get("Address");
			$AppntDate=Input::get("AppntDate");
			$ContactPerson=Input::get("ContactPerson");
			$Phone=Input::get("Phone");

			$AppntDate=date("d-M-Y",strtotime($AppntDate));
			$h = $AppntTime;
			$hm = $h * 60;
			$ms = $hm * 60;
			$AppntTime=gmdate("g A",$ms);

			$smsapi="http://115.114.132.71/servlet/com.aclwireless.pushconnectivity.listeners.TextListener?userId=idcamps&pass=pacamps1&contenttype=1&from=HEROFC&selfid=true&alert=1&dlrreq=true";

			$MsgContent="Dear $CustomerName, Your appointment is fixed at $AppntLocation. Appointment Date - $AppntDate, Time - $AppntTime. Address: $Address Contact Person - $ContactPerson. In case of any assistence Please give a missed call. $Tollfree";
			$EnMsgContent=urlencode($MsgContent);
			$smsurl=$smsapi."&to=".$Phone."&text=".$EnMsgContent;
			
			$MessageID=$wakka->get_response($smsurl);
			
			if($MessageID)
			print $MessageID;
			else
			print "Failed";
			//echo $CustomerName . ' = ' . $AppntLocation . ' = ' . $AppntTime . ' = ' . $Address . ' = ' . $AppntDate . ' = ' . $ContactPerson;			
		}
		if($action=="sendAPI")
		{
			$mobile=Input::get("mobile")!=""?Input::get("mobile"):$_SESSION['apiMobile'];
			$custName=Input::get("custName")!=""?Input::get("custName"):$_SESSION['apiCustName'];
			$lan=Input::get("lan")!=""?Input::get("lan"):$_SESSION['apiLan'];
			$emi=Input::get("emi")!=""?Input::get("emi"):$_SESSION['apiEmi'];
			$X_AUTH_T = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL21vYmlsZXBheW1lbnRzLmJlbm93LmluLyIsInN1YiI6ImhpbWFuc2h1LnNoYXJtYUBmdWxsZXJ0b25pbmRpYS5jb20iLCJkYXRhIjp7Im1lcmNoYW50SWQiOiIxODU1ODMiLCJtY2NDb2RlIjoiNzMyMiIsIm1vYmlsZU51bWJlciI6Ijg0NTIwNzc1NTUiLCJkaXNwbGF5TmFtZSI6IkZVTExFUlRPTiBJTkRJQSBDUkVESVQgQ09NUEFOWSBMSU1JVEVEIiwibWVyY2hhbnRDb2RlIjoiRDRESzgiLCJwcml2YXRlSWQiOiI2OTEifSwiaWF0IjoxNTMxOTExMjU5fQ.pJupG7g5iOHgsJbUucjP_Hu8Zfd-wIVJkijkHMZ9vl0';
		    $X_EMAIL_T = '[email protected]';
		    
		    $key = '[B@334418de'; // this is salt/key which would be provided by benow 
		    $inputArray = ['merchantCode'=>'D4DK8',"amount"=>$emi,"description"=>"FULLERTON INDIA CREDIT COMPANY LIMITED","customerName"=>$custName,"mobileNumber"=>$mobile,"refNumber"=>$lan]; // payload 
		    $input = json_encode($inputArray);
		    $key = openssl_digest($key,'sha256');
		    $key = openssl_digest($key,'md5');
		    $key = substr($key,0,16);
		    $iv = 'xxxxyyyyzzzzwwww'; // this will be provided by benow
		    $encryptedString = openssl_encrypt($input,'aes-128-cbc',$key,0,$iv);
		    $jsonString = $input;
		    $data = ['encryptedString'=>$encryptedString,'jsonString'=> $input];
		    $jsonBody = $data;
		    
		    $url = 'https://mobilepayments.benow.in/payments/paymentadapter/portablePaymentRequest';
		    $payload = json_encode($jsonBody);
		    $ch = curl_init();
		    curl_setopt($ch, CURLOPT_COOKIE, "");
		    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
		    curl_setopt($ch, CURLOPT_URL, $url);
		    curl_setopt($ch, CURLOPT_POST, 1);
		    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json',
		        'AUTHORIZATIONKEY:' . $X_AUTH_T,
		        'X-EMAIL:' . $X_EMAIL_T, 'Cache-Control:no-cache'
		    ));
		    $response = curl_exec($ch);
		    curl_close($ch);

		    Log::useFiles(storage_path().'/logs/SMS_'.date("d_m_Y").'.log');
		    Log::info(date("Y-m-d H:i:s")." Mobile=".$mobile." LAN=".$lan." Response=".$response);

		    if(isset($_SESSION['fapiRequest']))
		    { 	
    			$_SESSION['fapiRequest']	= '';
    			$_SESSION['apiMobile'] 		= '';
    			$_SESSION['apiCustName'] 	= '';
    			$_SESSION['apiLan'] 		= '';
    			$_SESSION['apiEmi'] 		= '';
		    }

		    return $response;
		
		}
	}
	public function show($id)
	{
		$data=array();
		$data['wakka'] = new KHRMSLib();
		if($id=="bulkupload")
		{
			return view('layout.module.record.bulkupload',$data);
		}
		if($id=="textsearch")
		{
			return view('layout.module.record.textsearch',$data);
		}
	}
	public function edit($id)
	{
		//
	}
	public function update($id)
	{
		//
	}
	public function destroy($id)
	{

	}


	public function dashboard()
	{
		//echo "OK";
	}

	public function churnData()
	{
		$data=array();
		$wakka = new KHRMSLib();

		$listVal = DB::table('currentqueue_list')->get();

		$rclientlst=$wakka->clientsReadAccess();

		$data['listVal'] = $listVal;
		$data['cntlistVal'] = count($listVal);
		$data['rclientlst'] = $rclientlst;

		return view('layout.module.record.churn',$data);	
	}

	public function saveChurnData()
	{
		$user_agent=Input::get('agent');
		$data = $_POST['data'];

		$exitAgent = DB::table('cq_logic')->where('user_agent','=',$user_agent)->first();

		if($exitAgent)
		{
			DB::update("update cq_logic set updated_at='".date("Y-m-d H:i:s")."', data='".$data."' where user_agent='".$user_agent."'");
		}
		else
		{
			DB::statement("insert into cq_logic set created_at='".date("Y-m-d H:i:s")."', updated_at='".date("Y-m-d H:i:s")."', user_agent='".$user_agent."', data='".$data."'");
		}

		return ;
	}
	public function supervisorUpload()
	{
		$data = array();
		$client = array();		

		$data['wakka'] = new KHRMSLib();
		$dashboarduser=Auth::user();

		$allusers=User::where('usertype','=','Telecaller')->get();

      $client="";

		foreach($allusers as $alluser)
		{
			$usrData = json_decode($alluser->data);
			$usrHRMSData = unserialize($usrData->hrmsdata);
			//echo "----userdta---".print_r($usrHRMSData);

			if($usrHRMSData['clientsownerlist']&&$usrHRMSData['clientsownerlist']!='null')
			//$client[] = $usrHRMSData['clientsownerlist'];
				
            $pbcode [] = explode(',', $usrHRMSData['clientsownerlist']);

		    $username[] = $alluser->username;
		    $userid[] = $alluser->id;
		}
        foreach ($pbcode as $pbarr) {
        	foreach($pbarr as $c){
        		$client[] .= $c;
        	}
        }
        // print_r($client);
		$data['client'] = $client;
		$data['username'] = array_combine($userid,$username);
		return view('layout.module.record.commentsUpload',$data);
	}
	public function rlpPbwise()
	{
		$data = array();

		$pbcode=Input::get('pbcode');

		$data['pbcode']=$pbcode;
		return view('layout.module.record.rlppbwise',$data);
	}

}