| Server IP : 162.214.74.102 / Your IP : 216.73.216.139 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_projetos/sopizzas/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Crondriverinvoice extends CI_Controller {
function __construct()
{
parent::__construct();
// this controller can only be called from the command line
//if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
$this->load->helper("url");
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->model('driver_model');
$this->load->model('frontend_model');
$this->load->library('myemail');
}
function index( $offset = 0 )
{
// $message = 'test';
// mail('earthtechnology5@gmail.com', 'My Subject', $message);
//$first = strtotime('last Sunday');
//$last = strtotime('next Saturday');
$to_date = date('Y-m-d');
$to_date1 = strtotime($to_date);
$fr_date = strtotime('-3 days', $to_date1);
$fr_date = date('Y-m-d',$fr_date);
//$today = date('Y-m-d');
//$date = strtotime($today);
//$startingSunday = strtotime('-' . date('w', $date) . ' days', $date);
$now = date('Y-m-d H:i:s');
$this->db->select('*');
$this->db->from('rt_driver');
$query = $this->db->get();
/*echo "<pre>";
print_r($query->result());
echo "</pre>";*/
$mailCount = 0;
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$status = 'Delivered';
$this -> db -> select('SUM(driver_commission) AS driver_commission,SUM(tip) AS driver_tip');
$this -> db -> from('rt_order');
$this -> db -> where('driverid', $row->driver_id);
$this -> db -> where('status', $status);
$this -> db -> where('date(delivery_completed_date) >=', $fr_date);
$this -> db -> where('date(delivery_completed_date) <=', $to_date);
$this -> db -> group_by('driverid');
$query = $this -> db -> get();
$result= $query->row_array();
/*if ($row->driver_id == 87) {
echo $this->db->last_query();
}*/
/*echo "<pre>";
print_r($result);
echo "</pre>";
continue;*/
if($query -> num_rows() == 1) {
$mailCount = $mailCount + 1;
$this->db->where('driverid', $row->driver_id);
$this->db->where('from_date', $fr_date);
$this->db->where('to_date', $to_date);
$delete=$this->db->delete('driver_invoice');
if ($result['driver_commission'] == '') {
$result['driver_commission'] = 0.00;
}
if ($result['driver_tip'] == '') {
$result['driver_tip'] = 0.00;
}
$this->db->trans_start();
$data_option = array(
'driverid' =>$row->driver_id,
'driver_first_name' =>$row->driver_first_name,
'driver_middle_name' =>isset($row->driver_middle_name)?$row->driver_middle_name:'',
'driver_last_name' =>$row->driver_last_name,
'driver_email' =>$row->driver_email,
'from_date' =>$fr_date,
'to_date' =>$to_date,
'amount' =>$result['driver_commission'],
'driver_tip' =>$result['driver_tip'],
'addeddate' =>$now
);
/*echo "<pre>";
print_r($data_option);
echo "</pre>";*/
$this->db->insert('driver_invoice',$data_option);
$invoice_id=$this->db->insert_id();
$this->db->trans_complete();
$this->db->trans_start();
$data_up = array(
'id_code' => md5($invoice_id)
);
$this->db->where('invoice_id', $invoice_id);
$this->db->update('driver_invoice', $data_up);
$this->db->trans_complete();
$this->send_my_mail($row->driver_id,$fr_date,$to_date,$invoice_id);
}
}
}
if (isset($mailCount) && $mailCount == 0) {
$mail_To = SITE_FEEDBACK_EMAIL;
$logo=base_url().'assets/logo-main.png';
$image_path = base_url().'assets/';
$to_date = date('Y-m-d');
$to_date1 = strtotime($to_date);
$fr_date = strtotime('-3 days', $to_date1);
$fr_date = date('Y-m-d',$fr_date);
$variables['fr_to_date'] = $fr_date.' to '.$to_date;
$variables['logo'] = $logo;
$variables['image_path'] = $image_path;
$variables['site_address'] = SITE_ADDRESS;
$variables['sender_name'] = SITENAME;
$variables['site_name'] = SITENAME;
$template_name = 'invoice_update';
$mail_data = $this->frontend_model->getEmailTemplate($template_name);
$mailcontent=htmlspecialchars_decode($mail_data->template);
$subject = $mail_data->subject;
foreach($variables as $key => $value) {
$mailcontent = str_replace('{{'.$key.'}}', $value, $mailcontent);
}
$mail_From = SITENAME;
$mail_Body = $mailcontent;
$this->send_my_mailX($mail_To, $subject, $mail_Body, $mail_CC="");
$this->send_my_mailX('earthtechnology7@gmail.com', $subject, $mail_Body, $mail_CC="");
//$this->send_my_mailX('mlpviado@gmail.com', $subject, $mail_Body, $mail_CC="");
}
}
function send_my_mail($driver_id,$fr_date,$to_date,$invoice_id)
{
$mail_CC = '';
$logo=base_url().'assets/logo-main.png';
$image_path = base_url().'assets/';
$variables = array();
$driver_data = $this->driver_model->getDriverData_details($driver_id);
$mail_To = $driver_data['driver_email'];
$driver_name = $driver_data['driver_first_name'].' '.$driver_data['driver_last_name'];
$link_button=anchor('applydriveronline/earning_details/' . md5($invoice_id),'<button>View Earning Details</button>');
$link = anchor('applydriveronline/earning_details/' . md5($invoice_id));
$only_link = base_url().'applydriveronline/earning_details/' . md5($invoice_id);
$variables['driver_name'] = $driver_name;
$to_date = date('Y-m-d');
$to_date1 = strtotime($to_date);
$fr_date = strtotime('-3 days', $to_date1);
$fr_date = date('Y-m-d',$fr_date);
$variables['fr_to_date'] = $fr_date.' to '.$to_date;
$variables['link_button'] = $link_button;
$variables['link'] = $link;
$variables['only_link'] = $only_link;
$variables['logo'] = $logo;
$variables['image_path'] = $image_path;
//$variables['sender_email'] = SITE_CONTACT_EMAIL;
$variables['site_address'] = SITE_ADDRESS;
$variables['sender_name'] = SITENAME;
$variables['site_name'] = SITENAME;
$template_name = 'driver_earning';
$mail_data = $this->frontend_model->getEmailTemplate($template_name);
$mailcontent=htmlspecialchars_decode($mail_data->template);
$subject = $mail_data->subject;
foreach($variables as $key => $value) {
$mailcontent = str_replace('{{'.$key.'}}', $value, $mailcontent);
}
if ($mail_CC != '') {
//$mail_CC .= ', dgershen@orderingsystemonline.com';
}
else {
//$mail_CC .= 'dgershen@orderingsystemonline.com';
}
$mail_From = SITENAME;
$mail_subject='Invoice';
$mail_Body = $mailcontent;
$this->send_my_mailX($mail_To,$mail_subject,$mail_Body,$mail_CC="");
$this->send_my_mailX('earthtechnology7@gmail.com',$mail_subject,$mail_Body,$mail_CC="");
//$this->send_my_mailX('mlpviado@gmail.com', $subject, $mail_Body, $mail_CC="");
}
function send_my_mailX($mail_To,$mail_subject,$mail_Body,$mail_CC="")
{
$mail_From = SITENAME;
$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = SMTP_HOST; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password It should be same as that of the SMTP user
//$mail->PluginDir = "/home/phpaucti/public_html/website_development/coding/includes/";
$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = $mail_From;
$emailArr = explode(',',$mail_To);
foreach($emailArr AS $emailVal) {
$mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
}
/*$emailCCArr = explode(',',$mail_CC);
foreach($emailCCArr AS $emailCCVal) {
$mail->AddCC($emailCCVal, ""); //Email address where you wish to receive/collect those emails.
}*/
$mail->WordWrap = 100; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $mail_subject;
$message = $mail_Body;
$mail->Body = $message;
if(!$mail->Send())
{
/*echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;*/
}
else
{
//echo 'okz';
}
}
}