$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
- $form->{ALL};
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
push @{ $form->{ALL} }, $ref;
}
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
- $form->{ALL};
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
push @{ $form->{ALL} }, $ref;
}
$main::lxdebug->enter_sub();
my ($self, $myconfig, $form) = @_;
+ my $query;
# connect to database
my $dbh = $form->dbconnect($myconfig);
if ($form->{id}) {
- my $query =
+ $query =
qq|SELECT description, inventory_accno_id,
(SELECT accno FROM chart WHERE id = inventory_accno_id) AS inventory_accno,
income_accno_id_0,
$sth->finish;
- my $query =
+ $query =
qq|SELECT count(id) = 0 AS orphaned
FROM parts
WHERE buchungsgruppen_id = ?|;
$query = qq|UPDATE payment_terms SET
description = ?, description_long = ?,
- ranking = ?,
terms_netto = ?, terms_skonto = ?,
percent_skonto = ?
WHERE id = ?|;
my @values = ($form->{description}, $form->{description_long},
- $form->{ranking} * 1,
$form->{terms_netto} * 1, $form->{terms_skonto} * 1,
$form->{percent_skonto} * 1,
$form->{id});
# save first currency in myconfig
$form->{currency} = substr($form->{curr}, 0, 3);
- my $myconfig = new User "$memberfile", "$form->{login}";
+ $myconfig = new User "$memberfile", "$form->{login}";
foreach my $item (keys %$form) {
$myconfig->{$item} = $form->{$item};
$main::lxdebug->leave_sub();
}
+# if $a is translatable to $b, return the factor between them.
+# else return 1
+sub convert_unit {
+ $main::lxdebug->enter_sub(2);
+ ($this, $a, $b, $all_units) = @_;
+
+ $main::lxdebug->leave_sub(2) and return 0 unless $all_units->{$a} && $all_units->{$b};
+ $main::lxdebug->leave_sub(2) and return 0 unless $all_units->{$a}{base_unit} eq $all_units->{$b}{base_unit};
+ $main::lxdebug->leave_sub(2) and return $all_units->{$a}{factor} / $all_units->{$b}{factor};
+}
+
sub unit_select_data {
$main::lxdebug->enter_sub();
$main::lxdebug->leave_sub();
}
+sub save_price_factor {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->get_standard_dbh($myconfig);
+
+ my $query;
+ my @values = ($form->{description}, conv_i($form->{factor}));
+
+ if ($form->{id}) {
+ $query = qq|UPDATE price_factors SET description = ?, factor = ? WHERE id = ?|;
+ push @values, conv_i($form->{id});
+
+ } else {
+ $query = qq|INSERT INTO price_factors (description, factor, sortkey) VALUES (?, ?, (SELECT COALESCE(MAX(sortkey), 0) + 1 FROM price_factors))|;
+ }
+
+ do_query($form, $dbh, $query, @values);
+
+ $dbh->commit();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_all_price_factors {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->get_standard_dbh($myconfig);
+
+ $form->{PRICE_FACTORS} = selectall_hashref_query($form, $dbh, qq|SELECT * FROM price_factors ORDER BY sortkey|);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_price_factor {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->get_standard_dbh($myconfig);
+
+ my $query = qq|SELECT description, factor,
+ ((SELECT COUNT(*) FROM parts WHERE price_factor_id = ?) +
+ (SELECT COUNT(*) FROM invoice WHERE price_factor_id = ?) +
+ (SELECT COUNT(*) FROM orderitems WHERE price_factor_id = ?)) = 0 AS orphaned
+ FROM price_factors WHERE id = ?|;
+
+ ($form->{description}, $form->{factor}, $form->{orphaned}) = selectrow_query($form, $dbh, $query, (conv_i($form->{id})) x 4);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_price_factor {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->get_standard_dbh($myconfig);
+
+ do_query($form, $dbh, qq|DELETE FROM price_factors WHERE id = ?|, conv_i($form->{id}));
+ $dbh->commit();
+
+ $main::lxdebug->leave_sub();
+}
1;