1 package SL::DB::Shipto;
6 use List::MoreUtils qw(all);
10 use SL::DB::MetaSetup::Shipto;
11 use SL::DB::Manager::Shipto;
12 use SL::DB::Helper::CustomVariables (
17 our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact
18 shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
20 __PACKAGE__->meta->initialize;
25 my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(shiptoname shiptostreet)),
28 qw(shiptozipcode shiptocity))));
36 return unless $self->shipto_id;
38 require SL::DB::Order;
39 require SL::DB::Invoice;
40 require SL::DB::DeliveryOrder;
42 return SL::DB::Manager::Order->get_all_count(query => [ shipto_id => $self->shipto_id ])
43 || SL::DB::Manager::Invoice->get_all_count(query => [ shipto_id => $self->shipto_id ])
44 || SL::DB::Manager::DeliveryOrder->get_all_count(query => [ shipto_id => $self->shipto_id ]);
50 # todo: consider cvars
51 my @fields_to_consider = grep { !m{^ (?: itime | mtime | shipto_id | trans_id | shiptocp_gender | module ) $}x } map {$_->name} $self->meta->columns;
53 return all { trim($self->$_) eq '' } @fields_to_consider;
57 $_[0]->trans_id(undef);
62 my ($self, $target) = @_;
64 my $type = ref($target) || $target;
65 my $module = $type =~ m{::Order$} ? 'OE'
66 : $type =~ m{::DeliveryOrder$} ? 'DO'
67 : $type =~ m{::Invoice$} ? 'AR'
68 : $type =~ m{::(?:Customer|Vendor)$} ? 'CT'
69 : croak "Unsupported target class '$type'";
71 my $new_shipto = SL::DB::Shipto->new(
72 (map { +($_ => $self->$_) }
73 grep { !m{^ (?: itime | mtime | shipto_id | trans_id ) $}x }
75 @{ $self->meta->columns }),
77 custom_variables => [ map { $_->clone_and_reset } @{ $self->custom_variables } ],
93 SL::DB::Shipto - Database model for shipping addresses
97 my $order = SL::DB::Order->new(id => …)->load;
98 if ($order->custom_shipto) {
99 my $cloned_shipto = $order->custom_shipto->clone('SL::DB::Invoice');
108 Returns truish if all fields to consider are empty, falsish if not.
109 Fields are trimmed before the test is performed.
110 C<shiptocp_gender> is not considered because in forms this is usually
111 a selection with 'm' as default value.
112 CVar fields are not considered by now.
118 =item C<clone $target>
120 Creates and returns a clone of the current object. The mandatory
121 parameter C<$target> must be either an instance of a Rose DB class or
122 the name of one. It's used for setting the new instance's C<module>
123 attribute to the correct value.
125 Currently the following classes are supported:
129 =item C<SL::DB::Order>
131 =item C<SL::DB::DeliveryOrder>
133 =item C<SL::DB::Invoice>
135 =item C<SL::DB::Customer>
137 =item C<SL::DB::Vendor>
149 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>