e82602e1acfcb533533cdde3ab8c6fd2181faf23
[freeside.git] / FS / FS / part_pkg / global_Mixin.pm
1 package FS::part_pkg::global_Mixin;
2
3 use strict;
4 use vars qw(%info);
5
6 use Tie::IxHash;
7 tie my %a2billing_types, 'Tie::IxHash', (
8   0 => 'Prepaid',
9   1 => 'Postpaid',
10 );
11
12 tie my %a2billing_simultaccess, 'Tie::IxHash', (
13   0 => 'Disabled',
14   1 => 'Enabled',
15 );
16
17 # much false laziness with FS::Record::ut_money
18 sub validate_moneyn {
19   my ($option, $valref) = @_;
20   if ( $$valref eq '' ) {
21     return '';
22   } elsif ( $$valref =~ /^\s*(\d*)(\.\d{1})\s*$/ ) {
23     #handle one decimal place without barfing out
24     $$valref = ( ($1||''). ($2.'0') ) || 0;
25   } elsif ( $$valref =~ /^\s*(\d*)(\.\d{2})?\s*$/ ) {
26     $$valref = ( ($1||''). ($2||'') ) || 0;
27   } else {
28     return "Illegal (money) $option: ". $$valref;
29   }
30   return '';
31 }
32
33
34 %info = (
35   'disabled' => 1,
36   'fields' => {
37     'setup_fee' => { 
38       'name' => 'Setup fee for this package',
39       'default' => 0,
40       'validate' => \&validate_moneyn,
41     },
42     'recur_fee' => { 
43       'name' => 'Recurring fee for this package',
44       'default' => 0,
45       'validate' => \&validate_moneyn,
46     },
47     'unused_credit_cancel' => {
48       'name' => 'Credit the customer for the unused portion of service at '.
49                  'cancellation',
50       'type' => 'checkbox',
51     },
52     'unused_credit_suspend' => {
53       'name' => 'Credit the customer for the unused portion of service when '.
54                 'suspending',
55       'type' => 'checkbox',
56     },
57     'unused_credit_change' => {
58       'name' => 'Credit the customer for the unused portion of service when '.
59                 'changing packages',
60       'type' => 'checkbox',
61     },
62     'delay_cancel' => {
63       'name' => 'Automatic suspension period before cancelling (configuration setting part_pkg-delay_cancel-days)',
64       'type' => 'checkbox',
65     },
66
67     # miscellany--maybe put this in a separate module?
68
69     'a2billing_tariff' => {
70       'name'        => 'A2Billing tariff group ID',
71       'display_if'  => sub {
72         FS::part_export->count("exporttype = 'a2billing'") > 0;
73       }
74     },
75     'a2billing_type' => {
76       'name'        => 'A2Billing card type',
77       'display_if'  => sub {
78         FS::part_export->count("exporttype = 'a2billing'") > 0;
79       },
80       'type'        => 'select',
81       'select_options' => \%a2billing_types,
82     },
83     'a2billing_simultaccess' => {
84       'name'        => 'A2Billing Simultaneous Access',
85       'display_if'  => sub {
86         FS::part_export->count("exporttype = 'a2billing'") > 0;
87       },
88       'type'        => 'select',
89       'select_options' => \%a2billing_simultaccess,
90     },  
91     'a2billing_carrier_cost_min' => {
92       'name'        => 'A2Billing inbound carrier cost',
93       'display_if'  => sub {
94         FS::part_export->count("exporttype = 'a2billing'") > 0;
95       },
96     },
97    'a2billing_carrer_initblock_offp' => {
98       'name'        => 'A2Billing inbound carrier min duration',
99       'display_if'  => sub {
100         FS::part_export->count("exporttype = 'a2billing'") > 0;
101       },
102     },
103     'a2billing_carrier_increment_offp' => {
104       'name'        => 'A2Billing inbound carrier billing block',
105       'display_if'  => sub {
106         FS::part_export->count("exporttype = 'a2billing'") > 0;
107       },
108     },
109     'a2billing_retail_cost_min_offp' => {
110       'name'        => 'A2Billing inbound retail cost',
111       'display_if'  => sub {
112         FS::part_export->count("exporttype = 'a2billing'") > 0;
113       },
114     },
115     'a2billing_retail_initblock_offp' => {
116       'name'        => 'A2Billing inbound retail min duration',
117       'display_if'  => sub {
118         FS::part_export->count("exporttype = 'a2billing'") > 0;
119       },
120     },
121     'a2billing_retail_increment_offp' => {
122       'name'        => 'A2Billing inbound retail billing block',
123       'display_if'  => sub {
124         FS::part_export->count("exporttype = 'a2billing'") > 0;
125      },
126    },
127
128  },
129   'fieldorder' => [ qw(
130     setup_fee
131     recur_fee
132     unused_credit_cancel
133     unused_credit_suspend
134     unused_credit_change
135     delay_cancel
136
137     a2billing_tariff
138     a2billing_type
139     a2billing_simultaccess
140     a2billing_carrier_cost_min
141     a2billing_carrer_initblock_offp
142     a2billing_carrier_increment_offp
143     a2billing_retail_cost_min_offp
144     a2billing_retail_initblock_offp
145     a2billing_retail_increment_offp
146   )],
147 );
148
149 1;