using CLS_BL;
using CLS_DL;
using CLS_PL;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SUNWEB
{
    public partial class SalesInvoice : System.Web.UI.Page
    {


        BL_SELECT ObjSel = new BL_SELECT();
        BLCompany ObjBL = new BLCompany();
        PLCOMMON ObjPL = new PLCOMMON();
        BL_USER ObjUserBL = new BL_USER(); //This Object for All User and Page Related fuctions included 
        PLCUSTOMER ObjCustPL = new PLCUSTOMER();
        Int32 K = 0;
        Int32 L = 0;
        Int32 S = 0;
        string ConStr = ConfigurationManager.ConnectionStrings["ConMysql"].ConnectionString;
        string ConStr_Rds = ConfigurationManager.ConnectionStrings["ConRDS"].ConnectionString;
        string Curr_Date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        string Curr_DateOnly = System.DateTime.Now.ToString("yyyy-MM-dd");
        DateTime MonthstartDt;
        DataSet ds = new DataSet();
        MYSQLDB ObjMain = new MYSQLDB();
        DataTable DT = new DataTable();
        DataTable Dt2 = new DataTable();
        DataTable DtLicense = new DataTable();
        DataTable DtSuperAdmin = new DataTable();
        DataTable DtMultiBranch = new DataTable();
        DataTable DtNormalUser = new DataTable();
        DataTable DTProductSale = new DataTable();
        MySqlCommand Cmdv = new MySqlCommand();
        // User Variables 
        string UserId = string.Empty;
        string UserName = string.Empty;
        string PortalTypeId = string.Empty;
        string cd_Id = string.Empty;
        string Datapath = string.Empty;
        string cd_BranchAlias = string.Empty;
        string IsMultiBranch = string.Empty;
        string IsSuperAdmin = string.Empty;
        string ActiveCallvalue = string.Empty;
        // License Variables ..
        string PID = string.Empty;
        string Page_Acess = string.Empty;
        string Read_Acess = string.Empty;
        string Write_Acess = string.Empty;
        string Isdowld_Acess = string.Empty;
        string Rcd_id = string.Empty;
        string RPortalid = string.Empty;
        string Useridvalue = string.Empty;
        string QueryCurr_Select = string.Empty;
        string L_MaxUserCnt = string.Empty;

        string L_SalesInvoice = string.Empty;
        string Branchidval = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;

        string HQ = string.Empty;
        string Cm_id = string.Empty;
        string ISHQ = string.Empty;
        DataSet DS = new DataSet();

        string Vw_Chk = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

            PID = "66";    // This is for SalesInvoice Page ..


            if (!IsPostBack)
            {
                txtStartDt.Text = Curr_DateOnly;
                txtEndDt.Text = Curr_DateOnly;
            }
            MonthstartDt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, 1);
            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == "") && ((Convert.ToBoolean(Session["IsMultiBranch"])) == true))
            {
                if (!IsPostBack)
                {
                    LoadBranchName4SuperAdmin();

                    string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
                    ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
                    if (ActiveCallvalue != " " || ActiveCallvalue != "Select Branch")
                    {
                        ActiveCall();
                    }
                }
            }
            else if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchName4SuperAdmin();
                }
                cd_BranchAlias = cmbBranches.SelectedItem.Text;
                //LoadInventoryListGrid(cd_BranchAlias, txtStartDt.Text, txtEndDt.Text);
            }
            else if (((Convert.ToBoolean(Session["IsMultiBranch"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchName();
                    ActiveCall();
                }
            }
            else if (((Session["PortalTypeId"].ToString() != "") || (Convert.ToBoolean(Session["IsSuperAdmin"])) == false) && ((Convert.ToBoolean(Session["IsMultiBranch"])) == false))
            {
                cmbBranches.Enabled = false;
                cmbBranches.Visible = false;

                Cm_id = ObjSel.GETcmid(Session["Cd_Id"].ToString());  // Get cm_id
                HQ = ObjSel.Get_HQ(Cm_id);     // Get the HQ Value
                Curr_BranchFullName = ObjSel.GetBranchFullName(HQ, Session["Branch_HQ"].ToString());
                lblBranchAliasName.ForeColor = System.Drawing.Color.DodgerBlue;
                lblBranchAliasName.Text = "Branch Name" + "&nbsp;" + "-" + "&nbsp;" + Curr_BranchFullName + "&nbsp; ";

                cd_BranchAlias = Session["Branch_HQ"].ToString();
                Datapath = Session["DataPath"].ToString();
                PortalTypeId = Session["PortalTypeId"].ToString();

                DT = ObjUserBL.GetPageRightsDetailsPid(Session["UserId"].ToString(), PID);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }
                if ((Session["L_SalesInvoice"].ToString() == "N") || (Session["Page_Acess"].ToString() == "N"))
                {
                    Response.Redirect("DeniedPage.aspx");
                }
                else
                {
                    // lblMsgTotalSelection.Text = "Item Sale  Between" + "&nbsp;&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  and  &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                    if (!IsPostBack)
                    {
                        if (Session["Isdowld_Acess"].ToString() == "N")
                        {
                            // btnExcel.Enabled = false;
                            Response.Write(@"<script language='javascript'>alert('No Access To download.')</script>");
                        }
                        else
                        {
                            btnGetReports.Visible = true;

                            if (cmbBranches.Visible == false)
                            {
                                //  BindGridview(Session["Branch_HQ"].ToString(), txtStartDt.Text, txtEndDt.Text);
                            }

                        }


                    }

                }

            }
            else
            {

            }


        }

        public void ActiveCall()
        {
            string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
            ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
            if (ActiveCallvalue == "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            }


            ISHQ = ObjMain.ExecuteScalar("select BranchName from " + ActiveCallvalue + ".branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 

            if (ISHQ != "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
                UPDATEBRANCH(ActiveCallvalue);
            }

            cd_BranchAlias = ActiveCallvalue;
            Curr_BranchFullName = ObjUserBL.GetBranchCurr_BranchVal(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), cd_BranchAlias);
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
            cmbBranches.Items.FindByText(Curr_BranchFullName).Selected = true;
            Branchidval = ObjUserBL.GetBranchIDbyName(ActiveCallvalue, ActiveCallvalue);
            DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Branchidval);
            if (DT.Rows.Count > 0)
            {
                Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                Session["Page_Acess"] = Page_Acess;
                Session["Read_Acess"] = Read_Acess;
                Session["Write_Acess"] = Write_Acess;
                Session["Isdowld_Acess"] = Isdowld_Acess;
            }
            Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + ActiveCallvalue + "';");
            RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
            DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);
            if (DtLicense.Rows.Count > 0)
            {


                L_SalesInvoice = DtLicense.Rows[0]["SALESINVOICE"].ToString();
                Session["L_SalesInvoice"] = L_SalesInvoice;
            }
            if (Session["L_SalesInvoice"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                Response.Redirect("DeniedPage.aspx");
            }
            else
            {

                //btnExcel.Enabled = true;
                //lblMsgTotalSelection.Text = "Total Sale Selection Between" + "&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                cd_BranchAlias = cmbBranches.SelectedItem.Text;
                // BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);
                System.Threading.Thread.Sleep(2000);

            }
            Session["selecteddb"] = ActiveCallvalue;

        }

        public void LoadBranchName()
        {
            DtNormalUser = ObjUserBL.GetBranchOnLoginValues8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtNormalUser.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtNormalUser;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }

        public void LoadBranchName4SuperAdmin()
        {
            DtSuperAdmin = ObjUserBL.GetBranchOnSuperAdmin8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtSuperAdmin.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtSuperAdmin;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }

        public void UPDATEBRANCH(string ActiveCallvalue)
        {
            if (!string.IsNullOrEmpty(Session["UserId"] as string))
            {
                Useridvalue = Session["UserId"].ToString();
                QueryCurr_Select = "Update portaldb.usermaster set ActiveValue='" + ActiveCallvalue + "' where Userid=" + Useridvalue + "";
                S = ObjMain.ExecuteNonQuery(QueryCurr_Select);
            }
            else
            {
                Response.Redirect("Login.aspx");

            }

        }

        protected void btnGetReports_Click(object sender, EventArgs e)
        {

        }

        protected void cmbBranches_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (cmbBranches.SelectedIndex == 0)
            {
                Response.Write("GroupSale.aspx");
            }
            else
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, cmbBranches.SelectedItem.Value);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();
                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }
                // Get the BranchAlias Name 
                BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                cd_BranchAlias = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + cd_BranchAlias + "';");
                RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
                DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);
                if (DtLicense.Rows.Count > 0)
                {
                    L_SalesInvoice = DtLicense.Rows[0]["SALESINVOICE"].ToString();
                    Session["L_SalesInvoice"] = L_SalesInvoice;

                }
                if (Session["L_SalesInvoice"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
                {
                    Response.Redirect("DeniedPage.aspx");
                }
                else
                {
                    #region Write(Button click ) & download rights ...

                    if (Session["Write_Acess"].ToString() == "N")
                    {
                        
                    }
                    if (Session["Isdowld_Acess"].ToString() == "N")
                    {
                        

                    }
                    #endregion


                    // XSS Prevention
                    string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtStartDt.Text);
                    string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtEndDt.Text);

                    //btnExcel.Enabled = true;
                    //lblMsgTotalSelection.Text = "Group Sales Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                    BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    cd_BranchAlias = Cmb_BranchName;
                  
                }
            }
            UPDATEBRANCH(cd_BranchAlias);

        }

        [WebMethod]
        public static string getInventories()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_Inventories(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string getCategories()
        {
            HttpContext context = HttpContext.Current;
           string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_Categories(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string getInventoryCostAverage()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_InventoryCostAverage(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string getInventoryCostAverageDetail()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_InventoryCostAverageDetail(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string POST_SITransaction(string jsondata)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();

            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            
            bearertoken = objAPI.GetBarerToken();
            string json = objAPI.POST_SITransaction(bearertoken, db, jsondata);
            //var obj = JsonConvert.DeserializeObject(json);
            //return obj.ToString();
            return json;
        }

        [WebMethod]
        public static string POST_SITranspayment( string jsondata)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();

            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();

            string json = objAPI.POST_SITranspyment(bearertoken, db, jsondata);
            //var obj = JsonConvert.DeserializeObject(json);
            //return obj.ToString();
            return json;
        }

        
        [WebMethod]
        public static string PUT_SITrans( string jsondata)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();

            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            string json = objAPI.PUT_SITrans(bearertoken, db, jsondata);
            return json;
        }

        [WebMethod]
        public static string GET_LASTSITrans()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_LASTSITrans(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string GET_AllTax()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_AllTax(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string GET_AllCustomer()
        {
            HttpContext context = HttpContext.Current;
            //string db = context.Session["selecteddb"].ToString();
            string db = "dahq";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.iCRM_GetAllCustomer(db, bearertoken);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string GetDecryptedValues(string cipertext)
        {
            HttpContext context = HttpContext.Current;
            BL_API ObjApi = new BL_API();           
            try
            {
                string _keyvalue = "SUNTOYOSUNTOYOSU";
                string _ciphertext = cipertext;
                var JSONData =
                "{" +

                    "\"cipherText\":\"" + _ciphertext + "\"," +
                    "\"key\":\"" + _keyvalue + "\"" +
                "}";

                string bearerToken = ObjApi.GetBarerToken();
                string jsonResult = ObjApi.API_POSTCALL_GET_DECRYPTED(bearerToken, JSONData);
                var sObject = JsonConvert.DeserializeObject(jsonResult);
                return sObject.ToString();
            }
            catch (Exception ex)
            {
                return "false";
            }
        }

        [WebMethod]
        public static string GET_AllPaymentType()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_AllPaymentType(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string GET_LASTSITranspayment()
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.GET_LASTSITranspayment(bearertoken, db);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string GET_SITranspayment_by_TranID(int transid)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.Get_SITranspayment_By_TransID(bearertoken, db,transid);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }


        [WebMethod]
        public static string DELETE_SITransbyTransid(int transid)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.DELETE_SITransbyTransID(bearertoken, db, transid);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string DELETE_SITransdetailbyTransid(int transid)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.DELETE_SITransdetailbyTransID(bearertoken, db,transid);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string DELETE_SITranspaymentbyTransid(int transid)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            //string db = "da1";
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.DELETE_SITranspaymentbyTransID(bearertoken, db, transid);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

        [WebMethod]
        public static string POST_SITransdetailCosting(string jsondata)
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            bearertoken = objAPI.GetBarerToken();
            string json = objAPI.POST_SITransDetailCosting(bearertoken, db, jsondata);            
            return json;
        }

        [WebMethod]
        public static string POST_InventoryCostAverageDetail(string jsondata)
        {
            HttpContext context = HttpContext.Current;
            //string db = context.Session["selecteddb"].ToString();
            BL_API objAPI = new BL_API();
            string bearertoken = string.Empty;
            string db = context.Session["selecteddb"].ToString();
            bearertoken = objAPI.GetBarerToken();
            string JSONResult = objAPI.POST_InventoryCostAverageDetail(bearertoken, db, jsondata);
            var sObject = JsonConvert.DeserializeObject(JSONResult);
            return sObject.ToString();
        }

    }
}