Exemple #1
0
        public static Invoice Create(Auction Auction, Customer Customer, bool Simulate)
        {
            Invoice result = new Invoice (Customer);

            List<Item> items;

            if (Auction != null)
            {
                items = Item.List (Auction);
            }
            else
            {
                items = Item.List ();
            }

            foreach (Item item in items)
            {
                if (item.AppovedForInvoice)
                {
                    if (!item.Invoiced)
                    {
                        if (item.CurrentBid != null)
                        {
                            if (item.CurrentBid.CustomerId == Customer.Id)
                            {
                                Case _case = Case.Load (item.CaseId);
                                result._auctionids.Add (_case.AuctionId);

                                result.Lines.Add (new InvoiceLine (item));
                            }
                        }
                    }
                }
            }

            if (result.Lines.Count == 0)
            {
                // EXCEPTION: Exception.InvoiceEmpty
                throw new Exception (string.Format (Strings.Exception.InvoiceEmpty));
            }

            if (!Simulate)
            {
                foreach (InvoiceLine line in result.Lines)
                {
                    Item item = Item.Load (line.ItemId);
                    item.Invoiced = true;
                    item.Save ();
                }

                result.Save ();
            }

            return result;
        }