Esempio n. 1
0
        public static InboundInvoice Create (Organization organization, DateTime dueDate, Int64 amountCents,
            FinancialAccount budget, string supplier, string description, string payToAccount, string ocr, 
            string invoiceReference, Person creatingPerson)
        {
            InboundInvoice newInvoice = FromIdentity(SwarmDb.GetDatabaseForWriting().
                CreateInboundInvoice(organization.Identity, dueDate, budget.Identity,
                    supplier, payToAccount, ocr,
                    invoiceReference, amountCents, creatingPerson.Identity));

            newInvoice.Description = description;  // Not in original schema; not cause for schema update

            // Create a corresponding financial transaction with rows

            FinancialTransaction transaction =
                FinancialTransaction.Create(organization.Identity, DateTime.Now,
                "Invoice #" + newInvoice.Identity + " from " + supplier);

            transaction.AddRow(organization.FinancialAccounts.DebtsInboundInvoices, -amountCents, creatingPerson);
            transaction.AddRow(budget, amountCents, creatingPerson);

            // Make the transaction dependent on the inbound invoice

            transaction.Dependency = newInvoice;

            // Create notification (slightly misplaced logic, but this is failsafest place)

            OutboundComm.CreateNotificationAttestationNeeded(budget, creatingPerson, supplier, (double)amountCents / 100.0, description, NotificationResource.InboundInvoice_Created); // Slightly misplaced logic, but failsafer here
            SwarmopsLogEntry.Create(creatingPerson,
                                    new InboundInvoiceCreatedLogEntry(creatingPerson, supplier, description, (double)amountCents / 100.0, budget), newInvoice);

            return newInvoice;
        }
Esempio n. 2
0
        public static OfficerChain FromOrganizationAndGeography (Organization org, Geography geo)
        {
            int[] concernedPeopleId = Roles.GetAllUpwardRoles(org.Identity, geo.Identity);
            People concernedPeople = People.FromIdentities(concernedPeopleId);

            return new OfficerChain(concernedPeople, org.Identity);
        }
Esempio n. 3
0
 public static PaperLetter Create (Person creator, Organization organization, string fromName,
     string[] replyAddressLines, DateTime receivedDate, Person recipient, RoleType recipientRole, 
     bool personal)
 {
     return Create(creator.Identity, organization.Identity, fromName, replyAddressLines, receivedDate,
                   recipient.Identity, recipientRole, personal);
 }
Esempio n. 4
0
 public Access(Organization organization, Geography geography, AccessAspect aspect, AccessType type)
 {
     this.Organization = organization;
     this.Geography = geography;
     this.Aspect = aspect;
     this.Type = type;
 }
Esempio n. 5
0
        public static void Run(string data, Organization organization, Person runningPerson)
        {
            if (!data.StartsWith("Date\t Time\t Time Zone\t Name\t Type"))
            {
                runningPerson.SendPhoneMessage("The file you uploaded does not appear to be a PayPal tab-delimited file of all activity. No processing done. The data has been discarded.");
                throw new ArgumentException("This does not appear to be a PayPal file");
            }

            ImportResult result = ImportPaypal(data);

            ImportStats stats = ProcessImportedData(result, organization, runningPerson);

            try
            {
                runningPerson.SendPhoneMessage("The PayPal file was processed. See mail for more details.");
            }
            catch (Exception)
            {
                // Ignore error on SMS transmit
            }

            string mailBody = string.Empty;

            mailBody += String.Format("Rows processed: {0,9:N0}\r\n", stats.ProcessedTransactionCount);
            mailBody += String.Format("Tx imported:    {0,9:N0}\r\n", stats.ImportedTransactionCount);
            mailBody += String.Format("Tx modified:    {0,9:N0}\r\n", stats.ModifiedTransactionCount - stats.ImportedTransactionCount);

            runningPerson.SendNotice("PayPal file imported", mailBody, organization.Identity);
        }
Esempio n. 6
0
 public static OutboundMail Create (Person author, string title,
                                    string body, int mailPriority, int mailType,
                                    Organization organization, Geography geography)
 {
     return Create(author, title, body, mailPriority, mailType, organization,
                    geography, DateTime.Now);
 }
Esempio n. 7
0
        static public void Generate (Person person, Organization organization)
        {
            GnuPG generatingInstance = new GnuPG();
            generatingInstance.Timeout = 120000;
            generatingInstance.GenerateKeyPair(person.Name, person.PartyEmail, organization.Name,
                                        new DateTime(DateTime.Today.Year + 2, 12, 31));

            GnuPGKeyCollection keys = new GnuPG().GetKeys();
            foreach (GnuPGKey key in keys)
            {
                if (key.UserId == person.PartyEmail)
                {
                    // Console.Write(" signing...");
                    generatingInstance.SignKey(key.Fingerprint, "*****@*****.**");
                    // Console.Write(" uploading...");
                    generatingInstance.UploadKey(key.Fingerprint.Replace(" ", ""));
                    string armorSecret = new GnuPG().GetSecretKey(key.Fingerprint.Replace(" ", ""));
                    string armorPublic = new GnuPG().GetPublicKey(key.Fingerprint.Replace(" ", ""));
                    // Console.Write(" deleting...");
                    key.Delete();

                    person.CryptoPublicKey = armorPublic;
                    person.CryptoSecretKey = armorSecret;
                    person.CryptoFingerprint = key.Fingerprint;
                }
            }

        }
Esempio n. 8
0
 public void LoadData(Stream dataStream, Organization organization)
 {
     using (TextReader reader = new StreamReader(dataStream))  // TODO: Is encoding necessary?
     {
         LoadData(reader, organization);
     }
 }
Esempio n. 9
0
 public static MeetingElection Create (Person creator, Organization org, Geography geo, string name, InternalPollResultsType resultsType, int maxVoteLength, DateTime runningOpens, DateTime runningCloses, DateTime votingOpens, DateTime votingCloses)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateInternalPoll(org.Identity, geo.Identity, name, maxVoteLength,
                                                                resultsType, creator.Identity, runningOpens,
                                                                runningCloses, votingOpens, votingCloses));
 }
Esempio n. 10
0
 public static PaymentGroup Create (Organization organization, DateTime timestamp, Currency currency, Person createdByPerson)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePaymentGroup(organization.Identity, timestamp,
                                                                currency.Identity,
                                                                System.DateTime.Now, createdByPerson.Identity));
 }
Esempio n. 11
0
 public Org (Organization org)
     : base(org)
 {
     try
     {
         parentName = Organization.FromIdentity(ParentOrganizationId).Name;
     }
     catch
     {
         parentName = "N/A";
     }
     try
     {
         anchorName = Geography.FromIdentity(AnchorGeographyId).Name;
     }
     catch
     {
         anchorName = "N/A";
     }
     try
     {
         countryCode = base.DefaultCountry.Code;
     }
     catch
     {
         countryCode = "N/A";
     }
 }
Esempio n. 12
0
        public static ExpenseClaim Create(Person claimer, Organization organization, FinancialAccount budget, 
                                      DateTime expenseDate, string description, Int64 amountCents)
        {
            ExpenseClaim newClaim = FromIdentityAggressive (SwarmDb.GetDatabaseForWriting().CreateExpenseClaim (claimer.Identity, organization.Identity,
                                                                       budget.Identity, expenseDate, description, amountCents));
            // Create the financial transaction with rows

            string transactionDescription = "Expense #" + newClaim.Identity + ": " + description;  // TODO: Localize

            if (transactionDescription.Length > 64)
            {
                transactionDescription = transactionDescription.Substring(0, 61) + "...";
            }

            FinancialTransaction transaction =
                FinancialTransaction.Create(organization.Identity, DateTime.Now,
                transactionDescription);

            transaction.AddRow(organization.FinancialAccounts.DebtsExpenseClaims, -amountCents, claimer);
            transaction.AddRow(budget, amountCents, claimer);
             
            // Make the transaction dependent on the expense claim

            transaction.Dependency = newClaim;

            // Create notifications

            OutboundComm.CreateNotificationAttestationNeeded(budget, claimer, string.Empty, (double)amountCents / 100.0, description, NotificationResource.ExpenseClaim_Created); // Slightly misplaced logic, but failsafer here
            OutboundComm.CreateNotificationFinancialValidationNeeded(organization, (double) amountCents/100.0,
                                                                     NotificationResource.Receipts_Filed);
            SwarmopsLogEntry.Create(claimer,
                                    new ExpenseClaimFiledLogEntry(claimer /*filing person*/, claimer /*beneficiary*/, (double) amountCents/100.0, budget, description), newClaim);

            return newClaim;
        }
Esempio n. 13
0
        public static void Run(string data, Organization organization, Person runningPerson)
        {
            if (!data.StartsWith("\r\n<html>\r\n<head>\r\n    <style>\r\n        .tal"))
            {
                runningPerson.SendPhoneMessage("The file you uploaded does not appear to be a Payson export file. No processing done. The data has been discarded.");
                throw new ArgumentException("This does not appear to be a Payson file");
            }

            if (organization.Identity != 1)
            {
                runningPerson.SendPhoneMessage("Payson import is currently only supported for PPSE. No processing done. The data has been discarded.");
                throw new Exception("Payson is only supported for PPSE at the moment.");
            }

            ImportResult result = ImportPayson(data);

            ImportStats stats = ProcessImportedData(result, organization, runningPerson);

            try
            {
                runningPerson.SendPhoneMessage("The Payson file was processed. See mail for more details.");
            }
            catch (Exception)
            {
                // Ignore error on SMS transmit
            }

            string mailBody = string.Empty;

            mailBody += String.Format("Rows processed: {0,9:N0}\r\n", stats.ProcessedTransactionCount);
            mailBody += String.Format("Tx imported:    {0,9:N0}\r\n", stats.ImportedTransactionCount);
            mailBody += String.Format("Tx modified:    {0,9:N0}\r\n", stats.ModifiedTransactionCount - stats.ImportedTransactionCount);

            runningPerson.SendNotice("Payson file imported", mailBody, organization.Identity);
        }
Esempio n. 14
0
 public static ExternalActivity Create (Organization organization, Geography geograpy, ExternalActivityType type, DateTime date, string description, Person createdByPerson)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateExternalActivity(organization.Identity, geograpy.Identity,
                                                                    date, type, description,
                                                                    createdByPerson.Identity));
 }
Esempio n. 15
0
 public static AutoMail Create (AutoMailType type, Organization org, Geography geo,
                                Person author, string title, string body)
 {
     SwarmDb.GetDatabaseForWriting().SetAutoMail (type, org.Identity, geo.Identity,
                                         author == null ? 0 : author.Identity, title, body);
     return FromTypeOrganizationAndGeography (type, org, geo);
 }
Esempio n. 16
0
        public static OutboundComm Create(Person sender, Person from, Organization organization, string resolverClassString, string recipientDataXml, string transmitterClassString, string payloadXml, OutboundCommPriority priority)
        {
            int newId = SwarmDb.GetDatabaseForWriting().CreateOutboundComm(sender != null? sender.Identity: 0, from != null? from.Identity: 0,
                                                                           organization != null? organization.Identity: 0, resolverClassString,
                                                                           recipientDataXml ?? string.Empty, transmitterClassString,
                                                                           payloadXml, priority);

            return FromIdentityAggressive(newId);
        }
Esempio n. 17
0
 public PayoutCreatedLogEntry(Person payingPerson, Person beneficiaryPerson, Organization organization, Currency currency, double amount, string reason)
 {
     this.Amount = amount;
     this.Currency = currency.Code;
     this.OrganizationId = organization.Identity;
     this.DateTime = DateTime.UtcNow;
     this.Description = reason;
     this.ActingPersonId = payingPerson.Identity; // do not save name for data retention reasons
     this.BeneficiaryPersonId = (beneficiaryPerson != null ? beneficiaryPerson.Identity : 0);
 }
Esempio n. 18
0
 public static OutboundMail Create (Person author, string title,
                                    string body, int mailPriority, int mailType,
                                    Organization organization, Geography geography, DateTime releaseDateTime)
 {
     return
         FromIdentity(SwarmDb.GetDatabaseForWriting().CreateOutboundMail(MailAuthorType.Person, author.Identity, title,
                                                                  body, mailPriority, mailType,
                                                                  geography.Identity, organization.Identity,
                                                                  releaseDateTime));
 }
Esempio n. 19
0
        public static PaymentGroup FromTag (Organization organization, string tag)
        {
            BasicPaymentGroup basicGroup = SwarmDb.GetDatabaseForReading().GetPaymentGroupByTag(organization.Identity, tag);

            if (basicGroup == null)
            {
                return null;
            }

            return FromBasic(basicGroup);
        }
Esempio n. 20
0
        public static Parley Create (Organization organization, Person person, FinancialAccount budgetInitial, string name, Geography geography, string description, string informationUrl, DateTime startDate, DateTime endDate, Int64 budgetCents, Int64 guaranteeCents, Int64 attendanceFeeCents)
        {
            Parley newParley = 
                FromIdentity(SwarmDb.GetDatabaseForWriting().CreateParley(organization.Identity, person.Identity,
                                                                 -(budgetInitial.Identity), name, geography.Identity,
                                                                 description, informationUrl, startDate, endDate,
                                                                 budgetCents, guaranteeCents, attendanceFeeCents));

            PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ParleyCreated, person.Identity, organization.Identity, 0, 0, newParley.Identity, string.Empty); 

            return newParley;
        }
Esempio n. 21
0
        public static OutboundInvoice Create (Organization organization, Person createdByPerson, DateTime dueDate, FinancialAccount budget, string customerName, string invoiceAddressMail, string invoiceAddressPaper, Currency currency, bool domestic, string theirReference)
        {
            OutboundInvoice invoice = FromIdentity (SwarmDb.GetDatabaseForWriting().CreateOutboundInvoice(organization.Identity, createdByPerson != null? createdByPerson.Identity : 0, dueDate,
                                                         budget.Identity, customerName, invoiceAddressPaper,
                                                         invoiceAddressMail, currency.Identity, string.Empty, domestic, Authentication.CreateRandomPassword(6), theirReference));

            // Set reference

            invoice.Reference =
                Formatting.AddLuhnChecksum(Formatting.ReverseString(DateTime.Now.ToString("yyyyMMddHHmm")) +
                                           invoice.Identity.ToString());

            return invoice;
        }
Esempio n. 22
0
        public static Payment CreateSingle (Organization organization, DateTime dateTime, Currency currency, Int64 amountCents, OutboundInvoice invoice, Person createdByPerson)
        {
            // TODO: Verify that invoice is not already closed; if so, issue refund

            // TODO: Verify correct amount

            invoice.SetPaid();

            PaymentGroup group = PaymentGroup.Create(organization, dateTime, currency, createdByPerson);
            Payment newPayment = FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePayment(group.Identity, amountCents, string.Empty, string.Empty, string.Empty, false,
                                                 invoice.Identity));
            group.AmountCents = amountCents;

            return newPayment;
        }
Esempio n. 23
0
        public static CashAdvance Create(Organization organization, Person forPerson, Person createdByPerson, Int64 amountCents, FinancialAccount budget, string description)
        {
            CashAdvance newAdvance = FromIdentityAggressive(SwarmDb.GetDatabaseForWriting().CreateCashAdvance(forPerson.Identity,
                                                                                          createdByPerson.Identity,
                                                                                          organization.Identity,
                                                                                          budget.Identity, amountCents,
                                                                                          description));

            OutboundComm.CreateNotificationAttestationNeeded(budget, forPerson, string.Empty, (double) amountCents/100.0, description, NotificationResource.CashAdvance_Requested); // Slightly misplaced logic, but failsafer here
            SwarmopsLogEntry.Create(forPerson,
                                    new CashAdvanceRequestedLogEntry(createdByPerson, forPerson, (double) amountCents/100.0, budget, description),
                                    newAdvance);

            return newAdvance;
        }
Esempio n. 24
0
        public static AutoMail FromTypeOrganizationAndGeography (AutoMailType type, Organization org, Geography geo)
        {
            BasicAutoMail basic = SwarmDb.GetDatabaseForReading().GetAutoMail (type, org.Identity, geo.Identity);

            if (basic == null)
            {
                return null;
            }

            if (basic.Body.Trim().Length < 3)
            {
                return null; // If there is no body, there is no mail
            }

            return FromBasic (basic);
        }
Esempio n. 25
0
        public static OutboundComm Create(Person sender, Person from, Organization organization, CommResolverClass resolverClass, string recipientDataXml, CommTransmitterClass transmitterClass, string payloadXml, OutboundCommPriority priority)
        {
            string resolverClassString = string.Empty;
            if (resolverClass != CommResolverClass.Unknown)
            {
                resolverClassString = resolverClass.ToString();
            }

            string transmitterClassString = string.Empty;
            if (transmitterClass != CommTransmitterClass.Unknown)
            {
                transmitterClassString = "Swarmops.Utility.Communications." + transmitterClass.ToString();
            }

            return Create(sender, from, organization, resolverClassString, recipientDataXml, transmitterClassString,
                          payloadXml, priority);
        }
Esempio n. 26
0
        static public BasicMailTemplate GetBestMatch (string templateName, string language, string country, Organization org)
        {
            List<BasicMailTemplate> tmplList = GetCachedTemplates(templateName);

            Organizations orgLine = ( org != null) ? org.GetLine() : new Organizations();

            int[] lineIDs = orgLine.Identities;
            List<int> idlist = new List<int>(lineIDs);

            BasicMailTemplate templateDefault = null;
            BasicMailTemplate countryDefault = null;
            BasicMailTemplate bestSofar = null;
            int bestIndex = -1;

            foreach (BasicMailTemplate bmt in tmplList)
            {
                int thisIndex = idlist.IndexOf(bmt.OrganizationId);
                if (thisIndex > bestIndex)
                {
                    bestIndex = thisIndex;
                    bestSofar = bmt;
                }
                else if (bmt.CountryCode.ToUpper() == country && bmt.OrganizationId < 1)
                {
                    countryDefault = bmt;
                }
                else if (bmt.CountryCode == "" && bmt.OrganizationId < 1)
                {
                    templateDefault = bmt;
                }
            }
            if (bestSofar != null)
                return bestSofar;
            else if (countryDefault != null)
                return countryDefault;
            else if (templateDefault != null)
                return templateDefault;
            else
                return null;
        }
Esempio n. 27
0
        public static OutboundComm CreateNotification (Organization organization, string notificationResourceString)
        {
            List<Person> recipients = People.FromSingle(Person.FromIdentity(1)); // Initial Admin recipient

            if (organization != null)
            {
                // TODO: Change to org admins
            }

            OutboundComm comm = OutboundComm.Create(null, null, organization, CommResolverClass.Unknown, null,
                                                    CommTransmitterClass.CommsTransmitterMail,
                                                    new PayloadEnvelope(new NotificationPayload(notificationResourceString)).ToXml(),
                                                    OutboundCommPriority.Low);

            foreach (Person person in recipients)
            {
                comm.AddRecipient(person);
            }

            comm.Resolved = true;

            return comm;
        }
Esempio n. 28
0
    public static void InitDatabase()
    {
        // Make sure we're uninitialized

        bool organizationOneExists = false;

        Swarmops.Logic.Structure.Organization organizationOne = null;

        try
        {
            organizationOne       = Swarmops.Logic.Structure.Organization.FromIdentity(1);
            organizationOneExists = true;
        }
        catch (Exception)
        {
            // We expect this to throw
        }

        if (organizationOneExists || organizationOne != null)
        {
            throw new InvalidOperationException("Cannot re-initialize database");
        }

        // Store database credentials

        SwarmDb.Configuration.Set(
            new SwarmDb.Configuration(
                _testReadCredentials,
                _testWriteCredentials,
                _testAdminCredentials));

        // Start an async thread that does all the work, then return

        Thread initThread = new Thread(InitDatabaseThread);

        initThread.Start();
    }
Esempio n. 29
0
 public static RoleLookup FromOrganization (Organization organization)
 {
     return FromOrganization(organization.Identity);
 }
Esempio n. 30
0
 public static RoleLookup FromGeographyAndOrganization (Geography geography, Organization organization)
 {
     return FromGeographyAndOrganization(geography.Identity, organization.Identity);
 }
Esempio n. 31
0
 public void SetCandidateDocumented (Organization organization, Person candidate)
 {
     SwarmDb.GetDatabaseForWriting().SetCandidateDocumentationReceived(this.Identity, organization.Identity, candidate.Identity);
 }
Esempio n. 32
0
 public OrganizationParameters(Organization organization)
 {
     this.organization = organization;
     this.data         = ObjectOptionalData.ForObject(organization);
 }