-
-
-
- |
- . $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"} =
@@ -535,7 +548,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',
@@ -546,7 +559,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',
@@ -555,8 +568,6 @@ $jsscript
'-default' => $selected_taxchart))
. qq| | |;
- my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
-
my $projectnumber =
NTI($cgi->popup_menu('-name' => "project_id_$i",
'-values' => \@project_values,
@@ -564,20 +575,19 @@ $jsscript
'-default' => $form->{"project_id_$i"} ));
print qq|
-
+
$selectAP_amount |
{"amount_$i"}> |
- {"tax_$i"}> |
- |
+ $form->{"tax_$i"} |
$tax
$projectnumber |
-
+
|;
$amount = "";
$project = "";
}
- $taxlabel =
+ my $taxlabel =
($form->{taxincluded})
? $locale->text('Tax Included')
: $locale->text('Tax');
@@ -585,7 +595,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,
@@ -597,52 +607,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 "
@@ -653,42 +665,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 ($::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"});
}
$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"}|;
+ }
}
}
@@ -696,42 +726,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|
- | |;
- $column_data{"source_$i"} =
- qq| | |;
- $column_data{"memo_$i"} =
- qq| | |;
- $column_data{"paid_project_id_$i"} =
+ 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");
+ }
}
- 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| |
|
@@ -752,13 +828,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 = $::request->{cgi};
+
+ $main::auth->assert('general_ledger');
my $follow_ups_block;
if ($form->{id}) {
@@ -793,8 +874,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||;
@@ -804,10 +885,9 @@ $follow_ups_block
|;
}
-
# 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}));
+ if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq "")));
print qq|
@@ -823,8 +903,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
@@ -835,51 +915,58 @@ $follow_ups_block
";
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub mark_as_paid {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
- &mark_as_paid_common(\%myconfig,"ap");
+ $main::auth->assert('general_ledger');
- $lxdebug->leave_sub();
+ &mark_as_paid_common(\%myconfig,"ap");
+
+ $main::lxdebug->leave_sub();
}
sub update {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
- $auth->assert('general_ledger');
+ $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;
- if (!$form->{"korrektur_$i"}) {
- ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
- if ($taxkey > 1) {
- if ($form->{taxincluded}) {
- $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
- } else {
- $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
- }
+ my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+ if ($taxkey > 1) {
+ if ($form->{taxincluded}) {
+ $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
} else {
- $form->{"tax_$i"} = 0;
+ $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
}
+ } else {
+ $form->{"tax_$i"} = 0;
}
$form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
@@ -896,16 +983,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"} =
@@ -926,31 +1021,37 @@ 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();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('general_ledger');
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- for $i (1 .. $form->{paidaccounts}) {
+ my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
+
+ 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",
@@ -966,26 +1067,38 @@ 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();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
- $auth->assert('general_ledger');
+ $main::auth->assert('general_ledger');
+
+ my ($inline) = @_;
# 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);
+ if ($myconfig{mandatory_departments} && !$form->{department}) {
+ $form->{saved_message} = $::locale->text('You have to specify a department.');
+ update();
+ exit;
+ }
+
+ 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;
@@ -995,19 +1108,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",
@@ -1018,16 +1131,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;
+ ::end_of_request();
}
- ($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;
@@ -1038,53 +1151,64 @@ sub post {
if(!exists $form->{addition} && $form->{id} ne "") {
$form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "POSTED";
- $form->save_history($form->dbconnect(\%myconfig));
+ $form->save_history;
}
- # /saving the history
+ # /saving the history
remove_draft() if $form->{remove_draft};
- $form->redirect($locale->text('Transaction posted!'));
+ # Dieser Text wird niemals ausgegeben: Probleme beim redirect?
+ $form->redirect($locale->text('Transaction posted!')) unless $inline;
+ } 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();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
- $auth->assert('general_ledger');
+ $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;
}
- # /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();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
- $auth->assert('general_ledger');
+ $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);
+ map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
$form->{paidaccounts} = 1;
$form->{rowcount}--;
$form->{invdate} = $form->current_date(\%myconfig);
&update;
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
sub delete {
- $lxdebug->enter_sub();
+ $main::lxdebug->enter_sub();
- $auth->assert('general_ledger');
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ $main::auth->assert('general_ledger');
$form->{title} = $locale->text('Confirm!');
@@ -1098,7 +1222,7 @@ sub delete {
|