X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=f909d86f6350fad78abedc1d64c2537af1576147;hb=175dd1fb247e46407ebc773b8103fc773a806fdf;hp=2c964d2d53d8edf820354ef2d27eda9296ce6740;hpb=a590a6518025280c2d6e76c87641764ca6198521;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 2c964d2d5..f909d86f6 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -59,7 +59,7 @@ sub add { 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; @@ -100,7 +100,7 @@ sub invoice_links { $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"); @@ -116,7 +116,7 @@ sub invoice_links { } } - my ($payment_id, $language_id, $taxzone_id); + my ($payment_id, $language_id, $taxzone_id, $currency); if ($form->{payment_id}) { $payment_id = $form->{payment_id}; } @@ -126,6 +126,9 @@ sub invoice_links { 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); @@ -141,6 +144,9 @@ sub invoice_links { 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} .= ""; } next unless $form->{acc_trans}{$key}; @@ -181,10 +187,12 @@ sub invoice_links { $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}; @@ -226,6 +234,12 @@ sub prepare_invoice { 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; @@ -254,9 +268,9 @@ sub form_header { 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; @@ -266,28 +280,28 @@ sub form_header { $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 @@ -302,9 +316,12 @@ sub form_header { 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}; @@ -354,7 +371,7 @@ sub form_footer { 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}; @@ -393,9 +410,27 @@ sub form_footer { $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"}; } @@ -433,10 +468,11 @@ sub update { $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}; @@ -467,7 +503,7 @@ sub update { if ($rows > 1) { - &select_item; + select_item(mode => 'IR'); ::end_of_request(); } else { @@ -546,7 +582,7 @@ sub storno { # 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 "") { @@ -575,7 +611,7 @@ sub use_as_template { $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); @@ -794,14 +830,15 @@ sub yes { $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; }