X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fir.pl;h=6c9c8a87eb67e70ee1470326b3dc6fdbada67df1;hb=96d3ef850a6170a3cbada36eb7f375ef99efe373;hp=f4345c1fe1cf3dc549a6531fee8638aae2b47e7b;hpb=b6dc5623d93c1be1c54248d4512e80f495af2899;p=kivitendo-erp.git
diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl
index f4345c1fe..6c9c8a87e 100644
--- a/bin/mozilla/ir.pl
+++ b/bin/mozilla/ir.pl
@@ -31,10 +31,11 @@
#
#======================================================================
+use SL::FU;
use SL::IR;
use SL::IS;
use SL::PE;
-use List::Util qw(max);
+use List::Util qw(max sum);
require "bin/mozilla/io.pl";
require "bin/mozilla/invoice_io.pl";
@@ -49,6 +50,8 @@ require "bin/mozilla/drafts.pl";
sub add {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
return $lxdebug->leave_sub() if (load_draft_maybe());
$form->{title} = $locale->text('Add Vendor Invoice');
@@ -63,10 +66,12 @@ sub add {
sub edit {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
# show history button
$form->{javascript} = qq||;
#/show hhistory button
-
+
$form->{title} = $locale->text('Edit Vendor Invoice');
&invoice_links;
@@ -79,6 +84,8 @@ sub edit {
sub invoice_links {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
# create links
$form->{webdav} = $webdav;
$form->{jsscript} = 1;
@@ -109,7 +116,7 @@ sub invoice_links {
IR->get_vendor(\%myconfig, \%$form);
IR->retrieve_invoice(\%myconfig, \%$form);
$form->{cp_id} = $cp_id;
-
+
if ($payment_id) {
$form->{payment_id} = $payment_id;
}
@@ -182,6 +189,8 @@ sub invoice_links {
sub prepare_invoice {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
if ($form->{id}) {
map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
@@ -215,6 +224,10 @@ sub prepare_invoice {
sub form_header {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
+ push @{ $form->{AJAX} }, CGI::Ajax->new('set_duedate_vendor' => "$form->{script}?action=set_duedate_vendor");
+
# set option selected
foreach $item (qw(AP vendor currency department)) {
$form->{"select$item"} =~ s/ selected//;
@@ -280,7 +293,7 @@ sub form_header {
}
my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
'-default' => $form->{"globalproject_id"}));
-
+
%labels = ();
@values = ();
my $i = 0;
@@ -288,7 +301,7 @@ sub form_header {
push(@values, $item);
$labels{$item} = $item;
}
-
+
$form->{currency} = $form->{defaultcurrency} unless $form->{currency};
my $currencies;
if (scalar @values) {
@@ -334,7 +347,7 @@ sub form_header {
: (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
'-onChange' => 'document.getElementById(\'update_button\').click();',
'-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
-
+
|;
%labels = ();
@@ -378,21 +391,33 @@ sub form_header {
$jsscript = "";
$button1 = qq|
-
- text('button') . qq|> | \n|;
+
+
+
+ | \n|;
+
+#, 'old_duedate__'' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
$button2 = qq|
-
- text('button') . qq|> | \n|;
+
+
+ text('button') . qq|>
+ | \n|;
#write Trigger
$jsscript =
- Form->write_trigger(\%myconfig, "2",
+ Form->write_trigger(\%myconfig, "2",
"invdate", "BL", "trigger1",
"duedate", "BL", "trigger2");
+ my $follow_up_vc = $form->{vendor};
+ $follow_up_vc =~ s/--.*?//;
+ my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
+
$form->{javascript} .= qq||;
$form->{javascript} .= qq||;
$form->{javascript} .= qq||;
+ $form->{javascript} .= qq||;
$jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
@@ -402,13 +427,14 @@ sub form_header {
$onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
print qq|
-
-
sub mark_as_paid {
$lxdebug->enter_sub();
- &mark_as_paid_common(\%myconfig,"ap");
+
+ $auth->assert('vendor_invoice_edit');
+
+ &mark_as_paid_common(\%myconfig,"ap");
+
$lxdebug->leave_sub();
}
sub update {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
&check_name(vendor);
- $form->{exchangerate} = $exchangerate if
- $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
+ $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
for $i (1 .. $form->{paidaccounts}) {
next unless $form->{"paid_$i"};
map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
- $form->{"exchangerate_$i"} = $exchangerate if
- $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
+ $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
+ $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
}
$i = $form->{rowcount};
@@ -936,6 +988,8 @@ sub update {
sub storno {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
if ($form->{storno}) {
$form->error($locale->text('Cannot storno storno invoice!'));
}
@@ -952,15 +1006,15 @@ sub storno {
# Payments must not be recorded for the new storno invoice.
$form->{paidaccounts} = 0;
map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
-
+
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "CANCELED";
$form->save_history($form->dbconnect(\%myconfig));
}
# /saving the history
-
+
$form->{storno_id} = $form->{id};
$form->{storno} = 1;
$form->{id} = "";
@@ -975,6 +1029,8 @@ sub storno {
sub use_as_template {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
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}--;
@@ -987,6 +1043,8 @@ sub use_as_template {
sub post_payment {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
for $i (1 .. $form->{paidaccounts}) {
if ($form->{"paid_$i"}) {
@@ -995,7 +1053,7 @@ sub post_payment {
$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}
@@ -1029,10 +1087,13 @@ sub post_payment {
sub post {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- $form->isblank("invdate", $locale->text('Invoice Date missing!'));
- $form->isblank("vendor", $locale->text('Vendor missing!'));
+ $form->isblank("invdate", $locale->text('Invoice Date missing!'));
+ $form->isblank("vendor", $locale->text('Vendor missing!'));
+ $form->isblank("invnumber", $locale->text('Invnumber missing!'));
$form->{invnumber} =~ s/^\s*//g;
$form->{invnumber} =~ s/\s*$//g;
@@ -1049,7 +1110,7 @@ sub post {
$invdate = $form->datetonum($form->{invdate}, \%myconfig);
$form->error($locale->text('Cannot post invoice for a closed period!'))
- if ($invdate <= $closedto);
+ if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
if ($form->{currency} ne $form->{defaultcurrency});
@@ -1061,7 +1122,7 @@ sub post {
$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}
@@ -1074,7 +1135,7 @@ sub post {
($form->{AP}) = split /--/, $form->{AP};
($form->{AP_paid}) = split /--/, $form->{AP_paid};
- $form->{storno} = 0;
+ $form->{storno} ||= 0;
$form->{id} = 0 if $form->{postasnew};
@@ -1083,7 +1144,7 @@ sub post {
if (IR->post_invoice(\%myconfig, \%$form)){
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "POSTED";
#$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
$form->save_history($form->dbconnect(\%myconfig));
@@ -1102,6 +1163,8 @@ sub post {
sub delete {
$lxdebug->enter_sub();
+ $auth->assert('vendor_invoice_edit');
+
$form->header;
print qq|
@@ -1113,6 +1176,7 @@ sub delete {
map { delete $form->{$_} } qw(action header);
foreach $key (keys %$form) {
+ next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
$form->{$key} =~ s/\"/"/g;
print qq|\n|;
}
@@ -1134,17 +1198,30 @@ sub delete {
sub yes {
$lxdebug->enter_sub();
+
+ $auth->assert('vendor_invoice_edit');
+
if (IR->delete_invoice(\%myconfig, \%$form)) {
# saving the history
if(!exists $form->{addition}) {
- $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
$form->{addition} = "DELETED";
$form->save_history($form->dbconnect(\%myconfig));
}
- # /saving the history
+ # /saving the history
$form->redirect($locale->text('Invoice deleted!'));
}
$form->error($locale->text('Cannot delete invoice!'));
$lxdebug->leave_sub();
}
+
+sub set_duedate_vendor {
+ $lxdebug->enter_sub();
+
+ print $form->ajax_response_header(), IR->get_duedate('vendor_id' => $form->{vendor_id},
+ 'invdate' => $form->{invdate},
+ 'default' => $form->{old_duedate});
+
+ $lxdebug->leave_sub();
+}