-
-
-
-
-
-
- | . $locale->text('Customer') . qq| |
- $customer |
- {customer_klass}>
- {customer_id}>
-
- |
- . $locale->text('Contact Person') . qq| |
- $contact |
-
-
- |
-
-
-
- | . $locale->text('Credit Limit') . qq| |
- $form->{creditlimit} |
- |
- | . $locale->text('Remaining') . qq| |
- $form->{creditremaining} |
-
-
- |
-
- $business
+
+
+ |
+ | . $locale->text('Transaction description') . qq| |
+ | . $cgi->textfield("-name" => "transaction_description", "-size" => 35, "-value" => $form->{transaction_description}) . qq| |
+ |;
+#
+#
+#
+# |
+#
+print qq|
|
-
+ |
|
@@ -513,45 +757,19 @@ sub form_header {
|
-
-
-$jsscript
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ $jsscript
|;
+ print qq||;
- foreach $item (split / /, $form->{taxaccounts}) {
- print qq|
-
-
-
-|;
- }
$lxdebug->leave_sub();
}
sub form_footer {
$lxdebug->enter_sub();
+ $auth->assert('invoice_edit');
+
$form->{invtotal} = $form->{invsubtotal};
if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
@@ -562,16 +780,16 @@ sub form_footer {
}
$rows = ($rows > $introws) ? $rows : $introws;
$notes =
- qq||;
+ qq||;
$intnotes =
- qq||;
+ qq||;
- $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
+ $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
$taxincluded = "";
if ($form->{taxaccounts}) {
$taxincluded = qq|
- {taxincluded}> |
+ {taxincluded}> |
. $locale->text('Tax Included') . qq|
|;
}
@@ -589,8 +807,9 @@ sub form_footer {
$tax .= qq|
- $form->{"${item}_description"} |
- $form->{"${item}_total"} |
+ $form->{"${item}_description"} |
+ . $form->{"${item}_rate"} * 100 .qq|% |
+ $form->{"${item}_total"} |
|;
}
@@ -601,8 +820,8 @@ sub form_footer {
$subtotal = qq|
- | . $locale->text('Subtotal') . qq| |
- $form->{invsubtotal} |
+ | . $locale->text('Subtotal') . qq| |
+ $form->{invsubtotal} |
|;
@@ -628,12 +847,13 @@ sub form_footer {
$tax .= qq|
- Enthaltene $form->{"${item}_description"} |
- $form->{"${item}_total"} |
+ Enthaltene $form->{"${item}_description"} |
+ . $form->{"${item}_rate"} * 100 .qq|% |
+ $form->{"${item}_total"} |
- Nettobetrag |
- $form->{"${item}_netto"} |
+ Nettobetrag |
+ $form->{"${item}_netto"} |
|;
}
@@ -645,31 +865,63 @@ sub form_footer {
$form->{invtotal} =
$form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
+ 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|
-
-
+
+
- | . $locale->text('Notes') . qq| |
- | . $locale->text('Internal Notes') . qq| |
+ | . $locale->text('Notes') . qq| |
+ | . $locale->text('Internal Notes') . qq| |
+ | . $locale->text('Payment Terms') . qq| |
-
+
$notes |
$intnotes |
+ |
+ $follow_ups_block
|
-
+ |
+
+
+ | . $locale->text('Ertrag') . qq| |
+ | . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq| |
+
+
+ | . $locale->text('Ertrag prozentual') . qq| |
+ | . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| % |
+
+
+
+
+ |
+
$taxincluded
-
+
$subtotal
$tax
- | . $locale->text('Total') . qq| |
- $form->{invtotal} |
+ | . $locale->text('Total') . qq| |
+ $form->{invtotal} |
@@ -681,20 +933,20 @@ sub form_footer {
if ($webdav) {
$webdav_list = qq|
-
|
+
|
- Dokumente im Webdav-Repository |
+ Dokumente im Webdav-Repository |
-
- Dateiname |
- Webdavlink |
+
+ Dateiname |
+ Webdavlink |
|;
- foreach $file (keys %{ $form->{WEBDAV} }) {
+ foreach $file (@{ $form->{WEBDAV} }) {
$webdav_list .= qq|
- $file |
- $form->{WEBDAV}{$file} |
+ $file->{name} |
+ $file->{type} |
|;
}
@@ -705,15 +957,27 @@ sub form_footer {
print $webdav_list;
}
+if ($form->{type} eq "credit_note") {
print qq|
-
-
- |
+
+
+ |
+ . $locale->text('Payments') . qq| |
+
+|;
+} else {
+ print qq|
+
+
+
+
+ |
. $locale->text('Incoming Payments') . qq| |
|;
+}
if ($form->{currency} eq $form->{defaultcurrency}) {
@column_index = qw(datepaid source memo paid AR_paid);
@@ -736,6 +1000,9 @@ sub form_footer {
";
+ my @triggers = ();
+ my $totalpaid = 0;
+
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
for $i (1 .. $form->{paidaccounts}) {
@@ -748,59 +1015,76 @@ sub form_footer {
# format amounts
$totalpaid += $form->{"paid_$i"};
- $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"});
+ if ($form->{"exchangerate_$i"} == 0) {
+ $form->{"exchangerate_$i"} = "";
+ }
$exchangerate = qq| |;
if ($form->{currency} ne $form->{defaultcurrency}) {
if ($form->{"forex_$i"}) {
- $exchangerate =
- qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+ $exchangerate = qq|$form->{"exchangerate_$i"}|;
} else {
- $exchangerate =
- qq|{"exchangerate_$i"}>|;
+ $exchangerate = qq||;
}
}
- $exchangerate .= qq|
-{"forex_$i"}>
-|;
+ $exchangerate .= qq||;
$column_data{"paid_$i"} =
- qq|{"paid_$i"}> | |;
- $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
+ qq| | |;
+ $column_data{"exchangerate_$i"} = qq|$exchangerate | |;
$column_data{"AR_paid_$i"} =
- qq| | |;
+ qq| | |;
$column_data{"datepaid_$i"} =
- qq|{"datepaid_$i"}> | |;
+ qq|
+ | |;
$column_data{"source_$i"} =
- qq| | |;
+ qq| | |;
$column_data{"memo_$i"} =
- qq| | |;
+ qq| | |;
map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
print "
\n";
+ push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
}
+ my $paid_missing = $form->{oldinvtotal} - $totalpaid;
+
print qq|
-{paidaccounts}>
-
-{oldinvtotal}>
-
+
+ |
+ |
+ | . $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| |
+
+|;
+
+ map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
+ print qq|
|
-
|
+
|
|;
- &print_options;
+ print_options();
print qq|
|
@@ -812,69 +1096,96 @@ sub form_footer {
$closedto = $form->datetonum($form->{closedto}, \%myconfig);
if ($form->{id}) {
+ my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
+
print qq|
-
-
-
-
+ |;
+ print qq| | if ($show_storno);
+ print qq|
|;
-
- if (!$form->{revtrans}) {
- if (!$form->{locked}) {
- print qq|
-
-
+ print qq|
+|;
+ if ($form->{id} && !($form->{type} eq "credit_note")) {
+ print qq|
+
|;
- }
}
+ if ($form->{radier}) {
+ print qq|
+
+|;
+ }
+
if ($invdate > $closedto) {
print qq|
-
-
|;
}
+ print qq|
+ |;
+
} else {
if ($invdate > $closedto) {
- print qq|
-
-
-
-
- |;
+ | .
+ NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
+ '-class' => 'submit'));
}
}
- if ($form->{menubar}) {
- require "$form->{path}/menu.pl";
- &menubar;
+ # button for saving history
+ if($form->{id} ne "") {
+ print qq|
+ |;
}
-
- print qq|
-
-{rowcount}>
-
-
-
-{path}>
-{login}>
-{password}>
-
+ # /button for saving history
+
+ # mark_as_paid button
+ if($form->{id} ne "") {
+ print qq||;
+ }
+ # /mark_as_paid button
+ print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
+ qq|
+
+
+| .
+$cgi->hidden("-name" => "callback", "-value" => $form->{callback})
+. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
+. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
+. qq|
@@ -885,45 +1196,45 @@ sub form_footer {
$lxdebug->leave_sub();
}
+sub mark_as_paid {
+ $lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
+ &mark_as_paid_common(\%myconfig,"ar");
+
+ $lxdebug->leave_sub();
+}
+
sub update {
$lxdebug->enter_sub();
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
- qw(exchangerate creditlimit creditremaining);
- if ($form->{second_run}) {
- $form->{print_and_post} = 0;
- }
+ $auth->assert('invoice_edit');
+
+ my ($recursive_call) = shift;
+
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
+
+ $form->{print_and_post} = 0 if $form->{second_run};
+ $taxincluded = "checked" if $form->{taxincluded};
+ $form->{update} = 1;
+
&check_name(customer);
- &check_project;
+ $form->{taxincluded} ||= $taxincluded;
- $form->{exchangerate} = $exchangerate
- if (
- $form->{forex} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
- )));
+ $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
for $i (1 .. $form->{paidaccounts}) {
- if ($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"}, 'buy'
- )));
- }
+ next unless $form->{"paid_$i"};
+ map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
+ $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
+ $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
}
$i = $form->{rowcount};
- $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
+ $exchangerate = $form->{exchangerate} || 1;
# if last row empty, check the form otherwise retrieve new item
if ( ($form->{"partnumber_$i"} eq "")
@@ -933,14 +1244,13 @@ sub update {
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
&check_form;
- } else {
+ } else {
IS->retrieve_item(\%myconfig, \%$form);
$rows = scalar @{ $form->{item_list} };
- $form->{"discount_$i"} =
- $form->format_amount(\%myconfig, $form->{discount} * 100);
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
if ($rows) {
$form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
@@ -952,24 +1262,22 @@ sub update {
} else {
- $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
+ $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
- map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
- qw(partnumber description unit);
- map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
- keys %{ $form->{item_list}[0] };
+ map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
+ map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
+
+ $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
+ $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
- $form->{"discount_$i"} = $form->{discount} * 100;
+ $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
- $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
- ($dec) = ($s =~ /\.(\d+)/);
- $dec = length $dec;
- $decimalplaces = ($dec > 2) ? $dec : 2;
+ ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
+ $decimalplaces = max 2, length $1;
if ($sellprice) {
$form->{"sellprice_$i"} = $sellprice;
} else {
-
# if there is an exchange rate adjust sellprice
$form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
$form->{"sellprice_$i"} /= $exchangerate;
@@ -977,36 +1285,24 @@ sub update {
$form->{"listprice_$i"} /= $exchangerate;
- $amount =
- $form->{"sellprice_$i"} * $form->{"qty_$i"} *
- (1 - $form->{"discount_$i"} / 100);
- map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
- map { $form->{"${_}_base"} += $amount }
- (split / /, $form->{"taxaccounts_$i"});
- map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
- split / /, $form->{"taxaccounts_$i"}
- if !$form->{taxincluded};
+ $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
+ map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
+ map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
+ map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
$form->{creditremaining} -= $amount;
- map {
- $form->{"${_}_$i"} =
- $form->format_amount(\%myconfig, $form->{"${_}_$i"},
- $decimalplaces)
- } qw(sellprice listprice);
+ map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
- $form->{"qty_$i"} =
- $form->format_amount(\%myconfig, $form->{"qty_$i"});
+ $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
if ($lizenzen) {
if ($form->{"inventory_accno_$i"} ne "") {
$form->{"lizenzen_$i"} = qq||;
foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
- $form->{"lizenzen_$i"} .=
- qq||;
+ $form->{"lizenzen_$i"} .= qq||;
}
- $form->{"lizenzen_$i"} .=
- qq||;
+ $form->{"lizenzen_$i"} .= qq||;
}
}
@@ -1029,24 +1325,65 @@ sub update {
&& ($form->{"description_$i"} eq "")) {
$form->{rowcount}--;
$form->{"discount_$i"} = "";
- &display_form;
- } else {
+ display_form();
+ } else {
$form->{"id_$i"} = 0;
- $form->{"unit_$i"} = $locale->text('ea');
+ new_item();
+ }
+ }
+ }
+ $lxdebug->leave_sub();
+}
+
+sub post_payment {
+ $lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+ 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!'));
- &new_item;
+ $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->{AR}) = split /--/, $form->{AR};
+ ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+ relink_accounts();
+ $form->redirect($locale->text('Payment posted!'))
+ if (IS->post_payment(\%myconfig, \%$form));
+ $form->error($locale->text('Cannot post payment!'));
+
+
$lxdebug->leave_sub();
}
sub post {
$lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->isblank("invdate", $locale->text('Invoice Date missing!'));
$form->isblank("customer", $locale->text('Customer missing!'));
+ $form->error($locale->text('Cannot post invoice for a closed period!'))
+ if ($form->date_closed($form->{"invdate"}, \%myconfig));
+
+ $form->{invnumber} =~ s/^\s*//g;
+ $form->{invnumber} =~ s/\s*$//g;
# if oldcustomer ne customer redo form
if (&check_name(customer)) {
@@ -1075,7 +1412,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}
@@ -1086,34 +1423,47 @@ sub post {
}
}
- ($form->{AR}) = split /--/, $form->{AR};
- ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+ ($form->{AR}) = split /--/, $form->{AR};
+ ($form->{AR_paid}) = split /--/, $form->{AR_paid};
+ $form->{storno} ||= 0;
$form->{label} = $locale->text('Invoice');
$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");
- }
- if ($print_post) {
- if (!(IS->post_invoice(\%myconfig, \%$form))) {
- $form->error($locale->text('Cannot post invoice!'));
+ if ($form->{postasnew}) {
+ if ($form->{type} eq "credit_note") {
+ undef($form->{cnnumber});
+ } else {
+ undef($form->{invnumber});
}
- } else {
- $form->redirect(
- $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
- if (IS->post_invoice(\%myconfig, \%$form));
- $form->error($locale->text('Cannot post invoice!'));
}
+ relink_accounts();
+ $form->error($locale->text('Cannot post invoice!'))
+ unless IS->post_invoice(\%myconfig, \%$form);
+ remove_draft() if $form->{remove_draft};
+
+ if(!exists $form->{addition}) {
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = $print_post ? "PRINTED AND POSTED" :
+ $form->{storno} ? "STORNO" :
+ "POSTED";
+ $form->save_history($form->dbconnect(\%myconfig));
+ }
+
+ $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
+ unless $print_post;
+
$lxdebug->leave_sub();
}
sub print_and_post {
$lxdebug->enter_sub();
+ $auth->assert('invoice_edit');
+
$old_form = new Form;
$print_post = 1;
$form->{print_and_post} = 1;
@@ -1124,13 +1474,61 @@ sub print_and_post {
}
+sub use_as_template {
+ $lxdebug->enter_sub();
+
+ $auth->assert('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}--;
+ $form->{invdate} = $form->current_date(\%myconfig);
+ &display_form;
+
+ $lxdebug->leave_sub();
+}
+
+sub storno {
+ $lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
+ if ($form->{storno}) {
+ $form->error($locale->text('Cannot storno storno invoice!'));
+ }
+
+ if (IS->has_storno(\%myconfig, $form, "ar")) {
+ $form->error($locale->text("Invoice has already been storno'd!"));
+ }
+
+ map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
+
+ 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 };
+
+ $form->{storno_id} = $form->{id};
+ $form->{storno} = 1;
+ $form->{id} = "";
+ $form->{invnumber} = "Storno zu " . $form->{invnumber};
+ $form->{rowcount}++;
+
+ post();
+ $lxdebug->leave_sub();
+}
+
sub preview {
$lxdebug->enter_sub();
+ $auth->assert('invoice_edit');
+
$form->{preview} = 1;
$old_form = new Form;
for (keys %$form) { $old_form->{$_} = $form->{$_} }
- $old_form->{rowcount}++;
&print_form($old_form);
$lxdebug->leave_sub();
@@ -1139,6 +1537,9 @@ sub preview {
sub delete {
$lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
if ($form->{second_run}) {
$form->{print_and_post} = 0;
}
@@ -1147,19 +1548,20 @@ sub delete {
print qq|
-
|;
@@ -1175,12 +1577,91 @@ sub delete {
$lxdebug->leave_sub();
}
+sub credit_note {
+ $lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
+ $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
+ $form->{duedate} =
+ $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+
+ $form->{id} = '';
+ $form->{rowcount}--;
+ $form->{shipto} = 1;
+
+
+ $form->{title} = $locale->text('Add Credit Note');
+ $form->{script} = 'is.pl';
+ $script = "is";
+ $buysell = 'buy';
+
+
+ # bo creates the id, reset it
+ map { delete $form->{$_} }
+ qw(id invnumber subject message cc bcc printed emailed queued);
+ $form->{ $form->{vc} } =~ s/--.*//g;
+ $form->{type} = "credit_note";
+
+
+ map { $form->{"select$_"} = "" } ($form->{vc}, currency);
+
+ map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
+ qw(creditlimit creditremaining);
+
+ $currency = $form->{currency};
+ &invoice_links;
+
+ $form->{currency} = $currency;
+ $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
+ $form->{exchangerate} = $form->{forex} || '';
+
+ $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
+
+ &prepare_invoice;
+
+
+ &display_form;
+
+ $lxdebug->leave_sub();
+}
+
sub yes {
$lxdebug->enter_sub();
- $form->redirect($locale->text('Invoice deleted!'))
- if (IS->delete_invoice(\%myconfig, \%$form, $spool));
+ $auth->assert('invoice_edit');
+
+ if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
+ # 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();
}
+
+sub e_mail {
+ $lxdebug->enter_sub();
+
+ $auth->assert('invoice_edit');
+
+ if (!$form->{id}) {
+ $print_post = 1;
+
+ my $saved_form = save_form();
+
+ post();
+
+ restore_form($saved_form, 0, qw(id invnumber));
+ }
+
+ edit_e_mail();
+
+ $lxdebug->leave_sub();
+}
| | | | |