select_tag(): Funktionalität von "with_empty" wiederherstellen
[kivitendo-erp.git] / SL / IR.pm
index bd8bd59..1f0ae58 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -269,27 +269,37 @@ sub post_invoice {
 
             # allocated >= 0
             # add entry for inventory, this one is for the sold item
-            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?),
-                                (SELECT tax_id 
-                                FROM taxkeys 
-                                WHERE chart_id= (SELECT id  
-                                                 FROM chart 
-                                                 WHERE accno = ?) 
+            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?,
+                               (SELECT taxkey_id
+                                FROM taxkeys
+                                WHERE chart_id= ?
                                 AND startdate <= ?
-                                ORDER BY startdate DESC LIMIT 1))|;
-            @values = ($ref->{trans_id},  $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate});
+                                ORDER BY startdate DESC LIMIT 1),
+                               (SELECT tax_id
+                                FROM taxkeys
+                                WHERE chart_id= ?
+                                AND startdate <= ?
+                                ORDER BY startdate DESC LIMIT 1),
+                               (SELECT chart_link FROM chart WHERE id = ?))|;
+            @values = ($ref->{trans_id},  $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{transdate},
+                       $ref->{inventory_accno_id});
             do_query($form, $dbh, $query, @values);
 
 # add expense
-            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?),
-                                (SELECT tax_id 
-                                 FROM taxkeys 
-                                 WHERE chart_id= (SELECT id  
-                                                  FROM chart 
-                                                  WHERE accno = ?) 
-                                 AND startdate <= ? 
-                                 ORDER BY startdate DESC LIMIT 1))|;
-            @values = ($ref->{trans_id},  $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate});
+            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?,
+                                (SELECT taxkey_id
+                                 FROM taxkeys
+                                 WHERE chart_id= ?
+                                 AND startdate <= ?
+                                 ORDER BY startdate DESC LIMIT 1),
+                                (SELECT tax_id
+                                 FROM taxkeys
+                                 WHERE chart_id= ?
+                                 AND startdate <= ?
+                                 ORDER BY startdate DESC LIMIT 1),
+                                (SELECT chart_link FROM chart WHERE id = ?))|;
+            @values = ($ref->{trans_id},  $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{transdate}, $ref->{expense_accno_id}, $ref->{transdate},
+                       $ref->{expense_accno_id});
             do_query($form, $dbh, $query, @values);
           }
         };
@@ -492,18 +502,26 @@ sub post_invoice {
 
       next if $payments_only || !$form->{amount}{$trans_id}{$accno};
 
-      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link)
                   VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
-                  (SELECT taxkey_id  FROM chart WHERE accno = ?), ?,
-                  (SELECT tax_id 
-                   FROM taxkeys 
-                   WHERE chart_id= (SELECT id  
-                                    FROM chart 
-                                    WHERE accno = ?) 
-                   AND startdate <= ? 
-                   ORDER BY startdate DESC LIMIT 1))|;
+                  (SELECT taxkey_id
+                   FROM taxkeys
+                   WHERE chart_id= (SELECT id
+                                    FROM chart
+                                    WHERE accno = ?)
+                   AND startdate <= ?
+                   ORDER BY startdate DESC LIMIT 1),
+                  ?,
+                  (SELECT tax_id
+                   FROM taxkeys
+                   WHERE chart_id= (SELECT id
+                                    FROM chart
+                                    WHERE accno = ?)
+                   AND startdate <= ?
+                   ORDER BY startdate DESC LIMIT 1),
+                  (SELECT link FROM chart WHERE accno = ?))|;
       @values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno},
-                 conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}));
+                 conv_date($form->{invdate}), $accno, conv_date($form->{invdate}), $project_id, $accno, conv_date($form->{invdate}), $accno);
       do_query($form, $dbh, $query, @values);
     }
   }
@@ -538,18 +556,26 @@ sub post_invoice {
 
     # record AP
     if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) {
-      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link)
                   VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
-                          (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
-                          (SELECT tax_id 
-                           FROM taxkeys 
-                           WHERE chart_id= (SELECT id  
-                                            FROM chart 
-                                            WHERE accno = ?) 
-                           AND startdate <= ? 
-                           ORDER BY startdate DESC LIMIT 1))|;
+                          (SELECT taxkey_id
+                           FROM taxkeys
+                           WHERE chart_id= (SELECT id
+                                            FROM chart
+                                            WHERE accno = ?)
+                           AND startdate <= ?
+                           ORDER BY startdate DESC LIMIT 1),
+                          ?,
+                          (SELECT tax_id
+                           FROM taxkeys
+                           WHERE chart_id= (SELECT id
+                                            FROM chart
+                                            WHERE accno = ?)
+                           AND startdate <= ?
+                           ORDER BY startdate DESC LIMIT 1),
+                          (SELECT link FROM chart WHERE accno = ?))|;
       @values = (conv_i($form->{id}), $form->{AP}, $amount,
-                 $form->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}));
+                 $form->{"datepaid_$i"}, $form->{AP}, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP});
       do_query($form, $dbh, $query, @values);
     }
 
@@ -557,17 +583,24 @@ sub post_invoice {
     my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
 
     $query =
-      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id)
+      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id, chart_link)
                 VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
-                (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
-                (SELECT tax_id 
-                 FROM taxkeys 
-                 WHERE chart_id= (SELECT id  
-                                  FROM chart WHERE accno = ?) 
-                 AND startdate <= ? 
-                 ORDER BY startdate DESC LIMIT 1))|;
+                (SELECT taxkey_id
+                 FROM taxkeys
+                 WHERE chart_id= (SELECT id
+                                  FROM chart WHERE accno = ?)
+                 AND startdate <= ?
+                 ORDER BY startdate DESC LIMIT 1),
+                ?,
+                (SELECT tax_id
+                 FROM taxkeys
+                 WHERE chart_id= (SELECT id
+                                  FROM chart WHERE accno = ?)
+                 AND startdate <= ?
+                 ORDER BY startdate DESC LIMIT 1),
+                (SELECT link FROM chart WHERE accno = ?))|;
     @values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
-               $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}));
+               $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($form->{"datepaid_$i"}), $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno);
     do_query($form, $dbh, $query, @values);
 
     $exchangerate = 0;
@@ -605,16 +638,11 @@ sub post_invoice {
       $form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2);
       next if ($form->{fx}{$accno}{$transdate} == 0);
 
-      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id)
+      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id, chart_link)
                   VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?,
-                  (SELECT tax_id 
-                   FROM taxkeys 
-                   WHERE chart_id= (SELECT id  
-                                   FROM chart 
-                                   WHERE accno = ?) 
-                   AND startdate <= ? 
-                   ORDER BY startdate DESC LIMIT 1))|;
-      @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate});
+                  (SELECT id FROM tax WHERE taxkey=0 LIMIT 1),
+                  (SELECT link FROM chart WHERE accno = ?))|;
+      @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno);
       do_query($form, $dbh, $query, @values);
     }
   }
@@ -1286,7 +1314,6 @@ sub retrieve_item {
     my $i = 0;
     while (my $ptr = $stw->fetchrow_hashref("NAME_lc")) {
 
-      #    if ($customertax{$ref->{accno}}) {
       if (($ptr->{accno} eq "") && ($ptr->{rate} == 0)) {
         $i++;
         $ptr->{accno} = $i;