Änderbarkeit bei Zahlungen f. Einkaufsrechnungen konfigurierbar.
[kivitendo-erp.git] / bin / mozilla / ir.pl
index 4ef4886..6b09b5b 100644 (file)
@@ -100,7 +100,7 @@ sub invoice_links {
   $form->{vc} = 'vendor';
 
   # create links
-  $form->{webdav}   = $::lx_office_conf{system}->{webdav};
+  $form->{webdav}   = $::lx_office_conf{features}->{webdav};
   $form->{jsscript} = 1;
 
   $form->create_links("AP", \%myconfig, "vendor");
@@ -181,10 +181,12 @@ sub invoice_links {
         $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};
@@ -226,6 +228,12 @@ sub prepare_invoice {
     foreach my $ref (@{ $form->{invoice_details} }) {
       $i++;
       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
+      # ü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;
@@ -256,7 +264,7 @@ sub form_header {
   my $locale   = $main::locale;
   my $cgi      = $main::cgi;
 
-  $main::auth->assert('invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   my %TMPL_VAR = ();
   my @custom_hiddens;
@@ -354,7 +362,7 @@ sub form_footer {
   my %myconfig = %main::myconfig;
   my $locale   = $main::locale;
 
-  $main::auth->assert('invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   $form->{invtotal}    = $form->{invsubtotal};
   $form->{oldinvtotal} = $form->{invtotal};
@@ -397,6 +405,16 @@ sub form_footer {
   my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
 
   for my $i (1 .. $form->{paidaccounts}) {
+    $form->{"changeable_$i"} = 1;
+    if ($::lx_office_conf{features}->{payments_changeable} == 0) {
+      # never
+      $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
+    } elsif ($::lx_office_conf{features}->{payments_changeable} == 2) {
+      # on the same day
+      $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') || 
+                                  ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
+    }
+
     $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
     if (!$form->{"AP_paid_$i"}) {
       $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
@@ -475,7 +493,7 @@ sub update {
 
       if ($rows > 1) {
 
-        &select_item;
+        select_item(mode => 'IR');
         ::end_of_request();
 
       } else {
@@ -554,7 +572,7 @@ 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_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
+  map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
 
   # saving the history
   if(!exists $form->{addition} && $form->{id} ne "") {
@@ -583,7 +601,7 @@ sub use_as_template {
 
   $main::auth->assert('vendor_invoice_edit');
 
-  map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
+  map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
   $form->{rowcount}--;
   $form->{invdate} = $form->current_date(\%myconfig);