Aufrufe von 'exit' durch eigene Funktion '::end_of_request()' ersetzt.
[kivitendo-erp.git] / bin / mozilla / ir.pl
index 0e64a5b..1119ad4 100644 (file)
@@ -463,21 +463,20 @@ 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;
+        ::end_of_request();
 
       } else {
 
         # override sellprice if there is one entered
         my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
-       # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
-        $form->{"discount_$i"} = $form->format_amount(\%myconfig,
-                                                     $form->{vendor_discount} * 100 );
+        # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
+        $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{vendor_discount} * 100 );
         map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
 
@@ -614,14 +613,14 @@ sub post_payment {
   ($form->{AP})      = split /--/, $form->{AP};
   ($form->{AP_paid}) = split /--/, $form->{AP_paid};
   if (IR->post_payment(\%myconfig, \%$form)){
-       if (!exists $form->{addition} && $form->{id} ne "") {
-               # saving the history
+    if (!exists $form->{addition} && $form->{id} ne "") {
+      # saving the history
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
-               $form->{addition} = "PAYMENT POSTED";
+      $form->{addition} = "PAYMENT POSTED";
       $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
-               $form->save_history($form->dbconnect(\%myconfig));
-               # /saving the history
-       }
+      $form->save_history($form->dbconnect(\%myconfig));
+      # /saving the history
+    }
 
     $form->redirect($locale->text('Payment posted!'));
   }
@@ -665,9 +664,16 @@ 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;
   }
 
+  remove_emptied_rows();
   &validate_items;
 
   my $closedto     = $form->datetonum($form->{closedto}, \%myconfig);
@@ -707,16 +713,16 @@ sub post {
 
   relink_accounts();
   if (IR->post_invoice(\%myconfig, \%$form)){
-       # saving the history
-       if(!exists $form->{addition} && $form->{id} ne "") {
+    # saving the history
+    if(!exists $form->{addition} && $form->{id} ne "") {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
       $form->{addition} = "POSTED";
-               #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
-               $form->save_history($form->dbconnect(\%myconfig));
-       }
-       # /saving the history
+      #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
+      $form->save_history($form->dbconnect(\%myconfig));
+    }
+    # /saving the history
     remove_draft() if $form->{remove_draft};
-       $form->redirect(  $locale->text('Invoice')
+    $form->redirect(  $locale->text('Invoice')
                   . " $form->{invnumber} "
                   . $locale->text('posted!'));
   }
@@ -777,8 +783,8 @@ sub yes {
     # saving the history
     if(!exists $form->{addition}) {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
-         $form->{addition} = "DELETED";
-         $form->save_history($form->dbconnect(\%myconfig));
+      $form->{addition} = "DELETED";
+      $form->save_history($form->dbconnect(\%myconfig));
     }
     # /saving the history
     $form->redirect($locale->text('Invoice deleted!'));