4 use vars qw( @ISA @EXPORT_OK );
12 $FS::svc_domain::whois_hack = 1;
13 $FS::svc_domain::whois_hack = 1;
15 @ISA = qw( Exporter );
16 @EXPORT_OK = qw( create_initial_data );
20 FS::Setup - Database setup
28 Currently this module simply provides a place to store common subroutines for
39 sub create_initial_data {
42 my $oldAutoCommit = $FS::UID::AutoCommit;
43 local $FS::UID::AutoCommit = 0;
44 $FS::UID::AutoCommit = 0;
49 populate_initial_data(%opt);
55 if ( $oldAutoCommit ) {
56 dbh->commit or die dbh->errstr;
61 sub populate_locales {
64 use FS::cust_main_county;
67 foreach my $country ( sort map uc($_), all_country_codes ) {
68 _add_country($country);
73 sub populate_addl_locales {
77 'FM' => 'Federated States of Micronesia',
78 'MH' => 'Marshall Islands',
80 'AA' => "Armed Forces Americas (except Canada)",
81 'AE' => "Armed Forces Europe / Canada / Middle East / Africa",
82 'AP' => "Armed Forces Pacific",
86 foreach my $country ( keys %addl ) {
87 foreach my $state ( keys %{ $addl{$country} } ) {
88 # $longname = $addl{$country}{$state};
89 _add_locale( 'country'=>$country, 'state'=>$state);
97 use Locale::SubCountry;
99 my( $country ) = shift;
101 my $subcountry = eval { new Locale::SubCountry($country) };
102 my @states = $subcountry ? $subcountry->all_codes : undef;
104 if ( !scalar(@states) || ( scalar(@states)==1 && !defined($states[0]) ) ) {
106 _add_locale( 'country'=>$country );
110 if ( $states[0] =~ /^(\d+|\w)$/ ) {
111 @states = map $subcountry->full_name($_), @states
114 foreach my $state ( @states ) {
115 _add_locale( 'country'=>$country, 'state'=>$state);
123 my $cust_main_county = new FS::cust_main_county( { 'tax'=>0, @_ });
124 my $error = $cust_main_county->insert;
125 die $error if $error;
128 sub populate_initial_data {
131 my $data = initial_data(%opt);
133 foreach my $table ( keys %$data ) {
135 my $class = "FS::$table";
139 my @records = @{ $data->{$table} };
141 foreach my $record ( @records ) {
142 my $args = delete($record->{'_insert_args'}) || [];
143 my $object = $class->new( $record );
144 my $error = $object->insert( @$args );
145 die "error inserting record into $table: $error\n"
156 #tie my %hash, 'Tie::DxHash',
157 tie my %hash, 'Tie::IxHash',
161 { 'groupname' => 'Superuser' },
164 #XXX need default new-style billing events
166 # 'part_bill_event' => [
167 # { 'payby' => 'CARD',
168 # 'event' => 'Batch card',
170 # 'eventcode' => '$cust_bill->batch_card(%options);',
172 # 'plan' => 'batch-card',
174 # { 'payby' => 'BILL',
175 # 'event' => 'Send invoice',
177 # 'eventcode' => '$cust_bill->send();',
181 # { 'payby' => 'DCRD',
182 # 'event' => 'Send invoice',
184 # 'eventcode' => '$cust_bill->send();',
188 # { 'payby' => 'DCHK',
189 # 'event' => 'Send invoice',
191 # 'eventcode' => '$cust_bill->send();',
195 # { 'payby' => 'DCLN',
196 # 'event' => 'Suspend',
198 # 'eventcode' => '$cust_bill->suspend();',
200 # 'plan' => 'suspend',
202 # #{ 'payby' => 'DCLN',
203 # # 'event' => 'Retriable',
205 # # 'eventcode' => '$cust_bill_event->retriable();',
207 # # 'plan' => 'retriable',
211 #you must create a service definition. An example of a service definition
212 #would be a dial-up account or a domain. First, it is necessary to create a
213 #domain definition. Click on View/Edit service definitions and Add a new
214 #service definition with Table svc_domain (and no modifiers).
217 'svcdb' => 'svc_domain',
221 #Now that you have created your first service, you must create a package
222 #including this service which you can sell to customers. Zero, one, or many
223 #services are bundled into a package. Click on View/Edit package
224 #definitions and Add a new package definition which includes quantity 1 of
225 #the svc_domain service you created above.
227 { 'pkg' => 'System Domain',
228 'comment' => '(NOT FOR CUSTOMERS)',
232 'pkg_svc' => { 1 => 1 }, # XXX
233 'primary_svc' => 1, #XXX
242 #After you create your first package, then you must define who is able to
243 #sell that package by creating an agent type. An example of an agent type
244 #would be an internal sales representitive which sells regular and
245 #promotional packages, as opposed to an external sales representitive
246 #which would only sell regular packages of services. Click on View/Edit
247 #agent types and Add a new agent type.
249 { 'atype' => 'internal' },
252 #Allow this agent type to sell the package you created above.
254 { 'typenum' => 1, #XXX
259 #After creating a new agent type, you must create an agent. Click on
260 #View/Edit agents and Add a new agent.
262 { 'agent' => 'Internal',
263 'typenum' => 1, # XXX
267 #Set up at least one Advertising source. Advertising sources will help you
268 #keep track of how effective your advertising is, tracking where customers
269 #heard of your service offerings. You must create at least one advertising
270 #source. If you do not wish to use the referral functionality, simply
271 #create a single advertising source only. Click on View/Edit advertising
272 #sources and Add a new advertising source.
274 { 'referral' => 'Internal', },
277 #Click on New Customer and create a new customer for your system accounts
278 #with billing type Complimentary. Leave the First package dropdown set to
281 { 'agentnum' => 1, #XXX
284 'last' => 'Accounts',
285 'address1' => '1234 System Lane',
286 'city' => 'Systemtown',
291 'payinfo' => 'system', #or something
292 'paydate' => '1/2037',
296 #From the Customer View screen of the newly created customer, order the
297 #package you defined above.
299 { 'custnum' => 1, #XXX
304 #From the Package View screen of the newly created package, choose
305 #(Provision) to add the customer's service for this new package.
306 #Add your own domain.
308 { 'domain' => $opt{'domain'},
311 'action' => 'N', #pseudo-field
315 #Go back to View/Edit service definitions on the main menu, and Add a new
316 #service definition with Table svc_acct. Select your domain in the domsvc
317 #Modifier. Set Fixed to define a service locked-in to this domain, or
318 #Default to define a service which may select from among this domain and
319 #the customer's domains.
330 sub populate_access {
333 use FS::access_right;
335 foreach my $rightname ( FS::AccessRight->rights ) {
336 my $access_right = new FS::access_right {
337 'righttype' => 'FS::access_group',
338 'rightobjnum' => 1, #$supergroup->groupnum,
339 'rightname' => $rightname,
341 my $ar_error = $access_right->insert;
342 die $ar_error if $ar_error;
345 #foreach my $agent ( qsearch('agent', {} ) ) {
346 my $access_groupagent = new FS::access_groupagent {
347 'groupnum' => 1, #$supergroup->groupnum,
348 'agentnum' => 1, #$agent->agentnum,
350 my $aga_error = $access_groupagent->insert;
351 die $aga_error if $aga_error;
356 sub populate_msgcat {
358 use FS::Record qw(qsearch);
361 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
362 my $error = $del_msgcat->delete;
363 die $error if $error;
366 my %messages = msgcat_messages();
368 foreach my $msgcode ( keys %messages ) {
369 foreach my $locale ( keys %{$messages{$msgcode}} ) {
370 my $msgcat = new FS::msgcat( {
371 'msgcode' => $msgcode,
373 'msg' => $messages{$msgcode}{$locale},
375 my $error = $msgcat->insert;
376 die $error if $error;
382 sub msgcat_messages {
385 # 'en_US' => 'Message',
390 'passwords_dont_match' => {
391 'en_US' => "Passwords don't match",
395 'en_US' => 'Invalid credit card number',
398 'unknown_card_type' => {
399 'en_US' => 'Unknown card type',
406 'empty_password' => {
407 'en_US' => 'Empty password',
410 'no_access_number_selected' => {
411 'en_US' => 'No access number selected',
415 'en_US' => 'Illegal (text)',
416 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
419 'illegal_or_empty_text' => {
420 'en_US' => 'Illegal or empty (text)',
421 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
424 'illegal_username' => {
425 'en_US' => 'Illegal username',
428 'illegal_password' => {
429 'en_US' => 'Illegal password (',
432 'illegal_password_characters' => {
433 'en_US' => ' characters)',
436 'username_in_use' => {
437 'en_US' => 'Username in use',
440 'illegal_email_invoice_address' => {
441 'en_US' => 'Illegal email invoice address',
445 'en_US' => 'Illegal (name)',
446 #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
450 'en_US' => 'Illegal (phone)',
455 'en_US' => 'Illegal (zip)',
460 'en_US' => 'Expired card',
464 'en_US' => 'Day Phone',
468 'en_US' => 'Night Phone',
471 'svc_external-id' => {
472 'en_US' => 'External ID',
475 'svc_external-title' => {
480 'en_US' => 'Driver\'s License',
484 'en_US' => 'Driver\'s License State',