Debugcode wieder entfernt.
[kivitendo-erp.git] / bin / mozilla / am.pl
index 95bea4d..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,16 +413,14 @@ 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} = 
@@ -437,16 +435,16 @@ sub list_account {
              ."&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();
 
@@ -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>
@@ -3156,7 +3158,7 @@ sub add_tax {
   };
   
   # Ausgabe des Templates
-  print($form->parse_html_template('am/edit_tax', $parameters_ref));
+  print($form->parse_html_template2('am/edit_tax', $parameters_ref));
 
   $lxdebug->leave_sub();
 }
@@ -3169,13 +3171,15 @@ sub edit_tax {
   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_template('am/edit_tax', $parameters_ref));
+  print($form->parse_html_template2('am/edit_tax', $parameters_ref));
 
   $lxdebug->leave_sub();
 }
@@ -3185,41 +3189,26 @@ sub list_tax {
 
   AM->taxes(\%myconfig, \%$form);
 
-  $form->{callback} =
-    "$form->{script}?action=list_tax&login=$form->{login}&password=$form->{password}";
+  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_template('am/list_tax', $parameters_ref));
+  print($form->parse_html_template2('am/list_tax', $parameters_ref));
 
   $lxdebug->leave_sub();
 }
 
 sub _get_taxaccount_selection{
-    $lxdebug->enter_sub();
+  $lxdebug->enter_sub();
 
   AM->get_tax_accounts(\%myconfig, \%$form);
 
-  my $i = 0;
-  foreach my $taxaccount (@{ $form->{ACCOUNTS} } ) {
-
-    # Fill in the Taxaxxounts as select options
-      if ($form->{chart_id} == $taxaccount->{id}) {
-        $form->{ACCOUNTS}[$i]{select_taxaccount} .=
-          qq|<option value="$taxaccount->{id}" selected="selected">
-            $form->{ACCOUNTS}[$i]{_taxaccount}\n|;
-      }
-      else {
-        $form->{ACCOUNTS}[$i]{select_taxaccount} .=
-          qq|<option value="$taxaccount->{id}">
-            $form->{ACCOUNTS}[$i]{_taxaccount}<!-- hallo-->\n|;
-      }
-    $i++;
-  }
-  return;
+  map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
   $lxdebug->leave_sub();
 }
@@ -3227,16 +3216,17 @@ sub _get_taxaccount_selection{
 sub save_tax {
   $lxdebug->enter_sub();
 
-  $form->isblank("chart_id", $locale->text('Tax-O-Matic account missing!'));
   $form->isblank("rate", $locale->text('Taxrate missing!'));
   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
-  
-  if ( $form->{rate} <= 0 || $form->{rate} >= 100 ) {
+
+  $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 ) {
+  if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
   }  
 
@@ -3254,3 +3244,99 @@ sub delete_tax {
 
   $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();
+}
+