Esempio n. 1
0
        /// <summary>
        /// Exports the contributions.
        /// </summary>
        /// <param name="modifiedSince">The modified since.</param>
        public static void ExportContributions(DateTime modifiedSince, bool exportContribImages)
        {
            try
            {
                var donations = GetDonations(false, modifiedSince, null)
                                .Where(d => d.refunded == false && d.payment_status == "succeeded")
                                .ToList();

                foreach (var donation in donations)
                {
                    var importTransaction        = PCOImportDonation.Translate(donation);
                    var importTransactionDetails = PCOImportDesignation.Translate(donation);

                    if (importTransaction != null)
                    {
                        ImportPackage.WriteToPackage(importTransaction);

                        foreach (var detail in importTransactionDetails)
                        {
                            if (detail != null)
                            {
                                ImportPackage.WriteToPackage(detail);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Writes the person attributes.
        /// </summary>
        public static void WritePersonAttributes()
        {
            foreach (var attrib in PersonAttributes)
            {
                var attribute = new PersonAttribute();

                // strip out "Ind" from the attribute name and add spaces between words
                attribute.Name     = ExtensionMethods.SplitCase(attrib.Key.Replace("Ind", ""));
                attribute.Key      = attrib.Key;
                attribute.Category = "Imported Attributes";

                switch (attrib.Value)
                {
                case "String":
                    attribute.FieldType = "Rock.Field.Types.TextFieldType";
                    break;

                case "DateTime":
                    attribute.FieldType = "Rock.Field.Types.DateTimeFieldType";
                    break;

                default:
                    attribute.FieldType = "Rock.Field.Types.TextFieldType";
                    break;
                }

                ImportPackage.WriteToPackage(attribute);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Exports the accounts.
        /// </summary>
        public static void ExportFinancialAccounts()
        {
            try
            {
                var funds = GetFunds(false, null, null);

                /*
                 * XDocument xdoc = XDocument.Parse( response.Content );
                 *
                 * if ( PCOApi.DumpResponseToXmlFile )
                 * {
                 *  xdoc.Save( Path.Combine( ImportPackage.PackageDirectory, $"API_FINANCIAL_ACCOUNTS_ResponseLog.xml" ) );
                 * }
                 */

                // process accounts
                foreach (var fund in funds)
                {
                    var importFund = PCOImportFund.Translate(fund);

                    if (importFund != null)
                    {
                        ImportPackage.WriteToPackage(importFund);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Exports the individuals.
        /// </summary>
        public static void ExportIndividuals(DateTime modifiedSince, string emailType, string campusKey)
        {
            try
            {
                _modifiedSince = modifiedSince;
                _emailType     = emailType;

                //load attributes
                LoadPersonAttributes();

                // write out the person attributes
                WritePersonAttributes();

                // export people
                using (var dtPeople = GetTableData(SQL_PEOPLE))
                {
                    foreach (DataRow row in dtPeople.Rows)
                    {
                        var importPerson = AcsPerson.Translate(row, campusKey);

                        if (importPerson != null)
                        {
                            ImportPackage.WriteToPackage(importPerson);
                        }
                    }
                }

                // export person notes
                using (var dtPeopleNotes = GetTableData(SQL_PEOPLE_NOTES))
                {
                    foreach (DataRow row in dtPeopleNotes.Rows)
                    {
                        var importNote = AcsPersonNote.Translate(row);

                        if (importNote != null)
                        {
                            ImportPackage.WriteToPackage(importNote);
                        }
                    }
                }

                // export family notes
                using (var dtFamilyNotes = GetTableData(SQL_FAMILY_NOTES))
                {
                    foreach (DataRow row in dtFamilyNotes.Rows)
                    {
                        var importNote = AcsFamilyNote.Translate(row);

                        if (importNote != null)
                        {
                            ImportPackage.WriteToPackage(importNote);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Exports the financial accounts.
        /// </summary>
        public static void ExportFinancialAccounts()
        {
            try
            {
                _request = new RestRequest(API_GIVING_CATEGORIES, Method.GET);
                _request.AddQueryParameter("session_id", SessionId);
                var response = _client.Execute(_request);
                ApiCounter++;

                dynamic data = JsonConvert.DeserializeObject(response.Content);

                JArray records = data.data;

                if (records.Count > 0)
                {
                    foreach (var account in records)
                    {
                        FinancialAccount importAccount = ElexioCommunityFinancialAccount.Translate(account);
                        if (importAccount != null)
                        {
                            ImportPackage.WriteToPackage(importAccount);
                        }

                        _accountLookups.Add((int)account["id"], (string)account["name"]);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Internal method for ExportFinancialAccounts().
        /// </summary>
        private void ExportFinancialAccounts_Internal()
        {
            var dvFunds = new DataView(_db.Table("Contribution").Data);

            // Get primary funds.
            var dtPrimaryFunds = dvFunds.ToTable(true, "fund_name");

            // Get sub-funds.
            dvFunds.RowFilter = "ISNULL(sub_fund_name, 'Null Column') <> 'Null Column'";
            var dtFunds = dvFunds.ToTable(true, "fund_name", "sub_fund_name");

            // Merge primary and sub-funds.
            dtFunds.Merge(dtPrimaryFunds);

            foreach (DataRow row in dtFunds.Rows)
            {
                var importAccount = F1FinancialAccount.Translate(row);

                if (importAccount != null)
                {
                    ImportPackage.WriteToPackage(importAccount);
                }
            }

            // Cleanup.
            dtFunds.Clear();
            GC.Collect();
        }
Esempio n. 7
0
        /// <summary>
        /// Takes a CSV filepath and adds all the breeze person note records within that file to the
        /// exported slingshot data
        /// </summary>
        public static void ExportNotes(string notesCsvFilename, BackgroundWorker worker)
        {
            try
            {
                // Reset the error message
                ErrorMessage = null;

                // Open the CSV file and begin reading the Breeze people notes data
                using (var reader = File.OpenText(notesCsvFilename))
                    using (var csv = new CsvReader(reader))
                    {
                        while (csv.Read())
                        {
                            var recordDictionary = csv.GetRecord <dynamic>() as IDictionary <string, object>;
                            var note             = BreezeNote.Translate(recordDictionary);
                            ImportPackage.WriteToPackage(note);

                            // Report percentage for progress bar
                            var percentage = ( double )reader.BaseStream.Position / reader.BaseStream.Length;
                            worker.ReportProgress(( int )(percentage * 100));
                        }
                    }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Exports the contributions.
        /// </summary>
        /// <param name="modifiedSince">The modified since.</param>
        public override void ExportContributions(DateTime modifiedSince, bool exportContribImages)
        {
            try
            {
                using (var dtContributions = GetTableData(SQL_CONTRIBUTIONS))
                {
                    //Get head of house holds because in F1 pledges can be tied to indiviuals or households
                    var headOfHouseHolds = GetTableData(SQL_PEOPLE).Select("household_position = 'Head' ");

                    foreach (DataRow row in dtContributions.Rows)
                    {
                        var importTransaction = F1FinancialTransaction.Translate(row, headOfHouseHolds);

                        if (importTransaction != null)
                        {
                            ImportPackage.WriteToPackage(importTransaction);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Writes the group types.
 /// </summary>
 public static void WriteGroupTypes()
 {
     // hardcode a generic group type
     ImportPackage.WriteToPackage(new GroupType()
     {
         Id   = 9999,
         Name = "Imported Group"
     });
 }
Esempio n. 10
0
 public static void WriteFinancialBatch()
 {
     // hardcode a generic financial batch
     ImportPackage.WriteToPackage(new FinancialBatch()
     {
         Id        = 9999,
         Name      = "Imported Transactions",
         Status    = BatchStatus.Closed,
         StartDate = DateTime.Now
     });
 }
Esempio n. 11
0
 /// <summary>
 /// Writes the group attributes.
 /// </summary>
 public static void WriteGroupAttributes()
 {
     // export person attribute list
     ImportPackage.WriteToPackage(new GroupAttribute()
     {
         Name      = "Has Childcare",
         Key       = "HasChildcare",
         Category  = "Small Group",
         FieldType = "Rock.Field.Types.BooleanFieldType"
     });
 }
Esempio n. 12
0
        /// <summary>
        /// Exports any contributions.  Currently, the ACS export file doesn't include
        ///  batches.
        /// </summary>
        public static void ExportContributions(DateTime modifiedSince)
        {
            try
            {
                // since the ACS export doesn't include batches and Rock expects transactions
                //  to belong to a batch, a default batch is created.
                WriteFinancialBatch();

                using (var dtContributions = GetTableData(SQL_FINANCIAL_TRANSACTIONS))
                {
                    foreach (DataRow row in dtContributions.Rows)
                    {
                        var importFinancialTransaction = AcsFinancialTransaction.Translate(row);

                        if (importFinancialTransaction != null)
                        {
                            ImportPackage.WriteToPackage(importFinancialTransaction);
                        }
                    }
                }

                using (var dtContributionDetails = GetTableData(SQL_FINANCIAL_TRANSACTIONDETAILS))
                {
                    foreach (DataRow row in dtContributionDetails.Rows)
                    {
                        var importFinancialTransactionDetail = AcsFinancialTransactionDetail.Translate(row);

                        if (importFinancialTransactionDetail != null)
                        {
                            ImportPackage.WriteToPackage(importFinancialTransactionDetail);
                        }
                    }
                }

                using (var dtPledges = GetTableData(SQL_FINANCIAL_PLEDGES))
                {
                    foreach (DataRow row in dtPledges.Rows)
                    {
                        var importFinancialPledge = AcsFinancialPledge.Translate(row);

                        if (importFinancialPledge != null)
                        {
                            ImportPackage.WriteToPackage(importFinancialPledge);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Exports the individuals.
        /// </summary>
        public static void ExportIndividuals()
        {
            try
            {
                // Get the Uder Defined Column information for a Person
                string fieldType;

                _PersonUDFColumns = new Dictionary <Tuple <string, string>, string>();
                using (DataTable data = GetTableData(SQL_UDF_COLUMNS))
                {
                    foreach (DataRow row in data.Rows)
                    {
                        switch (row.Field <string>("FIELD_TYPE"))
                        {
                        case "C":
                            fieldType = "text"; break;

                        case "N":
                            fieldType = "number"; break;      // Checkbox = 1 or 0

                        case "D":
                            fieldType = "date"; break;

                        default:
                            continue;
                        }
                        _PersonUDFColumns.Add(new Tuple <string, string>(row.Field <string>("UDF_NAME"), fieldType), row.Field <string>("UDF_COLUMN"));
                    }
                }

                // export people
                using (var dtPeople = GetTableData(SQL_PEOPLE))
                {
                    foreach (DataRow row in dtPeople.Rows)
                    {
                        var importPerson = SkPerson.Translate(row);
                        if (importPerson is null)
                        {
                            continue;
                        }

                        ImportPackage.WriteToPackage(importPerson);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Exports the financial pledges.
        /// </summary>
        public static void ExportFinancialPledges()
        {
            try
            {
                _request = new RestRequest(API_PLEDGE_CAMPAIGNS, Method.GET);
                _request.AddQueryParameter("session_id", SessionId);
                var response = _client.Execute(_request);
                ApiCounter++;

                dynamic data = JsonConvert.DeserializeObject(response.Content);

                JArray records = data.data;

                if (records.Count > 0)
                {
                    foreach (var pledge in records)
                    {
                        string pledgeId = pledge.Value <string>("campaignId");

                        _request = new RestRequest(API_PLEDGE_PEOPLE + pledgeId.ToString(), Method.GET);
                        _request.AddQueryParameter("session_id", SessionId);
                        response = _client.Execute(_request);
                        ApiCounter++;

                        data = JsonConvert.DeserializeObject(response.Content);

                        JArray personPledgeRecords = data.data;

                        if (personPledgeRecords != null)
                        {
                            foreach (var personPledge in personPledgeRecords)
                            {
                                FinancialPledge importPledge = ElexioCommunityFinancialPledge.Translate(personPledge);
                                if (importPledge != null)
                                {
                                    ImportPackage.WriteToPackage(importPledge);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Exports the person interactions.
        /// </summary>
        public static void ExportPersonInteractions()
        {
            // interactions as notes
            _client  = new RestClient(ElexioCommunityApi.ApiUrl);
            _request = new RestRequest(ElexioCommunityApi.API_INTERACTIONS, Method.GET);
            _request.AddQueryParameter("session_id", ElexioCommunityApi.SessionId);
            _request.AddQueryParameter("start", "1/1/1990");
            _request.AddQueryParameter("count", "10000");
            var response = _client.Execute(_request);

            ElexioCommunityApi.ApiCounter++;

            dynamic interactionData = JsonConvert.DeserializeObject(response.Content);

            var counter = 1000000; // offset to avoid collisions with regular person notes
            var records = interactionData.data.items;

            if (records != null)
            {
                foreach (var interaction in records)
                {
                    string personId = interaction.person.uid;
                    if (personId.AsIntegerOrNull().HasValue)
                    {
                        counter++;

                        PersonNote note = new PersonNote();
                        note.Id       = counter;
                        note.PersonId = personId.AsInteger();
                        note.DateTime = interaction.dateCompleted;
                        note.NoteType = "Legacy Interaction";
                        note.Caption  = interaction.type.name;
                        note.Text     = interaction.summary;

                        string assigned = interaction.assignee.uid;

                        if (assigned.AsIntegerOrNull().HasValue)
                        {
                            note.CreatedByPersonId = assigned.AsInteger();
                        }

                        ImportPackage.WriteToPackage(note);
                    }
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Exports any contributions.
        /// </summary>
        public static void ExportContributions(DateTime modifiedSince)
        {
            try
            {
                List <Batch> batches = GetTable("csbatch.udb").Map <Batch>();

                try
                {
                    foreach (Batch batch in batches)
                    {
                        var importBatch = SKBatch.Translate(batch);
                        if (modifiedSince.Year <= 1 || importBatch.CreatedDateTime > modifiedSince || importBatch.ModifiedDateTime > modifiedSince)
                        {
                            ImportPackage.WriteToPackage(importBatch);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorMessage = ex.Message;
                }

                List <Contribution>       contributions       = GetTable("csconmst.udb").Map <Contribution>();
                List <ContributionDetail> contributionDetails = GetTable("cscondtl.udb").Map <ContributionDetail>();

                foreach (Contribution contribution in contributions)
                {
                    var importFinancialTransaction = SKContribution.Translate(contribution, contributionDetails);


                    if (modifiedSince.Year <= 1 || importFinancialTransaction.CreatedDateTime > modifiedSince || importFinancialTransaction.ModifiedDateTime > modifiedSince)
                    {
                        ImportPackage.WriteToPackage(importFinancialTransaction);

                        foreach (var importDetail in importFinancialTransaction.FinancialTransactionDetails)
                        {
                            ImportPackage.WriteToPackage(importDetail);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }
        }