#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
# use Digest::MD5 qw(md5_hex);
require cfg ;
print header; # CGI.pm method
# unless ($username eq 'handre'or $username eq 'rory') { print "<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>" ; exit ; }
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
use Fcntl qw(:flock);
use File::Copy;
use File::Basename;
use Date::Calc qw(:all);
use Excel::Writer::XLSX;
use LWP::Simple qw($ua get);
use JSON ;
&today;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
$action = $ARGV[0] ;
our ($q) = CGI -> new() ;
our $iaction = $q -> param('iaction') || $action ;
our $isaved = $q -> param('isaved') || '' ;
# our $redirtype = 'search' ;
# our $testing = 1 ;
# our $debug = 1 ;
# &common_debug("glod_user_level = $glod_user_level [$usertype]") ;
# unless ($username eq 'rory') { print ">>>> DEVELOPMENT IN PROGRESS <<<<" ; exit ; }
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($is_operator && $glod_user_level == 2) { $glod_user_level = 3 ; } # upgrade operators level 2&3 to 3&4
our $nr_of_system_names_and_clubs = 15 ; our @all_select_ids = () ; our $minify_jquery = 1 ;
our $open_new_tab = qq~target="_blank"~ ; # opens booking page in a new tab
&db_open_ro;
$db_ignore_open_close=1;
&page_opts ;
if ($iaction eq 'filter' || $iaction eq 'search' || $iaction eq 'report'){
our $srchscr = 1 ;
our $savjqy = 0 ;
}
#------------------------------------------------------------------------------------------------------------------------------------------------------------------
our $table = 'event_quotes';
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # use File::Copy;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # use File::Path 'make_path';
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $src_dir = "$htmlpath/uploads/uploads/7408";
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $dst_dir = "$htmlpath/uploads/uploads/test_copy";
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # return unless -d $src_dir ;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # mkdir $dst_dir unless -d $dst_dir ;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # opendir(my $dh, $src_dir) or die "Can't open $src_dir: $!";
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $file_counter = 0 ;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my @files = readdir($dh);
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # foreach my $file (@files) {
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # next if $file =~ /^\.\.?$/ ;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $src_file = "$src_dir/$file";
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $dst_file = "$dst_dir/$file";
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # if(-f $src_file) {
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # copy("$src_file", " $dst_file") or die "File cannot be copied." ;
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # }
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # }
# while (my $file = readdir($dh)) {
# next if $file =~ /^\.\.?$/; # Skip '.' and '..'
# last if !$file || $file_counter >= 3 ;
# my $src_file = "$src_dir/$file";
# my $dst_file = "$dst_dir/$file";
# # print "\n 21 copy : $src_file, $dst_file" ;
# # system("cp", $src_file, $dst_file) == 0 or die "Failed to copy $src_file to $dst_file: $!";
# # print "Successfully copied $src_file to $dst_file\n";
# # if (copy($src_file, $dst_file)) {
# # print "Successfully copied $src_file to $dst_file\n";
# # } else {
# # print "\nFailed to copy $src_file to $dst_file: $!";
# # }
# $file_counter++ ;
# }
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # closedir($dh);
# while (1) {
# print "\n Hello World" ;
# last ;
# }
# use File::Copy;
# use File::Path 'make_path';
# my $src_dir = "$htmlpath/uploads/uploads/7408";
# my $dst_dir = "$htmlpath/uploads/uploads/test_copy";
# mkdir $dst_dir unless -d $dst_dir ;
# opendir(my $dh, $src_dir) or die "Can't open $src_dir: $!";
# my $file_count = 0 ;
# while (my $file = readdir($dh)) {
# next if $file =~ /^\.\.?$/; # Skip '.' and '..'
# $file_count++;
# last if $file_count == 3 ;
# }
# print "\nfile $file_count" ;
# while (my $file = readdir($dh)) {
# my $src_file = "$src_dir/$file";
# my $dst_file = "$dst_dir/$file";
# # copy($src_dir, $dst_dir) or warn "Failed to copy $src_file to $dst_file: $!";
# last ;
# }
# closedir($dh);
# for (7645 .. 20000) {
# my $src_dir = "$htmlpath/uploads/uploads/$_";
# if (-d $src_dir) {
# rmdir $src_dir ;
# }
# }
if ($iaction eq 'add') {
&add_screen ;
&common_min_screen1 ;
} elsif ($iaction eq 'edit') {
&common_min_load_params ;
&edit_screen ;
&common_min_screen1 ;
} elsif ($iaction eq 'save') {
# our $testing = 1 ;
&common_min_load_params ;
&insert ;
# &log_changes ;
&edit_or_list ;
} elsif ($iaction eq 'update') {
# our $testing = 1 ;
&common_min_load_params ;
&update ;
&log_changes ;
&edit_or_list ;
} elsif ($iaction eq 'copy') {
&common_min_load_params ;
&duplicate ;
&edit_screen ;
&common_min_screen1 ;
} elsif ($iaction eq 'delete') {
&common_min_load_params ;
&report_ifields ;
&delete ;
&common_min_screen2 ;
}
&common_min_action ;
$db_ignore_open_close=0 ;
&db_close_conn ;
exit;
#------------------------------------------------------------------------------------------
sub edit_or_list {
exit if $testing && substr($username,0,4) eq 'rory' ;
# if ($i{saveandexit} eq 'yes') {
# &list_screen ;
# &common_min_screen3;
# }
# else
# {
&edit_screen ;
&common_min_screen1;
# }
} #------------------------------------------------------------------------------------------
sub insert {
# &db_min_ro('users',"id,1 AS 'schools_manager'","`user_type`='schools_manager' AND `id`='$userid'",'','') ;
# $i{quote_created} = 1 if $is_schools_manager ;
# $i{quote_created} = 1 if $glod_user_level < 4 ;
$i{quote_created} = 1 if $glod_user_level < 3 ;
$i{quote_pending} = 1 unless $i{quote_accepted} || $i{quote_cancelled} || $i{quote_completed} || $i{quote_rejected} ;
our $i_quote_tab_default_full_half_items = qq~~ ;
&process_cost_items_full_half_day ;
&set_default_i_vals;
my $quote_cancelled = $i{quote_cancelled} ; my $quote_accepted = $i{quote_accepted} ; my $quote_rejected = $i{quote_rejected} ;
# $i{operator_ids} = '' ;
&build_event_details_fields($quote_accepted,$quote_rejected,$quote_cancelled) ;
&process_multi_select($quote_accepted,$quote_rejected,$quote_cancelled) ;
# &process_times_from ;
&add_db_fields ;
$i{last_update} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
$i{datetime} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
$i{user_id} = $userid ;
# &creat_db_cols;
$i{id} = &db_min_get_max($table,'id') ;
&upload_aisa_files ;
&process_upload_ifields;
&build_working_fields($i{id},$quote_accepted,$quote_rejected,$quote_cancelled) ;
$i{quote_nr} = $i{id} ;
my $quote_nr = $i{quote_nr} ;
$ignore{selected_event_length} = 1 ;
# $i{event_length} = $i{selected_event_length} ;
$i{custom_set} = 0 unless $i{custom_set} ;
foreach (keys %i) {
next if $ignore{$_} ;
&common_debug(" $_ : $i{$_}") ;
}
&db_min_insert($table) ;
&build_event_quotes_min_fields($quote_accepted,$quote_rejected,$quote_cancelled) ;
$i{quote_nr} = $quote_nr ;
# our $line = qq~$now_year$now_year$now_mm$now_dd$now_hour$now_min$now_sec|$now_year-$now_mm-$now_dd $now_hour:$now_min:$now_sec|event_quote_id='$i{id}'|user_id=$userid|action='Add'|~ ;
# foreach (keys %i) {
# next if $hidden{$_} == 1 || $ignore{$_} ;
# $line .= qq~$_='$i{$_}',~ ;
# }
$i{quote_tab_default_full_half_items} = $i_quote_tab_default_full_half_items ;
&db_min_insert('event_quotes_min') ;
} #------------------------------------------------------------------------------------------
sub update {
unless ($i{id}) {
$error = qq(NO ID) ;
return ;
}
our $i_quote_tab_default_full_half_items = qq~~ ;
$i{operator_ids} = '' ;
&process_cost_items_full_half_day ;
our $quote_accepted = $i{quote_accepted} ;
our $status = &common_status_txt($i{quote_completed},$i{quote_accepted},$i{quote_pending},$i{quote_cancelled},$i{quote_rejected}) ;
# &db_min_ro($table,"id,quote_accepted,grand_total,operator_ids,quote_cancelled,quote_rejected,demo_id,poc_id,recipient_id","`id`='$i{id}'",'','') ;
&db_min_ro($table,"*","`id`='$i{id}'",'','') ;
&set_default_i_vals ;
my $quote_cancelled = $db{$table}{$i{id}}{quote_cancelled} ;
my $quote_accepted = $db{$table}{$i{id}}{quote_accepted} ;
my $quote_rejected = $db{$table}{$i{id}}{quote_rejected} ;
&build_event_details_fields($quote_accepted,$quote_rejected,$quote_cancelled) ;
&process_multi_select($quote_accepted,$quote_rejected,$quote_cancelled) ;
&edit_db_fields ;
# &creat_db_cols ;
$i{last_update} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
&upload_aisa_files ;
&process_upload_ifields ;
# &process_times_from ;
our $hidden_expenses_amounts_exist = 0 ;
&build_working_fields($i{id},$quote_accepted,$quote_rejected,$quote_cancelled) ;
$i{quote_nr} = $i{id} ;
my $quote_nr = $i{quote_nr} ;
$ignore{selected_event_length} = 1 ;
# $i{event_length} = $i{selected_event_length} ;
$i{custom_set} = 0 unless $i{custom_set} ;
# &db_min_ro($table,"*","`id`='$i{id}'",'','') ;
# our $line = qq~~ ;
# my %col_to_be_updated = () ; my %ignore_for_now = () ;
# foreach (keys %i) {
# $col_to_be_updated{$_} = 1 ;
# }
# foreach my $col (keys %{$db{$table}{$i{id}}}) {
# next if $ignore{$col} or $hidden{$col} == 1 or substr($col,0,3) eq 'new' or not $col_to_be_updated{$col} ;
# if (($i{$col} or $db{$table}{$i{id}}{$col}) and $db{$table}{$i{id}}{$col} ne $i{$col}) {
# # $line .= qq~$col='$i{$col}',~ ;
# $line .= qq~$col='$db{$table}{$i{id}}{$col}',~ ;
# } elsif ((not $i{$col} and not $db{$table}{$i{id}}{$col}) or (($i{$col} or $db{$table}{$i{id}}{$col}) and $db{$table}{$i{id}}{$col} eq $i{$col})) {
# $ignore{$col} = 1 ; $ignore_for_now{$col} = 1 ;
# }
# }
# &db_min_upd($table,"id='$i{id}'") ;
our $line = qq~~ ;
&common_shared_log_update_changes($table) ;
our %sss = %i if $db{$table}{$i{id}}{sss_quote_nr} ;
&build_event_quotes_min_fields($quote_accepted,$quote_rejected,$quote_cancelled) ;
$i{quote_nr} = $quote_nr ;
&common_shared_log_update_changes("event_quotes_min","event_quotes_changes","changes") ;
# &db_min_ro('event_quotes_min','*',"id='$i{id}'",'','') ;
# foreach (keys %i) {
# $col_to_be_updated{$_} = 1 ;
# }
# foreach my $col (keys %{$db{event_quotes_min}{$i{id}}}) {
# next if $ignore{$col} or $hidden{$col} == 1 or substr($col,0,3) eq 'new' or not $col_to_be_updated{$col} ;
# if (($i{$col} or $db{event_quotes_min}{$i{id}}{$col}) and $db{event_quotes_min}{$i{id}}{$col} ne $i{$col}) {
# # $line .= qq~$col='$i{$col}',~ ;
# $line .= qq~$col='$db{event_quotes_min}{$i{id}}{$col}',~ ;
# } elsif ((not $i{$col} and not $db{event_quotes_min}{$i{id}}{$col}) or (($i{$col} or $db{event_quotes_min}{$i{id}}{$col}) and $db{event_quotes_min}{$i{id}}{$col} eq $i{$col})) {
# $ignore{$col} = 1 ; $ignore_for_now{$col} = 1 ;
# }
# }
# $line = qq~$now_year$now_year$now_mm$now_dd$now_hour$now_min$now_sec|$now_year-$now_mm-$now_dd $now_hour:$now_min:$now_sec|event_quote_id='$i{id}'|user_id=$userid|changed_from|~ . $line if $line ;
# $i{quote_tab_default_full_half_items} = $i_quote_tab_default_full_half_items ;
# &db_min_upd('event_quotes_min',"id='$i{id}'") ;
# foreach (keys %ignore_for_now) {
# $ignore{$_} = '' ;
# }
&sync_to_sss ;
} #------------------------------------------------------------------------------------------
sub upload_aisa_files {
my $attachmentdir = $htmlpath . "/uploads/uploads/$i{id}" ;
mkdir $attachmentdir if not -d $attachmentdir and ($i{iattachupload_1} or $i{iattachupload_2} or $i{iattachupload_3}) ;
$ignore_attach{iattachslip} = 1 ;
&common_upload_files("uploads/$i{id}") ;
$attachmentdir = $htmlpath . "/uploads/slips/$i{id}" ;
mkdir $attachmentdir if not -d $attachmentdir and $i{iattachslip} ;
$ignore_attach{iattachslip} = '' ;
$ignore_attach{iattachupload_1} = 1 ;
$ignore_attach{iattachupload_2} = 1 ;
$ignore_attach{iattachupload_3} = 1 ;
&common_upload_files("slips/$i{id}") ;
} #------------------------------------------------------------------------------------------
sub process_cost_items_full_half_day {
# &db_min_ro('event_cost_items','id','','','') ;
&db_min_ro('event_cost_items','id',"excl_from_expenses < 1",'','') ;
foreach (keys %{$db{event_cost_items}}) {
$ignore{"full_costing_event_$_"} = 1 ;
$ignore{"full_workings_event_$_"} = 1 ;
$ignore{"half_costing_event_$_"} = 1 ;
$ignore{"half_workings_event_$_"} = 1 ;
# $ignore{"prev_item_costing_event_$_"} = 1 ;
# $ignore{"prev_item_workings_event_$_"} = 1 ;
}
for (1 .. 100) {
$ignore{"added_full_day_cost_item_$_"} = 1 ;
$ignore{"added_half_day_cost_item_$_"} = 1 ;
$i_quote_tab_default_full_half_items .= ($i{"added_full_day_cost_item_$_"}) ? qq~1:$i{"added_full_day_cost_item_$_"};~ : ($i{"added_half_day_cost_item_$_"}) ? qq~2:$i{"added_half_day_cost_item_$_"};~ :qq~;~ ;
}
$i_quote_tab_default_full_half_items =~ s/;+$//;
} #------------------------------------------------------------------------------------------
sub sync_to_sss {
return unless $db{$table}{$i{id}}{sss_quote_nr} ;
my $sss_quote_nr = $db{$table}{$i{id}}{sss_quote_nr} ;
&db_switch_conn('sss');
my $reload_quote_id = $i{id} ;
%i = () ; %ignore = () ;
&db_min_ro('event_quotes','1,supplier_type_ids',"id='$sss_quote_nr'",'','') ;
my $cnt = 0 ;
$i{supplier_type_ids} = $sss{supplier_type_ids} ;
foreach (sort split(/\;/,$db{event_quotes}{1}{supplier_type_ids})) {
if ($_ ne '4' && $_ ne '5' && $_ ne '6' && $_ ne '7' && $_ ne '8') {
$i{supplier_type_ids} .= ($i{supplier_type_ids}) ? qq~;$_~ : qq~$_~ ;
}
}
# if ($sss{type} eq '10' && $db{event_quotes}{1}{supplier_type_ids} !~ /\b8\b/) {
# foreach (split(/\;/,$db{event_quotes}{1}{supplier_type_ids})) {
# $i{supplier_type_ids} .= qq~$_;~ if $_ ne '4' && $_ ne '5' && $_ ne '6' && $_ ne '7' && $_ ne '8' ;
# }
# $i{supplier_type_ids} .= qq~8~ ;
# } elsif ($sss{type} eq '13' && $db{event_quotes}{1}{supplier_type_ids} !~ /\b7\b/) {
# foreach (split(/\;/,$db{event_quotes}{1}{supplier_type_ids})) {
# $i{supplier_type_ids} .= qq~$_;~ if $_ ne '4' && $_ ne '5' && $_ ne '6' && $_ ne '7' && $_ ne '8' ;
# }
# $i{supplier_type_ids} .= qq~7~ ;
# } elsif ($sss{type} eq '3' && $db{event_quotes}{1}{supplier_type_ids} !~ /\b6\b/) {
# foreach (split(/\;/,$db{event_quotes}{1}{supplier_type_ids})) {
# $i{supplier_type_ids} .= qq~$_;~ if $_ ne '4' && $_ ne '5' && $_ ne '6' && $_ ne '7' && $_ ne '8' ;
# }
# $i{supplier_type_ids} .= qq~6~ ;
# } elsif ($sss{type} eq '2' && $db{event_quotes}{1}{supplier_type_ids} !~ /\b5\b/) {
# foreach (split(/\;/,$db{event_quotes}{1}{supplier_type_ids})) {
# $i{supplier_type_ids} .= qq~$_;~ if $_ ne '4' && $_ ne '5' && $_ ne '6' && $_ ne '7' && $_ ne '8' ;
# }
# $i{supplier_type_ids} .= qq~5~ ;
# }
$i{datetime} = $sss{datetime} ;
$i{last_update} = $sss{last_update} ;
$i{quote_date} = $sss{quote_date} if $sss{quote_date} ;
$i{date_from} = $sss{date_from} if $sss{date_from} ;
$i{date_to} = $sss{date_to} if $sss{date_to} ;
$i{qty} = $sss{qty} || 1 ;
$i{times_from} = $sss{times_from} if $sss{times_from} ;
$i{times_to} = $sss{times_to} if $sss{times_to} ;
$i{days_active} = $sss{days_active} if $sss{days_active} ;
$i{event_length} = $sss{event_length} if $sss{event_length} ;
$i{quote_pending} = $sss{quote_pending} ;
$i{quote_accepted} = $sss{quote_accepted} ;
$i{quote_cancelled} = $sss{quote_cancelled} ;
$i{quote_completed} = $sss{quote_completed} ;
$i{quote_rejected} = $sss{quote_rejected} ;
$i{ref} = $sss{ref} ;
$i{quote_to} = $sss{quote_to} ;
$i{notes} = $sss{notes} ;
$i{office_notes} = $sss{office_notes} ;
$i{poc_id} = $sss{poc_id} ;
# $i{poc_name} = $sss{poc_name} ;
# $i{poc_contact_nr} = $sss{poc_contact_nr} ;
# $i{festival_league_name} = $sss{festival_league_name} ;
$i{category_id_1} = $sss{category_id_1} ;
$i{category_id_2} = $sss{category_id_2} ;
my $category_details = ($sss{category_1_details} || $sss{category_2_details}) ? qq~$sss{category_1_details}|;|$sss{category_2_details}~ : qq~~ ;
$i{category_details} = $category_details ;
$i{recipient_id} = $sss{recipient_id} ;
# $i{recipient_name} = $sss{recipient_name} ;
# $i{recipient_nr} = $sss{recipient_nr} ; $ignore{recipient_nr} = 0 ;
$i{additional_notes} = $sss{additional_notes} ;
$i{linear_id} = $sss{linear_id} ;
$i{nr_of_units} = $sss{nr_of_systems} ;
$i{organisation_ids} = $sss{organisation_ids} ;
$i{city_ids} = $sss{city_id} ; $i{city_ids} =~ s/\,/\;/g ; $ignore{city_ids} = 0 ;
$i{region_id} = $sss{region_id} ;
$i{sport_type_ids} = $sss{sport_type_ids} ; $i{sport_type_ids} =~ s/\,/\;/g ;
$i{upload_1} = $sss{upload_1} ;
$i{upload_2} = $sss{upload_2} ;
$i{upload_3} = $sss{upload_3} ;
$ignore{upload_1} = (!$i{upload_1}) ? 1 : 0 ;
$ignore{upload_2} = (!$i{upload_2}) ? 1 : 0 ;
$ignore{upload_3} = (!$i{upload_3}) ? 1 : 0 ;
$i{event_system_id_multiple} = $sss{event_system_id_multiple} ;
$i{club_ids} = $sss{club_ids} ;
&db_min_upd($table,"id='$sss_quote_nr'") ;
#______________ Copying Files to SSS
$i{iattachupload_1} = $sss{iattachupload_1} ;
$i{iattachupload_2} = $sss{iattachupload_2} ;
$i{iattachupload_3} = $sss{iattachupload_3} ;
my $to_dir = $htmlpath_sss . "/uploads/uploads/$sss_quote_nr" ;
our $upload_files_to_sss = 1 ;
my $from_dir = "$htmlpath/uploads/uploads/$reload_quote_id" ;
$i{iattachupload_1} = &common_process_uploaded_file_names($i{iattachupload_1},"upload_1") if $i{iattachupload_1} ;
$i{iattachupload_2} = &common_process_uploaded_file_names($i{iattachupload_2},"upload_2") if $i{iattachupload_2} ;
$i{iattachupload_3} = &common_process_uploaded_file_names($i{iattachupload_3},"upload_3") if $i{iattachupload_3} ;
&common_min_copy_files($from_dir,$to_dir,"$i{iattachupload_1}") if $i{iattachupload_1} ;
&common_min_copy_files($from_dir,$to_dir,"$i{iattachupload_2}") if $i{iattachupload_2} ;
&common_min_copy_files($from_dir,$to_dir,"$i{iattachupload_3}") if $i{iattachupload_3} ;
$upload_files_to_sss = 0 ;
#______________ Copying Files to SSS
&db_switch_conn('aisa');
# foreach (keys %sss) {
# $i{$_} = $sss{$_} unless $ignore{$_} ;
# }
$i{id} = $reload_quote_id ;
} #------------------------------------------------------------------------------------------
sub log_changes {
return unless $line ;
chop $line ;
&common_log_changes("events/changes.dat",$line) ;
if ($db{$table}{$i{id}}{quote_accepted}) { # Can you change it that she only gets emails where an Accepted Event been edited by school manager and when they upload docs afterwards, She just need notification if there been changes to event she or anyone else already accepted it
# if (!$quote_accepted || $is_schools_manager || $glod_user_level < 4) {
if (!$quote_accepted || $is_schools_manager || $glod_user_level < 3) {
&send_email_to_manager($i{id},$status,$line) ;
}
}
} #------------------------------------------------------------------------------------------
sub process_times_from {
# for (1 .. 6) {
# $ignore{"time_from_$_"} = 1 ;
# $ignore{"time_to_$_"} = 1 ;
# $i{times_from} .= qq~$i{"time_from_$_"};~ if $_ > 1 ;
# $i{times_to} .= qq~$i{"time_to_$_"};~ if $_ < 6 ;
# }
# chop $i{times_from} if $i{times_from} ;
# chop $i{times_to} if $i{times_to} ;
} #------------------------------------------------------------------------------------------
sub send_email_to_manager {
my ($event_id,$status,$msg) = @_ ;
return if $username eq 'marizen' ; # don't send to marizen if she did the change.
my $usernametemp = (substr($username,0,4) eq 'rory') ? 'rory' : $username ;
my $attachpath = "$pdfpath/event_details" ; $attachfile = "Event_Details-$event_id.pdf" ;
my $subj = 'Event [' . $event_id . ']' ;
$subj .= " $status" if $status ;
$subj .= " by $username" if $username ;
$subj .= " : $i{ref}" if $i{ref} ;
my $event_details_pdf = get("$useropts{domain}$useropts{'scripts'}/pdf/event_details_pdf.pl?$event_id&&") ;
my $to = ($useropts{it}{$usernametemp}) ? "$usernametemp\@kre8it.co.za" : $email_events{1} ;
$got_mail_add{$to} = 1 ;
my $cc = ($is_schools_manager) ? "$useremail" : (!$got_mail_add{$useremail}) ? "$useremail" : '' ;
# my $bcc = ($useropts{it}{$usernametemp}) ? '' : 'rory@kre8it.co.za' ;
my $bcc = '' ;
&common_send_smtp_mail('',$to,$cc,$bcc,"$subj","Click here to view event details
$msg",'','html','',$attachpath,$attachfile,'',0,0) ;
} #------------------------------------------------------------------------------------------
sub build_event_details_fields {
my ($quote_accepted,$quote_rejected,$quote_cancelled) = @_ ;
# $i{operator_ids} .= qq~;\~;~ ;
our $cnt_last_system_row = 0 ;
for (1 .. $nr_of_system_names_and_clubs) {
$cnt_last_system_row = $_ if $i{"system_name_$_"} || $i{"club_name_$_"} ;
my $system_name = "system_name_$_" ;
my $club_name = "club_name_$_" ;
my $op_name = "operator_id_calibration_$_" ;
# my $sss_fixed_systems = "sss_fixed_systems_$_" ;
$ignore{$system_name} = 1 ;
$ignore{$club_name} = 1 ;
$ignore{$op_name} = 1 ;
# $ignore{$sss_fixed_systems} = 1 ;
}
return if ($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3 ;
unless ($cnt_last_system_row) {
$i{club_ids} = qq~~ ;
$i{event_system_id_multiple} = qq~~ ;
return ;
}
# return if $is_schools_manager ;
# return if $glod_user_level < 4 ;
# return if $glod_user_level < 3 ;
$i{operator_ids} = '' ;
# our $cnt_rows = 0 ;
my $sss_fixed_systems_exists = 0 ;
my @saved_system_ids = split(/\;/,$db{$table}{$i{id}}{event_system_id_multiple}) ;
my %sss_fixed_system = () ;
foreach (@saved_system_ids) {
my $system_id_ = $_ ;
$system_id_ =~ s/f-//g ;
$sss_fixed_system{$system_id_} = 1 if $_ =~ /f-/ ;
}
for my $event_row (1 .. $nr_of_system_names_and_clubs) {
my $op_name = "operator_id_calibration_$event_row" ;
$i{operator_ids} .= ($event_row <= $cnt_last_system_row || ($event_row > $cnt_last_system_row && $i{$op_name})) ? qq~$i{$op_name},~ : qq~~ ;
next if $event_row > $cnt_last_system_row ;
# my $sss_fixed_systems = "sss_fixed_systems_$event_row" ;
# $sss_fixed_systems_exists = 1 if $i{$sss_fixed_systems} ;
# next if $i{$sss_fixed_systems} ;
my $system_name = "system_name_$event_row" ;
my $club_name = "club_name_$event_row" ;
# next if !$i{$system_name} && !$i{$club_name} ;
# $cnt_rows++ ;
$i{club_ids} .= qq~$i{$club_name};~ ;
# $i{event_system_id_multiple} .= ($i{$sss_fixed_systems}) ? qq~f-$i{$system_name};~ : qq~$i{$system_name};~ ;
# my $saved_system_id = $saved_system_ids[$event_row-1] ;
# $saved_system_id =~ s/f-//g ;
$i{event_system_id_multiple} .= ($i{$system_name} && $sss_fixed_system{$i{$system_name}}) ? qq~f-$i{$system_name};~ : (!$i{$system_name} && $saved_system_ids[$event_row - 1] =~ /f-/) ? qq~$saved_system_ids[$event_row - 1];~ : qq~$i{$system_name};~ ;
# &process_system_club_operator($event_row) ;
}
# if ($sss_fixed_systems_exists) {
# for my $event_row (1 .. $nr_of_system_names_and_clubs) {
# my $sss_fixed_systems = "sss_fixed_systems_$event_row" ;
# next if !$i{$sss_fixed_systems} ;
# process_system_club_operator($event_row) ;
# }
# }
$ignore{club_name} = 1 ;
$i{club_ids} =~ s/;+$//;
$i{event_system_id_multiple} =~ s/;+$//;
if ($i{event_system_id_multiple} =~ /f-/) {
my @upd_systems = split(/\;/,$i{event_system_id_multiple}) ;
if ($upd_systems[-1] !~ /f-/) {
$i{event_system_id_multiple} =~ s/f-//g ;
} else {
my $cnt__ = 0 ;
foreach (@upd_systems) {
if ($upd_systems[$cnt__] =~ /f-/ && $upd_systems[$cnt__ + 1] && $upd_systems[$cnt__ + 1] !~ /f-/) {
$i{event_system_id_multiple} =~ s/f-//g ;
last ;
}
$cnt__++ ;
}
}
}
# chop $i{club_ids} if $i{club_ids} ;
# chop $i{event_system_id_multiple} if $i{event_system_id_multiple} ;
# chop $i{operator_ids} if $i{operator_ids} ;
} #------------------------------------------------------------------------------------------
# sub process_system_club_operator {
# my ($event_row) = @_ ;
# my $system_name = "system_name_$event_row" ;
# my $club_name = "club_name_$event_row" ;
# my $op_name = "operator_id_calibration_$event_row" ;
# return if !$i{$system_name} && !$i{$club_name} ;
# $cnt_rows++ ;
# $i{club_ids} .= qq~$i{$club_name};~ ;
# $i{event_system_id_multiple} .= ($i{$sss_fixed_systems}) ? qq~f-$i{$system_name};~ : qq~$i{$system_name};~ ;
# $i{operator_ids} .= qq~$i{$op_name},~ if $cnt_rows <= $cnt_last_row ;
# } #------------------------------------------------------------------------------------------
sub process_daily_details_from_the_events_datails_tab {
my ($id) = @_ ;
use Time::Piece ;
# my $final_day = 0 ;
# for (1 .. 20) {
# $final_day = $_ if $i{"day_$_"} ;
# }
my $final_day = &common_min_calc_day_diff($i{date_to},$i{date_from}) ;
for my $event_day (1 .. 20) {
$ignore{"time_from_$event_day"} = 1 ;
$ignore{"time_to_$event_day"} = 1 ;
$ignore{"day_$event_day"} = 1 ;
$ignore{"event_length_$event_day"} = 1 ;
$ignore{"selected_$event_day\_event_length"} = 1;
$i{times_from} .= qq~$i{"time_from_$event_day"};~ if $event_day > 1 && $i{"day_$event_day"} ;
$i{times_from} .= qq~;~ if $event_day > 1 && !$i{"day_$event_day"} ;
$i{times_to} .= qq~$i{"time_to_$event_day"};~ if $event_day < $final_day && $i{"day_$event_day"};
$i{times_to} .= qq~;~ if $event_day < $final_day && !$i{"day_$event_day"};
$i{days_active} .= qq~$i{"day_$event_day"};~ ;
$i{event_length} .= ($i{"day_$event_day"}) ? qq~$i{"event_length_$event_day"};~ : qq~;~ ;
}
# my $sss_fixed_systems_exists = 0 ;
for my $event_row (1 .. $nr_of_system_names_and_clubs) {
# my $sss_fixed_systems = "sss_fixed_systems_$event_row" ;
# $sss_fixed_systems_exists = 1 if $i{$sss_fixed_systems} ;
# next if $i{$sss_fixed_systems} ;
# &process_daily_operator_ids($event_row) ;
$ignore{"clicked_button_$event_row"} = 1 ;
my $system_name = "system_name_$event_row" ;
my $club_name = "club_name_$event_row" ;
# if (!$i{$system_name} && !$i{$club_name}) {
if ($cnt_last_system_row < $event_row) {
for my $event_day (1 .. 20) {
$ignore{"custom_operator_$event_row\_$event_day"} = 1 ;
}
next ;
}
for my $event_day (1 .. 20) {
$ignore{"custom_operator_$event_row\_$event_day"} = 1 ;
if ($i{"clicked_button_$event_row"}) {
$i{"custom_operator_$event_row\_$event_day"} = "" unless $i{"day_$event_day"} ;
$i{daily_operator_ids} .= qq~$i{"custom_operator_$event_row\_$event_day"};~ ;
}
}
# chop $i{daily_operator_ids} if $i{daily_operator_ids} && $i{"clicked_button_$event_row"} ;
$i{daily_operator_ids} =~ s/;+$//;
$i{daily_operator_ids} .= qq~|~ ;
}
# if ($sss_fixed_systems_exists) {
# for my $event_row (1 .. $nr_of_system_names_and_clubs) {
# my $sss_fixed_systems = "sss_fixed_systems_$event_row" ;
# next if !$i{$sss_fixed_systems} ;
# &process_daily_operator_ids($event_row) ;
# }
# }
$i{daily_operator_ids} =~ s/\|+$//;
# chop $i{daily_operator_ids} if $i{daily_operator_ids} ;
# chop $i{times_from} if $i{times_from} ;
# chop $i{times_to} if $i{times_to} ;
# chop $i{days_active} if $i{days_active} ;
# chop $i{event_length} if $i{event_length} ;
$i{times_from} =~ s/([^;])(;+)\z/$1/;
$i{times_to} =~ s/([^;])(;+)\z/$1/;
$i{days_active} =~ s/([^;])(;+)\z/$1/;
$i{event_length} =~ s/([^;])(;+)\z/$1/;
# $ignore{daily_operator_ids} = 1 if $i{daily_operator_ids} eq $db{$table}{$id}{daily_operator_ids} ;
# $ignore{times_from} = 1 if $i{times_from} eq $db{$table}{$id}{times_from} ;
# $ignore{times_to} = 1 if $i{times_to} eq $db{$table}{$id}{times_to} ;
# $ignore{days_active} = 1 if $i{days_active} eq $db{$table}{$id}{days_active} ;
# $ignore{event_length} = 1 if $i{event_length} eq $db{$table}{$id}{event_length} ;
} #------------------------------------------------------------------------------------------
# sub process_daily_operator_ids {
# my ($event_row) = @_ ;
# $ignore{"clicked_button_$event_row"} = 1 ;
# my $system_name = "system_name_$event_row" ;
# my $club_name = "club_name_$event_row" ;
# if (!$i{$system_name} && !$i{$club_name}) {
# for my $event_day (1 .. 20) {
# $ignore{"custom_operator_$event_row\_$event_day"} = 1 ;
# }
# return ;
# }
# for my $event_day (1 .. 20) {
# $ignore{"custom_operator_$event_row\_$event_day"} = 1 ;
# if ($i{"clicked_button_$event_row"}) {
# $i{"custom_operator_$event_row\_$event_day"} = "" unless $i{"day_$event_day"} ;
# $i{daily_operator_ids} .= qq~$i{"custom_operator_$event_row\_$event_day"};~ ;
# }
# }
# chop $i{daily_operator_ids} if $i{daily_operator_ids} && $i{"clicked_button_$event_row"} ;
# $i{daily_operator_ids} .= qq~|~ ;
# } #------------------------------------------------------------------------------------------
sub build_working_fields {
my ($id,$quote_accepted,$quote_rejected,$quote_cancelled) = @_ ;
if (($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3) {
### ADD IGNORE WITH EVENT SYSTEM NAME TABLE
for my $col (1 .. 20) {
$ignore{"time_from_$col"} = 1 ;
$ignore{"time_to_$col"} = 1 ;
$ignore{"day_$col"} = 1 ;
for (1 .. 15) {
$ignore{"custom_operator_$_\_$col"} = 1 ;
}
}
$ignore{total_amount_workings_event} = 1 ;
$ignore{total_vat_amount_workings_event} = 1 ;
$ignore{total_grand_amount_workings_event} = 1 ;
return ;
}
# if ($glod_user_level < 3) {
# $ignore{daily_operator_ids} = 1 ;
# $ignore{event_length} = 1 ;
# $ignore{times_from} = 1 ;
# $ignore{times_to} = 1 ;
# $ignore{event_length} = 1 ;
# }
&process_daily_details_from_the_events_datails_tab($id) ;
my $diplayed_exp_tab = 0 ; my $hidden_exp_tab = 0 ;
if ($glod_user_level > 3) {
# if ($glod_user_level > 2) {
$diplayed_exp_tab = 1 ;
} elsif ($glod_user_level < 4) {
# } elsif ($glod_user_level < 3) {
$hidden_exp_tab = 1 ;
# $ignore{sub_total} = 1 ;
# $ignore{vat_total} = 1 ;
# $ignore{grand_total} = 1 ;
}
# return if !$diplayed_exp_tab && !$hidden_exp_tab ;
$i{sub_total} = $i{sub_total_costing_event} ;
$i{vat_total} = $i{vat_total_costing_event} ;
$i{grand_total} = $i{grand_total_costing_event} ;
# $i{profit_loss} =~ s/\,//g ;
# $i{sub_total} =~ s/\,//g ;
# $i{vat_total} =~ s/\,//g ;
# $i{grand_total} =~ s/\,//g ;
$ignore{sub_total_workings_event} = 1 ;
$ignore{vat_total_workings_event} = 1 ;
$ignore{grand_total_workings_event} = 1 ;
$ignore{sub_total_costing_event} = 1 ;
$ignore{vat_total_costing_event} = 1 ;
$ignore{grand_total_costing_event} = 1 ;
$ignore{sub_total} = 1 if $i{sub_total} eq $db{$table}{$id}{sub_total} ;
$ignore{vat_total} = 1 if $i{vat_total} eq $db{$table}{$id}{vat_total} ;
$ignore{grand_total} = 1 if $i{grand_total} eq $db{$table}{$id}{grand_total} ;
for (1 .. 50) {
$y{1}{$_} = "excl_costing_event_$_" ;
$y{2}{$_} = "description_costing_event_$_" ;
$y{3}{$_} = "qty_costing_event_$_" ;
$y{4}{$_} = "amount_usd_costing_event_$_" ;
$y{5}{$_} = "amount_ttl_costing_event_$_" ;
$y{6}{$_} = "vat_costing_event_$_" ;
$y{7}{$_} = "excl_workings_event_$_" ;
$y{8}{$_} = "description_workings_event_$_" ;
$y{9}{$_} = "operator_workings_event_$_" ;
$y{10}{$_} = "remarks_workings_event_$_" ;
$y{11}{$_} = "supplier_workings_event_$_" ;
$y{12}{$_} = "ref_nr_workings_event_$_" ;
$y{13}{$_} = "qty_workings_event_$_" ;
$y{14}{$_} = "amount_usd_workings_event_$_" ;
$y{15}{$_} = "amount_ttl_workings_event_$_" ;
$y{16}{$_} = "vat_workings_event_$_" ;
# $y{17}{$_} = "curr_amnt_costing_event_$_" ;
$hidden_expenses_amounts_exist = ($hidden_expenses_amounts_exist || ($glod_user_level < 4 && ($y{8}{$_} || $y{9}{$_} || $y{13}{$_} || $i{$y{14}{$_}} || $i{$y{15}{$_}}))) ? 1 : 0 ;
foreach my $a (keys %y) {
foreach my $b (keys %{$y{$a}}) {
$ignore{$y{$a}{$b}} = 1 ;
$x{$a}{$b} = $i{$y{$a}{$b}} ;
}
}
}
# return if $i{custom_set} ;
if ($i{custom_set}) {
$i{total_amount_workings_event} = $i{sub_total_workings_event} ;
$i{total_vat_amount_workings_event} = $i{vat_total_workings_event} ;
$i{total_grand_amount_workings_event} = $i{grand_total_workings_event} ;
return ;
}
$i{total_amount_workings_event} = 0 ;
$i{total_vat_amount_workings_event} = 0 ;
$i{total_grand_amount_workings_event} = 0 ;
my %operator_day_count = () ; my %operator_row = () ;
my $operator_count = 0 ;
my %ii = () ;
# $i{operator_ids} = $db{$table}{$id}{operator_ids} if $glod_user_level < 3 ;
my @operator_ids = split(/\,/,$i{operator_ids}) ;
&db_min_ro('event_systems','id,system_type','','','') ;
for my $system_name_row_nr (1 .. $nr_of_system_names_and_clubs) {
my $field4 = "system_name_$system_name_row_nr" ;
# next if !$i{$field4} || $i{$field4} < 0 ;
$i{$field4} = -1 if !$i{$field4} && $i{"clicked_button_$system_name_row_nr"} ;
next unless $i{$field4} ;
for my $days (1 .. 20) {
my $day_field = "day_$days" ;
next unless $i{$day_field} ;
my $field1 = "custom_operator_$system_name_row_nr\_$days" ;
my $field2 = "operator_id_calibration_$system_name_row_nr" ;
my $field3 = "event_length_$days" ;
if ($i{$field1}) {
if ($i{$field4} eq '-1') {
$operator_day_count{blank_system}{$i{$field1}}++ ;
} elsif ($i{$field3} eq '1' && $db{event_systems}{$i{$field4}}{system_type} ne 'fixed') { #full day
$operator_day_count{afull_day_mobile}{$i{$field1}}++ ;
} elsif (($i{$field3} eq '1' && $db{event_systems}{$i{$field4}}{system_type} eq 'fixed') or ($i{$field3} eq '2' && $db{event_systems}{$i{$field4}}{system_type} ne 'fixed')) { #full day
$operator_day_count{bfull_day_fixed_half_day_mobile}{$i{$field1}}++ ;
} elsif ($i{$field3} eq '2' && $db{event_systems}{$i{$field4}}{system_type} eq 'fixed') {
$operator_day_count{chalf_day_fixed}{$i{$field1}}++ ;
}
}
}
}
if ($i{operator_ids}) {
my $cnt = 0 ;
foreach my $op_id (@operator_ids) {
$cnt++ ;
next unless $op_id ;
my $field5 = "system_name_$cnt" ;
$i{$field5} = -1 if !$i{$field5} && $i{"operator_id_calibration_$cnt"} ;
# if ($i{$field5} && $i{$field5} > 0) {
for my $days (1 .. 20) {
my $day_field = "day_$days" ;
next unless $i{$day_field} ;
my $field6 = "event_length_$days" ;
if ($i{$field5} eq '-1') {
$operator_day_count{blank_system}{$op_id}++ ;
} elsif ($i{$field6} eq '1' && $db{event_systems}{$i{$field5}}{system_type} && $db{event_systems}{$i{$field5}}{system_type} ne 'fixed') { #full day
$operator_day_count{afull_day_mobile}{$op_id}++ ;
} elsif (($i{$field6} eq '1' && $db{event_systems}{$i{$field5}}{system_type} eq 'fixed') or ($i{$field6} eq '2' && $db{event_systems}{$i{$field5}}{system_type} && $db{event_systems}{$i{$field5}}{system_type} ne 'fixed')) { #full day
$operator_day_count{bfull_day_fixed_half_day_mobile}{$op_id}++ ;
} elsif ($i{$field6} eq '2' && $db{event_systems}{$i{$field5}}{system_type} eq 'fixed') {
$operator_day_count{chalf_day_fixed}{$op_id}++ ;
}
}
next if $i{$field5} eq '-1' || $db{event_systems}{$i{$field5}}{system_type} ;
# } else {
for my $days (1 .. 20) {
my $day_field = "day_$days" ;
next unless $i{$day_field} ;
my $field6 = "event_length_$days" ;
if ($i{$field6} eq '1' && $i{type} ne '3') { #full day
$operator_day_count{afull_day_mobile}{$op_id}++ ;
} elsif (($i{$field6} eq '1' && $i{type} eq '3') or ($i{$field6} eq '2' && $i{type} ne '3')) { #full day
$operator_day_count{bfull_day_fixed_half_day_mobile}{$op_id}++ ;
} elsif ($i{$field6} eq '2' && $i{type} eq '3') {
$operator_day_count{chalf_day_fixed}{$op_id}++ ;
}
}
# }
}
}
my %iii = %i ;
our %i2 = () ;
for (1 .. 50) {
if ($i{"description_workings_event_$_"} eq '14' && $i{"operator_workings_event_$_"}) {
my $op = $i{"operator_workings_event_$_"} ;
my $day_len = ($i{"amount_usd_workings_event_$_"} eq '1000.00' || $db{event_quotes}{$id}{demo_id}) ? "afull_day_mobile" : ($i{"amount_usd_workings_event_$_"} eq '750.00') ? "bfull_day_fixed_half_day_mobile" : ($i{"amount_usd_workings_event_$_"} eq '500.00') ? "chalf_day_fixed" : "" ;
if ($day_len) {
$saved_values{$day_len}{$op}{saved_values} = 1 ;
$saved_values{$day_len}{$op}{supplier_workings_event} = $i{"supplier_workings_event_$_"} ;
$saved_values{$day_len}{$op}{ref_nr_workings_event} = $i{"ref_nr_workings_event_$_"} ;
$saved_values{$day_len}{$op}{remarks_workings_event} = $i{"remarks_workings_event_$_"} ;
$saved_values{$day_len}{$op}{vat_workings_event} = $i{"vat_workings_event_$_"} ;
$saved_values{$day_len}{$op}{excl_workings_event} = $i{"excl_workings_event_$_"} ;
# $saved_values{$day_len}{$op}{amount_usd_workings_event} = $i{"amount_usd_workings_event_$_"} if $day_len eq "other" ;
}
}
$i{"description_workings_event_$_"} = "" ;
$i{"operator_workings_event_$_"} = "" ;
$i{"qty_workings_event_$_"} = "" ;
$i{"amount_usd_workings_event_$_"} = "" ;
$i{"amount_ttl_workings_event_$_"} = "" ;
$i{"excl_workings_event_$_"} = "1";
$i{"vat_workings_event_$_"} = "" ;
$i{"supplier_workings_event_$_"} = "" ;
$i{"ref_nr_workings_event_$_"} = "" ;
$i{"remarks_workings_event_$_"} = "" ;
}
my $row_cnt = 0 ;
foreach my $len (sort keys %operator_day_count) {
foreach $op_id (sort keys %{$operator_day_count{$len}}) {
$row_cnt++ ;
$i2{description_workings_event} .= '14;' ;
$i2{operator_workings_event} .= "$op_id;" ;
$i2{qty_workings_event} .= "$operator_day_count{$len}{$op_id};" ;
# my $custom_saved_amnt = $saved_values{"other"}{$op_id}{amount_usd_workings_event} ;
$i2{amount_usd_workings_event} .= ($len eq 'blank_system') ? '0.00' : ($len eq "afull_day_mobile") ? '1000.00' : ($len eq "bfull_day_fixed_half_day_mobile") ? '750.00' : '500.00' ;
$i2{amount_usd_workings_event} .= qq~;~ ;
my $amnt = ($len eq 'blank_system') ? 0 : ($len eq "afull_day_mobile") ? 1000 * $operator_day_count{$len}{$op_id} * $i{roe} : ($len eq "bfull_day_fixed_half_day_mobile") ? 750 * $operator_day_count{$len}{$op_id} * $i{roe} : 500 * $operator_day_count{$len}{$op_id} * $i{roe} ;
$amnt = sprintf ("%0.2f",$amnt) ;
$i2{amount_workings_event} .= "$amnt;" ;
$i{total_amount_workings_event} += $amnt if !$saved_values{$len}{$op_id}{excl_workings_event} ;
if ($saved_values{$len}{$op_id}{saved_values}) {
foreach (keys %{$saved_values{$len}{$op_id}}) {
$i2{$_} .= qq~$saved_values{$len}{$op_id}{$_};~ if $_ ne "saved_values" ;
$i{total_vat_amount_workings_event} += $amnt*0.15 if !$saved_values{$len}{$op_id}{excl_workings_event} && $saved_values{$len}{$op_id}{vat_workings_event} && $_ eq "vat_workings_event" ;
}
} else {
$i2{supplier_workings_event} .= ";" ;
$i2{ref_nr_workings_event} .= ";" ;
$i2{remarks_workings_event} .= ";" ;
$i2{vat_workings_event} .= "1;" ;
$i2{excl_workings_event} .= "0;" ;
$i{total_vat_amount_workings_event} += $amnt*0.15 ;
}
}
}
for (1 .. 50) {
if ($iii{"description_workings_event_$_"} && $iii{"description_workings_event_$_"} ne '14') {
$row_cnt++ ;
$i2{"excl_workings_event"} .= qq~$iii{"excl_workings_event_$_"};~ ;
$i2{"description_workings_event"} .= qq~$iii{"description_workings_event_$_"};~ ;
$i2{"operator_workings_event"} .= qq~$iii{"operator_workings_event_$_"};~ ;
$i2{"remarks_workings_event"} .= qq~$iii{"remarks_workings_event_$_"};~ ;
$i2{"supplier_workings_event"} .= qq~$iii{"supplier_workings_event_$_"};~ ;
$i2{"ref_nr_workings_event"} .= qq~$iii{"ref_nr_workings_event_$_"};~ ;
$i2{"qty_workings_event"} .= qq~$iii{"qty_workings_event_$_"};~ ;
$i2{"amount_usd_workings_event"} .= qq~$iii{"amount_usd_workings_event_$_"};~ ;
$i2{"amount_workings_event"} .= qq~$iii{"amount_ttl_workings_event_$_"};~ ;
$i2{"vat_workings_event"} .= qq~$iii{"vat_workings_event_$_"};~ ;
$iii{"amount_ttl_workings_event_$_"} =~ s/\,//g ;
$i{total_amount_workings_event} += $iii{"amount_ttl_workings_event_$_"} if !$iii{"excl_workings_event_$_"} ;
$i{total_vat_amount_workings_event} += $iii{"amount_ttl_workings_event_$_"} * 0.15 if !$iii{"excl_workings_event_$_"} && $iii{"vat_workings_event_$_"} ;
}
}
unless ($row_cnt) {
$i2{excl_workings_event} = qq~~ ;
$i2{description_workings_event} = qq~~ ;
$i2{operator_workings_event} = qq~~ ;
$i2{remarks_workings_event} = qq~~ ;
$i2{supplier_workings_event} = qq~~ ;
$i2{ref_nr_workings_event} = qq~~ ;
$i2{qty_workings_event} = qq~~ ;
$i2{amount_usd_workings_event} = qq~~ ;
$i2{amount_workings_event} = qq~~ ;
$i2{vat_workings_event} = qq~~ ;
}
$i{total_grand_amount_workings_event} = $i{total_vat_amount_workings_event} + $i{total_amount_workings_event} ;
$i{profit_loss} = $db{$table}{$id}{grand_total} - $i{total_grand_amount_workings_event} ;
$i{total_amount_workings_event} = sprintf("%0.2f",$i{total_amount_workings_event}) ;
$i{total_vat_amount_workings_event} = sprintf("%0.2f",$i{total_vat_amount_workings_event}) ;
$i{total_grand_amount_workings_event} = sprintf("%0.2f",$i{total_grand_amount_workings_event}) ;
$i{profit_loss} = sprintf("%0.2f",$i{profit_loss}) ;
foreach (keys %i2) {
# chop $i2{$_} if $i2{$_} ;
# $i{$_} = $i2{$_} ;
}
} #------------------------------------------------------------------------------------------
sub build_event_quotes_min_fields {
my ($quote_accepted,$quote_rejected,$quote_cancelled) = @_ ;
my $category_details = qq~$i{category_1_details}|;|$i{category_2_details}~ if $i{category_1_details} || $i{category_2_details} ;
$i{category_details} = $category_details ;
$ignore{last_update} = 1 ;
$ignore{poc_contact_nr} = 1 ;
$ignore{poc_name} = 1 ;
$ignore{poc_id} = 1 ;
$ignore{format_of_title} = 1 ;
$ignore{additional_notes} = 1 ;
$ignore{upload_1} = 1 ;
$ignore{upload_2} = 1 ;
$ignore{upload_3} = 1 ;
$ignore{email} = 1 ;
$ignore{address} = 1 ;
$ignore{country_id} = 1 ;
$ignore{quote_date} = 1 ;
$ignore{contact_name} = 1 ;
$ignore{notes} = 1 ;
$ignore{tel} = 1 ;
$ignore{category_id_1} = 1 ;
$ignore{category_id_2} = 1 ;
$ignore{custom_set} = 1 ;
$ignore{quote_accepted} = 1 ;
$ignore{quote_cancelled} = 1 ;
$ignore{quote_rejected} = 1 ;
$ignore{quote_completed} = 1 ;
return if ($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3 ;
$iid = $i{id} ;
my $custom_set = $i{custom_set} ;
%i = %i2 ;
$i{custom_set} = $custom_set ;
if ($glod_user_level > 3) {
for (1 .. 50) {
next unless $x{2}{$_} ;
$i{excl_costing_event} .= "$x{1}{$_};" ;
$i{item_costing_event} .= "$x{2}{$_};";
$i{qty_costing_event} .= "$x{3}{$_};";
$i{usd_amnt_costing_event} .= "$x{4}{$_};";
$i{item_ttl_costing_event} .= "$x{5}{$_};";
$i{vat_costing_event} .= "$x{6}{$_};";
# $i{curr_amnt_costing_event} .= "$x{17}{$_};";
}
if ($i{custom_set}) {
for (1 .. 50) {
next unless $x{8}{$_} ;
$i{excl_workings_event} .= "$x{7}{$_};";
$i{description_workings_event} .= "$x{8}{$_};";
$i{operator_workings_event} .= "$x{9}{$_};";
$i{remarks_workings_event} .= "$x{10}{$_};";
$i{supplier_workings_event} .= "$x{11}{$_};";
$i{ref_nr_workings_event} .= "$x{12}{$_};";
$i{qty_workings_event} .= "$x{13}{$_};";
$i{amount_usd_workings_event} .= "$x{14}{$_};";
$i{amount_workings_event} .= "$x{15}{$_};";
$i{vat_workings_event} .= "$x{16}{$_};";
}
}
$i{excl_costing_event} = "" unless $i{excl_costing_event} ;
$i{item_costing_event} = "" unless $i{item_costing_event} ;
$i{qty_costing_event} = "" unless $i{qty_costing_event} ;
$i{usd_amnt_costing_event} = "" unless $i{usd_amnt_costing_event} ;
$i{item_ttl_costing_event} = "" unless $i{item_ttl_costing_event} ;
$i{vat_costing_event} = "" unless $i{vat_costing_event} ;
$i{excl_workings_event} = "" unless $i{excl_workings_event} ;
$i{description_workings_event} = "" unless $i{description_workings_event} ;
$i{operator_workings_event} = "" unless $i{operator_workings_event} ;
$i{remarks_workings_event} = "" unless $i{remarks_workings_event} ;
$i{supplier_workings_event} = "" unless $i{supplier_workings_event} ;
$i{ref_nr_workings_event} = "" unless $i{ref_nr_workings_event} ;
$i{qty_workings_event} = "" unless $i{qty_workings_event} ;
$i{amount_usd_workings_event} = "" unless $i{amount_usd_workings_event} ;
$i{amount_workings_event} = "" unless $i{amount_workings_event} ;
$i{vat_workings_event} = "" unless $i{vat_workings_event} ;
} elsif ($glod_user_level < 4 && $hidden_expenses_amounts_exist) {
for (1 .. 50) {
# $i{description_workings_event} .= "$x{8}{$_};";
# $i{operator_workings_event} .= "$x{9}{$_};";
# $i{qty_workings_event} .= "$x{13}{$_};";
# $i{amount_usd_workings_event} .= "$x{14}{$_};";
# $i{amount_workings_event} .= "$x{15}{$_};";
# $i{vat_workings_event} .= "$x{16}{$_};";
}
}
foreach (keys %i) { chop $i{$_} ; }
$i{category_details} = $category_details ;
$i{id} = $iid ;
} #------------------------------------------------------------------------------------------
sub process_multi_select {
my ($quote_accepted,$quote_rejected,$quote_cancelled) = @_ ;
# $ignore{event_system_id} = 1 ;
# if ($usertype ne 'schools_manager') {
# if ($glod_user_level > 3) {
# return if ($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3 ;
if (($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3) {
$ignore{operatorids} = 1 ;
$ignore{typedetailsid} = 1 ;
$ignore{organisationids} = 1 ;
$ignore{sporttypeids} = 1 ;
$ignore{operator_ids} = 1 ;
}
local @operatorids = split(/\,/,$i{operatorids}) ;
$i{nr_of_casuals} = scalar @operatorids || '0' ; $i{nr_of_casuals_2} = '0' ;
my $operatorids = join(",",@operatorids) ;
$operatorids =~ s/\s//g; # remove white space
$ignore{operatorids} = 1 ;
$i{operator_ids} .= $operatorids ;
$i{operator_ids} = 0 unless $i{operator_ids} ;
chop $i{operator_ids} if substr($i{operator_ids},-1,1) eq ',' ;
if ($glod_user_level > 2) {
local @typedetailsid = split(/\,/,$i{typedetailsid}) ;
my $typedetailsid = join(",",@typedetailsid) ;
$typedetailsid =~ s/\s//g; # remove white space
$ignore{typedetailsid} = 1 ;
$i{type_details_id} = $typedetailsid ;
$i{type_details_id} = 0 unless $i{type_details_id} ;
# @event_system_ids = split(/\,/,$i{event_system_ids}) ;
# my @db_event_system_ids = () ; foreach (@event_system_ids) { push @db_event_system_ids, $_ ; }
# my $db_event_system_ids = join(';',@db_event_system_ids) ;
# $ignore{event_system_ids} = 1 ;
# $i{event_system_id_multiple} = $db_event_system_ids ;
}
$ignore{city_ids} = 1 ;
$i{city_id} = $i{city_ids} ;
local @organisationids = split(/\,/,$i{organisationids}) ;
my $organisationids = join(",",@organisationids) ;
$organisationids =~ s/\s//g; # remove white space
$ignore{organisationids} = 1 ;
$i{organisation_ids} = $organisationids ;
$i{organisation_ids} = 0 unless $i{organisation_ids} ;
local @sporttypeids = split(/\,/,$i{sporttypeids}) ;
my $sporttypeids = join(",",@sporttypeids) ;
$sporttypeids =~ s/\s//g; # remove white space
$ignore{sporttypeids} = 1 ;
$i{sport_type_ids} = $sporttypeids ;
$i{sport_type_ids} = 0 unless $i{sport_type_ids} ;
local @suppliertypeids = split(/\,/,$i{suppliertypeids}) ;
my $suppliertypeids = join(";",@suppliertypeids) ;
$suppliertypeids =~ s/\s//g; # remove white space
$ignore{suppliertypeids} = 1 ;
$i{supplier_type_ids} = $suppliertypeids ;
$i{supplier_type_ids} = 0 unless $i{suppliertypeids} ;
$ignore{supplier_type_ids} = 1 ;
} #------------------------------------------------------------------------------------------
sub duplicate {
unless ($i{id}) {
$error = qq~NO ID~ ;
return ;
}
my $orig_id = $i{id} ;
&db_min_copy($table,$i{id}) ;
my $copy_id = $i{id} ;
&common_min_copy_files("$htmlpath/uploads/uploads/$orig_id","$htmlpath/uploads/uploads/$copy_id",'') ;
&db_min_ro($table,'1,sss_quote_nr',"id='$copy_id'","","") ;
my %ii = %i ;
# if ($db{$table}{1}{sss_quote_nr} || $db{$table}{1}{event_system_calibration_ids} || $db{$table}{1}{set_up_groups_status_ids}) {
%i = () ;
my %ignore_for_now = %ignore ;
%ignore = () ;
$i{sss_quote_nr} = '0' ;
&common_shared_event_quotes_column_not_to_copy ;
$ignore{sss_quote_nr} = (!$db{$table}{1}{sss_quote_nr}) ? 1 : 0 ;
# $ignore{event_system_calibration_ids} = (!$db{$table}{1}{event_system_calibration_ids}) ? 1 : 0 ;
# $ignore{set_up_groups_status_ids} = (!$db{$table}{1}{set_up_groups_status_ids}) ? 1 : 0 ;
&db_min_upd($table,"id='$copy_id'") ;
%ignore = %ignore_for_now ;
# }
%i = %ii ;
&db_min_copy('event_quotes_min',$orig_id) ;
%ii = %i ;
%i = () ;
$i{quote_nr} = $copy_id ;
$i{operator_dates_paid} = '' ;
$i{operator_dates_paid_min} = '' ;
$i{operator_amounts_paid} = '' ;
&db_min_upd('event_quotes_min',"id='$copy_id'") ;
%i = %ii ;
} #------------------------------------------------------------------------------------------
# sub copy {
# unless ($i{id}) {
# $error = qq~NO ID~ ;
# return ;
# }
# my $id = $i{id} ;
# &db_min_copy($table,$i{id}) ;
# my $id2 = $i{id} ;
# $i{id} = $id ;
# &db_min_copy('event_quotes_min',$i{id}) ;
# $i{id} = $id ;
# # use File::Copy;
# # # use File::Path 'make_path';
# # my $src_dir = "$htmlpath/uploads/uploads/$id";
# # my $dst_dir = "$htmlpath/uploads/uploads/$id2";
# # return unless -d $src_dir ;
# # mkdir $dst_dir unless -d $dst_dir ;
# # opendir(my $dh, $src_dir) or die "Can't open $src_dir: $!";
# # my $file_counter = 0 ;
# # while (my $file = readdir($dh)) {
# # next if $file =~ /^\.\.?$/; # Skip '.' and '..'
# # last if !$file || $file_counter >= 3 ;
# # my $src_file = "$src_dir/$file";
# # my $dst_file = "$dst_dir/$file";
# # copy($src_dir, $dst_dir) or warn "Failed to copy $src_file to $dst_file: $!";
# # $file_counter++ ;
# # }
# # closedir($dh);
# } #------------------------------------------------------------------------------------------
sub delete {
unless ($i{id}) { $error = uc "NO ID" ; return ; }
&db_min_ro($table,'1,sss_quote_nr',"id = '$i{id}'",'','') ;
my $sss_delete_id = $db{$table}{1}{sss_quote_nr} ;
my $aisa_delete_id = $i{id} ;
&db_min_delete('event_quotes',"`id`='$aisa_delete_id'") ;
&db_min_delete('event_quotes_min',"`id`='$aisa_delete_id'") ;
&common_min_delete_files("$htmlpath/uploads/uploads/$aisa_delete_id") ;
&common_min_delete_files("$htmlpath/pdf/event_details","Event_Details-$aisa_delete_id.pdf") ;
if ($sss_delete_id) {
&db_switch_conn('sss') ;
&db_min_ro($table,'1,id',"id = '$sss_delete_id' AND aisa_quote_nr = '$aisa_delete_id'",'','') ;
if ($db{$table}{1}{id}) {
&db_min_delete($table,"id = '$sss_delete_id'") ;
&common_min_delete_files("$htmlpath_sss/uploads/uploads/$sss_delete_id") ;
&common_min_delete_files("$htmlpath_sss/pdf/event_details","Event_Details-$sss_delete_id.pdf") ;
}
&db_switch_conn('aisa') ;
}
} #------------------------------------------------------------------------------------------
sub process_upload_ifields {
foreach (keys %uploads_file) { $i{$_} = $uploads_file{$_} ; $ignore{$_} = '' ; }
} #------------------------------------------------------------------------------------------
sub set_default_i_vals {
my $srch_where_sql = "`id`='$i{id}'" ;
$iaction eq 'save' ? &db_min_ro($table,'*','','id DESC',1) : &db_min_ro($table,'*',$srch_where_sql,'','') ;
foreach (sort { $col_name{$a} cmp $col_name{$b} } keys %col_name) {
$col = $col_name{$_} ;
# &common_min_debug("1. [$col] [$i{$col}]");
if (substr($col,0,4) eq 'vat_' or substr($col,0,5) eq 'excl_' or substr($col,0,4) eq 'qty_') {
$i{$col} = 0 unless $i{$col} ;
} # only create the column if it doesn't exist
if (substr($col,0,5) eq 'date_') {
$i{$col} = 'NULL' unless $i{$col} ;
} # only create the column if it doesn't exist
if (substr($col,0,11) eq 'amount_ttl_' or substr($col,0,9) eq 'usd_amnt_' or substr($col,0,10) eq 'curr_amnt_' or substr($col,0,9) eq 'item_ttl_' or substr($col,-6,6) eq '_total') {
$i{$col} = '0.00' unless $i{$col} ;
}
if ((substr($col,6,9) eq '_costing_' and substr($col,0,5) eq 'item_' and $i{$col}) or ($col eq 'quote_to' and $i{$col})) {
my @valarr = split(/\:/,$i{$col}) ;
$i{$col} = $valarr[0] ; # set the value to only be the id
}
}
$i{quote_completed} = 0 unless $i{quote_completed} ;
$i{quote_accepted} = 0 unless $i{quote_accepted} ;
$i{quote_pending} = 0 unless $i{quote_pending} ;
$i{quote_cancelled} = 0 unless $i{quote_cancelled} ;
$i{quote_rejected} = 0 unless $i{quote_rejected} ;
$i{annual_invoice} = 0 unless $i{annual_invoice} ;
$i{nr_of_casuals_2} = 0 unless $i{nr_of_casuals_2} ;
$i{linear_id} = 0 unless $i{linear_id} ;
$ignore{invoice_date} = 1 unless length($i{invoice_date}) == 10 ;
# if ($i{quote_completed}) {
# $i{quote_accepted} = 1 ;
# $i{quote_cancelled} = 0 ;
# $i{quote_pending} = 0 ;
# $i{quote_rejected} = 0 ;
# } elsif ($i{quote_accepted}) {
# $i{quote_cancelled} = 0 ;
# $i{quote_completed} = 0 ;
# $i{quote_pending} = 0 ;
# $i{quote_rejected} = 0 ;
# } elsif ($i{quote_rejected}) {
# $i{quote_cancelled} = 0 ;
# $i{quote_completed} = 0 ;
# $i{quote_pending} = 0 ;
# $i{quote_accepted} = 0 ;
# } elsif ($i{quote_pending}) {
# $i{quote_cancelled} = 0 ;
# $i{quote_rejected} = 0 ;
# }
$i{ligr} = ($i{ligr}) ? 'Yes' : 'No' ;
$i{city_id} = 0 unless $i{city_id} ;
$i{region_id} = 0 unless $i{region_id} ;
$i{category_id_1} = 0 unless $i{category_id_1} ;
$i{category_id_2} = 0 unless $i{category_id_2} ;
$i{po_nr} = 0 unless $i{po_nr} ;
# $i{grand_total} = '0.00' unless $i{grand_total} ;
$i{format_of_title} = uc $i{format_of_title} ;
$i{ref} = uc $i{ref} ;
$i{category_1_details} = uc $i{category_1_details} ;
$i{category_2_details} = uc $i{category_2_details} ;
&common_shared_process_poc_recipients("poc") ;
&common_shared_process_poc_recipients("recipient") ;
} #----------------------------------------------------------------------------------------
sub list_screen {
# my $page2 = 'event-quotes' ;
# if ($page2 && $ENV{SCRIPT_NAME} =~ /\_test/) { $page2 .= '-test' ; }
# my $action_delete_2 = qq~delete-$page2~ ;
# $print_footer_forms .= qq~
#
# ~ ;
$trigger_jquery_raw .= qq~
function deleteMinItem_custom (name,id) {
BootstrapDialog.confirm({
title: 'Confirm Delete',
message: 'Are you sure you want to delete '+name+'?',
type: BootstrapDialog.TYPE_DANGER, // <-- Default value is BootstrapDialog.TYPE_PRIMARY <-- Default value is BootstrapDialog.TYPE_WARNING
callback: function(result) {
if (result) {
let delete_url = "$useropts{scripts}/get/get_delete_event_quote.pl?"+id ;
\$.get(delete_url) ;
\$("#event_quote_row_"+id).html("") ;
}
}
}) ;
}
~ ;
&db_min_ro('event_type_details','id,name','','','') ;
&db_min_ro('event_quotes_categories','id,category','','','') ;
&db_min_ro('event_systems','id,name,description,system_type','','','') ;
&db_min_ro('clubs','id,name','','','') ;
&db_min_ro('cities','id,city,province','','','') ;
&db_min_ro('analytics_event_bookings','id,event_quote_id',"event_quote_id <> '0'",'','') ;
our %analytics_events = () ;
foreach (keys %{$db{analytics_event_bookings}}) {
$analytics_events{$db{analytics_event_bookings}{$_}{event_quote_id}} .= qq~$_;~ ;
}
&db_min_ro('users','id,username,name,email','','','') ;
foreach my $_id (keys %{$db{users}}) {
$username{$_id} = $db{users}{$_id}{username} ;
$name{$_id} = $db{users}{$_id}{name} ;
$email{$_id} = $db{users}{$_id}{email} ;
}
&db_min_ro('sport_types','*','','','') ;
foreach my $_id (keys %{$db{sport_types}}) { $sort_type{$_id} = $db{sport_types}{$_id}{name} ; }
&db_min_ro('organisations','id,name','','','') ;
foreach my $_id (keys %{$db{organisations}}) { $organisation{$_id} = $db{organisations}{$_id}{name} ; }
if ($iaction eq 'completed' or $i{options} eq 'completed') { push @report_sql, "q.quote_completed='1'" ; }
if ($iaction eq 'accepted' or $i{options} eq 'accepted') { push @report_sql, "q.quote_accepted='1'" ; }
if ($iaction eq 'rejected' or $i{options} eq 'rejected') { push @report_sql, "q.quote_rejected='1'" ; }
if ($iaction eq 'closed' or $i{options} eq 'closed') { push @report_sql, "(q.quote_cancelled='1' OR (q.quote_expiry<'$now_year-$now_mm-$now_dd' AND q.quote_accepted<>'1'))" ; }
if ($iaction eq 'pending' or $i{options} eq 'pending') { push @report_sql, "q.quote_pending='1'" ; }
if ($iaction eq 'list' or $i{options} eq 'list') { push @report_sql, "q.quote_cancelled<>'1'" ; }
my $t1 = 'event_quotes';
my $t2 = 'countries' ;
my $t3 = 'cities' ;
my $t4 = 'customers' ;
my $t5 = 'event_types' ;
my $t6 = 'regions' ;
my $t7 = 'event_quotes_min' ;
our $tables = "$t1,$t2,$t3,$t4,$t5,$t6,$t7" ;
if ($is_schools_manager || $is_operator) {
@report_sql_or = () ;
foreach $_reg_id (keys %{$glob_regids{$userid}}) {
push @report_sql_or, "q.region_id = '$_reg_id'"
}
my $sql_or = join(' OR ',@report_sql_or) ;
push @report_sql, "($sql_or)" if $sql_or ;
push @report_sql, "(q.quote_created='1')" if $is_schools_manager ;
# push @report_sql, "(q.user_id='$userid')" if $is_schools_manager ;
push @report_sql, "(q.quote_accepted='1')" if $is_operator && !$i{options} ;
}
push @report_sql, "(q.quote_completed <> '1')" if $iaction eq 'list' ;
my $srch_where_sql = join(' AND ', @report_sql) ; my $sql_where = ($srch_where_sql) ? "WHERE $srch_where_sql" : '' ;
&db_min_raw("SELECT q.id AS 'quote_id',
q.quote_nr,
q.sport_type_ids,
q.city_id,
q.region_id,
q.organisation_ids,
q.date_from,
q.date_to,
q.grand_total,
q.ref,
q.qty,
q.quote_expiry,
q.quote_to,
q.invoice_nr,
q.quote_date,
q.type,
q.currency,
q.country_id,
q.quote_cancelled,
q.quote_accepted,
q.quote_completed,
q.quote_pending,
q.quote_created,
q.quote_rejected,
q.activetab,
q.user_id,
q.category_1,
q.category_id_1,
q.category_2,
q.category_id_2,
q.additional_notes,
q.poc_id,
q.type_details_id,
q.club_ids,
q.event_system_id_multiple,
q.operator_ids,
q.format_of_title,
q.emailed_op_ids,
q.fixed_system_overall_status,
q.daily_operator_ids,
q.sss_quote_nr,
q.demo_id,
c.name AS 'country',
t.name AS 'customer',
y.city,
y.province,
r.code AS 'reg_code',
r.name AS 'region',
e.name AS 'event_type',
emin.category_details
FROM $t1 q LEFT JOIN $t2 c ON q.country_id = c.id
LEFT JOIN $t3 y ON q.city_id = y.id
LEFT JOIN $t4 t ON q.quote_to = t.id
LEFT JOIN $t5 e ON q.type = e.id
LEFT JOIN $t6 r ON q.region_id = r.id
LEFT JOIN $t7 emin ON q.id = emin.quote_nr
$sql_where;");
foreach $row (@$rows_array_ref) {
for (0 .. $col_cnt){
# &common_debug("[$_] $col_name{$_} -> @$row[$_]") ;
$db{$tables}{@$row[0]}{$col_name{$_}} = @$row[$_] ;
}
}
&tab_hash ; # load for PDF links
"e_list ; # load for PDF links
if ($iaction eq 'update' or $iaction eq 'save'){
&common_min_extra_crumb("list-$lcpage\s","List $ucfirstpage\s") ;
}
} #------------------------------------------------------------------------------------------
sub quote_list {
# our @sql_col_display = ("nr","date","customer","user","event","venue","location","sports_type","date_from","date_to","days","type") ;
# our @sql_col_display = ("nr","event_start","event_end","date_added","customer","user","event","venue","location","sports_type","days","type") ;
our @sql_col_display = () ;
our @col_display_excel = () ;
if ($usertype eq 'support') {
@sql_col_display = ("nr","event_start","days","event","location","sport","system_name","club_names","operators") ;
@col_display_excel = @sql_col_display ;
&report_xlsx_export_header("Events_Quotes",'events') ;
} else {
@col_display_excel = ("nr","event","event_start","event_end","days","type_of_system","system_details","system_name","sport_type","cities","region","venue","club_names","operators","client","poc_name","poc_contact_nr","category_1","category_1_details","category_2","category_2_details","format_of_title") ;
@sql_col_display = @col_display_excel ;
&report_xlsx_export_header("Events_Quotes",'events') ;
@sql_col_display = ("nr","event_start","event_end","days","date_added","customer","event","venue","location","sport","type","operators") ;
if ($userid eq '24') {
# if ($glod_user_level > 3) {
push @sql_col_display, "amount" ;
push @sql_col_display, "invoice_nr" ;
}
}
push @sql_col_display, "" ;
my @month_fullname = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") ; # if ($i{export_to_excel}) { &report_xls_export_header("Event Quotes",'event_quotes') ; }
my @day_of_week_text = ("", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") ;
our @months = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ;
foreach my $id (sort {$b <=> $a} keys %{$db{$tables}}) {
next unless $id ;
my $quote_expiry = $db{$tables}{$id}{quote_expiry} ; $quote_expiry =~ s/\-//iog ;
my $invoice_nr = $db{$tables}{$id}{invoice_nr} ;
my $quote_accepted = $db{$tables}{$id}{quote_accepted} ;
my $quote_pending = $db{$tables}{$id}{quote_pending} ;
my $quote_cancelled = $db{$tables}{$id}{quote_cancelled} ;
my $quote_completed = $db{$tables}{$id}{quote_completed} ;
my $quote_created = $db{$tables}{$id}{quote_created} ;
my $quote_rejected = $db{$tables}{$id}{quote_rejected} ;
my @cat_details = split('\|;\|',$db{$tables}{$id}{category_details}) ;
if ($quote_completed) {
$sortprefix = 'd' ;
} elsif ($quote_accepted) {
$sortprefix = 'c' ;
} elsif ($quote_rejected) {
$sortprefix = 'x' ;
} elsif ($quote_cancelled) {
$sortprefix = 'z' ;
} elsif ($quote_created) { # create by schools_manager
$sortprefix = 'a' ;
} elsif ($quote_pending) {
$sortprefix = 'b' ;
}
if ($usertype eq 'support') {
next unless $quote_accepted && !$quote_completed ;
}
# if ($quote_expiry and $quote_expiry<"$now_year$now_mm$now_dd" and $iaction ne 'report' and $iaction ne 'accepted' and $iaction ne 'closed' and $iaction ne 'all') { next ; }
my $quote_date = $db{$tables}{$id}{quote_date} ; $quote_date =~ s/\-//iog ;
$yr = substr($quote_date, 0, 4) ;
$mm = substr($quote_date, 4, 2) ;
$dd = substr($quote_date, 6, 2) ;
my ($yr2,$mm2,$dd2) = Add_Delta_Days($yr,$mm,$dd,60); #
$mm2 = sprintf("%02s", $mm2) ;
$dd2 = sprintf("%02s", $dd2) ;
$quote_date = "$yr2$mm2$dd2" ;
if ($quote_date && $quote_date < "$now_year$now_mm$now_dd" && $quote_accepted!=1 &&
$iaction ne 'report' && $iaction ne 'accepted' && $iaction ne 'closed' && $iaction ne 'all' &&
$i{options} ne 'accepted' && $i{options} ne 'closed' && $i{options} ne 'all')
{ next ; }
$print_tbody .= qq~~ ;
$xlsxcol=0;
my $quote_nr = $db{$tables}{$id}{quote_nr} ;
foreach (@sql_col_display) {
unless ($_) { next ; } # blank for the buttons column
my $val = $db{$tables}{$id}{$_} ;
my $align = qq~ class="dt-center"~ ;
my $nowrap = '' ;
# if ($_ eq 'event_end') { $val = substr($db{$tables}{$id}{date_to},0,10) ; $align = qq~ class="dt-center" style="width:6.9%"~ ; }
# elsif ($_ eq 'event_start') { $val = substr($db{$tables}{$id}{date_from},0,10) ; $nowrap = 'nowrap' ; }
if ($_ eq 'event_end') {
# my $sort_val = $db{$tables}{$id}{date_to} ;
# $sort_val =~ s/\-//g ;
# $sort_val =~ s/\://g ;
# $sort_val =~ s/ //g ;
my $sort_val = $db{$tables}{$id}{date_to} =~ s/[\-:\s]//gr;
$val = qq~$sort_val~ . &common_min_date_as_string(substr($db{$tables}{$id}{date_to},0,16)) ; $align = qq~ class="dt-center"~ ; $nowrap = 'nowrap' ;
} elsif ($_ eq 'event_start') {
my $sort_val = $db{$tables}{$id}{date_from} =~ s/[\-:\s]//gr;
$val = qq~$sort_val~ . &common_min_date_as_string(substr($db{$tables}{$id}{date_from},0,16)) ;
# my ($dy,$dm,$dd,$th,$tm,$ts) = &common_min_split_sql_date_time($db{$tables}{$id}{date_from}) ; my $sccyymmddhrmnsc = $dy . $dm . $dd . $th . $tm . $ts ; $val = "$sortprefix$sccyymmddhrmnsc" . substr($db{$tables}{$id}{date_from},0,16) ;
$nowrap = 'nowrap' ;
} elsif ($_ eq 'event') {
$val = $db{$tables}{$id}{ref} ;
$nowrap = '' ;
} elsif ($_ eq 'customer') {
$nowrap = 'nowrap' ;
} elsif ($_ eq 'date_added') {
my $sort_val = $db{$tables}{$id}{quote_date} =~ s/[\-:\s]//gr;
$val = qq~$sort_val~ . &common_min_date_as_string($db{$tables}{$id}{quote_date}) ;
$val = qq~$val~ ;
$nowrap = 'nowrap' ;
} elsif ($_ eq 'curr') {
$val = $db{$tables}{$id}{currency} ;
} elsif ($_ eq 'location') {
$val = ($db{$tables}{$id}{city} & $db{$tables}{$id}{reg_code}) ? "$db{$tables}{$id}{city}, $db{$tables}{$id}{reg_code}" : ($db{$tables}{$id}{city}) ? $db{$tables}{$id}{city} : $db{$tables}{$id}{reg_code} ;
$nowrap = 'nowrap' ;
} elsif ($_ eq 'country_id') {
$val = $db{$tables}{$id}{country} ;
} elsif ($_ eq 'days') {
$val = $db{$tables}{$id}{qty} ;
} elsif ($_ eq 'type') {
my $txt = uc substr($db{$tables}{$id}{event_type},0,1) ;
$val = qq~$txt~;
$nowrap = 'nowrap' ;
} elsif ($_ eq 'amount') {
my $ttl = sprintf("%0.2f",($db{$tables}{$id}{grand_total})) ;
$val = &common_commify($ttl) ;
} elsif ($_ eq 'system_name') {
# $val = '' ;
# foreach my $event_id (split(";",$db{$tables}{$id}{event_system_id_multiple})) {
# $val .= qq~$db{event_systems}{$event_id}{name} [$db{event_systems}{$event_id}{description}], ~ ;
# }
# chop $val if $val ; chop $val if $val ;
$val = join("
", map { "$db{event_systems}{$_}{name} [$db{event_systems}{$_}{description}]" } split(/\;/,$db{$tables}{$id}{event_system_id_multiple})) ;
} elsif ($_ eq 'club_names') {
# $val = '' ;
# foreach my $club_id (split(/\;/,$db{$tables}{$id}{club_ids})) {
# $val .= qq~$db{clubs}{$club_id}{name}, ~ ;
# }
# chop $val if $val ; chop $val if $val ;
$val = join("
",map { "$db{clubs}{$_}{name}" } split(/\;/,$db{$tables}{$id}{club_ids})) ;
} elsif ($_ eq 'operators') {
$val = '' ; $op_cnt = 0 ;
my %seen_op_id = () ;
my @op_ids = split(/\,/,$db{$tables}{$id}{operator_ids}) ;
for my $op_id (@op_ids) {
next if $seen_op_id{$op_id} || !$op_id ;
$seen_op_id{$op_id} = 1 ; $op_cnt++;
$val .= qq~$name{$op_id}
~ ;
}
foreach my $op_ids (split(/\|/,$db{$tables}{$id}{daily_operator_ids})) {
foreach my $opid (split(/\;/,$op_ids)) {
next if $seen_op_id{$opid} || !$opid ;
$seen_op_id{$opid} = 1 ; $op_cnt++;
$val .= qq~$name{$opid}
~ ;
}
}
$val = substr($val,0,-4) if $val ;
# $val = qq~~ if $val ;
$glyph_icon = ($op_cnt > 1) ? qq~~ : qq~~ ;
$val = qq~$glyph_icon~ if $val ;
} elsif ($_ eq 'venue') {
# my @oids = split(/\,/,$db{$tables}{$id}{organisation_ids}) ;
# my @venues = map { $organisation{$_} } @oids;
# $val = join(" & ",@venues) ;
$nowrap = '' ;
$val = join("
", map { $organisation{$_} } split(/\,/,$db{$tables}{$id}{organisation_ids})) ;
# foreach $_oid (@oids) {
# $val .= $organisation{$_oid} . ',' ;
# }
# chop $val ;
} elsif ($_ eq 'sport') {
# my @sptyps = split(/\,/,$db{$tables}{$id}{sport_type_ids}) ;
# my @sports = map { $sort_type{$_} } split(/\,/,$db{$tables}{$id}{sport_type_ids}) ;
# $val = join(", ",@sports) ; # foreach $_sp (@sptyps) { $val .= $sort_type{$_sp} . ', ' ; }
$val = join("
", map { $sort_type{$_} } split(/\,/,$db{$tables}{$id}{sport_type_ids})) ; # foreach $_sp (@sptyps) { $val .= $sort_type{$_sp} . ', ' ; }
# chop $val if $val ;
} elsif ($_ eq 'nr') {
$nowrap = 'nowrap' ;
$sort_val = sprintf("%06d",$id) ;
$sort_val = ($quote_accepted) ? qq~5~ . $sort_val : ($quote_completed) ? qq~4~ . $sort_val : ($quote_pending) ? qq~3~ . $sort_val : ($quote_rejected) ? qq~2~ . $sort_val : ($quote_cancelled) ? qq~1~ . $sort_val : qq~0~ . $sort_val ;
# my $event_id = $db{$tables}{$id}{id} ;
# $db{$tables}{$id}{id} = $db{$tables}{$id}{quote_id} ;
$val = qq~$sort_val~ . &common_min_get_event_quote_button($id,$tables,"event-quotes") ;
$val .= qq~~ if $db{$tables}{$id}{sss_quote_nr} ;
# $db{$tables}{$id}{id} = $event_id ;
if ($analytics_events{$id}) {
chop $analytics_events{$id} ;
foreach (sort {$a <=> $b} split(/\;/,$analytics_events{$id})) {
$val .= qq~~ ;
}
}
if ($db{$tables}{$id}{demo_id}) {
my $glod_user_level_eff = ($glod_user_level == 2 && $is_operator) ? 3 : $glod_user_level ;
# $val .= ($glod_user_level_eff < 3 || $db{$table}{$event_id}{quote_cancelled}) ?
$val .= ($glod_user_level_eff < 3 || $db{$tables}{$id}{quote_cancelled}) ?
qq~~ :
qq~~ ;
}
# my $class = 'info' ; my $style = '' ;
# if ($quote_completed) {
# $class = 'success' ; # green
# $tt_txt = 'Completed' ;
# } elsif ($quote_accepted) {
# $class = 'info' ; # blue
# $tt_txt = 'Accepted' ;
# my @fixed_system_overall_statuses = split(/\;/,$db{$tables}{$id}{fixed_system_overall_status}) ;
# my @event_system_ids = split(/\;/,$db{$tables}{$id}{event_system_id_multiple}) ;
# my $event_sys_cnt = 0 ; my $event_sys_test_status = 0 ; my $got_some_fixed = 0 ; my $fixed_status_color = '164473' ; # Dark Blue
# foreach my $event_id (@event_system_ids) {
# if ($db{event_systems}{$event_id}{system_type} eq 'fixed') {
# $tt_txt = 'Accepted and tests show All Clear for the Fixed Systems' if $tt_txt eq 'Accepted' ;
# $got_some_fixed = 1 ;
# if ($fixed_system_overall_statuses[$event_sys_cnt] == 3) { # Not Clear
# $fixed_status_color = '5d09d3' ; # Dark Purple
# $tt_txt = 'Accepted but Not Clear on some Fixed Systems' ;
# } elsif ($fixed_system_overall_statuses[$event_sys_cnt] == 2) { # Sound Issue
# $fixed_status_color = '5d092c' ;
# $tt_txt = 'Accepted but Sound Issue found on some Fixed Systems' ;
# }
# }
# $event_sys_cnt++;
# }
# if ($got_some_fixed) { $style = "style='background-color:#$fixed_status_color;border-color:#$fixed_status_color'"; }
# } elsif ($quote_rejected) {
# $style = 'style="background-color:#ca0ad3;border-color:#ca0ad3"'; # purple
# $tt_txt = 'Rejected' ;
# } elsif ($quote_cancelled) {
# $class = 'danger' ; # red
# $tt_txt = 'Cancelled' ;
# } elsif ($quote_created) { # create by schools_manager
# $style = 'style="background-color:#f6e305;border-color:#f6e305"'; # yellow
# $tt_txt = 'Pending, created by School Manager' ;
# } elsif ($quote_pending) {
# $class = 'warning' ; # orange
# $tt_txt = 'Pending' ;
# }
# my $tt = qq~data-toggle="tooltip" data-placement="right" data-title="$tt_txt"~;
# # &common_debug("$quote_nr quote_created [$quote_created] $style") if $quote_created ;
# # $val = ($is_schools_manager) ? qq~$quote_nr~ : qq~$quote_nr~ ;
# # $val = ($glod_user_level < 4 || $quote_cancelled) ? qq~$quote_nr~ : qq~$quote_nr~ ;
# $val = ($glod_user_level < 3 || $quote_cancelled) ? qq~$quote_nr~ : qq~$quote_nr~ ;
} elsif ($col_name eq 'poc_name') {
$val = $db{event_quotes_poc}{$db{$tables}{$id}{poc_id}}{name} ;
} elsif ($col_name eq 'poc_contact_nr') {
$val = $db{event_quotes_poc}{$db{$tables}{$id}{poc_id}}{contact_nr} ;
}
# elsif ($_ eq 'user') {
# $val = '' ;
# # $val = $db{users}{$db{$tables}{$id}{user_id}}{username} if $db{$tables}{$id}{user_id} ;
# $val = $username{$db{$tables}{$id}{user_id}} ;
# }
$print_tbody .= qq~$val | ~ ;
}
my $start_date = substr($db{$tables}{$id}{date_from},0,10);
my $end_date = substr($db{$tables}{$id}{date_to},0,10);
# my @event_dates = () ;
my $year = substr($db{$tables}{$id}{date_from}, 0, 4) ;
my $month = substr($db{$tables}{$id}{date_from}, 5, 2) ;
my $day = substr($db{$tables}{$id}{date_from}, 8, 2) ;
my $year_end = substr($db{$tables}{$id}{date_to}, 0, 4 ) ;
my $month_end = substr($db{$tables}{$id}{date_to}, 5, 2 ) ;
my $day_end = substr($db{$tables}{$id}{date_to}, 8, 2 ) ;
# push @event_dates, $year . '-' . $month . '-' . $day ;
# my $Dd = Delta_Days($year,$month,$day, $year_end,$month_end,$day_end);
my $row_count = 0;
# for my $event_date (sort @event_dates) {
$xlsxcol = 0 ;
$row_count++ ;
if (($quote_created and not $quote_accepted and not $quote_completed) or ($quote_completed and not $quote_created and not $quote_accepted and not $quote_completed)) {
$xlsxrow-- ;
}
my @event_sys = split(/;/,$db{$tables}{$id}{event_system_id_multiple}) ;
my $cnt_event_sys = 0 ;
foreach (split(/;/,$db{$tables}{$id}{event_system_id_multiple})) {
$cnt_event_sys++ ;
}
$cnt_event_sys = 1 unless $cnt_event_sys ;
foreach my $col_name (@col_display_excel) {
next if ($quote_created and not $quote_accepted and not $quote_completed) or ($quote_completed and not $quote_created and not $quote_accepted and not $quote_completed) ;
$val = $db{$tables}{$id}{$col_name} ;
# $xlsxrow-- if $col_name ne 'event_start' ;
if ($col_name eq 'event_end') { $val = substr($db{$tables}{$id}{date_to},0,16) ; }
elsif ($col_name eq 'event_start') { $val = substr($db{$tables}{$id}{date_from},0,16) ; }
elsif ($col_name eq 'nr') {
$val = $id ;
if ($db{$table}{$id}{demo_id}) {
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format108) ; $xlsxrow++; } # green
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($analytics_events{$id}) {
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format107) ; $xlsxrow++; } # green
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($quote_completed) {
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format80) ; $xlsxrow++; } # green
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($quote_accepted) {
my $accp_format = $format77 ;
my @fixed_system_overall_statuses = split(/\;/,$db{$tables}{$id}{fixed_system_overall_status}) ;
my @event_system_ids = split(/\;/,$db{$tables}{$id}{event_system_id_multiple}) ;
my $event_sys_cnt = 0 ; my $event_sys_test_status = 0 ; my $got_some_fixed = 0 ; my $possible_format = $format103 ; # '164473' ; # Dark Blue $format103
foreach my $event_id (@event_system_ids) {
if ($db{event_systems}{$event_id}{system_type} eq 'fixed') {
$tt_txt = 'Accepted and tests show All Clear for the Fixed Systems' if $tt_txt eq 'Accepted' ;
$got_some_fixed = 1 ;
if ($fixed_system_overall_statuses[$event_sys_cnt] == 3) { # Not Clear
# $fixed_status_color = '5d09d3' ; # Dark Purple $format105
$possible_format = $format105 ;
$tt_txt = 'Accepted but Not Clear on some Fixed Systems' ;
} elsif ($fixed_system_overall_statuses[$event_sys_cnt] == 2) { # Sound Issue
# $fixed_status_color = '5d092c' ; # $format106
$possible_format = $format106 ;
$tt_txt = 'Accepted but Sound Issue found on some Fixed Systems' ;
}
}
$event_sys_cnt++ ;
}
if ($got_some_fixed) { $accp_format = $possible_format ; }
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$accp_format) ; $xlsxrow++; } # blue
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($quote_pending) {
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format79) ; $xlsxrow++; } # blue
$xlsxrow = $xlsxrow - $cnt_event_sys ;
# next ;
# &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format79) ; # orange
} elsif ($quote_cancelled) {
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format81) ; $xlsxrow++; } # red
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($quote_rejected ) {
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format104) ; $xlsxrow++; } # red
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($quote_created) { # create by schools_manager
# next ;
# &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format78) ; # yellow
}
$xlsxcol++ ;
next ;
} elsif ($col_name eq 'event') {
$val = $db{$tables}{$id}{ref} ;
for (1 .. $cnt_event_sys) { &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol,$val,$format82) ; $xlsxrow++; }
$xlsxrow = $xlsxrow - $cnt_event_sys ;
$xlsxcol++;
next ;
} elsif ($col_name eq 'date') {
$val = substr($event_date, 5, 2 ) ;
$val = substr($event_date, 8, 2 ) . ' ' . $month_fullname[$val - 1] . ' ' . substr($event_date, 0, 4 ) ;
} elsif ($col_name eq 'days') {
$val = $db{$tables}{$id}{qty} ;
} elsif ($col_name eq 'type_of_system') {
$val = $db{$tables}{$id}{event_type} ;
} elsif ($col_name eq 'system_details') {
# $val = '' ;
# foreach my $type_id (split(",",$db{$tables}{$id}{type_details_id})) {
# $val .= qq~$db{event_type_details}{$type_id}{name}, ~;
# }
# chop $val if $val ; chop $val if $val ;
$val = join (", ", map{ "$db{event_type_details}{$_}{name}" } split(",",$db{$tables}{$id}{type_details_id})) ;
} elsif ($col_name eq 'system_name') {
for (0 .. $cnt_event_sys-1) {
$val = qq~$db{event_systems}{$event_sys[$_]}{name}~ unless $db{event_systems}{$event_sys[$_]}{description} ;
$val = qq~$db{event_systems}{$event_sys[$_]}{name} [$db{event_systems}{$event_sys[$_]}{description}]~ if $db{event_systems}{$event_sys[$_]}{description} ;
if ($event_date ne $end_date){
&report_write_events($val, 0) ;
} else {
&report_write_events($val, 1) ;
}
$xlsxrow++;
}
$xlsxrow = $xlsxrow - $cnt_event_sys ;
} elsif ($col_name eq 'sport_type') {
my @sptyps2 = split(/\,/,$db{$tables}{$id}{sport_type_ids}) ;
$val = '' ;
foreach $_sp (@sptyps2) {
$val .= qq~$sort_type{$_sp} & ~ ;
}
chop $val if $val ; chop $val if $val ;
# } elsif ($_ eq 'cities' && $row_count == 1) {
} elsif ($col_name eq 'cities') {
$val = qq~$db{$tables}{$id}{city}~ ;
if ($db{$tables}{$id}{city_id} =~ /,/) {
$val = '' ;
foreach my $c_id (split(",",$db{$tables}{$id}{city_id})) {
$val .= qq~$db{cities}{$c_id}{city}, ~ ;
}
chop $val if $val ; chop $val if $val ;
}
} elsif ($col_name eq 'region') {
$val = qq~$db{$tables}{$id}{region}~ ;
} elsif ($col_name eq 'venue') {
$val = '' ;
foreach my $venue_id (split(",",$db{$tables}{$id}{organisation_ids})) {
$val .= qq~$organisation{$venue_id} & ~ ;
}
chop $val if $val ; chop $val if $val ; chop $val if $val ;
} elsif ($col_name eq 'club_names') {
$val = '' ;
foreach my $club_id (split(";",$db{$tables}{$id}{club_ids})) {
$val .= qq~$db{clubs}{$club_id}{name}, ~ ;
}
chop $val if $val ; chop $val if $val ;
}
elsif ($col_name eq 'operators') {
$val = '' ;
# my @op_split3 = split(/;~;/,$db{$table}{$id}{operator_ids}) ;
# foreach my $op_id (split(/\,/,$op_split3[0])) {
foreach my $op_id (split(/\,/,$db{$tables}{$id}{operator_ids})) {
$val .= qq~$name{$op_id} [$email{$op_id}], ~ ;
}
chop $val if $val ; chop $val if $val ;
}
elsif ($col_name eq 'client') {
$val = $db{$tables}{$id}{customer} ;
} elsif ($col_name eq 'poc_name') {
$val = $db{event_quotes_poc}{$db{$tables}{$id}{poc_id}}{name} ;
} elsif ($col_name eq 'poc_contact_nr') {
$val = $db{event_quotes_poc}{$db{$tables}{$id}{poc_id}}{contact_nr} ;
} elsif ($col_name eq 'category_1') {
$val = $db{event_quotes_categories}{$db{$tables}{$id}{category_id_1}}{category} ;
} elsif ($col_name eq 'category_1_details') {
$val = $cat_details[0] ;
} elsif ($col_name eq 'category_2') {
$val = $db{event_quotes_categories}{$db{$tables}{$id}{category_id_2}}{category} ;
} elsif ($col_name eq 'category_2_details') {
$val = $cat_details[1] ;
} elsif ($row_count != 1) {
# $val = '' ;
}
if ($col_name ne 'system_name') {
for (1 .. $cnt_event_sys) {
if ($event_date ne $end_date){
&report_write_events($val, 0) ;
} else {
&report_write_events($val, 1) ;
}
$xlsxrow++;
}
$xlsxrow = $xlsxrow - $cnt_event_sys ;
}
# }
# ------------------------------------------------------------------------- HTML AFTER
$xlsxcol++;
}
$xlsxrow = $cnt_event_sys + $xlsxrow ;
my $quote_nr = $quote_nr ; $quote_nr =~ s/'//iog; unless ($quote_nr) { $quote_nr = $id ; }
# if ($useropts{boss}{$username} or $useropts{super}{$username}) { }
# my $view_butt = qq~~ ;
my $edit_butt = qq~~ ;
# my $delete_butt = ($glod_user_level < 4 || $quote_accepted || $quote_completed || $quote_rejected || $quote_pending) ? '' : qq~~ ;
my $delete_butt = ($glod_user_level < 3 || $quote_accepted || $quote_completed || $quote_rejected || $quote_pending) ? ''
: ($db{$table}{$id}{demo_id}) ? qq~~
: ($analytics_events{$id}) ? qq~~
: qq~~ ;
my $copy_butt = qq~~ ;
# my $copy_butt = qq~~;
# my $pdf_butt = qq~~;
my $pdf_butt .= qq~~;
$email_butt = qq~~;
my %emailed_op_ids = () ; my $all_op_ids = 1 ; my $cnt_op_ids = 0 ;
foreach my $op_id (split(/\;/,$db{$tables}{$id}{emailed_op_ids})) {
$emailed_op_ids{$op_id} = 1 ;
}
foreach my $op_id2 (split(/\,/,$db{$tables}{$id}{operator_ids})) {
$all_op_ids = 0 if $op_id2 and not $emailed_op_ids{$op_id2} ;
$cnt_op_ids++ if $op_id2 ;
}
if ($all_op_ids and $cnt_op_ids) {
$trigger_jquery_raw .= qq~
\$("#email_$id").css({
"background-color": "lightgrey",
"border-color": "lightgrey"
});
~ ;
}
if ($glod_user_level < 3) {
$delete_butt = '' ;
if ($quote_completed || $quote_cancelled || $quote_rejected) {
$edit_butt = '' ;
}
}
# $edit_butt = '' if $usertype eq 'support' ;
# $edit_butt = '' if $quote_cancelled && !$useropts{it}{$username};
$edit_butt = qq~$edit_butt ~ if $edit_butt ;
$copy_butt = qq~$copy_butt ~ if $copy_butt ;
$delete_butt = qq~$delete_butt ~ if $delete_butt ;
$pdf_butt = qq~$pdf_butt ~ if $pdf_butt ;
$email_butt = qq~$email_butt ~ if $email_butt ;
if ($quote_created and not $quote_completed and not $quote_accepted) {
$pdf_butt = qq~~ ; $email_butt = qq~~ ;
}
# $email_butt = qq~ ~ unless $email_butt ;
# $pdf_butt = qq~ ~ unless $pdf_butt ;
$print_tbody .= qq~ $edit_butt$copy_butt$delete_butt$pdf_butt$email_butt |
~ ;
}
$worksheet{$ws}->set_column(0,0,10) ;
$worksheet{$ws}->set_column(1,1,50) ;
$worksheet{$ws}->set_column(2,3,20) ;
$worksheet{$ws}->set_column(4,4,10) ;
$worksheet{$ws}->set_column(5,10,30) ;
$worksheet{$ws}->set_column(11,11,75) ;
$worksheet{$ws}->set_column(12,21,30) ;
&report_xlsx_export_footer('L',15,'events') ;
if ($usertype eq 'support') {
$fnsortcol = 1 ; # start date
$fnsortorder = 'asc' ;
}
# &common_min_extra_crumb("search-$lcpage\s","Search Screen") if $glod_user_level > 3 ;
&common_min_extra_crumb("filter-$lcpage\s","Search Screen") if $glod_user_level > 3 ;
} #-------------------------------------------------------------------------------
sub thead {
&common_min_thead ;
} #-------------------------------------------------------------------------------
sub add_db_fields {
&hidden_fields ;
$hidden{id} = 2 ;
} #------------------------------------------------------------------------------------------
sub edit_db_fields {
&hidden_fields ;
$hidden{id} = 1 ;
# $readonly{ref} = 'READONLY' ;
} #------------------------------------------------------------------------------------------
sub view_db_fields {
&hidden_fields ;
$hidden{id} = 1 ;
$label{ref} = 1 ;
$label{qty} = 1 ;
$label{date_from} = 1 ;
$label{date_to} = 1 ;
$label{sport_type_ids} = 1 ;
$label{region_id} = 1 ;
$label{city_id} = 1 ;
$label{organisation_ids} = 1 ;
} #------------------------------------------------------------------------------------------
sub hidden_fields {
# if ($glod_user_level < 4) {
if ($glod_user_level < 3) {
$ignore{type_of_system} = 1 ;
$ignore{system_details} = 1 ;
$ignore{system_name} = 1 ;
$ignore{operators} = 1 ;
# $ignore{operator_ids} = 1 ;
}
if ($glod_user_level < 4) {
# if ($glod_user_level < 3) {
$ignore{po_nr} = 1 ;
$ignore{income} = 1 ;
$ignore{sub_total} = 1 ;
$ignore{vat_total} = 1 ;
$ignore{grand_total} = 1 ;
$ignore{custom_set} = 1 ;
}
# $ignore{custom_set} = 1 ;
$ignore{event_system_calibration_ids} = 1 ;
$ignore{event_system_calibration_status} = 1 ;
$ignore{category_1_details} = 1 ;
$ignore{category_2_details} = 1 ;
$ignore{iattachslip} = 1 ;
$ignore{iattachupload_1} = 1 ;
$ignore{iattachupload_2} = 1 ;
$ignore{iattachupload_3} = 1 ;
$ignore{iattachupload_1} = 1 ;
$ignore{iattachupload_2} = 1 ;
$ignore{iattachupload_3} = 1 ;
$ignore{sport_type_ids_readonly} = 1 ;
$ignore{region_id_readonly} = 1 ;
$ignore{city_id_readonly} = 1 ;
$ignore{organisation_ids_readonly} = 1 ;
$ignore{linear_id_readonly} = 1 ;
$ignore{custom_selected_region} = 1 ;
$ignore{custom_selected_country} = 1 ;
# $ignore{date_to} = 1 ;
# $ignore{date_from} = 1 ;
$ignore{iaction} = 1 ;
$required{qty} = 4 ; # number
$required{quote_nr} = 1 ;
$readonly{quote_nr} = 'READONLY' ;
$required{quote_to} = 1 ;
$required{currency} = 1 ;
$required{roe} = 1 ;
$required{ref} = 1 ;
$required{region_id} = 1 ;
$required{country_id} = '' ;
$required{city_id} = 1 ;
$required{poc_name} = 1 ;
$required{poc_contact_nr} = 1 ;
$required{category_id_1} = 1 ;
$required{category_1_details} = 1 ;
$required{category_id_2} = 1 ;
$required{category_2_details} = 1 ;
$hidden{quote_date} = 2 ;
$hidden{last_update} = 2 ;
$hidden{user_id} = 2 ;
$hidden{datetime} = 2 ;
$ignore{saveandexit} = 1 ;
$ignore{income} = 1 ;
$ignore{expenses} = 1 ;
$trigger_jquery_raw .= qq~var curr_changed=0;~;
$trigger_jquery_raw .= qq~var curr_changedW=0;~;
$trigger_jquery_raw .= qq~\$.validate();~;
$extra_js .= qq~~;
} #------------------------------------------------------------------------------------------
sub add_screen {
$selected{max_cams}{10} = 'SELECTED';
&select_opts('') ;
%col_name = () ;
&db_min_ro($table,'*',"id > 1 AND id < 10",'','') ;
$page_title = substr($page_title,0,-1) ;
$db{$table}{''}{quote_nr} = &db_min_get_max($table,'quote_nr') ;
$db{$table}{''}{qty} = 1 ;
# if ($username eq 'rory') { $db{$table}{''}{quote_nr} = 1000 ; }
&add_db_fields ;
&build_boxes('','save') ;
local $all_select_ids_string = join(",",@all_select_ids) ;
$trigger_jquery_raw .= qq~\$("$all_select_ids_string").chosen({ allow_single_deselect:true,search_contains: true });~ ;
} #------------------------------------------------------------------------------------------
sub view_screen {
&edit_screen ;
} #------------------------------------------------------------------------------------------
sub edit_screen {
unless ($i{id}) { $warning = qq(NO ID) ; return ; }
# my $users_cols = "id,name,user_type" ; $users_cols = "id,name,user_type,region_ids" if $glod_user_level < 4 ;
my $users_cols = "id,name,user_type" ; $users_cols = "id,name,user_type,region_ids" if $glod_user_level < 3 ;
&db_min_ro('users',$users_cols,"`user_type` LIKE 'casual%' OR `user_type` = 'schools_manager'",'','') ;
foreach (keys %{$db{users}}) {
next if $db{users}{$_}{user_type} eq 'schools_manager' ;
$casual_name{$_} = $db{users}{$_}{name} ;
$casual_type{$_} = uc substr($db{users}{$_}{user_type},-1,1) ;
$casuals{$_} = 1 if substr($db{users}{$_}{user_type},0,6) eq 'casual' ;
}
# unless ($iaction eq 'save' or $iaction eq 'update') {
&db_min_ro($table,'*',"id='$i{id}'",'','') ;
# }
# if ($glod_user_level < 4) {
# my @abcdef = split(/ /,$db{$table}{$i{id}}{date_from}) ;
# my ($year1,$month1,$day1) = split(/-/,$abcdef[0]) ;
# my ($hour1,$min1,$sec1) = split(/:/,$abcdef[1]) ;
# $trigger_jquery .= qq~
# const date1 = new Date("$year1-$month1-$day1T$hour1:$min1:$sec1");
# const date2 = new Date("$now_year-$now_mm-$now_ddT$now_hour:$now_min:$now_sec");
# let timeDiffMillis = Math.abs(date1 - date2);
# let timeDiffHours = timeDiffMillis / (1000 * 60 * 60);
# if (date1 >= date2 && timeDiffHours <= 18) {
# \$("#cancelbutt").removeClass('btn btn-danger').addClass('btn btn-void');
# }
# ~ ;
# }
my @system_name_ids = split(";",$db{$table}{$i{id}}{event_system_id_multiple}) ;
my @club_ids = split(";",$db{$table}{$i{id}}{club_ids}) ;
my @op_ids = ($db{$table}{$i{id}}{operator_ids} =~ /,/) ? split(",",$db{$table}{$i{id}}{operator_ids}) : ($db{$table}{$i{id}}{operator_ids} =~ /;/) ? split(";",$db{$table}{$i{id}}{operator_ids}) : $db{$table}{$i{id}}{operator_ids} ;
my $cnt_rows = 0 ;
for (1 .. $nr_of_system_names_and_clubs) {
$cnt_rows = $_ if $system_name_ids[$_ - 1] or $club_ids[$_ - 1] ;
}
our @table_op_ids = () ;
our @multi_select_op_ids = () ;
for (1 .. $cnt_rows) {
push @table_op_ids,$op_ids[$_ - 1] if $op_ids[$_ - 1] ;
push @table_op_ids,0 unless $op_ids[$_ - 1] ;
}
for ($cnt_rows+1 .. $nr_of_system_names_and_clubs) {
push @multi_select_op_ids,$op_ids[$_ - 1] if $op_ids[$_ - 1] ;
}
our $quote_completed = $db{$table}{$i{id}}{quote_completed} ;
our $quote_accepted = $db{$table}{$i{id}}{quote_accepted} ;
our $quote_pending = $db{$table}{$i{id}}{quote_pending} ;
our $quote_cancelled = $db{$table}{$i{id}}{quote_cancelled} ;
our $quote_rejected = $db{$table}{$i{id}}{quote_rejected} ;
# our $cancel_butt = ($d_check[2] > $now_ccyymmddhrmnsc && $iaction eq 'edit' && ($quote_completed || $quote_accepted || $quote_pending) && ($glod_user_level > 2 || $is_schools_manager)) ? 1 : 0 ;
our $cancel_butt = ($iaction eq 'edit' && ($quote_completed || $quote_accepted || $quote_pending) && ($glod_user_level > 2 || $is_schools_manager)) ? 1 : 0 ;
our $invoice_exists = 1 if $db{$table}{$i{id}}{invoice_nr} ;
# if ($is_schools_manager) {
if ($is_schools_manager || $glod_user_level < 4) {
my @ed_from = &common_split_sql_time($db{$table}{$i{id}}{date_from}) ;
my @d_check = &common_add_delta_dhms($ed_from[0],$ed_from[1],$ed_from[2],$ed_from[3],$ed_from[4],$ed_from[5],0,-18,0,0) ; # go 18 hours back from event start
if ($d_check[2] < $now_ccyymmddhrmnsc) {
$cancel_butt = 0 ;
}
}
# &common_debug("cancel_butt=$cancel_butt [$i{id}] [$db{$table}{$i{id}}{date_from}] [($d_check[2] > $now_ccyymmddhrmnsc && iaction=$iaction eq 'edit' && (quote_completed=$quote_completed || quote_accepted=$quote_accepted || quote_pending=$quote_pending) && (glod_user_level=$glod_user_level > 2 || is_schools_manager=$is_schools_manager))]");
&db_min_ro('events','id,event_quote_nr,category,user_id,startdate,enddate',"event_quote_nr='$db{$table}{$i{id}}{quote_nr}'",'','') ;
$max_cams = $db{$table}{$i{id}}{max_cams} if $db{$table}{$i{id}}{max_cams} ;
$page_title = substr($page_title,0,-1) ;
$page_title .= " : $i{id}" ;
$custom_back_button = qq~ ~ ;
# $custom_back_button = qq~$val~ ;
# our $open_new_tab = qq~target="_blank"~ ; # opens booking page in a new tab
&common_min_footer('id',"$lcpage\s");
&edit_db_fields ;
$selected{max_cams}{$db{$table}{$i{id}}{max_cams}} = 'SELECTED';
$selected{casual_worker}{$db{$table}{$i{id}}{casual_worker}} = 'SELECTED';
$selected{casual_worker_2}{$db{$table}{$i{id}}{casual_worker_2}} = 'SELECTED';
# my @assigned_users_a = split(/\:/,$db{$table}{$i{id}}{operator_names_type_a}) ;
# my @assigned_users_b = split(/\:/,$db{$table}{$i{id}}{operator_names_type_b}) ;
# for (@assigned_users_a){ $selected{operator_names_type_a}{$_} = 'SELECTED'; }
# for (@assigned_users_b){ $selected{operator_names_type_b}{$_} = 'SELECTED'; }
# $selected{operator_names_type_b}{$db{$table}{$i{id}}{operator_names_type_b}} = 'SELECTED';
&select_opts($i{id}) ;
our $saveandexit = 1 ;
&build_boxes($i{id},'update') ;
&common_min_extra_crumb("filter-$lcpage\s","Search $ucfirstpage\s") if $glod_user_level > 3 ;
local $all_select_ids_string = join(",",@all_select_ids) ;
$trigger_jquery_raw .= qq~\$("$all_select_ids_string").chosen({ allow_single_deselect:true,search_contains: true });~ ;
} #------------------------------------------------------------------------------------------
sub build_boxes {
my ($id,$action) = @_ ;
our @jquery_trigger_fields = () ;
our @jquery_custom_vat_ids = () ;
our @jquery_duty_ids = () ;
our @jquery_workings_trigger_fields = () ;
push @jquery_trigger_fields, 'inputRoe' ;
push @jquery_workings_trigger_fields, 'inputRoe' ;
for (1 .. 15) {
push @jquery_workings_trigger_fields, "checkboxVat_workings_event_$_" ;
push @jquery_workings_trigger_fields, "checkboxExcl_workings_event_$_" ;
# push @jquery_workings_trigger_fields, "checkboxVat_$_\_workings_casual_users" ;
# push @jquery_workings_trigger_fields, "checkboxExcl_$_\_workings_casual_users" ;
}
&tab_curr_symbols;
foreach $col(keys %required) {
&common_min_forms_required ;
}
our $tab_cnt = 0 ;
&tab_load_vars;
$print_box_content_rows .= &common_min_forms_start($table) ;
#--------------------------------------------------------------------------
$print_box_content_rows .= qq~
~ ;
&build_boxes_top($id);
$print_box_content_rows .= qq~
~ ;
#--------------------------------------------------------------------------
$print_box_content_rows .= qq~~ ;
&tab_cnt;
$print_box_content_rows .= qq(
);
foreach (sort {$a<=>$b} keys %cntxt) {
my $tab_name = &tab_names($_) ; my $c_actv = '' ; # if ($_==1) { $c_actv = 'class="active"' ; }
# # if ($is_schools_manager) {
# if ($glod_user_level < 4) {
# $c_actv = ($_==2) ? 'class="active"' : '' ;
# } else {
# $c_actv = (($_==1 && $db{$table}{$id}{activetab} eq '') || ($db{$table}{$id}{activetab} eq $tab_name)) ? 'class="active"' : '' ;
# }
$c_actv = ($_==2) ? 'class="active"' : '' ;
# if ($_==1 && $db{$table}{$id}{activetab} eq '') {
# $c_actv = 'class="active"' ;
# } elsif ($db{$table}{$id}{activetab} eq $tab_name) {
# $c_actv = 'class="active"' ;
# }
# &common_min_debug("activetab [$tab_name] $c_actv ");
$print_box_content_rows .= qq(- $tab_name
);
$tab_cnt++;
}
$print_box_content_rows .= qq(
);
our %tab_sections = () ;
foreach (keys %cntxt) {
my $tab_name = &tab_names($_) ; my $active = '' ;
# # if ($is_schools_manager) {
# if ($glod_user_level < 4) {
# $active = ($_==2) ? 'active' : '' ;
# } else {
# $active = (($_==1 && $db{$table}{$id}{activetab} eq '') || ($db{$table}{$id}{activetab} eq $tab_name)) ? 'active' : '' ;
# }
$active = ($_==2) ? 'active' : '' ;
# if (($_==1) and ($db{$table}{$id}{activetab} eq '')) {
# $active = 'active' ;
# }
# elsif ($db{$table}{$id}{activetab} eq $tab_name) {
# $active = 'active' ;
# }
my $colsleft = 12 ; my $showright = '' ;
if ($cntxt{$_} eq 'one' or $cntxt{$_} eq 'seven') {
$colsleft = 6 ;
$showright = 1 ;
}
$print_box_content_rows .= qq~
~;
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= qq~
~ ;
&build_boxes_left($id,$_);
$print_box_content_rows .= qq~
~ ;
if ($showright) {
$print_box_content_rows .= qq~
~ ;
&build_boxes_right($id,$_);
$print_box_content_rows .= qq~
~ ;
}
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= qq~
~ ;
if ($id) {
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= ($tab_name eq 'Quote') ? qq~
~ : qq~
~ ;
$print_box_content_rows .= &common_min_box_foot;
}
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= qq~
~ ;
}
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= qq~
~ ;
#--------------------------------------------------------------------------
$print_box_content_rows .= qq~
~ ;
&build_boxes_bottom($id);
$print_box_content_rows .= qq~
~ ;
#--------------------------------------------------------------------------
our $skip_save_btn = ($quote_completed && $glod_user_level <= 3) ? 1 : 0 ;
$print_box_content_rows .= &common_min_forms_end($id,$table,$action,$skip) ;
my $jquery_trigger_ids = '#' . join(",#",@jquery_trigger_fields) ;
my $jquery_workings_trigger_ids = '#' . join(",#",@jquery_workings_trigger_fields) ;
my $jq_tab_var = '' ;
my $jq_tab = '' ;
my $inp_tab_val = '' ;
foreach (keys %cntxt) {
$jq_tab_var .= qq(var totalTab_$_=0 ; ) ;
$jq_tab .= qq(totalTab_$_=0 ; ) ;
} # $inp_tab_val .= qq(\$("#inputTotal_tab_$_").val(totalTab_$_.toFixed(2)) ;) ;
# $trigger_jquery_raw .= qq~
# \$("#selectCurrency").change(function() {
# curr_changed=1;
# curr_changedW=1;
# console.log("1. curr_changed: "+curr_changed) ;
# calcCurr();
# });
# \$('#event_quotes-form:checkbox').change(function() {
# calcAll();
# });
# function calcCosting(excl,item,qty,usd,conv,vat,ttl)
# {
# var itval = item.val();
# var uval = usd.val();
# var cval = conv.val(); // currency amount
# var qval = qty.val();
# var vval = vat.val();
# // var tval = ttl.val();
# if (excl.val() != 0){
# var xval = 1;
# }
# else if (excl.val() == 0){
# var xval = 0;
# }
# //var xval = excl.val();
# var dis = \$("#selectDiscount").val();
# var roe = \$("#inputRoe").val(); // getNum()
# if (!itval) {
# calcAll();
# return ;
# }
# var arrP = itval.split(":"); // 3:0.00:100.00:200.00:223.00:223.00:250.00:250.00:200.00 // id:freight:nett:main_price:gross_10_1_50:gross_10_51_plus:gross_20_1_50:gross_20_51_plus:gross_50 //
# var list = { freight:arrP[1], nett:arrP[2], main_price:arrP[3], source_admin:arrP[4], perc3:arrP[5], perc5:arrP[6], perc6:arrP[6], perc8:arrP[7], perc10:arrP[8], perc15:arrP[9], perc20:arrP[10] };
# if (!qval) {
# qval=1;
# qty.val(qval);
# } // set quantity if blank
# if (!uval) // set USD amount if no amount
# {
# var uval = list.main_price;
# if (dis==3 && qval>0)
# {
# uval=list.perc3;
# }
# else if (dis==5 && qval>0)
# {
# uval=list.perc5;
# }
# else if (dis==6 && qval>0)
# {
# uval=list.perc6;
# }
# else if (dis==8 && qval>0)
# {
# uval=list.perc8;
# }
# else if (dis==10 && qval>0)
# {
# uval=list.perc10;
# }
# else if (dis==15 && qval>0)
# {
# uval=list.perc15;
# }
# else if (dis==20 && qval>0)
# {
# uval=list.perc20;
# }
# }
# var usdAmnt = uval * 1 ;
# // var currAmnt = usdAmnt / roe ;
# var currAmnt = usdAmnt * roe ;
# var ttlAmnt = currAmnt * qval ;
# usd.val(usdAmnt.toFixed(2)) ; // set USD currency amount
# conv.val(currAmnt.toFixed(2)) ; // set foreign currency amount
# ttl.val(ttlAmnt.toFixed(2)) ; // set total amount
# calcAll(); // recalculate the entire sheet
# console.log("COSTINGS CALCCOSTINGS build boxes : USD AMOUNT="+usdAmnt + "CURR AMOUNT="+currAmnt + "TOTAL AMOUNT="+ttlAmnt) ;
# // alert(usdAmnt+'(inputAmount_usd_$field):'+usd+':'+qty+'(inputQty_$field)') ; // 0.00:100.00:200.00:223.00:223.00:250.00:250.00:200.00 //
# }
# function calcCostingWorkings(excl,item,qty,usd,conv,vat)
# {
# var itvalW = item.val();
# var uvalW = usd.val();
# var cvalW = conv.val(); // currency amount
# var qvalW = qty.val();
# var vvalW = vat.val();
# var xvalW = excl.val();
# if (excl.val() != 0){
# var xvalW = 1 ;
# }
# else if (excl.val() == 0){
# var xvalW = 0 ;
# }
# // var disW = \$("#selectDiscount").val();
# var roeW = \$("#inputRoe").val(); // getNum()
# if (!itvalW) {
# calcAllWorkings();
# return ;
# }
# if (!qvalW) {
# qvalW = 1 ;
# qtyW.val(qvalW) ;
# } // set quantity if blank
# var usdAmntW = uvalW * 1 ;
# var currAmntW = usdAmntW * roeW ;
# var ttlAmntW = currAmntW * qvalW ;
# usd.val(usdAmntW.toFixed(2)) ; // set USD currency amount
# // conv.val(currAmntW.toFixed(2)) ; // set foreign currency amount
# conv.val(ttlAmntW.toFixed(2)) ; // set foreign currency amount
# // ttl.val(ttlAmntW.toFixed(2)) ; // set total amount
# calcAllWorkings(); // recalculate the entire sheet
# // console.log("WORKINGS CALCCOSTINGSWORKINGS build boxes : USD AMOUNT="+usdAmntW + "CURR AMOUNT="+currAmntW + "TOTAL AMOUNT="+ttlAmntW) ;
# console.log("calcCostingWorkings tabs: EXCL="+xvalW+", DESCRIPTION="+item+", AMOUNT USD="+uvalW+", QTY="+qvalW+", AMOUNT="+ttlAmntW+", VAT="+vvalW) ;
# }
# function calcCurr()
# {
# var roe = \$("#inputRoe") ;
# // roe.val(1); // default currency to 1
# // var curr = \$("#selectCurrency").val() ;
# // var url = "$useropts{scripts}/get/get_roe.pl?" + curr ;
# // \$.get(url, function(json) {
# // \$.each(json, function(key, data) {
# // roe.val(data.sell_rate);
# // });
# // calcAll();
# // },
# // 'json');
# }
# ~;
# $trigger_jquery_raw .= qq~
# var currArr = {}; // var vat_total = {} ; var total_total = {} ; var subtotal = {} ; var fs_total = {} ;
# var currArrW = {};
# $js_curr_arr
# var currVal = \$("#selectCurrency").val() ;
# var prevRoe = '' ;
# var curRoe = '' ;
# var currValW = \$("#selectCurrency").val() ;
# var prevRoeW = '' ;
# var curRoeW = '' ;
# var grandTtl = 0 ;
# var grandSub = 0 ;
# var grandVat = 0 ;
# var grandTtlW = 0 ;
# var grandSubW = 0 ;
# var grandVatW = 0 ;
# $jq_tab_var
# \$("$jquery_trigger_ids").change(function() {
# // calcAll();
# });
# function calcAll()
# {
# if (!\$("#selectCurrency\_chosen").val()) {
# \$("#selectCurrency\_chosen").val('ZAR');
# \$("#selectCurrency\_chosen").trigger("chosen:updated");
# }
# if (!\$("#inputRoe").val() || \$("#inputRoe").val() <= 0) { \$("#inputRoe").val(1) ; }
# grandTtl= 0 ;
# grandSub = 0 ;
# grandVat = 0 ;
# $jq_tab
# $re_calc_jquery
# \$("#inputSub_total").val(grandSub.toFixed(2)) ;
# \$("#inputVat_total").val(grandVat.toFixed(2)) ;
# \$("#inputGrand_total").val(grandTtl.toFixed(2)) ;
# \$("#inputIncome").val(grandTtl.toFixed(2)) ;
# calcProfitLoss() ;
# console.log("COSTINGS CALC_ALL: SUB TOTAL="+grandSub + "VAT TOTAL="+grandVat + "GRAND TOTAL="+grandTtl ) ;
# curr_changed=0;
# // console.log("2. curr_changed: "+curr_changed) ;
# }
# // \$("$jquery_workings_trigger_ids").change(function() {
# ///calcAllWorkings();
# // });
# function calcAllWorkings()
# {
# if (!\$("#selectCurrency\_chosen").val()) {
# \$("#selectCurrency\_chosen").val('ZAR');
# \$("#selectCurrency\_chosen").trigger("chosen:updated");
# }
# if (!\$("#inputRoe").val()) { \$("#inputRoe").val(1) ; }
# grandTtlW = 0 ;
# grandSubW = 0 ;
# grandVatW = 0 ;
# $re_calc_jqueryW
# \$("#inputTotal_amount_workings_event").val(grandSubW.toFixed(2)) ;
# \$("#inputTotal_vat_amount_workings_event").val(grandVatW.toFixed(2)) ;
# \$("#inputTotal_grand_amount_workings_event").val(grandTtlW.toFixed(2)) ;
# \$("#inputExpenses").val(grandTtlW.toFixed(2)) ; // Profit loss calculation
# calcProfitLoss() ;
# console.log("WORKINGS CALC_ALLWORKINGS: SUB TOTAL="+grandSubW + "VAT TOTAL="+grandVatW + "GRAND TOTAL="+grandTtlW ) ;
# curr_changedW=0;
# }
# function calcProfitLoss()
# {
# let inc = \$("#inputIncome").val() ;
# let exp = \$("#inputExpenses").val() ;
# let pl = inc - exp ;
# \$("#inputProfit_loss").val(pl.toFixed(2)) ;
# }
# ~ ;
# $onload .= qq(onload="calcAll();");
if ($iaction eq 'add'){ $onload .= qq~onload="calcCurr();"~ ; }
# $onload .= qq~onload="calcCurr();"~ ;
&build_workings_costings_forms_jquery if $glod_user_level > 4 ;
} #----------------------------------------------------------------------------------------
sub build_boxes_top {
my ($id) = @_ ;
&event_tabs_build_boxes_top($id) ;
$trigger_jquery .= qq~
let qu_to = \$("select[name='quote_to']").val() ;
var colonIndex = qu_to.indexOf(":") ; var extractedNumber ;
if (colonIndex !== -1) {
extractedNumber = qu_to.substring(0, colonIndex);
} else {
extractedNumber = qu_to ;
}
if (extractedNumber != 5) {
\$("#inputPoc_name").removeAttr("data-validation") ;
\$("#inputPoc_contact_nr").removeAttr("data-validation") ;
\$("#selectCategory_id_1").removeAttr("data-validation") ;
\$("#textareaCategory_1_details").removeAttr("data-validation") ;
\$("#selectCategory_id_2").removeAttr("data-validation") ;
\$("#textareaCategory_2_details").removeAttr("data-validation") ;
\$("label[for='inputPoc_name'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='inputPoc_contact_nr'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='selectCategory_id_1'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='textareaCategory_1_details'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='selectCategory_id_2'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='textareaCategory_2_details'] i.glyphicon-asterisk.yellow").remove();
}
~ ;
$trigger_jquery_raw .= qq~
\$("select[name='quote_to']").change(function() {
let qu_to = \$("select[name='quote_to']").val() ;
var colonIndex = qu_to.indexOf(":") ; var extractedNumber ;
if (colonIndex !== -1) {
extractedNumber = qu_to.substring(0, colonIndex);
} else {
extractedNumber = qu_to ;
}
if (extractedNumber != 5) {
\$("#inputPoc_name").removeAttr("data-validation") ;
\$("#inputPoc_contact_nr").removeAttr("data-validation") ;
\$("#selectCategory_id_1").removeAttr("data-validation") ;
\$("#textareaCategory_1_details").removeAttr("data-validation") ;
\$("#selectCategory_id_2").removeAttr("data-validation") ;
\$("#textareaCategory_2_details").removeAttr("data-validation") ;
\$("label[for='inputPoc_name'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='inputPoc_contact_nr'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='selectCategory_id_1'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='textareaCategory_1_details'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='selectCategory_id_2'] i.glyphicon-asterisk.yellow").remove();
\$("label[for='textareaCategory_2_details'] i.glyphicon-asterisk.yellow").remove();
} else if (extractedNumber == 5 && \$("label[for='inputPoc_name']").find("i.glyphicon.glyphicon-asterisk.yellow").length === 0) {
\$("label[for='inputPoc_name']").append('
') ;
\$("label[for='inputPoc_contact_nr']").append('
') ;
\$("label[for='selectCategory_id_1']").append('
') ;
\$("label[for='textareaCategory_1_details']").append('
') ;
\$("label[for='selectCategory_id_2']").append('
') ;
\$("label[for='textareaCategory_2_details']").append('
') ;
\$("#inputPoc_name").attr("data-validation", "required");
\$("#inputPoc_contact_nr").attr("data-validation", "required");
\$("#selectCategory_id_1").attr("data-validation", "required");
\$("#textareaCategory_1_details").attr("data-validation", "required");
\$("#selectCategory_id_2").attr("data-validation", "required");
\$("#textareaCategory_2_details").attr("data-validation", "required");
}
});
~ ;
} #----------------------------------------------------------------------------------------
sub build_boxes_left {
my ($id,$tab) = @_ ;
our ($lcol,$fcol) = &common_min_columns(3,6) ;
&event_tabs_build_qt_left($id,$tab);
} #----------------------------------------------------------------------------------------
sub build_boxes_right {
my ($id,$tab) = @_ ;
our ($lcol,$fcol) = &common_min_columns(3,6) ;
&tab_build_qt_right($id,$tab);
} #----------------------------------------------------------------------------------------
sub build_boxes_bottom {
my ($id) = @_ ;
our ($lcol,$fcol) = &common_min_columns(2,2) ;
$add_form_fields = '' ;
# --------------- START GRAND TOTAL ----------------------------------------------------------------------------------------------------------------------
$print_box_content_rows .= &common_min_form_input('activetab',$db{$table}{$id}{activetab},'hidden') ;
# --------------- END RAND TOTAL ------------------------------------------------------------------------------------------------------------------------
} #----------------------------------------------------------------------------------------
sub build_extra_name_row_1 {
my ($row_cnt,$display) = @_ ;
my $count_dates_in_first_extra_row = 0 ;
$display = ($display) ? "style='display:none;'" : "" ;
my $extra_row_hearders_1 = qq~~ ;
return $extra_row_hearders_1 ;
} #----------------------------------------------------------------------------------------
sub build_extra_name_row_2 {
my ($row_cnt,$display) = @_ ;
$display = ($display) ? "style='display:none;'" : "" ;
my $extra_row_hearders_2 = qq~~ ;
return $extra_row_hearders_2;
} #----------------------------------------------------------------------------------------
sub build_system_name_form {
my ($system_ids,$club_ids,$quote_accepted,$quote_rejected,$quote_cancelled,$daily_operator_ids,$days_active,$quote_completed) = @_ ;
my @system_name_ids = split(";",$system_ids) ;
# if ($system_ids =~ /f-/ && ($db{$table}{$i{id}}{supplier_ids} !~ /\b62\b/ || $db{$table}{$i{id}}{supplier_type_ids} !~ /\b6\b/)) {
# $system_ids = "" ;
# foreach (@system_name_ids) {
# $system_ids = "$_;" if $_ !~ /f-/ ;
# }
# $system_ids =~ s/;+$// ;
# @system_name_ids = split(";",$system_ids) ;
# }
my @club_ids = split(";",$club_ids) ;
our @days_active_arr = split(/\;/,$days_active) ;
my @daily_op_ids = () ;
# # my @arr_fixed_system_online_status = split(/\;/,$db{$table}{$i{id}}{fixed_system_online_status}) ;
# # my @arr_fixed_system_network_test = split(/\;/,$db{$table}{$i{id}}{fixed_system_network_test}) ;
# # my @arr_fixed_system_system_test = split(/\;/,$db{$table}{$i{id}}{fixed_system_system_test}) ;
# # my @arr_fixed_system_test_event = split(/\;/,$db{$table}{$i{id}}{fixed_system_test_event}) ;
# # my @arr_fixed_system_sound_test = split(/\;/,$db{$table}{$i{id}}{fixed_system_sound_test}) ;
# # my @arr_fixed_system_overall_status = split(/\;/,$db{$table}{$i{id}}{fixed_system_overall_status}) ;
# # my @arr_fixed_system_additional_comments = split(/\;/,$db{$table}{$i{id}}{fixed_system_additional_comments}) ;
# # my @arr_calibrator_amounts_paid = split(/\;/,$db{$table}{$i{id}}{calibrator_amounts_paid}) ;
# # my @arr_calibrator_dates_paid = split(/\;/,$db{$table}{$i{id}}{calibrator_dates_paid}) ;
# # my @arr_event_system_calibration_ids = split(/\;/,$db{$table}{$i{id}}{event_system_calibration_ids}) ;
# # my @arr_event_system_calibration_status = split(/\;/,$db{$table}{$i{id}}{event_system_calibration_status}) ;
# # my @arr_set_up_groups_head_operator_ids = split(/\;/,$db{$table}{$i{id}}{set_up_groups_head_operator_ids}) ;
# # my @arr_set_up_groups_status_ids = split(/\;/,$db{$table}{$i{id}}{set_up_groups_status_ids}) ;
# # for (0 .. $nr_of_system_names_and_clubs - 1) {
# # my $row_cnt = $_ + 1 ;
# # $arr_fixed_system_online_status[$_] = "" if $arr_fixed_system_online_status[$_] !~ /(\d+)/g && $arr_fixed_system_online_status[$_] !~ /none/ ;
# # $arr_fixed_system_network_test[$_] = "" if $arr_fixed_system_network_test[$_] !~ /(\d+)/g && $arr_fixed_system_network_test[$_] !~ /none/ ;
# # $arr_fixed_system_system_test[$_] = "" if $arr_fixed_system_system_test[$_] !~ /(\d+)/g && $arr_fixed_system_system_test[$_] !~ /none/ ;
# # $arr_fixed_system_test_event[$_] = "" if $arr_fixed_system_test_event[$_] !~ /(\d+)/g && $arr_fixed_system_test_event[$_] !~ /none/ ;
# # $arr_fixed_system_sound_test[$_] = "" if $arr_fixed_system_sound_test[$_] !~ /(\d+)/g && $arr_fixed_system_sound_test[$_] !~ /none/ ;
# # $arr_fixed_system_overall_status[$_] = "" if $arr_fixed_system_overall_status[$_] !~ /(\d+)/g && $arr_fixed_system_overall_status[$_] !~ /none/ ;
# # $arr_fixed_system_additional_comments[$_] = "" if $arr_fixed_system_additional_comments[$_] !~ /(\d+)/g && $arr_fixed_system_additional_comments[$_] !~ /none/ ;
# # $arr_calibrator_amounts_paid[$_] = "" if $arr_calibrator_amounts_paid[$_] !~ /(\d+)/g && $arr_calibrator_amounts_paid[$_] !~ /none/ ;
# # $arr_calibrator_dates_paid[$_] = "" if $arr_calibrator_dates_paid[$_] !~ /(\d+)/g && $arr_calibrator_dates_paid[$_] !~ /none/ ;
# # $arr_event_system_calibration_ids[$_] = "" if $arr_event_system_calibration_ids[$_] !~ /(\d+)/g && $arr_event_system_calibration_ids[$_] !~ /none/ ;
# # $arr_event_system_calibration_status[$_] = "" if $arr_event_system_calibration_status[$_] !~ /(\d+)/g && $arr_event_system_calibration_status[$_] !~ /none/ ;
# # $arr_set_up_groups_head_operator_ids[$_] = "" if $arr_set_up_groups_head_operator_ids[$_] !~ /(\d+)/g && $arr_set_up_groups_head_operator_ids[$_] !~ /none/ ;
# # $arr_set_up_groups_status_ids[$_] = "" if $arr_set_up_groups_status_ids[$_] !~ /(\d+)/g && $arr_set_up_groups_status_ids[$_] !~ /none/ ;
# # $system_used{fixed_report}{$row_cnt} = ($arr_fixed_system_online_status[$_] || $arr_fixed_system_network_test[$_] || $arr_fixed_system_system_test[$_] || $arr_fixed_system_test_event[$_] || $arr_fixed_system_sound_test[$_] || $arr_fixed_system_overall_status[$_] || $arr_fixed_system_additional_comments[$_]) ? 1 : 0 ;
# # $system_used{calibration_report}{$row_cnt} = ($arr_calibrator_amounts_paid[$_] || $arr_calibrator_dates_paid[$_] || $arr_event_system_calibration_ids[$_] || $arr_event_system_calibration_status[$_]) ? 1 : 0 ;
# # $system_used{set_up_report}{$row_cnt} = ($arr_set_up_groups_head_operator_ids[$_] || $arr_set_up_groups_status_ids[$_]) ? 1 : 0 ;
# # }
# event_system_head_operator_ids
local $system_count = 0 ; local $system_day_cnt = 0 ; my %row_has_daily_op = () ; my $some_row_has_daily_op = 0 ; our $some_row_has_daily_op_1 = 0 ; our $some_row_has_daily_op_2 = 0 ; my $active_days_count = 0 ;
foreach my $row (split(/\|/,$daily_operator_ids)) {
$system_count++ ;
next unless $row ;
$system_day_cnt = 0 ; $active_days_count = 0 ;
foreach my $default_op (split(/\;/,$row)) {
$system_day_cnt++ ;
next if !$days_active_arr[$system_day_cnt-1] ;
$active_days_count++ ;
$default_op_ids{$system_count}{$system_day_cnt} = $default_op if $default_op ;
$row_has_daily_op{$system_count} = 1 if $default_op ;
$row_has_daily_op_1{$system_count} = 1 if $default_op && $active_days_count <= 10 ;
$row_has_daily_op_2{$system_count} = 1 if $default_op && $active_days_count > 10 ;
$some_row_has_daily_op = 1 if $default_op ;
$some_row_has_daily_op_1 = 1 if $default_op && $active_days_count <= 10 ;
$some_row_has_daily_op_2 = 1 if $default_op && $active_days_count > 10 ;
}
}
$active_days_count = 0 ; my $total_days = 0 ;
foreach (@days_active_arr) {
$active_days_count++ if $_ ;
$total_days++ ;
}
$some_row_has_daily_op = 0 if $active_days_count > 6 ;
$fcol = 2 ; $lcol = 2 ;
# $dlg_add_club = ($glod_user_level < 3 && ($quote_accepted || $quote_rejected || $quote_cancelled)) ? '
' : qq~
~ ;
$dlg_add_club = ((($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3) || ($quote_completed && $glod_user_level <= 3)) ? '
' : qq~
~ ;
my $dlg_operator_ids = '' ;
# if ($glod_user_level > 2 || ($glod_user_level < 3 && ($quote_accepted || $quote_rejected || $quote_cancelled))) {
$add_form_fields .= qq~
$dlg_add_club
$dlg_operator_ids
~ ;
our %date_is_displayed_in_first_extra_row = () ;
if ($active_days_count <= 6) {
for (1 .. 20) {
$add_form_fields .= ($some_row_has_daily_op && $days_active_arr[$_ - 1]) ? qq~
~ : ($some_row_has_daily_op && !$days_active_arr[$_ - 1] && $final_day >= $_) ? qq~
~ :
qq~
~ ;
}
$add_form_fields .= qq~
~ ;
} else {
for (1 .. 20) {
$add_form_fields .= qq~
~ ;
}
$add_form_fields .= qq~
~ ;
}
my $note_display_butt = qq~~ ;
my $system_name_id = "" ; my $club_name_id = "" ;
my @plus_button_ids = () ; my @event_system_ids = () ; my @event_club_ids = () ; my @event_operator_ids = () ; my @overall_op_ids = () ;
my @table_system_name_ids = () ; my @table_club_name_ids = () ; my @table_operator_calibration_ids = () ;
my $old_op_opts = $opts{operator_ids} ;
$opts{operator_ids} =~ s/\SELECTED//g ;
for my $row_cnt (1 .. $nr_of_system_names_and_clubs) {
if ($system_name_ids[$row_cnt - 1] =~ /f-/ && ($db{$table}{$i{id}}{supplier_ids} !~ /\b62\b/ || $db{$table}{$i{id}}{supplier_type_ids} !~ /\b6\b/)) {
$system_name_ids[$row_cnt - 1] = "" ;
$system_name_ids[$row_cnt] = "" if $system_name_ids[$row_cnt] =~ /f-/ ;
$club_ids[$row_cnt - 1] = "" ;
}
my $select_sys_name = 0 ; my $select_club_name = 0 ;
$add_form_fields .= ($active_days_count > 6 && $some_row_has_daily_op_1 && $row_cnt > 1 && ($row_has_daily_op{$row_cnt} || $system_name_ids[$row_cnt - 1] || $club_ids[$row_cnt - 1] || $table_op_ids[$row_cnt - 1])) ? qq~~ : qq~~ ;
$add_form_fields .= qq~
~ if $row_cnt > 1 && !$system_name_ids[$row_cnt - 1] && !$club_ids[$row_cnt - 1] && !$row_has_daily_op{$row_cnt} && !$table_op_ids[$row_cnt - 1] ;
$add_form_fields .= qq~
~ if $row_cnt == 1 || $system_name_ids[$row_cnt - 1] || $club_ids[$row_cnt - 1] || $row_has_daily_op{$row_cnt} || $table_op_ids[$row_cnt - 1] ;
push @plus_button_ids,"#btn_system_name_$row_cnt" ;
my $input_fields_dates_1 = qq~~ ;
my $input_fields_1 = qq~~ ;
my $input_fields_dates_2 = qq~~ ;
my $input_fields_2 = qq~~ ;
# if ($glod_user_level < 3 && ($quote_accepted || $quote_rejected || $quote_cancelled)) {
# $add_form_fields .= qq~
~ if $row_cnt > 1 and not $system_name_ids[$row_cnt - 1] and not $club_ids[$row_cnt - 1] ;
# }
if ($row_cnt == 1 || $row_has_daily_op{$row_cnt} || $system_name_ids[$row_cnt - 1] || $club_ids[$row_cnt - 1] || $table_op_ids[$row_cnt - 1]) {
# if ($glod_user_level < 3 && ($quote_accepted || $quote_rejected || $quote_cancelled)) {
if ((($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3) || ($quote_completed && $glod_user_level <= 3)) {
$system_name_id = "inputSystem_name_" ; $club_name_id = "inputClub_name_" ;
$readonly{"system_name_$row_cnt"} = "READONLY" ; $readonly{"club_name_$row_cnt"} = "READONLY" ; $readonly{"operator_id_calibration_$row_cnt"} = "READONLY" ;
$add_form_fields .= qq~
~ ;
$add_form_fields .= qq~
~ ;
$fcol = 4 ;
my $system_id = $system_name_ids[$row_cnt - 1] ;
$system_id =~ s/f-//g ;
$add_form_fields .= &common_min_form_input_col("system_name_$row_cnt",$db{event_systems}{$system_id}{name}) ;
$add_form_fields .= &common_min_form_input_col("club_name_$row_cnt",$db{clubs}{$club_ids[$row_cnt - 1]}{name}) ;
$add_form_fields .= &common_min_form_input_col("operator_id_calibration_$row_cnt",$db{users}{$table_op_ids[$row_cnt - 1]}{name}) ;
$add_form_fields .= qq~
~ ;
$fcol = 1 ;
if ($row_has_daily_op{$row_cnt} && $some_row_has_daily_op) {
for (1 .. 20) {
$readonly{"custom_operator_$row_cnt\_$_"} = "READONLY" ;
$add_form_fields .= ($days_active_arr[$_ - 1]) ? &common_min_form_input_col("custom_operator_$row_cnt\_$_",$db{users}{$default_op_ids{$row_cnt}{$_}}{name}) : "" ;
}
} elsif ($row_has_daily_op{$row_cnt} && $some_row_has_daily_op_1) {
my $displayed_dates = 0 ;
# $add_form_fields .= qq~
~ ;
$input_fields_dates_1 = qq~
~ ;
$input_fields_1 = qq~
~ ;
$input_fields_dates_2 = qq~~ ;
$input_fields_2 = qq~~ ;
my %date_used = () ;
for (1 .. 20) {
if ($days_active_arr[$_ - 1] && $displayed_dates < 10) {
$input_fields_dates_1 .= qq~
~ ;
$readonly{"custom_operator_$row_cnt\_$_"} = "READONLY" ;
$input_fields_1 .= &common_min_form_input_col("custom_operator_$row_cnt\_$_",$db{users}{$default_op_ids{$row_cnt}{$_}}{name}) ;
$displayed_dates++ ;
$date_used{$_} = 1 ;
}
}
for (11 .. 20) {
if ($days_active_arr[$_ - 1] && !$date_used{$_}) {
$input_fields_2 = qq~
~ unless $input_fields_2 ;
$input_fields_dates_2 = qq~
~ unless $input_fields_dates_2 ;
$input_fields_dates_2 .= qq~
~ ;
$readonly{"custom_operator_$row_cnt\_$_"} = "READONLY" ;
$input_fields_2 .= &common_min_form_input_col("custom_operator_$row_cnt\_$_",$db{users}{$default_op_ids{$row_cnt}{$_}}{name}) ;
}
}
$input_fields_1 .= qq~
~ ;
$input_fields_dates_1 .= qq~
~ ;
$input_fields_2 .= qq~
~ if $input_fields_2 ;
$input_fields_dates_2 .= qq~
~ if $input_fields_dates_2 ;
}
$fcol = 4 ;
} else {
$system_name_id = "selectSystem_name_" ; $club_name_id = "selectClub_name_" ; $op_name_id = "selectOperator_id_calibration_" ;
push @event_system_ids,"#$system_name_id$row_cnt\_chosen" ;
push @event_club_ids,"#$club_name_id$row_cnt\_chosen" ;
push @event_operator_ids,"#$op_name_id$row_cnt\_chosen" ;
push @overall_op_ids,"#selectOperator_id_calibration_$row_cnt" ;
# $opts{fixed_event_system_id} .= qq~
~ if $db{event_systems}{$_}{system_type} eq 'fixed' ;
# $opts{mobile_event_system_id} .= qq~
~ if $db{event_systems}{$_}{system_type} eq 'mobile' ;
# $opts{mobile_or_solo_event_system_id}
# $opts{"system_name_$row_cnt"} = (($system_used{fixed_report}{$row_cnt} && $system_used{set_up_report}{$row_cnt}) || ($system_used{fixed_report}{$row_cnt} && $system_used{calibration_report}{$row_cnt})) ? $opts{event_system_id} : ($system_used{fixed_report}{$row_cnt} || $system_name_ids[$row_cnt - 1] =~ /f-/) ? $opts{fixed_event_system_id} : ($system_used{set_up_report}{$row_cnt}) ? $opts{mobile_or_solo_event_system_id} : ($system_used{calibration_report}{$row_cnt}) ? $opts{mobile_event_system_id} : $opts{event_system_id} ;
$opts{"system_name_$row_cnt"} = (($system_used{fixed_report}{$row_cnt} && $system_used{set_up_report}{$row_cnt}) || ($system_used{fixed_report}{$row_cnt} && $system_used{calibration_report}{$row_cnt})) ? $opts{event_system_id} : ($system_used{fixed_report}{$row_cnt} || $system_name_ids[$row_cnt - 1] =~ /f-/) ? $opts{fixed_event_system_id} : ($system_used{set_up_report}{$row_cnt}) ? $opts{mobile_or_solo_event_system_id} : ($system_used{calibration_report}{$row_cnt}) ? $opts{mobile_event_system_id} : $opts{event_system_id} ;
# $opts{"system_name_$row_cnt"} = $opts{event_system_id} ;
$opts{"club_name_$row_cnt"} = $opts{club_ids} ;
$opts{"operator_id_calibration_$row_cnt"} = $opts{operator_ids} ;
$allow_deselect{"system_name_$row_cnt"} = ($system_used{fixed_report}{$row_cnt} || $system_used{set_up_report}{$row_cnt} || $system_used{calibration_report}{$row_cnt}) ? 0 : 1 ;
$allow_deselect{"club_name_$row_cnt"} = 1 ; $allow_deselect{"operator_id_calibration_$row_cnt"} = 1 ;
my $sys_name_id = $system_name_ids[$row_cnt - 1] ;
$sys_name_id =~ s/f-//g ;
# my $fixed_system_indication = ($system_name_ids[$row_cnt - 1] =~ /f-/) ? qq~
~ : qq~~ ;
# my $aisa_system_indication = ($system_name_ids[$row_cnt - 1] !~ /f-/) ? qq~
~ : qq~~ ;
if ($sys_name_id) {
$trigger_jquery_raw .= qq~
\$("#selectSystem_name_$row_cnt").val('$sys_name_id').trigger("chosen:updated") ;
orig_selected_system_names["$row_cnt"] = "$sys_name_id" ;
if (default_cost_item_rates[get_event_cost_id["$sys_name_id"]]) {
system_with_cost_item_rates_selected = 1 ;
}
~ ;
} else {
push @table_system_name_ids,"#selectSystem_name_$row_cnt" ;
}
my $club_id = $club_ids[$row_cnt - 1] ;
if ($club_id) {
$trigger_jquery_raw .= qq~\$("#selectClub_name_$row_cnt").val('$club_id').trigger("chosen:updated") ; ~ ;
} else {
push @table_club_name_ids,"#selectClub_name_$row_cnt" ;
}
my $op_id = $table_op_ids[$row_cnt - 1] ;
$preferred_title{"operator_id_calibration_$row_cnt"} = "Operator $row_cnt" ;
$fcol = 4 ;
$add_form_fields .= qq~
~ ;
$add_form_fields .= qq~
~ ;
$add_form_fields .= &common_min_form_select_col("system_name_$row_cnt",$sys_name_id) if $row_cnt == 1 ;
$add_form_fields .= &common_min_form_select_col("system_name_$row_cnt",'') if $row_cnt > 1 ;
$add_form_fields .= &common_min_form_select_col("club_name_$row_cnt",$club_ids[$row_cnt - 1]) if $row_cnt == 1 ;
$add_form_fields .= &common_min_form_select_col("club_name_$row_cnt",'') if $row_cnt > 1 ;
$add_form_fields .= &common_min_form_select_col("operator_id_calibration_$row_cnt",'') ;
$add_form_fields .= qq~
~ ;
$fcol = 2 ;
my $clicked_op_butt = ($row_has_daily_op{$row_cnt}) ? qq~value="1"~ : qq~~ ;
# if ($glod_user_level > 2) {
my $clicked_any_button = ($row_cnt == 1) ? "
" : "" ;
$add_form_fields .= qq~
~ ;
push @table_plus_button_ids,"#add_daily_operators_$row_cnt" ; # my $daily_op_exists = 0 ;
# }
if (!$row_has_daily_op{$row_cnt} && $op_id) {
$trigger_jquery_raw .= qq~\$("#selectOperator_id_calibration_$row_cnt").val('$op_id') ; \$("#selectOperator_id_calibration_$row_cnt").trigger("chosen:updated") ; ~ ;
}
else {
push @table_operator_calibration_ids,"#selectOperator_id_calibration_$row_cnt" ;
}
for (1 .. 20) {
push @daily_op_ids,"#selectCustom_operator_$row_cnt\_$_" ;
}
if ($active_days_count <= 6) {
for (1 .. 20) {
# push @daily_op_ids,"#selectCustom_operator_$row_cnt\_$_" ;
my $style_disp = ($row_has_daily_op{$row_cnt} && $days_active_arr[$_ - 1]) ? "" : "style='display:none;'" ;
if (!$row_has_daily_op{$row_cnt} || ($style_disp && $row_has_daily_op{$row_cnt} && $final_day < $_)) {
$add_form_fields .= qq~
~ ;
} else {
# $style_disp = ($row_has_daily_op{$row_cnt} && $days_active_arr[$_ - 1]) ? "" : "style='display:none;'" ;
$style_disp = (!$days_active_arr[$_ - 1]) ? "style='display:none;'" : "" ;
my $class = ($style_disp) ? 0 : 1 ;
push @all_select_ids,"#selectCustom_operator_$row_cnt\_$_" ; #####CHECK!!!!!!!!!!!!!!!!!!!!!!!!!!
# push @daily_op_ids,"#selectCustom_operator_$row_cnt\_$_" ;
$add_form_fields .= qq~
~ ;
$trigger_jquery_raw .= qq~
\$("#selectCustom_operator_$row_cnt\_$_").val("$default_op_ids{$row_cnt}{$_}") ; \$("#selectCustom_operator_$row_cnt\_$_").trigger("chosen:updated") ;
if (!\$("#clicked_any_button").text()) {
\$("#clicked_any_button").text("1") ;
}
if (!\$("input[name='clicked_button_$row_cnt']").val()){
\$("input[name='clicked_button_$row_cnt']").val("1") ;
}
~ if $default_op_ids{$row_cnt}{$_} ;
}
}
my $extra_row_hearders_1 = &build_extra_name_row_1($row_cnt,1) ;
$add_form_fields .= qq~
$extra_row_hearders_1$extra_row_hearders_2$extra_row_hearders_1$extra_row_hearders_2$input_fields_dates_1$input_fields_1$input_fields_dates_2$input_fields_2~ ;
}
# $add_form_fields .= ($active_days_count > 6 && $some_row_has_daily_op_1 && ($row_cnt == 1 || $row_has_daily_op{$row_cnt} || $system_name_ids[$row_cnt - 1] || $club_ids[$row_cnt - 1] || $table_op_ids[$row_cnt - 1])) ? qq~
~ : qq~~ ;
$note_display_butt = '' ;
# if ($glod_user_level < 3 && ($quote_accepted || $quote_rejected || $quote_cancelled)) {
if ((($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3) || ($quote_completed && $glod_user_level <= 3)) {
$note_display_butt = qq~display:none;~ ;
} else {
if ($row_cnt > 1 && !$system_name_ids[$row_cnt-1] && !$club_ids[$row_cnt-1] && !$row_has_daily_op{$row_cnt} && !$table_op_ids[$row_cnt - 1]) {
$note_display_butt = qq~display:none;~ ;
}
if ($system_name_ids[$row_cnt] || $club_ids[$row_cnt] || $row_has_daily_op{$row_cnt + 1} || $table_op_ids[$row_cnt]) {
$note_display_butt = qq~display:none;~ ;
}
$add_form_fields .= qq~
~ ;
}
# $trigger_jquery_raw .= qq~
# \$("#btn_system_name_$row_cnt").click(function () {
# var v = $row_cnt + 1 ; var v2 = $row_cnt + 2 ;
# \$("#btn_row_$row_cnt").hide();
# if (v < 15 && \$('#system_name_row_'+v2).is(':hidden')) {
# \$("#btn_row_"+v).show();
# }
# \$("#system_name_row_"+v).show();
# });
# ~ ;
# $trigger_jquery .= qq~\$("#$system_name_id$row_cnt\_chosen").css("width","100%");~ ;
# $trigger_jquery .= qq~\$("#$club_name_id$row_cnt\_chosen").css("width","100%");~ ;
# $trigger_jquery .= qq~\$("#$op_name_id$row_cnt\_chosen").css("width","90%");~ ;
}
$opts{operator_ids} = $old_op_opts ;
my $table_system_name_ids_string = join(",",@table_system_name_ids) ;
my $table_club_name_ids_string = join(",",@table_club_name_ids) ;
my $table_operator_calibration_ids_string = join(",",@table_operator_calibration_ids) ;
my @all_table_ids = () ;
push @all_table_ids,$table_system_name_ids_string if $table_system_name_ids_string ;
push @all_table_ids,$table_club_name_ids_string if $table_club_name_ids_string ;
push @all_table_ids,$table_operator_calibration_ids_string if $table_operator_calibration_ids_string ;
my $all_table_ids_string = join(",",@all_table_ids) ;
$trigger_jquery_raw .= qq~
\$("$all_table_ids_string").val('') ; \$("$all_table_ids_string").trigger("chosen:updated") ;
~ if $all_table_ids_string ;
my $plus_button_ids_string = join(",",@plus_button_ids) ;
# if ($glod_user_level < 3 && ($quote_accepted || $quote_rejected || $quote_cancelled)) {
if ((($quote_accepted || $quote_rejected || $quote_cancelled) && $glod_user_level < 3) || ($quote_completed && $glod_user_level <= 3)) {
} else {
my $system_name_options = &fix_options_for_javascript($opts{"system_name_1"}) ;
my $club_name_options = &fix_options_for_javascript($opts{"club_name_1"}) ;
our $operator_options = &fix_options_for_javascript($opts{"operator_id_calibration_1"}) ;
my $event_system_ids_string = join(",",@event_system_ids) ;
my $event_club_ids_string = join(",",@event_club_ids) ;
my $event_operator_ids_string = join(",",@event_operator_ids) ;
my $daily_op_ids_string = join(",",@daily_op_ids) ;
my $overall_op_ids_string = join(",",@overall_op_ids) ;
$trigger_jquery .= qq~\$("$event_system_ids_string").css("width","100%");~ ;
$trigger_jquery .= qq~\$("$event_club_ids_string").css("width","100%");~ ;
$trigger_jquery .= qq~\$("$event_operator_ids_string").css("width","90%");~ ;
my $table_plus_button_ids_string = join (",",@table_plus_button_ids) ;
# $table_plus_button_ids_string = "#selectCustom_operator_1_1,#selectCustom_operator_1_3,#selectCustom_operator_1_2" ;
# $table_plus_button_ids_string = "#selectCustom_operator_1_1,#selectCustom_operator_1_3,#selectCustom_operator_1_2" ;
$trigger_jquery_raw .= qq~
function get_row_nr (id) {
let lastIndex = id.lastIndexOf('_');
lastIndex = parseInt(lastIndex) ;
let row_nr = id.substring(1+lastIndex);
row_nr = parseInt(row_nr) ;
return row_nr ;
}
function add_checkbox (row_nr,field_name,field_id,tindex,fcol) {
let checkbox = "
" ;
return checkbox ;
}
function add_input (row_nr,field_name,field_id,placeholder,tindex,readonly,fcol) {
let input = "
" ;
return input ;
}
function add_select (row_nr,field_name,field_id,placeholder,options,tindex,fcol,width,div_id,hide_div) {
let select = "
" ;
select = select + add_select_raw(row_nr,field_name,field_id,placeholder,options,tindex,width) ;
select = select + "
" ;
return select ;
}
function add_select_raw (row_nr,field_name,field_id,placeholder,options,tindex,width) {
let select_raw = "
" ;
return select_raw ;
}
function add_event_system_extra_row (row_cnt,nr_of_active_days) {
}
function add_event_system_row (row_cnt,nr_of_active_days) {
let new_row = "
" ;
new_row = new_row + add_select (row_cnt,"system_name_"+row_cnt,"selectSystem_name_"+row_cnt,"Select System Name "+row_cnt,"$system_name_options",-1,4,100,'','') ;
new_row = new_row + add_select (row_cnt,"club_name_"+row_cnt,"selectClub_name_"+row_cnt,"Select Club Name "+row_cnt,"$club_name_options",-1,4,100,'','') ;
new_row = new_row + add_select (row_cnt,"operator_id_calibration_"+row_cnt,"selectOperator_id_calibration_"+row_cnt,"Select Operator "+row_cnt,"$operator_options",-1,4,90,'','') ;
// let glod_user_level = parseInt("$glod_user_level") ;
// if (glod_user_level < 3) { return new_row ; }
new_row = new_row +"
" ;
let extra_row_1,extra_row_2,extra_name_row_1,extra_name_row_2 ;
// if (nr_of_active_days <= 6) {
for (let col=1; col<=20; col++) {
// if (\$("#day_"+col).val()) {
// new_row = new_row + add_select (row_cnt,"custom_operator_"+row_cnt+"_"+col,"selectCustom_operator_"+row_cnt+"_"+col,"Select an Option","$operator_options",-1,1,100,"id='day_"+row_cnt+"_"+col+"'","style='display:none;'") ;
// } else {
new_row = new_row + "
" ;
// }
}
new_row = new_row+"
" ;
extra_row_1 = "