| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 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 Cronrestaurantinvoice 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->model('restaurantmanagement_model');
$this->load->library('myemail');
}
function index( $offset = 0 )
{
// $message = 'test';
// mail('earthtechnology5@gmail.com', 'My Subject', $message);
$to_date=date('Y-m-d');
$to_date1 = strtotime($to_date);
$fr_date = strtotime('-6 days', $to_date1);
$fr_date = date('Y-m-d',$fr_date);
$thisDay = date('Y-m-d', strtotime('-1 days', $to_date1));
// $thisDay = date('Y-m-d', strtotime('2017-03-31'));
// echo $thisDay; exit();
$now = date('Y-m-d');
$this->db->select('*');
$this->db->from('rt_restaurant');
$query = $this->db->get();
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$status = 'Delivered';
$this -> db -> select('SUM(menuprice_total) AS ordersubtotal, SUM(ordertotalprice) AS ordergrandtotal, SUM(commission) AS commissiontotal, SUM(taxvalue) AS taxtotal, SUM(offervalue) AS offertotal');
$this -> db -> from('rt_order');
$this -> db -> where('restaurant_id', $row->restaurant_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 -> where('date(delivery_completed_date)', $thisDay);
$this -> db -> group_by('restaurant_id');
$query = $this -> db -> get();
$result= $query->row_array();
if($query -> num_rows() == 1 && $result['ordersubtotal']>0) {
$this->db->where('restaurant_id', $row->restaurant_id);
//$this->db->where('from_date', $fr_date);
//$this->db->where('to_date', $to_date);
$this->db->where('from_date', $thisDay);
$this->db->where('to_date', $thisDay);
$delete=$this->db->delete('restaurant_invoice');
/*$this->db->trans_start();
$this->db->select('*');
$this->db->from('rt_setting_payment');
$this->db->limit('1');
$paypalQuery = $this->db->get();
if ($paypalQuery->num_rows() > 0) {
$paypalData = $paypalQuery->row();
$paypalAmt = $result['ordergrandtotal'] * (($paypalData->paypal_fee / 2) / 100);
$order_amount = $result['ordersubtotal'] - $result['commissiontotal'] - $paypalAmt;
}
else {
$order_amount = $result['ordersubtotal'] - $result['commissiontotal'];
}*/
// $order_amount = $result['ordersubtotal'] - $result['commissiontotal'];
// $RestaurantShare = number_format($itemTotal + $taxAmount - $offervalue - $commission, 2, '.', '');
// $order_amount = number_format($result['ordersubtotal'] + $result['taxtotal'] - $result['offertotal'] - $result['commissiontotal'], 2, '.', '');
$order_amount = number_format($result['ordersubtotal'] + $result['taxtotal'], 2, '.', '');
$data_option = array(
'restaurant_id' =>$row->restaurant_id,
'restaurant_name' =>$row->restaurant_name,
'restaurant_email' =>$row->restaurant_contact_email,
'from_date' =>$thisDay,
'to_date' =>$thisDay,
'order_amount' =>$order_amount,
'addeddate' => $now
);
$this->db->insert('restaurant_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('restaurant_invoice', $data_up);
$this->db->trans_complete();
//$this->send_my_mail($row->restaurant_id,$fr_date,$to_date,$invoice_id);
$this->send_my_mail($row->restaurant_id,$thisDay,$thisDay,$invoice_id);
}
}
}
}
function send_my_mail($restaurant_id,$fr_date,$to_date,$invoice_id)
{
$mail_CC = '';
$logo=base_url().'assets/logo-main.png';
$image_path = base_url().'assets/';
$variables = array();
$restaurant_data = $this->restaurantmanagement_model->GetRestauratDetails($restaurant_id);
$mail_To = $restaurant_data['restaurant_contact_email'];
$contact_name = $restaurant_data['restaurant_contact_name'];
$link_button=anchor('restaurantadmin/invoice_details/' . md5($invoice_id),'<button>View Earning Details</button>');
$link = anchor('restaurantadmin/invoice_details/' . md5($invoice_id));
$only_link = base_url().'restaurantadmin/invoice_details/' . md5($invoice_id);
$variables['contact_name'] = $contact_name;
$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 = 'restaurant_invoice';
$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="");
}
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 'ok';
}
}
}