#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } require cfg ; print "Content-type: text/html\n\n"; # unless ($useropts{it}{$username}) { print "<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>" ; exit ; } #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- use CGI::Carp qw(fatalsToBrowser); use CGI; use Mail::Sendmail; use Fcntl qw(:flock); use File::Copy; use File::Basename; use Date::Calc qw(:all); use Excel::Writer::XLSX; use Time::Piece; use Time::Seconds; # my $start_time_str = "09:30:00" ; # my $end_time_str = "17:45:00" ; # Create Time::Piece objects for start and end times # my $start_time = Time::Piece->strptime($start_time_str, "%H:%M:%S"); # my $end_time = Time::Piece->strptime($end_time_str, "%H:%M:%S"); # Calculate the difference in seconds and convert to hours # my $time_diff_in_hours = (Time::Piece->strptime($end_time_str,"%H:%M:%S") - Time::Piece->strptime($start_time_str,"%H:%M:%S")) / ONE_HOUR; &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 $open_new_tab = qq~target="_blank"~ ; # our $debug = 1 ; our $testing = 1 ; #-------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- &page_opts ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- our $srchscr = 1 ; &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &report_screen if $iaction eq '' ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; if ($iaction eq 'report') { &common_min_load_params ; &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &report_ifields ; &list_screen ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; &screen3 ; } if ($iaction eq 'save') { &common_min_load_params ; &db_open_upd ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &update ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; exit if $username eq 'rory' && $testing ; &screen4 ; } # &common_min_action; exit; #------------------------------------------------------------------------------------------ sub update { &db_min_ro('logistics_costs','event_nr,file_name_ids,cost_type',"",'','') ; my %ii = %i ; my %cost_types = () ; foreach (keys %ii) { if ($_ =~ /costtype_/) { my ($NA,$event_id,$file_id,$amnt_cnt) = split(/\_/,$_) ; $cost_types{$event_id}{$file_id}{$amnt_cnt} = 1 ; next if $event_and_file_has_diff_cost_types{$event_id}{$file_id} ; if ($prev_cost_type{$event_id}{$file_id} && $prev_cost_type{$event_id}{$file_id} ne $ii{$_}) { $event_and_file_has_diff_cost_types{$event_id}{$file_id} = 1 ; } $prev_cost_type{$event_id}{$file_id} = $ii{$_} ; } } my %seen_event = () ; foreach (keys %ii) { if ($_ =~ /costtype_/) { my ($NA,$event_id,$file_id1,$amnt_cnt1) = split(/\_/,$_) ; next if $seen_event{$event_id} ; $seen_event{$event_id} = 1 ; %i = () ; my $saved_event_id = ($event_id =~ /\d+/) ? $event_id : -1 ; my @saved_files = split(/\:/,$db{logistics_costs}{$saved_event_id}{file_name_ids}) ; my $used_file = 0 ; foreach my $file_id (@saved_files) { my $used_amnt = 0 ; $used_file = 1 ; if ($event_and_file_has_diff_cost_types{$event_id}{$file_id}) { foreach my $amnt_cnt (sort {$a <=> $b} %{$cost_types{$event_id}{$file_id}}) { my $field_name = "costtype_$event_id\_$file_id\_$amnt_cnt" ; $i{cost_type} .= qq~$ii{$field_name};;~ ; $used_amnt = 1 ; } $i{cost_type} = substr($i{cost_type},0,-2) if $used_amnt ; $i{cost_type} .= qq~::~ ; } else { $i{cost_type} .= qq~$ii{$_}::~ ; } } $i{cost_type} = substr($i{cost_type},0,-2) if $used_file ; $ignore{cost_type} = 1 if $i{cost_type} eq $db{logistics_costs}{$event_id}{cost_type} ; &db_min_upd("logistics_costs","event_nr='$event_id'") ; } } %i = %ii ; # exit ; } #------------------------------------------------------------------------------------------ sub report_ifields { if ($i{event_id} && $i{event_id} ne 'all' && $i{event_id} ne 'na_event' && $i{event_id} ne 'N/A') { push @report_sql_2, "(id = '$i{event_id}')" ; &db_min_ro('event_quotes','1,ref',"`id`='$i{event_id}'",'','') ; } if ($db{event_quotes}{1}{ref}) { push @report_results, "(EVENT QUOTE = '$db{event_quotes}{1}{ref}')" ; push @report_sql, "(event_nr = '$i{event_id}')" ; } elsif ($i{event_id} eq 'N/A') { push @report_results, "EVENT NAME UNKNOWN" ; push @report_sql, "(event_nr = '-1')" ; push @report_sql_2, "(id = '-1')" ; } elsif ($i{event_id} && $i{event_id} eq 'all') { push @report_results, "ALL EVENTS" ; } else { push @report_sql, "(event_nr = '$i{event_id}')" ; push @report_results, "(EVENT NR = '$i{event_id}')" ; } if ($i{cost_type}) { push @report_results, "(COST TYPE LIKE '$i{cost_type}')" ; push @report_sql, "(cost_type LIKE '%$i{cost_type}%')" ; } $report_results_msg = uc join(', ',@report_results) ; if (not $report_results_msg) { # $error = qq(ENTER AT LEAST ONE SEARCH PARAMETER); # &report_screen ; } else { $isaved = qq(SELECT WHERE $report_results_msg) ; } } #------------------------------------------------------------------------------------------ sub list_screen { $print_box_content_rows .= &common_min_forms_start('logistics-costs') ; my $srch_where_sql = join(' AND ', @report_sql) ; my $srch_where_sql_2 = join(' AND ', @report_sql_2) ; &load_list_vars("$srch_where_sql","$srch_where_sql_2") ; our @sql_col_display = ("event_nr","cost_type","amounts","uploaded_from") ; foreach my $event_id (sort {$a <=> $b} keys %{$db{$table}}) { # my $event_id = $db{$table}{$id}{event_nr} ; # $db{$table}{na}{file_name_ids} = $db{$table}{$event_id}{file_name_ids} if $event_id < 0 ; next if $event_id eq 'breakdown' ; if ($db{$table}{$event_id}{file_name_ids}) { my @all_amounts_per_file_uploaded = split(/\:/,$db{$table}{$event_id}{amounts}) ; my @files_uploaded = split(/\:/,$db{$table}{$event_id}{file_name_ids}) ; my @all_cost_type = split(/\::/,$db{$table}{$event_id}{cost_type}) ; my $file_cnt = 0 ; $event_id = "na" if $event_id < 0 ; foreach my $file_id (@files_uploaded) { my @amounts_per_file_uploaded = split(/\;/,$all_amounts_per_file_uploaded[$file_cnt]) ; if ($all_amounts_per_file_uploaded[$file_cnt] =~ /;/ && $all_cost_type[$file_cnt] && $all_cost_type[$file_cnt] !~ /;/) { my $abc = $all_cost_type[$file_cnt] ; foreach (@amounts_per_file_uploaded) { $all_cost_type[$file_cnt] .= qq~;;$abc~ ; } } my @files_cost_type = split(/\;;/,$all_cost_type[$file_cnt]) ; my $amnt_cnt = 0 ; foreach my $sep_amnt (@amounts_per_file_uploaded) { $amnt_cnt++ ; $print_tbody .= qq~