Beispiel #1
0
        /// <summary>
        /// Updates asynchronously the specified invoice.
        /// </summary>
        /// <param name="entity">The invoice to update.</param>
        /// <returns>Instance of <see cref="JsonInvoice"/> class with modified entity.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public async Task <JsonInvoice> UpdateAsync(JsonInvoice entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(await base.UpdateSingleEntityAsync(string.Format("invoices/{0}.json", entity.id), entity));
        }
Beispiel #2
0
        /// <summary>
        /// Creates asynchronously the specified new invoice.
        /// </summary>
        /// <param name="entity">The new invoice.</param>
        /// <returns>ID of newly created invoice.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public async Task <int> CreateAsync(JsonInvoice entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(await base.CreateEntityAsync("invoices.json", entity));
        }
Beispiel #3
0
        /// <summary>
        /// Updates the specified invoice.
        /// </summary>
        /// <param name="entity">The invoice to update.</param>
        /// <returns>Instance of <see cref="JsonInvoice"/> class with modified entity.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public JsonInvoice Update(JsonInvoice entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(base.UpdateSingleEntity(string.Format("invoices/{0}.json", entity.id), entity));
        }
Beispiel #4
0
        /// <summary>
        /// Creates the specified new invoice.
        /// </summary>
        /// <param name="entity">The new invoice.</param>
        /// <returns>ID of newly created invoice.</returns>
        /// <exception cref="ArgumentNullException">entity</exception>
        public int Create(JsonInvoice entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(base.CreateEntity("invoices.json", entity));
        }
Beispiel #5
0
        private static void ImportInvoices()
        {
            Console.WriteLine("Importing invoices:");
            using (var dc = new InvoicingEntities()) {
                foreach (var i in dc.Invoices) {
                    // Compute invoice number
                    var invoiceNumber = string.Format("{0}01{1:00000}", i.DateTaxed.Year - 1980, i.SeqId);

                    // Map old contact ID to new
                    var subjectId = subjectIdMap[i.ContactId];
                    Console.Write("  #{0}: {1}...", i.InvoiceId, invoiceNumber);

                    // Create new invoice entity
                    var newInvoice = new JsonInvoice {
                        number = invoiceNumber,
                        subject_id = subjectId,
                        issued_on = i.DateCreated,
                        taxable_fulfillment_due = i.DateTaxed,
                        due_on = i.DateDue,
                        lines = new List<JsonInvoiceLine>()
                    };

                    // Add invoice items
                    foreach (var l in i.Items) {
                        newInvoice.lines.Add(new JsonInvoiceLine {
                            name = l.Name,
                            quantity = l.Quantity,
                            unit_name = l.Unit,
                            unit_price = l.UnitPrice,
                            vat_rate = l.Tax
                        });
                    }

                    // Create invoice
                    var newInvoiceId = context.Invoices.Create(newInvoice);
                    Console.WriteLine("OK, ID={0}", newInvoiceId);

                    // Get payment status
                    if (i.Payments.Any()) {
                        Console.Write("  #{0}: Updating payment status...", i.InvoiceId);
                        var datePaid = i.Payments.Max(x => x.DateReceived);
                        context.Invoices.SetPaymentStatus(newInvoiceId, InvoicePaymentStatus.Paid, datePaid);
                    }
                    else {
                        Console.Write("  #{0}: Updating delivery status...", i.InvoiceId);
                        context.Invoices.SendMessage(newInvoiceId, InvoiceMessageType.NoMessage);
                    }
                    Console.WriteLine("OK");
                }
            }
        }
        /// <summary>
        /// Updates the specified invoice.
        /// </summary>
        /// <param name="entity">The invoice to update.</param>
        /// <returns>Instance of <see cref="JsonInvoice"/> class with modified entity.</returns>
        /// <exception cref="System.ArgumentNullException">entity</exception>
        public JsonInvoice Update(JsonInvoice entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");

            return base.UpdateSingleEntity(string.Format("invoices/{0}.json", entity.id), entity);
        }
        /// <summary>
        /// Creates the specified new invoice.
        /// </summary>
        /// <param name="entity">The new invoice.</param>
        /// <returns>ID of newly created invoice.</returns>
        /// <exception cref="System.ArgumentNullException">entity</exception>
        public int Create(JsonInvoice entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");

            return base.CreateEntity("invoices.json", entity);
        }
Beispiel #8
0
        private static void ShowInvoices()
        {
            Console.Write("Creating new subject...");
            var subjectId = context.Subjects.Create(new JsonSubject {
                name = "ACME, s. r. o.",
                street = "Testovací 123",
                city = "Praha",
                zip = "11000",
                country = "CZ",
                registration_no = "12345678",
                vat_no = "CZ12345678",
                email = "*****@*****.**"
            });
            Console.WriteLine("OK, ID={0}", subjectId);

            Console.Write("Creating new invoice...");
            var newInvoice = new JsonInvoice {
                subject_id = subjectId,
                client_street = "Jiná ulice 123",
                lines = new List<JsonInvoiceLine>(),
            };
            newInvoice.lines.Add(new JsonInvoiceLine { name = "Položka 1", quantity = 1, unit_name = "ks", unit_price = 100, vat_rate = 21 });
            newInvoice.lines.Add(new JsonInvoiceLine { name = "Položka 2", quantity = 3, unit_name = "hod.", unit_price = 1234, vat_rate = 21 });
            var newInvoiceId = context.Invoices.Create(newInvoice);
            Console.WriteLine("OK, ID={0}", newInvoiceId);

            Console.Write("Reading back invoice information...");
            newInvoice = context.Invoices.SelectSingle(newInvoiceId);
            Console.WriteLine("OK");

            Console.Write("Sending invoice by e-mail...");
            context.Invoices.SendMessage(newInvoiceId, InvoiceMessageType.InvoiceMessage);
            Console.WriteLine("OK");

            Console.Write("Marking invoice as paid...");
            context.Invoices.SetPaymentStatus(newInvoiceId, InvoicePaymentStatus.Paid);
            Console.WriteLine("OK");

            Console.Write("Deleting invoice...");
            context.Invoices.Delete(newInvoiceId);
            Console.WriteLine("OK");

            Console.Write("Deleting subject...");
            context.Subjects.Delete(subjectId);
            Console.WriteLine("OK");
        }