$form->{title} |
@@ -441,64 +438,68 @@ sub form_header {
-
-
-
- | . $locale->text('Vendor') . qq| |
- $vendor |
-
-
-
- {terms}>
-
-
- |
-
-
-
- | . $locale->text('Credit Limit') . qq| |
- $form->{creditlimit} |
- | . $locale->text('Remaining') . qq| |
- $form->{creditremaining} |
- {creditlimit}>
- {creditremaining}>
-
-
- |
-
- | . $locale->text('Currency') . qq| |
- |
-
- {defaultcurrency}>
- {fxgain_accno}>
- {fxloss_accno}>
- $exchangerate
-
- $department
- $taxincluded
-
- |
-
-
+ |
+
|
@@ -506,73 +507,99 @@ sub form_header {
$jsscript
-
-
-
{rowcount}>
-
-
-
- |
- . $locale->text('Account') . qq| |
- |
- . $locale->text('Amount') . qq| |
- |
- . $locale->text('Tax') . qq| |
- |
- . $locale->text('Korrektur') . qq| |
- |
- . $locale->text('Taxkey') . qq| |
- |
- . $locale->text('Project') . qq| |
-
+
+
+
+ | . $locale->text('Account') . qq| |
+ | . $locale->text('Amount') . qq| |
+ | . $locale->text('Tax') . qq| |
+ | . $locale->text('Taxkey') . qq| |
+ | . $locale->text('Project') . qq| |
+
|;
- $amount = $locale->text('Amount');
- $project = $locale->text('Project');
+ my $amount = $locale->text('Amount');
+ my $project = $locale->text('Project');
- for $i (1 .. $form->{rowcount}) {
+ for my $i (1 .. $form->{rowcount}) {
# format amounts
$form->{"amount_$i"} =
$form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
$form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
- $selectAP_amount = $selectAP_amount_unquoted;
- $re_amount = quotemeta($form->{"AP_amount_$i"});
- $selectAP_amount =~
- s/option value=\"${re_amount}\"/option value=\"$form->{"AP_amount_$i"}\" selected/;
- $tax = $taxchart;
- $tax_selected = $form->{"taxchart_$i"};
- $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
- $tax =
- qq| | |;
-
- my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
+
+ my $selected_accno_full;
+ my ($accno_row) = split(/--/, $form->{"AP_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_AP_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}";
+ }
+
+ $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
+
+ my $selectAP_amount =
+ NTI($cgi->popup_menu('-name' => "AP_amount_$i",
+ '-id' => "AP_amount_$i",
+ '-style' => 'width:400px',
+ '-onChange' => "setTaxkey(this, $i)",
+ '-values' => \@AP_amount_values,
+ '-labels' => \%AP_amount_labels,
+ '-default' => $selected_accno_full))
+ . $cgi->hidden('-name' => "previous_AP_amount_$i",
+ '-default' => $selected_accno_full);
+
+ my $tax = qq|| .
+ NTI($cgi->popup_menu('-name' => "taxchart_$i",
+ '-id' => "taxchart_$i",
+ '-style' => 'width:200px',
+ '-values' => \@taxchart_values,
+ '-labels' => \%taxchart_labels,
+ '-default' => $selected_taxchart))
+ . qq| | |;
+
+ my $projectnumber =
+ NTI($cgi->popup_menu('-name' => "project_id_$i",
+ '-values' => \@project_values,
+ '-labels' => \%project_labels,
+ '-default' => $form->{"project_id_$i"} ));
print qq|
-
- |
+
+ $selectAP_amount |
{"amount_$i"}> |
- {"tax_$i"}> |
- |
+ $form->{"tax_$i"} |
$tax
-
- {"project_id_$i"}>
- |
-
+ $projectnumber |
+
|;
$amount = "";
$project = "";
}
- $taxlabel =
+ my $taxlabel =
($form->{taxincluded})
? $locale->text('Tax Included')
: $locale->text('Tax');
+ $form->{invtotal_unformatted} = $form->{invtotal};
$form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
+ my $APselected =
+ NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
+ '-style' => 'width:400px',
+ '-values' => \@AP_values, '-labels' => \%AP_labels,
+ '-default' => $form->{APselected}));
print qq|
@@ -580,52 +607,54 @@ $jsscript
|
- |
-
- $form->{invtotal} |
+ ${APselected} |
+ $form->{invtotal} |
- {oldinvtotal}>
- {oldtotalpaid}>
+ {oldinvtotal}>
+ {oldtotalpaid}>
-
+
- |
+ |
-
- |
+
+ |
- | . $locale->text('Notes') . qq| |
- $notes |
-
+ | . $locale->text('Notes') . qq| |
+ $notes |
+
|
-
- | . $locale->text('Payments') . qq| |
-
+
+ | . $locale->text('Payments') . qq| |
+
|;
- if ($form->{currency} eq $form->{defaultcurrency}) {
- @column_index = qw(datepaid source memo paid AP_paid);
+ my @column_index;
+ if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
+ @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
} else {
- @column_index = qw(datepaid source memo paid exchangerate AP_paid);
+ @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
}
+ my %column_data;
$column_data{datepaid} = "" . $locale->text('Date') . " | ";
$column_data{paid} = "" . $locale->text('Amount') . " | ";
$column_data{exchangerate} = "" . $locale->text('Exch') . " | ";
$column_data{AP_paid} = "" . $locale->text('Account') . " | ";
$column_data{source} = "" . $locale->text('Source') . " | ";
$column_data{memo} = "" . $locale->text('Memo') . " | ";
+ $column_data{paid_project_id} = "" . $locale->text('Project Number') . " | ";
print "
@@ -635,33 +664,61 @@ $jsscript
";
- my @triggers = ();
+ my @triggers = ();
+ $form->{totalpaid} = 0;
+
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
+ for my $i (1 .. $form->{paidaccounts}) {
print "
";
- $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
- $form->{"selectAP_paid_$i"} =~
- s/option value=\"$form->{"AP_paid_$i"}\">/option value=\"$form->{"AP_paid_$i"}\" selected>/;
+ my $selectAP_paid =
+ NTI($cgi->popup_menu('-name' => "AP_paid_$i",
+ '-id' => "AP_paid_$i",
+ '-values' => \@AP_paid_values,
+ '-labels' => \%AP_paid_labels,
+ '-default' => $form->{"AP_paid_$i"}));
+
+ $form->{totalpaid} += $form->{"paid_$i"};
# format amounts
if ($form->{"paid_$i"}) {
$form->{"paid_$i"} =
- $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ }
+ if ($form->{"exchangerate_$i"} == 0) {
+ $form->{"exchangerate_$i"} = "";
+ } else {
+ $form->{"exchangerate_$i"} =
+ $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ }
+
+ print qq|{"acc_trans_id_$i"}>\n|;
+ print qq|{"gldate_$i"}>\n|;
+ my $changeable = 1;
+ if ($::lx_office_conf{features}->{payments_changeable} == 0) {
+ # never
+ $changeable = ($form->{"acc_trans_id_$i"})? 0 : 1;
+ }
+ if ($::lx_office_conf{features}->{payments_changeable} == 2) {
+ # on the same day
+ $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"});
}
- $form->{"exchangerate_$i"} =
- $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
$exchangerate = qq| |;
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
if ($form->{"forex_$i"}) {
$exchangerate =
qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
} else {
- $exchangerate =
- qq|{"exchangerate_$i"}>|;
+ if ($changeable) {
+ $exchangerate =
+ qq|{"exchangerate_$i"}>|;
+ } else {
+ $exchangerate =
+ qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+ }
}
}
@@ -669,31 +726,98 @@ $jsscript
{"forex_$i"}>
|;
- $column_data{"paid_$i"} =
- qq|{"paid_$i"}> | |;
- $column_data{"AP_paid_$i"} =
- qq| | |;
- $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
- $column_data{"datepaid_$i"} =
- qq|{"datepaid_$i"}>
- | |;
- $column_data{"source_$i"} =
- qq| | |;
- $column_data{"memo_$i"} =
- qq| | |;
+ my $datepaid;
+ if ($changeable) {
+ $datepaid = qq|
+ | |;
+ } else {
+ $datepaid = qq|$form->{"datepaid_$i"} | |.
+ qq|{"datepaid_$i"}>|;
+ }
+
+ my $paid;
+ if ($changeable) {
+ $paid = qq| | |;
+ } else {
+ $paid = qq|$form->{"paid_$i"} | |.
+ qq|{"paid_$i"}>|;
+ }
+
+ my $source;
+ if ($changeable) {
+ $source = qq| | |;
+ } else {
+ $source = qq|$form->{"source_$i"} | |.
+ qq|{"source_$i"}>|;
+ }
+
+ my $memo;
+ if ($changeable) {
+ $memo = qq| | |;
+ } else {
+ $memo = qq|$form->{"memo_$i"} | |.
+ qq|{"memo_$i"}>|;
+ }
+
+ my $AP_paid;
+ if ($changeable) {
+ $AP_paid = qq|${selectAP_paid} | |;
+ } else {
+ $AP_paid = qq|$form->{"AP_paid_$i"} | |.
+ qq|{"AP_paid_$i"}>|;
+ }
+
+ my $paid_project_id;
+ if ($changeable) {
+ $paid_project_id =
+ qq||
+ . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
+ '-values' => \@project_values,
+ '-labels' => \%project_labels,
+ '-default' => $form->{"paid_project_id_$i"} ))
+ . qq| | |;
+ } else {
+ my $projectnumber = $project_labels{$form->{"paid_project_id_$i"}};
+ $paid_project_id = qq|$projectnumber | |.
+ qq|{"paid_project_id_$i"}>|;
+ }
+
+ $column_data{"paid_$i"} = $paid;
+ $column_data{"AP_paid_$i"} = $AP_paid;
+ $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
+ $column_data{"datepaid_$i"} = $datepaid;
+ $column_data{"source_$i"} = $source;
+ $column_data{"memo_$i"} = $memo;
+ $column_data{"paid_project_id_$i"} = $paid_project_id;
map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
print "
";
- push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
+ if ($changeable) {
+ push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
+ }
}
- map { $form->{$_} =~ s/\"/"/g } qw(selectAP_paid);
- print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
+
+ my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
+
+ print qq|
+
+ |
+ |
+ | . $locale->text('Total') . qq| |
+ | . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq| |
+
+
+ |
+ |
+ | . $locale->text('Missing amount') . qq| |
+ | . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq| |
+
+| . $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
qq|
{paidaccounts}>
-
|
@@ -704,53 +828,86 @@ $jsscript
|;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub form_footer {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+ my $cgi = $::request->{cgi};
+
+ $main::auth->assert('general_ledger');
+
+ my $follow_ups_block;
+ if ($form->{id}) {
+ my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
+
+ if (@{ $follow_ups} ) {
+ my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
+ $follow_ups_block = qq|| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|
|;
+ }
+ }
print qq|
-