Subversion Repositories SmartDukaan

Rev

Rev 20097 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20076 naman 1
<?php 
2
App::uses('CakeEmail','Network/Email');
3
 
4
class CallhistoryShell extends AppShell{
5
	public $uses = array('Callhistory');
6
 
7
	public function main(){
8
		$cur_date = date('Y-m-d', time());
9
		$newdate = date('Y-m-d', strtotime(' -1 day'));
10
		if(date('D',time()) == 'Sun'){
11
			$newdate = date('Y-m-d', strtotime(' -2 day'));
12
		}elseif(date('D',strtotime(' -1 day')) == 'Sun'){
13
			$newdate = date('Y-m-d', strtotime(' -2 day'));
14
		}
15
 
16
		$header ="id,retailer_id,Agent,Mobile No.,Call Type,Sms Verified,Call Time,Duration Sec.,Call Disposition,Disposition Description,Created";
17
		$file = fopen("callhistory.csv","w");
18
		fputcsv($file, explode(',',$header));
19
		$callquery = "select c.* , a.name from callhistory c join agents a on c.agent_id = a.id where c.call_time > '".$newdate."' and c.agent_id> 2";
20
		$result = $this->Callhistory->query($callquery);
21
 
22
		foreach ($result as $key => $row){
20077 naman 23
			$phone = substr($row['c']['mobile_number'], 0, 4) . str_repeat("X", strlen($row['c']['mobile_number']) - 6) . substr($row['c']['mobile_number'], -2);			
24
			$content = $row['c']['id'].",".$row['c']['retailer_id'].",".$row['a']['name'].",".$phone.",".$row['c']['call_type'].",".$row['c']['sms_verified'].",".$row['c']['call_time'].",".$row['c']['duration_sec'].",".$row['c']['call_disposition'].",".$row['c']['disposition_description'].",".$row['c']['created'];
20076 naman 25
			$this->out($content);
26
			echo "\n";
27
			fputcsv($file,explode(',',$content));
28
		}
29
 
30
		fclose($file);
31
 
32
 
33
		$Email = new CakeEmail();
34
		$Email->config('smtp')
35
		->from(array('help@profitmandi.com' => 'Admin at ProfitMandi'))
20306 amit.gupta 36
		->to('amit.sirohi@shop2020.in')
37
		->cc('ritesh.chauhan@shop2020.in')
20076 naman 38
		->attachments(array(
39
				'callhistory.csv' => array(
20083 naman 40
						'file' => 'callhistory.csv',
20076 naman 41
						'mimetype' => 'text/csv',
42
						'contentId' => 'my-unique-id'
43
				)))
44
		->subject('Callhistory Report');
20077 naman 45
		if($Email->send('Callhistory Report'))
20076 naman 46
		{
47
			$this->out('Email Sent..');
48
		} else  {
49
			$this->out('Email does not sent..');
50
		}
51
	}
52
}
53
 
54
?>