X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=b84516b7d87c4007ce8c1e8c9a6a4e9892903cdd;hb=a90b3fb8ebabdefdce605df9999fa8f284856e55;hp=3736fbe2cb09f792dc248143d96bd241819ac019;hpb=5b47ed3efe5f4ef0810096b0f4849047cee54690;p=kivitendo-erp.git
diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl
index 3736fbe2c..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,101 +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");
- #quote all_vendor Bug 133
- foreach $ref (@{ $form->{all_vendor} }) {
- $ref->{name} = $form->quote($ref->{name});
- }
+ _assert_access();
- if ($form->{all_vendor}) {
- unless ($form->{vendor_id}) {
- $form->{vendor_id} = $form->{all_vendor}->[0]->{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};
- }
+ $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;
-
- if ($payment_id) {
- $form->{payment_id} = $payment_id;
- }
- if ($language_id) {
- $form->{language_id} = $language_id;
- }
- if ($taxzone_id) {
- $form->{taxzone_id} = $taxzone_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};
@@ -179,24 +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);
my $i = 0;
- foreach $ref (@{ $form->{invoice_details} }) {
+ 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"},
@@ -212,636 +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->{radier} =
- ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
-
- #quote selectvendor Bug 133
- $form->{"selectvendor"} = $form->quote($form->{"selectvendor"});
+ 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->{exchangerate} =
- $form->format_amount(\%myconfig, $form->{exchangerate});
-
- $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} .=
- "";
- } else {
- $form->{selecttaxzone} .=
- "";
- }
+ # hiddens
+ $TMPL_VAR{HIDDENS} = [qw(
+ id type queued printed emailed title vc discount
+ title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
+ max_dunning_level dunning_amount
+ shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact shiptophone shiptofax
+ shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
+ convert_from_do_ids convert_from_oe_ids convert_from_ap_ids show_details gldate useasnew
+ ), @custom_hiddens,
+ map { $_.'_rate', $_.'_description', $_.'_taxnumber', $_.'_tax_id' } split / /, $form->{taxaccounts}];
- }
- } else {
- $form->{selecttaxzone} =~ s/ selected//g;
- if ($form->{taxzone_id} ne "") {
- $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
- }
- }
+ $TMPL_VAR{payment_terms_obj} = get_payment_terms_for_invoice();
+ $form->{duedate} = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR{payment_terms_obj};
- $taxzone = qq|
-
- | . $locale->text('Steuersatz') . qq| |
- |
-
-
|;
-
-
-
- $vendor =
- ($form->{selectvendor})
- ? qq|\n|
- : qq||;
-
- $contact =
- ($form->{selectcontact})
- ? qq|\n|
- : qq||;
-
- $department = qq|
-
- | . $locale->text('Department') . qq| |
-
-
- |
-
-| if $form->{selectdepartment};
-
- $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
-
- # use JavaScript Calendar or not
- $form->{jsscript} = $form->{jscalendar};
- $jsscript = "";
- if ($form->{jsscript}) {
-
- # with JavaScript Calendar
- $button1 = qq|
- {invdate}> |
- text('button') . qq|> |
- |;
- $button2 = qq|
- {duedate}> |
- text('button') . qq|> |
- |;
-
- #write Trigger
- $jsscript =
- Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
- "duedate", "BL", "trigger2");
- } else {
+ $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part kivi.CustomerVendor kivi.Validator ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_project client_js));
- # without JavaScript Calendar
- $button1 =
- qq|{invdate}> | |;
- $button2 =
- qq|{duedate}> | |;
- }
+ setup_ir_action_bar();
- $form->{"javascript"} .= qq||;
+ $form->header();
- $jsscript .=
- $form->write_trigger(\%myconfig, 2,
- "orddate", "BL", "trigger_orddate",
- "quodate", "BL", "trigger_quodate");
+ print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
- $form->header;
+ $main::lxdebug->leave_sub();
+}
- print qq|
-
+sub _sort_payments {
+ my @fields = qw(acc_trans_id gldate datepaid source memo paid AP_paid);
+ my @payments =
+ grep { $_->{paid} != 0 }
+ map {
+ my $idx = $_;
+ +{ map { ($_ => delete($::form->{"${_}_${idx}"})) } @fields }
+ } (1..$::form->{paidaccounts});
-
-
-
-