#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } use CGI qw( :standard ); use CGI::Carp qw(fatalsToBrowser); require cfg ; print header; # CGI.pm method #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- 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 $redirtype = 'search' ; # our $debug = 1 ; # our $testing = 1 ; our $cust_cols = 1 ; # display _blank_3.pm our $camera_cnt_allowed = 1000 ; our $max_cams = 10 ; if ($useropts{tickets}{$username}) { print "Content-type: text/html\n\n"; require '401.pm' ; exit ; } #-------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- # unless ($username eq 'handre' or $username eq 'rory') { print "<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>" ; exit ; } # &db_open_ro; # $db_ignore_open_close=1; &page_opts ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- $ignore{"yearly_total"} = 1 ; $ignore{"yearly_totals_1"} = 1 ; $ignore{"yearly_totals_2"} = 1 ; $ignore{"yearly_totals_3"} = 1 ; $ignore{"yearly_totals_4"} = 1 ; $ignore{"yearly_totals_5"} = 1 ; if ($iaction eq 'add') { &add_screen ; &common_min_screen1 ; } if ($iaction eq 'edit') { &common_min_load_params ; &edit_screen ; &common_min_screen1 ; } if ($iaction eq 'save') { &common_min_load_params ; &insert ; &edit_or_list ; } if ($iaction eq 'update') { &common_min_load_params ; &update ; &edit_or_list ; } if ($iaction eq 'copy') { &common_min_load_params ; &duplicate ; &edit_screen ; &common_min_screen1 ; } if ($iaction eq 'delete') { &common_min_load_params ; &delete ; &common_min_screen2 ; } &common_min_action; # $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it # &db_close_conn ; exit; #------------------------------------------------------------------------------------------ sub edit_or_list { # if ($i{saveandexit} eq 'yes') { # &list_screen ; # &common_min_screen3; # } # else # { &edit_screen ; &common_min_screen1; # } } #------------------------------------------------------------------------------------------ sub insert { &add_db_fields ; $i{last_update} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; $i{datetime} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; $i{user_id} = $userid ; &set_default_i_vals; # &creat_db_cols; $i{id} = &db_min_get_max($table,'id') ; &titles_for_pdf ; &common_upload_files("costings/$i{id}") ; &process_upload_ifields; &process_totals ; our $nr_of_costing_rows = $i{nr_of_costing_rows} ; &db_open_upd ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &switch_table ; &db_min_insert($table) ; &new_table ; &db_min_insert('quotes_min') ; &update_camera; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; # exit ; } #------------------------------------------------------------------------------------------ sub update { unless ($i{id}) { $error = qq(NO ID) ; return ; } &edit_db_fields ; # &creat_db_cols; &titles_for_pdf ; &set_default_i_vals ; $i{last_update} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; &common_upload_files("costings/$i{id}") ; &process_upload_ifields ; &process_totals ; our $nr_of_costing_rows = $i{nr_of_costing_rows} ; &db_open_upd ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &switch_table ; &log_changes_1 ; # &db_min_upd($table,"id='$i{id}'") ; &common_shared_log_update_changes($table) ; &new_table ; &log_changes_2 ; &common_shared_log_update_changes("quotes_min","quotes_changes","changes") ; foreach (keys %ignore_for_now) { $ignore{$_} = '' ; } &update_camera ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; } #------------------------------------------------------------------------------------------ sub process_totals { my @ttlarr = ("one_time_fee","monthly_recurring_fee","annual_fee") ; my @ttlarr2 = ("subtotal","vat","total") ; foreach my $a (@ttlarr) { foreach my $b (@ttlarr2) { my $field = "$b\_$a" ; my $field_1 = "$b\_$a\_1" ; my $field_2 = "$b\_$a\_2" ; $ignore{$field_1} = 1 ; $ignore{$field_2} = 1 ; # $i{$field} = qq~$i{$field_1};$i{$field_2}~ ; } } $ignore{subtotal} = 1 ; $ignore{total} = 1 ; $ignore{vat} = 1 ; } #------------------------------------------------------------------------------------------ sub log_changes_1 { &db_min_ro($table,"*","`id`='$i{id}'",'','') ; our $line = qq~$now_year$now_mm$now_dd$now_hour$now_min$now_sec|$now_year-$now_mm-$now_dd $now_hour:$now_min:$now_sec|quote_id='$i{id}'|user_id=$userid|changed_from|~ ; my %col_to_be_updated = () ; my %ignore_for_now = () ; foreach (keys %i) { $col_to_be_updated{$_} = 1 ; } foreach my $col (keys %{$db{$table}{$i{id}}}) { next if $ignore{$col} or $hidden{$col} == 1 or substr($col,0,3) eq 'new' or not $col_to_be_updated{$col} ; if (($i{$col} or $db{$table}{$i{id}}{$col}) and $db{$table}{$i{id}}{$col} ne $i{$col}) { # $line .= qq~$col='$i{$col}',~ ; $line .= qq~$col='$db{$table}{$i{id}}{$col}',~ ; } elsif ((not $i{$col} and not $db{$table}{$i{id}}{$col}) or (($i{$col} or $db{$table}{$i{id}}{$col}) and $db{$table}{$i{id}}{$col} eq $i{$col})) { $ignore{$col} = 1 ; $ignore_for_now{$col} = 1 ; } } } #------------------------------------------------------------------------------------------ sub log_changes_2 { &db_min_ro('quotes_min','*',"id='$i{id}'",'','') ; foreach (keys %i) { $col_to_be_updated{$_} = 1 ; } foreach my $col (keys %{$db{quotes_min}{$i{id}}}) { next if $ignore{$col} or $hidden{$col} == 1 or substr($col,0,3) eq 'new' or not $col_to_be_updated{$col} ; if (($i{$col} or $db{quotes_min}{$i{id}}{$col}) and $db{quotes_min}{$i{id}}{$col} ne $i{$col}) { # $line .= qq~$col='$i{$col}',~ ; $line .= qq~$col='$db{quotes_min}{$i{id}}{$col}',~ ; } elsif ((not $i{$col} and not $db{quotes_min}{$i{id}}{$col}) or (($i{$col} or $db{quotes_min}{$i{id}}{$col}) and $db{quotes_min}{$i{id}}{$col} eq $i{$col})) { $ignore{$col} = 1 ; $ignore_for_now{$col} = 1 ; } } chop $line if $line ; &common_log_changes("events/changes_quotes.dat",$line) if $line ; # exit ; } #------------------------------------------------------------------------------------------ sub db_min_upd_raw { my ($sql) = @_ ; &common_debug($sql) ; my $sth = $dbh->prepare($sql) ; $sth->execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!"; $sth->finish(); } #------------------------------------------------------------------------------------------ sub titles_for_pdf { my $do_insert = 0; # our %sec_cnt = ('a_systems' => "3-Systems", 'b_software_licence' => "3-Software Licence (Monthly Fee)", 'c_game_breakdown_analytics' => "2-Game Breakdown and Analytics (Annual Fee)", 'd_installation_kits' => "7-Installation Kits", 'e_hardware_add_ons' => "7-Hardware Add Ons", 'f_additional_services' => "7-Additional Services", 'g_match_credits' => "4-Match Credits", 'h_other' => "5-Other", 'i_rental' => "2-Rental"); $sql_insert_pdf = qq~INSERT INTO `quotes_pdf_titles` (quote_id, old_name, new_name) VALUES ~ ; db_min_ro('quotes_pdf_titles', '*', "quote_id = $i{id}", '', '') ; foreach (keys %{$db{quotes_pdf_titles}}){ next unless $db{quotes_pdf_titles}{$_}{quote_id} == $i{id} ; $quote_id_old_pdf_titles{$db{quotes_pdf_titles}{$_}{quote_id}}{$db{quotes_pdf_titles}{$_}{old_name}} = 1 ; # &common_debug("ABC: $db{quotes_pdf_titles}{$_}{quote_id}, $db{quotes_pdf_titles}{$_}{old_name} $i{id}\n") ; } # &common_debug("ABC: ") ; $do_insert = 0 ; foreach(keys %sec_cnt){ $first_name = substr($sec_cnt{$_}, 2) ; $_k = substr($_,1) ; $ignore{$_k} = 1 ; if ($quote_id_old_pdf_titles{$i{id}}{$first_name} and $i{$_k}){ $sql_update_pdf = qq(UPDATE `quotes_pdf_titles` SET new_name = '$i{$_k}' WHERE old_name = '$first_name' and quote_id = $i{id} ;) ; &db_min_upd_raw($sql_update_pdf) ; } elsif (not $quote_id_old_pdf_titles{$i{id}}{$first_name} and $i{$_k}){ $sql_insert_pdf .= qq(($i{id}, '$first_name', '$i{$_k}'),) ; $do_insert = 1 ; } elsif ($quote_id_old_pdf_titles{$i{id}}{$first_name} and not $i{$_k}) { $sql_update_pdf = qq(UPDATE `quotes_pdf_titles` SET new_name = '$first_name' WHERE old_name = '$first_name' and quote_id = $i{id} ;) ; &db_min_upd_raw($sql_update_pdf) ; } elsif (not $quote_id_old_pdf_titles{$i{id}}{$first_name} and not $i{$_k}) { $sql_insert_pdf .= qq(($i{id}, '$first_name', '$first_name'),) ; $do_insert = 1 ; } } if ($do_insert){ chop $sql_insert_pdf ; $sql_insert_pdf .= ";" ; &db_min_upd_raw($sql_insert_pdf) ; } } #------------------------------------------------------------------------------------------ sub switch_table { &db_min_ro('quote_notes','*',"id='1'",'','') ; my @note_fields = ("note","payment_term","roe","delivery_time") ; for my $row_cnt (1 .. 12) { foreach my $fields (@note_fields) { my $field = "$fields\_$row_cnt" ; $ignore{$field} = (($i{$field} && $i{$field} eq $db{quote_notes}{1}{$field}) || (($fields eq "payment_term" || $fields eq "roe") && $row_cnt > 6) || ($fields eq "delivery_time" && $row_cnt > 4)) ? 1 : 0 ; $i{$field} = (!$i{$field} && $db{quote_notes}{1}{$field}) ? "-1" : $i{$field} ; } } # local @ttlarr = ("one_time_fee","monthly_recurring_fee","annual_fee") ; # local @ttlarr2 = ("subtotal","vat","total") ; # foreach my $a (@ttlarr) { # foreach my $b (@ttlarr2) { # my $field_1 = "1_$b\_$a" ; # my $field_2 = "2_$b\_$a" ; # my $field = "$b\_$a" ; # $i{$field} = qq~$i{$field_1};$i{$field_2}~ ; # $ignore{$field_1} = 1 ; # $ignore{$field_2} = 1 ; # } # } %y = () ; foreach (keys %i) { if ($_ =~ /^excl_costing_/ || $_ =~ /^description_costing_/ || $_ =~ /^qty_costing_/ || $_ =~ /^zar_amount_costing_/ || $_ =~ /^total_costing_/ || $_ =~ /^vat_costing_/) { $ignore{$_} = 1 ; } } for (1 .. $nr_of_costing_rows) { # $y{1}{$_} = "curr_amnt_" . "$_" . "_costing_additional_services"; # $y{2}{$_} = "curr_amnt_" . "$_" . "_costing_game_breakdown_analytics"; # $y{3}{$_} = "curr_amnt_" . "$_" . "_costing_hardware_add_ons"; # $y{4}{$_} = "curr_amnt_" . "$_" . "_costing_installation_kits"; # $y{5}{$_} = "curr_amnt_" . "$_" . "_costing_match_credits"; # $y{6}{$_} = "curr_amnt_" . "$_" . "_costing_other"; # $y{7}{$_} = "curr_amnt_" . "$_" . "_costing_rental"; # $y{8}{$_} = "curr_amnt_" . "$_" . "_costing_software_licence"; # $y{9}{$_} = "curr_amnt_" . "$_" . "_costing_systems"; # $y{10}{$_} = "excl_" . "$_" . "_costing_additional_services"; # $y{11}{$_} = "excl_" . "$_" . "_costing_game_breakdown_analytics"; # $y{12}{$_} = "excl_" . "$_" . "_costing_hardware_add_ons"; # $y{13}{$_} = "excl_" . "$_" . "_costing_installation_kits"; # $y{14}{$_} = "excl_" . "$_" . "_costing_match_credits"; # $y{15}{$_} = "excl_" . "$_" . "_costing_other"; # $y{16}{$_} = "excl_" . "$_" . "_costing_rental"; # $y{17}{$_} = "excl_" . "$_" . "_costing_software_licence"; # $y{18}{$_} = "excl_" . "$_" . "_costing_systems"; # $y{19}{$_} = "excl_" . "$_" . "_delivery_times"; # $y{20}{$_} = "excl_" . "$_" . "_notes"; # $y{21}{$_} = "excl_" . "$_" . "_payment_terms"; # $y{22}{$_} = "excl_" . "$_" . "_purchase_summary"; # $y{23}{$_} = "excl_" . "$_" . "_roes"; # $y{24}{$_} = "excl_" . "$_" . "_terms"; # $y{25}{$_} = "item_" . "$_" . "_costing_additional_services"; # $y{26}{$_} = "item_" . "$_" . "_costing_game_breakdown_analytics"; # $y{27}{$_} = "item_" . "$_" . "_costing_hardware_add_ons"; # $y{28}{$_} = "item_" . "$_" . "_costing_installation_kits"; # $y{29}{$_} = "item_" . "$_" . "_costing_match_credits"; # $y{30}{$_} = "item_" . "$_" . "_costing_other"; # $y{31}{$_} = "item_" . "$_" . "_costing_rental"; # $y{32}{$_} = "item_" . "$_" . "_costing_software_licence"; # $y{33}{$_} = "item_" . "$_" . "_costing_systems"; # $y{34}{$_} = "item_" . "$_" . "_purchase_summary"; # $y{35}{$_} = "item_ttl_" . "$_" . "_costing_additional_services"; # $y{36}{$_} = "item_ttl_" . "$_" . "_costing_game_breakdown_analytics"; # $y{37}{$_} = "item_ttl_" . "$_" . "_costing_hardware_add_ons"; # $y{38}{$_} = "item_ttl_" . "$_" . "_costing_installation_kits"; # $y{39}{$_} = "item_ttl_" . "$_" . "_costing_match_credits"; # $y{40}{$_} = "item_ttl_" . "$_" . "_costing_other"; # $y{41}{$_} = "item_ttl_" . "$_" . "_costing_rental"; # $y{42}{$_} = "item_ttl_" . "$_" . "_costing_software_licence"; # $y{43}{$_} = "item_ttl_" . "$_" . "_costing_systems"; # $y{44}{$_} = "qty_" . "$_" . "_costing_additional_services"; # $y{45}{$_} = "qty_" . "$_" . "_costing_game_breakdown_analytics"; # $y{46}{$_} = "qty_" . "$_" . "_costing_hardware_add_ons"; # $y{47}{$_} = "qty_" . "$_" . "_costing_installation_kits"; # $y{48}{$_} = "qty_" . "$_" . "_costing_match_credits"; # $y{49}{$_} = "qty_" . "$_" . "_costing_other"; # $y{50}{$_} = "qty_" . "$_" . "_costing_rental"; # $y{51}{$_} = "qty_" . "$_" . "_costing_software_licence"; # $y{52}{$_} = "qty_" . "$_" . "_costing_systems"; # $y{53}{$_} = "usd_amnt_" . "$_" . "_costing_additional_services"; # $y{54}{$_} = "usd_amnt_" . "$_" . "_costing_game_breakdown_analytics"; # $y{55}{$_} = "usd_amnt_" . "$_" . "_costing_hardware_add_ons"; # $y{56}{$_} = "usd_amnt_" . "$_" . "_costing_installation_kits"; # $y{57}{$_} = "usd_amnt_" . "$_" . "_costing_match_credits"; # $y{58}{$_} = "usd_amnt_" . "$_" . "_costing_other"; # $y{59}{$_} = "usd_amnt_" . "$_" . "_costing_rental"; # $y{60}{$_} = "usd_amnt_" . "$_" . "_costing_software_licence"; # $y{61}{$_} = "usd_amnt_" . "$_" . "_costing_systems"; # $y{62}{$_} = "vat_" . "$_" . "_costing_additional_services"; # $y{63}{$_} = "vat_" . "$_" . "_costing_game_breakdown_analytics"; # $y{64}{$_} = "vat_" . "$_" . "_costing_hardware_add_ons"; # $y{65}{$_} = "vat_" . "$_" . "_costing_installation_kits"; # $y{66}{$_} = "vat_" . "$_" . "_costing_match_credits"; # $y{67}{$_} = "vat_" . "$_" . "_costing_other"; # $y{68}{$_} = "vat_" . "$_" . "_costing_rental"; # $y{69}{$_} = "vat_" . "$_" . "_costing_software_licence"; # $y{70}{$_} = "vat_" . "$_" . "_costing_systems"; $y{71}{$_} = "excl_costing_$_" ; $y{72}{$_} = "description_costing_$_" ; $y{73}{$_} = "qty_costing_$_" ; $y{74}{$_} = "zar_amount_costing_$_" ; $y{75}{$_} = "vat_costing_$_"; $y{76}{$_} = "total_costing_$_"; foreach my $a (keys %y){ foreach my $b (keys %{$y{$a}}){ # $ignore{$y{$a}{$b}} = 1 ; $x{$a}{$b} = $i{$y{$a}{$b}} ; } } } } #------------------------------------------------------------------------------------------ sub new_table { # my ($insert_part) = @_ ; $iid = $i{id} ; my $quote_nr = $i{quote_nr} ; %i = () ; $i{id} = $iid ; $i{quote_nr} = $quote_nr ; $ignore{quote_nr} = 1 ; for (1 .. $nr_of_costing_rows) { # $i{curr_amnt_costing_additional_services} .= "$x{1}{$_};" ; # $i{curr_amnt_costing_game_breakdown_analytics} .= "$x{2}{$_};" ; # $i{curr_amnt_costing_hardware_add_ons} .= "$x{3}{$_};" ; # $i{curr_amnt_costing_installation_kits} .= "$x{4}{$_};" ; # $i{curr_amnt_costing_match_credits} .= "$x{5}{$_};" ; # $i{curr_amnt_costing_other} .= "$x{6}{$_};" ; # $i{curr_amnt_costing_rental} .= "$x{7}{$_};" ; # $i{curr_amnt_costing_software_licence} .= "$x{8}{$_};" ; # $i{curr_amnt_costing_systems} .= "$x{9}{$_};" ; # $i{excl_costing_additional_services} .= "$x{10}{$_};" ; # $i{excl_costing_game_breakdown_analytics} .= "$x{11}{$_};" ; # $i{excl_costing_hardware_add_ons} .= "$x{12}{$_};" ; # $i{excl_costing_installation_kits} .= "$x{13}{$_};" ; # $i{excl_costing_match_credits} .= "$x{14}{$_};" ; # $i{excl_costing_other} .= "$x{15}{$_};" ; # $i{excl_costing_rental} .= "$x{16}{$_};" ; # $i{excl_costing_software_licence} .= "$x{17}{$_};" ; # $i{excl_costing_systems} .= "$x{18}{$_};" ; # $i{excl_delivery_times} .= "$x{19}{$_};" ; # $i{excl_notes} .= "$x{20}{$_};" if $x{20}{$_}; # $i{excl_notes} .= "0;" if not $x{20}{$_}; # $i{excl_payment_terms} .= "$x{21}{$_};" ; # $i{excl_purchase_summary} .= "$x{22}{$_};" if $x{22}{$_}; # $i{excl_purchase_summary} .= "0;" if not $x{22}{$_}; # $i{excl_roes} .= "$x{23}{$_};" ; # $i{excl_terms} .= "$x{24}{$_};" ; # $i{item_costing_additional_services} .= "$x{25}{$_};" ; # $i{item_costing_game_breakdown_analytics} .= "$x{26}{$_};" ; # $i{item_costing_hardware_add_ons} .= "$x{27}{$_};" ; # $i{item_costing_installation_kits} .= "$x{28}{$_};" ; # $i{item_costing_match_credits} .= "$x{29}{$_};" ; # $i{item_costing_other} .= "$x{30}{$_};" ; # $i{item_costing_rental} .= "$x{31}{$_};" ; # $i{item_costing_software_licence} .= "$x{32}{$_};" ; # $i{item_costing_systems} .= "$x{33}{$_};" ; # $i{item_purchase_summary} .= "$x{34}{$_};" ; # $i{item_ttl_costing_additional_services} .= "$x{35}{$_};" ; # $i{item_ttl_costing_game_breakdown_analytics} .= "$x{36}{$_};" ; # $i{item_ttl_costing_hardware_add_ons} .= "$x{37}{$_};" ; # $i{item_ttl_costing_installation_kits} .= "$x{38}{$_};" ; # $i{item_ttl_costing_match_credits} .= "$x{39}{$_};" ; # $i{item_ttl_costing_other} .= "$x{40}{$_};" ; # $i{item_ttl_costing_rental} .= "$x{41}{$_};" ; # $i{item_ttl_costing_software_licence} .= "$x{42}{$_};" ; # $i{item_ttl_costing_systems} .= "$x{43}{$_};" ; # $i{qty_costing_additional_services} .= "$x{44}{$_};" ; # $i{qty_costing_game_breakdown_analytics} .= "$x{45}{$_};" ; # $i{qty_costing_hardware_add_ons} .= "$x{46}{$_};" ; # $i{qty_costing_installation_kits} .= "$x{47}{$_};" ; # $i{qty_costing_match_credits} .= "$x{48}{$_};" ; # $i{qty_costing_other} .= "$x{49}{$_};" ; # $i{qty_costing_rental} .= "$x{50}{$_};" ; # $i{qty_costing_software_licence} .= "$x{51}{$_};" ; # $i{qty_costing_systems} .= "$x{52}{$_};" ; # $i{usd_amnt_costing_additional_services} .= "$x{53}{$_};" ; # $i{usd_amnt_costing_game_breakdown_analytics} .= "$x{54}{$_};" ; # $i{usd_amnt_costing_hardware_add_ons} .= "$x{55}{$_};" ; # $i{usd_amnt_costing_installation_kits} .= "$x{56}{$_};" ; # $i{usd_amnt_costing_match_credits} .= "$x{57}{$_};" ; # $i{usd_amnt_costing_other} .= "$x{58}{$_};" ; # $i{usd_amnt_costing_rental} .= "$x{59}{$_};" ; # $i{usd_amnt_costing_software_licence} .= "$x{60}{$_};" ; # $i{usd_amnt_costing_systems} .= "$x{61}{$_};" ; # $i{vat_costing_additional_services} .= "$x{62}{$_};" ; # $i{vat_costing_game_breakdown_analytics} .= "$x{63}{$_};" ; # $i{vat_costing_hardware_add_ons} .= "$x{64}{$_};" ; # $i{vat_costing_installation_kits} .= "$x{65}{$_};" ; # $i{vat_costing_match_credits} .= "$x{66}{$_};" ; # $i{vat_costing_other} .= "$x{67}{$_};" ; # $i{vat_costing_rental} .= "$x{68}{$_};" ; # $i{vat_costing_software_licence} .= "$x{69}{$_};" ; # $i{vat_costing_systems} .= "$x{70}{$_};" ; $i{excl_costing} .= "$x{71}{$_};" ; $i{description_costing} .= "$x{72}{$_}:;:" ; $i{qty_costing} .= "$x{73}{$_};" ; $i{amount_costing} .= "$x{74}{$_};" ; $i{vat_costing} .= "$x{75}{$_};" ; } # if ($insert_part){ # $sql_insert_1 = qq~INSERT INTO `quotes_min` (~ ; # $sql_insert_2 = qq~VALUES (~ ; # } foreach (keys %i) { next if $_ eq 'id' ; if ($_ =~ /^excl_/ || $_ =~ /^vat_/) { $i{$_} =~ s/\0//g ; } elsif ($_ =~ /_amnt_/ || $_ =~ /_amount_/) { $i{$_} =~ s/^0.00//g ; $i{$_} =~ s/\;0.00/\;/g ; } $i{$_} =~ s/;+$//g ; $i{$_} =~ s/\:;:+$//g if $_ =~ /^description_/ ; } # if ($insert_part){ # $sql_insert_1 .= qq~$_,~ ; # $sql_insert_2 .= qq~'$i{$_}',~ ; # } # } # if ($insert_part){ # chop $sql_insert_1 ; # chop $sql_insert_2 ; # $sql_insert_2 .= qq~) ;~ ; # $final_insert = $sql_insert_1 . $sql_insert_2 ; # &db_min_upd_raw($final_insert) ; # } } #------------------------------------------------------------------------------------------ sub update_camera { # &common_debug("1. update_camera : $i{quote_nr}"); unless ($i{quote_nr}) { $error = qq~NO QUOTE NR~ ; return ; } # &common_debug("update_camera : $error"); $ignore{quote_nr} = '' ; $q{quote_nr} = $i{quote_nr} ; # $q{quote_ref} = $i{ref} ; $q{id} = $i{id} ; %i=(); $i{quote_delivery_date} = NULL ; $i{quote_active_date} = NULL ; $i{quote_ew_date_from} = NULL ; $i{quote_ew_date_to} = NULL ; $i{quote_cam_desc} = NULL ; $i{quote_cam_excl} = 0 ; $i{quote_cam_num} = 0 ; $i{quote_nr} = 0 ; $i{quote_ref} = NULL ; # &db_min_ro('cameras','*',"quote_nr='$q{quote_nr}'",'','') ; # &db_min_ro('quotes','*','','','') ; &db_min_upd('cameras',"quote_nr='$q{quote_nr}'") ; # remove all previous links to this quote # $i{quote_nr} = $q{quote_nr} ; # $i{quote_ref} = $q{quote_ref} ; for (1 .. $camera_cnt_allowed) { # &common_debug("$_. camera_nr_$_\_camera_details [".$q{"camera_nr_$_\_camera_details"}."]"); next unless $q{"camera_nr_$_\_camera_details"} ; %i=(); $i{quote_nr} = $q{quote_nr} ; $i{quote_delivery_date} = $q{"delivery_date_$_\_camera_details"} if $q{"delivery_date_$_\_camera_details"} ; $i{quote_active_date} = $q{"active_date_$_\_camera_details"} if $q{"active_date_$_\_camera_details"} ; $i{quote_ew_date_from} = $q{"ew_date_from_$_\_camera_details"} if $q{"ew_date_from_$_\_camera_details"} ; $i{quote_ew_date_to} = $q{"ew_date_to_$_\_camera_details"} if $q{"ew_date_to_$_\_camera_details"} ; $i{quote_cam_desc} = $q{"description_$_\_camera_details"} if $q{"description_$_\_camera_details"} ; $i{quote_cam_excl} = $q{"excl_$_\_camera_details"} if $q{"excl_$_\_camera_details"} ; $i{quote_cam_num} = $_ if $_ ; $i{quote_ref} = $q{"ref_$_\_camera_details"} if $q{"ref_$_\_camera_details"} ; my @valarr = split(/\:/,$q{"camera_nr_$_\_camera_details"}) ; # $id:camera_nr:camera_system_id:serial_nr:date_delivered:camera_system:item_code:date_active my $abrv_cam_system = substr($valarr[1],0,3); # &common_debug("[".$q{"camera_nr_$_\_camera_details"}."] abrv_cam_system=$abrv_cam_system, abrv_prev_cam_system=$abrv_prev_cam_system, prev_cam_nr=$prev_cam_nr, link to: c_excl_$_\_camera_details") ; if ($abrv_cam_system eq 'VPU' and ($abrv_prev_cam_system eq 'S1' or $abrv_prev_cam_system eq 'S2' or $abrv_prev_cam_system_other eq 'Prime' or $abrv_prev_cam_system_other eq 'Coach')) { # $trigger_jquery .= qq~\$("#c_excl_$_\_camera_details").append("");\$('[data-toggle="tooltip"]').tooltip({html:true}) ;~; my $s1_cnt = $_-1; $i{quote_linked_vpu} = $q{"serial_nr_$s1_cnt\_camera_details"} if $q{"serial_nr_$s1_cnt\_camera_details"} ; } $abrv_prev_cam_system = substr($abrv_cam_system,0,2); $abrv_prev_cam_system_other = substr($abrv_cam_system,0,5); $prev_cam_nr = $valarr[1] ; my $cam_id = $valarr[0] ; next unless $cam_id ; &db_min_upd('cameras',"id='$cam_id'") ; # add the new details from the screen # $i{quote_linked_vpu} = '' ; } $i{id} = $q{id} ; } #------------------------------------------------------------------------------------------ sub duplicate { unless ($i{id}) { $error = qq~NO ID~ ; return ; } local $copy_id = $i{id} ; &db_min_copy($table,$copy_id) ; &db_min_copy('quotes_min',$copy_id) ; &common_min_copy_files("$htmlpath/uploads/workings/$copy_id","$htmlpath/uploads/workings/$i{id}") ; } #------------------------------------------------------------------------------------------ sub delete { my $dbid = 'id' ; if ($uniq_id) { $dbid = $uniq_id ; } unless ($i{$dbid}) { $error = uc "NO $dbid" ; return ; } &db_min_delete('quotes',"$dbid='$i{$dbid}'") ; &db_min_delete('quotes_min',"$dbid='$i{$dbid}'") ; &common_min_delete_files("$htmlpath/uploads/workings/$i{$dbid}") ; }#------------------------------------------------------------------------------------------ sub process_upload_ifields { $ignore{costing_1} = 1 ; $ignore{costing_2} = 1 ; $ignore{costing_3} = 1 ; $ignore{iattachcosting_1} = 1 ; $ignore{iattachcosting_2} = 1 ; $ignore{iattachcosting_3} = 1 ; $i{costing_uploads} = qq~$i{iattachcosting_1}:;:$i{iattachcosting_2}:;:$i{iattachcosting_3}~ ; $i{costing_uploads} =~ s/\:;:+$//g ; # foreach (keys %uploads_file) { $i{$_} = $uploads_file{$_} ; $ignore{$_} = '' ; } } #------------------------------------------------------------------------------------------ sub set_default_i_vals { my @camera_details = ('camera_nr_','serial_nr_','description_','active_date_','delivery_date_','ew_date_from_','ew_date_to_','ref_','excl_') ; for (1 .. $camera_cnt_allowed) { foreach my $cdet_ (@camera_details) { my $col = "$cdet_$_\_camera_details"; $ignore{$col} = 1 ; # set the value to only be the id $q{$col} = $i{$col} ; # set the value to only be the id } } my $srch_where_sql = "`id`='$i{id}'" ; $iaction eq 'save' ? &db_min_ro($table,'*','','id DESC',1) : &db_min_ro($table,'*',$srch_where_sql,'','') ; foreach (sort { $col_name{$a} cmp $col_name{$b} } keys %col_name) { $col = $col_name{$_} ; &common_min_debug("1. [$col] [$i{$col}]"); if (substr($col,0,4) eq 'vat_' or substr($col,0,5) eq 'excl_' or substr($col,0,4) eq 'qty_') { unless ($i{$col}) { $i{$col} = 0 ; } } # only create the column if it doesn't exist if (substr($col,0,9) eq 'usd_amnt_' or substr($col,0,10) eq 'curr_amnt_' or substr($col,0,9) eq 'item_ttl_' or substr($col,-6,6) eq '_total') { unless ($i{$col}) { $i{$col} = '0.00' ; } } # # if (substr($col,0,14) eq 'delivery_date_' or substr($col,0,12) eq 'active_date_') { # if (substr($col,0,14) eq 'delivery_date_' or substr($col,0,12) eq 'active_date_' or substr($col,0,8) eq 'ew_date_') { # unless ($i{$col}) { $i{$col} = NULL ; } # } # if ((substr($col,6,9) eq '_costing_' and substr($col,0,5) eq 'item_' and $i{$col}) or ($col eq 'quote_to' and $i{$col}) or (substr($col,-15,15) eq '_camera_details' and substr($col,0,10) eq 'camera_nr_' and $i{$col})) { # if ((substr($col,6,9) eq '_costing_' and substr($col,0,5) eq 'item_' and $i{$col}) or ($col eq 'quote_to' and $i{$col})) { if (((substr($col,6,9) eq '_costing_' or substr($col,7,9) eq '_costing_') and substr($col,0,5) eq 'item_' and $i{$col}) or ($col eq 'quote_to' and $i{$col})) { # item_1_costing_match_credits my @valarr = split(/\:/,$i{$col}) ; $i{$col} = $valarr[0] ; # set the value to only be the id } # if (substr($col,-15,15) eq '_camera_details') { # # if (substr($col,0,9) eq 'camera_nr') { # # my @valarr = split(/\:/,$i{$col}) ; # # $q{$col} = $i{$col} ; # set the value to only be the id # # $i{$col} = $valarr[0] ; # set the value to only be the id # # } elsif (substr($col,0,5) eq 'excl_') { # # # do nothing # # } else { # $ignore{$col} = 1 ; # set the value to only be the id # $q{$col} = $i{$col} ; # set the value to only be the id # # } # } # &common_min_debug("2. [$col] [$i{$col}]"); } $i{terms} = 0 unless $i{terms} ; $i{quote_accepted} = 0 unless $i{quote_accepted} ; $i{quote_pending} = 0 unless $i{quote_pending} ; $i{quote_cancelled} = 0 unless $i{quote_cancelled} ; $i{annual_invoice} = 0 unless $i{annual_invoice} ; $i{period} = 0 unless $i{period} ; $i{max_cams} = 0 unless $i{max_cams} ; $i{camera_system_id} = 0 unless $i{camera_system_id} ; $i{country_shipped} = 0 unless $i{country_shipped} ; $i{discount} = 0 unless $i{discount} ; $i{systems_included} = 0 unless $i{systems_included} ; $i{rental_included} = 0 unless $i{rental_included} ; $i{total_1_purchase_summary} = "0.00" unless $i{total_1_purchase_summary} ; $i{total_2_purchase_summary} = "0.00" unless $i{total_2_purchase_summary} ; $i{total_3_purchase_summary} = "0.00" unless $i{total_3_purchase_summary} ; for my $a (1 .. 3) { for my $b (1 .. 3) { $i{"year_$a\_$b\_purchase_summary"} = "0.00" unless $i{"year_$a\_$b\_purchase_summary"} ; } } $ignore{invoice_date} = 1 unless length($i{invoice_date}) == 10 ; } #---------------------------------------------------------------------------------------- sub list_screen { &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it # my $tables = 'towns,airport_codes' ; # &db_min_ro($tables,'towns.id,towns.airport_code,airport_codes.name,towns.name','towns.airport_code=airport_codes.iata_code','','') ; # foreach my $id (keys %{$db{$tables}}) { $user{$id} = $db{$tables}{$id}{name} ; } # &db_min_ro('users','id,name','','','') ; # foreach my $id (keys %{$db{users}}) { $user{$id} = $db{users}{$id}{name} ; } # &db_min_ro('customers','id,name','','','') ; # foreach my $id (keys %{$db{customers}}) { $customers{$id} = $db{customers}{$id}{name} ; } # &db_min_ro('camera_systems','*','','','') ; # foreach my $id (keys %{$db{camera_systems}}) { $camera_system{$id} = $db{camera_systems}{$id}{name} ; } # &db_min_ro('countries','*','','','') ; # foreach my $id (keys %{$db{countries}}) { $country{$id} = $db{countries}{$id}{name} ; } if ($iaction eq 'accepted' or $i{options} eq 'accepted') { push @report_sql, "$table.quote_accepted='1'" ; } if ($iaction eq 'closed' or $i{options} eq 'closed') { push @report_sql, "($table.quote_cancelled='1' OR ($table.quote_expiry<'$now_year-$now_mm-$now_dd' AND $table.quote_accepted<>'1'))" ; } if ($iaction eq 'pending' or $i{options} eq 'pending') { push @report_sql, "$table.quote_pending='1'" ; } if ($iaction eq 'list' or $i{options} eq 'list') { push @report_sql, "$table.quote_cancelled<>'1'" ; } my $t1 = $table ; my $t2 = 'countries' ; my $t3 = 'camera_systems' ; my $t4 = 'customers' ; my $t5 = 'quote_type' ; my $t6 = 'quotes_min' ; our $tables = "$t1,$t2,$t3,$t4,$t5,$t6" ; # push @report_sql, "($t1.country_shipped=$t2.id)" ; # push @report_sql, "($t1.camera_system_id=$t3.id)" ; # push @report_sql, "($t1.quote_to=$t4.id)" ; # push @report_sql, "($t1.type_id=$t5.id)" ; my $srch_where_sql = join(' AND ', @report_sql) ; $srch_where_sql = "1" unless $srch_where_sql ; # &db_min_ro($tables,"$t1.id AS 'quote_id',$t1.quote_nr,$t1.ref,$t1.qty,$t1.quote_expiry,$t1.quote_to,$t1.invoice_nr,$t1.quote_date,$t1.type,$t1.currency,$t1.country_shipped,$t1.total_1_purchase_summary,$t1.total_2_purchase_summary,$t1.total_3_purchase_summary,$t1.quote_cancelled,$t1.quote_accepted,$t1.quote_pending,$t1.activetab,$t2.name AS 'country',$t3.name AS 'camera_system',$t4.name AS 'customer',$t5.name AS 'type'",$srch_where_sql,'','') ; &db_min_raw(" SELECT $t1.id AS 'quote_id', $t1.quote_nr, $t1.ref, $t1.qty, $t1.quote_expiry, $t1.quote_to, $t1.invoice_nr, $t1.quote_date, $t1.type, $t1.currency, $t1.country_shipped, $t1.total_1_purchase_summary, $t1.total_2_purchase_summary, $t1.total_3_purchase_summary, $t1.quote_cancelled, $t1.quote_accepted, $t1.quote_pending, $t1.activetab, $t1.roe, $t2.name AS 'country', $t3.name AS 'camera_system', $t4.name AS 'customer', $t5.name AS 'type', $t6.qty_costing, $t6.amount_costing, $t6.vat_costing, $t6.excl_costing FROM $t1 LEFT JOIN $t2 ON $t1.country_shipped=$t2.id LEFT JOIN $t3 ON $t1.camera_system_id=$t3.id LEFT JOIN $t4 ON $t1.quote_to=$t4.id LEFT JOIN $t5 ON $t1.type_id=$t5.id LEFT JOIN $t6 ON $t1.id=$t6.id WHERE $srch_where_sql ; ") ; foreach $row (@$rows_array_ref) { for (0 .. $col_cnt){ # &common_debug("[$_] $col_name{$_} -> @$row[$_]") ; $db{$tables}{@$row[0]}{$col_name{$_}} = @$row[$_] ; } } $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; &tab_hash ; # load for PDF links # &common_load_quote_vars("cameras.quote_nr>0 AND cameras.quote_cam_num='1' AND (cameras.quote_delivery_date IS NOT NULL or cameras.quote_active_date IS NOT NULL) AND cameras.quote_nr=quotes.quote_nr"); &common_load_quote_vars("cameras.quote_nr>0 AND cameras.quote_nr=quotes.quote_nr"); # foreach (keys %quote_cam_delivery_date) { # $store_quote_cam_delivery_date{$_}{1} = $quote_cam_delivery_date{$_}{1} ; # } # foreach (keys %quote_cam_delivery_date) { # $store_quote_cam_active_date{$_}{1} = $quote_cam_active_date{$_}{1} ; # } "e_list ; # load for PDF links # our $fnsort = 1 ; # used &common_min_screen3 for fnsort column &common_min_table if ($iaction eq 'update' or $iaction eq 'save'){ &common_min_extra_crumb("list-$lcpage\s","List $ucfirstpage\s") ; } } #------------------------------------------------------------------------------------------ sub quote_list { our @sql_col_display = ("nr","date","customer","country","type","qty","CUR","amount","invoice_nr","") ; # our @sql_col_display = ("nr","date","customer","ref","country","camera_system_id","qty","curr","amount","invoice_nr","type","date_delivered","date_active","flag","") ; # our @sql_col_display = ("nr","date","customer","ref","invoice_nr","type","") ; if ($i{export_to_excel}) { &report_xls_export_header("Quotes",'quotes') ; } # &common_min_debug("[$table]"); our $open_new_tab = qq~target="_blank"~ ; foreach my $id (sort {$b <=> $a} keys %{$db{$tables}}) { # &common_min_debug("[$id] [$tables] [$db{$tables}{$id}{quote_nr} ]"); unless ($id) { next ; } our $quote_expiry = $db{$tables}{$id}{quote_expiry} ; $quote_expiry =~ s/\-//iog ; # my $quote_date = $db{$tables}{$id}{quote_date} ; $quote_date =~ s/\-//iog ; # if ($quote_expiry and $quote_expiry<"$now_year$now_mm$now_dd" and $iaction ne 'report' and $iaction ne 'accepted' and $iaction ne 'closed' and $iaction ne 'all') { next ; } # $yr = substr($quote_date, 0, 4) ; # $mm = substr($quote_date, 4, 2) ; # $dd = substr($quote_date, 6, 2) ; # my ($yr2,$mm2,$dd2) = Add_Delta_Days($yr,$mm,$dd,60); # # $mm2 = sprintf("%02s", $mm2) ; # $dd2 = sprintf("%02s", $dd2) ; # $quote_date = "$yr2$mm2$dd2" ; # if ($quote_date and $quote_date<"$now_year$now_mm$now_dd" and $db{$tables}{$id}{quote_accepted}!=1 and # $iaction ne 'report' and $iaction ne 'accepted' and $iaction ne 'closed' and $iaction ne 'all' and # $i{options} ne 'accepted' and $i{options} ne 'closed' and $i{options} ne 'all') # { next ; } if ($quote_expiry and $quote_expiry<"$now_year$now_mm$now_dd" and $db{$tables}{$id}{quote_accepted}!=1 and $iaction ne 'report' and $iaction ne 'accepted' and $iaction ne 'closed' and $iaction ne 'all' and $i{options} ne 'accepted' and $i{options} ne 'closed' and $i{options} ne 'all') { next ; } # &common_min_debug("[$id] [$tables] [$db{$tables}{$id}{quote_nr} ]"); $print_tbody .= qq~