Rev 20097 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('CakeEmail','Network/Email');class CallhistoryShell extends AppShell{public $uses = array('Callhistory');public function main(){$cur_date = date('Y-m-d', time());$newdate = date('Y-m-d', strtotime(' -1 day'));if(date('D',time()) == 'Sun'){$newdate = date('Y-m-d', strtotime(' -2 day'));}elseif(date('D',strtotime(' -1 day')) == 'Sun'){$newdate = date('Y-m-d', strtotime(' -2 day'));}$header ="id,retailer_id,Agent,Mobile No.,Call Type,Sms Verified,Call Time,Duration Sec.,Call Disposition,Disposition Description,Created";$file = fopen("callhistory.csv","w");fputcsv($file, explode(',',$header));$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";$result = $this->Callhistory->query($callquery);foreach ($result as $key => $row){$phone = substr($row['c']['mobile_number'], 0, 4) . str_repeat("X", strlen($row['c']['mobile_number']) - 6) . substr($row['c']['mobile_number'], -2);$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'];$this->out($content);echo "\n";fputcsv($file,explode(',',$content));}fclose($file);$Email = new CakeEmail();$Email->config('smtp')->from(array('help@profitmandi.com' => 'Admin at ProfitMandi'))->to('amit.sirohi@shop2020.in')->cc('ritesh.chauhan@shop2020.in')->attachments(array('callhistory.csv' => array('file' => 'callhistory.csv','mimetype' => 'text/csv','contentId' => 'my-unique-id')))->subject('Callhistory Report');if($Email->send('Callhistory Report')){$this->out('Email Sent..');} else {$this->out('Email does not sent..');}}}?>