Debugcode wieder entfernt.
[kivitendo-erp.git] / bin / mozilla / am.pl
index 02290c7..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>
@@ -3137,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();
+}
+