X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=305b6aaade5245bac75ae6ea1e70ad5abea8ea1e;hb=29fbefec2d08f8030848f09d249fc269ea877359;hp=8a01c195902e21265897b2c70d622632de5355d3;hpb=d5c1e4fa391f26fc0acd568729a98493edf319d8;p=kivitendo-erp.git
diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl
index 8a01c1959..305b6aaad 100644
--- a/bin/mozilla/ar.pl
+++ b/bin/mozilla/ar.pl
@@ -31,14 +31,23 @@
#
#======================================================================
+use POSIX qw(strftime);
+
use SL::AR;
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;
@@ -124,6 +133,8 @@ sub display_form {
sub create_links {
$lxdebug->enter_sub();
+ my ($duedate, $taxincluded, @curr);
+
$form->create_links("AR", \%myconfig, "customer");
$duedate = $form->{duedate};
@@ -177,112 +188,7 @@ sub create_links {
# build the popup menus
$form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
- # forex
- $form->{forex} = $form->{exchangerate};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
- foreach $key (keys %{ $form->{AR_links} }) {
- # if there is a value we have an old entry
- my $j = 0;
- my $k = 0;
-
- for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
- if ($key eq "AR_paid") {
- $j++;
- $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno};
-
- # reverse paid
- $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
- $form->{"datepaid_$j"} =
- $form->{acc_trans}{$key}->[$i - 1]->{transdate};
- $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
- $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
-
- $form->{"forex_$j"} = $form->{"exchangerate_$i"} =
- $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
- $form->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id};
- $form->{paidaccounts}++;
-
- } else {
-
- $akey = $key;
- $akey =~ s/AR_//;
-
- if ($key eq "AR_tax" || $key eq "AP_tax") {
- $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
- "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} =
- $form->round_amount(
- $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
- 2);
-
- if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) {
- $totaltax +=
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
- $taxrate +=
- $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
- } else {
- $totalwithholding +=
- $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"};
- $withholdingrate +=
- $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"};
- }
- $index = $form->{acc_trans}{$key}->[$i - 1]->{index};
- $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
- $totaltax += $form->{"tax_$index"};
-
- } else {
- $k++;
- $form->{"${akey}_$k"} =
- $form->round_amount(
- $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate,
- 2);
- if ($akey eq 'amount') {
- $form->{rowcount}++;
- $totalamount += $form->{"${akey}_$i"};
-
- $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} =
- "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}";
- $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate};
- $form->{"project_id_$k"} =
- "$form->{acc_trans}{$key}->[$i-1]->{project_id}";
- }
- $form->{"${key}_$i"} =
- "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
-
- if ($akey eq "AR") {
- $form->{ARselected} = $form->{acc_trans}{$key}->[$i-1]->{accno};
-
- } elsif ($akey eq "amount") {
- $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} .
- "--" . $form->{acc_trans}{$key}->[$i-1]->{id};
- $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} .
- "--" . $form->{acc_trans}{$key}->[$i-1]->{rate};
- }
- }
- }
- }
- }
-
- $form->{taxincluded} = $taxincluded if ($form->{id});
- $form->{paidaccounts} = 1 if not defined $form->{paidaccounts};
-
- if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
-
- # add tax to amounts and invtotal
- for $i (1 .. $form->{rowcount}) {
- $taxamount =
- ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
- $tax = $form->round_amount($taxamount, 2);
- $diff += ($taxamount - $tax);
- $form->{"amount_$i"} += $form->{"tax_$i"};
- }
- $form->{amount_1} += $form->round_amount($diff, 2);
- }
-
- $taxamount = $form->round_amount($taxamount, 2);
- $form->{tax} = $taxamount;
-
- $form->{invtotal} = $totalamount + $totaltax;
+ AR->setup_form($form);
$form->{locked} =
($form->datetonum($form->{transdate}, \%myconfig) <=
@@ -294,6 +200,13 @@ sub create_links {
sub form_header {
$lxdebug->enter_sub();
+ my ($title, $readonly, $exchangerate, $rows);
+ my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
+ my ($jsscript, $button1, $button2, $onload);
+ my ($selectAR_amount, $selectAR_paid, $korrektur_checked, $ARselected, $tax);
+ my (@column_index, %column_data);
+
+
$title = $form->{title};
$form->{title} = $locale->text("$title Accounts Receivables Transaction");
@@ -331,16 +244,28 @@ 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->{exchangerate} = $exchangerate
+ if (
+ $form->{forex} = (
+ $exchangerate =
+ $form->check_exchangerate(
+ \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
+ )));
+
# 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} =
@@ -385,13 +310,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|
@@ -618,7 +540,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"} =
@@ -685,6 +607,7 @@ $jsscript
$project = "";
}
+ $form->{invtotal_unformatted} = $form->{invtotal};
$form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
$ARselected =
@@ -756,9 +679,11 @@ $jsscript
";
- my @triggers = ();
+ my @triggers = ();
+ my $totalpaid = 0;
+
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
- for $i (1 .. $form->{paidaccounts}) {
+ for my $i (1 .. $form->{paidaccounts}) {
print "
";
@@ -770,6 +695,8 @@ $jsscript
'-labels' => \%AR_paid_labels,
'-default' => $form->{"AR_paid_$i"}));
+ $totalpaid += $form->{"paid_$i"};
+
# format amounts
if ($form->{"paid_$i"}) {
$form->{"paid_$i"} =
@@ -778,6 +705,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"}) {
@@ -822,7 +753,22 @@ $jsscript
push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
}
- print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
+ my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
+
+ print qq|
+
+ |
+ |
+ | . $locale->text('Total') . qq| |
+ | . H($form->format_amount(\%myconfig, $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}>
@@ -841,6 +787,8 @@ $jsscript
sub form_footer {
$lxdebug->enter_sub();
+ my ($transdate, $closedto);
+
print qq|
@@ -869,11 +817,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'));
- print qq|\n|;
if ($form->{id}) {
if ($form->{radier}) {
print qq|
@@ -889,7 +838,7 @@ sub form_footer {
} else {
if ($transdate > $closedto) {
- print qq| | .
+ print qq| | .
NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
}
}
@@ -900,9 +849,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 "
@@ -913,29 +869,36 @@ sub form_footer {
$lxdebug->leave_sub();
}
+sub mark_as_paid {
+ $lxdebug->enter_sub();
+ &mark_as_paid_common(\%myconfig,"ar");
+ $lxdebug->leave_sub();
+}
+
sub update {
$lxdebug->enter_sub();
my $display = shift;
+ my ($totaltax, $exchangerate, $totalpaid);
+
$form->{invtotal} = 0;
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;
+ my $j = $#a;
if (!$form->{"korrektur_$i"}) {
- ($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;
@@ -967,14 +930,14 @@ sub update {
)));
$form->{invdate} = $form->{transdate};
- $save_AR = $form->{AR};
- &check_name(customer);
+ my $save_AR = $form->{AR};
+ check_name("customer");
$form->{AR} = $save_AR;
$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"} =
@@ -1004,46 +967,57 @@ sub update {
$lxdebug->leave_sub();
}
+#
+# ToDO: fix $closedto and $invdate
+#
sub post_payment {
$lxdebug->enter_sub();
- for $i (1 .. $form->{paidaccounts}) {
+
+ $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 ($datepaid <= $closedto);
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 {
+ # inline post
+ post(1);
+}
+
sub post {
$lxdebug->enter_sub();
+ 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);
+ 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 ($transdate <= $closedto);
$form->error($locale->text('Zero amount posting!'))
@@ -1054,7 +1028,7 @@ 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);
@@ -1071,27 +1045,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();
}
@@ -1139,7 +1115,7 @@ sub delete {