X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=4cd96ca9f9322cd318315884980ba7ad8e599a16;hb=b8125c17c8add08c9b84fb054f797547a853dd3a;hp=e90b12cf651161bc64a9bdc9dbfc7f53aeb0fc82;hpb=5f6d6d4eaca3a3d238c678ef3f2a1fe676c3a77a;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index e90b12cf6..4cd96ca9f 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -58,6 +58,10 @@ sub add { $main::auth->assert('vendor_invoice_edit'); + if (!$::instance_conf->get_allow_new_purchase_invoice) { + $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")); + } + return $main::lxdebug->leave_sub() if (load_draft_maybe()); $form->{title} = $locale->text('Record Vendor Invoice'); @@ -203,6 +207,8 @@ sub prepare_invoice { $main::auth->assert('vendor_invoice_edit'); + $form->{type} = "purchase_invoice"; + if ($form->{id}) { map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber); @@ -327,11 +333,11 @@ sub form_header { 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 show_details gldate + convert_from_do_ids convert_from_oe_ids show_details gldate useasnew ), @custom_hiddens, map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}]; - $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery)); + $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part)); $form->header(); @@ -505,6 +511,20 @@ sub update { if ($sellprice) { $form->{"sellprice_$i"} = $sellprice; } else { + my $record = _make_record(); + my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record); + my $best_price = $price_source->best_price; + my $best_discount = $price_source->best_discount; + + if ($best_price) { + $::form->{"sellprice_$i"} = $best_price->price; + $::form->{"active_price_source_$i"} = $best_price->source; + } + if ($best_discount) { + $::form->{"discount_$i"} = $best_discount->discount; + $::form->{"active_discount_source_$i"} = $best_discount->source; + } + # if there is an exchange rate adjust sellprice $form->{"sellprice_$i"} /= $exchangerate; } @@ -566,6 +586,8 @@ 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_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form }; + # set new ids for storno invoice + delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"}; # saving the history if(!exists $form->{addition} && $form->{id} ne "") { @@ -598,6 +620,10 @@ sub use_as_new { $form->{paidaccounts} = 1; $form->{rowcount}--; $form->{invdate} = $form->current_date(\%myconfig); + + $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"}; + + $form->{useasnew} = 1; &display_form; $main::lxdebug->leave_sub(); @@ -701,7 +727,8 @@ sub post { $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->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});