1 package SL::DB::Shipto;
 
   7 use SL::DB::MetaSetup::Shipto;
 
   8 use SL::DB::Manager::Shipto;
 
   9 use SL::DB::Helper::CustomVariables (
 
  14 our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact
 
  15                            shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
 
  17 __PACKAGE__->meta->initialize;
 
  21   my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(shiptoname shiptostreet)),
 
  24                                                qw(shiptozipcode shiptocity))));
 
  32   return unless $self->shipto_id;
 
  34   require SL::DB::Order;
 
  35   require SL::DB::Invoice;
 
  36   require SL::DB::DeliveryOrder;
 
  38   return SL::DB::Manager::Order->get_all_count(query => [ shipto_id => $self->shipto_id ])
 
  39       || SL::DB::Manager::Invoice->get_all_count(query => [ shipto_id => $self->shipto_id ])
 
  40       || SL::DB::Manager::DeliveryOrder->get_all_count(query => [ shipto_id => $self->shipto_id ]);
 
  44   $_[0]->trans_id(undef);
 
  49   my ($self, $target) = @_;
 
  51   my $type   = ref($target) || $target;
 
  52   my $module = $type =~ m{::Order$}               ? 'OE'
 
  53              : $type =~ m{::DeliveryOrder$}       ? 'DO'
 
  54              : $type =~ m{::Invoice$}             ? 'AR'
 
  55              : $type =~ m{::(?:Customer|Vendor)$} ? 'CT'
 
  56              :                                      croak "Unsupported target class '$type'";
 
  58   my $new_shipto = SL::DB::Shipto->new(
 
  59     (map  { +($_ => $self->$_) }
 
  60      grep { !m{^ (?: itime | mtime | shipto_id | trans_id ) $}x }
 
  62      @{ $self->meta->columns }),
 
  64     custom_variables => [ map { $_->clone_and_reset } @{ $self->custom_variables } ],
 
  80 SL::DB::Shipto - Database model for shipping addresses
 
  84   my $order = SL::DB::Order->new(id => …)->load;
 
  85   if ($order->custom_shipto) {
 
  86     my $cloned_shipto = $order->custom_shipto->clone('SL::DB::Invoice');
 
  93 =item C<clone $target>
 
  95 Creates and returns a clone of the current object. The mandatory
 
  96 parameter C<$target> must be either an instance of a Rose DB class or
 
  97 the name of one. It's used for setting the new instance's C<module>
 
  98 attribute to the correct value.
 
 100 Currently the following classes are supported:
 
 104 =item C<SL::DB::Order>
 
 106 =item C<SL::DB::DeliveryOrder>
 
 108 =item C<SL::DB::Invoice>
 
 110 =item C<SL::DB::Customer>
 
 112 =item C<SL::DB::Vendor>
 
 124 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>