taxdescription = ?,
rate = ?,
chart_id = ?,
- taxnumber = (SELECT accno FROM chart WHERE id = ? ),
skonto_sales_chart_id = ?,
skonto_purchase_chart_id = ?,
chart_categories = ?
taxdescription,
rate,
chart_id,
- taxnumber,
skonto_sales_chart_id,
skonto_purchase_chart_id,
chart_categories,
comma(tk.startdate::text) AS startdate,
comma(tk.taxkey_id::text) AS taxkey,
comma(tx.taxdescription || to_char (tx.rate, '99V99' ) || '%') AS taxdescription,
- comma(tx.taxnumber::text) AS taxaccount,
+ comma(taxchart.accno::text) AS taxaccount,
comma(tk.pos_ustva::text) AS tk_ustva,
( SELECT accno
FROM chart c2
FROM chart c
LEFT JOIN taxkeys tk ON (c.id = tk.chart_id)
LEFT JOIN tax tx ON (tk.tax_id = tx.id)
+ LEFT JOIN chart taxchart ON (taxchart.id = tx.chart_id)
WHERE 1=1
$where
GROUP BY c.accno, c.id, c.description, c.charttype,
skonto_sales_chart_id => { type => 'integer' },
taxdescription => { type => 'text', not_null => 1 },
taxkey => { type => 'integer', not_null => 1 },
- taxnumber => { type => 'text' },
);
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
SQL
my $query_tax = <<SQL;
- SELECT c.accno, t.taxdescription AS description, t.rate, t.taxnumber
+ SELECT c.accno, t.taxdescription AS description, t.rate,
+ c.accno as taxnumber
FROM tax t
LEFT JOIN chart c ON c.id = t.chart_id
WHERE t.id IN
# get tax rates and description
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
$query =
- qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber FROM tax t
+ qq|SELECT c.accno, t.taxdescription, t.rate,
+ c.accno as taxnumber -- taxnumber is same as accno, but still accessed as taxnumber in code
+ FROM tax t
LEFT JOIN chart c ON (c.id = t.chart_id)
WHERE t.id in
(SELECT tk.tax_id FROM taxkeys tk
# get tax rates and description
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
$query =
- qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber
+ qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
FROM tax t
LEFT JOIN chart c on (c.id = t.chart_id)
WHERE t.id IN
push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} }, $form->{"${item}_rate"} * 100);
push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} }, $form->{"${item}_taxnumber"});
- my $tax_obj = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"});
+ # taxnumber is used for grouping the amount of the various taxes
+
+ # this code assumes that at most one tax entry can point to the same
+ # chart_id, even though chart_id does not have a unique constraint!
+
+ # this chart_id is then looked up via its accno, which is the key that is
+ # used to group the different taxes by for a record
+
+ # not every tax has a taxnumber (e.g. tax-free), but that is ok, because
+ # then there would be no tax amount to assign it to
+
+ my $tax_objs = SL::DB::Manager::Tax->get_objects_from_sql(
+ sql => 'SELECT * FROM tax WHERE chart_id = (SELECT id FROM chart WHERE accno = ?)',
+ args => [ $form->{"${item}_taxnumber"} ]
+ );
+ my $tax_obj;
+ if ( $tax_objs ) {
+ $tax_obj = $tax_objs->[0];
+ }
my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) : '';
push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
}
# get tax rates and description
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
$query =
- qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber FROM tax t
+ qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
+ FROM tax t
LEFT JOIN chart c ON (c.id = t.chart_id)
WHERE t.id IN
(SELECT tk.tax_id FROM taxkeys tk
# get tax rates and description
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
$query =
- qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber
+ qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
FROM tax t
LEFT JOIN chart c ON (c.id = t.chart_id)
WHERE t.id in
# get tax rates and description
my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
$query =
- qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber | .
- qq|FROM tax t LEFT JOIN chart c on (c.id = t.chart_id) | .
+ qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber | .
+ qq|FROM tax t | .
+ qq|LEFT JOIN chart c on (c.id = t.chart_id) | .
qq|WHERE t.id IN (SELECT tk.tax_id FROM taxkeys tk | .
qq| WHERE tk.chart_id = (SELECT id FROM chart WHERE accno = ?) | .
qq| AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1) | .
push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} }, $form->{"${item}_rate"} * 100);
push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} }, $form->{"${item}_taxnumber"});
- my $tax_obj = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"});
+ my $tax_objs = SL::DB::Manager::Tax->get_objects_from_sql(
+ sql => 'SELECT * from tax where chart_id = (SELECT id FROM chart WHERE accno = ?)',
+ args => [ $form->{"${item}_taxnumber"} ]
+ );
+ my $tax_obj;
+ if ( $tax_objs ) {
+ $tax_obj = $tax_objs->[0];
+ }
my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) : '';
push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
}
if (!$self->{handles}->{get_tax_info}) {
$self->{queries}->{get_tax_info} = qq|
- SELECT t.rate AS taxrate, t.taxnumber, t.taxdescription, t.chart_id AS taxchart_id,
+ SELECT t.rate AS taxrate, c.accno as taxnumber, t.taxdescription, t.chart_id AS taxchart_id,
c.accno AS taxaccno, c.description AS taxaccount
FROM taxkeys tk
LEFT JOIN tax t ON (tk.tax_id = t.id)