-
-
-
- |
- . $locale->text('Account') . qq| |
- |
- . $locale->text('Amount') . qq| |
- |
- . $locale->text('Tax') . 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"} =
@@ -534,7 +547,7 @@ $jsscript
$selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
- $selectAP_amount =
+ my $selectAP_amount =
NTI($cgi->popup_menu('-name' => "AP_amount_$i",
'-id' => "AP_amount_$i",
'-style' => 'width:400px',
@@ -545,7 +558,7 @@ $jsscript
. $cgi->hidden('-name' => "previous_AP_amount_$i",
'-default' => $selected_accno_full);
- $tax = qq|| .
+ my $tax = qq| | | .
NTI($cgi->popup_menu('-name' => "taxchart_$i",
'-id' => "taxchart_$i",
'-style' => 'width:200px',
@@ -561,19 +574,19 @@ $jsscript
'-default' => $form->{"project_id_$i"} ));
print qq|
- |
+
$selectAP_amount |
{"amount_$i"}> |
$form->{"tax_$i"} |
$tax
$projectnumber |
-
+
|;
$amount = "";
$project = "";
}
- $taxlabel =
+ my $taxlabel =
($form->{taxincluded})
? $locale->text('Tax Included')
: $locale->text('Tax');
@@ -581,7 +594,7 @@ $jsscript
$form->{invtotal_unformatted} = $form->{invtotal};
$form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
- $APselected =
+ my $APselected =
NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
'-style' => 'width:400px',
'-values' => \@AP_values, '-labels' => \%AP_labels,
@@ -593,45 +606,47 @@ $jsscript
- ${APselected} |
- $form->{invtotal} |
+ ${APselected} |
+ $form->{invtotal} |
- {oldinvtotal}>
- {oldtotalpaid}>
+ {oldinvtotal}>
+ {oldtotalpaid}>
-
+
- |
+ |
-
- |
+
+ |
-
- | . $locale->text('Payments') . qq| |
-
+
+ | . $locale->text('Payments') . qq| |
+
|;
- if ($form->{currency} eq $form->{defaultcurrency}) {
+ 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 paid_project_id);
}
+ my %column_data;
$column_data{datepaid} = "" . $locale->text('Date') . " | ";
$column_data{paid} = "" . $locale->text('Amount') . " | ";
$column_data{exchangerate} = "" . $locale->text('Exch') . " | ";
@@ -649,42 +664,60 @@ $jsscript
";
my @triggers = ();
- my $totalpaid = 0;
+ $form->{totalpaid} = 0;
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
+ for my $i (1 .. $form->{paidaccounts}) {
print "
";
- $selectAP_paid =
+ 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"}));
- $totalpaid += $form->{"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);
}
- $form->{"exchangerate_$i"} =
- $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
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 (SL::DB::Default->get->payments_changeable == 0) {
+ # never
+ $changeable = ($form->{"acc_trans_id_$i"})? 0 : 1;
+ }
+ if (SL::DB::Default->get->payments_changeable == 2) {
+ # on the same day
+ $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$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"}|;
+ }
}
}
@@ -692,42 +725,88 @@ $jsscript
{"forex_$i"}>
|;
- $column_data{"paid_$i"} =
- qq| | |;
- $column_data{"AP_paid_$i"} =
- qq|${selectAP_paid} | |;
- $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
- $column_data{"datepaid_$i"} =
- qq|
+ my $datepaid;
+ if ($changeable) {
+ $datepaid = qq| |
| |;
- $column_data{"source_$i"} =
- qq| | |;
- $column_data{"memo_$i"} =
- qq| | |;
- $column_data{"paid_project_id_$i"} =
+ } 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");
+ }
}
- my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
+ my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
print qq|
|
|
| . $locale->text('Total') . qq| |
- | . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq| |
+ | . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq| |
|
@@ -748,105 +827,63 @@ $jsscript
|;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub form_footer {
- $lxdebug->enter_sub();
-
- $auth->assert('general_ledger');
+ $::lxdebug->enter_sub;
+ $::auth->assert('general_ledger');
- my $follow_ups_block;
- if ($form->{id}) {
- my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
+ my $num_due;
+ my $num_follow_ups;
+ 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| |;
+ if (@{ $follow_ups }) {
+ $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
+ $num_follow_ups = scalar @{ $follow_ups }
}
}
- print qq|
-
-$follow_ups_block
-
-
-
-|
-. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
-. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
-. qq|
-
-
-|;
-
- if (!$form->{id} && $form->{draft_id}) {
- print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
- '-value' => 1, '-checked' => $form->{remove_draft},
- '-label' => '')) .
- qq| |);
- }
-
- $transdate = $form->datetonum($form->{transdate}, \%myconfig);
- $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+ my $transdate = $::form->datetonum($::form->{transdate}, \%::myconfig);
+ my $closedto = $::form->datetonum($::form->{closedto}, \%::myconfig);
- print qq||;
+ my $storno = $::form->{id}
+ && !IS->has_storno(\%::myconfig, $::form, 'ap')
+ && !IS->is_storno( \%::myconfig, $::form, 'ap', $::form->{id})
+ && ($::form->{totalpaid} == 0 || $::form->{totalpaid} eq '');
- if ($form->{id}) {
- if ($form->{radier}) {
- print qq|
-
-|;
- }
- # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
- print qq| |
- if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($total_paid == 0) || ($total_paid eq "")));
+ $::form->header;
+ print $::form->parse_html_template('ap/form_footer', {
+ num_due => $num_due,
+ num_follow_ups => $num_follow_ups,
+ show_post_draft => ($transdate > $closedto) && !$::form->{id},
+ show_storno => $storno,
+ });
- print qq|
-
-
-|;
- } elsif (($transdate > $closedto) && !$form->{id}) {
- print qq|
- | .
- NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
- }
- # button for saving history
- if($form->{id} ne "") {
- print qq| |;
- }
- # /button for saving history
- # mark_as_paid button
- if($form->{id} ne "") {
- print qq| |;
- }
- # /mark_as_paid button
- print "
-
-
-
- |