summaryrefslogtreecommitdiff
path: root/FS/FS/location_Mixin.pm
blob: b010374a9e51264900c09f6ed7111a8a10be4381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package FS::location_Mixin;

use strict;
use FS::Record qw( qsearchs );
use FS::cust_location;

=item cust_location

Returns the location object, if any (see L<FS::cust_location>).

=cut

sub cust_location {
  my( $self, %opt ) = @_;

  return '' unless $self->locationnum;

  return $opt{_cache}->{$self->locationnum}
    if $opt{_cache} && $opt{_cache}->{$self->locationnum};

  my $cust_location = 
    qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );

  $opt{_cache}->{$self->locationnum} = $cust_location
     if $opt{_cache};
  
  $cust_location;
}

=item cust_location_or_main

If this package is associated with a location, returns the locaiton (see
L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).

=cut

sub cust_location_or_main {
  my $self = shift;
  $self->cust_location(@_) || $self->cust_main;
}

=item location_label [ OPTION => VALUE ... ]

Returns the label of the location object (see L<FS::cust_location>).

=cut

sub location_label {
  my $self = shift;
  my $object = $self->cust_location_or_main or return '';
  $object->location_label(@_);
}

=item location_hash

Returns a hash of values for the location, either from the location object,
the cust_main shipping address, or the cust_main address, whichever is present
first.

=cut

sub location_hash {
  my $self = shift;
  my $object = $self->cust_location_or_main;
  $object->location_hash(@_);
}

1;