1 package FS::part_pkg::bulk_Common;
2 use base qw( FS::part_pkg::flat );
5 use vars qw($DEBUG $me %info);
10 $me = '[FS::part_pkg::bulk_Common]';
14 'inherit_fields' => [ 'global_Mixin' ],
16 'svc_setup_fee' => { 'name' => 'Setup fee for each new service',
19 'svc_recur_fee' => { 'name' => 'Recurring fee for each service',
22 'summarize_svcs'=> { 'name' => 'Show a count of services on the invoice, '.
23 'instead of a detailed list',
27 'fieldorder' => [ 'svc_setup_fee', 'svc_recur_fee',
28 'summarize_svcs', 'no_prorate' ],
34 my $str = $self->SUPER::price_info;
35 my $svc_setup_fee = $self->option('svc_setup_fee');
36 my $svc_recur_fee = $self->option('svc_recur_fee');
37 my $conf = new FS::Conf;
38 my $money_char = $conf->config('money_char') || '$';
39 $str .= ", bulk " if $str;
40 $str .= ": $money_char" . $svc_setup_fee . " one-time per service"
42 $str .= ", " if ($svc_setup_fee && $svc_recur_fee);
43 $str .= $money_char . $svc_recur_fee . " recurring per service"
48 #some false laziness-ish w/agent.pm... not a lot
50 my($self, $cust_pkg, $sdate, $details, $param ) = @_;
52 my $conf = new FS::Conf;
53 my $money_char = $conf->config('money_char') || '$';
55 my $last_bill = $cust_pkg->last_bill;
57 my $total_svc_charge = 0;
60 my %part_svc_label = ();
62 my $summarize = $self->option('summarize_svcs',1);
64 foreach my $cust_svc ( $self->_bulk_cust_svc( $cust_pkg, $sdate ) ) {
66 my @label = $cust_svc->label_long( $$sdate, $last_bill );
67 die "fatal: no label found for svcnum ". $cust_svc->svcnum
68 unless scalar(@label); #?
69 my $svc_details = $label[0]. ': '. $label[1]. ': ';
70 $part_svc_label{$cust_svc->svcpart} ||= $label[0];
74 my $setup = $self->_bulk_setup($cust_pkg, $cust_svc);
76 $svc_charge += $setup;
77 $svc_details .= $money_char. sprintf('%.2f setup, ', $setup);
78 $n_setup{$cust_svc->svcpart}++;
81 my( $recur, $r_details ) = $self->_bulk_recur($cust_pkg, $cust_svc, $sdate);
83 $svc_charge += $recur;
84 $svc_details .= $money_char. sprintf('%.2f', $recur). $r_details;
85 $n_recur{$cust_svc->svcpart}++;
86 push @$details, $svc_details if !$summarize;
89 $total_svc_charge += $svc_charge;
94 foreach my $svcpart (keys %part_svc_label) {
95 push @$details, sprintf('Setup fee: %d @ '.$money_char.'%.2f',
96 $n_setup{$svcpart}, $self->option('svc_setup_fee') )
97 if $self->option('svc_setup_fee') and $n_setup{$svcpart};
98 push @$details, sprintf('%d services @ '.$money_char.'%.2f',
99 $n_recur{$svcpart}, $self->option('svc_recur_fee') )
100 if $n_recur{$svcpart};
104 my $charge = $self->base_recur($cust_pkg, $sdate) + $total_svc_charge;
106 $param->{'override_charges'} = $total_svc_charge / $self->freq;
107 my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param);
109 sprintf('%.2f', $charge - $discount );
112 sub hide_svc_detail { 1; }
114 sub is_free_options {
115 qw( setup_fee recur_fee svc_setup_fee svc_recur_fee );