- WHERE chart_id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- # delete chart of account record
- $query = qq|DELETE FROM chart
- WHERE id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- # delete account taxkeys
- $query = qq|DELETE FROM taxkeys
- WHERE chart_id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- # commit and redirect
- my $rc = $dbh->commit;
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-
- return $rc;
-}
-
-sub lead {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query = qq|SELECT id, lead
- FROM leads
- ORDER BY 2|;
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
- push @{ $form->{ALL} }, $ref;
- }
-
- $sth->finish;
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_lead {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- qq|SELECT l.id, l.lead | .
- qq|FROM leads l | .
- qq|WHERE l.id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})");
-
- my $ref = $sth->fetchrow_hashref("NAME_lc");
-
- map { $form->{$_} = $ref->{$_} } keys %$ref;
-
- $sth->finish;
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_lead {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
- my ($query);
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my @values = ($form->{description});
- # id is the old record
- if ($form->{id}) {
- $query = qq|UPDATE leads SET
- lead = ?
- WHERE id = ?|;
- push(@values, $form->{id});
- } else {
- $query = qq|INSERT INTO leads
- (lead)
- VALUES (?)|;
- }
- do_query($form, $dbh, $query, @values);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_lead {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
- my ($query);
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $query = qq|DELETE FROM leads
- WHERE id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub language {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form, $return_list) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- "SELECT id, description, template_code, article_code, " .
- " output_numberformat, output_dateformat, output_longdates " .
- "FROM language ORDER BY description";
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $ary = [];
-
- while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
- push(@{ $ary }, $ref);
- }
-
- $sth->finish;
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-
- if ($return_list) {
- return @{$ary};
- } else {
- $form->{ALL} = $ary;
- }
-}
-
-sub get_language {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- "SELECT description, template_code, article_code, " .
- " output_numberformat, output_dateformat, output_longdates " .
- "FROM language WHERE id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{"id"}) || $form->dberror($query . " ($form->{id})");
-
- my $ref = $sth->fetchrow_hashref("NAME_lc");
-
- map { $form->{$_} = $ref->{$_} } keys %$ref;
-
- $sth->finish;
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_language_details {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form, $id) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- "SELECT template_code, " .
- " output_numberformat, output_dateformat, output_longdates " .
- "FROM language WHERE id = ?";
- my @res = selectrow_query($form, $dbh, $query, $id);
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-
- return @res;
-}
-
-sub save_language {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
- my (@values, $query);
-
- map({ push(@values, $form->{$_}); }
- qw(description template_code article_code
- output_numberformat output_dateformat output_longdates));
-
- # id is the old record
- if ($form->{id}) {
- $query =
- "UPDATE language SET " .
- " description = ?, template_code = ?, article_code = ?, " .
- " output_numberformat = ?, output_dateformat = ?, " .
- " output_longdates = ? " .
- "WHERE id = ?";
- push(@values, $form->{id});
- } else {
- $query =
- "INSERT INTO language (" .
- " description, template_code, article_code, " .
- " output_numberformat, output_dateformat, output_longdates" .
- ") VALUES (?, ?, ?, ?, ?, ?)";
- }
- do_query($form, $dbh, $query, @values);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_language {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
- my $query;
-
- # connect to database
- my $dbh = $form->dbconnect_noauto($myconfig);
-
- foreach my $table (qw(generic_translations units_language)) {
- $query = qq|DELETE FROM $table WHERE language_id = ?|;
- do_query($form, $dbh, $query, $form->{"id"});
- }
-
- $query = "DELETE FROM language WHERE id = ?";
- do_query($form, $dbh, $query, $form->{"id"});
-
- $dbh->commit();
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-
-sub buchungsgruppe {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query = qq|SELECT id, description,
- inventory_accno_id,
- (SELECT accno FROM chart WHERE id = inventory_accno_id) AS inventory_accno,
- income_accno_id_0,
- (SELECT accno FROM chart WHERE id = income_accno_id_0) AS income_accno_0,
- expense_accno_id_0,
- (SELECT accno FROM chart WHERE id = expense_accno_id_0) AS expense_accno_0,
- income_accno_id_1,
- (SELECT accno FROM chart WHERE id = income_accno_id_1) AS income_accno_1,
- expense_accno_id_1,
- (SELECT accno FROM chart WHERE id = expense_accno_id_1) AS expense_accno_1,
- income_accno_id_2,
- (SELECT accno FROM chart WHERE id = income_accno_id_2) AS income_accno_2,
- expense_accno_id_2,
- (select accno FROM chart WHERE id = expense_accno_id_2) AS expense_accno_2,
- income_accno_id_3,
- (SELECT accno FROM chart WHERE id = income_accno_id_3) AS income_accno_3,
- expense_accno_id_3,
- (SELECT accno FROM chart WHERE id = expense_accno_id_3) AS expense_accno_3
- FROM buchungsgruppen
- ORDER BY sortkey|;
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- $form->{ALL} = [];
- while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
- push @{ $form->{ALL} }, $ref;
- }
-
- $sth->finish;
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_buchungsgruppe {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
- my $query;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- if ($form->{id}) {
- $query =
- qq|SELECT description, inventory_accno_id,
- (SELECT accno FROM chart WHERE id = inventory_accno_id) AS inventory_accno,
- income_accno_id_0,
- (SELECT accno FROM chart WHERE id = income_accno_id_0) AS income_accno_0,
- expense_accno_id_0,
- (SELECT accno FROM chart WHERE id = expense_accno_id_0) AS expense_accno_0,
- income_accno_id_1,
- (SELECT accno FROM chart WHERE id = income_accno_id_1) AS income_accno_1,
- expense_accno_id_1,
- (SELECT accno FROM chart WHERE id = expense_accno_id_1) AS expense_accno_1,
- income_accno_id_2,
- (SELECT accno FROM chart WHERE id = income_accno_id_2) AS income_accno_2,
- expense_accno_id_2,
- (select accno FROM chart WHERE id = expense_accno_id_2) AS expense_accno_2,
- income_accno_id_3,
- (SELECT accno FROM chart WHERE id = income_accno_id_3) AS income_accno_3,
- expense_accno_id_3,
- (SELECT accno FROM chart WHERE id = expense_accno_id_3) AS expense_accno_3
- FROM buchungsgruppen
- WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})");
-
- my $ref = $sth->fetchrow_hashref("NAME_lc");
-
- map { $form->{$_} = $ref->{$_} } keys %$ref;
-
- $sth->finish;
-
- $query =
- qq|SELECT count(id) = 0 AS orphaned
- FROM parts
- WHERE buchungsgruppen_id = ?|;
- ($form->{orphaned}) = selectrow_query($form, $dbh, $query, $form->{id});
- }
-
- $query = "SELECT inventory_accno_id, income_accno_id, expense_accno_id ".
- "FROM defaults";
- ($form->{"std_inventory_accno_id"}, $form->{"std_income_accno_id"},
- $form->{"std_expense_accno_id"}) = selectrow_query($form, $dbh, $query);
-
- my $module = "IC";
- $query = qq|SELECT c.accno, c.description, c.link, c.id,
- d.inventory_accno_id, d.income_accno_id, d.expense_accno_id
- FROM chart c, defaults d
- WHERE c.link LIKE '%$module%'
- ORDER BY c.accno|;
-
-
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
- while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
- foreach my $key (split(/:/, $ref->{link})) {
- if (!$form->{"std_inventory_accno_id"} && ($key eq "IC")) {
- $form->{"std_inventory_accno_id"} = $ref->{"id"};
- }
- if ($key =~ /$module/) {
- if ( ($ref->{id} eq $ref->{inventory_accno_id})
- || ($ref->{id} eq $ref->{income_accno_id})
- || ($ref->{id} eq $ref->{expense_accno_id})) {
- push @{ $form->{"${module}_links"}{$key} },
- { accno => $ref->{accno},
- description => $ref->{description},
- selected => "selected",
- id => $ref->{id} };
- } else {
- push @{ $form->{"${module}_links"}{$key} },
- { accno => $ref->{accno},
- description => $ref->{description},
- selected => "",
- id => $ref->{id} };
- }
- }
- }
- }
- $sth->finish;
-
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_buchungsgruppe {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my @values = ($form->{description}, $form->{inventory_accno_id},
- $form->{income_accno_id_0}, $form->{expense_accno_id_0},
- $form->{income_accno_id_1}, $form->{expense_accno_id_1},
- $form->{income_accno_id_2}, $form->{expense_accno_id_2},
- $form->{income_accno_id_3}, $form->{expense_accno_id_3});
-
- my $query;
-
- # id is the old record
- if ($form->{id}) {
- $query = qq|UPDATE buchungsgruppen SET
- description = ?, inventory_accno_id = ?,
- income_accno_id_0 = ?, expense_accno_id_0 = ?,
- income_accno_id_1 = ?, expense_accno_id_1 = ?,
- income_accno_id_2 = ?, expense_accno_id_2 = ?,
- income_accno_id_3 = ?, expense_accno_id_3 = ?
- WHERE id = ?|;
- push(@values, $form->{id});
- } else {
- $query = qq|SELECT COALESCE(MAX(sortkey) + 1, 1) FROM buchungsgruppen|;
- my ($sortkey) = $dbh->selectrow_array($query);
- $form->dberror($query) if ($dbh->err);
- push(@values, $sortkey);
- $query = qq|INSERT INTO buchungsgruppen
- (description, inventory_accno_id,
- income_accno_id_0, expense_accno_id_0,
- income_accno_id_1, expense_accno_id_1,
- income_accno_id_2, expense_accno_id_2,
- income_accno_id_3, expense_accno_id_3,
- sortkey)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
- }
- do_query($form, $dbh, $query, @values);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_buchungsgruppe {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);