+
+ exit unless $field;
+}
+
+sub validate_date
+{
+ my $ans = shift;
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+
+ return sprintf("%d.%d.%d", $mday, $mon+1, $year+1900) unless length $ans;
+
+ my @arr = split(/\./, $ans);
+
+ return sprintf("%d.%d.%d", $ans, $mon+1, $year+1900) if scalar @arr == 1;
+ return sprintf("%d.%d.%d", $arr[0], $arr[1], $year+1900) if scalar @arr == 2;
+ return sprintf("%d.%d.%d", $arr[0], $arr[1],
+ length $arr[2] > 2 ? $arr[2] : $arr[2] + 2000);
+}
+
+my $answers;
+sub calculate_price
+{
+ my $ans = shift;
+
+ if (!defined $answers->{tax_assigned} || !length $answers->{tax_assigned}) {
+ $answers->{tax_assigned} = $ans - ($ans / ((100+$answers->{tax_percent})/100));
+ }
+
+ if ($answers->{einaus} =~ /[ei]/i) {
+ $answers->{tax_assigned} *= -1 if $answers->{tax_assigned} < 0;
+ $ans *= -1 if $ans < 0;
+ } else {
+ $answers->{tax_assigned} *= -1 if $answers->{tax_assigned} > 0;
+ $ans *= -1 if $ans > 0;
+ }
+
+ return $ans;
+}
+
+sub complete_category
+{
+ my ($text, $line, $start) = @_;
+
+ return () unless exists $answers->{category} && length $answers->{category};
+
+ my $sql = sprintf("SELECT DISTINCT description FROM %s WHERE category = '%s' AND description LIKE '%s%%' ORDER BY description",
+ $table,
+ $answers->{category},
+ $line);
+ my $sth = $dbh->prepare($sql);
+ $sth->execute;
+ my @complete;
+ while (my $row = $sth->fetchrow_hashref) {
+ $row->{description} = substr $row->{description}, $start if $start;
+ push @complete, $row->{description};
+ }
+
+ return @complete;
+}
+
+sub complete_categoryname
+{
+ my ($text, $line, $start) = @_;
+
+ return () unless length $line;
+
+ my $sql = sprintf("SELECT DISTINCT category FROM %s WHERE category LIKE '%s%%' ORDER BY category",
+ $table,
+ $line);
+ my $sth = $dbh->prepare($sql);
+ $sth->execute;
+ my @complete;
+ while (my $row = $sth->fetchrow_hashref) {
+ $row->{category} = substr $row->{category}, $start if $start;
+ push @complete, $row->{category};
+ }
+
+ return @complete;
+}
+
+sub default_year
+{
+ my $answers = shift;
+
+ my @arr = split(/\./, $answers->{date});
+ return $arr[2];