SL::DB::Invoice->new_from: auch Leistungsdatum (tax_point) übernehmen
[kivitendo-erp.git] / SL / GL.pm
index a1d3a9d..9eb741d 100644 (file)
--- a/SL/GL.pm
+++ b/SL/GL.pm
@@ -123,12 +123,12 @@ sub _post_transaction {
   $query =
     qq|UPDATE gl SET
          reference = ?, description = ?, notes = ?,
-         transdate = ?, deliverydate = ?, department_id = ?, taxincluded = ?,
+         transdate = ?, deliverydate = ?, tax_point = ?, department_id = ?, taxincluded = ?,
          storno = ?, storno_id = ?, ob_transaction = ?, cb_transaction = ?
        WHERE id = ?|;
 
   @values = ($form->{reference}, $form->{description}, $form->{notes},
-             conv_date($form->{transdate}), conv_date($form->{deliverydate}), conv_i($form->{department_id}), $form->{taxincluded} ? 't' : 'f',
+             conv_date($form->{transdate}), conv_date($form->{deliverydate}), conv_date($form->{tax_point}), conv_i($form->{department_id}), $form->{taxincluded} ? 't' : 'f',
              $form->{storno} ? 't' : 'f', conv_i($form->{storno_id}), $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f',
              conv_i($form->{id}));
   do_query($form, $dbh, $query, @values);
@@ -637,7 +637,7 @@ sub transaction {
 
   if ($form->{id}) {
     $query =
-      qq|SELECT g.reference, g.description, g.notes, g.transdate, g.deliverydate,
+      qq|SELECT g.reference, g.description, g.notes, g.transdate, g.deliverydate, g.tax_point,
            g.storno, g.storno_id,
            g.department_id, d.description AS department,
            e.name AS employee, g.taxincluded, g.gldate,
@@ -773,12 +773,22 @@ sub get_chart_balances {
 }
 
 sub get_active_taxes_for_chart {
-  my ($self, $chart_id, $transdate) = @_;
+  my ($self, $chart_id, $transdate, $tax_id) = @_;
 
   my $chart         = SL::DB::Chart->new(id => $chart_id)->load;
   my $active_taxkey = $chart->get_active_taxkey($transdate);
+
+  my $where = [ chart_categories => { like => '%' . $chart->category . '%' } ];
+
+  if ( defined $tax_id && $tax_id >= 0 ) {
+    $where = [ or => [ chart_categories => { like => '%' . $chart->category . '%' },
+                       id               => $tax_id
+                     ]
+             ];
+  }
+
   my $taxes         = SL::DB::Manager::Tax->get_all(
-    where   => [ chart_categories => { like => '%' . $chart->category . '%' }],
+    where   => $where,
     sort_by => 'taxkey, rate',
   );
 
@@ -789,3 +799,48 @@ sub get_active_taxes_for_chart {
 }
 
 1;
+
+__END__
+
+=pod
+
+=encoding utf8
+
+=head1 NAME
+
+SL::GL - some useful GL functions
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<get_active_taxes_for_chart> $transdate $tax_id
+
+Returns a list of valid taxes for a certain chart.
+
+If the optional param transdate exists one entry in the returning list
+may get the attribute C<is_default> for this specific tax-dependent date.
+The possible entries are filtered by the charttype of the tax, i.e. only taxes
+whose chart_categories match the category of the chart will be shown.
+
+In the case of existing records, e.g. when opening an old ar record, due to
+changes in the configurations the desired tax might not be available in the
+dropdown anymore. If we are loading an old record and know its tax_id (from
+acc_trans), we can pass $tax_id as the third parameter and be sure that the
+original tax always appears in the dropdown.
+
+The functions returns an array which may be used for building dropdowns in ar/ap/gl code.
+
+=back
+
+=head1 TODO
+
+=head1 BUGS
+
+Nothing here yet.
+
+=head1 AUTHOR
+
+G. Richardson E<lt>grichardson@kivitec.de<gt>
+
+=cut