示例#1
0
        static void GetOrderByDate(string token, string order_date, string status, string date_condetion)
        {
            try
            {
                string searchCiretia = $"/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=created_at&searchCriteria[filter_groups][0][filters][0][value]={order_date} 00:00:00&searchCriteria[filter_groups][0][filters][0][condition_type]={date_condetion}&searchCriteria[filter_groups][1][filters][1][field]=status&searchCriteria[filter_groups][1][filters][1][value]=%25{status}%25&searchCriteria[filter_groups][1][filters][1][condition_type]=like";
                var    request       = CreateRequest(searchCiretia, Method.GET, token);
                var    response      = Client.Execute(request);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    //var data =  response.Content;
                    M2OrderItem result = new M2OrderItem();
                    M2OrderByDateBillingAddress addressList         = new M2OrderByDateBillingAddress();
                    M2OrderByDatesItems         m2OrderByDatesItems = new M2OrderByDatesItems();

                    string content = response.Content;

                    M2OrderByDates order = JsonConvert.DeserializeObject <M2OrderByDates>(content);
                    //check the total order
                    if (order.total_count == 0)
                    {
                        MessageBox.Show("Sorry no data found", "No Record");
                    }
                    else
                    {
                        List <M2OrderByDatesItems> datas = new List <M2OrderByDatesItems>(order.items);

                        foreach (var data in datas)
                        {
                            List <M2OrderItem> items = new List <M2OrderItem>(data.items);
                            addressList         = data.billing_address;
                            m2OrderByDatesItems = data;


                            foreach (var item in items)
                            {
                                AddToGridByDate(form.dgv, item, m2OrderByDatesItems, addressList);
                            }
                        }
                    }
                }
                else
                {
                    M2Error m2Error = JsonConvert.DeserializeObject <M2Error>(response.Content);
                    MessageBox.Show(m2Error.message, "Error " + response.StatusCode);
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
        }
示例#2
0
        static void AddToGridByDate(DataGridView grid, M2OrderItem item, M2OrderByDatesItems invoice, M2OrderByDateBillingAddress 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;
                    SGST = 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");
            }
        }