From e497261817ee2cf3acb5ee3dda3c5906f1c13a4f Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sat, 8 Jun 2013 05:14:19 -0700 Subject: [PATCH] multi-currency, RT#21565 --- FS/FS/Schema.pm | 1 + FS/FS/cust_main.pm | 1 + FS/FS/cust_pkg.pm | 18 +++++++++++ FS/FS/part_pkg.pm | 24 ++++++++++++++ FS/FS/part_pkg/currency_fixed.pm | 67 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 FS/FS/part_pkg/currency_fixed.pm diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 048718641..f1cc09c02 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1081,6 +1081,7 @@ sub tables_hashref { 'ship_night', 'varchar', 'NULL', 20, '', '', 'ship_fax', 'varchar', 'NULL', 12, '', '', 'ship_mobile', 'varchar', 'NULL', 12, '', '', + 'currency', 'char', 'NULL', 3, '', '', 'payby', 'char', '', 4, '', '', 'payinfo', 'varchar', 'NULL', 512, '', '', 'paycvv', 'varchar', 'NULL', 512, '', '', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index f4c3beb87..3fbee1594 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1757,6 +1757,7 @@ sub check { || $self->ut_flag('invoice_noemail') || $self->ut_flag('message_noemail') || $self->ut_enum('locale', [ '', FS::Locales->locales ]) + || $self->ut_currency('currency') ; my $company = $self->company; diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 65bfc80ae..835738604 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -2343,6 +2343,24 @@ sub num_cust_event { $sth->fetchrow_arrayref->[0]; } +=item part_pkg_currency_option OPTIONNAME + +Returns the option value for the given name and the currency of this customer +(see L). If this customer has no currency, returns +the regular option value for the given name (see L). + +=cut + +sub part_pkg_currency_option { + my( $self, $optionname ) = @_; + my $part_pkg = $self->part_pkg; + if ( my $currency = $self->cust_main->currency ) { + $part_pkg->part_pkg_currency_option($currency, $optionname); + } else { + $part_pkg->option($optionname); + } +} + =item cust_svc [ SVCPART ] (old, deprecated usage) =item cust_svc [ OPTION => VALUE ... ] (current usage) diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 67372ac64..22e8828d6 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -1076,6 +1076,8 @@ sub can_discount { 0; } sub can_start_date { 1; } +sub can_currency_exchange { 0; } + sub freqs_href { # moved to FS::Misc to make this accessible to other packages # at initialization @@ -1270,6 +1272,28 @@ sub part_pkg_currency_options { map { $_->optionname => $_->optionvalue } $self->part_pkg_currency(shift); } +=item part_pkg_currency_option CURRENCY OPTIONNAME + +Returns the option value for the given name and currency. + +=cut + +sub part_pkg_currency_option { + my( $self, $currency, $optionname ) = @_; + my $part_pkg_currency = + qsearchs('part_pkg_currency', { 'pkgpart' => $self->pkgpart, + 'currency' => $currency, + 'optionname' => $optionname, + } + )#; + #fatal if not found? that works for our use cases from + #part_pkg/currency_fixed, but isn't how we would typically/expect the method + #to behave. have to catch it there if we change it here... + or die "Unknown price for ". $self->pkg_comment. " in $currency\n"; + + $part_pkg_currency->optionvalue; +} + =item bill_part_pkg_link Returns the associated part_pkg_link records (see L). diff --git a/FS/FS/part_pkg/currency_fixed.pm b/FS/FS/part_pkg/currency_fixed.pm new file mode 100644 index 000000000..bee6c5b4e --- /dev/null +++ b/FS/FS/part_pkg/currency_fixed.pm @@ -0,0 +1,67 @@ +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(qsearch qsearchs); + +%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; +} + +#some false laziness w/recur_Common, could have been better about it.. pry when +# we do discounting +sub calc_setup { + my($self, $cust_pkg, $sdate, $details, $param) = @_; + + return 0 if $self->prorate_setup($cust_pkg, $sdate); + + sprintf('%.2f', $cust_pkg->part_pkg_currency_option('setup_fee') ); +} + +sub base_recur { + my( $self, $cust_pkg ) = @_; + sprintf('%.2f', $cust_pkg->part_pkg_currency_option('recur_fee') ); +} + +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 ) = @_; + #$self->calc_recur_Common($cust_pkg,$sdate,$details,$param); + $self->calc_recur_Common(@_); +} + +sub is_free { 0; } + +sub can_currency_exchange { 1; } + +1; -- 2.11.0