コード例 #1
0
ファイル: OutboundInvoice.cs プロジェクト: osoftware/Swarmops
        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);
        }