#!/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 ; # our $testing = 1 ; #-------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- &page_opts ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- print "Content-type: text/html\n\n"; our $srchscr = 0 ; our $fnsortcol = 0 ; our $redirtype = 'summary' ; # our $redirtype = 'list' ; # $redirtype = 'search' ; &common_min_action; exit; #------------------------------------------------------------------------------------------ sub validate { # called from common_min_action # my $exists = '' ; # &db_min_ro($table,'*',"name='$i{name}'",'','') ; # foreach my $id (keys %{$db{$table}}) { # if ($db{$table}{$id}{name} eq $i{name}) { # $exists = 1 ; # } # } # if ($exists) { # $alert = &common_min_alert('warning',"NAME ALREADY EXISTS!",'ok') ; # %col_name = (); # # &add_screen; # # &screen1; # &common_min_add_screen; # &common_min_screen1; # } } #------------------------------------------------------------------------------------------ sub insert { &add_db_fields ; $i{last_edited_by} = $userid ; $i{added_by} = $userid ; $i{id} = &db_min_get_max($table,'id') ; $i{type_cnt} = &db_min_get_max($table,'type_cnt',"`type`='$i{type}'") ; if ($i{type} =~ /\_/g) { my @t = split(/\_/,$i{type}); $code_start = substr($t[0],0,2) . substr($t[1],0,1) ; } else { $code_start = substr($i{type},0,3) ;} $i{item_code} = uc $code_start . sprintf("%03s", $i{type_cnt}) ; &val_check ; $i{date_added} = "$now_ccyy_mm_dd" ; $i{last_updated} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; &db_min_insert($table) ; } #------------------------------------------------------------------------------------------ sub update { unless ($i{id}) { $error = qq(NO ID) ; return ; } &edit_db_fields ; if ($userid) { $i{last_edited_by} = $userid ; } &val_check ; $i{last_updated} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; &db_min_upd($table,"id='$i{id}'") ; } #------------------------------------------------------------------------------------------ sub val_check { unless ($i{excl}) { $i{excl} = '0' ; } unless ($i{excl_from_summary}) { $i{excl_from_summary} = '0' ; } $i{nett} = sprintf("%.2f",$i{nett}) ; $i{freight} = sprintf("%.2f",$i{freight}) ; $i{main_price} = sprintf("%.2f",$i{main_price}) ; # $i{gross_10_1_50} = sprintf("%.2f",$i{gross_10_1_50}) ; # $i{gross_10_51_plus} = sprintf("%.2f",$i{gross_10_51_plus}) ; # $i{gross_20_1_50} = sprintf("%.2f",$i{gross_20_1_50}) ; # $i{gross_20_51_plus} = sprintf("%.2f",$i{gross_20_51_plus}) ; # $i{gross_50} = sprintf("%.2f",$i{gross_50}) ; $i{'source_admin'} = sprintf("%.2f",$i{'source_admin'}) ; $i{'3_perc'} = sprintf("%.2f",$i{'3_perc'}) ; $i{'5_perc'} = sprintf("%.2f",$i{'5_perc'}) ; $i{'6_perc'} = sprintf("%.2f",$i{'6_perc'}) ; $i{'8_perc'} = sprintf("%.2f",$i{'8_perc'}) ; $i{'10_perc'} = sprintf("%.2f",$i{'10_perc'}) ; $i{'15_perc'} = sprintf("%.2f",$i{'15_perc'}) ; $i{'20_perc'} = sprintf("%.2f",$i{'20_perc'}) ; } #------------------------------------------------------------------------------------------ sub sort_fields { %sort_field = () ; $sort_field{1} = 'description' ; $sort_field{2} = 'type' if $iaction eq 'add' ; $sort_field{3} = 'excl' ; $sort_field{4} = 'excl_from_summary' ; $sort_field{6} = 'nett' ; $sort_field{7} = 'freight' ; $sort_field{8} = 'source_admin' ; $sort_field{9} = 'main_price' ; $sort_field{10} = '3_perc' ; $preferred_title{'3_perc'} = '3%' ; $sort_field{11} = '5_perc' ; $preferred_title{'5_perc'} = '5%' ; $sort_field{12} = '6_perc' ; $preferred_title{'6_perc'} = '6%' ; $sort_field{13} = '8_perc' ; $preferred_title{'8_perc'} = '8%' ; $sort_field{14} = '10_perc' ; $preferred_title{'10_perc'} = '10%' ; $sort_field{15} = '15_perc' ; $preferred_title{'15_perc'} = '15%' ; $sort_field{16} = '20_perc' ; $preferred_title{'20_perc'} = '20%' ; } #------------------------------------------------------------------------------- sub report_ifields { &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &load_search_vars ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; if ($i{date_added_from} and $i{date_added_to}) { # check dates my $date_added_from_check = $i{date_added_from} ; $date_added_from_check =~ s/\-//g ; my $date_added_to_check = $i{date_added_to} ; $date_added_to_check =~ s/\-//g ; if ($date_added_from_check > $date_added_to_check) { $error = qq(PRICE LIST FROM ($i{date_added_from}) > PRICE LIST TO ($i{date_added_to})); &report_screen; } } if ($i{date_added_from}) { push @report_sql, "(`date_added` >= '$i{date_added_from}')" ; push @report_results, "date_added >= $i{date_added_from}" ; } if ($i{date_added_to}) { push @report_sql, "(`date_added` <= '$i{date_added_to}')" ; push @report_results, "date_added <= $i{date_added_to}" ; } $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 { # &db_min_ro('camera','id,name','','','') ; # foreach my $id (keys %{$db{camera}}) { $camera_name{$id} = $db{camera}{$id}{name} ; } # &db_min_ro('company','id,name','','','') ; # foreach my $id (keys %{$db{company}}) { $company_name{$id} = $db{company}{$id}{name} ; } # &db_min_ro('insurer','id,name','','','') ; # foreach my $id (keys %{$db{insurer}}) { $asset_insurer_name{$id} = $db{insurer}{$id}{name} ; } } #------------------------------------------------------------------------------------------ sub sort_prefixes { if ($iaction eq 'summary') { $sort_prefix_title{systems} = 'aaa' ; $sort_prefix{systems} = 'bbb' ; $sort_prefix_title{software_licence} = 'ccc' ; $sort_prefix{software_licence} = 'ddd' ; $sort_prefix_title{installation_kits} = 'eee' ; $sort_prefix{installation_kits} = 'fff' ; $sort_prefix_title{hardware_add_ons} = 'ggg' ; $sort_prefix{hardware_add_ons} = 'hhh' ; $sort_prefix_title{game_breakdown_analytics} = 'iii' ; $sort_prefix{game_breakdown_analytics} = 'jjj' ; $sort_prefix_title{additional_services} = 'kkk' ; $sort_prefix{additional_services} = 'lll' ; $sort_prefix_title{match_credits} = 'sss' ; $sort_prefix{match_credits} = 'ttt' ; } else { $sort_prefix_title{systems} = 'aaa' ; $sort_prefix{systems} = 'bbb' ; $sort_prefix_title{software_licence} = 'ccc' ; $sort_prefix{software_licence} = 'ddd' ; $sort_prefix_title{installation_kits} = 'eee' ; $sort_prefix{installation_kits} = 'fff' ; $sort_prefix_title{hardware_add_ons} = 'ggg' ; $sort_prefix{hardware_add_ons} = 'hhh' ; $sort_prefix_title{game_breakdown_analytics} = 'iii' ; $sort_prefix{game_breakdown_analytics} = 'jjj' ; $sort_prefix_title{additional_services} = 'kkk' ; $sort_prefix{additional_services} = 'lll' ; $sort_prefix_title{extended_services} = 'mmm' ; $sort_prefix{extended_services} = 'nnn' ; $sort_prefix_title{training_services} = 'ooo' ; $sort_prefix{training_services} = 'ppp' ; $sort_prefix_title{other_services} = 'qqq' ; $sort_prefix{other_services} = 'rrr' ; $sort_prefix_title{match_credits} = 'sss' ; $sort_prefix{match_credits} = 'ttt' ; } } #------------------------------------------------------------------------------------------ sub list_screen { &sort_prefixes ; my $srch_where_sql = join(' AND ', @report_sql) ; my $add_sql_where = '' ; # our @sql_col_display = ("id","item_code","excl","main_price","nett","type","type_cnt","description","freight","gross_10_1_50","gross_10_51_plus","gross_20_1_50","gross_20_51_plus","gross_50","last_updated","last_edited_by","") ; # our @sql_col_display = ("id","item_code","excl","main_price","nett","type","type_cnt","description","freight","source_admin","3_perc","5_perc","8_perc","10_perc","15_perc","20_perc","") ; # our @sql_col_display = ("description","main_price","3_perc","5_perc","6_perc","8_perc","10_perc","15_perc","20_perc") ; our @sql_col_display = ("description") ; push @sql_col_display, "nett" if $useropts{boss}{$username} ; push @sql_col_display, "main_price" ; push @sql_col_display, "3_perc" ; push @sql_col_display, "5_perc" ; push @sql_col_display, "6_perc" ; push @sql_col_display, "8_perc" ; push @sql_col_display, "10_perc" ; push @sql_col_display, "15_perc" ; push @sql_col_display, "20_perc" ; push @sql_col_display, "" ; our $exportdir = 'pricelist' ; &report_xls_export_header("Price-list$xlsreportname",$exportdir) ; &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &load_list_vars("$srch_where_sql$add_sql_where") ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; my $table_colspan = scalar @sql_col_display ; # get number ioif columns # foreach my $id (sort {$b <=> $a} keys %{$db{$table}}) { foreach my $id (sort {$db{$table}{$b}{type} cmp $db{$table}{$a}{type}} keys %{$db{$table}}) { # if (($i{active} == 1) and ($camera_id_in_use_for_devices{$id} < 1)) { next ; } # Active with devices # if (($i{active} == 2) and ($camera_id_in_use_for_devices{$id} > 0)) { next ; } # Active without devices # &common_debug("$iaction - $db{$table}{$id}{excl_from_summary} [description=$db{$table}{$id}{description}]") ; if ($iaction eq 'summary') { next if $db{$table}{$id}{excl_from_summary} ; next unless $sort_prefix_title{$db{$table}{$id}{type}} ; } my $print_type = uc $db{$table}{$id}{type} ; $print_type =~ s/\_/ /g ;# my @type_parts = split(/\_/,$print_type) ; @type_parts = map ucfirst, @type_parts; $print_type = join(" ", @type_parts) ; unless ($done_type_group{$db{$table}{$id}{type}}){ # $print_tbody .= qq~