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',