Merge branch 'master' into bug1640
[kivitendo-erp.git] / bin / mozilla / ir.pl
index 09ef524..fab18f7 100644 (file)
@@ -59,7 +59,7 @@ sub add {
 
   return $main::lxdebug->leave_sub() if (load_draft_maybe());
 
-  $form->{title} = $locale->text('Add Vendor Invoice');
+  $form->{title} = $locale->text('Record Vendor Invoice');
 
   &invoice_links;
   &prepare_invoice;
@@ -100,7 +100,7 @@ sub invoice_links {
   $form->{vc} = 'vendor';
 
   # create links
-  $form->{webdav}   = $main::webdav;
+  $form->{webdav}   = $::lx_office_conf{features}->{webdav};
   $form->{jsscript} = 1;
 
   $form->create_links("AP", \%myconfig, "vendor");
@@ -171,7 +171,7 @@ sub invoice_links {
   foreach my $key (keys %{ $form->{AP_links} }) {
 
     foreach my $ref (@{ $form->{AP_links}{$key} }) {
-      $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
+      $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}</option>";
     }
 
     next unless $form->{acc_trans}{$key};
@@ -226,6 +226,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,9 +262,9 @@ sub form_header {
   my $locale   = $main::locale;
   my $cgi      = $main::cgi;
 
-  $main::auth->assert('invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
-  our %TMPL_VAR = ();
+  my %TMPL_VAR = ();
   my @custom_hiddens;
 
   $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
@@ -354,7 +360,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};
@@ -393,9 +399,17 @@ sub form_footer {
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
   $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
 
+  # Standard Konto für Umlaufvermögen
+  my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
   for my $i (1 .. $form->{paidaccounts}) {
     $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
-    $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
+    if (!$form->{"AP_paid_$i"}) {
+      $form->{"selectAP_paid_$i"} =~ s/option>$accno_arap--(.*?)>/option selected>$accno_arap--$1>/;
+    } else {
+      $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
+    }
+
     $totalpaid += $form->{"paid_$i"};
   }
 
@@ -463,12 +477,12 @@ sub update {
     my $rows = scalar @{ $form->{item_list} };
 
     if ($rows) {
-      $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
+      $form->{"qty_$i"} = 1 unless $form->parse_amount(\%myconfig, $form->{"qty_$i"});
 
       if ($rows > 1) {
 
-        &select_item;
-        exit;
+        select_item(mode => 'IR');
+        ::end_of_request();
 
       } else {
 
@@ -552,7 +566,7 @@ sub storno {
   if(!exists $form->{addition} && $form->{id} ne "") {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
     $form->{addition} = "CANCELED";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
 
@@ -618,7 +632,7 @@ sub post_payment {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
       $form->{addition} = "PAYMENT POSTED";
       $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
-      $form->save_history($form->dbconnect(\%myconfig));
+      $form->save_history;
       # /saving the history
     }
 
@@ -664,6 +678,12 @@ sub post {
   # if the vendor changed get new values
   if (&check_name('vendor')) {
     &update;
+    ::end_of_request();
+  }
+
+  if ($myconfig{mandatory_departments} && !$form->{department_id}) {
+    $form->{saved_message} = $::locale->text('You have to specify a department.');
+    update();
     exit;
   }
 
@@ -712,7 +732,7 @@ sub post {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
       $form->{addition} = "POSTED";
       #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
-      $form->save_history($form->dbconnect(\%myconfig));
+      $form->save_history;
     }
     # /saving the history
     remove_draft() if $form->{remove_draft};
@@ -778,7 +798,7 @@ sub yes {
     if(!exists $form->{addition}) {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
       $form->{addition} = "DELETED";
-      $form->save_history($form->dbconnect(\%myconfig));
+      $form->save_history;
     }
     # /saving the history
     $form->redirect($locale->text('Invoice deleted!'));