Speichern und Anzeigen eines Verkäufers bei Verkaufsmasken.
[kivitendo-erp.git] / SL / CA.pm
index 28ffc2e..91df43c 100644 (file)
--- a/SL/CA.pm
+++ b/SL/CA.pm
@@ -42,7 +42,7 @@ sub all_accounts {
 
   my ($self, $myconfig, $form) = @_;
 
-  my $amount = ();
+  my %amount;
 
   # connect to database
   my $dbh = $form->dbconnect($myconfig);
@@ -65,16 +65,43 @@ sub all_accounts {
   $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
 
-  my $gifi = ();
+  my %gifi;
   while (my ($accno, $description) = $sth->fetchrow_array) {
     $gifi{$accno} = $description;
   }
   $sth->finish;
 
-  $query = qq|SELECT c.id, c.accno, c.description, c.charttype, c.gifi_accno,
-              c.category, c.link
-              FROM chart c
-             ORDER BY accno|;
+  $query = qq{
+    SELECT 
+      c.accno,
+      c.id,
+      c.description,
+      c.charttype,
+      c.category,
+      c.link,
+      c.pos_bwa,
+      c.pos_bilanz,
+      c.pos_eur,
+      c.valid_from,
+      c.datevautomatik,
+      comma(tk.startdate) AS startdate,
+      comma(tk.taxkey_id) AS taxkey,
+      comma(tx.taxdescription || to_char (tx.rate, '99V99' ) || '%') AS taxdescription,
+      comma(tx.taxnumber) AS taxaccount,
+      comma(tk.pos_ustva) AS tk_ustva,
+      ( SELECT accno
+      FROM chart c2
+      WHERE c2.id = c.id
+      ) AS new_account
+    FROM chart c
+    LEFT JOIN taxkeys tk ON (c.id = tk.chart_id)
+    LEFT JOIN tax tx ON (tk.tax_id = tx.id)
+    GROUP BY c.accno, c.id, c.description, c.charttype, c.gifi_accno,
+      c.category, c.link, c.pos_bwa, c.pos_bilanz, c.pos_eur, c.valid_from,      
+      c.datevautomatik
+    ORDER BY c.accno
+  };
+
   $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
 
@@ -144,29 +171,11 @@ sub all_transactions {
     $glwhere .= " AND ac.transdate <= '$form->{todate}'";
   }
 
-  if ($form->{eur}) {
-    $AR_PAID = qq|AND ac.trans_id IN
-                  (
-                    SELECT trans_id
-                    FROM acc_trans
-                    JOIN chart ON (chart_id = id)
-                    WHERE link LIKE '%AR_paid%'
-                    $subwhere
-                  )|;
-    $AP_PAID = qq|AND ac.trans_id IN
-                  (
-                    SELECT trans_id
-                    FROM acc_trans
-                    JOIN chart ON (chart_id = id)
-                    WHERE link LIKE '%AP_paid%'
-                    $subwhere
-                  )|;
-  } else {
-    $where .= $fromto;
-    $AR_PAID = "";
-    $AP_PAID = "";
-    $glwhere = "";    # note! gl will be aliased as "a" later...
-  }
+
+  $where .= $fromto;
+  $AR_PAID = "";
+  $AP_PAID = "";
+  $glwhere = "";    # note! gl will be aliased as "a" later...
   my $sortorder = join ', ',
     $form->sort_columns(qw(transdate reference description));
   my $false = ($myconfig->{dbdriver} eq 'Pg') ? FALSE: q|'0'|;