public static Refund Create (Payment payment, Person creatingPerson, Int64 amountCents) { if (amountCents > payment.AmountCents) { throw new ArgumentException("Refund amount cannot exceed payment amount"); } Refund refund = FromIdentity(SwarmDb.GetDatabaseForWriting().CreateRefund(payment.Identity, creatingPerson.Identity, amountCents)); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.RefundCreated, 0, refund.Payment.OutboundInvoice.Organization.Identity, Geography.RootIdentity, 0, refund.Identity, string.Empty); return refund; }
public static PaymentInformationList ForPayment(Payment payment) { BasicPaymentInformation[] basicInfoList = SwarmDb.GetDatabaseForReading().GetPaymentInformation(payment.Identity); return(FromArray(basicInfoList)); }
public OutboundInvoice Credit(Person creditingPerson) { OutboundInvoice credit = Create(Organization, creditingPerson, DateTime.Now, Budget, CustomerName, InvoiceAddressMail, InvoiceAddressPaper, Currency, Domestic, TheirReference); if (Domestic) // TODO: LANGUAGE { credit.AddItem("Kredit för faktura " + Reference, -AmountCents); credit.AddItem("DETTA ÄR EN KREDITFAKTURA OCH SKA EJ BETALAS", 0.00); AddItem( String.Format("KREDITERAD {0:yyyy-MM-dd} i kreditfaktura {1}", DateTime.Today, credit.Reference), 0.00); } else { credit.AddItem("Credit for invoice " + Reference, -AmountCents); credit.AddItem("THIS IS A CREDIT. DO NOT PAY.", 0.00); AddItem( String.Format("CREDITED {0:yyyy-MM-dd} in credit invoice {1}", DateTime.Today, credit.Reference), 0.00); } CreditInvoice = credit; credit.CreditsInvoice = this; credit.Open = false; // Create the financial transaction with rows FinancialTransaction transaction = FinancialTransaction.Create(credit.OrganizationId, DateTime.Now, "Credit Invoice #" + credit.Identity + " to " + credit.CustomerName); transaction.AddRow( Organization.FromIdentity(credit.OrganizationId).FinancialAccounts.AssetsOutboundInvoices, credit.AmountCents, creditingPerson); transaction.AddRow(credit.Budget, -credit.AmountCents, creditingPerson); // Make the transaction dependent on the credit transaction.Dependency = credit; // Create the event for PirateBot-Mono to send off mails PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoiceCreated, creditingPerson.Identity, OrganizationId, Geography.RootIdentity, 0, credit.Identity, string.Empty); // If this invoice was already closed, issue a credit. If not closed, close it. if (Open) { Open = false; } else { Payment payment = Payment; if (payment != null) { payment.Refund(creditingPerson); } } return(credit); }
public static Refund Create (Payment payment, Person creatingPerson) { return Create(payment, creatingPerson, 0L); }
public static void AutomatchAgainstUnbalancedTransactions(Organization organization, Person person) { // Matches unbalanced financial transactions against unclosed outbound invoices // Should this be in bot? OutboundInvoices invoices = ForOrganization(organization); // gets all open // build a hash of all invoice reference numbers, ours and theirs (and let's hope for no collision...) // TODO: Collision detection Dictionary <string, OutboundInvoice> invoiceLookup = new Dictionary <string, OutboundInvoice>(); foreach (OutboundInvoice invoice in invoices) { invoiceLookup[RemoveNoise(invoice.TheirReference)] = invoice; invoiceLookup[RemoveNoise(invoice.Reference)] = invoice; } FinancialTransactions transactions = FinancialTransactions.GetUnbalanced(organization); foreach (FinancialTransaction transaction in transactions) { string[] words = transaction.Description.Split(' '); bool collision = false; int invoiceId = 0; OutboundInvoice identifiedInvoice = null; foreach (string word in words) { string cleanWord = RemoveNoise(word); if (invoiceLookup.ContainsKey(cleanWord)) { OutboundInvoice invoice = invoiceLookup[cleanWord]; if (transaction.Rows.AmountCentsTotal == invoice.AmountCents) { // Matching description and amount if (invoiceId != 0 && invoiceId != invoice.Identity) { collision = true; } else if (invoice.Open) // double check it wasn't closed previously in loop { invoiceId = invoice.Identity; identifiedInvoice = invoice; } } } } // If invoiceId != 0 and collision == false, we've found exactly one match if (invoiceId != 0 && !collision) { Payment.CreateSingle(organization, transaction.DateTime, identifiedInvoice.Currency, identifiedInvoice.AmountCents, identifiedInvoice, person); // Balance transaction against outbound invoices transaction.AddRow(organization.FinancialAccounts.AssetsOutboundInvoices, -identifiedInvoice.AmountCents, person); } } }