- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query = qq|SELECT id, lead
- FROM leads
- ORDER BY 2|;
-
- $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
- FROM leads l
- WHERE l.id = $form->{id}|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- 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) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $form->{lead} =~ s/\'/\'\'/g;
-
- # id is the old record
- if ($form->{id}) {
- $query = qq|UPDATE leads SET
- lead = '$form->{description}'
- WHERE id = $form->{id}|;
- } else {
- $query = qq|INSERT INTO leads
- (lead)
- VALUES ('$form->{description}')|;
- }
- $dbh->do($query) || $form->dberror($query);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_lead {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $query = qq|DELETE FROM leads
- WHERE id = $form->{id}|;
- $dbh->do($query) || $form->dberror($query);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub business {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query = qq|SELECT id, description, discount, customernumberinit, salesman
- FROM business
- ORDER BY 2|;
-
- $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_business {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- qq|SELECT b.description, b.discount, b.customernumberinit, b.salesman
- FROM business b
- WHERE b.id = $form->{id}|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $ref = $sth->fetchrow_hashref(NAME_lc);
-
- map { $form->{$_} = $ref->{$_} } keys %$ref;
-
- $sth->finish;
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_business {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $form->{description} =~ s/\'/\'\'/g;
- $form->{discount} /= 100;
- $form->{salesman} *= 1;
-
- # id is the old record
- if ($form->{id}) {
- $query = qq|UPDATE business SET
- description = '$form->{description}',
- discount = $form->{discount},
- customernumberinit = '$form->{customernumberinit}',
- salesman = '$form->{salesman}'
- WHERE id = $form->{id}|;
- } else {
- $query = qq|INSERT INTO business
- (description, discount, customernumberinit, salesman)
- VALUES ('$form->{description}', $form->{discount}, '$form->{customernumberinit}', '$form->{salesman}')|;
- }
- $dbh->do($query) || $form->dberror($query);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_business {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $query = qq|DELETE FROM business
- WHERE id = $form->{id}|;
- $dbh->do($query) || $form->dberror($query);
-
- $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";
-
- $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 = $dbh->selectrow_array($query, undef, $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 (?, ?, ?, ?, ?, ?)";
- }
- $dbh->do($query, undef, @values) ||
- $form->dberror($query . " (" . join(", ", @values) . ")");
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_language {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect_noauto($myconfig);
-
- my $query = "DELETE FROM units_language WHERE language_id = ?";
- $dbh->do($query, undef, $form->{"id"}) ||
- $form->dberror($query . " ($form->{id})");
-
- $query = "DELETE FROM language WHERE id = ?";
- $dbh->do($query, undef, $form->{"id"}) ||
- $form->dberror($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|;
-
- $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) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- if ($form->{id}) {
- my $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;
-
- my $query =
- qq|SELECT count(id) = 0 AS orphaned
- FROM parts
- WHERE buchungsgruppen_id = ?|;
- ($form->{orphaned}) = $dbh->selectrow_array($query, undef, $form->{id});
- $form->dberror($query . " ($form->{id})") if ($dbh->err);
- }
-
- $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"}) = $dbh->selectrow_array($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 MAX(sortkey) + 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);
-
- $query = qq|DELETE FROM buchungsgruppen WHERE id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub swap_buchungsgruppen {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect_noauto($myconfig);
-
- my $query =
- qq|SELECT
- (SELECT sortkey FROM buchungsgruppen WHERE id = ?) AS sortkey1,
- (SELECT sortkey FROM buchungsgruppen WHERE id = ?) AS sortkey2|;
- my @values = ($form->{"id1"}, $form->{"id2"});
- my @sortkeys = selectrow_query($form, $dbh, $query, @values);
-
- $query = qq|UPDATE buchungsgruppen SET sortkey = ? WHERE id = ?|;
- my $sth = $dbh->prepare($query);
- $sth->execute($sortkeys[1], $form->{"id1"}) ||
- $form->dberror($query . " ($sortkeys[1], $form->{id1})");
- $sth->execute($sortkeys[0], $form->{"id2"}) ||
- $form->dberror($query . " ($sortkeys[0], $form->{id2})");
- $sth->finish();
-
- $dbh->commit();
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub printer {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query = qq|SELECT id, printer_description, template_code, printer_command
- FROM printers
- ORDER BY 2|;
-
- $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_printer {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- qq|SELECT p.printer_description, p.template_code, p.printer_command
- FROM printers p
- WHERE p.id = $form->{id}|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $ref = $sth->fetchrow_hashref(NAME_lc);
-
- map { $form->{$_} = $ref->{$_} } keys %$ref;
-
- $sth->finish;
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_printer {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $form->{printer_description} =~ s/\'/\'\'/g;
- $form->{printer_command} =~ s/\'/\'\'/g;
- $form->{template_code} =~ s/\'/\'\'/g;
-
-
- # id is the old record
- if ($form->{id}) {
- $query = qq|UPDATE printers SET
- printer_description = '$form->{printer_description}',
- template_code = '$form->{template_code}',
- printer_command = '$form->{printer_command}'
- WHERE id = $form->{id}|;
- } else {
- $query = qq|INSERT INTO printers
- (printer_description, template_code, printer_command)
- VALUES ('$form->{printer_description}', '$form->{template_code}', '$form->{printer_command}')|;
- }
- $dbh->do($query) || $form->dberror($query);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_printer {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- $query = qq|DELETE FROM printers
- WHERE id = $form->{id}|;
- $dbh->do($query) || $form->dberror($query);
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub payment {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query = qq|SELECT *
- FROM payment_terms
- ORDER BY id|;
-
- $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100));
- push @{ $form->{ALL} }, $ref;
- }
-
- $sth->finish;
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_payment {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $query =
- qq|SELECT *
- FROM payment_terms
- WHERE id = $form->{id}|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- my $ref = $sth->fetchrow_hashref(NAME_lc);
- $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100));
-
- map { $form->{$_} = $ref->{$_} } keys %$ref;
-
- $sth->finish;
-
- $dbh->disconnect;
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_payment {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;