X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=528d2c4edd6fde7a09d05bb1a46d3ec8366ac5c7;hb=875873f10da35c4359e4bc994e709c247aab905e;hp=667c7b3b7a56efc28b54d8955bb8c0f39689c91d;hpb=f36eb9fca78c4940b486b7dafa4ab636cdaf99cd;p=kivitendo-erp.git
diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl
index 667c7b3b7..528d2c4ed 100644
--- a/bin/mozilla/ar.pl
+++ b/bin/mozilla/ar.pl
@@ -31,14 +31,25 @@
#
#======================================================================
+use POSIX qw(strftime);
+use List::Util qw(sum first);
+
use SL::AR;
+use SL::FU;
use SL::IS;
use SL::PE;
-use Data::Dumper;
+use SL::ReportGenerator;
+
+# use strict;
+#use warnings;
+
+# imports
+our ($cgi, $form, $lxdebug, $locale, %myconfig);
require "bin/mozilla/arap.pl";
require "bin/mozilla/common.pl";
require "bin/mozilla/drafts.pl";
+require "bin/mozilla/reportgenerator.pl";
1;
@@ -75,6 +86,8 @@ require "bin/mozilla/drafts.pl";
sub add {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
return $lxdebug->leave_sub() if (load_draft_maybe());
# saving the history
@@ -86,9 +99,7 @@ sub add {
# /saving the history
$form->{title} = "Add";
- $form->{callback} =
- "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
- unless $form->{callback};
+ $form->{callback} = "ar.pl?action=add" unless $form->{callback};
AR->get_transdate(\%myconfig, $form);
$form->{initial_transdate} = $form->{transdate};
@@ -100,6 +111,9 @@ sub add {
sub edit {
$lxdebug->enter_sub();
+
+ $auth->assert('general_ledger');
+
# show history button
$form->{javascript} = qq||;
#/show hhistory button
@@ -115,6 +129,8 @@ sub edit {
sub display_form {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
&form_header;
&form_footer;
@@ -124,6 +140,10 @@ sub display_form {
sub create_links {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
+ my ($duedate, $taxincluded, @curr);
+
$form->create_links("AR", \%myconfig, "customer");
$duedate = $form->{duedate};
@@ -189,6 +209,15 @@ sub create_links {
sub form_header {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
+ my ($title, $readonly, $exchangerate, $rows);
+ my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
+ my ($jsscript, $button1, $button2, $onload);
+ my ($selectAR_amount, $selectAR_paid, $ARselected, $tax);
+ my (@column_index, %column_data);
+
+
$title = $form->{title};
$form->{title} = $locale->text("$title Accounts Receivables Transaction");
@@ -226,16 +255,23 @@ sub form_header {
$readonly = ($form->{radier}) ? "" : $readonly;
# set option selected
- foreach $item (qw(customer currency department employee)) {
+ foreach my $item (qw(customer currency department employee)) {
$form->{"select$item"} =~ s/ selected//;
$form->{"select$item"} =~
s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
}
+ $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
+
# format amounts
$form->{exchangerate} =
$form->format_amount(\%myconfig, $form->{exchangerate});
+ if ($form->{exchangerate} == 0) {
+ $form->{exchangerate} = "";
+ }
+
$form->{creditlimit} =
$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
$form->{creditremaining} =
@@ -280,13 +316,10 @@ sub form_header {
| if $form->{selectdepartment};
- $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
+ my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
- $customer =
- ($form->{selectcustomer})
- ? qq||
+ $customer = ($form->{selectcustomer})
+ ? qq||
: qq||;
$employee = qq|
@@ -307,12 +340,13 @@ selectcustomer}|
map({ push(@old_project_ids, $form->{"project_id_$_"})
if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
- $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 0,
- "old_id" => \@old_project_ids },
- "charts" => { "key" => "ALL_CHARTS",
- "transdate" => $form->{transdate} },
- "taxcharts" => "ALL_TAXCHARTS");
+ $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" },);
map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
@{ $form->{ALL_CHARTS} });
@@ -395,9 +429,14 @@ selectcustomer}|
qq|
| |;
}
+ 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|| .
+ qq||;
$form->header;
$onload = qq|focus()|;
@@ -413,6 +452,10 @@ selectcustomer}|
{closedto}>
{locked}>
+
+
+
+
| . ($form->{saved_message} ? qq|$form->{saved_message}
| : "") . qq|
@@ -429,7 +472,7 @@ selectcustomer}|
| . $locale->text('Customer') . qq| |
- $customer |
+ $customer |
@@ -502,8 +545,6 @@ $jsscript
|
. $locale->text('Tax') . qq| |
|
- . $locale->text('Korrektur') . qq| |
- |
. $locale->text('Taxkey') . qq| |
|
. $locale->text('Project') . qq| |
@@ -513,7 +554,7 @@ $jsscript
$amount = $locale->text('Amount');
$project = $locale->text('Project');
- for $i (1 .. $form->{rowcount}) {
+ for my $i (1 .. $form->{rowcount}) {
# format amounts
$form->{"amount_$i"} =
@@ -536,7 +577,13 @@ $jsscript
$selected_taxchart = "$item->{id}--$item->{rate}";
}
- $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$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 {
+ $selected_taxchart = $taxchart_init;
+ }
+ }
$selectAR_amount =
NTI($cgi->popup_menu('-name' => "AR_amount_$i",
@@ -558,8 +605,6 @@ $jsscript
'-default' => $selected_taxchart))
. qq||;
- $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
-
my $projectnumber =
NTI($cgi->popup_menu('-name' => "project_id_$i",
'-values' => \@project_values,
@@ -570,8 +615,7 @@ $jsscript
$selectAR_amount |
{"amount_$i"}> |
- {"tax_$i"}> |
- |
+ $form->{"tax_$i"} |
$tax
$projectnumber |
@@ -656,7 +700,7 @@ $jsscript
my $totalpaid = 0;
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
+ for my $i (1 .. $form->{paidaccounts}) {
print "
";
@@ -678,6 +722,10 @@ $jsscript
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
+ if ($form->{"exchangerate_$i"} == 0) {
+ $form->{"exchangerate_$i"} = "";
+ }
+
$exchangerate = qq| |;
if ($form->{currency} ne $form->{defaultcurrency}) {
if ($form->{"forex_$i"}) {
@@ -756,14 +804,27 @@ $jsscript
sub form_footer {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
+ my ($transdate, $closedto);
+
+ 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|
+$follow_ups_block
+
-
-{login}>
-{password}>
|
. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
@@ -784,11 +845,12 @@ sub form_footer {
$transdate = $form->datetonum($form->{transdate}, \%myconfig);
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
+ print qq|\n|;
+
# 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, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && !$form->{paid_1});
+ print qq| |
+ if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($total_paid == 0) || ($total_paid eq "")));
- print qq|\n|;
if ($form->{id}) {
if ($form->{radier}) {
print qq|
@@ -800,11 +862,14 @@ sub form_footer {
|;
}
print qq|
- |;
+
+ |;
} else {
if ($transdate > $closedto) {
- print qq| | .
+ print qq| | .
NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
}
}
@@ -815,9 +880,16 @@ sub form_footer {
}
# button for saving history
if($form->{id} ne "") {
- print qq|{id}); name=history id=history value=| . $locale->text('history') . qq|>|;
+ print qq| {id}); name=history id=history value=| . $locale->text('history') . qq|> |;
}
# /button for saving history
+ # mark_as_paid button
+ if($form->{id} ne "") {
+ print qq||;
+ }
+ # /mark_as_paid button
+
print "
@@ -828,38 +900,51 @@ sub form_footer {
$lxdebug->leave_sub();
}
+sub mark_as_paid {
+ $lxdebug->enter_sub();
+
+ $auth->assert('general_ledger');
+
+ &mark_as_paid_common(\%myconfig,"ar");
+
+ $lxdebug->leave_sub();
+}
+
sub update {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
my $display = shift;
+ my ($totaltax, $exchangerate, $totalpaid);
+
$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 AR_amount projectnumber oldprojectnumber project_id);
- $count = 0;
- @a = ();
+ my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
+ my $count = 0;
+ my @a = ();
- for $i (1 .. $form->{rowcount}) {
- $form->{"amount_$i"} =
- $form->parse_amount(\%myconfig, $form->{"amount_$i"});
+ 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 $j = $#a;
+ 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);
@@ -873,23 +958,28 @@ sub update {
$form->{rowcount} = $count + 1;
map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
- $form->{exchangerate} = $exchangerate
- if (
- $form->{forex} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
- )));
+ $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
$form->{invdate} = $form->{transdate};
- $save_AR = $form->{AR};
- &check_name(customer);
- $form->{AR} = $save_AR;
+
+ $form->{invdate} = $form->{transdate};
+
+ my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1);
+
+ &check_name("customer");
+
+ $form->{AR} = $saved_variables{AR};
+ if ($saved_variables{AR_amount_1} =~ m/.--./) {
+ map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
+ } else {
+ delete $form->{taxchart_1};
+ }
$form->{invtotal} =
($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
- for $i (1 .. $form->{paidaccounts}) {
+ for my $i (1 .. $form->{paidaccounts}) {
if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
map {
$form->{"${_}_$i"} =
@@ -898,13 +988,8 @@ sub update {
$totalpaid += $form->{"paid_$i"};
- $form->{"exchangerate_$i"} = $exchangerate
- if (
- $form->{"forex_$i"} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
- )));
+ $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
+ $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
}
}
@@ -919,47 +1004,65 @@ sub update {
$lxdebug->leave_sub();
}
+#
+# ToDO: fix $closedto and $invdate
+#
sub post_payment {
$lxdebug->enter_sub();
- for $i (1 .. $form->{paidaccounts}) {
+
+ $auth->assert('general_ledger');
+
+ $form->{defaultcurrency} = $form->get_default_currency(\%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 ($datepaid <= $closedto);
+ $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}) {
- $form->{"exchangerate_$i"} = $form->{exchangerate}
- if ($invdate == $datepaid);
- $form->isblank("exchangerate_$i",
- $locale->text('Exchangerate for payment missing!'));
+# $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
+ $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
}
}
}
($form->{AR}) = split /--/, $form->{AR};
($form->{AR_paid}) = split /--/, $form->{AR_paid};
- $form->redirect($locale->text('Payment posted!'))
- if (AR->post_payment(\%myconfig, \%$form));
- $form->error($locale->text('Cannot post payment!'));
-
+ $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
+ $form->error($locale->text('Cannot post payment!'));
$lxdebug->leave_sub();
}
+sub _post {
+
+ $auth->assert('general_ledger');
+
+ # inline post
+ post(1);
+}
+
sub post {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
+ my ($inline) = @_;
+
+ my ($datepaid);
+
# check if there is an invoice number, invoice and due date
$form->isblank("transdate", $locale->text('Invoice Date missing!'));
$form->isblank("duedate", $locale->text('Due Date missing!'));
$form->isblank("customer", $locale->text('Customer missing!'));
- $closedto = $form->datetonum($form->{closedto}, \%myconfig);
- $transdate = $form->datetonum($form->{transdate}, \%myconfig);
- $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
+ 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));
$form->error($locale->text('Zero amount posting!'))
unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
@@ -969,14 +1072,14 @@ sub post {
delete($form->{AR});
- 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);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
$form->error($locale->text('Cannot post payment for a closed period!'))
- if ($datepaid <= $closedto);
+ if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
if ($form->{currency} ne $form->{defaultcurrency}) {
$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
@@ -986,27 +1089,29 @@ sub post {
}
# if oldcustomer ne customer redo form
- ($customer) = split /--/, $form->{customer};
+ my ($customer) = split /--/, $form->{customer};
if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
- &update;
+ update();
exit;
}
$form->{AR}{receivables} = $form->{ARselected};
+ $form->{storno} = 0;
+ $lxdebug->message(0, $form->{amount});
$form->{id} = 0 if $form->{postasnew};
- if (AR->post_transaction(\%myconfig, \%$form)) {
- # saving the history
- if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumbers} = "invnumber_$form->{invnumber}";
- $form->{addition} = "POSTED";
- $form->save_history($form->dbconnect(\%myconfig));
- }
- # /saving the history
- remove_draft() if $form->{remove_draft};
- $form->redirect($locale->text('Transaction posted!'));
+ $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
+
+ # saving the history
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ $form->{snumbers} = "invnumber_$form->{invnumber}";
+ $form->{addition} = "POSTED";
+ $form->save_history($form->dbconnect(\%myconfig));
}
- $form->error($locale->text('Cannot post transaction!'));
+ # /saving the history
+ remove_draft() if $form->{remove_draft};
+
+ $form->redirect($locale->text('Transaction posted!')) unless $inline;
$lxdebug->leave_sub();
}
@@ -1014,6 +1119,8 @@ sub post {
sub post_as_new {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
$form->{postasnew} = 1;
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
@@ -1030,6 +1137,8 @@ sub post_as_new {
sub use_as_template {
$lxdebug->enter_sub();
+ $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;
$form->{rowcount}--;
@@ -1042,6 +1151,8 @@ sub use_as_template {
sub delete {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
$form->{title} = $locale->text('Confirm!');
$form->header;
@@ -1054,7 +1165,8 @@ sub delete {