DeliveryOrder: fix validate on save
[kivitendo-erp.git] / SL / Controller / DeliveryOrder / TypeData.pm
1 package SL::Controller::DeliveryOrder::TypeData;
2
3 use strict;
4 use Exporter qw(import);
5 use Scalar::Util qw(weaken);
6 use SL::Locale::String qw(t8);
7 use SL::DB::DeliveryOrder::TypeData qw(:types :subs);
8
9 use Rose::Object::MakeMethods::Generic scalar => [ qw(c) ];
10
11 sub new {
12   my ($class, $controller) = @_;
13   my $o = bless {}, $class;
14
15   if ($controller) {
16     $o->c($controller);
17     weaken($o->{c});
18   }
19
20   return $o;
21 }
22
23 sub validate {
24   my ($self, $string) = @_;
25   validate_type($string);
26 }
27
28 sub text {
29   my ($self, $string) = @_;
30   get3($self->c->type, "text", $string);
31 }
32
33 sub show_menu {
34   my ($self, $string) = @_;
35   get3($self->c->type, "show_menu", $string);
36 }
37
38 sub workflow {
39   my ($self, $string) = @_;
40   get3($self->c->type, "workflow", $string);
41 }
42
43 sub properties {
44   my ($self, $string) = @_;
45   get3($self->c->type, "properties", $string);
46 }
47
48 sub access {
49   get($_[0]->c->type, "right");
50 }
51
52 sub is_quotation {
53   get3($_[0]->c->type, "properties", "is_quotation");
54 }
55
56 sub customervendor {
57   get3($_[0]->c->type, "properties", "customervendor");
58 }
59
60 sub is_customer {
61   get3($_[0]->c->type, "properties", "is_customer");
62 }
63
64 sub nr_key {
65   get3($_[0]->c->type, "properties", "nr_key");
66 }
67
68 sub part_classification_query {
69   my ($self, $string) = @_;
70   get($self->c->type, "part_classification_query");
71 }
72
73 sub set_reqdate_by_type {
74   my ($self) = @_;
75
76   if (!$self->c->order->reqdate) {
77     $self->c->order->reqdate(DateTime->today_local->next_workday(extra_days => 1));
78   }
79 }
80
81 sub get_reqdate_by_type {
82   my ($self, $reqdate, $saved_reqdate) = @_;
83
84   if ($reqdate == $saved_reqdate) {
85     return DateTime->today_local->next_workday(extra_days => 1);
86   } else {
87     return $reqdate;
88   }
89 }
90
91 1;