1 package FS::part_pkg::bulk_Common;
2 use base qw( FS::part_pkg::flat );
5 use vars qw($DEBUG $me %info);
8 use FS::Record qw(qsearchs);
11 $me = '[FS::part_pkg::bulk_Common]';
15 'inherit_fields' => [ 'global_Mixin' ],
17 'svc_setup_fee' => { 'name' => 'Setup fee for each new service',
20 'svc_recur_fee' => { 'name' => 'Recurring fee for each service',
23 'summarize_svcs'=> { 'name' => 'Show a count of services on the invoice, '.
24 'instead of a detailed list',
28 'name' => 'Only charge fees for these services',
29 'type' => 'select_multiple',
30 'select_table' => 'part_svc',
31 'select_key' => 'svcpart',
32 'select_label' => 'svc',
34 'parse' => sub { @_ }, #should this be the default in /edit/process/part_pkg.cgi?
37 'fieldorder' => [ 'svc_setup_fee', 'svc_recur_fee', 'only_svcs',
38 'summarize_svcs', 'no_prorate' ],
44 my $str = $self->SUPER::price_info(@_);
45 my $svc_setup_fee = $self->option('svc_setup_fee');
46 my $svc_recur_fee = $self->option('svc_recur_fee');
47 my $conf = new FS::Conf;
48 my $money_char = $conf->config('money_char') || '$';
49 $str .= ", bulk " if $str;
50 $str .= ": $money_char" . $svc_setup_fee . " one-time per service"
52 $str .= ", " if ($svc_setup_fee && $svc_recur_fee);
53 $str .= $money_char . $svc_recur_fee . " recurring per service"
58 #some false laziness-ish w/agent.pm... not a lot
60 my($self, $cust_pkg, $sdate, $details, $param ) = @_;
62 my $conf = new FS::Conf;
63 my $money_char = $conf->config('money_char') || '$';
65 my $last_bill = $cust_pkg->last_bill;
67 my $total_svc_charge = 0;
70 my %part_svc_label = ();
73 my $summarize = $self->option('summarize_svcs',1);
75 foreach my $cust_svc ( $self->_bulk_cust_svc( $cust_pkg, $sdate ) ) {
77 my $pkg_svc = $pkg_svc{ $cust_pkg->pkgpart. '_'. $cust_svc->svcpart }
78 ||= qsearchs('pkg_svc', { 'pkgpart' => $cust_pkg->pkgpart,
79 'svcpart' => $cust_svc->svcpart});
80 next if $pkg_svc->bulk_skip;
82 my @label = $cust_svc->label_long( $$sdate, $last_bill );
83 die "fatal: no label found for svcnum ". $cust_svc->svcnum
84 unless scalar(@label); #?
85 my $svc_details = $label[0]. ': '. $label[1]. ': ';
86 $part_svc_label{$cust_svc->svcpart} ||= $label[0];
90 my $setup = $self->_bulk_setup($cust_pkg, $cust_svc);
92 $svc_charge += $setup;
93 $svc_details .= $money_char. sprintf('%.2f setup, ', $setup);
94 $n_setup{$cust_svc->svcpart}++;
97 my( $recur, $r_details ) = $self->_bulk_recur($cust_pkg, $cust_svc, $sdate);
99 $svc_charge += $recur;
100 $svc_details .= $money_char. sprintf('%.2f', $recur). $r_details;
101 $n_recur{$cust_svc->svcpart}++;
102 push @$details, $svc_details if !$summarize;
105 $total_svc_charge += $svc_charge;
110 foreach my $svcpart (keys %part_svc_label) {
111 push @$details, sprintf('Setup fee: %d @ '.$money_char.'%.2f',
112 $n_setup{$svcpart}, $self->option('svc_setup_fee') )
113 if $self->option('svc_setup_fee') and $n_setup{$svcpart};
114 push @$details, sprintf('%d services @ '.$money_char.'%.2f',
115 $n_recur{$svcpart}, $self->option('svc_recur_fee') )
116 if $n_recur{$svcpart};
120 my $charge = $self->base_recur($cust_pkg, $sdate) + $total_svc_charge;
122 $param->{'override_charges'} = $total_svc_charge / $self->freq;
123 my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
125 sprintf('%.2f', $charge - $discount );
128 sub hide_svc_detail { 1; }
130 sub is_free_options {
131 qw( setup_fee recur_fee svc_setup_fee svc_recur_fee );
134 sub can_usageprice { 0; }
136 sub _only_svcs_filter {
137 my ($self, @cust_svc) = @_;
138 my @only_svcs = split(', ',$self->option('only_svcs',1));
141 my $svcpart = $_->svcpart;
142 grep(/^$svcpart$/,@only_svcs);