Add support for billing date
authorJoey Schulze <joey@infodrom.org>
Wed, 3 May 2017 23:27:07 +0000 (01:27 +0200)
committerJoey Schulze <joey@infodrom.org>
Mon, 10 Jul 2017 20:48:29 +0000 (22:48 +0200)
src/InfoCon/buch/infocon

index 21e5fe7..b0d6961 100755 (executable)
@@ -465,6 +465,10 @@ sub buchung_input
            'title' => 'bezahlt',
            'type' => 'boolean',
            'default' => 0},
+       'billing_date' => {
+           'title' => 'wann',
+           'type' => 'date',
+           'validate' => \&validate_date},
        'weiter' => {
            'title' => 'Weiter',
            'type' => 'boolean',
@@ -486,16 +490,19 @@ sub buchung_input
            if ($f eq 'tax_assigned' && $answers->{'tax_percent'} == 0) {
                $answers->{$f} = 0;
                next;
-           } elsif ($f eq 'paid') {
+           }
+           $ans = read_input($f, $fields->{$f});
+           $answers->{$f} = $ans;
+
+           if ($f eq 'paid') {
                if ($answers->{paid}) {
-                   my @now = localtime(time);
-                   $answers->{billing_date} = sprintf('%04d-%02d-%02d', $now[5]+1900, $now[4]+1, $now[3]);
+                   $fields->{'billing_date'}{'default'} = $answers->{'date'};
+                   $ans = read_input('billing_date', $fields->{'billing_date'});
+                   $answers->{billing_date} = $ans;
                } else {
                    $answers->{billing_date} = undef;
                }
            }
-           $ans = read_input($f, $fields->{$f});
-           $answers->{$f} = $ans;
        }
 
        $sth->execute(get_next_nr(),
@@ -507,7 +514,7 @@ sub buchung_input
                      $answers->{tax_percent},
                      $answers->{tax_assigned},
                      $answers->{price},
-                     $answers->{billing_date},
+                     defined $answers->{billing_date} ? date_to_string($answers->{billing_date}) : undef,
                      $answers->{paid});
 
        $weiter = $answers->{weiter};