use SL::DBUtils;
use SL::DO;
use SL::GenericTranslations;
+use SL::HTML::Restrict;
use SL::IO;
use SL::MoreCommon;
use SL::DB::Default;
+use SL::DB::TaxZone;
use List::Util qw(min);
use strict;
# connect to database, turn off autocommit
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
+ my $restricter = SL::HTML::Restrict->create;
+
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
my $defaultcurrency = $form->{defaultcurrency};
# update parts table by setting lastcost to current price, don't allow negative values by using abs
$query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|;
- @values = (abs($form->{"sellprice_$i"} / $basefactor), conv_i($form->{"id_$i"}));
+ @values = (abs($fxsellprice * $form->{exchangerate} / $basefactor), conv_i($form->{"id_$i"}));
do_query($form, $dbh, $query, @values);
# check if we sold the item already and
my $taxzone = $form->{taxzone_id} * 1;
$query =
qq|SELECT i.id, i.qty, i.allocated, i.trans_id, i.base_qty,
- bg.inventory_accno_id, bg.expense_accno_id_${taxzone} AS expense_accno_id, a.transdate
- FROM invoice i, ar a, parts p, buchungsgruppen bg
+ bg.inventory_accno_id, tc.expense_accno_id AS expense_accno_id, a.transdate
+ FROM invoice i, ar a, parts p, buchungsgruppen bg, taxzone_charts tc
WHERE (i.parts_id = p.id)
AND (i.parts_id = ?)
AND ((i.base_qty + i.allocated) > 0)
AND (i.trans_id = a.id)
AND (p.buchungsgruppen_id = bg.id)
+ AND (tc.buchungsgruppen_id = p.buchungsgruppen_id)
+ AND (tc.taxzone_id = ${taxzone})
ORDER BY transdate|;
# ORDER BY transdate guarantees FIFO
project_id, serialnumber, price_factor_id, price_factor, marge_price_factor)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, (SELECT factor FROM price_factors WHERE id = ?), ?)|;
@values = ($invoice_id, conv_i($form->{id}), conv_i($form->{"id_$i"}),
- $form->{"description_$i"}, $form->{"longdescription_$i"}, $form->{"qty_$i"} * -1,
+ $form->{"description_$i"}, $restricter->process($form->{"longdescription_$i"}), $form->{"qty_$i"} * -1,
$baseqty * -1, $form->{"sellprice_$i"}, $fxsellprice, $form->{"discount_$i"}, $allocated,
$form->{"unit_$i"}, conv_date($form->{deliverydate}),
conv_i($form->{"project_id_$i"}), $form->{"serialnumber_$i"},
# set values which could be empty
my $taxzone_id = $form->{taxzone_id} * 1;
+ $taxzone_id = SL::DB::Manager::TaxZone->get_default->id unless SL::DB::Manager::TaxZone->find_by(id => $taxzone_id);
# Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr
# korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen
}
$form->{invnumber} = $form->{id} unless $form->{invnumber};
- $taxzone_id = 0 if (3 < $taxzone_id) || (0 > $taxzone_id);
-
# save AP record
$query = qq|UPDATE ap SET
invnumber = ?, ordnumber = ?, quonumber = ?, transdate = ?,
}
- # add shipto
$form->{name} = $form->{vendor};
$form->{name} =~ s/--\Q$form->{vendor_id}\E//;
+
+ # add shipto
$form->add_shipto($dbh, $form->{id}, "AP");
# delete zero entries
map { $form->{$_} = $ref->{$_} } keys %$ref;
my $transdate = $form->{invdate} ? $dbh->quote($form->{invdate}) : "current_date";
- my $taxzone_id = $form->{taxzone_id} * 1;
- $taxzone_id = 0 if ((3 < $taxzone_id) || (0 > $taxzone_id));
+ my $taxzone_id = $form->{taxzone_id} * 1;
+ $taxzone_id = SL::DB::Manager::TaxZone->get_default->id unless SL::DB::Manager::TaxZone->find_by(id => $taxzone_id);
# retrieve individual items
$query =
FROM invoice i
JOIN parts p ON (i.parts_id = p.id)
LEFT JOIN chart c1 ON ((SELECT inventory_accno_id FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id)
- LEFT JOIN chart c2 ON ((SELECT income_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c2.id)
- LEFT JOIN chart c3 ON ((SELECT expense_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c3.id)
+ LEFT JOIN chart c2 ON ((SELECT tc.income_accno_id FROM taxzone_charts tc where tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c2.id)
+ LEFT JOIN chart c3 ON ((SELECT tc.expense_accno_id FROM taxzone_charts tc where tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c3.id)
LEFT JOIN project pr ON (i.project_id = pr.id)
LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id)
}
$sth->finish();
- # get shipto if we do not convert an order or invoice
- if (!$params->{shipto}) {
- delete @{$params}{qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail)};
-
- $query = qq|SELECT * FROM shipto WHERE (trans_id = ?) AND (module= 'CT')|;
- $ref = selectfirst_hashref_query($form, $dbh, $query, $vid);
- @{$params}{keys %$ref} = @{$ref}{keys %$ref};
- map { $params->{$_} = $ref->{$_} } keys %$ref;
- }
-
if (!$params->{id} && $params->{type} !~ /_(order|quotation)/) {
# setup last accounts used
$query =
}
my $taxzone_id = $form->{taxzone_id} * 1;
- $taxzone_id = 0 if ((3 < $taxzone_id) || (0 > $taxzone_id));
+ $taxzone_id = SL::DB::Manager::TaxZone->get_default->id unless SL::DB::Manager::TaxZone->find_by(id => $taxzone_id);
my $query =
qq|SELECT
FROM buchungsgruppen
WHERE id = p.buchungsgruppen_id) = c1.id)
LEFT JOIN chart c2 ON
- ((SELECT income_accno_id_${taxzone_id}
- FROM buchungsgruppen
- WHERE id = p.buchungsgruppen_id) = c2.id)
+ ((SELECT tc.income_accno_id
+ FROM taxzone_charts tc
+ WHERE tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c2.id)
LEFT JOIN chart c3 ON
- ((SELECT expense_accno_id_${taxzone_id}
- FROM buchungsgruppen
- WHERE id = p.buchungsgruppen_id) = c3.id)
+ ((SELECT tc.expense_accno_id
+ FROM taxzone_charts tc
+ WHERE tc.taxzone_id = '$taxzone_id' and tc.buchungsgruppen_id = p.buchungsgruppen_id) = c3.id)
LEFT JOIN partsgroup pg ON (pg.id = p.partsgroup_id)
LEFT JOIN price_factors pfac ON (pfac.id = p.price_factor_id)
WHERE $where|;