use SL::DB::AuthUser;
use SL::DB::Default;
use SL::DB::Employee;
+use SL::DB::Chart;
use SL::GenericTranslations;
use strict;
my ($self, $myconfig, $form) = @_;
+
+ my $chart_obj = SL::DB::Manager::Chart->find_by(id => $form->{id}) || die "Can't open chart";
+
# connect to database
my $dbh = $form->dbconnect($myconfig);
my $query = qq{
SELECT c.accno, c.description, c.charttype, c.category,
- c.link, c.pos_bilanz, c.pos_eur, c.new_chart_id, c.valid_from,
+ c.link, c.pos_bilanz, c.pos_eur, c.pos_er, c.new_chart_id, c.valid_from,
c.pos_bwa, datevautomatik,
tk.taxkey_id, tk.pos_ustva, tk.tax_id,
tk.tax_id || '--' || tk.taxkey_id AS tax, tk.startdate
$sth->finish;
}
- # check if we have any transactions
- $query = qq|SELECT a.trans_id FROM acc_trans a
- WHERE a.chart_id = ?|;
- $main::lxdebug->message(LXDebug->QUERY(), "\$query=\n $query");
- $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})");
- ($form->{orphaned}) = $sth->fetchrow_array;
- $form->{orphaned} = !$form->{orphaned};
- $sth->finish;
+ # check if there any transactions for this chart
+ $form->{orphaned} = $chart_obj->has_transaction ? 0 : 1;
# check if new account is active
- $form->{new_chart_valid} = 0;
- if ($form->{new_chart_id}) {
- $query = qq|SELECT current_date-valid_from FROM chart
- WHERE id = ?|;
- $main::lxdebug->message(LXDebug->QUERY(), "\$query=\n $query");
- my ($count) = selectrow_query($form, $dbh, $query, $form->{id});
- if ($count >=0) {
- $form->{new_chart_valid} = 1;
- }
- $sth->finish;
- }
+ # The old sql query was broken since at least 2006 and always returned 0
+ $form->{new_chart_valid} = $chart_obj->new_chart_valid;
$dbh->disconnect;
pos_bwa = ?,
pos_bilanz = ?,
pos_eur = ?,
+ pos_er = ?,
new_chart_id = ?,
valid_from = ?,
datevautomatik = ?
conv_i($form->{pos_bwa}),
conv_i($form->{pos_bilanz}),
conv_i($form->{pos_eur}),
+ conv_i($form->{pos_er}),
conv_i($form->{new_chart_id}),
conv_date($form->{valid_from}),
($form->{datevautomatik} eq 'T') ? 'true':'false',
t.taxdescription,
round(t.rate * 100, 2) AS rate,
(SELECT accno FROM chart WHERE id = chart_id) AS taxnumber,
- (SELECT description FROM chart WHERE id = chart_id) AS account_description
+ (SELECT description FROM chart WHERE id = chart_id) AS account_description,
+ (SELECT accno FROM chart WHERE id = skonto_sales_chart_id) AS skonto_chart_accno,
+ (SELECT description FROM chart WHERE id = skonto_sales_chart_id) AS skonto_chart_description,
+ (SELECT accno FROM chart WHERE id = skonto_purchase_chart_id) AS skonto_chart_purchase_accno,
+ (SELECT description FROM chart WHERE id = skonto_purchase_chart_id) AS skonto_chart_purchase_description
FROM tax t
ORDER BY taxkey, rate|;
push @{ $form->{ACCOUNTS} }, $ref;
}
+ $form->{AR_PAID} = SL::DB::Manager::Chart->get_all(where => [ link => { like => '%AR_paid%' } ], sort_by => 'accno ASC');
+ $form->{AP_PAID} = SL::DB::Manager::Chart->get_all(where => [ link => { like => '%AP_paid%' } ], sort_by => 'accno ASC');
+
+ $form->{skontochart_value_title_sub} = sub {
+ my $item = shift;
+ return [
+ $item->{id},
+ $item->{accno} .' '. $item->{description},
+ ];
+ };
+
$sth->finish;
$dbh->disconnect;
chart_id,
chart_categories,
(id IN (SELECT tax_id
- FROM acc_trans)) AS tax_already_used
+ FROM acc_trans)) AS tax_already_used,
+ skonto_sales_chart_id,
+ skonto_purchase_chart_id
FROM tax
WHERE id = ? |;
$chart_categories .= 'E' if $form->{expense};
$chart_categories .= 'C' if $form->{costs};
- my @values = ($form->{taxkey}, $form->{taxdescription}, $form->{rate}, conv_i($form->{chart_id}), conv_i($form->{chart_id}), $chart_categories);
+ my @values = ($form->{taxkey}, $form->{taxdescription}, $form->{rate}, conv_i($form->{chart_id}), conv_i($form->{chart_id}), conv_i($form->{skonto_sales_chart_id}), conv_i($form->{skonto_purchase_chart_id}), $chart_categories);
if ($form->{id} ne "") {
$query = qq|UPDATE tax SET
- taxkey = ?,
- taxdescription = ?,
- rate = ?,
- chart_id = ?,
- taxnumber = (SELECT accno FROM chart WHERE id= ? ),
- chart_categories = ?
+ taxkey = ?,
+ taxdescription = ?,
+ rate = ?,
+ chart_id = ?,
+ taxnumber = (SELECT accno FROM chart WHERE id = ? ),
+ skonto_sales_chart_id = ?,
+ skonto_purchase_chart_id = ?,
+ chart_categories = ?
WHERE id = ?|;
} else {
rate,
chart_id,
taxnumber,
+ skonto_sales_chart_id,
+ skonto_purchase_chart_id,
chart_categories,
id
)
- VALUES (?, ?, ?, ?, (SELECT accno FROM chart WHERE id = ?), ?, ?)|;
+ VALUES (?, ?, ?, ?, (SELECT accno FROM chart WHERE id = ?), ?, ?, ?, ?)|;
}
push(@values, $form->{id});
do_query($form, $dbh, $query, @values);