X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/8b5bed7fe52952d9c09b3cc18ef483f6670a78d0..dbf9afadb952dc9e5aae33879af96a703f3baf43:/bin/mozilla/ap.pl diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 8e9e4cae1..2c886322f 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -39,7 +39,7 @@ use List::UtilsBy qw(sort_by); use SL::AP; use SL::FU; use SL::GL; -use SL::Helper::Flash qw(flash); +use SL::Helper::Flash qw(flash flash_later); use SL::IR; use SL::IS; use SL::ReportGenerator; @@ -130,6 +130,7 @@ sub load_record_template { $::form->{currency} = $template->currency->name; $::form->{direct_debit} = $template->direct_debit; $::form->{globalproject_id} = $template->project_id; + $::form->{payment_id} = $template->payment_id; $::form->{AP_chart_id} = $template->ar_ap_chart_id; $::form->{transdate} = $today->to_kivitendo; $::form->{duedate} = $today->to_kivitendo; @@ -213,6 +214,7 @@ sub save_record_template { vendor_id => $::form->{vendor_id} || undef, department_id => $::form->{department_id} || undef, project_id => $::form->{globalproject_id} || undef, + payment_id => $::form->{payment_id} || undef, taxincluded => $::form->{taxincluded} ? 1 : 0, direct_debit => $::form->{direct_debit} ? 1 : 0, ordnumber => $::form->{ordnumber}, @@ -449,7 +451,7 @@ sub form_header { my $follow_up_vc = $form->{vendor_id} ? SL::DB::Vendor->load_cached($form->{vendor_id})->name : ''; my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)"; - $::request->layout->add_javascripts("autocomplete_chart.js", "show_vc_details.js", "show_history.js", "follow_up.js", "kivi.Draft.js", "kivi.GL.js", "kivi.RecordTemplate.js", "kivi.File.js", "kivi.AP.js", "kivi.CustomerVendor.js", "kivi.Validator.js", "autocomplete_project.js"); + $::request->layout->add_javascripts("autocomplete_chart.js", "show_vc_details.js", "show_history.js", "follow_up.js", "kivi.Draft.js", "kivi.SalesPurchase.js", "kivi.GL.js", "kivi.RecordTemplate.js", "kivi.File.js", "kivi.AP.js", "kivi.CustomerVendor.js", "kivi.Validator.js", "autocomplete_project.js"); # $form->{totalpaid} is used by the action bar setup to determine # whether or not canceling is allowed. Therefore it must be # calculated prior to the action bar setup. @@ -559,10 +561,11 @@ sub form_header { $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid}; + $form->{payment_id} = $form->{invoice_obj}->{payment_id} // $form->{payment_id}; print $form->parse_html_template('ap/form_header', { today => DateTime->today, currencies => SL::DB::Manager::Currency->get_all_sorted, - payment_terms => SL::DB::Manager::PaymentTerm->get_all_sorted(query => [ or => [ obsolete => 0, id => $::form->{payment_id}*1 ]]), + payment_terms => SL::DB::Manager::PaymentTerm->get_all_sorted(query => [ or => [ obsolete => 0, id => $form->{payment_id}*1 ]]), }); $main::lxdebug->leave_sub(); @@ -854,13 +857,30 @@ sub post { $form->{what_done} = "invoice"; $form->save_history; } - # no restore_from_session_id needed. we like to have a newly generated - # list of invoices for bank transactions - print $form->redirect_header($form->{callback}) if ($form->{callback} =~ /BankTransaction/); - $form->redirect($locale->text('AP transaction posted.') . ' ' . $locale->text('ID') . ': ' . $form->{id}) unless $inline; - # TODO Add callback/return flag in myconfig - # With version 3.5 we can add documents, but only after posting. there should be a flag in myconfig for the user - # $form->{callback} ||= 'ap.pl?action=edit&id=' . $form->{id} if $myconfig{no_reset_arap}; + + if (!$inline) { + my $msg = $locale->text("AP transaction '#1' posted (ID: #2)", $form->{invnumber}, $form->{id}); + if ($form->{callback} =~ /BankTransaction/) { + # no restore_from_session_id needed. we like to have a newly generated + # list of invoices for bank transactions + SL::Helper::Flash::flash_later('info', $msg); + print $form->redirect_header($form->{callback}); + $::dispatcher->end_request; + + } elsif ('doc-tab' eq $form->{after_action}) { + # Redirect with callback containing a fragment does not work (by now) + # because the callback info is stored in the session an parsing the + # callback parameters does not support fragments (see SL::Form::redirect). + # So use flash_later for the message and redirect_headers for redirecting. + my $add_doc_url = build_std_url("script=ap.pl", 'action=edit', 'id=' . E($form->{id}), 'fragment=ui-tabs-docs'); + SL::Helper::Flash::flash_later('info', $msg); + print $form->redirect_header($add_doc_url); + $::dispatcher->end_request; + + } else { + $form->redirect($msg); + } + } } else { $form->error($locale->text('Cannot post transaction!')); @@ -1058,11 +1078,14 @@ sub ap_transactions { my $department_description; $department_description = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id}; + my $project_description; + $project_description = SL::DB::Manager::Project->find_by(id => $form->{project_id})->description if $form->{project_id}; my @options; push @options, $locale->text('Vendor') . " : $form->{vendor}" if ($form->{vendor}); push @options, $locale->text('Contact Person') . " : $form->{cp_name}" if ($form->{cp_name}); push @options, $locale->text('Department') . " : $department_description" if ($form->{department_id}); + push @options, $locale->text('Project') . " : $project_description" if ($project_description); push @options, $locale->text('Invoice Number') . " : $form->{invnumber}" if ($form->{invnumber}); push @options, $locale->text('Order Number') . " : $form->{ordnumber}" if ($form->{ordnumber}); push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes}); @@ -1323,6 +1346,34 @@ sub setup_ap_display_form_action_bar { $is_linked_bank_transaction = 1; } + my $create_post_action = sub { + # $_[0]: description + # $_[1]: after_action + action => [ + $_[0], + submit => [ '#form', { action => "post", after_action => $_[1] } ], + checks => [ 'kivi.validate_form', 'kivi.AP.check_fields_before_posting', 'kivi.AP.check_duplicate_invnumber' ], + disabled => !$may_edit_create ? t8('You must not change this AP transaction.') + : $is_closed ? t8('The billing period has already been locked.') + : $is_storno ? t8('A canceled invoice cannot be posted.') + : ($::form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.') + : ($::form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.') + : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.') + : undef, + ], + }; + + my @post_entries; + if ($::instance_conf->get_ap_add_doc && $::instance_conf->get_doc_storage) { + @post_entries = ( $create_post_action->(t8('Post'), 'doc-tab'), + $create_post_action->(t8('Post and new booking')) ); + } elsif ($::instance_conf->get_doc_storage) { + @post_entries = ( $create_post_action->(t8('Post')), + $create_post_action->(t8('Post and upload document'), 'doc-tab') ); + } else { + @post_entries = ( $create_post_action->(t8('Post')) ); + } + for my $bar ($::request->layout->get('actionbar')) { $bar->add( action => [ @@ -1333,20 +1384,8 @@ sub setup_ap_display_form_action_bar { accesskey => 'enter', disabled => !$may_edit_create ? t8('You must not change this AP transaction.') : undef, ], - combobox => [ - action => [ - t8('Post'), - submit => [ '#form', { action => "post" } ], - checks => [ 'kivi.validate_form', 'kivi.AP.check_fields_before_posting', 'kivi.AP.check_duplicate_invnumber' ], - disabled => !$may_edit_create ? t8('You must not change this AP transaction.') - : $is_closed ? t8('The billing period has already been locked.') - : $is_storno ? t8('A canceled invoice cannot be posted.') - : ($::form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.') - : ($::form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.') - : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.') - : undef, - ], + @post_entries, action => [ t8('Post Payment'), submit => [ '#form', { action => "post_payment" } ],