X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=dd4f113ce2b772075a9350a79fddb4c0889fae02;hb=e47236274c273b267417094489eb8ab5ec492c7a;hp=744e0c558caddc2f03d22b3aa8e2226b37f58113;hpb=ab03d1c3d38c67e10c8c2fe8db08ee4cb1bcde5c;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 744e0c558..dd4f113ce 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -24,7 +24,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Inventory received module @@ -34,15 +35,18 @@ use SL::FU; use SL::IR; use SL::IS; -use SL::PE; +use SL::DB::BankTransactionAccTrans; use SL::DB::Default; +use SL::DB::Department; +use SL::DB::Project; +use SL::DB::PurchaseInvoice; +use SL::DB::Vendor; +use List::MoreUtils qw(uniq); use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); require "bin/mozilla/io.pl"; -require "bin/mozilla/invoice_io.pl"; -require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; -require "bin/mozilla/drafts.pl"; use strict; @@ -50,6 +54,20 @@ use strict; # end of main +sub _may_view_or_edit_this_invoice { + return 1 if $::auth->assert('ap_transactions', 1); # may edit all invoices + return 0 if !$::form->{id}; # creating new invoices isn't allowed without invoice_edit + return 0 if !$::form->{globalproject_id}; # existing records without a project ID are not allowed + return SL::DB::Project->new(id => $::form->{globalproject_id})->load->may_employee_view_project_invoices(SL::DB::Manager::Employee->current); +} + +sub _assert_access { + my $cache = $::request->cache('ap.pl::_assert_access'); + + $cache->{_may_view_or_edit_this_invoice} = _may_view_or_edit_this_invoice() if !exists $cache->{_may_view_or_edit_this_invoice}; + $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")) if ! $cache->{_may_view_or_edit_this_invoice}; +} + sub add { $main::lxdebug->enter_sub(); @@ -58,7 +76,11 @@ sub add { $main::auth->assert('vendor_invoice_edit'); - return $main::lxdebug->leave_sub() if (load_draft_maybe()); + if (!$::instance_conf->get_allow_new_purchase_invoice) { + $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")); + } + + $form->{show_details} = $::myconfig{show_form_details}; $form->{title} = $locale->text('Record Vendor Invoice'); @@ -72,10 +94,14 @@ sub add { sub edit { $main::lxdebug->enter_sub(); + # Delay access check to after the invoice's been loaded in + # "create_links" so that project-specific invoice rights can be + # evaluated. + my $form = $main::form; my $locale = $main::locale; - $main::auth->assert('vendor_invoice_edit'); + $form->{show_details} = $::myconfig{show_form_details}; # show history button $form->{javascript} = qq||; @@ -93,89 +119,31 @@ sub edit { sub invoice_links { $main::lxdebug->enter_sub(); + # Delay access check to after the invoice's been loaded so that + # project-specific invoice rights can be evaluated. + my $form = $main::form; my %myconfig = %main::myconfig; - $main::auth->assert('vendor_invoice_edit'); - $form->{vc} = 'vendor'; # create links - $form->{webdav} = $::instance_conf->get_webdav; - $form->create_links("AP", \%myconfig, "vendor"); - #quote all_vendor Bug 133 - foreach my $ref (@{ $form->{all_vendor} }) { - $ref->{name} = $form->quote($ref->{name}); - } - - if ($form->{all_vendor}) { - unless ($form->{vendor_id}) { - $form->{vendor_id} = $form->{all_vendor}->[0]->{id}; - } - } + _assert_access(); - my ($payment_id, $language_id, $taxzone_id, $currency, $delivery_term_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}; - } - if ($form->{currency}) { - $currency = $form->{currency}; - } - if ($form->{delivery_term_id}) { - $delivery_term_id = $form->{delivery_term_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; - } - if ($currency) { - $form->{currency} = $currency; - } - if ($delivery_term_id) { - $form->{delivery_term_id} = $delivery_term_id; - } + $form->restore_vars(qw(payment_id language_id taxzone_id + currency delivery_term_id intnotes cp_id)); my @curr = $form->get_all_currencies(); map { $form->{selectcurrency} .= "