@@ -673,6 +730,7 @@ sub form_footer {
|;
+ my @triggers = ();
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
for $i (1 .. $form->{paidaccounts}) {
@@ -685,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"});
@@ -705,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"} =
@@ -721,6 +782,7 @@ sub form_footer {
print qq|
|;
+ push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
}
print qq|
@@ -740,44 +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|
|;
print qq|
-| unless ($form->{storno});
+| if ($show_storno);
if ($form->{radier}) {
print qq|
|;
}
- } else {
- if ($invdate > $closedto) {
- print qq|
- |;
- }
- }
+ print qq|
+|;
- if ($form->{menubar}) {
- require "$form->{path}/menu.pl";
- &menubar;
}
- print qq|
-
-{rowcount}>
+ if (!$form->{id} && ($invdate > $closedto)) {
+ print qq| | .
+ NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
+ '-class' => 'submit'));
+ }
-
+ print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
+ $form->hide_form(qw(rowcount callback draft_id draft_description login password));
-{path}>
-{login}>
-{password}>
+ # button for saving history
+ if($form->{id} ne "") {
+ print qq|
+ |;
+ }
+ # /button for saving history
-
+print qq|
@@ -794,8 +865,6 @@ sub update {
&check_name(vendor);
- &check_project;
-
$form->{exchangerate} = $exchangerate
if (
$form->{forex} = (
@@ -822,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 "")
@@ -913,15 +982,48 @@ sub 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;
- &post();
$lxdebug->leave_sub();
-
}
sub post_payment {
@@ -946,8 +1048,18 @@ sub post_payment {
($form->{AP}) = split /--/, $form->{AP};
($form->{AP_paid}) = split /--/, $form->{AP_paid};
- $form->redirect($locale->text(' Payment posted!'))
- if (IR->post_payment(\%myconfig, \%$form));
+ 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!'));
@@ -960,6 +1072,9 @@ sub post {
$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;
@@ -1000,16 +1115,22 @@ sub post {
$form->{id} = 0 if $form->{postasnew};
- # get new invnumber in sequence if no invnumber is given or if posasnew was requested
- if (!$form->{invnumber} || $form->{postasnew}) {
- $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
- }
relink_accounts();
- $form->redirect( $locale->text('Invoice')
+ 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();
@@ -1019,7 +1140,6 @@ sub delete {
$lxdebug->enter_sub();
$form->header;
-
print qq|
@@ -1051,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();
|