Fixed import script so it sets "attending" correctly so that attendance gets prepopul...
[eq/.git] / bin / import_ward_data
index 800f28e7092d91da5d23519b939e1f59edd3cfa0..6fbb96b3ba1e7400a251c92c2b6f546ca583a60d 100755 (executable)
@@ -138,13 +138,22 @@ sub update_tc_individual_table
                $phone = $membership_data{$index}{'Household Phone'};
                $priesthood = $membership_data{$index}{'Priesthood'};
                $hhposition = $membership_data{$index}{'HH Position'};
-               $organization = $organization_by_id{$id};
+               $steward = ""; # This will be set later
+               # Default to the "Elders" quorum if the Organization data per member isn't available
+               # Only add "Elders" to the quorum since we don't have any other data availalbe to us to make a call
+               # TODO: make steward flexible with a setting in the config file 
+               if((! -e "$datadir/Organization\ class\ per\ member.csv") && ($priesthood =~ /Elder/i)) { 
+                       $steward = "Elder";
+                       $organization = "Elders"; 
+               }
+               # Preferred method is to pull organization data from the csv file
+               else { $organization = $organization_by_id{$id}; }
                $attending = 0;
                if(($organization =~ /Elders/) ||
                   ($organization =~ /Young Men/) ||
                   ($organization =~ /Sunday School/) ||
                   ($organization =~ /Primary/)
-                  ) { $attending = 1; }
+                 ) { $attending = 1; }
                if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "$areacode-$1"; }
                if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
                $email = $membership_data{$index}{'indiv E-mail'};
@@ -157,7 +166,7 @@ sub update_tc_individual_table
                if($rows == 0) {
                        # No existing records found for this individual, make a new entry
                        print "   Adding new individual: $individual_name\n";
-                       $sth = $dbh->prepare("insert into tc_individual values (NULL,'$id',\"$individual_name\",'$address','$phone','$email','$hhposition','$priesthood','',NULL,$attending,1)");
+                       $sth = $dbh->prepare("insert into tc_individual values (NULL,'$id',\"$individual_name\",'$address','$phone','$email','$hhposition','$priesthood','$steward',NULL,$attending,1)");
                        $sth->execute or die "-E- DB error: $DBI::errstr\n";
                } elsif($rows == 1) {
                        # An existing record was found for this individual, update it
@@ -221,6 +230,7 @@ sub update_tc_calling_table()
                $name =~ s/\'/\\'/g; #'
                $organization = $organization_data{$index}{'Organization'};
                $organization_by_name{$name} = $organization;
+               $indiv_id = $organization_data{$index}{'Indiv ID'};
                $organization_by_id{$indiv_id} = $organization;
                $position = $organization_data{$index}{'Position'};
                $sustained = $organization_data{$index}{'Sustained'};
@@ -663,13 +673,14 @@ if(defined $opt_o) {
 
 ###################################################
 # Process command line options
+our $datadir;
 if(defined $opt_n) { $datadir = $opt_n; }
 else { $datadir = shift(@ARGV); }
 print "\n-> Processing all ward data files in $datadir\n";
 
 ###################################################
 # Parse Ward Data Files
-&csv_to_hash("$datadir/Organization\ class\ per\ member.csv", \%organization_class_data);
+&optional_csv_to_hash("$datadir/Organization\ class\ per\ member.csv", \%organization_class_data);
 &csv_to_hash("$datadir/Membership.csv",\%membership_data);
 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
 &csv_to_hash("$datadir/Organization.csv",\%organization_data);
@@ -690,7 +701,7 @@ if($opt_v) {
 
 if($opt_s) { $dbh->disconnect(); exit; }
 
-# Now update the various eq DB tables
+# Now update the various DB tables
 &update_tc_calling_table();
 &update_tc_individual_table();
 &update_tc_companionship_table();