Verwendete Schnittstelle (CGI/FastCGI) in Versionsinfoscreen anzeigen
[kivitendo-erp.git] / bin / mozilla / ap.pl
index bac1b81..ae5d9d8 100644 (file)
@@ -92,7 +92,7 @@ sub add {
 
   $form->{title} = "Add";
 
-  $form->{callback} = "ap.pl?action=add" unless $form->{callback};
+  $form->{callback} = "ap.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
 
   AP->get_transdate(\%myconfig, $form);
   $form->{initial_transdate} = $form->{transdate};
@@ -156,11 +156,9 @@ sub create_links {
   $form->{notes} = $form->{intnotes} unless $form->{notes};
 
   # currencies
-  my @curr = split(/:/, $form->{currencies});
-  chomp $curr[0];
-  $form->{defaultcurrency} = $curr[0];
+  $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
-  map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
+  map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
 
   # vendors
   if (@{ $form->{all_vendor} || [] }) {
@@ -246,22 +244,15 @@ sub form_header {
   $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
-
   # format amounts
-  $form->{exchangerate} =
-    $form->format_amount(\%myconfig, $form->{exchangerate});
-  if ($form->{exchangerate} == 0) {
-    $form->{exchangerate} = "";
-  }
-  $form->{creditlimit} =
-    $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
-  $form->{creditremaining} =
-    $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
+  $form->{exchangerate}    = $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");
 
   my $exchangerate = qq|
 <input type=hidden name=forex value=$form->{forex}>
 |;
-  if ($form->{currency} ne $form->{defaultcurrency}) {
+  if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
     if ($form->{forex}) {
       $exchangerate .= qq|
             <tr>
@@ -639,7 +630,7 @@ $jsscript
 |;
 
   my @column_index;
-  if ($form->{currency} eq $form->{defaultcurrency}) {
+  if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) {
     @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
   } else {
     @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
@@ -663,7 +654,7 @@ $jsscript
 ";
 
   my @triggers  = ();
-  my $totalpaid = 0;
+  $form->{totalpaid} = 0;
 
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
   for my $i (1 .. $form->{paidaccounts}) {
@@ -678,7 +669,7 @@ $jsscript
                            '-labels' => \%AP_paid_labels,
                            '-default' => $form->{"AP_paid_$i"}));
 
-    $totalpaid += $form->{"paid_$i"};
+    $form->{totalpaid} += $form->{"paid_$i"};
 
     # format amounts
     if ($form->{"paid_$i"}) {
@@ -692,7 +683,7 @@ $jsscript
     }
 
     $exchangerate = qq|&nbsp;|;
-    if ($form->{currency} ne $form->{defaultcurrency}) {
+    if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
       if ($form->{"forex_$i"}) {
         $exchangerate =
           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
@@ -734,14 +725,14 @@ $jsscript
     push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
   }
 
-  my $paid_missing = $form->{invtotal_unformatted} - $totalpaid;
+  my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
 
   print qq|
         <tr>
           <td></td>
           <td></td>
           <td align="center">| . $locale->text('Total') . qq|</td>
-          <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
+          <td align="center">| . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq|</td>
         </tr>
         <tr>
           <td></td>
@@ -820,9 +811,8 @@ $follow_ups_block
 |;
     }
     # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
-    our $total_paid;
     print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
-      if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($total_paid == 0) || ($total_paid eq "")));
+      if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq "")));
 
     print qq| <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
               <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|">
@@ -975,7 +965,8 @@ sub post_payment {
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
-  our $invdate;
+  my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
+
   for my $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
       my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
@@ -985,7 +976,7 @@ sub post_payment {
       $form->error($locale->text('Cannot post payment for a closed period!'))
         if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
 
-      if ($form->{currency} ne $form->{defaultcurrency}) {
+      if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
         $form->{"exchangerate_$i"} = $form->{exchangerate}
           if ($invdate == $datepaid);
         $form->isblank("exchangerate_$i",
@@ -1019,6 +1010,12 @@ sub post {
   $form->isblank("duedate",   $locale->text("Due Date missing!"));
   $form->isblank("vendor",    $locale->text('Vendor missing!'));
 
+  if ($myconfig{mandatory_departments} && !$form->{department}) {
+    $form->{saved_message} = $::locale->text('You have to specify a department.');
+    update();
+    exit;
+  }
+
   my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
   my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
@@ -1034,7 +1031,7 @@ sub post {
   $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
 
   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
-    if ($form->{currency} ne $form->{defaultcurrency});
+    if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
   delete($form->{AP});
 
   for my $i (1 .. $form->{paidaccounts}) {
@@ -1046,7 +1043,7 @@ sub post {
       $form->error($locale->text('Cannot post payment for a closed period!'))
         if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
 
-      if ($form->{currency} ne $form->{defaultcurrency}) {
+      if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
         $form->{"exchangerate_$i"} = $form->{exchangerate}
           if ($transdate == $datepaid);
         $form->isblank("exchangerate_$i",
@@ -1060,7 +1057,7 @@ sub post {
   my ($vendor) = split /--/, $form->{vendor};
   if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
     &update;
-    exit;
+    ::end_of_request();
   }
   my ($debitaccno,    $debittaxkey)    = split /--/, $form->{AP_amountselected};
   my ($taxkey,        $NULL)           = split /--/, $form->{taxchartselected};
@@ -1077,13 +1074,15 @@ sub post {
     if(!exists $form->{addition} && $form->{id} ne "") {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
       $form->{addition} = "POSTED";
-      $form->save_history($form->dbconnect(\%myconfig));
+      $form->save_history;
     }
     # /saving the history
     remove_draft() if $form->{remove_draft};
+    # Dieser Text wird niemals ausgegeben: Probleme beim redirect?
     $form->redirect($locale->text('Transaction posted!'));
+  } else {
+    $form->error($locale->text('Cannot post transaction!'));
   }
-  $form->error($locale->text('Cannot post transaction!'));
 
   $main::lxdebug->leave_sub();
 }
@@ -1101,7 +1100,7 @@ sub post_as_new {
   if(!exists $form->{addition} && $form->{id} ne "") {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
     $form->{addition} = "POSTED AS NEW";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
   &post;
@@ -1179,12 +1178,12 @@ sub yes {
 
   $main::auth->assert('general_ledger');
 
-  if (AP->delete_transaction(\%myconfig, \%$form, $main::spool)) {
+  if (AP->delete_transaction(\%myconfig, \%$form)) {
     # saving the history
     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('Transaction deleted!'));
@@ -1290,7 +1289,7 @@ sub ap_transactions {
     'duedate'                 => { 'text' => $locale->text('Due Date'), },
     'transaction_description' => { 'text' => $locale->text('Transaction description'), },
     'notes'                   => { 'text' => $locale->text('Notes'), },
-    'employee'                => { 'text' => $locale->text('Salesperson'), },
+    'employee'                => { 'text' => $locale->text('Employee'), },
     'globalprojectnumber'     => { 'text' => $locale->text('Project Number'), },
     'vendornumber'            => { 'text' => $locale->text('Vendor Number'), },
     'country'                 => { 'text' => $locale->text('Country'), },
@@ -1336,6 +1335,7 @@ sub ap_transactions {
                        'attachment_basename'  => $locale->text('vendor_invoice_list') . strftime('_%Y%m%d', localtime time),
     );
   $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   # add sort and escape callback, this one we use for the add sub
   $form->{callback} = $href .= "&sort=$form->{sort}";
@@ -1427,7 +1427,7 @@ sub storno {
   if(!exists $form->{addition} && $form->{id} ne "") {
     $form->{snumbers} = "ordnumber_$form->{ordnumber}";
     $form->{addition} = "STORNO";
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history