public async Task <JsonResult> GetVendorItem([FromBody] AddPO vendor)
        {
            try
            {
                if (string.IsNullOrEmpty(vendor.ItemNo))
                {
                    return(await _purchaseLogic.SendRespose("False", "Blank Item No").ConfigureAwait(false));
                }
                JArray item_info = await _purchaseLogic.GetVendorItem(vendor).ConfigureAwait(false);

                JObject jo = item_info.Children <JObject>().FirstOrDefault(o => o["condition"] != null);
                if (jo.Value <string>("condition") == "True")
                {
                    decimal cost_per_unit, gst_percentage;
                    cost_per_unit  = jo.Value <decimal>("cost_per_unit");
                    gst_percentage = jo.Value <decimal>("gst_percentage");
                    jo.Add(new JProperty("quantity", (vendor.Quantity)));
                    jo.Add(new JProperty("amount", decimal.Round((cost_per_unit * vendor.Quantity), 2)));
                    jo.Add(new JProperty("discount", decimal.Round((jo.Value <decimal>("amount") * vendor.Discount) / 100, 2)));
                    jo.Add(new JProperty("total_amount", decimal.Round(jo.Value <decimal>("amount") - jo.Value <decimal>("discount"), 2)));
                    jo.Add(new JProperty("gst_amount", decimal.Round((jo.Value <decimal>("total_amount") * gst_percentage) / 100, 2)));
                    jo.Add(new JProperty("grand_total", decimal.Round(jo.Value <decimal>("total_amount") + jo.Value <decimal>("gst_amount"), 2)));
                    JArray response = new JArray(jo);
                    return(new JsonResult(response));
                }
                else
                {
                    return(new JsonResult(item_info));
                }
            }
            catch (Exception ee)
            {
                return(await _purchaseLogic.SendRespose("False", ee.Message).ConfigureAwait(false));
            }
        }
Exemplo n.º 2
0
        internal async Task <JArray> GetVendorItem(AddPO vendor)
        {
            SqlConnection cn = null;

            try
            {
                cn = Connection.GetConnection();
                SqlCommand smd = new SqlCommand("purchase_order_add_new_item", cn)
                {
                    CommandType = CommandType.StoredProcedure
                };

                smd.Parameters.Add("@jsonOutput", SqlDbType.NVarChar, -1).Direction = ParameterDirection.Output;
                smd.Parameters.AddWithValue("@item_no", vendor.ItemNo);
                smd.Parameters.AddWithValue("@vendor_id", vendor.VendorNo);
                // Execute the command
                await smd.ExecuteNonQueryAsync().ConfigureAwait(false);

                // Get the values
                string json = smd.Parameters["@jsonOutput"].Value.ToString();
                smd.Dispose();

                JArray arr = JArray.Parse(json);

                return(arr);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Connection.CloseConnection(ref cn);
            }
        }