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