#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } use CGI qw( :standard ); use CGI::Carp qw(fatalsToBrowser); use LWP::Simple qw($ua get); use Date::Calc qw(:all); use MIME::Lite; use Mail::Sendmail; use Time::Piece ; require cfg ; print header; # CGI.pm method #------------------------------------------------------------------------------- my @ARGV = split(/\&/, $ENV{'QUERY_STRING'}); my $type = $ARGV[0] ; our ($q) = CGI -> new() ; my $iaction = $q -> param('iaction') ; my $iattachdoc = $q -> param('iattachdoc') ; # our $debug = 1 ; # our $testing = 1 ; #------------------------------------------------------------------------------------------ &today ; # my $string = qq~6565,2,328.00~ ; if ($iaction eq '') { &screen1 ; } elsif ($iaction eq 'upload') { &db_open_ro ; our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it &read_import ; &read_db ; &process ; &screen4 ; $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it &db_close_conn ; } # elsif ($iaction eq 'save') { # &common_min_load_params ; # &db_open_upd ; # our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it # &read_read_import_lines ; # &update ; # $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it # &db_close_conn ; # &screen2 ; # } exit; #------------------------------------------------------------------------------------------ sub read_read_import_lines { our $max_unmatched_id = 0 ; my $upload_filehandle = $q->upload('iattachdoc') ; } #------------------------------------------------------------------------------------------ sub update { # &db_min_ro('logistics_costs','event_nr,amounts,file_name_ids,cost_type',"",'','') ; # &db_min_ro('logistics_costs_tables',"1,MAX(id)+1 AS 'max_id'","",'','') ; # $db{logistics_costs_tables}{1}{max_id} = 1 unless $db{logistics_costs_tables}{1}{max_id} ; # my %ii = %i ; my $updated_logistics_costs_tables = 0 ; my $file_id = 0 ; my %cost_types = () ; my %event_has_diff_cost_types = () ; my %prev_cost_type = () ; # foreach (keys %ii) { # if ($_ =~ /costtype_/) { # my ($NA,$event_id,$amnt_cnt) = split(/\_/,$_) ; # $event_id = ($event_id =~ /\d+/) ? $event_id : -1 ; # $cost_types{$event_id}{$amnt_cnt} = $ii{$_} ; # if ($prev_cost_type{$event_id} && $prev_cost_type{$event_id} ne $ii{$_}) { # $event_has_diff_cost_types{$event_id} = 1 ; # } # $prev_cost_type{$event_id} = $ii{$_} ; # } # } # foreach (keys %ii) { # if ($_ =~ /breakdownamnts_/) { # unless ($updated_logistics_costs_tables) { # $updated_logistics_costs_tables = 1 ; # %i = () ; # $i{id} = $db{logistics_costs_tables}{1}{max_id} ; # $file_id = $i{id} ; # $i{file_name} = $ii{uploaded_file_name} ; # $i{file_total} = $ii{uploaded_file_total} ; # $i{file_total} = sprintf("%.0f",$i{file_total}) ; # $i{file_nr_of_unique_events} = $ii{file_nr_of_unique_events} ; # $i{file_nr_of_rows} = $ii{file_nr_of_rows} ; # $i{date_uploaded} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ; # $i{uploaded_by} = $userid ; # # &db_min_insert('logistics_costs_tables') ; # } # my ($NA,$event_id) = split(/\_/,$_) ; # %i = () ; # $i{event_nr} = ($event_id =~ /\d+/) ? $event_id : -1 ; # $i{cost_type} = ($db{logistics_costs}{$i{event_nr}}{cost_type}) ? "$db{logistics_costs}{$i{event_nr}}{cost_type}::" : "" ; # my $added_to_cost_type = 0 ; # foreach my $amnt_cnt (sort {$a <=> $b} keys %{$cost_types{$i{event_nr}}}) { # $added_to_cost_type = 1 ; # $i{cost_type} .= qq~$cost_types{$i{event_nr}}{$amnt_cnt};;~ ; # last unless $event_has_diff_cost_types{$i{event_nr}} ; # } # $i{cost_type} = substr($i{cost_type},0,-2) if $added_to_cost_type ; # # $i{cost_type} = ($db{logistics_costs}{$i{event_nr}}{cost_type} ) ? "$db{logistics_costs}{$i{event_nr}}{cost_type}::" . $ii{"costtype_$event_id"} : $ii{"costtype_$event_id"} ; # $i{file_name_ids} = ($db{logistics_costs}{$i{event_nr}}{file_name_ids}) ? "$db{logistics_costs}{$i{event_nr}}{file_name_ids}:$file_id" : "$file_id" ; # $i{amounts} = ($db{logistics_costs}{$i{event_nr}}{amounts} ) ? "$db{logistics_costs}{$i{event_nr}}{amounts}:$ii{$_}" : "$ii{$_}" ; ; # $i{amounts} =~ s/\,//g ; # $i{amounts} =~ s/\.00//g ; # if ($i{event_nr} && $db{logistics_costs}{$i{event_nr}}{event_nr}) { # $ignore{event_nr} = 1 ; # # &db_min_upd('logistics_costs',"event_nr='$i{event_nr}'") ; # } else { # &db_min_ro('logistics_costs',"1,MAX(id)+1 AS 'max_id'","",'','') ; # $db{logistics_costs}{1}{max_id} = 1 unless $db{logistics_costs}{1}{max_id} ; # $i{id} = $db{logistics_costs}{1}{max_id} ; # # &db_min_insert('logistics_costs') ; # } # } # } } #------------------------------------------------------------------------------------------ sub read_import { $print_box_content_rows .= &common_min_forms_start('import-bank-transactions-form') ; my $upload_filehandle = $q->upload('iattachdoc') ; unless ($upload_filehandle) { $warning = "PLEASE UPLOAD A CSV FILE!!!" ; &common_min_alert_type ; &screen1 ; } our %totals = () ; my $line_cnt = 0 ; my %event_cnt = () ; if ($upload_filehandle !~ /.csv/) { $error = "PLEASE UPLOAD A CSV TYPE FILE!!!" ; &common_min_alert_type ; &screen1 ; } my $file_total_amnt = 0 ; my $file_nr_of_rows = 0 ; &db_min_ro('bank_transactions','id','','','') ; if ($type eq 'csv') { while ( <$upload_filehandle> ) { # foreach (@imported_file_data) { next if $_ !~ /\d+/ ; $file_nr_of_rows++ ; chomp $_; $_ =~ s/\R\z// ; my @data_arr = split(/\,/,$_) ; next if $db{bank_transactions}{$data_arr[0]}{id} ; $data{$data_arr[0]}{date_time} = $data_arr[1] ; $data{$data_arr[0]}{transaction_date} = $data_arr[2] ; $data{$data_arr[0]}{amount} = $data_arr[3] ; $data{$data_arr[0]}{balance} = $data_arr[4] ; $data{$data_arr[0]}{description} = $data_arr[5] ; $data{$data_arr[0]}{account_nr} = $data_arr[6] ; $data{$data_arr[0]}{category_id} = $data_arr[7] ; $data{$data_arr[0]}{client_id} = $data_arr[8] ; $data{$data_arr[0]}{invoice_nr} = $data_arr[9] ; } } foreach my $id (sort {$a <=> $b} keys %data) { %i = () ; $i{id} = $id ; foreach my $col (keys %{$data{$id}}) { $i{$col} = $data{$id}{$col} ; } &db_min_insert('bank_transactions') ; } # my $col_names = "id,date_time,transaction_date,amount,balance,description,account_nr,category_id,client_id,invoice_nr" ; # my $values = join("\n,",map{ "($_,'$data{$_}{date_time}','$data{$_}{transaction_date}','$data{$_}{amount}','$data{$_}{balance}','$data{$_}{description}','$data{$_}{account_nr}',$data{$_}{category_id},$data{$_}{client_id},'$data{$_}{invoice_nr}')" } keys %data) ; # print "\n INSERT INTO bank_transactions ($col_names) VALUES \n $values ;" if $values ; return ; # $file_total_amnt = sprintf("%.0f",$file_total_amnt) ; # our @sql_col_display = ("event_nr","cost_type","logistics_totals") ; # my $file_total = 0 ; my $file_nr_of_unique_events = 0 ; # &db_min_ro('event_quotes','id,quote_completed,quote_accepted,fixed_system_overall_status,event_system_id_multiple,quote_rejected,quote_cancelled,quote_created,quote_pending,sss_quote_nr',"",'','') ; # &db_min_ro('event_systems',"*",'','','') ; # my %seen_event = () ; # foreach my $event_id (sort {$a <=> $b} keys %totals) { # next if $event_id eq 'breakdown' ; # my $amnt_cnt = 0 ; # foreach my $sep_amnt (split(/\;/,$totals{breakdown}{$event_id})) { # $print_tbody .= qq~~ ; # $amnt_cnt++ ; # foreach (@sql_col_display) { # my $val = '' ; # my $class = qq~class="dt-center"~ ; # if ($_ eq 'event_nr') { # $val = ($event_id eq 'IBT') ? &common_min_get_event_quote_button("N/A") : &common_min_get_event_quote_button($event_id) ; # $file_nr_of_unique_events++ unless $seen_event{$event_id} ; # } elsif ($_ eq 'cost_type') { # $val = ($event_id eq 'IBT') ? $event_id : "" ; # $val = ($val) ? &common_min_table_input("costtype_$event_id\_$amnt_cnt",$val) : "" ; # } elsif ($_ eq 'logistics_totals') { # chop $totals{breakdown}{$event_id} if $totals{breakdown}{$event_id} ; # # my $seperate_amnts_tooltip = ($totals{breakdown}{$event_id} =~ /:/) ? $totals{breakdown}{$event_id} : qq~~ ; # # $seperate_amnts_tooltip =~ s/\:/\
/g ; # # $seperate_amnts_tooltip = qq~title data-toggle="tooltip" data-placement="right" data-original-title="Seperate Amounts :
$seperate_amnts_tooltip"~ if $seperate_amnts_tooltip ; # my $breakdownamnts = ($seen_event{$event_id}) ? qq~~ : qq~~ ; # # # # $totals{seperate}{$event_id}{$event_cnt{$event_id}} # # $totals{seperate}{$event_id}{$amnt_cnt} = &common_commify(sprintf("%.02f",$totals{seperate}{$event_id}{$amnt_cnt})) ; # $val = qq~$breakdownamnts~ . qq~~ . $totals{seperate}{$event_id}{$amnt_cnt} . qq~~ ; # $file_total += $totals{$event_id} unless $seen_event{$event_id} ; # } # # style="display:none; # $print_tbody .= qq~$val~ ; # } # $print_tbody .= qq~~ ; # $seen_event{$event_id} = 1 ; # } # } # &db_min_ro('logistics_costs_tables',"1,id","`file_total`='$file_total_amnt' AND `file_nr_of_unique_events`='$file_nr_of_unique_events' AND `file_nr_of_rows`='$file_nr_of_rows'",'','') ; # if ($db{logistics_costs_tables}{1}{id}) { # $warning = "THE FILE UPLOADED HAVE ALREADY BEEN SAVED!!!" ; # &common_min_alert_type ; # # &screen1 ; # # $print_box_content_rows .= qq~~ ; # } # $file_total = sprintf("%.02f",$file_total) ; # $print_box_content_rows .= qq~~ ; # $print_box_content_rows .= qq~~ ; # $print_box_content_rows .= qq~~ ; # $print_box_content_rows .= qq~~ ; # # $db_ignore_open_close = 0 ; # do one open and one close instead of repeating it # # &db_close_conn ; } #------------------------------------------------------------------------------------------ sub read_db { } #------------------------------------------------------------------------------------------ sub process { } #------------------------------------------------------------------------------------------ sub screen1 { &common_min_dialog ; $print_box_content_rows .= qq~
~; # my $date_inputs = &common_min_form_datepicker() ; print < $alert

Upload file from PC.

 
 
 
$dialog{'common'}{'js'} ENDOFTEXT # exit ; } #------------------------------------------------------------------------------------------ # sub screen2 { # # # my $jquery = qq~parent.\$("#alertbar").html(""); # parent.location.reload(); # parent.BootstrapDialog.closeAll() ;~ unless $debug ; # print < # # # # $useropts{title} # # # # # # # ENDOFTEXT # # # } #------------------------------------------------------------------------------------------ # sub screen3 { # &thead; # if ($isaved) { $alert = &common_min_alert('success',"$ucpage $isaved!",'ok') ; } else { &common_min_alert_type ; } # # my $page = "$lcpage\s" ; # my $page = "event-quotes" ; # if ($s{no}) { $page = $lcpage ; } # &common_min_thead ; # # &common_min_table('id',$page,'list') ; # $print_box_content_rows .= qq~ # # $print_thead # # $print_tbody # #
# ~ ; # # &common_min_table_select_jquery("#itv-table td:nth-last-child(2),#itv-table td:nth-last-child(10)") ; # # our $savjqy = 1 ; # # &common_min_extra_crumb("manage-$lcpage\s","Manage $ucfirstpage\s") ; # # $extra_form_fields .= qq~~ ; # # # # # # # # # # # # # # ~ ; # our $savjqy = 1 ; # $trigger_jquery_raw .= qq~ # \$("#savebutt").click( function () { # \$("#import-bank-transactions-form").submit() ; # }) ; # ~ ; # $print_box_content_rows .= &common_min_forms_end('','','save') ; # require _blank_4 ; # exit ; # } #------------------------------------------------------------------------------------------ sub screen4 { $trigger_jquery_raw .= qq~ if ("$i{analytics}" == "1") { parent.\$("#$i{sel_field}").append(""); parent.\$("#$i{sel_field}").trigger("chosen:updated"); } parent.BootstrapDialog.closeAll() ; ~; &common_min_dialog_save_screen ; } #------------------------------------------------------------------------------------------ use today ; use common ; # use production_time ;