add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / part_pkg / currency_fixed.pm
1 package FS::part_pkg::currency_fixed;
2 #can't discount yet
3 #use base qw( FS::part_pkg::discount_Mixin FS::part_pkg::recur_Common );
4 use base qw( FS::part_pkg::recur_Common );
5
6 use strict;
7 use vars qw( %info );
8 use FS::Record qw(qsearchs); # qsearch qsearchs);
9 use FS::currency_exchange;
10
11 %info = (
12   'name' => 'Per-currency pricing from package definitions',
13   'shortname' => 'Per-currency pricing',
14   'inherit_fields' => [ 'prorate_Mixin', 'global_Mixin' ],
15   'fields' => {
16     'cutoff_day'    => { 'name' => 'Billing Day (1 - 28) for prorating or '.
17                                    'subscription',
18                          'default' => '1',
19                        },
20
21     'recur_method'  => { 'name' => 'Recurring fee method',
22                          #'type' => 'radio',
23                          #'options' => \%recur_method,
24                          'type' => 'select',
25                          'select_options' => \%FS::part_pkg::recur_Common::recur_method,
26                        },
27   },
28   'fieldorder' => [qw( recur_method cutoff_day ),
29                    FS::part_pkg::prorate_Mixin::fieldorder,
30                   ],
31   'weight' => '59',
32 );
33
34 sub price_info {
35     my $self = shift;
36     my $str = $self->SUPER::price_info(@_);
37     $str .= " (or local currency pricing)" if $str;
38     $str;
39 }
40
41 sub base_setup {
42   my($self, $cust_pkg, $sdate, $details, $param ) = @_;
43
44   $self->calc_currency_option('setup_fee', $cust_pkg, $sdate, $details, $param);
45 }
46
47 sub calc_setup {
48   my($self, $cust_pkg, $sdate, $details, $param) = @_;
49
50   return 0 if $self->prorate_setup($cust_pkg, $sdate);
51
52   $self->base_setup($cust_pkg, $sdate, $details, $param);
53 }
54
55 use FS::Conf;
56 sub calc_currency_option {
57   my($self, $optionname, $cust_or_quotation_pkg, $sdate, $details, $param) = @_;
58
59   my($currency, $amount) =
60     $cust_or_quotation_pkg->part_pkg_currency_option($optionname);
61   return sprintf('%.2f', $amount ) unless $currency;
62
63   $param->{'billed_currency'} = $currency;
64   $param->{'billed_amount'}   = $amount;
65
66   my $currency_exchange = qsearchs('currency_exchange', {
67     'from_currency' => $currency,
68     'to_currency'   => ( FS::Conf->new->config('currency') || 'USD' ),
69   }) or die "No exchange rate from $currency\n";
70
71   #XXX do we want the rounding here to work differently?
72   #my $recognized_amount =
73   sprintf('%.2f', $amount * $currency_exchange->rate);
74 }
75
76 sub base_recur {
77   my( $self, $cust_or_quotation_pkg, $sdate, $details, $param ) = @_;
78   $self->calc_currency_option(
79     'recur_fee', $cust_or_quotation_pkg, $sdate, $details, $param || {}
80   );
81 }
82
83 sub can_discount { 0; } #can't discount yet (percentage would work, but amount?)
84 sub calc_recur {
85   my $self = shift;
86
87   #my($cust_pkg, $sdate, $details, $param ) = @_;
88   my $cust_pkg = $_[0];
89
90   ($cust_pkg->quantity || 1) * $self->calc_recur_Common(@_); #($cust_pkg,$sdate,$details,$param);
91
92 }
93
94 sub is_free { 0; }
95
96 sub can_currency_exchange { 1; }
97
98 sub can_usageprice { 0; }
99
100 1;