sub logistics_load_db_vars {
&db_min_ro('organisations','*',"",'','') ;
&db_min_ro('logistics_locations','*',"",'','') ;
&db_min_ro('logistics_suppliers','*',"active = '1'",'','') ;
&db_min_ro('logistics_items','*',"",'','') ;
&db_min_ro('event_systems','id,logistics_location_id',"(`system_type` = 'mobile' OR `system_type` = 'solo' OR `description` lIKE 'cricket%')",'','') ;
foreach (keys %i) {
local @abc = split("_",$_) ;
if (substr($_,0,7) eq 'update_') {
$seen_event_id{$abc[-1]} = 1 ;
}
}
# create_waybill_out_5136
local @event_ids = () ;
foreach (keys %seen_event_id) {
push @event_ids , "`id` = '$_'" ;
}
local $e_q_sql = join (" OR ",@event_ids) ;
&db_min_ro($table,'id,event_system_id_multiple,logistics_suppliers,logistics_waybill_nrs,logistics_status_ids,logistics_venue_id,logistics_item_ids,poc_id,recipient_id,logistics_special_instructions,logistics_complete,logistics_dcb_waybill,date_from,date_to,logistics_delivery_datetime,logistics_received_by,logistics_location_other,logistics_system_location_id,logistics_last_changed_by,logistics_dcb_comments,logistics_shipment_operator_id',"$e_q_sql",'','') ;
} #------------------------------------------------------------------------------------------
sub logistics_dates {
my ($from_to,$id) = @_ ;
$nowrap = 'nowrap' ;
my ($year1,$month1,$day1) = split(/\-/,substr($db{$table}{$id}{date_from},0,10)) ;
my ($year2,$month2,$day2) = split(/\-/,substr($db{$table}{$id}{date_to},0,10)) ;
$val = qq~~ ;
if ($year1 ne $year2 && $month1 ne $month2 && $day1 ne $day2) {
$val = qq~ $day1 $month_names[$month1] $year1 -
$day2 $month_names[$month2] $year2~ ;
} elsif ($year1 eq $year2 && $month1 ne $month2) {
$val = qq~ $day1 $month_names[$month1] -
$day2 $month_names[$month2] $year2~ ;
} elsif ($year1 eq $year2 && $month1 eq $month2 && $day1 ne $day2) {
$val = qq~ $day1 - $day2 $month_names[$month2] $year2~ ;
} elsif ($year1 eq $year2 && $month1 eq $month2 && $day1 eq $day2) {
$val = qq~ $day2 $month_names[$month2] $year2~ ;
}
my $stime = substr($db{$table}{$id}{date_from},11,5) ;
my $etime = substr($db{$table}{$id}{date_to},11,5) ;
$valxlsx = $val ;
$valxlsx =~ s/
//g ;
# $val = qq~$val~ ;
# &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol+1,$stime,$formatting) ;
# &xlsxcreator_write_xlsx($ws,$xlsxrow,$xlsxcol+2,$etime,$formatting) ;
} #------------------------------------------------------------------------------------------
sub logistics_venue {
my ($from_to,$id) = @_ ;
$val = '' ; $nowrap = 'nowrap' ;
foreach my $_oid (@venue_ids) {
$val .= qq~$db{organisations}{$_oid}{name}~ ;
$val .= qq~ [$db{organisations}{$_oid}{region_code}]~ if $db{organisations}{$_oid}{region_code} ;
$val .= ',' ;
}
$val = substr($val,0,-1) if $val ;
$valxlsx = $val ;
$valxlsx =~ s/\,/\;/g ;
if (length($val) > 30) {
$val =~ s/\,/\
/g ;
$val = substr($val,0,27) . qq~~ ;
} else {
$val =~ s/\,/\
/g ;
}
} #------------------------------------------------------------------------------------------
sub logistics_system {
my ($from_to,$id) = @_ ;
$val = '' ; my $tooltip = '' ;
foreach my $event_sys_id (@system_name_ids) {
next unless $event_sys_id ;
next unless $db{event_systems}{$event_sys_id}{system_type} ;
$system_count++ ;
$tooltip .= qq~
$db{event_systems}{$event_sys_id}{name}~ ;
$tooltip .= qq~ [$db{event_systems}{$event_sys_id}{description}]~ if $db{event_systems}{$event_sys_id}{description} ;
}
$tooltip = substr($tooltip,4) if $tooltip ;
$val = $tooltip ;
# $val = ($system_count > 1) ? qq~~ : ($system_count == 1) ? qq~~ : "" ;
$valxlsx = $tooltip ;
$valxlsx =~ s/\
/\;/g ;
} #------------------------------------------------------------------------------------------
sub logistics_from_to {
my ($from_to,$id) = @_ ;
$val = '' ; $valxlsx = 'MUSTBEBLANK' ;
if (($from_to eq 'to' && $current_date <= $start_date) || ($from_to eq 'from' && $current_date <= $end_date)) {
$found_editable = 1 ;
$trigger_jquery_raw .= qq~\$("#$ucfirstfield{1},#$ucfirstfield{2}").chosen({allow_single_deselect:true}) ; ~ ;
my $col_venue = ($from_to eq 'to') ? 10 : 11 ;
my $col_log_loc = ($from_to eq 'to') ? 11 : 10 ;
if (($_ eq 'to' && $from_to eq 'to') || ($_ eq 'from' && $iaction eq 'report_from')) { # && $iaction eq 'report') || ($_ eq 'from' && $_ eq 'report_from')
$val = qq~
~ ;
$trigger_jquery_raw .= qq~
\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child($col_venue)").css("z-index","$cali_cnt") ;
~ ;
if ($db{$table}{$id}{logistics_venue_id}) {
$valxlsx = "$db{organisations}{$db{$table}{$id}{logistics_venue_id}}{name} [$db{organisations}{$db{$table}{$id}{logistics_venue_id}}{region_code}]" if $db{organisations}{$db{$table}{$id}{logistics_venue_id}}{region_code} ;
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{1}").val("$db{$table}{$id}{logistics_venue_id}") ;
~ ;
push @selects_with_default_ids,"#$ucfirstfield{1}" if $ucfirstfield{1} ;
push @table_with_default_ids,"#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child($col_venue)" ;
$default_javascript .= qq~"$field{1}":"$db{$table}{$id}{logistics_venue_id}",~ ;
} elsif ($venue_ids[0]) {
$valxlsx = "$db{organisations}{$venue_ids[0]}{name} [$db{organisations}{$venue_ids[0]}{region_code}]" if $db{organisations}{$venue_ids[0]}{region_code} ;
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{1}").val("$venue_ids[0]") ;
~ ;
push @selects_with_default_ids,"#$ucfirstfield{1}" if $ucfirstfield{1} ;
$default_javascript .= qq~"$field{1}":"$venue_ids[0]",~ ;
} else {
$default_javascript .= qq~"$field{1}":"",~ ;
}
} else {
$val = qq~
~ ;
my $found_loc = 0 ;
$trigger_jquery_raw .= qq~
\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child($col_log_loc)").css("z-index","$cali_cnt") ;
~ ;
foreach my $event_sys_id (@system_name_ids) {
next unless $event_sys_id ;
next unless $db{event_systems}{$event_sys_id}{system_type} ;
if ($db{event_systems}{$event_sys_id}{logistics_location_id}) {
$valxlsx = $db{logistics_locations}{$db{event_systems}{$event_sys_id}{logistics_location_id}}{location} ;
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{2}").val("$db{event_systems}{$event_sys_id}{logistics_location_id}") ;
~ ;
$found_loc = 1 ;
push @selects_with_default_ids,"#$ucfirstfield{2}" if $ucfirstfield{2} ;
push @table_with_default_ids,"#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child($col_log_loc)" ;
$default_javascript .= qq~"$field{2}":"$db{event_systems}{$event_sys_id}{logistics_location_id}",~ ;
}
last ;
}
if (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Johannesburg/) {
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{2}").val("1") ;
~ ;
$default_javascript .= qq~"$field{2}":"1",~ ;
push @selects_with_default_ids,"#$ucfirstfield{2}" if $ucfirstfield{2} ;
} elsif (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Cape Town/) {
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{2}").val("2") ;
~ ;
$default_javascript .= qq~"$field{2}":"2",~ ;
push @selects_with_default_ids,"#$ucfirstfield{2}" if $ucfirstfield{2} ;
} elsif (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Durban/) {
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{2}").val("3") ;
~ ;
push @selects_with_default_ids,"#$ucfirstfield{2}" if $ucfirstfield{2} ;
$default_javascript .= qq~"$field{2}":"3",~ ;
} elsif (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Bloemfontein/) {
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{2}").val("4") ;
~ ;
push @selects_with_default_ids,"#$ucfirstfield{2}" if $ucfirstfield{2} ;
$default_javascript .= qq~"$field{2}":"4",~ ;
} elsif (!$found_loc) {
$default_javascript .= qq~"$field{2}":"",~ ;
}
}
push @dropdown_chosen_ids,"#$ucfirstfield{1}\_chosen,#$ucfirstfield{2}\_chosen" if $ucfirstfield{1} && $ucfirstfield{2} ;
} else {
if (($_ eq 'to' && $from_to eq 'to') || ($_ eq 'from' && $iaction eq 'report_from')) {
if ($db{$table}{$id}{logistics_venue_id}) {
$val = qq~$db{organisations}{$db{$table}{$id}{logistics_venue_id}}{name}~ ;
$val .= qq~ [$db{organisations}{$db{$table}{$id}{logistics_venue_id}}{region_code}]~ if $db{organisations}{$db{$table}{$id}{logistics_venue_id}}{region_code} ;
} elsif ($venue_ids[0]) {
$val = qq~$db{organisations}{$venue_ids[0]}{name}~ ;
$val .= qq~ [$db{organisations}{$venue_ids[0]}{region_code}]~ if $db{organisations}{$venue_ids[0]}{region_code} ;
}
} else {
my $found_loc = 0 ;
foreach my $event_sys_id (@system_name_ids) {
next unless $event_sys_id ;
next unless $db{event_systems}{$event_sys_id}{system_type} ;
if ($db{event_systems}{$event_sys_id}{logistics_location_id}) {
$val = $db{logistics_locations}{$db{event_systems}{$event_sys_id}{logistics_location_id}}{location} ;
$found_loc = 1 ;
last ;
}
}
if (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Johannesburg/) {
$val = $db{logistics_locations}{1}{location} ;
} elsif (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Cape Town/) {
$val = $db{logistics_locations}{2}{location} ;
} elsif (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Durban/) {
$val = $db{logistics_locations}{3}{location} ;
} elsif (!$found_loc && $db{cities}{$db{$table}{$id}{city_id}}{name} =~ /Bloemfontein/) {
$val = $db{logistics_locations}{4}{location} ;
}
}
$valxlsx = $val ;
}
} #------------------------------------------------------------------------------------------
sub logistics_supplier {
my ($from_to,$id) = @_ ;
$val = '' ; $valxlsx = 'MUSTBEBLANK' ;
if (($from_to eq 'to' && $current_date <= $start_date) || ($from_to eq 'from' && $current_date <= $end_date)) {
$found_editable = 1 ;
$preferred_title{$field{supplier}} = "Supplier" ;
$opts{$field{supplier}} = $opts{logistics_supplier} ;
$trigger_jquery_raw .= qq~\$("#$ucfirstfield{supplier}").chosen({ allow_single_deselect:true });~ ;
$val = qq~~ ;
$trigger_jquery_raw .= qq~
\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(9)").css("z-index","$cali_cnt") ;
~ ;
if ($logistics_supplier_ids_hash{$id}{$from_to}) {
$valxlsx = $db{logistics_suppliers}{$logistics_supplier_ids_hash{$id}{$from_to}}{supplier} ;
push @selects_with_default_ids,"#$ucfirstfield{supplier}" if $ucfirstfield{supplier} ;
push @table_with_default_ids,"#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(9)" ;
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{supplier}").val("$logistics_supplier_ids_hash{$id}{$from_to}") ;
// \$("#$ucfirstfield{supplier}").trigger("chosen:updated") ;
// \$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(9)").css("background-color","#424949") ;
~ ;
}
push @dropdown_chosen_ids,"#$ucfirstfield{supplier}\_chosen" if $ucfirstfield{supplier} ;
} elsif ($logistics_supplier_ids_hash{$id}{$from_to}) {
$val = $db{logistics_suppliers}{$logistics_supplier_ids_hash{$id}{$from_to}}{supplier} ;
$valxlsx = $val ;
}
} #------------------------------------------------------------------------------------------
sub logistics_status {
my ($from_to,$id) = @_ ;
local %status_hash = (1 =>"Booked",2 => "Pending",3=>"In Transit",4 =>"Delivered") ;
$val = '' ; $valxlsx = 'MUSTBEBLANK' ;
# if (($from_to eq 'to' && $current_date <= $end_date) || ($from_to eq 'from' && $current_date <= $start_date)) {
if (($from_to eq 'to' && $current_date <= $start_date) || ($from_to eq 'from' && $current_date <= $end_date)) {
$found_editable = 1 ;
$preferred_title{$field{status}} = "Status" ;
$opts{$field{status}} = $opts{status} ;
$trigger_jquery_raw .= qq~\$("#$ucfirstfield{status}").chosen({ allow_single_deselect:true });~ ;
$val = qq~~ ;
$trigger_jquery_raw .= qq~
\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(8)").css("z-index","$cali_cnt") ;
~ ;
$val = &common_min_form_select_col($field{status},'') ; ########### >= OR >
if ($logistics_status_ids_hash{$id}{$from_to}) {
$valxlsx = $status_hash{$logistics_status_ids_hash{$id}{$from_to}} ;
$trigger_jquery_raw .= qq~
\$("#$ucfirstfield{status}").val("$logistics_status_ids_hash{$id}{$from_to}") ;
// \$("#$ucfirstfield{status}").trigger("chosen:updated") ;
~ ;
$default_javascript .= qq~"$field{status}":"$logistics_status_ids_hash{$id}{$from_to}",~ ;
push @selects_with_default_ids,"#$ucfirstfield{status}" if $ucfirstfield{status} ;
if ($logistics_status_ids_hash{$id}{$from_to} eq '1') { #Booked
$trigger_jquery_raw .= qq~\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(8)").css("background-color","rgb(81,203,242)") ; ~ ;
} elsif ($logistics_status_ids_hash{$id}{$from_to} eq '2') { #Pending
$trigger_jquery_raw .= qq~\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(8)").css("background-color","rgb(66,73,73)") ; ~ ;
} elsif ($logistics_status_ids_hash{$id}{$from_to} eq '3') { #In Transit
$trigger_jquery_raw .= qq~\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(8)").css("background-color","rgb(255,165,0) ") ; ~ ;
} elsif ($logistics_status_ids_hash{$id}{$from_to} eq '4') { #Delivered
$trigger_jquery_raw .= qq~\$("#$useropts{table_id} tr:eq($cali_cnt) td:nth-last-child(8)").css("background-color","rgb(46,204,113)") ; ~ ;
}
} else {
$default_javascript .= qq~"$field{status}":"2",~ ;
}
push @dropdown_chosen_ids,"#$ucfirstfield{status}\_chosen" if $ucfirstfield{status} ;
} elsif ($logistics_status_ids_hash{$id}{$from_to}) {
$val = $logistics_status_ids_hash{$logistics_status_ids_hash{$id}{$from_to}} ;
$valxlsx = $status_hash{$logistics_status_ids_hash{$id}{$from_to}} ;
}
} #------------------------------------------------------------------------------------------
sub logistics_waybill_nr {
my ($from_to,$id) = @_ ;
my $fname = 'waybill_nr' ; $val = '' ; $valxlsx = 'MUSTBEBLANK' ;
my $wb_code = 'AIS' . uc substr($from_to,0,1) . '_' ;
if (($from_to eq 'to' && $current_date <= $start_date) || ($from_to eq 'from' && $current_date <= $end_date)) {
$found_editable = 1 ;
my $print_field = &common_min_print_field($field{$fname}) ; $tindex++ ;
my $wb_nr = ($logistics_waybill_ids_hash{$id}{$from_to}) ? $logistics_waybill_ids_hash{$id}{$from_to} : $wb_code . $id ;
$default_javascript .= qq~"$field{$fname}":"$wb_nr",~ ;
$val = qq~