-
-
-
-$jsscript
-
-
-
- {rowcount}>
-|;
+ my @old_project_ids = grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{rowcount};
- $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2);
-
- $amount = $locale->text('Amount');
- $project = $locale->text('Project');
-
- for $i (1 .. 1) {
-
-
- # format amounts
- $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
-
- print qq|
-
- | $amount |
- {"amount_$i"}> |
- $project |
-
- {"project_id_$i"}>
- |
- |
-
-|;
- $amount = "";
- $project = "";
- }
+ $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
+ "all" => 0,
+ "old_id" => \@old_project_ids },
+ "charts" => { "key" => "ALL_CHARTS",
+ "transdate" => $form->{transdate} },
+ "taxcharts" => { "key" => "ALL_TAXCHARTS",
+ "module" => "AR" },);
- $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax');
+ $_->{link_split} = { map { $_ => 1 } split/:/, $_->{link} } for @{ $form->{ALL_CHARTS} };
- print qq|
-
- | $taxlabel |
- {"tax"}> |
- |
- |
- |
-
-|;
-
+ my %project_labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{"ALL_PROJECTS"} };
+ my (@AR_amount_values);
+ my (@AR_values);
+ my (@AR_paid_values);
+ my %chart_labels;
+ my %charts;
+ my $taxchart_init;
- $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
+ foreach my $item (@{ $form->{ALL_CHARTS} }) {
+ if ($item->{link_split}{AR_amount}) {
+ $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
+ my $key = "$item->{accno}--$item->{tax_id}";
+ push(@AR_amount_values, $key);
+ } elsif ($item->{link_split}{AR}) {
+ push(@AR_values, $item->{accno});
+ } elsif ($item->{link_split}{AR_paid}) {
+ push(@AR_paid_values, $item->{accno});
+ }
- print qq|
-
-
- | |.$locale->text('Total').qq| |
- $form->{invtotal} |
-
- {oldinvtotal}>
- {oldtotalpaid}>
-
-
-
- |
- |
-
-
-
-
- | |.$locale->text('Notes').qq| |
- $notes |
-
-
- |
-
-
-
-
-
- | |.$locale->text('Incoming Payments').qq| |
-
-|;
+ # weirdness for AR_amount
+ $chart_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
+ $chart_labels{"$item->{accno}--$item->{tax_id}"} = "$item->{accno}--$item->{description}";
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AR_paid);
- } else {
- @column_index = qw(datepaid source memo paid exchangerate AR_paid);
+ $charts{$item->{accno}} = $item;
}
- $column_data{datepaid} = "".$locale->text('Date')." | ";
- $column_data{paid} = "".$locale->text('Amount')." | ";
- $column_data{exchangerate} = "".$locale->text('Exch')." | ";
- $column_data{AR_paid} = "".$locale->text('Account')." | ";
- $column_data{source} = "".$locale->text('Source')." | ";
- $column_data{memo} = "".$locale->text('Memo')." | ";
-
- print "
-
-";
- map { print "$column_data{$_}\n" } @column_index;
- print "
-
-";
+ my %taxchart_labels = ();
+ my @taxchart_values = ();
+ my %taxcharts = ();
+ foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
+ my $key = "$item->{id}--$item->{rate}";
+ $taxchart_init = $key if ($taxchart_init eq $item->{id});
+ push(@taxchart_values, $key);
+ $taxchart_labels{$key} = "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
+ $taxcharts{$item->{id}} = $item;
+ }
+ my $follow_up_vc = $form->{customer};
+ $follow_up_vc =~ s/--.*?//;
+ my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
+
+ $form->{javascript} .=
+ qq|| .
+ qq|| .
+ qq||;
+
+# $amount = $locale->text('Amount');
+# $project = $locale->text('Project');
+
+ my @transactions;
+ for my $i (1 .. $form->{rowcount}) {
+ my $transaction = {
+ amount => $form->{"amount_$i"},
+ tax => $form->{"tax_$i"},
+ project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"},
+ };
+
+ my $selected_accno_full;
+ my ($accno_row) = split(/--/, $form->{"AR_amount_$i"});
+ my $item = $charts{$accno_row};
+ $selected_accno_full = "$item->{accno}--$item->{tax_id}";
+
+ my $selected_taxchart = $form->{"taxchart_$i"};
+ my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
+ my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"});
+
+ if ($previous_accno &&
+ ($previous_accno eq $selected_accno) &&
+ ($previous_tax_id ne $selected_tax_id)) {
+ my $item = $taxcharts{$selected_tax_id};
+ $selected_taxchart = "$item->{id}--$item->{rate}";
+ }
- $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
- print "
-
-";
-
- $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
- $form->{"selectAR_paid_$i"} =~ s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
-
- # format amounts
- $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
- $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
-
- $exchangerate = qq| |;
- if ($form->{currency} ne $form->{defaultcurrency}) {
- if ($form->{"forex_$i"}) {
- $exchangerate = qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+ if (!$form->{"taxchart_$i"}) {
+ if ($form->{"AR_amount_$i"} =~ m/.--./) {
+ $selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
} else {
- $exchangerate = qq|{"exchangerate_$i"}>|;
+ $selected_taxchart = $taxchart_init;
}
}
-
- $exchangerate .= qq|
-{"forex_$i"}>
-|;
- $column_data{paid} = qq|| {"paid_$i"}> | |;
- $column_data{AR_paid} = qq| | |;
- $column_data{exchangerate} = qq|$exchangerate | |;
- $column_data{datepaid} = qq|{"datepaid_$i"}> | |;
- $column_data{source} = qq| | |;
- $column_data{memo} = qq| | |;
-
- map { print qq|$column_data{$_}\n| } @column_index;
-
- print "
-
-";
+ $transaction->{selectAR_amount} =
+ NTI($cgi->popup_menu('-name' => "AR_amount_$i",
+ '-id' => "AR_amount_$i",
+ '-style' => 'width:400px',
+ '-onChange' => "setTaxkey(this, $i)",
+ '-values' => \@AR_amount_values,
+ '-labels' => \%chart_labels,
+ '-default' => $selected_accno_full))
+ . $cgi->hidden('-name' => "previous_AR_amount_$i",
+ '-default' => $selected_accno_full);
+
+ $transaction->{taxchart} =
+ NTI($cgi->popup_menu('-name' => "taxchart_$i",
+ '-id' => "taxchart_$i",
+ '-style' => 'width:200px',
+ '-values' => \@taxchart_values,
+ '-labels' => \%taxchart_labels,
+ '-default' => $selected_taxchart));
+
+ push @transactions, $transaction;
}
- map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid);
- print qq|
-{paidaccounts}>
-
-
-
- |
-
-