Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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 tie my %count_available_phones, 'Tie::IxHash', (
34   0 => 'Provisioned phone services',
35   1 => 'All available phone services',
36 );
37
38 %info = (
39   'disabled' => 1,
40   'fields' => {
41     'setup_fee' => { 
42       'name' => 'Setup fee for this package',
43       'default' => 0,
44       'validate' => \&validate_moneyn,
45     },
46     'recur_fee' => { 
47       'name' => 'Recurring fee for this package',
48       'default' => 0,
49       'validate' => \&validate_moneyn,
50     },
51     'unused_credit_cancel' => {
52       'name' => 'Credit the customer for the unused portion of service at '.
53                  'cancellation',
54       'type' => 'checkbox',
55     },
56     'unused_credit_suspend' => {
57       'name' => 'Credit the customer for the unused portion of service when '.
58                 'suspending',
59       'type' => 'checkbox',
60     },
61     'unused_credit_change' => {
62       'name' => 'Credit the customer for the unused portion of service when '.
63                 'changing packages',
64       'type' => 'checkbox',
65     },
66     'delay_cancel' => {
67       'name' => 'Automatic suspension period before cancelling (configuration setting part_pkg-delay_cancel-days)',
68       'type' => 'checkbox',
69     },
70     'count_available_phones' => { 'name' => 'Count taxable phone lines',
71       'type' => 'radio',
72       'options' => \%count_available_phones,
73       'default' => 0,
74     },
75
76     # miscellany--maybe put this in a separate module?
77
78     'a2billing_tariff' => {
79       'name'        => 'A2Billing tariff group ID',
80       'display_if'  => sub {
81         FS::part_export->count("exporttype = 'a2billing'") > 0;
82       }
83     },
84     'a2billing_type' => {
85       'name'        => 'A2Billing card type',
86       'display_if'  => sub {
87         FS::part_export->count("exporttype = 'a2billing'") > 0;
88       },
89       'type'        => 'select',
90       'select_options' => \%a2billing_types,
91     },
92     'a2billing_simultaccess' => {
93       'name'        => 'A2Billing Simultaneous Access',
94       'display_if'  => sub {
95         FS::part_export->count("exporttype = 'a2billing'") > 0;
96       },
97       'type'        => 'select',
98       'select_options' => \%a2billing_simultaccess,
99     },  
100     'a2billing_carrier_cost_min' => {
101       'name'        => 'A2Billing inbound carrier cost',
102       'display_if'  => sub {
103         FS::part_export->count("exporttype = 'a2billing'") > 0;
104       },
105     },
106    'a2billing_carrer_initblock_offp' => {
107       'name'        => 'A2Billing inbound carrier min duration',
108       'display_if'  => sub {
109         FS::part_export->count("exporttype = 'a2billing'") > 0;
110       },
111     },
112     'a2billing_carrier_increment_offp' => {
113       'name'        => 'A2Billing inbound carrier billing block',
114       'display_if'  => sub {
115         FS::part_export->count("exporttype = 'a2billing'") > 0;
116       },
117     },
118     'a2billing_retail_cost_min_offp' => {
119       'name'        => 'A2Billing inbound retail cost',
120       'display_if'  => sub {
121         FS::part_export->count("exporttype = 'a2billing'") > 0;
122       },
123     },
124     'a2billing_retail_initblock_offp' => {
125       'name'        => 'A2Billing inbound retail min duration',
126       'display_if'  => sub {
127         FS::part_export->count("exporttype = 'a2billing'") > 0;
128       },
129     },
130     'a2billing_retail_increment_offp' => {
131       'name'        => 'A2Billing inbound retail billing block',
132       'display_if'  => sub {
133         FS::part_export->count("exporttype = 'a2billing'") > 0;
134      },
135    },
136
137  },
138   'fieldorder' => [ qw(
139     setup_fee
140     recur_fee
141     unused_credit_cancel
142     unused_credit_suspend
143     unused_credit_change
144     delay_cancel
145
146     count_available_phones
147
148     a2billing_tariff
149     a2billing_type
150     a2billing_simultaccess
151     a2billing_carrier_cost_min
152     a2billing_carrer_initblock_offp
153     a2billing_carrier_increment_offp
154     a2billing_retail_cost_min_offp
155     a2billing_retail_initblock_offp
156     a2billing_retail_increment_offp
157   )],
158 );
159
160 1;