static void GetOrderById(string token, string orderId) { try { var request = CreateRequest("/rest/V1/orders/" + orderId, Method.GET, token); var response = Client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { //var data = response.Content; OrderItem result = new OrderItem(); M2SalesOrderBillingAddress addressList = new M2SalesOrderBillingAddress(); //M2Invoice invoice = JsonConvert.DeserializeObject<M2Invoice>(response.Content); M2SalesOrder order = JsonConvert.DeserializeObject <M2SalesOrder>(response.Content); addressList = order.billing_address; List <OrderItem> data = new List <OrderItem>(order.items); foreach (var item in data) { result = item; //MainForm form = new MainForm(); AddToGridByOrder(form.dgv, result, order, addressList); } } else { M2Error m2Error = JsonConvert.DeserializeObject <M2Error>(response.Content); MessageBox.Show(m2Error.message, "Error " + response.StatusCode); } } catch (Exception er) { MessageBox.Show(er.Message); } }
static void AddToGridByOrder(DataGridView grid, OrderItem item, M2SalesOrder invoice, M2SalesOrderBillingAddress billingAddress) { try { string sku = item.sku; double CGST, SGST, BASE_AMOUNT, RateBasic, DeliveryCharge, BaseDiscountAmount, LineAmount, InvoiceAmount; string IGST, TaxRate; string customerName, customerLastName; customerName = invoice.customer_firstname; customerLastName = invoice.customer_lastname; if (customerName == null) { customerName = billingAddress.firstname; customerLastName = billingAddress.lastname; } ReadFromExcelFile(sku); TaxRate = masterItem.IGST + "%"; IGST = masterItem.IGST; CGST = masterItem.CGST; SGST = masterItem.SGST; StringBuilder stringBuilder = new StringBuilder(); List <string> streets = new List <string>(billingAddress.street); foreach (var street in streets) { stringBuilder.Append(street); } BASE_AMOUNT = item.base_row_total_incl_tax; //discount amount per line BaseDiscountAmount = item.base_discount_amount; //get the base amount before tax if (BaseDiscountAmount > 0) { LineAmount = BASE_AMOUNT - BaseDiscountAmount; //line amount before tax RateBasic = LineAmount * 100 / (100 + Double.Parse(masterItem.IGST)); } else { LineAmount = BASE_AMOUNT; //line amount before tax RateBasic = BASE_AMOUNT * 100 / (100 + Double.Parse(masterItem.IGST)); } DeliveryCharge = invoice.shipping_amount; //check billing state if (billingAddress.region.Equals(STATE)) { //calculate taxe on base rate + delivery charge CGST = (RateBasic + DeliveryCharge) * CGST / 100; SGST = (RateBasic + DeliveryCharge) * SGST / 100; IGST = "0"; //invoice amount InvoiceAmount = RateBasic + DeliveryCharge + CGST + SGST; } else { CGST = 0.0; SGST = 0.0; //calculate taxe on base rate + delivery charge IGST = ((RateBasic + DeliveryCharge) * Double.Parse(masterItem.IGST) / 100).ToString("#.##"); //invoice amount InvoiceAmount = RateBasic + DeliveryCharge + Double.Parse(IGST); } //add row to data table dt.Rows.Add(invoice.increment_id, invoice.created_at, "POS Invoice", "Main Location", customerName + " " + customerLastName, stringBuilder.ToString(), "", "", "", billingAddress.country_id, billingAddress.region, "", "", "POS Sales", item.name, "", TaxRate, "", "", item.qty_ordered, "NO", item.base_price_incl_tax, RateBasic.ToString("#.##"), item.discount_percent, LineAmount, invoice.shipping_amount, CGST.ToString("#.##"), SGST.ToString("#.##"), IGST, "", InvoiceAmount.ToString("#.##"), "", "", sku); // set data grid view data source grid.DataSource = dt; grid.Columns["SKU"].Visible = false; grid.AllowUserToAddRows = false; } catch (Exception er) { MessageBox.Show(er.Message, "Error"); } }