enable CardFortress in test database, #71513
[freeside.git] / FS / FS / location_Mixin.pm
1 package FS::location_Mixin;
2
3 use strict;
4 use FS::Record qw( qsearchs );
5 use FS::cust_location;
6
7 =item cust_location
8
9 Returns the location object, if any (see L<FS::cust_location>).
10
11 =cut
12
13 sub cust_location {
14   my( $self, %opt ) = @_;
15
16   return '' unless $self->locationnum;
17
18   return $opt{_cache}->{$self->locationnum}
19     if $opt{_cache} && $opt{_cache}->{$self->locationnum};
20
21   my $cust_location = 
22     qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
23
24   $opt{_cache}->{$self->locationnum} = $cust_location
25      if $opt{_cache};
26   
27   $cust_location;
28 }
29
30 =item cust_location_or_main
31
32 If this package is associated with a location, returns the locaiton (see
33 L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
34
35 =cut
36
37 sub cust_location_or_main {
38   my $self = shift;
39   $self->cust_location(@_) || $self->cust_main;
40 }
41
42 =item location_label [ OPTION => VALUE ... ]
43
44 Returns the label of the location object (see L<FS::cust_location>).
45
46 =cut
47
48 sub location_label {
49   my $self = shift;
50   my $object = $self->cust_location_or_main or return '';
51   $object->location_label(@_);
52 }
53
54 =item location_hash
55
56 Returns a hash of values for the location, either from the location object,
57 the cust_main shipping address, or the cust_main address, whichever is present
58 first.
59
60 =cut
61
62 sub location_hash {
63   my $self = shift;
64   my $object = $self->cust_location_or_main;
65   $object->location_hash(@_);
66 }
67
68 1;