-
-
-
- |
- . $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 +544,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 +555,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 +571,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 +591,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,52 +603,54 @@ $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') . " | ";
$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') . " | ";
+ $column_data{paid_project_id} = "" . $locale->text('Project Number') . " | ";
print "
@@ -652,12 +664,12 @@ $jsscript
my $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,
@@ -678,7 +690,7 @@ $jsscript
}
$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"}|;
@@ -699,7 +711,7 @@ $jsscript
$column_data{"exchangerate_$i"} = qq|$exchangerate | |;
$column_data{"datepaid_$i"} =
qq|
- | |;
+ |;
$column_data{"source_$i"} =
qq| | |;
$column_data{"memo_$i"} =
@@ -748,13 +760,18 @@ $jsscript
|;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub form_footer {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+ my $cgi = $main::cgi;
+
+ $main::auth->assert('general_ledger');
my $follow_ups_block;
if ($form->{id}) {
@@ -789,8 +806,8 @@ $follow_ups_block
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||;
@@ -800,10 +817,10 @@ $follow_ups_block
|;
}
-
# ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
+ our $total_paid;
print qq| |
- if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}));
+ if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($total_paid == 0) || ($total_paid eq "")));
print qq|
@@ -819,8 +836,8 @@ $follow_ups_block
print qq| |;
}
# /button for saving history
- # mark_as_paid button
- if($form->{id} ne "") {
+ # mark_as_paid button
+ if($form->{id} ne "") {
print qq| |;
}
# /mark_as_paid button
@@ -831,41 +848,50 @@ $follow_ups_block
";
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub mark_as_paid {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
- $auth->assert('general_ledger');
+ $main::auth->assert('general_ledger');
- &mark_as_paid_common(\%myconfig,"ap");
+ &mark_as_paid_common(\%myconfig,"ap");
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub update {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('general_ledger');
my $display = shift;
$form->{invtotal} = 0;
+ delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
+
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
qw(exchangerate creditlimit creditremaining);
- @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id);
- $count = 0;
- for $i (1 .. $form->{rowcount}) {
+ my @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id taxchart);
+ my $count = 0;
+ my (@a, $j, $totaltax);
+ for my $i (1 .. $form->{rowcount}) {
$form->{"amount_$i"} =
$form->parse_amount(\%myconfig, $form->{"amount_$i"});
$form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
if ($form->{"amount_$i"}) {
push @a, {};
$j = $#a;
- ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+ my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
if ($taxkey > 1) {
if ($form->{taxincluded}) {
$form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
@@ -890,16 +916,24 @@ sub update {
$form->{exchangerate} = $form->{forex} if $form->{forex};
$form->{invdate} = $form->{transdate};
- $save_AP = $form->{AP};
- &check_name("vendor");
- $form->{AP} = $save_AP;
+ my %saved_variables = map +( $_ => $form->{$_} ), qw(AP AP_amount_1 taxchart_1);
+
+ my $vendor_changed = &check_name("vendor");
+
+ $form->{AP} = $saved_variables{AP};
+ if ($saved_variables{AP_amount_1} =~ m/.--./) {
+ map { $form->{$_} = $saved_variables{$_} } qw(AP_amount_1 taxchart_1);
+ } else {
+ delete $form->{taxchart_1};
+ }
$form->{rowcount} = $count + 1;
$form->{invtotal} =
($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
- for $i (1 .. $form->{paidaccounts}) {
+ my $totalpaid;
+ for my $i (1 .. $form->{paidaccounts}) {
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
map {
$form->{"${_}_$i"} =
@@ -920,31 +954,36 @@ sub update {
$form->{oldtotalpaid} = $totalpaid;
# notes
- $form->{notes} = $form->{intnotes};
+ $form->{notes} = $form->{intnotes} if $vendor_changed;
&display_form;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub post_payment {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
- $auth->assert('general_ledger');
+ $main::auth->assert('general_ledger');
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- for $i (1 .. $form->{paidaccounts}) {
+ our $invdate;
+ for my $i (1 .. $form->{paidaccounts}) {
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
- $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+ my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
$form->error($locale->text('Cannot post payment for a closed period!'))
if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
$form->{"exchangerate_$i"} = $form->{exchangerate}
if ($invdate == $datepaid);
$form->isblank("exchangerate_$i",
@@ -960,26 +999,30 @@ sub post_payment {
$form->error($locale->text('Cannot post payment!'));
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub post {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('general_ledger');
# check if there is a vendor, invoice and due date
$form->isblank("transdate", $locale->text("Invoice Date missing!"));
$form->isblank("duedate", $locale->text("Due Date missing!"));
$form->isblank("vendor", $locale->text('Vendor missing!'));
- $closedto = $form->datetonum($form->{closedto}, \%myconfig);
- $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+ my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+ my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
$form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
my $zero_amount_posting = 1;
- for $i (1 .. $form->{rowcount}) {
+ for my $i (1 .. $form->{rowcount}) {
if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
$zero_amount_posting = 0;
last;
@@ -989,19 +1032,19 @@ sub post {
$form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
- if ($form->{currency} ne $form->{defaultcurrency});
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
delete($form->{AP});
- for $i (1 .. $form->{paidaccounts}) {
+ for my $i (1 .. $form->{paidaccounts}) {
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
- $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+ my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
$form->error($locale->text('Cannot post payment for a closed period!'))
if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
- if ($form->{currency} ne $form->{defaultcurrency}) {
+ if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
$form->{"exchangerate_$i"} = $form->{exchangerate}
if ($transdate == $datepaid);
$form->isblank("exchangerate_$i",
@@ -1012,16 +1055,16 @@ sub post {
}
# if old vendor ne vendor redo form
- ($vendor) = split /--/, $form->{vendor};
+ my ($vendor) = split /--/, $form->{vendor};
if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
&update;
exit;
}
- ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
- ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
- ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
- $form->{AP}{amount_1} = $debitaccno;
- $form->{AP}{payables} = $payablesaccno;
+ my ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
+ my ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
+ my ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
+# $form->{AP_amount_1} = $debitaccno;
+ $form->{AP_payables} = $payablesaccno;
$form->{taxkey} = $taxkey;
$form->{storno} = 0;
@@ -1034,37 +1077,45 @@ sub post {
$form->{addition} = "POSTED";
$form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
remove_draft() if $form->{remove_draft};
+ # Dieser Text wird niemals ausgegeben: Probleme beim redirect?
$form->redirect($locale->text('Transaction posted!'));
+ } else {
+ $form->error($locale->text('Cannot post transaction!'));
}
- $form->error($locale->text('Cannot post transaction!'));
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub post_as_new {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('general_ledger');
$form->{postasnew} = 1;
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
$form->{snumbers} = qq|invnumber_| . $form->{invnumber};
- $form->{addition} = "POSTED AS NEW";
- $form->save_history($form->dbconnect(\%myconfig));
+ $form->{addition} = "POSTED AS NEW";
+ $form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
&post;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub use_as_template {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('general_ledger');
map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
$form->{paidaccounts} = 1;
@@ -1072,13 +1123,16 @@ sub use_as_template {
$form->{invdate} = $form->current_date(\%myconfig);
&update;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub delete {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
- $auth->assert('general_ledger');
+ $main::auth->assert('general_ledger');
$form->{title} = $locale->text('Confirm!');
@@ -1092,7 +1146,7 @@ sub delete {
|