add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / sched_avail.pm
1 package FS::sched_avail;
2 use base qw( FS::Record );
3
4 use strict;
5 #use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::sched_avail - Object methods for sched_avail records
10
11 =head1 SYNOPSIS
12
13   use FS::sched_avail;
14
15   $record = new FS::sched_avail \%hash;
16   $record = new FS::sched_avail { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::sched_avail object represents an availability period/interval.
29 FS::sched_avail inherits from FS::Record.  The following fields are currently
30 supported:
31
32 =over 4
33
34 =item availnum
35
36 primary key
37
38 =item itemnum
39
40 itemnum
41
42 =item wday
43
44 wday
45
46 =item stime
47
48 stime
49
50 =item etime
51
52 etime
53
54 =item override_date
55
56 override_date
57
58
59 =back
60
61 =head1 METHODS
62
63 =over 4
64
65 =item new HASHREF
66
67 Creates a new period.  To add the period to the database, see L<"insert">.
68
69 Note that this stores the hash reference, not a distinct copy of the hash it
70 points to.  You can ask the object for a copy with the I<hash> method.
71
72 =cut
73
74 sub table { 'sched_avail'; }
75
76 =item insert
77
78 Adds this record to the database.  If there is an error, returns the error,
79 otherwise returns false.
80
81 =item delete
82
83 Delete this record from the database.
84
85 =item replace OLD_RECORD
86
87 Replaces the OLD_RECORD with this one in the database.  If there is an error,
88 returns the error, otherwise returns false.
89
90 =item check
91
92 Checks all fields to make sure this is a valid period.  If there is
93 an error, returns the error, otherwise returns false.  Called by the insert
94 and replace methods.
95
96 =cut
97
98 sub check {
99   my $self = shift;
100
101   my $error = 
102     $self->ut_numbern('availnum')
103     || $self->ut_foreign_key('itemnum', 'sched_item', 'itemnum')
104     || $self->ut_number('wday')
105     || $self->ut_number('stime')
106     || $self->ut_number('etime')
107     || $self->ut_numbern('override_date')
108   ;
109   return $error if $error;
110
111   $self->SUPER::check;
112 }
113
114 =item stime_pretty
115
116 =item etime_pretty
117
118 =cut
119
120 sub stime_pretty { shift->_time_pretty('stime', @_); }
121 sub etime_pretty { shift->_time_pretty('etime', @_); }
122
123 sub _time_pretty {
124   my( $self, $field ) = @_;
125
126   pretty_time( $self->$field() );
127 }
128
129 #helper sub
130 sub pretty_time {
131   my $t = shift;
132
133   return 'Midnight' if $t == 0 || $t == 1440;
134   return 'Noon'     if $t == 720;
135
136   my $h = int( $t / 60 );
137   my $m = $t % 60;
138
139   my $ap = 'AM';
140   if    ( $h == 0 || $h == 24 ) { $h = 12; }
141   elsif ( $h == 12 )           { $ap = 'PM'; }
142   elsif ( $h > 12 )            { $ap = 'PM'; $h -= 12; }
143
144   sprintf('%02d:%02d'." $ap", $h, $m);
145
146 }
147
148 =back
149
150 =head1 BUGS
151
152 =head1 SEE ALSO
153
154 L<FS::sched_item>, L<FS::Record>
155
156 =cut
157
158 1;
159