kivitendo/bin/mozilla/is.pl @ ee792a3f
d319704a | Moritz Bunkus | #=====================================================================
|
||
# LX-Office ERP
|
||||
# Copyright (C) 2004
|
||||
# Based on SQL-Ledger Version 2.1.9
|
||||
# Web http://www.lx-office.org
|
||||
#
|
||||
#=====================================================================
|
||||
# SQL-Ledger Accounting
|
||||
# Copyright (c) 1998-2002
|
||||
#
|
||||
# Author: Dieter Simader
|
||||
# Email: dsimader@sql-ledger.org
|
||||
# Web: http://www.sql-ledger.org
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#======================================================================
|
||||
#
|
||||
# Inventory invoicing module
|
||||
#
|
||||
#======================================================================
|
||||
7a7f33b5 | Moritz Bunkus | use SL::FU;
|
||
d319704a | Moritz Bunkus | use SL::IS;
|
||
use SL::PE;
|
||||
07d71c33 | Stephan Köhler | use Data::Dumper;
|
||
7a7f33b5 | Moritz Bunkus | use List::Util qw(max sum);
|
||
d319704a | Moritz Bunkus | |||
d629acd8 | Sven Schöling | require "bin/mozilla/io.pl";
|
||
b6dc5623 | Sven Schöling | require "bin/mozilla/invoice_io.pl";
|
||
d629acd8 | Sven Schöling | require "bin/mozilla/arap.pl";
|
||
bde667c2 | Moritz Bunkus | require "bin/mozilla/drafts.pl";
|
||
d2bafad3 | Thomas Kasulke | |||
5486b4a9 | Sven Schöling | use strict;
|
||
my $edit;
|
||||
my $payment;
|
||||
my $print_post;
|
||||
d319704a | Moritz Bunkus | 1;
|
||
# end of main
|
||||
sub add {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
bde667c2 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
return $main::lxdebug->leave_sub() if (load_draft_maybe());
|
||||
bde667c2 | Moritz Bunkus | |||
54e4131e | Moritz Bunkus | if ($form->{type} eq "credit_note") {
|
||
$form->{title} = $locale->text('Add Credit Note');
|
||||
if ($form->{storno}) {
|
||||
$form->{title} = $locale->text('Add Storno Credit Note');
|
||||
}
|
||||
} else {
|
||||
$form->{title} = $locale->text('Add Sales Invoice');
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
8c7e4493 | Moritz Bunkus | $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
|
||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $form->{jsscript} = "date";
|
||
d319704a | Moritz Bunkus | |||
&invoice_links;
|
||||
&prepare_invoice;
|
||||
&display_form;
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub edit {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
ee792a3f | Sven Schöling | my $locale = $main::locale;
|
||
1c084510 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
2b89ec97 | Thomas Kasulke | # show history button
|
||
$form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
|
||||
#/show hhistory button
|
||||
fb4d2ffa | Moritz Bunkus | |||
ee792a3f | Sven Schöling | if ($form->{type} eq "credit_note") {
|
||
$form->{title} = $locale->text('Edit Credit Note');
|
||||
$form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
|
||||
} else {
|
||||
$form->{title} = $locale->text('Edit Sales Invoice');
|
||||
$form->{title} = $locale->text('Edit Storno Invoice') if $form->{storno};
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my ($language_id, $printer_id);
|
||
8f3dc0b4 | Stephan Köhler | if ($form->{print_and_post}) {
|
||
081a4f97 | Moritz Bunkus | $form->{action} = "print";
|
||
8f3dc0b4 | Stephan Köhler | $form->{resubmit} = 1;
|
||
54e4131e | Moritz Bunkus | $language_id = $form->{language_id};
|
||
$printer_id = $form->{printer_id};
|
||||
8f3dc0b4 | Stephan Köhler | }
|
||
d319704a | Moritz Bunkus | &invoice_links;
|
||
&prepare_invoice;
|
||||
54e4131e | Moritz Bunkus | if ($form->{print_and_post}) {
|
||
$form->{language_id} = $language_id;
|
||||
$form->{printer_id} = $printer_id;
|
||||
}
|
||||
d319704a | Moritz Bunkus | &display_form;
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub invoice_links {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
0bb0eb67 | Stephan Köhler | |||
5486b4a9 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
$main::auth->assert('invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{vc} = 'customer';
|
||
# create links
|
||||
5486b4a9 | Sven Schöling | $form->{webdav} = $main::webdav;
|
||
$form->{lizenzen} = $main::lizenzen;
|
||||
d319704a | Moritz Bunkus | |||
$form->create_links("AR", \%myconfig, "customer");
|
||||
if ($form->{all_customer}) {
|
||||
unless ($form->{customer_id}) {
|
||||
$form->{customer_id} = $form->{all_customer}->[0]->{id};
|
||||
2ff471a7 | Moritz Bunkus | $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
|
||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
5486b4a9 | Sven Schöling | my $payment_id;
|
||
54e4131e | Moritz Bunkus | if ($form->{payment_id}) {
|
||
$payment_id = $form->{payment_id};
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my $language_id;
|
||
54e4131e | Moritz Bunkus | if ($form->{language_id}) {
|
||
$language_id = $form->{language_id};
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my $taxzone_id;
|
||
54e4131e | Moritz Bunkus | if ($form->{taxzone_id}) {
|
||
$taxzone_id = $form->{taxzone_id};
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my $id;
|
||
54e4131e | Moritz Bunkus | if ($form->{id}) {
|
||
$id = $form->{id};
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my $shipto_id;
|
||
54e4131e | Moritz Bunkus | if ($form->{shipto_id}) {
|
||
$shipto_id = $form->{shipto_id};
|
||||
f9f5330a | Stephan Köhler | }
|
||
5486b4a9 | Sven Schöling | my $cp_id = $form->{cp_id};
|
||
54e4131e | Moritz Bunkus | IS->get_customer(\%myconfig, \%$form);
|
||
1f2c9572 | Philip Reetz | |||
27562848 | Moritz Bunkus | #quote all_customer Bug 133
|
||
5486b4a9 | Sven Schöling | foreach my $ref (@{ $form->{all_customer} }) {
|
||
27562848 | Moritz Bunkus | $ref->{name} = $form->quote($ref->{name});
|
||
}
|
||||
54e4131e | Moritz Bunkus | if ($id) {
|
||
$form->{id} = $id;
|
||||
}
|
||||
d319704a | Moritz Bunkus | IS->retrieve_invoice(\%myconfig, \%$form);
|
||
$form->{cp_id} = $cp_id;
|
||||
54e4131e | Moritz Bunkus | if ($payment_id) {
|
||
$form->{payment_id} = $payment_id;
|
||||
}
|
||||
if ($language_id) {
|
||||
$form->{language_id} = $language_id;
|
||||
}
|
||||
if ($taxzone_id) {
|
||||
$form->{taxzone_id} = $taxzone_id;
|
||||
}
|
||||
if ($shipto_id) {
|
||||
$form->{shipto_id} = $shipto_id;
|
||||
}
|
||||
d319704a | Moritz Bunkus | $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
|
||
# departments
|
||||
if ($form->{all_departments}) {
|
||||
$form->{selectdepartment} = "<option>\n";
|
||||
$form->{department} = "$form->{department}--$form->{department_id}";
|
||||
map {
|
||||
$form->{selectdepartment} .=
|
||||
54451a50 | Thomas Kasulke | "<option>$_->{description}--$_->{id}</option>\n"
|
||
d319704a | Moritz Bunkus | } (@{ $form->{all_departments} });
|
||
}
|
||||
$form->{employee} = "$form->{employee}--$form->{employee_id}";
|
||||
# forex
|
||||
$form->{forex} = $form->{exchangerate};
|
||||
5486b4a9 | Sven Schöling | my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
|
||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | foreach my $key (keys %{ $form->{AR_links} }) {
|
||
foreach my $ref (@{ $form->{AR_links}{$key} }) {
|
||||
54451a50 | Thomas Kasulke | $form->{"select$key"} .=
|
||
"<option>$ref->{accno}--$ref->{description}</option>\n";
|
||||
d319704a | Moritz Bunkus | }
|
||
if ($key eq "AR_paid") {
|
||||
5486b4a9 | Sven Schöling | next unless $form->{acc_trans}{$key};
|
||
for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
|
||||
d319704a | Moritz Bunkus | $form->{"AR_paid_$i"} =
|
||
"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
|
||||
# reverse paid
|
||||
$form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
|
||||
$form->{"datepaid_$i"} =
|
||||
$form->{acc_trans}{$key}->[$i - 1]->{transdate};
|
||||
$form->{"forex_$i"} = $form->{"exchangerate_$i"} =
|
||||
$form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
|
||||
$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
|
||||
$form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
|
||||
$form->{paidaccounts} = $i;
|
||||
}
|
||||
} else {
|
||||
$form->{$key} =
|
||||
"$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
|
||||
}
|
||||
}
|
||||
$form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
|
||||
$form->{AR} = $form->{AR_1} unless $form->{id};
|
||||
$form->{locked} =
|
||||
($form->datetonum($form->{invdate}, \%myconfig) <=
|
||||
$form->datetonum($form->{closedto}, \%myconfig));
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub prepare_invoice {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
0bb0eb67 | Stephan Köhler | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
54e4131e | Moritz Bunkus | if ($form->{type} eq "credit_note") {
|
||
$form->{type} = "credit_note";
|
||||
$form->{formname} = "credit_note";
|
||||
} else {
|
||||
$form->{type} = "invoice";
|
||||
$form->{formname} = "invoice";
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
if ($form->{id}) {
|
||||
fcd7e932 | Moritz Bunkus | my $i = 0;
|
||
5486b4a9 | Sven Schöling | foreach my $ref (@{ $form->{invoice_details} }) {
|
||
d319704a | Moritz Bunkus | $i++;
|
||
54e4131e | Moritz Bunkus | |||
d319704a | Moritz Bunkus | map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
|
||
a0a30f41 | Sven Schöling | $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
|
||
my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
|
||||
$dec = length $dec;
|
||||
my $decimalplaces = ($dec > 2) ? $dec : 2;
|
||||
0bb0eb67 | Stephan Köhler | |||
a0a30f41 | Sven Schöling | $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
|
||
(my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
|
||||
$dec_qty = length $dec_qty;
|
||||
0bb0eb67 | Stephan Köhler | |||
a0a30f41 | Sven Schöling | $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
|
||
d319704a | Moritz Bunkus | |||
a0a30f41 | Sven Schöling | $form->{rowcount} = $i;
|
||
07d71c33 | Stephan Köhler | |||
d319704a | Moritz Bunkus | }
|
||
a0a30f41 | Sven Schöling | |||
# get pricegroups for parts
|
||||
IS->get_pricegroups_for_parts(\%myconfig, \%$form);
|
||||
set_pricegroup($_) for 1 .. $form->{rowcount};
|
||||
d319704a | Moritz Bunkus | }
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub form_header {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
my $cgi = $main::cgi;
|
||||
ef73414c | Stephan Köhler | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
4cc5904b | Sven Schöling | our %TMPL_VAR = ();
|
||
my @custom_hiddens;
|
||||
a05eead3 | Sven Schöling | $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
|
||
$form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
|
||||
0cb4ad8c | Philip Reetz | |||
fb37acdc | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
a05eead3 | Sven Schöling | $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
|
||
9e117fbd | Philip Reetz | |||
54e4131e | Moritz Bunkus | $payment = qq|<option value=""></option>|;
|
||
5486b4a9 | Sven Schöling | foreach my $item (@{ $form->{payment_terms} }) {
|
||
54e4131e | Moritz Bunkus | if ($form->{payment_id} eq $item->{id}) {
|
||
$payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
|
||||
} else {
|
||||
$payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
|
||||
}
|
||||
}
|
||||
8c7e4493 | Moritz Bunkus | my $set_duedate_url = "$form->{script}?action=set_duedate";
|
||
85e36de2 | Philip Reetz | |||
ee792a3f | Sven Schöling | push @ { $form->{AJAX} }, new CGI::Ajax( 'set_duedate' => $set_duedate_url );
|
||
54e4131e | Moritz Bunkus | |||
cfc6a60d | Moritz Bunkus | my @old_project_ids = ($form->{"globalproject_id"});
|
||
a05eead3 | Sven Schöling | map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
|
||
1e251313 | Moritz Bunkus | $form->get_lists("contacts" => "ALL_CONTACTS",
|
||
"shipto" => "ALL_SHIPTO",
|
||||
"projects" => { "key" => "ALL_PROJECTS",
|
||||
"all" => 0,
|
||||
"old_id" => \@old_project_ids },
|
||||
4cc5904b | Sven Schöling | "employees" => "ALL_EMPLOYEES",
|
||
"salesmen" => "ALL_SALESMEN",
|
||||
1e251313 | Moritz Bunkus | "taxzones" => "ALL_TAXZONES",
|
||
"currencies" => "ALL_CURRENCIES",
|
||||
"customers" => "ALL_CUSTOMERS",
|
||||
"price_factors" => "ALL_PRICE_FACTORS");
|
||||
54e4131e | Moritz Bunkus | |||
4cc5904b | Sven Schöling | $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
|
||
$TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
|
||||
$TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
|
||||
$TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
|
||||
# customer
|
||||
$TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
|
||||
$TMPL_VAR{vclimit} = $myconfig{vclimit};
|
||||
$TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('$form->{vc}', '', @{[ $form->{vc} eq 'vendor' ? 1 : 0 ]}, 0)";
|
||||
push @custom_hiddens, "$form->{vc}_id";
|
||||
push @custom_hiddens, "old$form->{vc}";
|
||||
push @custom_hiddens, "select$form->{vc}";
|
||||
# currencies and exchangerate
|
||||
my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
|
||||
my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
|
||||
$form->{currency} = $form->{defaultcurrency} unless $form->{currency};
|
||||
$TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
|
||||
$TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
|
||||
'-values' => \@values, '-labels' => \%labels)) if scalar @values;
|
||||
push @custom_hiddens, "forex";
|
||||
push @custom_hiddens, "exchangerate" if $form->{forex};
|
||||
$TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
|
||||
$TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
|
||||
40662c08 | Thomas Kasulke | |||
4cc5904b | Sven Schöling | $form->{fokus} = "invoice.customer";
|
||
ddbe3ea5 | Moritz Bunkus | |||
4cc5904b | Sven Schöling | my $follow_up_vc = $form->{customer};
|
||
$follow_up_vc =~ s/--\d*\s*$//;
|
||||
$TMPL_VAR{customer_name} = $follow_up_vc;
|
||||
ddbe3ea5 | Moritz Bunkus | |||
4cc5904b | Sven Schöling | # set option selected
|
||
ee792a3f | Sven Schöling | foreach my $item (qw(AR)) {
|
||
d319704a | Moritz Bunkus | $form->{"select$item"} =~ s/ selected//;
|
||
a05eead3 | Sven Schöling | $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
|
||
d319704a | Moritz Bunkus | }
|
||
ee792a3f | Sven Schöling | $TMPL_VAR{is_type_credit_note} = $form->{type} eq "credit_note";
|
||
$TMPL_VAR{is_format_html} = $form->{format} eq 'html';
|
||||
$TMPL_VAR{dateformat} = $myconfig{dateformat};
|
||||
$TMPL_VAR{numberformat} = $myconfig{numberformat};
|
||||
d319704a | Moritz Bunkus | |||
4cc5904b | Sven Schöling | # hiddens
|
||
$TMPL_VAR{HIDDEN} = [qw(
|
||||
id action type media format queued printed emailed title vc discount
|
||||
creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
|
||||
max_dunning_level dunning_amount
|
||||
shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
|
||||
shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
|
||||
convert_from_do_ids convert_from_oe_ids
|
||||
), @custom_hiddens,
|
||||
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
|
||||
d319704a | Moritz Bunkus | |||
d7f06042 | Moritz Bunkus | $form->{jsscript} = 1;
|
||
4cc5904b | Sven Schöling | $form->header();
|
||
print $form->parse_html_template("is/form_header", \%TMPL_VAR);
|
||||
52983c08 | Sven Schöling | |||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub form_footer {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
my $cgi = $main::cgi;
|
||||
0bb0eb67 | Stephan Köhler | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{invtotal} = $form->{invsubtotal};
|
||
5486b4a9 | Sven Schöling | my ($rows, $introws);
|
||
d319704a | Moritz Bunkus | if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
|
||
$rows = 2;
|
||||
}
|
||||
if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
|
||||
$introws = 2;
|
||||
}
|
||||
$rows = ($rows > $introws) ? $rows : $introws;
|
||||
5486b4a9 | Sven Schöling | my $notes =
|
||
da10bf75 | Thomas Kasulke | qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
|
||
5486b4a9 | Sven Schöling | my $intnotes =
|
||
da10bf75 | Thomas Kasulke | qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
|
||
fb4d2ffa | Moritz Bunkus | |||
8ef6c902 | Thomas Kasulke | $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
|
||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $taxincluded = "";
|
||
d319704a | Moritz Bunkus | if ($form->{taxaccounts}) {
|
||
$taxincluded = qq|
|
||||
8ef6c902 | Thomas Kasulke | <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
|
||
383022ae | Stephan Köhler | . $locale->text('Tax Included') . qq|</b><br><br>|;
|
||
d319704a | Moritz Bunkus | }
|
||
5486b4a9 | Sven Schöling | my ($tax, $subtotal);
|
||
d319704a | Moritz Bunkus | if (!$form->{taxincluded}) {
|
||
5486b4a9 | Sven Schöling | foreach my $item (split / /, $form->{taxaccounts}) {
|
||
d319704a | Moritz Bunkus | if ($form->{"${item}_base"}) {
|
||
$form->{"${item}_total"} =
|
||||
$form->round_amount(
|
||||
$form->{"${item}_base"} * $form->{"${item}_rate"},
|
||||
2);
|
||||
$form->{invtotal} += $form->{"${item}_total"};
|
||||
$form->{"${item}_total"} =
|
||||
$form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
|
||||
$tax .= qq|
|
||||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <th align="right">$form->{"${item}_description"} |
|
||
5e59cc54 | Udo Spallek | . $form->{"${item}_rate"} * 100 .qq|%</th>
|
||
da10bf75 | Thomas Kasulke | <td align="right">$form->{"${item}_total"}</td>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
|;
|
||||
}
|
||||
}
|
||||
$form->{invsubtotal} =
|
||||
$form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
|
||||
$subtotal = qq|
|
||||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <th align="right">| . $locale->text('Subtotal') . qq|</th>
|
||
<td align="right">$form->{invsubtotal}</td>
|
||||
d319704a | Moritz Bunkus | </tr>
|
||
|;
|
||||
}
|
||||
if ($form->{taxincluded}) {
|
||||
5486b4a9 | Sven Schöling | foreach my $item (split / /, $form->{taxaccounts}) {
|
||
d319704a | Moritz Bunkus | if ($form->{"${item}_base"}) {
|
||
$form->{"${item}_total"} =
|
||||
$form->round_amount(
|
||||
($form->{"${item}_base"} * $form->{"${item}_rate"} /
|
||||
(1 + $form->{"${item}_rate"})
|
||||
),
|
||||
2);
|
||||
$form->{"${item}_netto"} =
|
||||
$form->round_amount(
|
||||
($form->{"${item}_base"} - $form->{"${item}_total"}),
|
||||
2);
|
||||
$form->{"${item}_total"} =
|
||||
$form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
|
||||
$form->{"${item}_netto"} =
|
||||
$form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
|
||||
$tax .= qq|
|
||||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <th align="right">Enthaltene $form->{"${item}_description"} |
|
||
5e59cc54 | Udo Spallek | . $form->{"${item}_rate"} * 100 .qq|%</th>
|
||
da10bf75 | Thomas Kasulke | <td align="right">$form->{"${item}_total"}</td>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <th align="right">Nettobetrag</th>
|
||
<td align="right">$form->{"${item}_netto"}</td>
|
||||
d319704a | Moritz Bunkus | </tr>
|
||
|;
|
||||
}
|
||||
}
|
||||
}
|
||||
$form->{oldinvtotal} = $form->{invtotal};
|
||||
$form->{invtotal} =
|
||||
$form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
|
||||
7a7f33b5 | Moritz Bunkus | 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|
|
||||
<tr>
|
||||
<td colspan="2">| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</td>
|
||||
</tr>
|
||||
|;
|
||||
}
|
||||
}
|
||||
d319704a | Moritz Bunkus | print qq|
|
||
<tr>
|
||||
<td>
|
||||
da10bf75 | Thomas Kasulke | <table width="100%">
|
||
<tr valign="bottom">
|
||||
d319704a | Moritz Bunkus | <td>
|
||
<table>
|
||||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <th align="left">| . $locale->text('Notes') . qq|</th>
|
||
<th align="left">| . $locale->text('Internal Notes') . qq|</th>
|
||||
<th align="right">| . $locale->text('Payment Terms') . qq|</th>
|
||||
d319704a | Moritz Bunkus | </tr>
|
||
da10bf75 | Thomas Kasulke | <tr valign="top">
|
||
d319704a | Moritz Bunkus | <td>$notes</td>
|
||
<td>$intnotes</td>
|
||||
3879426c | Moritz Bunkus | <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value, 'invdate__' + invdate.value],['duedate'])">$payment
|
||
54e4131e | Moritz Bunkus | </select></td>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
7a7f33b5 | Moritz Bunkus | $follow_ups_block
|
||
d319704a | Moritz Bunkus | </table>
|
||
</td>
|
||||
4d8a6515 | Philip Reetz | <td>
|
||
<table>
|
||||
<tr>
|
||||
<th align=left>| . $locale->text('Ertrag') . qq|</th>
|
||||
<td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
|
||||
<td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
|
||||
</tr>
|
||||
<input type=hidden name="marge_total" value="$form->{"marge_total"}">
|
||||
<input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
|
||||
</table>
|
||||
</td>
|
||||
<td align="right">
|
||||
d319704a | Moritz Bunkus | $taxincluded
|
||
4d8a6515 | Philip Reetz | <table>
|
||
d319704a | Moritz Bunkus | $subtotal
|
||
$tax
|
||||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <th align="right">| . $locale->text('Total') . qq|</th>
|
||
<td align="right">$form->{invtotal}</td>
|
||||
d319704a | Moritz Bunkus | </tr>
|
||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|;
|
||||
5486b4a9 | Sven Schöling | my $webdav_list;
|
||
if ($main::webdav) {
|
||||
d319704a | Moritz Bunkus | $webdav_list = qq|
|
||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <td><hr size="3" noshade></td>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
0576299f | Moritz Bunkus | <tr>
|
||
da10bf75 | Thomas Kasulke | <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
da10bf75 | Thomas Kasulke | <table width="100%">
|
||
<td align="left" width="30%"><b>Dateiname</b></td>
|
||||
<td align="left" width="70%"><b>Webdavlink</b></td>
|
||||
d319704a | Moritz Bunkus | |;
|
||
5486b4a9 | Sven Schöling | foreach my $file (@{ $form->{WEBDAV} }) {
|
||
d319704a | Moritz Bunkus | $webdav_list .= qq|
|
||
0576299f | Moritz Bunkus | <tr>
|
||
7e2bf6ca | Moritz Bunkus | <td align="left">$file->{name}</td>
|
||
<td align="left"><a href="$file->{link}">$file->{type}</a></td>
|
||||
d319704a | Moritz Bunkus | </tr>
|
||
|;
|
||||
}
|
||||
$webdav_list .= qq|
|
||||
</table>
|
||||
</tr>
|
||||
|;
|
||||
print $webdav_list;
|
||||
}
|
||||
54e4131e | Moritz Bunkus | if ($form->{type} eq "credit_note") {
|
||
print qq|
|
||||
<tr>
|
||||
<td>
|
||||
da10bf75 | Thomas Kasulke | <table width="100%">
|
||
<tr class="listheading">
|
||||
<th colspan="6" class="listheading">|
|
||||
54e4131e | Moritz Bunkus | . $locale->text('Payments') . qq|</th>
|
||
</tr>
|
||||
|;
|
||||
} else {
|
||||
d319704a | Moritz Bunkus | print qq|
|
||
<tr>
|
||||
<td>
|
||||
da10bf75 | Thomas Kasulke | <table width="100%">
|
||
<tr class="listheading">
|
||||
<th colspan="6" class="listheading">|
|
||||
383022ae | Stephan Köhler | . $locale->text('Incoming Payments') . qq|</th>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
|;
|
||||
54e4131e | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my @column_index;
|
||
d319704a | Moritz Bunkus | if ($form->{currency} eq $form->{defaultcurrency}) {
|
||
@column_index = qw(datepaid source memo paid AR_paid);
|
||||
} else {
|
||||
@column_index = qw(datepaid source memo paid exchangerate AR_paid);
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my %column_data;
|
||
d319704a | Moritz Bunkus | $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
|
||
$column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
|
||||
$column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
|
||||
$column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
|
||||
$column_data{source} = "<th>" . $locale->text('Source') . "</th>";
|
||||
$column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
|
||||
print "
|
||||
<tr>
|
||||
";
|
||||
map { print "$column_data{$_}\n" } @column_index;
|
||||
print "
|
||||
</tr>
|
||||
";
|
||||
4d20c181 | Moritz Bunkus | my @triggers = ();
|
||
my $totalpaid = 0;
|
||||
a14a3ff5 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
|
||
5486b4a9 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
d319704a | Moritz Bunkus | |||
print "
|
||||
<tr>\n";
|
||||
$form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
|
||||
$form->{"selectAR_paid_$i"} =~
|
||||
s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
|
||||
# format amounts
|
||||
$totalpaid += $form->{"paid_$i"};
|
||||
bd32b607 | Philip Reetz | if ($form->{"paid_$i"}) {
|
||
$form->{"paid_$i"} =
|
||||
$form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
|
||||
}
|
||||
d319704a | Moritz Bunkus | $form->{"exchangerate_$i"} =
|
||
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
|
||||
fb37acdc | Moritz Bunkus | if ($form->{"exchangerate_$i"} == 0) {
|
||
$form->{"exchangerate_$i"} = "";
|
||||
}
|
||||
5486b4a9 | Sven Schöling | my $exchangerate = qq| |;
|
||
d319704a | Moritz Bunkus | if ($form->{currency} ne $form->{defaultcurrency}) {
|
||
if ($form->{"forex_$i"}) {
|
||||
da10bf75 | Thomas Kasulke | $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
|
||
d319704a | Moritz Bunkus | } else {
|
||
da10bf75 | Thomas Kasulke | $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
|
||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
da10bf75 | Thomas Kasulke | $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
|
||
d319704a | Moritz Bunkus | |||
$column_data{"paid_$i"} =
|
||||
be4e11d3 | Thomas Kasulke | qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
|
||
da10bf75 | Thomas Kasulke | $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
|
||
d319704a | Moritz Bunkus | $column_data{"AR_paid_$i"} =
|
||
da10bf75 | Thomas Kasulke | qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
|
||
d319704a | Moritz Bunkus | $column_data{"datepaid_$i"} =
|
||
be4e11d3 | Thomas Kasulke | qq|<td align="center"><input id="datepaid_$i" name="datepaid_$i" size="11" title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
|
||
a14a3ff5 | Moritz Bunkus | <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
|
||
d319704a | Moritz Bunkus | $column_data{"source_$i"} =
|
||
da10bf75 | Thomas Kasulke | qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
|
||
d319704a | Moritz Bunkus | $column_data{"memo_$i"} =
|
||
da10bf75 | Thomas Kasulke | qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
|
||
d319704a | Moritz Bunkus | |||
map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
|
||||
print "
|
||||
</tr>\n";
|
||||
a14a3ff5 | Moritz Bunkus | push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
|
||
d319704a | Moritz Bunkus | }
|
||
4d20c181 | Moritz Bunkus | my $paid_missing = $form->{oldinvtotal} - $totalpaid;
|
||
print qq|
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td align="center">| . $locale->text('Total') . qq|</td>
|
||||
<td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td align="center">| . $locale->text('Missing amount') . qq|</td>
|
||||
<td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
|
||||
</tr>
|
||||
|;
|
||||
fb4d2ffa | Moritz Bunkus | map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
|
||
da10bf75 | Thomas Kasulke | print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
|
||
383022ae | Stephan Köhler | </table>
|
||
d319704a | Moritz Bunkus | </td>
|
||
</tr>
|
||||
<tr>
|
||||
da10bf75 | Thomas Kasulke | <td><hr size="3" noshade></td>
|
||
d319704a | Moritz Bunkus | </tr>
|
||
<tr>
|
||||
<td>
|
||||
|;
|
||||
1514a9d0 | Moritz Bunkus | print_options();
|
||
d319704a | Moritz Bunkus | |||
print qq|
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|;
|
||||
5486b4a9 | Sven Schöling | my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
|
||
my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
|
||||
d319704a | Moritz Bunkus | |||
if ($form->{id}) {
|
||||
acf18ea9 | Philip Reetz | my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && (($totalpaid == 0) || ($totalpaid eq ""));
|
||
a104b890 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | print qq|
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Update') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Ship to') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Print') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
036fe04d | Moritz Bunkus | . $locale->text('E-mail') . qq|"> |;
|
||
da10bf75 | Thomas Kasulke | print qq|<input class="submit" type="submit" name="action" value="|
|
||
a104b890 | Moritz Bunkus | . $locale->text('Storno') . qq|"> | if ($show_storno);
|
||
da10bf75 | Thomas Kasulke | print qq|<input class="submit" type="submit" name="action" value="|
|
||
54e4131e | Moritz Bunkus | . $locale->text('Post Payment') . qq|">
|
||
98764afa | Philip Reetz | |;
|
||
da10bf75 | Thomas Kasulke | print qq|<input class="submit" type="submit" name="action" value="|
|
||
98764afa | Philip Reetz | . $locale->text('Use As Template') . qq|">
|
||
d319704a | Moritz Bunkus | |;
|
||
7a7f33b5 | Moritz Bunkus | if ($form->{id} && !($form->{type} eq "credit_note")) {
|
||
print qq|
|
||||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
54e4131e | Moritz Bunkus | . $locale->text('Credit Note') . qq|">
|
||
d319704a | Moritz Bunkus | |;
|
||
7a7f33b5 | Moritz Bunkus | }
|
||
9e117fbd | Philip Reetz | if ($form->{radier}) {
|
||
print qq|
|
||||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
9e117fbd | Philip Reetz | . $locale->text('Delete') . qq|">
|
||
|;
|
||||
7a7f33b5 | Moritz Bunkus | }
|
||
54e4131e | Moritz Bunkus | |||
d319704a | Moritz Bunkus | |||
if ($invdate > $closedto) {
|
||||
print qq|
|
||||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Order') . qq|">
|
||
|;
|
||||
}
|
||||
7a7f33b5 | Moritz Bunkus | print qq|
|
||
<input type="button" class="submit" onclick="follow_up_window()" value="|
|
||||
. $locale->text('Follow-Up')
|
||||
. qq|">|;
|
||||
d319704a | Moritz Bunkus | } else {
|
||
if ($invdate > $closedto) {
|
||||
da10bf75 | Thomas Kasulke | print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Update') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Ship to') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
383022ae | Stephan Köhler | . $locale->text('Preview') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('E-mail') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
383022ae | Stephan Köhler | . $locale->text('Print and Post') . qq|">
|
||
da10bf75 | Thomas Kasulke | <input class="submit" type="submit" name="action" value="|
|
||
bde667c2 | Moritz Bunkus | . $locale->text('Post') . qq|"> | .
|
||
NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
|
||||
'-class' => 'submit'));
|
||||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
2b89ec97 | Thomas Kasulke | # button for saving history
|
||
if($form->{id} ne "") {
|
||||
print qq|
|
||||
4e27e828 | Moritz Bunkus | <input type="button" class="submit" onclick="set_history_window(|
|
||
. Q($form->{id})
|
||||
. qq|);" name="history" id="history" value="|
|
||||
. $locale->text('history')
|
||||
ce47a234 | Thomas Kasulke | . qq|"> |;
|
||
2b89ec97 | Thomas Kasulke | }
|
||
# /button for saving history
|
||||
5486b4a9 | Sven Schöling | |||
# mark_as_paid button
|
||||
if($form->{id} ne "") {
|
||||
print qq|<input type="submit" class="submit" name="action" value="|
|
||||
ce47a234 | Thomas Kasulke | . $locale->text('mark as paid') . qq|">|;
|
||
}
|
||||
# /mark_as_paid button
|
||||
a14a3ff5 | Moritz Bunkus | print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
|
||
qq|
|
||||
d319704a | Moritz Bunkus | |||
da10bf75 | Thomas Kasulke | <input type="hidden" name="rowcount" value="$form->{rowcount}">
|
||
| .
|
||||
fb4d2ffa | Moritz Bunkus | $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
|
||
bde667c2 | Moritz Bunkus | . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
|
||
8c7e4493 | Moritz Bunkus | . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
|
||
82574e78 | Geoffrey Richardson | . $cgi->hidden('-name' => 'customer_discount', '-value' => [$form->{customer_discount}])
|
||
8c7e4493 | Moritz Bunkus | . qq|
|
||
d319704a | Moritz Bunkus | </form>
|
||
</body>
|
||||
</html>
|
||||
|;
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
ce47a234 | Thomas Kasulke | sub mark_as_paid {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | &mark_as_paid_common(\%myconfig,"ar");
|
||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ce47a234 | Thomas Kasulke | }
|
||
d319704a | Moritz Bunkus | sub update {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
$main::auth->assert('invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
ac517355 | Philip Reetz | my ($recursive_call) = shift;
|
||
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
|
||||
fb4d2ffa | Moritz Bunkus | |||
52983c08 | Sven Schöling | $form->{print_and_post} = 0 if $form->{second_run};
|
||
5486b4a9 | Sven Schöling | my $taxincluded = "checked" if $form->{taxincluded};
|
||
54e4131e | Moritz Bunkus | $form->{update} = 1;
|
||
5486b4a9 | Sven Schöling | &check_name("customer");
|
||
d319704a | Moritz Bunkus | |||
52983c08 | Sven Schöling | $form->{taxincluded} ||= $taxincluded;
|
||
d1d9b5a7 | Thomas Kasulke | |||
a53233e5 | Sven Schöling | $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
|
||
$form->{exchangerate} = $form->{forex} if $form->{forex};
|
||||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
52983c08 | Sven Schöling | next unless $form->{"paid_$i"};
|
||
map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
|
||||
a53233e5 | Sven Schöling | $form->{"forex_$i"} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
|
||
$form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
|
||||
d319704a | Moritz Bunkus | }
|
||
5486b4a9 | Sven Schöling | my $i = $form->{rowcount};
|
||
my $exchangerate = $form->{exchangerate} || 1;
|
||||
d319704a | Moritz Bunkus | |||
# if last row empty, check the form otherwise retrieve new item
|
||||
if ( ($form->{"partnumber_$i"} eq "")
|
||||
&& ($form->{"description_$i"} eq "")
|
||||
&& ($form->{"partsgroup_$i"} eq "")) {
|
||||
$form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
|
||||
&check_form;
|
||||
54e4131e | Moritz Bunkus | } else {
|
||
d319704a | Moritz Bunkus | IS->retrieve_item(\%myconfig, \%$form);
|
||
5486b4a9 | Sven Schöling | my $rows = scalar @{ $form->{item_list} };
|
||
d319704a | Moritz Bunkus | |||
82574e78 | Geoffrey Richardson | $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
|
||
d319704a | Moritz Bunkus | |||
if ($rows) {
|
||||
$form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
|
||||
if ($rows > 1) {
|
||||
&select_item;
|
||||
exit;
|
||||
} else {
|
||||
5486b4a9 | Sven Schöling | my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
|
||
ef73414c | Stephan Köhler | |||
52983c08 | Sven Schöling | map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
|
||
map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
|
||||
5486b4a9 | Sven Schöling | |||
52983c08 | Sven Schöling | $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
|
||
$form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
|
||||
d319704a | Moritz Bunkus | |||
1e251313 | Moritz Bunkus | $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
|
||
52983c08 | Sven Schöling | ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
|
||
5486b4a9 | Sven Schöling | my $decimalplaces = max 2, length $1;
|
||
d319704a | Moritz Bunkus | |||
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;
|
||||
}
|
||||
$form->{"listprice_$i"} /= $exchangerate;
|
||||
5486b4a9 | Sven Schöling | my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
|
||
52983c08 | Sven Schöling | 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};
|
||||
d319704a | Moritz Bunkus | |||
$form->{creditremaining} -= $amount;
|
||||
52983c08 | Sven Schöling | map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
|
||
d319704a | Moritz Bunkus | |||
52983c08 | Sven Schöling | $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
|
||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | if ($main::lizenzen) {
|
||
d319704a | Moritz Bunkus | if ($form->{"inventory_accno_$i"} ne "") {
|
||
$form->{"lizenzen_$i"} = qq|<option></option>|;
|
||||
5486b4a9 | Sven Schöling | foreach my $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
|
||
52983c08 | Sven Schöling | $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
|
||
d319704a | Moritz Bunkus | }
|
||
52983c08 | Sven Schöling | $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
|
||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
07d71c33 | Stephan Köhler | # get pricegroups for parts
|
||
ef73414c | Stephan Köhler | IS->get_pricegroups_for_parts(\%myconfig, \%$form);
|
||
07d71c33 | Stephan Köhler | |||
# build up html code for prices_$i
|
||||
&set_pricegroup($i);
|
||||
d319704a | Moritz Bunkus | }
|
||
&display_form;
|
||||
} else {
|
||||
# ok, so this is a new part
|
||||
# ask if it is a part or service item
|
||||
if ( $form->{"partsgroup_$i"}
|
||||
&& ($form->{"partsnumber_$i"} eq "")
|
||||
&& ($form->{"description_$i"} eq "")) {
|
||||
$form->{rowcount}--;
|
||||
$form->{"discount_$i"} = "";
|
||||
d83df93a | Moritz Bunkus | display_form();
|
||
d319704a | Moritz Bunkus | |||
d83df93a | Moritz Bunkus | } else {
|
||
d319704a | Moritz Bunkus | $form->{"id_$i"} = 0;
|
||
d83df93a | Moritz Bunkus | new_item();
|
||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
}
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
2b89ec97 | Thomas Kasulke | |||
54e4131e | Moritz Bunkus | sub post_payment {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
$main::auth->assert('invoice_edit');
|
||||
fb37acdc | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | our $invdate;
|
||
8c7e4493 | Moritz Bunkus | |||
fb37acdc | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
5486b4a9 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
bd32b607 | Philip Reetz | if ($form->{"paid_$i"}) {
|
||
5486b4a9 | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
54e4131e | Moritz Bunkus | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
$form->error($locale->text('Cannot post payment for a closed period!'))
|
||||
9e06d0e4 | Philip Reetz | if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
|
||
54e4131e | Moritz Bunkus | |||
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};
|
||||
b3501bdf | Moritz Bunkus | relink_accounts();
|
||
d5c1e4fa | Moritz Bunkus | $form->redirect($locale->text('Payment posted!'))
|
||
54e4131e | Moritz Bunkus | if (IS->post_payment(\%myconfig, \%$form));
|
||
$form->error($locale->text('Cannot post payment!'));
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | |||
sub post {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
fb37acdc | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
$main::auth->assert('invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
fb37acdc | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
d319704a | Moritz Bunkus | $form->isblank("invdate", $locale->text('Invoice Date missing!'));
|
||
$form->isblank("customer", $locale->text('Customer missing!'));
|
||||
9e06d0e4 | Philip Reetz | $form->error($locale->text('Cannot post invoice for a closed period!'))
|
||
if ($form->date_closed($form->{"invdate"}, \%myconfig));
|
||||
d319704a | Moritz Bunkus | |||
a426a839 | Moritz Bunkus | $form->{invnumber} =~ s/^\s*//g;
|
||
$form->{invnumber} =~ s/\s*$//g;
|
||||
d319704a | Moritz Bunkus | # if oldcustomer ne customer redo form
|
||
5486b4a9 | Sven Schöling | if (&check_name('customer')) {
|
||
d319704a | Moritz Bunkus | &update;
|
||
exit;
|
||||
}
|
||||
07d71c33 | Stephan Köhler | if ($form->{second_run}) {
|
||
$form->{print_and_post} = 0;
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
&validate_items;
|
||||
5486b4a9 | Sven Schöling | my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
|
||
my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
|
||||
d319704a | Moritz Bunkus | |||
$form->error($locale->text('Cannot post invoice for a closed period!'))
|
||||
if ($invdate <= $closedto);
|
||||
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
|
||||
if ($form->{currency} ne $form->{defaultcurrency});
|
||||
5486b4a9 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
5563e116 | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
5486b4a9 | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
d319704a | Moritz Bunkus | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
$form->error($locale->text('Cannot post payment for a closed period!'))
|
||||
9e06d0e4 | Philip Reetz | if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
|
||
d319704a | Moritz Bunkus | |||
if ($form->{currency} ne $form->{defaultcurrency}) {
|
||||
$form->{"exchangerate_$i"} = $form->{exchangerate}
|
||||
if ($invdate == $datepaid);
|
||||
$form->isblank("exchangerate_$i",
|
||||
$locale->text('Exchangerate for payment missing!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
34e47354 | Moritz Bunkus | ($form->{AR}) = split /--/, $form->{AR};
|
||
($form->{AR_paid}) = split /--/, $form->{AR_paid};
|
||||
$form->{storno} ||= 0;
|
||||
d319704a | Moritz Bunkus | |||
$form->{label} = $locale->text('Invoice');
|
||||
$form->{id} = 0 if $form->{postasnew};
|
||||
6dce043f | Stephan Köhler | # get new invnumber in sequence if no invnumber is given or if posasnew was requested
|
||
7712480e | Moritz Bunkus | if ($form->{postasnew}) {
|
||
54e4131e | Moritz Bunkus | if ($form->{type} eq "credit_note") {
|
||
7712480e | Moritz Bunkus | undef($form->{cnnumber});
|
||
54e4131e | Moritz Bunkus | } else {
|
||
7712480e | Moritz Bunkus | undef($form->{invnumber});
|
||
54e4131e | Moritz Bunkus | }
|
||
6dce043f | Stephan Köhler | }
|
||
7712480e | Moritz Bunkus | |||
b3501bdf | Moritz Bunkus | relink_accounts();
|
||
d946f59b | Sven Schöling | $form->error($locale->text('Cannot post invoice!'))
|
||
unless IS->post_invoice(\%myconfig, \%$form);
|
||||
remove_draft() if $form->{remove_draft};
|
||||
if(!exists $form->{addition}) {
|
||||
a0f6a00c | Thomas Kasulke | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
d946f59b | Sven Schöling | $form->{addition} = $print_post ? "PRINTED AND POSTED" :
|
||
$form->{storno} ? "STORNO" :
|
||||
"POSTED";
|
||||
$form->save_history($form->dbconnect(\%myconfig));
|
||||
383022ae | Stephan Köhler | }
|
||
fb4d2ffa | Moritz Bunkus | |||
d946f59b | Sven Schöling | $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
|
||
unless $print_post;
|
||||
d319704a | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
383022ae | Stephan Köhler | sub print_and_post {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
383022ae | Stephan Köhler | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $old_form = new Form;
|
||
383022ae | Stephan Köhler | $print_post = 1;
|
||
$form->{print_and_post} = 1;
|
||||
&post();
|
||||
07d71c33 | Stephan Köhler | |||
8f3dc0b4 | Stephan Köhler | &edit();
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
383022ae | Stephan Köhler | |||
}
|
||||
98764afa | Philip Reetz | sub use_as_template {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
98764afa | Philip Reetz | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
9419dfc9 | Philip Reetz | 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);
|
||
98764afa | Philip Reetz | $form->{paidaccounts} = 1;
|
||
$form->{rowcount}--;
|
||||
$form->{invdate} = $form->current_date(\%myconfig);
|
||||
&display_form;
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
98764afa | Philip Reetz | }
|
||
54e4131e | Moritz Bunkus | sub storno {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
54e4131e | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
$main::auth->assert('invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
54e4131e | Moritz Bunkus | if ($form->{storno}) {
|
||
$form->error($locale->text('Cannot storno storno invoice!'));
|
||||
}
|
||||
a1a3bfd8 | Moritz Bunkus | if (IS->has_storno(\%myconfig, $form, "ar")) {
|
||
213317d3 | Moritz Bunkus | $form->error($locale->text("Invoice has already been storno'd!"));
|
||
}
|
||||
8c7e4493 | Moritz Bunkus | map({ my $key = $_; delete($form->{$key}) unless (grep({ $key eq $_ } qw(id login password stylesheet type))); } keys(%{ $form }));
|
||
7bc5598c | Moritz Bunkus | |||
3740b503 | Moritz Bunkus | invoice_links();
|
||
prepare_invoice();
|
||||
7bc5598c | Moritz Bunkus | relink_accounts();
|
||
3740b503 | Moritz Bunkus | # 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 };
|
||||
54e4131e | Moritz Bunkus | $form->{storno_id} = $form->{id};
|
||
$form->{storno} = 1;
|
||||
$form->{id} = "";
|
||||
$form->{invnumber} = "Storno zu " . $form->{invnumber};
|
||||
3740b503 | Moritz Bunkus | $form->{rowcount}++;
|
||
54e4131e | Moritz Bunkus | |||
3740b503 | Moritz Bunkus | post();
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
383022ae | Stephan Köhler | sub preview {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
383022ae | Stephan Köhler | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
383022ae | Stephan Köhler | $form->{preview} = 1;
|
||
5486b4a9 | Sven Schöling | my $old_form = new Form;
|
||
383022ae | Stephan Köhler | for (keys %$form) { $old_form->{$_} = $form->{$_} }
|
||
&print_form($old_form);
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
383022ae | Stephan Köhler | |||
}
|
||||
d319704a | Moritz Bunkus | sub delete {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
07d71c33 | Stephan Köhler | if ($form->{second_run}) {
|
||
$form->{print_and_post} = 0;
|
||||
}
|
||||
d319704a | Moritz Bunkus | $form->header;
|
||
print qq|
|
||||
<body>
|
||||
da10bf75 | Thomas Kasulke | <form method="post" action="$form->{script}">
|
||
d319704a | Moritz Bunkus | |;
|
||
# delete action variable
|
||||
map { delete $form->{$_} } qw(action header);
|
||||
5486b4a9 | Sven Schöling | foreach my $key (keys %$form) {
|
||
8c7e4493 | Moritz Bunkus | next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
|
||
d319704a | Moritz Bunkus | $form->{$key} =~ s/\"/"/g;
|
||
da10bf75 | Thomas Kasulke | print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
|
||
d319704a | Moritz Bunkus | }
|
||
print qq|
|
||||
da10bf75 | Thomas Kasulke | <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
|
||
d319704a | Moritz Bunkus | |||
<h4>|
|
||||
. $locale->text('Are you sure you want to delete Invoice Number')
|
||||
. qq| $form->{invnumber}
|
||||
</h4>
|
||||
<p>
|
||||
da10bf75 | Thomas Kasulke | <input name="action" class="submit" type="submit" value="|
|
||
d319704a | Moritz Bunkus | . $locale->text('Yes') . qq|">
|
||
</form>
|
||||
|;
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
54e4131e | Moritz Bunkus | sub credit_note {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
54e4131e | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
$main::auth->assert('invoice_edit');
|
||||
8c7e4493 | Moritz Bunkus | |||
54e4131e | Moritz Bunkus | $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';
|
||||
5486b4a9 | Sven Schöling | our $script = "is";
|
||
our $buysell = 'buy';
|
||||
fb4d2ffa | Moritz Bunkus | |||
54e4131e | Moritz Bunkus | |||
# 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";
|
||||
5486b4a9 | Sven Schöling | map { $form->{"select$_"} = "" } ($form->{vc}, 'currency');
|
||
54e4131e | Moritz Bunkus | |||
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
|
||||
qw(creditlimit creditremaining);
|
||||
5486b4a9 | Sven Schöling | my $currency = $form->{currency};
|
||
54e4131e | Moritz Bunkus | &invoice_links;
|
||
$form->{currency} = $currency;
|
||||
a53233e5 | Sven Schöling | $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
|
||
$form->{exchangerate} = $form->{forex} || '';
|
||||
54e4131e | Moritz Bunkus | |||
$form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
|
||||
&prepare_invoice;
|
||||
&display_form;
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
54e4131e | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | sub yes {
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
5486b4a9 | Sven Schöling | if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
|
||
2b89ec97 | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition}) {
|
||||
fb4d2ffa | Moritz Bunkus | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
2b89ec97 | Thomas Kasulke | $form->{addition} = "DELETED";
|
||
$form->save_history($form->dbconnect(\%myconfig));
|
||||
}
|
||||
fb4d2ffa | Moritz Bunkus | # /saving the history
|
||
$form->redirect($locale->text('Invoice deleted!'));
|
||||
2b89ec97 | Thomas Kasulke | }
|
||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot delete invoice!'));
|
||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
d946f59b | Sven Schöling | |||
sub e_mail {
|
||||
5486b4a9 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
d946f59b | Sven Schöling | |||
5486b4a9 | Sven Schöling | $main::auth->assert('invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
ffea1346 | Moritz Bunkus | if (!$form->{id}) {
|
||
$print_post = 1;
|
||||
d946f59b | Sven Schöling | |||
ffea1346 | Moritz Bunkus | my $saved_form = save_form();
|
||
d946f59b | Sven Schöling | |||
ffea1346 | Moritz Bunkus | post();
|
||
8c7e4493 | Moritz Bunkus | restore_form($saved_form, 0, qw(id invnumber));
|
||
ffea1346 | Moritz Bunkus | }
|
||
edit_e_mail();
|
||||
d946f59b | Sven Schöling | |||
5486b4a9 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d946f59b | Sven Schöling | }
|