Debugcode wieder entfernt.
[kivitendo-erp.git] / bin / mozilla / am.pl
index 3b47b8e..1372438 100644 (file)
@@ -161,7 +161,7 @@ sub account_header {
         if ($item eq ''){
           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
         } 
-        elsif ( $item == $taxkey_used->{pos_ustva} ) {
+        elsif ( $item eq $taxkey_used->{pos_ustva} ) {
           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
         }
         else {
@@ -413,40 +413,38 @@ sub list_account {
 
   foreach $ca (@{ $form->{CA} }) {
 
-    $ca->{debit}  = "&nbsp;";
-    $ca->{credit} = "&nbsp;";
+    $ca->{debit}  = "";
+    $ca->{credit} = "";
 
     if ($ca->{amount} > 0) {
-      $ca->{credit} =
-        $form->format_amount(\%myconfig, $ca->{amount}, 2, "&nbsp;");
+      $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
     }
     if ($ca->{amount} < 0) {
-      $ca->{debit} =
-        $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, "&nbsp;");
+      $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
     }
     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:''; 
     $ca->{link_edit_account} = 
         qq|$form->{script}?action=edit_account&id=$ca->{id}|
-       .qq|&path=$form->{path}&login=$form->{login}|
+       .qq|&login=$form->{login}|
        .qq|&password=$form->{password}&callback=$callback|;
   }
   
   # Ajax 
   my $list_account_details_url = 
-              "$form->{script}?login=$form->{login}&path=$form->{path}"
+              "$form->{script}?login=$form->{login}"
              ."&password=$form->{password}&action=list_account_details&";
   
   
-  my $pjx = new CGI::Ajax( 
-             'list_account_details' => $list_account_details_url 
-  );
+  my $pjx = new CGI::Ajax('list_account_details' => $list_account_details_url);
 
   # Eneable AJAX debuging
   #$pjx->DEBUG(1);
   #$pjx->JSDEBUG(1);
     
   push(@ { $form->{AJAX} }, $pjx);
-  
+
+  $form->{stylesheets} = "list_accounts.css";
+
   $form->header;
   
   
@@ -455,7 +453,7 @@ sub list_account {
   };
   
   # Ausgabe des Templates
-  print($form->parse_html_template('am/list_accounts', $parameters_ref));
+  print($form->parse_html_template2('am/list_accounts', $parameters_ref));
   
   $lxdebug->leave_sub();
 
@@ -474,7 +472,7 @@ sub list_account_details {
 
   # construct callback
   $callback =
-    "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}";
 
   $form->header;
 
@@ -2301,8 +2299,12 @@ sub payment_header {
   <li>| . $locale->text("&lt;%skonto_amount%&gt; -- The deductible amount")
 . qq|</li>
   <li>| . $locale->text("&lt;%total%&gt; -- Amount payable")
+. qq|</li>
+  <li>| . $locale->text("&lt;%total_wo_skonto%&gt; -- Amount payable less discount")
 . qq|</li>
   <li>| . $locale->text("&lt;%invtotal%&gt; -- Invoice total")
+. qq|</li>
+  <li>| . $locale->text("&lt;%invtotal_wo_skonto%&gt; -- Invoice total less discount")
 . qq|</li>
   <li>| . $locale->text("&lt;%currency%&gt; -- The selected currency")
 . qq|</li>
@@ -3061,7 +3063,6 @@ sub show_am_history {
                        $restriction .= " OR addition = '" . $_ . "'";
                }
        }
-       
        $restriction .= (($form->{transdate} ne "" && $form->{reqdate} ne "") 
                                                ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|' AND st.itime::date <= '| . $form->{reqdate} . qq|'|
                                                : (($form->{transdate} ne "" && $form->{reqdate} eq "") 
@@ -3071,38 +3072,48 @@ sub show_am_history {
                                                                : ""
                                                        )
                                                );
+  $restriction .= ($form->{mitarbeiter} eq "" ? "" 
+          : ($form->{mitarbeiter} =~ /^[0-9]*$/  
+            ? " AND employee_id = " . $form->{mitarbeiter} 
+            : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
+  
        my $dbh = $form->dbconnect(\%myconfig);
-       my $searchSNumber = $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'};
-       $restriction .= ($form->{mitarbeiter} eq "" ? "" 
-                                       : ($form->{mitarbeiter} =~ /^[0-9]*$/  
-                                               ? " AND employee_id = " . $form->{mitarbeiter} 
-                                               : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
-       my $query = qq|SELECT trans_id AS id FROM history_erp WHERE sNumbers = '$searchSNumber' |;
+       my $query = qq|SELECT trans_id AS id FROM history_erp | . 
+                ($form->{'searchid'} ? 
+                  qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'| : 
+                  qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
 
   my $sth = $dbh->prepare($query);
        
        $sth->execute() || $form->dberror($query);
-       
-  if($sth->fetch() <= 0) {
-    $sth->finish();
-    my $query = qq|SELECT id FROM $search{$form->{what2search}} 
-           WHERE $searchNo{$form->{'what2search'}} ILIKE '$form->{"searchid"}' 
-           |;
-  }
-  $sth->execute() || $form->dberror($query);  
-       $form->{title} = $locale->text("History Search");
+  
+  $form->{title} = $locale->text("History Search");
        $form->header();
-       my $daten = "";
-       while(my $hash_ref = $sth->fetchrow_hashref()){
-    $daten =  $form->get_history($dbh,$hash_ref->{id},$restriction,$form->{order});
+       
+  my $i = 1;
+  my $daten = qq||;
+  while(my $hash_ref = $sth->fetchrow_hashref()){
+    if($i) {
+      $daten .= $hash_ref->{id};
+      $i = 0;
+    }
+    else {
+      $daten .= " OR trans_id = " . $hash_ref->{id};
+    }
   }
-       $dbh->disconnect();
+  
+  my ($sort, $sortby) = split(/\-\-/, $form->{order});
+  $sort =~ s/.*\.(.*)$/$1/;
+
        print $form->parse_html_template("/common/show_history", 
-    {"DATEN" => $daten,
-     "SUCCESS" => ($daten != 0 ? 1 : 0),
-     "NONEWWINDOW" => 1
+    {"DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
+     "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
+     "NONEWWINDOW" => 1,
+     uc($sort) => 1,
+     uc($sort)."BY" => $sortby
     });
-       $lxdebug->leave_sub();
+       $dbh->disconnect();
+  $lxdebug->leave_sub();
 }
 
 sub get_employee_id {
@@ -3128,3 +3139,204 @@ sub swap_units {
 
   $lxdebug->leave_sub();
 }
+
+sub add_tax {
+  $lxdebug->enter_sub();
+
+  $form->{title} =  $locale->text('Add');
+
+  $form->{callback} =
+    "$form->{script}?action=add_tax&login=$form->{login}&password=$form->{password}"
+    unless $form->{callback};
+
+  _get_taxaccount_selection();
+
+  $form->header();
+  
+  my $parameters_ref = {
+#    ChartTypeIsAccount         => $ChartTypeIsAccount,
+  };
+  
+  # Ausgabe des Templates
+  print($form->parse_html_template2('am/edit_tax', $parameters_ref));
+
+  $lxdebug->leave_sub();
+}
+
+sub edit_tax {
+  $lxdebug->enter_sub();
+
+  $form->{title} =  $locale->text('Edit');
+
+  AM->get_tax(\%myconfig, \%$form);
+  _get_taxaccount_selection();
+
+  $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
+
+  $form->header();
+  
+  my $parameters_ref = {
+  };
+  
+  # Ausgabe des Templates
+  print($form->parse_html_template2('am/edit_tax', $parameters_ref));
+
+  $lxdebug->leave_sub();
+}
+
+sub list_tax {
+  $lxdebug->enter_sub();
+
+  AM->taxes(\%myconfig, \%$form);
+
+  map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
+
+  $form->{callback} = build_std_url('action=list_tax');
+
+  $form->{title} = $locale->text('Tax-O-Matic');
+
+  $form->header();
+  
+  # Ausgabe des Templates
+  print($form->parse_html_template2('am/list_tax', $parameters_ref));
+
+  $lxdebug->leave_sub();
+}
+
+sub _get_taxaccount_selection{
+  $lxdebug->enter_sub();
+
+  AM->get_tax_accounts(\%myconfig, \%$form);
+
+  map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
+
+  $lxdebug->leave_sub();
+}
+
+sub save_tax {
+  $lxdebug->enter_sub();
+
+  $form->isblank("rate", $locale->text('Taxrate missing!'));
+  $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
+  $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
+
+  $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
+
+  if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
+    $form->error($locale->text('Tax Percent is a number between 0 and 100'));
+  }
+
+  if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
+    $form->error($locale->text('Tax Percent is a number between 0 and 100'));
+  }  
+
+  AM->save_tax(\%myconfig, \%$form);
+  $form->redirect($locale->text('Tax saved!'));
+
+  $lxdebug->leave_sub();
+}
+
+sub delete_tax {
+  $lxdebug->enter_sub();
+
+  AM->delete_tax(\%myconfig, \%$form);
+  $form->redirect($locale->text('Tax deleted!'));
+
+  $lxdebug->leave_sub();
+}
+
+sub add_price_factor {
+  $lxdebug->enter_sub();
+
+  $form->{title}      = $locale->text('Add Price Factor');
+  $form->{callback} ||= build_std_url('action=add_price_factor');
+  $form->{fokus}      = 'description';
+
+  $form->header();
+  print $form->parse_html_template2('am/edit_price_factor');
+
+  $lxdebug->leave_sub();
+}
+
+sub edit_price_factor {
+  $lxdebug->enter_sub();
+
+  $form->{title}      = $locale->text('Edit Price Factor');
+  $form->{callback} ||= build_std_url('action=add_price_factor');
+  $form->{fokus}      = 'description';
+
+  AM->get_price_factor(\%myconfig, $form);
+
+  $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
+
+  $form->header();
+  print $form->parse_html_template2('am/edit_price_factor');
+
+  $lxdebug->leave_sub();
+}
+
+sub list_price_factors {
+  $lxdebug->enter_sub();
+
+  AM->get_all_price_factors(\%myconfig, \%$form);
+
+  my $previous;
+  foreach my $current (@{ $form->{PRICE_FACTORS} }) {
+    if ($previous) {
+      $previous->{next_id}    = $current->{id};
+      $current->{previous_id} = $previous->{id};
+    }
+
+    $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
+
+    $previous = $current;
+  }
+
+  $form->{callback} = build_std_url('action=list_price_factors');
+  $form->{title}    = $locale->text('Price Factors');
+  $form->{url_base} = build_std_url('callback');
+
+  $form->header();
+  print $form->parse_html_template2('am/list_price_factors');
+
+  $lxdebug->leave_sub();
+}
+
+sub save_price_factor {
+  $lxdebug->enter_sub();
+
+  $form->isblank("description", $locale->text('Description missing!'));
+  $form->isblank("factor", $locale->text('Factor missing!'));
+
+  $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
+
+  AM->save_price_factor(\%myconfig, $form);
+
+  $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
+
+  $form->redirect($locale->text('Price factor saved!'));
+
+  $lxdebug->leave_sub();
+}
+
+sub delete_price_factor {
+  $lxdebug->enter_sub();
+
+  AM->delete_price_factor(\%myconfig, \%$form);
+
+  $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
+
+  $form->redirect($locale->text('Price factor deleted!'));
+
+  $lxdebug->leave_sub();
+}
+
+sub swap_price_factors {
+  $lxdebug->enter_sub();
+
+  AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
+  list_price_factors();
+
+  $lxdebug->leave_sub();
+}
+