freeside/FS/FS cust_pkg.pm,1.44,1.45
ivan
ivan at pouncequick.420.am
Mon Apr 5 04:55:38 PDT 2004
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv32088/FS/FS
Modified Files:
cust_pkg.pm
Log Message:
apply some heuristics to transfer ordering: primaries first, then sorted by quantity
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- cust_pkg.pm 4 Apr 2004 22:20:40 -0000 1.44
+++ cust_pkg.pm 5 Apr 2004 11:55:35 -0000 1.45
@@ -508,11 +508,21 @@
sub cust_svc {
my $self = shift;
- if ( $self->{'_svcnum'} ) {
- values %{ $self->{'_svcnum'}->cache };
- } else {
+ #if ( $self->{'_svcnum'} ) {
+ # values %{ $self->{'_svcnum'}->cache };
+ #} else {
+ map { $_->[0] }
+ sort { $b->[1] cmp $a->[1] or $a->[2] <=> $b->[2] }
+ map {
+ my $pkg_svc = qsearchs( 'pkg_svc', { 'pkgpart' => $self->pkgpart,
+ 'svcpart' => $_->svcpart } );
+ [ $_,
+ $pkg_svc ? $pkg_svc->primary_svc : '',
+ $pkg_svc ? $pkg_svc->quantity : 0,
+ ];
+ }
qsearch ( 'cust_svc', { 'pkgnum' => $self->pkgnum } );
- }
+ #}
}
=item labels
@@ -654,7 +664,6 @@
my $remaining = 0;
my $dest;
my %target;
- my $pkg_svc;
if (ref ($dest_pkgnum) eq 'FS::cust_pkg') {
$dest = $dest_pkgnum;
@@ -665,13 +674,11 @@
return ('Package does not exist: '.$dest_pkgnum) unless $dest;
- foreach $pkg_svc (qsearch('pkg_svc', { pkgpart => $dest->pkgpart })) {
+ foreach my $pkg_svc ( $dest->part_pkg->pkg_svc ) {
$target{$pkg_svc->svcpart} = $pkg_svc->quantity;
}
- my $cust_svc;
-
- foreach $cust_svc ($dest->cust_svc) {
+ foreach my $cust_svc ($dest->cust_svc) {
$target{$cust_svc->svcpart}--;
}
@@ -682,9 +689,20 @@
next if exists $svcpart2svcparts{$svcpart};
my $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } );
$svcpart2svcparts{$svcpart} = [
+ map { $_->[0] }
+ sort { $b->[1] cmp $a->[1] or $a->[2] <=> $b->[2] }
+ map {
+ my $pkg_svc = qsearchs( 'pkg_svc', { 'pkgpart' => $dest->pkgpart,
+ 'svcpart' => $_ } );
+ [ $_,
+ $pkg_svc ? $pkg_svc->primary_svc : '',
+ $pkg_svc ? $pkg_svc->quantity : 0,
+ ];
+ }
+
grep { $_ != $svcpart }
- map { $_->svcpart }
- qsearch('part_svc', { 'svcdb' => $part_svc->svcdb } )
+ map { $_->svcpart }
+ qsearch('part_svc', { 'svcdb' => $part_svc->svcdb } )
];
warn "alternates for svcpart $svcpart: ".
join(', ', @{$svcpart2svcparts{$svcpart}}). "\n"
@@ -692,7 +710,7 @@
}
}
- foreach $cust_svc ($self->cust_svc) {
+ foreach my $cust_svc ($self->cust_svc) {
if($target{$cust_svc->svcpart} > 0) {
$target{$cust_svc->svcpart}--;
my $new = new FS::cust_svc {
@@ -716,7 +734,7 @@
} @{$svcpart2svcparts{$cust_svc->svcpart}};
if ( @alternate ) {
warn "alternate(s) found\n" if $DEBUG;
- my $change_svcpart = $alternate[0]; #arbitrary.
+ my $change_svcpart = $alternate[0];
$target{$change_svcpart}--;
my $new = new FS::cust_svc {
svcnum => $cust_svc->svcnum,
More information about the freeside-commits
mailing list