@@ -606,6 +730,7 @@ sub form_footer {
|;
+ my @triggers = ();
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
for $i (1 .. $form->{paidaccounts}) {
@@ -618,8 +743,10 @@ sub form_footer {
s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
# format amounts
- $form->{"paid_$i"} =
- $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ if ($form->{"paid_$i"}) {
+ $form->{"paid_$i"} =
+ $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ }
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
@@ -638,12 +765,13 @@ sub form_footer {
|;
$column_data{"paid_$i"} =
- qq|{"paid_$i"}> | |;
+ qq| | |;
$column_data{"exchangerate_$i"} = qq|$exchangerate | |;
$column_data{"AP_paid_$i"} =
qq| | |;
$column_data{"datepaid_$i"} =
- qq|{"datepaid_$i"}> | |;
+ qq|
+ | |;
$column_data{"source_$i"} =
qq|{"source_$i"}> | |;
$column_data{"memo_$i"} =
@@ -654,6 +782,7 @@ sub form_footer {
print qq|
|;
+ push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
}
print qq|
@@ -673,56 +802,53 @@ sub form_footer {
$invdate = $form->datetonum($form->{invdate}, \%myconfig);
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
+ print qq|
+|;
+
if ($form->{id}) {
+ my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
+
print qq|
+ . $locale->text('Post Payment') . qq|">
|;
-
- if (!$form->{revtrans}) {
- if (!$form->{locked}) {
- print qq|
-
-
+ print qq|
+| if ($show_storno);
+ if ($form->{radier}) {
+ print qq|
+
|;
- }
- }
-
- if ($invdate > $closedto) {
- print qq|
-
-
+ }
+ print qq|
|;
- }
- } else {
- if ($invdate > $closedto) {
- print qq|
- |;
- }
}
- if ($form->{menubar}) {
- require "$form->{path}/menu.pl";
- &menubar;
+ if (!$form->{id} && ($invdate > $closedto)) {
+ print qq| | .
+ NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
+ '-class' => 'submit'));
}
- print qq|
-
-{rowcount}>
+ print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
+ $form->hide_form(qw(rowcount callback draft_id draft_description login password));
-
+ # button for saving history
+ if($form->{id} ne "") {
+ print qq|
+ |;
+ }
+ # /button for saving history
-{path}>
-{login}>
-{password}>
-
-
+print qq|
@@ -739,8 +865,6 @@ sub update {
&check_name(vendor);
- &check_project;
-
$form->{exchangerate} = $exchangerate
if (
$form->{forex} = (
@@ -767,7 +891,7 @@ sub update {
}
$i = $form->{rowcount};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
+ $exchangerate = ($form->{exchangerate} * 1) ? $form->{exchangerate} * 1 : 1;
if ( ($form->{"partnumber_$i"} eq "")
&& ($form->{"description_$i"} eq "")
@@ -775,7 +899,7 @@ sub update {
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
&check_form;
- } else {
+ } else {
IR->retrieve_item(\%myconfig, \%$form);
@@ -851,12 +975,106 @@ sub update {
$lxdebug->leave_sub();
}
+sub storno {
+ $lxdebug->enter_sub();
+
+ if ($form->{storno}) {
+ $form->error($locale->text('Cannot storno storno invoice!'));
+ }
+
+ if (IS->has_storno(\%myconfig, $form, "ap")) {
+ $form->error($locale->text("Invoice has already been storno'd!"));
+ }
+
+ my $employee_id = $form->{employee_id};
+ invoice_links();
+ prepare_invoice();
+ relink_accounts();
+
+ # 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->{addition} = "CANCELED";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+
+ $form->{storno_id} = $form->{id};
+ $form->{storno} = 1;
+ $form->{id} = "";
+ $form->{invnumber} = "Storno zu " . $form->{invnumber};
+ $form->{rowcount}++;
+ $form->{employee_id} = $employee_id;
+ post();
+ $lxdebug->leave_sub();
+
+}
+
+sub use_as_template {
+ $lxdebug->enter_sub();
+
+ 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}--;
+ $form->{invdate} = $form->current_date(\%myconfig);
+ &display_form;
+
+ $lxdebug->leave_sub();
+}
+
+sub post_payment {
+ $lxdebug->enter_sub();
+ for $i (1 .. $form->{paidaccounts}) {
+ if ($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->{currency} ne $form->{defaultcurrency}) {
+ $form->{"exchangerate_$i"} = $form->{exchangerate}
+ if ($invdate == $datepaid);
+ $form->isblank("exchangerate_$i",
+ $locale->text('Exchangerate for payment missing!'));
+ }
+ }
+ }
+
+ ($form->{AP}) = split /--/, $form->{AP};
+ ($form->{AP_paid}) = split /--/, $form->{AP_paid};
+ if (IR->post_payment(\%myconfig, \%$form)){
+
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ # saving the history
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "PAYMENT POSTED";
+ $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
+ $form->save_history($form->dbconnect(\%myconfig));
+ # /saving the history
+ $form->redirect($locale->text(' Payment posted!'));
+ }
+ }
+ $form->error($locale->text('Cannot post payment!'));
+
+
+ $lxdebug->leave_sub();
+}
+
sub post {
$lxdebug->enter_sub();
$form->isblank("invdate", $locale->text('Invoice Date missing!'));
$form->isblank("vendor", $locale->text('Vendor missing!'));
+ $form->{invnumber} =~ s/^\s*//g;
+ $form->{invnumber} =~ s/\s*$//g;
+
# if the vendor changed get new values
if (&check_name(vendor)) {
&update;
@@ -875,7 +1093,7 @@ sub post {
if ($form->{currency} ne $form->{defaultcurrency});
for $i (1 .. $form->{paidaccounts}) {
- if ($form->{"paid_$i"}) {
+ if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
$datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
@@ -897,10 +1115,22 @@ sub post {
$form->{id} = 0 if $form->{postasnew};
- $form->redirect( $locale->text('Invoice')
+
+ relink_accounts();
+ if (IR->post_invoice(\%myconfig, \%$form)){
+ # saving the history
+ if(!exists $form->{addition} && $form->{id} ne "") {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "POSTED";
+ #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+ remove_draft() if $form->{remove_draft};
+ $form->redirect( $locale->text('Invoice')
. " $form->{invnumber} "
- . $locale->text('posted!'))
- if (IR->post_invoice(\%myconfig, \%$form));
+ . $locale->text('posted!'));
+ }
$form->error($locale->text('Cannot post invoice!'));
$lxdebug->leave_sub();
@@ -910,7 +1140,6 @@ sub delete {
$lxdebug->enter_sub();
$form->header;
-
print qq|
@@ -942,9 +1171,16 @@ sub delete {
sub yes {
$lxdebug->enter_sub();
-
- $form->redirect($locale->text('Invoice deleted!'))
- if (IR->delete_invoice(\%myconfig, \%$form));
+ if (IR->delete_invoice(\%myconfig, \%$form)) {
+ # saving the history
+ if(!exists $form->{addition}) {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "DELETED";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+ # /saving the history
+ $form->redirect($locale->text('Invoice deleted!'));
+ }
$form->error($locale->text('Cannot delete invoice!'));
$lxdebug->leave_sub();
|