aisa/scripts/warranty_report.pl

293 lines
11 KiB
Perl
Raw Normal View History

2025-11-26 09:31:54 +00:00
#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
require cfg ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
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;
&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 $debug = 1 ;
#-------- page opts --------------------------------------------------------------------------------------------------------------------------------------------------
&page_opts ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
print "Content-type: text/html\n\n";
our $srchscr = 1 ;
&db_open_ro ;
our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it
if ($iaction eq ''){ &report_screen ; }
&common_min_action;
$db_ignore_open_close = 0 ; # do one open and one close instead of repeating it
&db_close_conn ;
exit;
#------------------------------------------------------------------------------------------
sub report_ifields {
&load_search_vars ;
# if ($i{camera_id}) {
# push @report_sql, "(`id`='$i{camera_id}')" ;
# push @report_results, "camera = $camera_name{$i{camera_id}}" ;
# $xlsreportname .= '-' . $i{camera_id} ;
# # our $acc_id_sql_where = "`camera_id`='$i{camera_id}'"
# }
# if ($i{camera_system_id}) {
# push @report_sql, "(`camera_system_id`='$i{camera_system_id}')" ;
# push @report_results, "camera_system = $camera_system{$i{camera_id}}" ;
# $xlsreportname .= '-' . $i{camera_system_id} ;
# }
if ($i{camera_system_id} and $i{camera_system_id} ne 'main' and $i{camera_system_id} ne 'other' and $i{camera_system_id} ne 'all') {
push @report_sql, "(`camera_system_id`='$i{camera_system_id}')" ;
push @report_results, "camera_system = $camera_system{$i{camera_system_id}}" ;
$xlsreportname .= '-' . $i{camera_id} ;
# our $acc_id_sql_where = "`camera_id`='$i{camera_id}'"
} elsif ($i{camera_system_id} eq 'main' or $i{camera_system_id} eq 'other' or $i{camera_system_id} eq 'all') {
push @report_results, "camera_system = $i{camera_system_id}" ;
}
if ($i{date_from} and $i{date_to}) { # check dates
my $date_from_check = $i{date_from} ;
$date_from_check =~ s/\-//g ;
my $date_to_check = $i{date_to} ;
$date_to_check =~ s/\-//g ;
if ($date_from_check > $date_to_check) { $error = qq(CAMERAS FROM ($i{date_from}) > CAMERAS TO ($i{date_to})); &report_screen; }
}
if ($i{date_from}) {
# push @report_sql, "(`date_active` >= '$i{date_from}')" ;
# push @report_results, "date_active >= $i{date_from}" ;
push @report_sql, "(`date_time` >= '$i{date_from}')" ;
push @report_results, "date_time >= $i{date_from}" ;
}
if ($i{date_to}) {
# push @report_sql, "(`date_active` <= '$i{date_to}')" ;
# push @report_results, "date_active <= $i{date_to}" ;
push @report_sql, "(`date_time` <= '$i{date_to}')" ;
push @report_results, "date_time <= $i{date_to}" ;
}
if ($i{client_id}) {
# push @report_sql, "(`client_id` = '$i{client_id}')" ;
push @report_results, "Client = $client{$i{client_id}}" ;
}
$report_results_msg = uc join(', ', @report_results) ;
unless ($report_results_msg) { $error = qq(ENTER AT LEAST ONE SEARCH PARAMETER); &report_screen; } else { $isaved = qq(SELECT WHERE $report_results_msg) ; }
} #------------------------------------------------------------------------------------------
sub load_search_vars {
# my $cameras_sql_where = "`id`='$i{camera_id}'" ;
# &db_min_ro('cameras','id,camera_nr',$cameras_sql_where,'','') ;
# foreach my $id (keys %{$db{cameras}}) { $camera_name{$id} = $db{cameras}{$id}{camera_nr} ; }
my $camera_systems_sql_where = "`id`='$i{camera_system_id}'" if $i{camera_system_id} ;
&db_min_ro('camera_systems','id,name',$camera_systems_sql_where,'','') ;
foreach my $id (keys %{$db{camera_systems}}) { $camera_system{$id} = $db{camera_systems}{$id}{name} ; }
# my $price_list_sql_where = " AND `id`='$i{camera_system_id}'" if $i{camera_system_id} ;
# &db_min_ro('price_list','id,description',"`excl`<>'1' AND `type`='systems'$price_list_sql_where",'','') ;
# foreach my $id (keys %{$db{price_list}}) { $camera_system{$id} = $db{price_list}{$id}{name} ; }
# my $customers_sql_where = "`id`='$i{client_id}'" if $i{client_id} ;
# &db_min_ro('customers','*',$customers_sql_where,'','') ;
# foreach my $id (keys %{$db{customers}}) { $client{$id} = $db{customers}{$id}{name} ; }
if ($i{client_id}) {
my $customers_sql_where = "`id`='$i{client_id}'" ;
&db_min_ro('customers','*',$customers_sql_where,'','') ;
foreach my $id (keys %{$db{customers}}) { $client{$id} = $db{customers}{$id}{name} ; }
}
} #------------------------------------------------------------------------------------------
sub list_screen {
my $srch_where_sql = join(' AND ', @report_sql) ;
my $add_sql_where = '' ;
# our @sql_col_display = ("id","camera_nr","camera_serial_nr","date_received","client_id","ref_nr","ref","date_delivered","extended_warranty") ;
our @sql_col_display = ("camera_nr","camera_system_id","camera_serial_nr","vpu_serial_nr","date_received","client_id","ref_nr","ref","date_delivered","extended_warranty") ;
&report_xls_export_header("Extended_Warranty_Report$xlsreportname",'warrantyreport') ;
&load_list_vars("$srch_where_sql$add_sql_where") ;
foreach my $id (sort {$b <=> $a} keys %{$db{$table}}) {
next unless $db{$table}{$id}{quote_ew_date_from} or $db{$table}{$id}{quote_ew_date_to} ;
next if (&common_camera_system_filter($table,$id)) ;
if ($i{client_id}) {
next unless $client{$i{client_id}} eq $quote_customer{$id} ;
}
$print_tbody .= qq~<tr>~ ;
$xlscol=0;
foreach (@sql_col_display) {
unless ($_) { next ; } # blank for the buttons column
my $val = $db{$table}{$id}{$_} ;
my $align = '' ;
my $center = qq~ class="dt-center"~ ;
if ($_ eq 'date_received') { $align = $center ; }
if ($_ eq 'date_delivered') { $val = $db{$table}{$id}{quote_delivery_date} ; $align = $center ; }
if ($_ eq 'client_id') { $val = $quote_customer{$id} ; }
if ($_ eq 'ref_nr') { $val = $db{$table}{$id}{quote_nr} ; $align = $center ; }
# if ($_ eq 'ref') { $val = $db{$table}{$id}{quote_ref} ? "<b><i>$db{$table}{$id}{quote_ref}</i></b>" : $quote_ref{$id} ; }
if ($_ eq 'ref') { $val = $db{$table}{$id}{quote_ref} ? $db{$table}{$id}{quote_ref} : $quote_ref{$id} ; }
if ($_ eq 'camera_system_id') { $val = $camera_system{$val} ; }
if ($_ eq 'camera_serial_nr') { $val = $db{$table}{$id}{serial_nr} ; }
if ($_ eq 'extended_warranty') {
$val = $db{$table}{$id}{quote_ew_date_from} if $db{$table}{$id}{quote_ew_date_from} ;
$val .= "/$db{$table}{$id}{quote_ew_date_to}" if $db{$table}{$id}{quote_ew_date_to} ;
$align = $center ;
}
# if ($_ eq 'vpu_serial_nr') { $val = &common_check_for_linked_vpu($db{$table}{$id}{camera_nr},$quote_nr{$id},$id,'SN') ; }
if ($_ eq 'vpu_serial_nr') { $val = $linked_sn{$db{$table}{$id}{serial_nr}} ; }
&report_xls_export_process_cell('','',$val) ; # ------------------------------------------------------------------------- HTML AFTER
$xlscol++;
$val = &common_camera_links($table,$id,$val) if $_ eq 'camera_nr' or $_ eq 'ref_nr' ;
$print_tbody .= qq~<td $align>$val</td>~ ;
}
$print_tbody .= qq~</tr>~ ;
$xlsrow++ ;
}
&report_xls_export_footer('L',15,'warrantyreport') ;
$fnsortcol = 3 ;
$fnsortorder = 'asc' ;
$print_more_boxes .= qq~<br><button type="button" class="btn btn-default" onclick="history.go(-1);">Back</button><br><br>~ ;
&common_min_extra_crumb("$lcpage-report","Search Screen") ;
} #------------------------------------------------------------------------------------------
sub set_tick {
my ($color,$tooltip) = @_ ;
$tick{green} = qq~<span style="display:none;">2</span><span class="label label-success"><i $tooltip class="glyphicon glyphicon-ok"></i></span>~ ;
$tick{orange} = qq~<span style="display:none;">1</span><span class="label label-warning"><i $tooltip class="glyphicon glyphicon-ok"></i></span>~ ;
$tick{red} = qq~<span style="display:none;">0</span><span class="label label-danger"><i $tooltip class="glyphicon glyphicon-ok"></i></span>~ ;
return ($tick{$color}) ;
} #------------------------------------------------------------------------------------------
sub load_list_vars {
my ($where) = @_ ;
&db_min_ro('camera_systems','id,name','','','') ;
foreach my $id (keys %{$db{camera_systems}}) { $camera_system{$id} = $db{camera_systems}{$id}{name} ; }
&db_min_ro('customers','id,name','','','') ;
foreach my $id (keys %{$db{customers}}) { $customer{$id} = $db{customers}{$id}{name} ; }
# &common_load_quote_vars('>0');
&common_load_quote_vars("cameras.quote_nr>0 AND cameras.quote_nr=quotes.quote_nr");
&db_min_ro($table,'*',$where,'','') ;
# foreach my $id (keys %{$db{$table}}) {
# $cam_nr{$id} = $db{$table}{$id}{camera_nr} ;
# $serial_nr{$id} = $db{$table}{$id}{serial_nr} ;
# }
} #------------------------------------------------------------------------------------------
sub thead {
&common_min_thead ;
} #-------------------------------------------------------------------------------
sub page_opts {
our $glyphicon = 'list' ;
our $lcpage = 'extended' ;
&common_page_name ;
our $table = 'cameras' ;
$page_title = 'Extended Warranty' ;
} #-------------------------------------------------------------------------------
sub report_screen {
our $lcol = 3 ;
our $fcol = 5 ;
$print_box_content_rows .= &common_min_forms_start('report') ;
&common_camera_opts ;
&common_min_select_opts('camera_system_id','camera_systems','code',$i{camera_system_id},'') ;
&common_min_select_opts('client_id','customers','name',$i{client_id},'') ;
my @datefrom = &common_add_delta_ymd(-2,0,0) ;
$print_box_content_rows .= &common_min_form_datepicker('date_from',"$datefrom[0]-01-01") ;
$print_box_content_rows .= &common_min_form_datepicker('date_to',"$now_year-$now_mm-$now_dd") ;
$print_box_content_rows .= &common_min_form_select('camera_system_id','') ;
$print_box_content_rows .= &common_min_form_select('client_id','') ;
$print_box_content_rows .= &common_min_forms_end('','','report') ;
&common_min_search_screen ;
} #-------------------------------------------------------------------------------
use common ;
use report ;
use xlsxcreator ;
use today ;
1;