per-agent disable_previous_balance, #15863
[freeside.git] / FS / FS / svc_Parent_Mixin.pm
1 package FS::svc_Parent_Mixin;
2
3 use strict;
4 use NEXT;
5 use FS::Record qw(qsearch qsearchs);
6 use FS::cust_svc;
7
8 =head1 NAME
9
10 FS::svc_Parent_Mixin - Mixin class for svc_ classes with a parent_svcnum field
11
12 =head1 SYNOPSIS
13
14 package FS::svc_table;
15 use vars qw(@ISA);
16 @ISA = qw( FS::svc_Parent_Mixin FS::svc_Common );
17
18 =head1 DESCRIPTION
19
20 This is a mixin class for svc_ classes that contain a parent_svcnum field.
21
22 =cut
23
24 =head1 METHODS
25
26 =over 4
27
28 =item parent_cust_svc
29
30 Returns the parent FS::cust_svc object.
31
32 =cut
33
34 sub parent_cust_svc {
35   my $self = shift;
36   qsearchs('cust_svc', { 'svcnum' => $self->parent_svcnum } );
37 }
38
39 =item parent_svc_x
40
41 Returns the corresponding parent FS::svc_ object.
42
43 =cut
44
45 sub parent_svc_x {
46   my $self = shift;
47   $self->parent_cust_svc->svc_x;
48 }
49
50 =item children_cust_svc
51
52 Returns a list of any child FS::cust_svc objects.
53
54 Note: This is not recursive; it only returns direct children.
55
56 =cut
57
58 sub children_cust_svc { 
59   my $self = shift;
60   qsearch('cust_svc', { 'parent_svcnum' => $self->svcnum } );
61 }
62
63 =item children_svc_x
64
65 Returns the corresponding list of child FS::svc_ objects.
66
67 =cut
68
69 sub children_svc_x {
70   my $self = shift;
71   map { $_->svc_x } $self->children_cust_svc;
72 }
73
74 =item check
75
76 This class provides a check subroutine which takes care of checking the
77 parent_svcnum field.  The svc_ class which uses it will call SUPER::check at
78 the end of its own checks, and this class will call NEXT::check to pass 
79 the check "up the chain" (see L<NEXT>).
80
81 =cut
82
83 sub check {
84   my $self = shift;
85
86   $self->ut_foreign_keyn('parent_svcnum', 'cust_svc', 'svcnum')
87     || $self->NEXT::check;
88
89 }
90
91 =back
92
93 =head1 BUGS
94
95 Do we need a recursive child finder for multi-layered children?
96
97 =head1 SEE ALSO
98
99 L<FS::svc_Common>, L<FS::Record>
100
101 =cut
102
103 1;