use SL::IR;
use SL::IS;
use SL::PE;
+use SL::DB::Default;
use List::Util qw(max sum);
require "bin/mozilla/io.pl";
$form->{vc} = 'vendor';
# create links
- $form->{webdav} = $::lx_office_conf{system}->{webdav};
- $form->{jsscript} = 1;
+ $form->{webdav} = $::instance_conf->get_webdav;
$form->create_links("AP", \%myconfig, "vendor");
}
}
- my ($payment_id, $language_id, $taxzone_id);
- if ($form->{payment_id}) {
- $payment_id = $form->{payment_id};
- }
- if ($form->{language_id}) {
- $language_id = $form->{language_id};
- }
- if ($form->{taxzone_id}) {
- $taxzone_id = $form->{taxzone_id};
- }
+ $form->backup_vars(qw(payment_id language_id taxzone_id
+ currency delivery_term_id intnotes cp_id));
- my $cp_id = $form->{cp_id};
IR->get_vendor(\%myconfig, \%$form);
IR->retrieve_invoice(\%myconfig, \%$form);
- $form->{cp_id} = $cp_id;
- if ($payment_id) {
- $form->{payment_id} = $payment_id;
- }
- if ($language_id) {
- $form->{language_id} = $language_id;
- }
- if ($taxzone_id) {
- $form->{taxzone_id} = $taxzone_id;
- }
+ $form->restore_vars(qw(payment_id language_id taxzone_id
+ currency delivery_term_id intnotes cp_id));
- my @curr = split(/:/, $form->{currencies}); #seems to be missing
+ my @curr = $form->get_all_currencies();
map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
$form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
$form->{"AP_paid_$i"} =
"$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
+ $form->{"acc_trans_id_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{acc_trans_id};
# reverse paid
$form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
$form->{"datepaid_$i"} =
$form->{acc_trans}{$key}->[$i - 1]->{transdate};
+ $form->{"gldate_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
$form->{"forex_$i"} = $form->{"exchangerate_$i"} =
$form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
$form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
foreach my $ref (@{ $form->{invoice_details} }) {
$i++;
map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
+ # übernommen aus is.pl Fix für Bug 1642. Nebenwirkungen? jb 12.5.2011
+ # getestet: Lieferantenauftrag -> Rechnung i.O.
+ # Lieferantenauftrag -> Lieferschein -> Rechnung i.O.
+ # Werte: 20% (Lieferantenrabatt), 12,4% individuell und 0,4 individuell s.a.
+ # Screenshot zu Bug 1642
+ $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
$dec = length $dec;
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- my $cgi = $main::cgi;
+ my $cgi = $::request->{cgi};
- $main::auth->assert('invoice_edit');
+ $main::auth->assert('vendor_invoice_edit');
my %TMPL_VAR = ();
my @custom_hiddens;
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- my $set_duedate_url = "$form->{script}?action=set_duedate";
-
- push @ { $form->{AJAX} }, new CGI::Ajax( 'set_duedate' => $set_duedate_url );
-
my @old_project_ids = ($form->{"globalproject_id"});
map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
- $form->get_lists("contacts" => "ALL_CONTACTS",
- "shipto" => "ALL_SHIPTO",
- "projects" => { "key" => "ALL_PROJECTS",
+ $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
"all" => 0,
"old_id" => \@old_project_ids },
- "employees" => "ALL_EMPLOYEES",
"taxzones" => "ALL_TAXZONES",
"currencies" => "ALL_CURRENCIES",
"vendors" => "ALL_VENDORS",
"departments" => "all_departments",
"price_factors" => "ALL_PRICE_FACTORS");
- $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{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
+ $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ or => [
+ cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+ and => [
+ cp_cv_id => undef,
+ cp_id => $::form->{cp_id} * 1
+ ]
+ ]
+ ]);
$TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
# customer
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};
+ # show_exchangerate is also later needed in another template
+ $form->{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;
+ '-values' => \@values, '-labels' => \%labels,
+ '-onchange' => "document.getElementById('update_button').click();"
+ )) 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} =~ /-/;
- $form->{fokus} = "invoice.vendor";
-
my $follow_up_vc = $form->{vendor};
$follow_up_vc =~ s/--\d*\s*$//;
$TMPL_VAR{vendor_name} = $follow_up_vc;
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
+ convert_from_do_ids convert_from_oe_ids show_details gldate
), @custom_hiddens,
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
- $form->{jsscript} = 1;
+ $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase));
+
$form->header();
print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- $main::auth->assert('invoice_edit');
+ $main::auth->assert('vendor_invoice_edit');
$form->{invtotal} = $form->{invsubtotal};
$form->{oldinvtotal} = $form->{invtotal};
my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
for my $i (1 .. $form->{paidaccounts}) {
+ $form->{"changeable_$i"} = 1;
+ if (SL::DB::Default->get->payments_changeable == 0) {
+ # never
+ $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
+ } elsif (SL::DB::Default->get->payments_changeable == 2) {
+ # on the same day
+ $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
+ ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
+ }
+
$form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
if (!$form->{"AP_paid_$i"}) {
$form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
$totalpaid += $form->{"paid_$i"};
}
+ $form->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
+
print $form->parse_html_template('ir/form_footer', {
is_type_credit_note => ($form->{type} eq "credit_note"),
totalpaid => $totalpaid,
paid_missing => $form->{invtotal} - $totalpaid,
show_storno => $form->{id} && !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap") && !$totalpaid,
- show_delete => ($form->current_date(\%myconfig) eq $form->{gldate}),
+ show_delete => ($::instance_conf->get_ir_changeable == 2)
+ ? ($form->current_date(\%myconfig) eq $form->{gldate})
+ : ($::instance_conf->get_ir_changeable == 1),
});
##print $form->parse_html_template('ir/_payments'); # parser
##print $form->parse_html_template('webdav/_list'); # parser
$main::auth->assert('vendor_invoice_edit');
-# map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
-
&check_name('vendor');
+ if (!$form->{forex}) { # read exchangerate from input field (not hidden)
+ $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
+ }
$form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
$form->{exchangerate} = $form->{forex} if $form->{forex};
if ($rows > 1) {
- &select_item;
+ select_item(mode => 'IR');
::end_of_request();
} else {
$form->error($locale->text("Invoice has already been storno'd!"));
}
+ $form->error($locale->text('Cannot post storno for a closed period!'))
+ if ( $form->date_closed($form->{invdate}, \%myconfig));
+
my $employee_id = $form->{employee_id};
invoice_links();
prepare_invoice();
# 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 };
+ map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
}
-sub use_as_template {
+sub use_as_new {
$main::lxdebug->enter_sub();
my $form = $main::form;
$main::auth->assert('vendor_invoice_edit');
- map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
+ map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
$form->{paidaccounts} = 1;
$form->{rowcount}--;
$form->{invdate} = $form->current_date(\%myconfig);
my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
my $max_datepaid = _max_datepaid();
+ $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
+ if ($form->date_max_future($invdate, \%myconfig));
$form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
$form->header;
print qq|
-<body>
-
<form method=post action=$form->{script}>
|;
$main::lxdebug->leave_sub();
}
-sub set_duedate_vendor {
- $main::lxdebug->enter_sub();
+sub get_duedate_vendor {
+ $::lxdebug->enter_sub;
- my $form = $main::form;
+ my $result = IR->get_duedate(
+ vendor_id => $::form->{vendor_id},
+ invdate => $::form->{invdate},
+ default => $::form->{old_duedate},
+ );
- print $form->ajax_response_header(), IR->get_duedate('vendor_id' => $form->{vendor_id},
- 'invdate' => $form->{invdate},
- 'default' => $form->{old_duedate});
-
- $main::lxdebug->leave_sub();
+ print $::form->ajax_response_header, $result;
+ $::lxdebug->leave_sub;
}