X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=site_perl%2Fcust_pkg.pm;h=31b4524f201791200d200b7af0d77a8c9f58d370;hp=5b119ed28085695988e3cee808e2b220c0ade513;hb=de46aa575f3e726a9b005172706cff5e542955fd;hpb=a99792ee88e249c27c661a4ece2b4fa241f59e76 diff --git a/site_perl/cust_pkg.pm b/site_perl/cust_pkg.pm index 5b119ed28..31b4524f2 100644 --- a/site_perl/cust_pkg.pm +++ b/site_perl/cust_pkg.pm @@ -44,6 +44,8 @@ FS::cust_pkg - Object methods for cust_pkg objects $part_pkg = $record->part_pkg; + @labels = $record->labels; + $error = FS::cust_pkg::order( $custnum, \@pkgparts ); $error = FS::cust_pkg::order( $custnum, \@pkgparts, \@remove_pkgnums ] ); @@ -95,6 +97,22 @@ sub table { 'cust_pkg'; } Adds this billing item to the database ("Orders" the item). If there is an error, returns the error, otherwise returns false. +sub insert { + my $self = shift; + + # custnum might not have have been defined in sub check (for one-shot new + # customers), so check it here instead + + my $error = $self->ut_number('custnum'); + return $error if $error + + return "Unknown customer" + unless qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); + + $self->SUPER::insert; + +} + =item delete Currently unimplemented. You don't want to delete billing items, because there @@ -152,7 +170,7 @@ sub check { my $error = $self->ut_numbern('pkgnum') - || $self->ut_number('custnum') + || $self->ut_numbern('custnum') || $self->ut_number('pkgpart') || $self->ut_numbern('setup') || $self->ut_numbern('bill') @@ -161,8 +179,10 @@ sub check { ; return $error if $error; - return "Unknown customer" - unless qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); + if ( $self->custnum ) { + return "Unknown customer" + unless qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); + } return "Unknown pkgpart" unless qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } ); @@ -193,6 +213,7 @@ sub cancel { local $SIG{QUIT} = 'IGNORE'; local $SIG{TERM} = 'IGNORE'; local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; foreach my $cust_svc ( qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } ) @@ -219,7 +240,7 @@ sub cancel { unless ( $self->getfield('cancel') ) { my %hash = $self->hash; - $hash{'cancel'} = $^T; + $hash{'cancel'} = time; my $new = new FS::cust_pkg ( \%hash ); $error = $new->replace($self); return $error if $error; @@ -246,6 +267,7 @@ sub suspend { local $SIG{QUIT} = 'IGNORE'; local $SIG{TERM} = 'IGNORE'; local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; foreach my $cust_svc ( qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } ) @@ -267,7 +289,7 @@ sub suspend { unless ( $self->getfield('susp') ) { my %hash = $self->hash; - $hash{'susp'} = $^T; + $hash{'susp'} = time; my $new = new FS::cust_pkg ( \%hash ); $error = $new->replace($self); return $error if $error; @@ -294,6 +316,7 @@ sub unsuspend { local $SIG{QUIT} = 'IGNORE'; local $SIG{TERM} = 'IGNORE'; local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; foreach my $cust_svc ( qsearch('cust_svc',{'pkgnum'=> $self->pkgnum } ) @@ -336,6 +359,18 @@ sub part_pkg { qsearchs( 'part_pkg', { 'pkgpart' => $self->pkgpart } ); } +=item labels + +Returns a list of lists, calling the label method for all services +(see L) of this billing item. + +=cut + +sub labels { + my $self = shift; + map { [ $_->label ] } qsearch ( 'cust_svc', { 'pkgnum' => $self->pkgnum } ); +} + =back =head1 SUBROUTINES @@ -417,38 +452,39 @@ sub order { local $SIG{QUIT} = 'IGNORE'; local $SIG{TERM} = 'IGNORE'; local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; #first cancel old packages # my($pkgnum); foreach $pkgnum ( @{$remove_pkgnums} ) { my($old) = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum}); - return "Package $pkgnum not found to remove!" unless $old; + die "Package $pkgnum not found to remove!" unless $old; my(%hash) = $old->hash; - $hash{'cancel'}=$^T; - my($new) = create FS::cust_pkg ( \%hash ); + $hash{'cancel'}=time; + my($new) = new FS::cust_pkg ( \%hash ); my($error)=$new->replace($old); - return $error if $error; + die "Couldn't update package $pkgnum: $error" if $error; } #now add new packages, changing cust_svc records if necessary # my($pkgpart); while ($pkgpart=shift @{$pkgparts} ) { - my($new) = create FS::cust_pkg ( { + my($new) = new FS::cust_pkg ( { 'custnum' => $custnum, 'pkgpart' => $pkgpart, } ); my($error) = $new->insert; - return $error if $error; + die "Couldn't insert new cust_pkg record: $error" if $error; my($pkgnum)=$new->getfield('pkgnum'); my($cust_svc); foreach $cust_svc ( @{ shift @cust_svc } ) { my(%hash) = $cust_svc->hash; $hash{'pkgnum'}=$pkgnum; - my($new) = create FS::cust_svc ( \%hash ); + my($new) = new FS::cust_svc ( \%hash ); my($error)=$new->replace($cust_svc); - return $error if $error; + die "Couldn't link old service to new package: $error" if $error; } } @@ -459,7 +495,7 @@ sub order { =head1 VERSION -$Id: cust_pkg.pm,v 1.5 1999-01-18 21:58:07 ivan Exp $ +$Id: cust_pkg.pm,v 1.8 1999-03-25 13:48:14 ivan Exp $ =head1 BUGS @@ -490,7 +526,18 @@ fixed for new agent->agent_type->type_pkgs in &order ivan@sisd.com 98-mar-7 pod ivan@sisd.com 98-sep-21 $Log: cust_pkg.pm,v $ -Revision 1.5 1999-01-18 21:58:07 ivan +Revision 1.8 1999-03-25 13:48:14 ivan +allow empty custnum in sub check (but call that an error in sub insert), +for one-screen new customer entry + +Revision 1.7 1999/02/09 09:55:06 ivan +invoices show line items for each service in a package (see the label method +of FS::cust_svc) + +Revision 1.6 1999/01/25 12:26:12 ivan +yet more mod_perl stuff + +Revision 1.5 1999/01/18 21:58:07 ivan esthetic: eq and ne were used in a few places instead of == and != Revision 1.4 1998/12/29 11:59:45 ivan