sub schedule_load_list_vars {
my ($where) = @_ ;
&db_min_ro('regions','*','','','') ;
&db_min_ro('users','id,name,user_type,username,region_ids',"`name` NOT LIKE 'Rory%' AND `name` NOT LIKE 'Handre%'",'','') ;
$opts{schedule_users} .= qq~~ ;
# $opts{head_operator} .= qq~~ ;
foreach my $_uid (sort {$db{users}{$a}{name} cmp $db{users}{$b}{name}} keys %{$db{users}}) {
next if $useropts{it}{$db{users}{$_uid}{username}} ;
my $regions = qq~~ ;
foreach (split(/\,/,$db{users}{$_uid}{region_ids})) {
$regions .= qq~$db{regions}{$_}{code},~ ;
}
chop $regions if $regions ;
$regions = qq~[$regions]~ if $regions ;
# if ($db{users}{$_uid}{user_type} eq 'support' || $db{users}{$_uid}{user_type} eq 'manager' || $db{users}{$_uid}{user_type} eq 'casual_calibrator' || $monitoring_report) {
if ($db{users}{$_uid}{user_type} eq 'casual_calibrator' || (($monitoring_report || $troubleshoot_monitoring_report) && $db{users}{$_uid}{user_type} ne 'casual_c' && $db{users}{$_uid}{user_type} ne 'schools_manager' && $db{users}{$_uid}{user_type} ne 'support' && $db{users}{$_uid}{user_type} ne 'permanent')) {
$opts{schedule_users} .= qq~~ ;
}
if (($db{users}{$_uid}{user_type} eq 'support' || $db{users}{$_uid}{user_type} eq 'casual_calibrator') && $temp_calibrator_report) {
$opts{support_users} .= qq~~ ;
$tot_support_users_cnt++;
}
if ($db{users}{$_uid}{user_type} eq 'casual_c') {
$opts{fixture_check} .= qq~~ ;
}
}
my $event_systems_sql_where = ($monitoring_report || $troubleshoot_monitoring_report) ? "" : "system_type = 'mobile'" ;
&db_min_ro('event_systems','*',$event_systems_sql_where,'','') ;
&db_min_ro($table,"id,club_ids,qty,ref,organisation_ids,quote_accepted,event_system_id_multiple,region_id,sport_type_ids,operator_ids,date_from,date_to,times_from,times_to,daily_operator_ids,days_active,monitor_ids,temp_calibrator_ids$extra_column","$where AND `quote_accepted` = '1'",'','') ;
my $min_id = 0 ; my $max_id = 0 ;
foreach my $id (keys %{$db{$table}}) {
next unless $id ; my $cnt = 0 ;
my @ed_from = &common_split_sql_time($db{$table}{$id}{date_from}) ;
my @ed_to = &common_split_sql_time($db{$table}{$id}{date_to}) ;
&common_date_array("$ed_from[0]$ed_from[1]$ed_from[2]","$ed_to[0]$ed_to[1]$ed_to[2]") ;
$sort_calibration_by_time_ref{"$ed_from[0]$ed_from[1]$ed_from[2]$ed_from[3]$ed_from[4]-$id"} = $id ;
}
&db_min_ro('sport_types','*','','','') ;
&db_min_ro('organisations','id,name','','','') ;
&db_min_ro('clubs','id,name','','','') if $monitoring_report || $troubleshoot_monitoring_report ;
our $table_ = "shift_operator_ids" ;
my $col_ = ($monitoring_report) ? "monitor_ids" : ($troubleshoot_monitoring_report) ? "troubleshoot_monitor_ids" : "temp_calibrator_ids,temp_calibrator_support_shifts" ;
my $col2_ = ($monitoring_report) ? ",monitor_notes" : ($troubleshoot_monitoring_report) ? ",troubleshoot_monitor_notes" : "" ;
&db_min_ro($table_,"date$col2_,$col_","`date` >= '$i{date_from}' AND `date` <= '$i{date_to}'") ;
} #------------------------------------------------------------------------------------------
sub schedule_build_extra_table {
my ($field_name,$table_name,$table_col_name,$table_col_name_notes,$table_id) = @_ ;
my $ws2 = join ' ', map { ucfirst $_ } split /_/, $field_name ;
$ws2 .= "s" ;
&xlsxcreator_add_worksheet($ws2) ;
my $col2 = 0 ;
foreach (@sql_col_display_extra) {
next if $_ eq "update" || !$_ || $_ eq 'notes' ;
my $coltitle = $_ ;
$coltitle =~ s/\_id//g ;
$coltitle =~ s/\_/ /g ;
my $ucfirst = join '', map { ucfirst lc } split /(\s+)/, $coltitle;
&xlsxcreator_write_xlsx($ws2,0,$col2,$ucfirst,$format_management_report_headings) ;
$col2++;
}
$col2=0 ;
&xlsxcreator_freeze_panes($ws2,1,0) ; # Freeze the first 3 rows
my $uc_field_name = ucfirst $field_name ;
# $db{$table_name}{$i{date}}{$table_col_name} = qq~147;132|||~ ;
# for (0 .. 3) { $schedule_ids[$_] = "null" unless $schedule_ids[$_] ; }
$format84 -> set_left('1') ;
my ($s_year,$s_mon,$s_day) = split("-",$i{date_from}) ;
my ($e_year,$e_mon,$e_day) = split("-",$i{date_to}) ;
$s_mon = sprintf("%02d",$s_mon) ;
$s_day = sprintf("%02d",$s_day) ;
our $date_cnt = 1 ; my $row_cnt = 0 ;
return if int("$s_year$s_mon$s_day") > int("$e_year$e_mon$e_day") ;
our @months = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ;
my %row_cnt_shifts = () ; my $max_row_cnt = 0 ;
while (int("$s_year$s_mon$s_day") <= int("$e_year$e_mon$e_day")) {
$db{$table_name}{"$s_year-$s_mon-$s_day"}{$table_col_name} =~ s/\;/\,/g ;
my @schedule_ids = split(/\|/,$db{$table_name}{"$s_year-$s_mon-$s_day"}{$table_col_name}) ;
my $date = "$s_year-$s_mon-$s_day" ;
my $date_str = &common_min_date_as_string($date) ;
our $default_javascript = "" ; my %default_javascript_short = () ;
my $val_notes = qq~~ ;
foreach my $col (@sql_col_display_extra) {
my $formatting = $format92 ;
next if substr($col,0,5) eq 'shift' && substr($col,0,7) ne 'shift_1' ;
my $val = '' ; my $nowrap = '' ; my $align = qq~~ ; my $val_min = "" ;
my $row_span = '' ;
if ($col eq 'date') {
$row_cnt++ ;
$row_span = qq~rowspan="2"~ if $monitoring_report || $troubleshoot_monitoring_report ;
$val = $date_str . qq~~ ;
$nowrap = "nowrap" ;
&xlsxcreator_write_xlsx($ws2,$max_row_cnt+1,0,$date_str ,$formatting) ;
} elsif (substr($col,0,7) eq 'shift_1') {
$align = qq~ class="dt-center"~ ;
local $place_holder = substr($ws2,0,-1) ;
for (1 .. 4) {
$row_cnt_shifts{$_} = $max_row_cnt + 1 ;
}
for my $shift_cnt (1 .. 4) {
# $row_cnt_shifts{$shift_cnt} = ($max_row_cnt && $shift_cnt == 1) ? $max_row_cnt + 1 : 1 ;
my $field = "$field_name\_$shift_cnt\_1_1_$date_cnt" ;
$opts{$field} = $opts{schedule_users} ;
$preferred_placeholder{$field} = ($troubleshoot_monitoring_report) ? "Shift Troubleshoot Monitor $shift_cnt $date_cnt" : "$place_holder $shift_cnt $date_cnt" ;
$multiple{$field} = 1 ;
my $table_col = 6-$shift_cnt ;
push @first_table_multi_select_table_cells,"#$table_id tr:eq($row_cnt) td:nth-last-child($table_col)" ;
$val .= &common_min_table_select($field,$schedule_ids[$shift_cnt - 1],'',$row_cnt,$table_col,'',$schedule_ids[$shift_cnt - 1],'shift',$table_id) ;
foreach (split(/\,/,$schedule_ids[$shift_cnt - 1])) {
next unless $_ ;
$trigger_jquery_raw .= qq~\$("#select$uc_field_name\_$shift_cnt\_1_1_$date_cnt option[value='$_']").prop("selected",true);~ ;
&xlsxcreator_write_xlsx($ws2,$row_cnt_shifts{$shift_cnt},$shift_cnt,"$db{users}{$_}{name}",$formatting) ;
$row_cnt_shifts{$shift_cnt}++ ;
}
$max_row_cnt = $row_cnt_shifts{$shift_cnt} if !$max_row_cnt || $max_row_cnt < $row_cnt_shifts{$shift_cnt} ;
$val .= qq~
~ if $shift_cnt < 4 ;
}
} elsif ($col eq 'notes') {
$row_cnt++ ;
my @notes = split(/\:\|\:/,$db{$table_name}{$date}{$table_col_name_notes}) ;
# $max_row_cnt-- ;
# $max_row_cnt++ if $db{$table_name}{$date}{$table_col_name_notes} =~ /(\d+)/g || $db{$table_name}{$date}{$table_col_name_notes} =~ /[a-zA-Z]/ ;
for my $shift_cnt (1 .. 4) {
my $field = "$field_name\_notes_$shift_cnt\_1_1_$date_cnt" ;
$preferred_placeholder{$field} = ($troubleshoot_monitoring_report) ? "Shift Troubleshoot Monitor Notes $shift_cnt $date_cnt" : "Shift Monitor Notes $shift_cnt $date_cnt" ;
$val_notes .= &common_min_table_textarea($field,$notes[$shift_cnt-1],'',$row_cnt,5-$shift_cnt,'',$notes[$shift_cnt-1],'',$table_id) ;
&xlsxcreator_write_xlsx($ws2,$max_row_cnt,$shift_cnt,$notes[$shift_cnt-1],$format97) if $db{$table_name}{$date}{$table_col_name_notes} =~ /(\d+)/g || $db{$table_name}{$date}{$table_col_name_notes} =~ /[a-zA-Z]/ ;
$val_notes .= qq~ | ~ if $shift_cnt < 4 ;
}
$val_notes = qq~ | | $val_notes |
~ ;
} elsif ($col eq "update") {
$row_span = qq~rowspan="2"~ if $monitoring_report || $troubleshoot_monitoring_report ;
$align = qq~ class="dt-center"~ ;
my $field = "update_1_1_$date_cnt" ;
$val = &common_min_form_checkbox_col($field,'') ;
chop $default_javascript if $default_javascript ;
if ($default_javascript) {
push @default_javascript_by_id, qq~"1_1_$date_cnt":{$default_javascript}~ ; ## ???
for (1 .. 4) {
my $field = "#textarea" . ucfirst "$field_name\_notes\_$_\_1_1_$date_cnt" ;
push @all_update_field_ids,"$field" if $monitoring_report || $troubleshoot_monitoring_report ;
$field = "#select" . ucfirst "$field_name\_$_\_1_1_$date_cnt" ;
push @all_update_field_ids,"$field" ;
}
}
}
$print_tbody_extra .= qq~$val | ~ if $col ne 'notes' ;
$print_tbody_extra .= qq~$val_notes~ if $col eq 'update' ;
}
($s_year,$s_mon,$s_day) = Add_Delta_Days($s_year,$s_mon,$s_day,1) ;
$s_mon = sprintf("%02d",$s_mon) ;
$s_day = sprintf("%02d",$s_day) ;
$date_cnt++ ;
}
$date_cnt-- ;
# &common_min_table_select_fixed_width_jquery(1) ;
# &common_min_table_select_default_values_jquery ;
# @all_select_ids = () ; @selects_with_default_ids = () ; %col_name_select_ids = () ; %table_with_default_ids = () ; %selects_by_def_val = () ;
@sql_col_display_extra = ("date","shift_1_(08:00-11:00)","shift_2_(11:00-14:00)","shift_3_(14:00-17:00)","shift_4_(17:00-21:00)","update") if $monitoring_report || $troubleshoot_monitoring_report ;
$worksheet{$ws2}->set_column(0,0,10) ;
$worksheet{$ws2}->set_column(1,5,50) if $monitoring_report || $troubleshoot_monitoring_report ;
$worksheet{$ws2}->set_column(1,5,20) if $temp_calibrator_report ;
$trigger_jquery_raw .= qq~\$("#$table_id tr:eq(0) th:nth-last-child(2),#$table_id tr th:nth-last-child(3),#$table_id tr th:nth-last-child(4),#$table_id tr th:nth-last-child(5)").css("width","23%")~ ;
} #------------------------------------------------------------------------------------------
sub schedule_build_extra_second_table {
my ($field_name,$table_name,$table_col_name) = @_ ;
my $ws2 = join ' ', map { ucfirst $_ } split /_/, $field_name ;
$ws2 .= "s" ;
&xlsxcreator_add_worksheet($ws2) ;
my $col2 = 0 ;
foreach (@sql_col_display_2) {
next if $_ eq "update" || !$_ ;
my $coltitle = $_ ;
$coltitle =~ s/\_id//g ;
$coltitle =~ s/\_/ /g ;
my $ucfirst = join '', map { ucfirst lc } split /(\s+)/, $coltitle;
&xlsxcreator_write_xlsx($ws2,0,$col2,$ucfirst,$format_management_report_headings) ;
$col2++;
}
$col2=0 ;
&xlsxcreator_freeze_panes($ws2,1,0) ; # Freeze the first 3 rows
my ($s_year,$s_mon,$s_day) = split("-",$i{date_from}) ;
my ($e_year,$e_mon,$e_day) = split("-",$i{date_to}) ;
$s_mon = sprintf("%02d",$s_mon) ;
$s_day = sprintf("%02d",$s_day) ;
$opts{name} = $opts{support_users} ;
$radio_opts{shift} = "Half Day (<7 hours);Full Day (7 hours+)" ;
my $nr_of_options = scalar split("option>
~ ;
$xlsxrow++ ;
$row_cnt++ ;
$quote_and_ops_ids .= qq~"$row_cnt\_$temp_id":"$date_val",~ ;
}
# chop $op_ids if $op_ids ;
# $quote_and_ops_ids .= qq~"$row_cnt_$id":[$op_ids],~ if $op_ids ;
}
my $col_cnt = 0 ;
foreach my $col (@sql_col_display) {
if ($col eq 'date') {
&xlsxcreator_write_xlsx($ws,$xlsxrow,$col_cnt,"TOTALS",$format_management_report_total) ;
} elsif ($col eq "amounts_paid" || $col eq "amount_payable") {
&xlsxcreator_write_xlsx($ws,$xlsxrow,$col_cnt,"$amnt_tots{$col}",$format_management_report_totals) ;
} else {
&xlsxcreator_write_xlsx($ws,$xlsxrow,$col_cnt,"-",$format_management_report_totals) ;
}
$col_cnt++ ;
}
chop $quote_and_ops_ids if $quote_and_ops_ids ;
# $print_tbody .= qq~~ ;
# $print_tbody .= qq~
~ ;
$worksheet{$ws} -> set_column(0,0,15) ;
$worksheet{$ws} -> set_column(1,1,25) ;
$worksheet{$ws} -> set_column(2,7,20) if $i{paid_status} eq 'all' ;
$worksheet{$ws} -> set_column(2,5,20) if $i{paid_status} ne 'all' ;
$box_icon .= qq~~ if $i{paid_status} ne 'paid' && $count_outstanding > 0 ;
&report_xlsx_export_footer('L',15,"$field\_payments_report") ;
$fnsortcol = 0;
$fnsortorder = 'asc' ;
&common_min_extra_crumb("$lcpage\s","Search Screen") ;
$trigger_jquery_raw .= qq~
function selectAll() {
let jsObject = {
$quote_and_ops_ids
} ;
for (let key in jsObject) {
let op_id = jsObject[key] ;
let parts = key.split("_") ;
let event_id = parts[1] ;
\$(\$("#itv-table").dataTable().fnGetNodes()).find(\$("input[name=paid_"+event_id+"_"+op_id+"]")).each(function () {
// console.log("input[name=paid_"+event_id+"_"+op_id+"]") ;
if(\$(this).is(':checked')) {
\$(this).prop('checked',false) ;
} else {
\$(this).prop('checked',true) ;
}
}) ;
}
}
~;
my $field_id = "#$field2\-payment-form" ;
# my $savebuttjs = ($count_outstanding > 0) ? qq~$("$field_id").submit();' : 'noty({text:"There are no calibrators to pay!",layout:"center",type:"error",timeout:3000});return;~ ;
$trigger_jquery_raw .= qq~
\$("#savebutt").click(function() {
// $savebuttjs
\$("$field_id").submit();
}) ;
~ ;
$fcol = 2 ;
$print_box_content_rows .= qq~~ ;
$print_box_content_rows .= &common_min_form_input_col("date_from",$i{date_from}) ; #date_from_i_field
$print_box_content_rows .= &common_min_form_input_col("date_to",$i{date_to}) ; #date_to_i_field
$print_box_content_rows .= &common_min_form_input_col("$field\_id",$i{"$field\_id"}) ; #temp_calibrator_id_i_field
$print_box_content_rows .= &common_min_form_input_col("$field\s_paid",$i{"$field\s_paid"}) ;
$print_box_content_rows .= qq~
~ ;
$print_box_content_rows .= &common_min_forms_start("$field2\-payment") if $count_outstanding ;
} #------------------------------------------------------------------------------------------
sub schedule_payments_load_list_vars {
my ($where,$field) = @_ ;
my $users_sql = ($field =~ /calibrator/) ? "`user_type` = 'casual_calibrator' OR `user_type` = 'support'" : "" ;
&db_min_ro('users','id,name',"$users_sql",'','') ;
&db_min_ro($table,"date,$field\_ids,$field\_dates_paid,$field\_amounts_paid,temp_calibrator_support_shifts","`date`>='$i{date_from}' AND `date`<='$i{date_to}' $where",'','') ;
# &db_min_ro('shift_monitor_ids','date,monitor_ids',"`date`>='$i{date_from}' AND `date`<='$i{date_to}' $where",'','') ;
our %operator_count = () ; our %amounts_paid = () ; our %dates_amounts_paid = () ; our %operator_shifts_string = () ;
# my @monitor_shifts = ("","08:00-11:00","11:00-14:00","14:00-17:00","17:00-21:00") ;
my @operator_shifts = ($field =~ /calibrator/) ? ("","07:00-10:00","10:00-13:00","13:00-16:00","16:00-19:00") : ("","08:00-11:00","11:00-14:00","14:00-17:00","17:00-21:00") ;
foreach my $date (keys %{$db{$table}}) {
my $shift_cnt = 0 ;
foreach my $shift (split(/\|/,$db{$table}{$date}{"$field\_ids"})) {
$shift_cnt++ ;
next unless $shift ;
foreach my $temp_id (split(/\;/,$shift)) {
next unless $temp_id ;
$operator_count{$date}{$temp_id} += 1 ;
$operator_shifts_string{$date}{$temp_id} .= qq~$operator_shifts[$shift_cnt];~ ;
}
}
$shift_cnt = 0 ;
# foreach my $shift (split(/\|/,$db{$table}{$date}{monitor_ids})) {
# $shift_cnt++ ;
# next unless $shift ;
# foreach my $temp_id (split(/\;/,$shift)) {
# next unless $temp_id ;
# $operator_count{$date}{$temp_id} += 1 ;
# $operator_shifts{$date}{$temp_id} .= qq~$monitor_shifts[$shift_cnt],~ ;
# }
# }
my @date_pay = split(/\;/,$db{$table}{$date}{"$field\_dates_paid"}) ;
my @amount_pay = split(/\;/,$db{$table}{$date}{"$field\_amounts_paid"}) ;
my $cnt = 0 ;
foreach my $temp_id_amnt (@amount_pay) {
my @temp_amnt = split(/\:/,$temp_id_amnt) ;
$amounts_paid{$date}{$temp_amnt[0]} += $temp_amnt[1] ;
$dates_amounts_paid{$temp_amnt[0]}{$date_pay[$cnt]} += $temp_amnt[1] ;
$cnt++ ;
}
if ($temp_calibrator_payments_report && $db{$table}{$date}{temp_calibrator_support_shifts}) {
foreach my $shift (split(/\|/,$db{$table}{$date}{temp_calibrator_support_shifts})) {
$shift_cnt++ ;
next unless $shift ;
my @abc = split(/\:/,$shift) ;
next unless $abc[0] ;
$operator_count{$date}{$abc[0]} += 0 ;
# $operator_count{$date}{$abc[0]} += ($abc[1] eq '1') ? 0.5 : 1 ;
$temp_calibrator_support{count}{$date}{$abc[0]}{$abc[1]} += ($abc[1] eq '1') ? 0.5 : 1 ;
$temp_calibrator_support{shift_count}{$date}{$abc[0]}{$abc[1]} += 1 ;
$operator_shifts_string{$date}{$abc[0]} .= ($abc[1] eq '1') ? qq~Half Day (<7 hours);~ : qq~Full Day (7 hours+);~ ;
$support_user{$abc[0]} = 1 ;
}
}
}
} #------------------------------------------------------------------------------------------
sub schedule_payments_report_screen {
my ($field) = @_ ;
our $lcol = 3 ;
our $fcol = 5 ;
$print_box_content_rows .= &common_min_forms_start('report') ;
&common_min_select_opts("$field\_id",'users',"name",$i{"$field\_id"},'','',"`name` NOT LIKE 'Rory%' AND `name` NOT LIKE 'Handre%'") ;
# &common_min_select_opts('event_quote_id','event_quotes',"ref",$i{event_quote_id},'','',"") ;
$first_day_month = sprintf("%02d",$first_day_month) ; $first_day = sprintf("%02d",$first_day) ;
$print_box_content_rows .= &common_min_form_datepicker('date_from',"$now_year-$now_mm-01") unless $i{date_from} ;
my $days_in_month = Days_in_Month($now_year,$now_mm) ;
$print_box_content_rows .= &common_min_form_datepicker('date_to',"$now_year-$now_mm-$days_in_month") ;
# my ($sql_next_day) = &common_add_delta_days(1) ;
# my ($next_year,$next_month,$next_day) = split(/\-/,$sql_next_day) ;
# $print_box_content_rows .= &common_min_form_datepicker('date',"$next_year-$next_month-$next_day") ; #unless $i{date_from} ;
$opts{paid_status} .= qq~All~ ;
$opts{paid_status} .= qq~Paid~ ;
$opts{paid_status} .= qq~Outstanding~ ;
$print_box_content_rows .= &common_min_form_select("$field\_id",'') ;
# $print_box_content_rows .= &common_min_form_select('event_quote_id','') ;
$print_box_content_rows .= &common_min_form_select('paid_status','') ;
$print_box_content_rows .= &common_min_forms_end('','','report') ;
&common_min_search_screen ;
} #------------------------------------------------------------------------------------------
1 ;