X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=b84516b7d87c4007ce8c1e8c9a6a4e9892903cdd;hb=affd886bff7af48273af3dad20ea0680398489a3;hp=264100e743b151ccd980ae0ee008b301bca22668;hpb=0bb0eb67db98f28ec8faf8dfe8c233268332f842;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 264100e74..b84516b7d 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -24,37 +24,88 @@ # 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 # #====================================================================== +use SL::FU; use SL::IR; -use SL::PE; - -require "$form->{path}/io.pl"; -require "$form->{path}/arap.pl"; +use SL::IS; +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/common.pl"; + +use strict; 1; # 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 { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = $locale->text('Add Vendor Invoice'); + $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.")); + } + + $form->{show_details} = $::myconfig{show_form_details}; + + $form->{title} = $locale->text('Record Vendor Invoice'); &invoice_links; &prepare_invoice; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); + $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; + + $form->{show_details} = $::myconfig{show_form_details}; + + # show history button + $form->{javascript} = qq||; + #/show hhistory button $form->{title} = $locale->text('Edit Vendor Invoice'); @@ -62,77 +113,60 @@ sub edit { &prepare_invoice; &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub invoice_links { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - # create links - $form->{webdav} = $webdav; + # Delay access check to after the invoice's been loaded so that + # project-specific invoice rights can be evaluated. - # set jscalendar - $form->{jscalendar} = $jscalendar; + my $form = $main::form; + my %myconfig = %main::myconfig; + $form->{vc} = 'vendor'; + + # create links $form->create_links("AP", \%myconfig, "vendor"); - if ($form->{all_vendor}) { - unless ($form->{vendor_id}) { - $form->{vendor_id} = $form->{all_vendor}->[0]->{id}; - } - } + _assert_access(); + + $form->backup_vars(qw(payment_id language_id taxzone_id + currency delivery_term_id intnotes cp_id)); - $cp_id = $form->{cp_id}; IR->get_vendor(\%myconfig, \%$form); IR->retrieve_invoice(\%myconfig, \%$form); - $form->{cp_id} = $cp_id; - # currencies - @curr = split /:/, $form->{currencies}; - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + $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} .= ""; } + next unless $form->{acc_trans}{$key}; + if ($key eq "AP_paid") { - for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { + for my $i (1 .. scalar @{ $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}; @@ -155,23 +189,37 @@ sub invoice_links { ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub prepare_invoice { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + _assert_access(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $form->{type} = "purchase_invoice"; if ($form->{id}) { map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber); - foreach $ref (@{ $form->{invoice_details} }) { + my $i = 0; + foreach my $ref (@{ $form->{invoice_details} }) { $i++; map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref}; - - ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); + # ü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; - $decimalplaces = ($dec > 2) ? $dec : 2; + my $decimalplaces = ($dec > 2) ? $dec : 2; $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, @@ -187,587 +235,387 @@ sub prepare_invoice { } } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub form_header { - $lxdebug->enter_sub(); +sub setup_ir_action_bar { + my $form = $::form; + my $change_never = $::instance_conf->get_ir_changeable == 0; + my $change_on_same_day_only = $::instance_conf->get_ir_changeable == 2 && ($form->current_date(\%::myconfig) ne $form->{gldate}); + my $has_storno = ($::form->{storno} && !$::form->{storno_id}); + my $payments_balanced = ($::form->{oldtotalpaid} == 0); + my $may_edit_create = $::auth->assert('vendor_invoice_edit', 1); - # set option selected - foreach $item (qw(AP vendor currency department contact)) { - $form->{"select$item"} =~ s/ selected//; - $form->{"select$item"} =~ - s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + my $has_sepa_exports; + if ($form->{id}) { + my $invoice = SL::DB::Manager::PurchaseInvoice->find_by(id => $form->{id}); + $has_sepa_exports = 1 if ($invoice->find_sepa_export_items()->[0]); } - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); + my $is_linked_bank_transaction; + if ($::form->{id} + && SL::DB::Default->get->payments_changeable != 0 + && SL::DB::Manager::BankTransactionAccTrans->find_by(ap_id => $::form->{id})) { - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - - #build contacts - if ($form->{all_contacts}) { - - $form->{selectcontact} = ""; - foreach $item (@{ $form->{all_contacts} }) { - if ($form->{cp_id} == $item->{cp_id}) { - $form->{selectcontact} .= - "