return $main::lxdebug->leave_sub() if (load_draft_maybe());
- $form->{title} = $locale->text('Add Vendor Invoice');
+ $form->{title} = $locale->text('Record Vendor Invoice');
&invoice_links;
&prepare_invoice;
$form->{vc} = 'vendor';
# create links
- $form->{webdav} = $main::webdav;
+ $form->{webdav} = $::lx_office_conf{features}->{webdav};
$form->{jsscript} = 1;
$form->create_links("AP", \%myconfig, "vendor");
}
}
- my ($payment_id, $language_id, $taxzone_id);
+ my ($payment_id, $language_id, $taxzone_id, $currency);
if ($form->{payment_id}) {
$payment_id = $form->{payment_id};
}
if ($form->{taxzone_id}) {
$taxzone_id = $form->{taxzone_id};
}
+ if ($form->{currency}) {
+ $currency = $form->{currency};
+ }
my $cp_id = $form->{cp_id};
IR->get_vendor(\%myconfig, \%$form);
if ($taxzone_id) {
$form->{taxzone_id} = $taxzone_id;
}
+ if ($currency) {
+ $form->{currency} = $currency;
+ }
my @curr = split(/:/, $form->{currencies}); #seems to be missing
map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
foreach my $key (keys %{ $form->{AP_links} }) {
foreach my $ref (@{ $form->{AP_links}{$key} }) {
- $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
+ $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
}
next unless $form->{acc_trans}{$key};
$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};
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};
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
$form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
+ # Standard Konto für Umlaufvermögen
+ my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
for my $i (1 .. $form->{paidaccounts}) {
+ $form->{"changeable_$i"} = 1;
+ if ($::lx_office_conf{features}->{payments_changeable} == 0) {
+ # never
+ $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
+ } elsif ($::lx_office_conf{features}->{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};
- $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
+ if (!$form->{"AP_paid_$i"}) {
+ $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
+ } else {
+ $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
+ }
+
$totalpaid += $form->{"paid_$i"};
}
$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 {
# 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 "") {
$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);
$main::lxdebug->leave_sub();
}
-sub set_duedate_vendor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
+sub get_duedate_vendor {
+ $::lxdebug->enter_sub;
- print $form->ajax_response_header(), IR->get_duedate('vendor_id' => $form->{vendor_id},
- 'invdate' => $form->{invdate},
- 'default' => $form->{old_duedate});
+ my $result = 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;
}