Пример #1
0
        public static void CreateSalesInvoice(string compId, int companyCount, int productCount, List <Product> orderList)
        {
            salesInvoiceFeedEntry salesInvoice = new salesInvoiceFeedEntry();

            salesInvoice.salesInvoiceLines = new salesInvoiceLineFeed();
            // Find a customer to associate with the new sales invoice
            salesInvoice.tradingAccount = GetCustomer(compId, companyCount);

            if (salesInvoice.tradingAccount == null)
            {
                // No customer record means we can go no further
                Console.WriteLine("Unable to find a customer record");
                Console.ReadKey(true);
                Console.ReadLine();
                return;
            }


            foreach (Product product in orderList)
            {
                // Lookup a commodity to use on the new sales invoice
                commodityFeedEntry commodity = GetCommodity(product.Name, productCount);
                if (commodity == null)
                {
                    // No commodity record means we go no further
                    Console.WriteLine("Unable to find a commodity record");
                    Console.ReadKey(true);
                    Console.ReadLine();
                    return;
                }

                commodityFeedEntry commodityReference = new commodityFeedEntry();
                commodityReference.UUID = commodity.UUID;

                taxCodeFeedEntry taxCode = GetTaxCode();
                if (taxCode == null)
                {
                    // No record means we go no further
                    Console.WriteLine("Unable to find a tax code record");
                    Console.ReadKey(true);
                    Console.ReadLine();
                    return;
                }

                taxCodeFeedEntry taxReference = new taxCodeFeedEntry();
                taxReference.UUID     = taxCode.UUID;
                salesInvoice.taxCodes = new taxCodeFeed();
                salesInvoice.taxCodes.Entries.Add(taxReference);

                // Create a new sale invoice line using the commodity we just looked up
                salesInvoiceLineFeedEntry orderLine = new salesInvoiceLineFeedEntry();
                orderLine.type        = "Standard";
                orderLine.text        = commodity.description;
                orderLine.commodity   = commodityReference;
                orderLine.quantity    = Convert.ToDecimal(product.Quantity);
                orderLine.actualPrice = Convert.ToDecimal(product.ListPrice);
                orderLine.netTotal    = orderLine.quantity * orderLine.actualPrice;

                orderLine.taxCodes = new taxCodeFeed();
                orderLine.taxCodes.Entries.Add(taxReference);

                // Associate the lines with our invoice

                salesInvoice.salesInvoiceLines.Entries.Add(orderLine);
            }

            // Now we have constructed our new invoice we can submit it using the HTTP POST verb
            //string url = "http://localhost:5495/sdata/accounts50/GCRM/-/salesInvoices";
            //string url = "http://dewsburypc1:5495/sdata/accounts50/GCRM/-/salesInvoices";
            string   url             = dataSourceTest + "salesInvoices";
            SDataUri salesInvoiceUri = new SDataUri(url);

            SDataRequest invoiceRequest = new SDataRequest(salesInvoiceUri.Uri, salesInvoice, Sage.Integration.Messaging.Model.RequestVerb.POST);

            invoiceRequest.Username = username;
            invoiceRequest.Password = password;

            // IF successful the POST operation will provide us with a the newly created sales invoice
            salesInvoiceFeedEntry savedSalesInvoice = new salesInvoiceFeedEntry();

            invoiceRequest.RequestFeedEntry <salesInvoiceFeedEntry>(savedSalesInvoice);


            if (invoiceRequest.IsStatusValidForVerb)
            {
                Console.WriteLine(string.Format("Successfully created sales invoice {0}", savedSalesInvoice.reference));
                Console.ReadLine();
            }
            else
            {
                // There was a problem
                Console.WriteLine("Create failed. Response was {0}", invoiceRequest.HttpStatusCode.ToString());
                if (invoiceRequest.Diagnoses != null)
                {
                    foreach (Diagnosis diagnosis in invoiceRequest.Diagnoses)
                    {
                        Console.WriteLine(diagnosis.Message);
                    }
                    Console.ReadLine();
                }
            }
        }
Пример #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (textBoxPass.Text != "")
            {
                // Create a new instance of a salesInvoice
                salesInvoiceFeedEntry salesInvoice = new salesInvoiceFeedEntry();

                // Find a customer to associate with the new sales invoice
                salesInvoice.tradingAccount = GetCustomer(textBoxPass.Text);

                if (salesInvoice.tradingAccount == null)
                {
                    // No customer record means we can go no further
                    Console.WriteLine("Unable to find a customer record");
                    Console.ReadKey(true);
                    return;
                }
                // Lookup a commodity to use on the new sales invoice
                commodityFeedEntry commodity = GetCommodity(textBoxPass.Text);
                if (commodity == null)
                {
                    // No commodity record means we go no further
                    Console.WriteLine("Unable to find a commodity record");
                    Console.ReadKey(true);
                    return;
                }
                else
                {
                    MessageBox.Show("Password Correct");
                }

                commodityFeedEntry commodityReference = new commodityFeedEntry();
                commodityReference.UUID = commodity.UUID;

                // Lookup a commodity to use on the new sales invoice
                taxCodeFeedEntry taxCode = GetTaxCode(textBoxPass.Text);
                if (taxCode == null)
                {
                    // No record means we go no further
                    Console.WriteLine("Unable to find a tax code record");
                    Console.ReadKey(true);
                    return;
                }

                // Example of creating a historical invoice
                //salesInvoice.date = salesInvoice.taxDate = DateTime.UtcNow.AddDays(-2);

                // NOTE: This example omits the use of tax code for brevity.
                // Not specifying tax codes means that appropriate defaults will be used automatically.
                // However it is strongly recommended that tax codes are explicitly set to ensure expected results
                taxCodeFeedEntry taxReference = new taxCodeFeedEntry();
                taxReference.UUID = taxCode.UUID;

                salesInvoice.taxCodes = new taxCodeFeed();
                salesInvoice.taxCodes.Entries.Add(taxReference);

                salesInvoice.carrierTotalPrice = 100;
                salesInvoice.carrierTaxPrice   = 20;
                salesInvoice.carrierNetPrice   = 80;

                // Create a new sale invoice line using the commodity we just looked up
                salesInvoiceLineFeedEntry orderLine = new salesInvoiceLineFeedEntry();
                orderLine.type       = "Standard";
                orderLine.text       = commodity.description;
                orderLine.commodity  = commodityReference;
                orderLine.quantity   = 2;
                orderLine.netTotal   = 50;
                orderLine.taxTotal   = 10;
                orderLine.grossTotal = 60;
                orderLine.taxCodes   = new taxCodeFeed();
                orderLine.taxCodes.Entries.Add(taxReference);

                // Create another invoice line this time as free text
                salesInvoiceLineFeedEntry freetextOrderLine = new salesInvoiceLineFeedEntry();
                freetextOrderLine.type = "Free Text"; // Equivalent to S1 stock code
                freetextOrderLine.text = textBoxDes.Text;
                try
                {
                    freetextOrderLine.quantity = Convert.ToInt32(textBoxQuan.Text);
                    freetextOrderLine.netTotal = Convert.ToInt32(textBoxPrice.Text);
                }
                catch (FormatException fe)
                {
                    MessageBox.Show("Only Int");
                }
                freetextOrderLine.taxTotal   = 0;
                freetextOrderLine.grossTotal = 0;
                freetextOrderLine.taxCodes   = new taxCodeFeed();
                freetextOrderLine.taxCodes.Entries.Add(taxReference);


                /*
                 * // Create a 3rd invoice line this time as a message
                 * salesInvoiceLineFeedEntry messageOrderLine = new salesInvoiceLineFeedEntry();
                 * messageOrderLine.type = "Commentary"; // Equivalent to M stock code
                 * messageOrderLine.text = "A message line created via Sdata";
                 */



                // Associate the lines with our invoice
                salesInvoice.salesInvoiceLines = new salesInvoiceLineFeed();
                //   salesInvoice.salesInvoiceLines.Entries.Add(orderLine);
                salesInvoice.salesInvoiceLines.Entries.Add(freetextOrderLine);
                //   salesInvoice.salesInvoiceLines.Entries.Add(messageOrderLine);

                // Now we have constructed our new invoice we can submit it using the HTTP POST verb
                Sage.Common.Syndication.SDataUri salesInvoiceUri = new Sage.Common.Syndication.SDataUri();
                salesInvoiceUri.BuildLocalPath("Accounts50", "GCRM", "-", "salesInvoices");

                SDataRequest invoiceRequest = new SDataRequest(salesInvoiceUri.Uri, salesInvoice, Sage.Integration.Messaging.Model.RequestVerb.POST);
                invoiceRequest.Username = "******";
                invoiceRequest.Password = textBoxPass.Text;

                // IF successful the POST operation will provide us with a the newly created sales invoice
                salesInvoiceFeedEntry savedSalesInvoice = new salesInvoiceFeedEntry();
                invoiceRequest.RequestFeedEntry <salesInvoiceFeedEntry>(savedSalesInvoice);

                if (invoiceRequest.IsStatusValidForVerb)
                {
                    Console.WriteLine(string.Format("Successfully created sales invoice {0}", savedSalesInvoice.reference));
                }
                else
                {
                    // There was a problem
                    Console.WriteLine("Create failed. Response was {0}", invoiceRequest.HttpStatusCode.ToString());
                    if (invoiceRequest.Diagnoses != null)
                    {
                        foreach (Diagnosis diagnosis in invoiceRequest.Diagnoses)
                        {
                            Console.WriteLine(diagnosis.Message);
                        }
                    }
                }


                Console.WriteLine("We\'re finished!!!");

                MessageBox.Show("Successfully created sales invoice");
            }
        }