dailyupload_calllog.php 3.05 KB
<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
use Config;

use App\Models\User;
use App\Models\Accesslog;

use App\Models\CRMCall;
use Schema;
use PDO;

use Illuminate\Database\Schema\Blueprint;

class dailyupload_calllog extends Command {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $signature = 'dailyupload_calllog';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'dailyupload_calllog';

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function handle()
	{
		$nowts=time();
		echo "\n".date('Y-m-d H:i:s')."\n";
			$logdate=strtotime('0 day');			
			$date=date('F_Y');	
			$tcol=0;$fieldsarr=array();$extrahdrarr=array();
			$server_ip=env('app_ip');
			$central_ip=env('central_ip');
			$calllog_report = "calllog_report_".$date;
			//$calllog_report = "calllog_report_".date("d_m_Y",$logdate);
			$created_at=date("Y-m-d H:i:s");

			$conn = array(
				'driver'    => 'mysql',
				'host'      => $central_ip,
				'database'  => env('DB_DATABASE', 'kstych_flexydial'),
				'username'  => env('DB_USERNAME', 'root'),
				'password'  => env('DB_PASSWORD', ''),
				'charset'   => 'utf8',
				'collation' => 'utf8_unicode_ci',
				'prefix'    => '',
				'options'   => array(
					PDO::ATTR_TIMEOUT => 5,
					),
				);
			Config::set("database.connections.conn", $conn);
			if(DB::connection("conn")->getDatabaseName())
			{
			
			$serverclist=DB::connection("conn")->select(DB::raw("select id from server_details where server_ip='$server_ip'"));	
			$server_id=$serverclist[0]->id;		
			if($server_id<10){	
			$server_id="0".$server_id;
			}

			$clist=DB::connection("conn")->select(DB::raw("select count(*) as cnt,server from $calllog_report where created_at>'".date("Y-m-d",$logdate)."' and created_at<'".date("Y-m-d",$logdate+24*60*60)."' group by server"));	
			$caar=[];
			foreach($clist as $cline)
			{
				$caar[$cline->server]=	$cline->cnt;
				

			}
				$mlist=DB::select(DB::raw("select count(*) as countrecord from crmcalls where created_at>'".date("Y-m-d",$logdate)."' and created_at<'".date("Y-m-d",$logdate+24*60*60)."'"));

					$location_cont='0';
					$central_cont='0';

					$location_cont=$mlist[0]->countrecord;
					if(array_key_exists($server_id,$caar)){
						$central_cont=$caar[$server_id];
					}else{
						$central_cont=0;

					}
					$dif=($central_cont)-($mlist[0]->countrecord);

					if($dif==0){

						$result="Y";

						DB::connection("conn")->insert(DB::raw("insert into dailyupload_calllog_records set created_at='$created_at',server_id='$server_id',server_ip='$server_ip',central_count='$central_cont',location_count='$location_cont',difference='$dif',result='$result'"));

					}else{
						
						$result="N";
						DB::connection("conn")->insert(DB::raw("insert into dailyupload_calllog_records set created_at='$created_at',server_id='$server_id',server_ip='$server_ip',central_count='$central_cont',location_count='$location_cont',difference='$dif',result='$result'"));

					}	
	
 DB::connection("conn")->disconnect();
			
		}
			
	}		
	

}