예제 #1
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);
        }
예제 #2
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;
        }
예제 #3
0
        public static Payment ForOutboundInvoice(OutboundInvoice invoice)
        {
            BasicPayment[] array = SwarmDb.GetDatabaseForReading().GetPayments(invoice);

            if (array.Length == 0)
            {
                return(null); // or throw exception?
            }

            if (array.Length > 1)
            {
                throw new InvalidDataException("There can not be two payments for one invoice");
            }

            return(FromBasic(array[0]));
        }
예제 #4
0
        public static Payment ForOutboundInvoice (OutboundInvoice invoice)
        {
            BasicPayment[] array = SwarmDb.GetDatabaseForReading().GetPayments(invoice);

            if (array.Length == 0)
            {
                return null; // or throw exception?
            }

            if (array.Length > 1)
            {
                throw new InvalidDataException("There can not be two payments for one invoice");
            }

            return FromBasic(array[0]);
        }
예제 #5
0
        public static Payment Create(PaymentGroup group, double amount, string reference, string fromAccount, string key, bool hasImage)
        {
            // Match against outbound invoice, too

            OutboundInvoice invoice = OutboundInvoice.FromReference(reference);

            // TODO: Verify that invoice is not already closed; if so, issue refund

            // TODO: Verify correct amount

            invoice.Open = false;

            PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoicePaid, 0, group.Organization.Identity,
                                 Geography.RootIdentity, 0, invoice.Identity, string.Empty);

            return(FromIdentity(SwarmDb.GetDatabaseForWriting().CreatePayment(group.Identity, amount, reference, fromAccount, key, hasImage,
                                                                              invoice.Identity)));
        }
예제 #6
0
        public static OutboundInvoice FromReference(string reference)
        {
            // TODO: Verify Luhn


            // Use identity as drogue chute

            string identityString = reference.Substring(12, reference.Length - 13);

            OutboundInvoice result = FromIdentity(Int32.Parse(identityString));

            if (result.Reference != reference)
            {
                throw new ArgumentException("No such outbound invoice");
            }

            return(result);
        }
예제 #7
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 =
                FromIdentityAggressive(SwarmDb.GetDatabaseForWriting()
                                       .CreatePayment(group.Identity, amountCents, string.Empty, string.Empty, string.Empty, false,
                                                      invoice.Identity));

            group.AmountCents = amountCents;

            return(newPayment);
        }
예제 #8
0
        public OutboundInvoice Credit(Person creditingPerson)
        {
            OutboundInvoice credit = Create(Organization, DateTime.Now,
                                            Budget, CustomerName,
                                            InvoiceAddressMail,
                                            InvoiceAddressPaper, Currency,
                                            Domestic, TheirReference, creditingPerson);

            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);
        }
예제 #9
0
 public static OutboundInvoiceItems ForInvoice(OutboundInvoice invoice)
 {
     return(FromArray(SwarmDb.GetDatabaseForReading().GetOutboundInvoiceItems(invoice)));
 }