Subversion Repositories SmartDukaan

Rev

Rev 20077 | Go to most recent revision | Details | 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){
23
			$content = $row['c']['id'].",".$row['c']['retailer_id'].",".$row['a']['name'].",".$row['c']['mobile_number'].",".$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'];
24
			$this->out($content);
25
			echo "\n";
26
			fputcsv($file,explode(',',$content));
27
		}
28
 
29
		fclose($file);
30
 
31
 
32
		$Email = new CakeEmail();
33
		$Email->config('smtp')
34
		->from(array('help@profitmandi.com' => 'Admin at ProfitMandi'))
35
		->to('naman.kumar@shop2020.in')
36
		->attachments(array(
37
				'callhistory.csv' => array(
38
						'file' => '../app/callhistory.csv',
39
						'mimetype' => 'text/csv',
40
						'contentId' => 'my-unique-id'
41
				)))
42
		->subject('Callhistory Report');
43
		if($Email->send('Report'))
44
		{
45
			$this->out('Email Sent..');
46
		} else  {
47
			$this->out('Email does not sent..');
48
		}
49
	}
50
}
51
 
52
?>