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 Locale::SubCountry;
65 use FS::cust_main_county;
68 foreach my $country ( sort map uc($_), all_country_codes ) {
70 my $subcountry = eval { new Locale::SubCountry($country) };
71 my @states = $subcountry ? $subcountry->all_codes : undef;
73 if ( !scalar(@states) || ( scalar(@states)==1 && !defined($states[0]) ) ) {
75 my $cust_main_county = new FS::cust_main_county({
77 'country' => $country,
79 my $error = $cust_main_county->insert;
84 if ( $states[0] =~ /^(\d+|\w)$/ ) {
85 @states = map $subcountry->full_name($_), @states
88 foreach my $state ( @states ) {
90 my $cust_main_county = new FS::cust_main_county({
93 'country' => $country,
95 my $error = $cust_main_county->insert;
105 sub populate_initial_data {
108 my $data = initial_data(%opt);
110 foreach my $table ( keys %$data ) {
112 my $class = "FS::$table";
116 my @records = @{ $data->{$table} };
118 foreach my $record ( @records ) {
119 my $args = delete($record->{'_insert_args'}) || [];
120 my $object = $class->new( $record );
121 my $error = $object->insert( @$args );
122 die "error inserting record into $table: $error\n"
133 #tie my %hash, 'Tie::DxHash',
134 tie my %hash, 'Tie::IxHash',
138 { 'groupname' => 'Superuser' },
142 'part_bill_event' => [
144 'event' => 'Batch card',
146 'eventcode' => '$cust_bill->batch_card(%options);',
148 'plan' => 'batch-card',
151 'event' => 'Send invoice',
153 'eventcode' => '$cust_bill->send();',
158 'event' => 'Send invoice',
160 'eventcode' => '$cust_bill->send();',
165 'event' => 'Send invoice',
167 'eventcode' => '$cust_bill->send();',
172 'event' => 'Suspend',
174 'eventcode' => '$cust_bill->suspend();',
179 'event' => 'Retriable',
181 'eventcode' => '$cust_bill_event->retriable();',
183 'plan' => 'retriable',
187 #you must create a service definition. An example of a service definition
188 #would be a dial-up account or a domain. First, it is necessary to create a
189 #domain definition. Click on View/Edit service definitions and Add a new
190 #service definition with Table svc_domain (and no modifiers).
193 'svcdb' => 'svc_domain',
197 #Now that you have created your first service, you must create a package
198 #including this service which you can sell to customers. Zero, one, or many
199 #services are bundled into a package. Click on View/Edit package
200 #definitions and Add a new package definition which includes quantity 1 of
201 #the svc_domain service you created above.
203 { 'pkg' => 'System Domain',
204 'comment' => '(NOT FOR CUSTOMERS)',
208 'pkg_svc' => { 1 => 1 }, # XXX
209 'primary_svc' => 1, #XXX
218 #After you create your first package, then you must define who is able to
219 #sell that package by creating an agent type. An example of an agent type
220 #would be an internal sales representitive which sells regular and
221 #promotional packages, as opposed to an external sales representitive
222 #which would only sell regular packages of services. Click on View/Edit
223 #agent types and Add a new agent type.
225 { 'atype' => 'internal' },
228 #Allow this agent type to sell the package you created above.
230 { 'typenum' => 1, #XXX
235 #After creating a new agent type, you must create an agent. Click on
236 #View/Edit agents and Add a new agent.
238 { 'agent' => 'Internal',
239 'typenum' => 1, # XXX
243 #Set up at least one Advertising source. Advertising sources will help you
244 #keep track of how effective your advertising is, tracking where customers
245 #heard of your service offerings. You must create at least one advertising
246 #source. If you do not wish to use the referral functionality, simply
247 #create a single advertising source only. Click on View/Edit advertising
248 #sources and Add a new advertising source.
250 { 'referral' => 'Internal', },
253 #Click on New Customer and create a new customer for your system accounts
254 #with billing type Complimentary. Leave the First package dropdown set to
257 { 'agentnum' => 1, #XXX
260 'last' => 'Accounts',
261 'address1' => '1234 System Lane',
262 'city' => 'Systemtown',
267 'payinfo' => 'system', #or something
268 'paydate' => '1/2037',
272 #From the Customer View screen of the newly created customer, order the
273 #package you defined above.
275 { 'custnum' => 1, #XXX
280 #From the Package View screen of the newly created package, choose
281 #(Provision) to add the customer's service for this new package.
282 #Add your own domain.
284 { 'domain' => $opt{'domain'},
287 'action' => 'N', #pseudo-field
291 #Go back to View/Edit service definitions on the main menu, and Add a new
292 #service definition with Table svc_acct. Select your domain in the domsvc
293 #Modifier. Set Fixed to define a service locked-in to this domain, or
294 #Default to define a service which may select from among this domain and
295 #the customer's domains.
306 sub populate_access {
309 use FS::access_right;
311 foreach my $rightname ( FS::AccessRight->rights ) {
312 my $access_right = new FS::access_right {
313 'righttype' => 'FS::access_group',
314 'rightobjnum' => 1, #$supergroup->groupnum,
315 'rightname' => $rightname,
317 my $ar_error = $access_right->insert;
318 die $ar_error if $ar_error;
321 #foreach my $agent ( qsearch('agent', {} ) ) {
322 my $access_groupagent = new FS::access_groupagent {
323 'groupnum' => 1, #$supergroup->groupnum,
324 'agentnum' => 1, #$agent->agentnum,
326 my $aga_error = $access_groupagent->insert;
327 die $aga_error if $aga_error;
332 sub populate_msgcat {
334 use FS::Record qw(qsearch);
337 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
338 my $error = $del_msgcat->delete;
339 die $error if $error;
342 my %messages = msgcat_messages();
344 foreach my $msgcode ( keys %messages ) {
345 foreach my $locale ( keys %{$messages{$msgcode}} ) {
346 my $msgcat = new FS::msgcat( {
347 'msgcode' => $msgcode,
349 'msg' => $messages{$msgcode}{$locale},
351 my $error = $msgcat->insert;
352 die $error if $error;
358 sub msgcat_messages {
361 # 'en_US' => 'Message',
366 'passwords_dont_match' => {
367 'en_US' => "Passwords don't match",
371 'en_US' => 'Invalid credit card number',
374 'unknown_card_type' => {
375 'en_US' => 'Unknown card type',
382 'empty_password' => {
383 'en_US' => 'Empty password',
386 'no_access_number_selected' => {
387 'en_US' => 'No access number selected',
391 'en_US' => 'Illegal (text)',
392 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in field',
395 'illegal_or_empty_text' => {
396 'en_US' => 'Illegal or empty (text)',
397 #'en_US' => 'Only letters, numbers, spaces, and the following punctuation symbols are permitted: ! @ # $ % & ( ) - + ; : \' " , . ? / in required field',
400 'illegal_username' => {
401 'en_US' => 'Illegal username',
404 'illegal_password' => {
405 'en_US' => 'Illegal password (',
408 'illegal_password_characters' => {
409 'en_US' => ' characters)',
412 'username_in_use' => {
413 'en_US' => 'Username in use',
416 'illegal_email_invoice_address' => {
417 'en_US' => 'Illegal email invoice address',
421 'en_US' => 'Illegal (name)',
422 #'en_US' => 'Only letters, numbers, spaces and the following punctuation symbols are permitted: , . - \' in field',
426 'en_US' => 'Illegal (phone)',
431 'en_US' => 'Illegal (zip)',
436 'en_US' => 'Expired card',
440 'en_US' => 'Day Phone',
444 'en_US' => 'Night Phone',
447 'svc_external-id' => {
448 'en_US' => 'External ID',
451 'svc_external-title' => {