Merge branch 'after-262'
[kivitendo-erp.git] / bin / mozilla / cp.pl
index d454faf..721a4a8 100644 (file)
@@ -34,6 +34,8 @@
 use SL::CP;
 use SL::IS;
 use SL::IR;
+use SL::AR;
+use SL::AP;
 use strict ("vars", "subs");
 #use warnings;
 
@@ -74,30 +76,23 @@ sub payment {
       @{ $form->{"all_$form->{vc}"} };
   }
 
-  # departments
-  # auf departments kann man auch nicht mehr buchen. Raus oder wieder 
-  # aktivieren? Im Backend dann auch anpassen. jb 12.10.2010
-  if (@{ $form->{all_departments} || [] }) {
-    $form->{selectdepartment} = "<option>\n";
-    $form->{department}       = "$form->{department}--$form->{department_id}";
-
-    map {
-      $form->{selectdepartment} .=
-        "<option>$_->{description}--$_->{id}\n"
-    } (@{ $form->{all_departments} || [] });
-  }
-
   CP->paymentaccounts(\%myconfig, \%$form);
 
+  # Standard Konto für Umlaufvermögen
+  my $accno_arap = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
   $form->{selectaccount} = "";
   $form->{"select$form->{ARAP}"} = "";
 
-  map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" }
-    @{ $form->{PR}{"$form->{ARAP}_paid"} };
-  map {
-    $form->{"select$form->{ARAP}"} .=
-      "<option>$_->{accno}--$_->{description}\n"
-  } @{ $form->{PR}{ $form->{ARAP} } };
+  map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n";
+        $form->{account}        = "$_->{accno}--$_->{description}" if ($_->{accno} eq $accno_arap) } @{ $form->{PR}{"$form->{ARAP}_paid"} };
+
+  # Braucht man das hier überhaupt? Erstmal auskommentieren .. jan 18.12.2010
+  #  map {
+  #    $form->{"select$form->{ARAP}"} .=
+  #      "<option>$_->{accno}--$_->{description}\n"
+  #  } @{ $form->{PR}{ $form->{ARAP} } };
+  # ENDE LOESCHMICH in 2012
 
   # currencies
   # oldcurrency ist zwar noch hier als fragment enthalten, wird aber bei
@@ -105,9 +100,10 @@ sub payment {
   # old_$FOO habe ich auch noch nicht verstanden ...
   # Ok. Wenn currency übernommen werden, dann in callback-string über-
   # geben und hier reinparsen, oder besser multibox oder html auslagern?
-  @curr_unsorted = split(/:/, $form->{currencies});
-  chomp $curr_unsorted[0];
-  @curr = sort {} @curr_unsorted;
+  # Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
+  # Wofür macht das Sinn?
+  @curr = split(/:/, $form->{currencies});
+  chomp $curr[0];
   $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
     $curr[0];
 
@@ -126,7 +122,7 @@ sub form_header {
 
   $auth->assert('cash');
 
-  my ($vc, $vclabel, $allvc, $arap, $department, $exchangerate);
+  my ($vc, $vclabel, $allvc, $arap, $exchangerate);
   my ($jsscript, $button1, $button2, $onload);
 
   $vclabel = ucfirst $form->{vc};
@@ -167,8 +163,7 @@ sub form_header {
 |;
     }
   }
-
-  foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}, "department") {
+  foreach my $item ($form->{vc}, "account", "currency", $form->{ARAP}) {
     $form->{"select$item"} =~ s/ selected//;
     $form->{"select$item"} =~
       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
@@ -252,6 +247,10 @@ sub form_header {
                 <input type=hidden name="$form->{vc}_id" value="|    . H($form->{"$form->{vc}_id"}) . qq|">
                 <input type=hidden name="old$form->{vc}" value="|    . H($form->{"old$form->{vc}"}) . qq|">
               </tr>
+              <tr>
+                <th align=right>| . $locale->text('Invoice Number') . qq|</th>
+                <td><input name="invnumber" size="35"</td>
+              </tr>
               <tr valign=top>
                 <th align=right nowrap>| . $locale->text('Address') . qq|</th>
                 <td colspan=2>
@@ -283,7 +282,6 @@ sub form_header {
           </td>
           <td align=right>
             <table>
-              $department
               <tr>
                 <th align=right nowrap>| . $locale->text('Account') . qq|</th>
                 <td colspan=3><select name=account>$form->{selectaccount}</select>
@@ -532,7 +530,19 @@ sub update {
       }
     }
   }
-
+  # Falls Suche über Rechnungsnummer und kein Kundenname vorhanden
+  if ($form->{invnumber} && !($form->{$form->{vc}})){
+  $form->{open} ='Y'; # nur die offenen rechnungen
+  if ($form->{ARAP} eq 'AR'){
+    AR->ar_transactions(\%myconfig, \%$form);
+    # den ersten treffen nehmen und mit dem namen überschreiben
+    $form->{$form->{vc}} = $form->{AR}[0]{name};
+  } else {
+    # s.o. nur für zahlungsausgang
+    AP->ap_transactions(\%myconfig, \%$form);
+    $form->{$form->{vc}} = $form->{AP}[0]{name};
+    }
+  }
   # get customer and invoices
   $updated = &check_name($form->{vc});
 
@@ -638,8 +648,11 @@ sub post {
     $form->error($locale->text('Exchangerate missing!'))
       unless $form->{exchangerate};
   }
+
   # Beim Aktualisieren wird das Konto übernommen
-  $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&muh=kuh&account=$form->{account}";
+  # und jetzt auch Beleg und Datum
+  $form->{callback} = "cp.pl?action=payment&vc=$form->{vc}&type=$form->{type}&account=$form->{account}&$form->{currency}" . 
+                      "&datepaid=$form->{datepaid}&source=$form->{source}";
 
   my $msg1 = "$form->{origtitle} posted!";
   my $msg2 = "Cannot post $form->{origtitle}!";
@@ -675,7 +688,7 @@ sub check_form {
   for my $i (1 .. $form->{rowcount}) {
     if ($form->{"checked_$i"}) {
       if ($form->parse_amount(\%myconfig, $form->{"paid_$i"}, 2) <= 0) { # negativen Betrag eingegeben
-          $form->error($locale->text('No zero or negative values, please! Correct row number:' . $i));
+          $form->error($locale->text('Amount has to be greater then zero! Wrong row number: ') . $i);
       }
         undef($selected_check);
         # last; # ich muss doch über alle buchungen laufen, da ich noch