my $ref = $sth->fetchrow_hashref("NAME_lc");
map { $form->{$_} = $ref->{$_} } keys %$ref;
+ $sth->finish;
- # remove any trailing whitespace
- $form->{curr} =~ s/\s*$//;
+ #get name of currency instead of id:
+ $query = qq|SELECT name AS curr FROM currencies WHERE id=?|;
+ ($form->{curr}) = selectrow_query($form, $dbh, $query, conv_i($form->{currency_id}));
- $sth->finish;
if ( $form->{salesman_id} ) {
my $query =
qq|SELECT ct.name AS salesman | .
$query = qq|SELECT nextval('id')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO customer (id, name) VALUES (?, '')|;
+ $query = qq|INSERT INTO customer (id, name, currency_id) VALUES (?, '', (SELECT currency_id FROM defaults))|;
do_query($form, $dbh, $query, $form->{id});
}
qq|user_password = ?, | .
qq|c_vendor_id = ?, | .
qq|klass = ?, | .
- qq|curr = ?, | .
+ qq|currency_id = (SELECT id FROM currencies WHERE name = ?), | .
qq|taxincluded_checked = ? | .
qq|WHERE id = ?|;
my @values = (
$form->{user_password},
$form->{c_vendor_id},
conv_i($form->{klass}),
- substr($form->{currency}, 0, 3),
+ $form->{currency},
$form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef,
$form->{id}
);
$query = qq|SELECT nextval('id')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO vendor (id, name) VALUES (?, '')|;
+ $query = qq|INSERT INTO vendor (id, name, currency_id) VALUES (?, '', (SELECT currency_id FROM defaults))|;
do_query($form, $dbh, $query, $form->{id});
my $vendornumber = SL::TransNumber->new(type => 'vendor',
qq| username = ?, | .
qq| user_password = ?, | .
qq| v_customer_id = ?, | .
- qq| curr = ? | .
+ qq| currency_id = (SELECT id FROM currencies WHERE name = ?) | .
qq|WHERE id = ?|;
my @values = (
$form->{vendornumber},
$form->{username},
$form->{user_password},
$form->{v_customer_id},
- substr($form->{currency}, 0, 3),
+ $form->{currency},
$form->{id}
);
do_query($form, $dbh, $query, @values);
"salesman" => "e.name"
);
+ $form->{sort} ||= "name";
my $sortorder;
if ( $join_records ) {
# in UNION case order by hash key, e.g. salesman
- # the UNION created an implicit select around the result
- $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $form->{sort} : "name";
+ # the UNION created an implicit select around the result
+ $sortorder = $allowed_sort_columns{$form->{sort}} ? $form->{sort} : "name";
} else {
# in not UNION case order by hash value, e.g. e.name
- $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $allowed_sort_columns{$form->{sort}} : "ct.name";
- };
- $form->{sort} = $sortorder;
+ $sortorder = $allowed_sort_columns{$form->{sort}} ? $allowed_sort_columns{$form->{sort}} : "ct.name";
+ }
my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
if ($sortorder !~ /(business|id)/ && !$join_records) {
qq| WHERE cv.id = a.vendor_id)|;
}
$form->{l_invnumber} = $form->{l_ordnumber} = $form->{l_quonumber} = "";
- };
+ }
if ($form->{obsolete} eq "Y") {
$where .= qq| AND obsolete|;
}
$query .= qq| ORDER BY $sortorder|;
-
+
$form->{CT} = selectall_hashref_query($form, $dbh, $query, @values);
$main::lxdebug->leave_sub();