aisa/scripts/cron/auto_get_next_day_events_test.pl

155 lines
5.4 KiB
Perl
Raw Normal View History

2025-11-26 09:31:54 +00:00
#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
use CGI::Carp qw(fatalsToBrowser);
use Mail::POP3Client;
use MIME::Parser;
use Fcntl qw(:flock) ;
use DBI ;
use MIME::Lite;
use Mail::Sendmail;
use Date::Calc qw(:all);
use Excel::Writer::XLSX ;
use Time::Piece ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
require cfg_paths ;
&config_set_vars ;
&config_set_paths ;
# https://itvadmin.co.za/cgi-bin/scripts/cron/auto_get_next_day_events.pl?1
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
# my @ARGV = split(/\&/, $ENV{'QUERY_STRING'});
our $debug = $ARGV[0] ; our $username = 'rory' if $debug == 1 ; print "Content-type: text/html\n\n" if $debug == 1 ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
&today;
# &common_send_smtp_mail('','rory@kre8it.co.za','','',"Calibration : $now_dd_mm_ccyy","Start calibration cron...",'',1,'','','','',0,0) ;
&db_open_ro;
$db_ignore_open_close=1;
&load_vars ;
$db_ignore_open_close = 0 ; # do one open and one close instead of repeating it
&db_close_conn ;
&create_excel_file ;
&send_email ;
exit;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
sub load_vars {
our ($sql_next_day) = &common_add_delta_days(1) ;
our ($next_year,$next_month,$next_day) = split(/\-/,$sql_next_day) ;
our $table = 'event_quotes' ;
&db_min_ro($table,"1,count(*) AS 'next_day_cnt'","('$sql_next_day 23:59:59' >= `date_from` AND '$sql_next_day 00:00:00' <= `date_to`) AND `quote_accepted` = '1'",'','') ;
unless ($db{event_quotes}{1}{next_day_cnt}) {
$db_ignore_open_close = 0 ; # do one open and one close instead of repeating it
&db_close_conn ;
exit ;
}
$i{date_from} = $sql_next_day ; # hack for calibration_build_table_and_or_excel to simulate search
$i{date_to} = $sql_next_day ; # hack for calibration_build_table_and_or_excel to simulate search
&calibration_load_list_vars("('$sql_next_day 23:59:59' >= `date_from` AND '$sql_next_day 00:00:00' <= `date_to`)") ;
} #-------------------------------------------------------------------------------
sub create_excel_file {
# return if $file_exists ;
our $day_of_week = Day_of_Week($next_year,$next_month,$next_day) ;
my @day_of_week_name = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") ;
$day_of_week = $day_of_week_name[$day_of_week] ;
my $date = &common_write_date_interval("$next_year-$next_month-$next_day","$next_year-$next_month-$next_day") ;
our $xlsx_title_heading = "Events $date" ;
our $xlsxdir = "next_day_events" ;
our $xlsxreportname = "Next_Day_Events" ;
our $calibration_report = 1 ; #our $calibration_report_cron = 1 ;
&calibration_build_table_and_or_excel(0) ;
} #-------------------------------------------------------------------------------
sub send_email {
&common_debug("send_email START") ;
# my @email_adds = ('cristy@itvafrica.net','marizen@itvafrica.net','dom@itvafrica.net','erin@itvafrica.net','techsupport@itvafrica.net','dan@itvafrica.net','kyle@itvafrica.net','admin@kre8it.co.za') ;
my @email_adds = ('rory@kre8it.co.za') ;
# # my $to = 'rory@kre8it.co.za' ; # only 1 email address in $to
# my $to = 'cristy@itvafrica.net' ; # only 1 email address in $to
# # my $cc = 'marizen@itvafrica.net;dom@itvafrica.net;erin@itvafrica.net;techsupport@itvafrica.net;dan@itvafrica.net;kyle@itvafrica.net;admin@kre8it.co.za' ;
# my $cc = 'marizen@itvafrica.net' ;
# # my $bcc = 'viv@itvafrica.net' ;
# # my $bcc = 'rory@kre8it.co.za' ;
# # my $bcc = 'k@re8it.com' ;
# my $bcc = 'dom@itvafrica.net' ;
# &common_debug("send_email $to") ;
# if ($email{$userid}) { $bcc .= ';' . $email{$userid} ; }
# if ($username eq 'rory') { $to = 'rory@kre8it.co.za' ; $cc = 'k@re8it.com;rory@mathew.za.net' ; $bcc = 'admin@kre8it.co.za' ; }
# # if ($debug) { $to = 'rory@kre8it.co.za' ; $cc = 'k@re8it.com;rory@mathew.za.net' ; $bcc = 'admin@kre8it.co.za' ; }
# # if ($username eq 'handre') { $to = 'handre@kre8it.co.za' ; }
if (not -f $xlsxfile) {
$attachpath = '' ; $attachfile = '' ;
} else {
$attachpath = $xlsxdir ; $attachfile = $xlsxname ;
}
&common_debug("send_email $xlsxpath/$xlsxname") ;
# my $attach_flyer = 0 ; my $message = qq~Hello World~ ; my $isubject = qq~Hello World~ ;
my $date_to_text = Date_to_Text($next_year,$next_month,$next_day) ;
&common_debug("send_email : $date_to_text") ;
$cntsend=0;
foreach my $_eadd (@email_adds) {
$cntsend++ ;
# $to = ($debug) ? 'rory@kre8it.co.za' : $_eadd ;
$to = $_eadd ;
$cc = '' ;
$bcc = ($email{$userid} && $cntsend == 1) ? "$email{$userid}" : '' ; $bcc = '' if $debug ;
&common_send_smtp_mail('',"$to","$cc","$bcc","Calibration : $date_to_text","Please see attached calibration...",'','html','',$xlsxpath,$xlsxname,'',0,0) ;
last if $debug ;
}
# &common_send_smtp_mail('',$to,'',$bcc,$isubject,$message,'',1,'','','','',0,0) ;
} #-------------------------------------------------------------------------------
use db ;
use common ;
use today ;
use xlsxcreator ;
use report ;
use calibration_test ;
1;