dailyupload_calllog.php
3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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('CENTRAL_DB'),
'username' => env('CENTRAL_USERNAME'),
'password' => env('CENTRAL_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();
}
}
}