public void DeleteInvoice(Invoice invoice)
        {
            if ((invoice.EntityState == EntityState.Detached))
                this.ObjectContext.Invoices.Attach(invoice);

            this.ObjectContext.Invoices.DeleteObject(invoice);
        }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            var currentBusinessAccount = CurrentBusinessAccount.Get<BusinessAccount>(context);

            var currentRouteTask = CurrentBusinessAccount.Get<RouteTask>(context);

            var invoice = new Invoice();
        }
 public void InsertInvoice(Invoice invoice)
 {
     if ((invoice.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(invoice, EntityState.Added);
     }
     else
     {
         this.ObjectContext.Invoices.AddObject(invoice);
     }
 }
        public Invoice MakeChild()
        {
            var invoiceChild = new Invoice
                                   {
                                       DueDate = this.DueDate,
                                       FixedScheduleOptionInt = this.FixedScheduleOptionInt,
                                       Memo = this.Memo,
                                       RelativeScheduleDays = this.RelativeScheduleDays,
                                       ScheduleModeInt = this.ScheduleModeInt,
                                       BillToLocation = this.BillToLocation,
                                       SalesTerm = this.SalesTerm
                                   };

            return invoiceChild;
        }
Beispiel #5
0
        /// <summary>
        /// Adds the item to the table only if the item does not already exist in the table.
        /// If it does exist, the method will update that item to the current details
        /// </summary>
        /// <param name="currentInvoice">The current invoice.</param>
        /// <param name="newItem">The new item to add to the table.</param>
        public static void AddUpdateToTable(Invoice currentInvoice, InvoiceTableDataModel newItem)
        {
            //Check that this DataConnectionString is right
            var storageAccount =
                CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));

            var serviceContext = new InvoiceTableDataServiceContext(storageAccount.TableEndpoint.ToString(),
                                                                    storageAccount.Credentials);

            // Create the table if there is not already a table with the name of the Business Account
            storageAccount.CreateCloudTableClient().CreateTableIfNotExist(currentInvoice.BusinessAccount.Name);

            //Query that checks to see if and object with the same InvoiceId exists in the Table specified
            var existsQuery = serviceContext.CreateQuery<InvoiceTableDataModel>(currentInvoice.BusinessAccount.Name).Where(
                e => e.InvoiceId == newItem.InvoiceId);

            //Gets the first and hopefully only item in the Table that matches
            var existingObject = existsQuery.FirstOrDefault();

            //If an item doesnt exist yet, add that object
            if (existingObject == null)
            {
                //Adds the new object to the Table
                serviceContext.AddObject(currentInvoice.BusinessAccount.Name, newItem);
            }
            //If an item exists already, update the item and save the changes
            else
            {
                //No need to update the InvoiceId becuase it should be the same
                //Update the change type becuase it could change from Update to Delete or vicea versa
                existingObject.ChangeType = newItem.ChangeType;

                serviceContext.UpdateObject(existingObject);
            }

            //Saves the Tables
            serviceContext.SaveChanges();
        }
Beispiel #6
0
        /// <summary>
        /// Makes a call to the QuickBooks Online Data Services to delete the specified invoice
        /// </summary>
        /// <param name="currentBusinessAccount">The current business account.</param>
        /// <param name="currentInvoice">The current invoice.</param>
        public static void DeleteInvoice(BusinessAccount currentBusinessAccount, Invoice currentInvoice)
        {
            var quickBooksSession = SerializationTools.Deserialize<QuickBooksSession>(currentBusinessAccount.QuickBooksSessionXml);

            //URL for the QuickBooks DataService for getting the deleting an Invoice
            //Here we are accessing QuickBooks Online data
            var serviceEndPoint = String.Format(quickBooksSession.BaseUrl + @"/resource/invoice/v2/" + quickBooksSession.RealmId + "/" + currentInvoice.CustomerId + "?methodx=delete");

            var oSession = CreateOAuthSessionAndAccessToken(currentBusinessAccount);

            //Sets up the Post Request bus does not actually send it out
            IConsumerRequest consumerRequest = oSession.Request();
            consumerRequest = consumerRequest.ForMethod("POST");
            consumerRequest = consumerRequest.ForUri(new Uri(serviceEndPoint));

            #region Generates the XML body of the Post call

            var filter = "Name=" + ":EQUALS:" + currentInvoice.Client.Name;

            var clientXML = GetEntityList(currentBusinessAccount, "customers", filter);

            var clientId = "";

            //Splits the response XML into by line
            string[] responseArray = clientXML.Split('<');

            //Checks each line for the one containing the BaseURL
            foreach (string s in responseArray)
            {
                if (s.Contains(":Id>"))
                {
                    responseArray = s.Split('>');
                    clientId = responseArray[1];
                    break;
                }
            }

            var body = QuickBooksXml.InvoiceXml(currentInvoice, clientId, Operation.Delete);

            #endregion

            //Signs the Request
            consumerRequest = consumerRequest.SignWithToken();

            //Sends the request with the body attached
            consumerRequest.Post().WithRawContentType("application/xml").WithRawContent(Encoding.ASCII.GetBytes((string)body));

            //Reads the response XML
            var responseString = consumerRequest.ReadBody();
        }
 public void UpdateInvoice(Invoice currentInvoice)
 {
     this.ObjectContext.Invoices.AttachAsModified(currentInvoice);
 }
Beispiel #8
0
        /// <summary>
        /// Invoices the XML.
        /// </summary>
        /// <param name="invoice">The invoice.</param>
        /// <param name="clientId">The client id.</param>
        /// <param name="operation">The enum representation of the operation.</param>
        /// <returns></returns>
        public static string InvoiceXml(Invoice invoice, string clientId, Operation operation)
        {
            return QuickBooksElementXml("Invoice", (writer, builder) =>
            {
                #region Additions for Update & Delete

                if (operation == Operation.Update || operation == Operation.Delete)
                {
                    //Customer Id and SyncToken are required for Updates and Deletes

                    writer.CreateElement("Id", invoice.CustomerId, "idDomain", "QBO");
                    writer.CreateElement("SyncToken", invoice.SyncToken);

                    //No more is necessary, return the Delete XML
                    if (operation == Operation.Delete)
                        return;

                    writer.CreateElement("CreateTime", invoice.CreateTime);
                    writer.CreateElement("LastUpdatedTime", invoice.LastUpdatedTime);
                }

                #endregion

                #region Header

                writer.WriteElement("Header", () =>
                {
                    writer.CreateElement("Msg", invoice.Memo);

                    writer.CreateElement("CustomerId", clientId, "idDomain", "QBO");

                    writer.WriteElement("BillAddr", () =>
                    {
                        writer.CreateElement("Line1", invoice.BillToLocation.AddressLineOne);

                        writer.CreateElement("Line2", invoice.BillToLocation.AddressLineTwo);

                        writer.CreateElement("City", invoice.BillToLocation.AdminDistrictTwo);

                        writer.CreateElement("CountrySubDivisionCode", invoice.BillToLocation.AdminDistrictOne);

                        writer.CreateElement("ZipCode", invoice.BillToLocation.PostalCode);
                    });

                    //writer.CreateElement("SalesTermId", invoiceToCreate.BillToLocation.AdminDistrictTwo);
                    //writer.CreateElement("DueDate", invoiceToCreate.DueDate.ToString());
                });

                #endregion

                //Add the line items
                #region Line Items

                foreach (var item in invoice.LineItems)
                {
                    writer.WriteElement("Line", () =>
                    {
                        writer.CreateElement("Desc", item.Description);
                        writer.CreateElement("Amount", item.Amount);
                    });
                }

                #endregion
            });
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Invoices EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToInvoices(Invoice invoice)
 {
     base.AddObject("Invoices", invoice);
 }
 /// <summary>
 /// Create a new Invoice object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="scheduleModeInt">Initial value of the ScheduleModeInt property.</param>
 public static Invoice CreateInvoice(global::System.Guid id, global::System.Int32 scheduleModeInt)
 {
     Invoice invoice = new Invoice();
     invoice.Id = id;
     invoice.ScheduleModeInt = scheduleModeInt;
     return invoice;
 }