예제 #1
0
        /// <summary>
        /// Get all articles that are handled by
        /// pyramid as stock articles
        /// </summary>
        /// <param name="ident"></param>
        /// <returns></returns>
        private List <OrderArtCL> getCheckoutableArticles(string artnr, int getStock)
        {
            List <OrderArtCL> orderArts = new List <OrderArtCL>();
            string            sSql      = "SELECT a.artnr,  a.artnamn, a.artikelkod "
                                          + " from artikel a "
                                          + " where a.artikelkod is not null "
                                          + " and a.kategori = 1 ";

            if (artnr != "")
            {
                sSql += " and a.artnr = :artnr ";
            }
            // sSql += " order by a.artnamn ";

            NxParameterCollection pc = new NxParameterCollection();

            if (artnr != "")
            {
                pc.Add("artnr", artnr);
            }
            string    errText = "";
            DataTable dt      = cdb.getData(sSql, ref errText, pc);

            if (errText != "")
            {
                OrderArtCL oa = new OrderArtCL();
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                oa.ErrCode    = -100;
                oa.ErrMessage = errText;
                orderArts.Add(oa);
                return(orderArts);
            }
            // 2018-05-22 KJBO
            PyramidServ.ServiceSoapClient client = new PyramidServ.ServiceSoapClient();
            foreach (DataRow dr in dt.Rows)
            {
                OrderArtCL oa = new OrderArtCL();
                oa.Artnr      = dr["artnr"].ToString();
                oa.ArtNamn    = dr["artnamn"].ToString();
                oa.Artikelkod = dr["artikelkod"].ToString();
                // 2018-05-22 KJBO
                if (getStock == 1)
                {
                    oa.Stock = getPyramidArtStock(dr["artikelkod"].ToString(), client);
                }
                orderArts.Add(oa);
            }
            client.Close();
            return(orderArts);
        }
예제 #2
0
        public OrderArtCL checkoutOrderArt(string ident, OrderArtCL oa)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            if (identOK == -1)
            {
                OrderArtCL oaRet = new OrderArtCL();
                oaRet.ErrCode    = -10;
                oaRet.ErrMessage = "Ogiltigt login";
                return(oaRet);
            }
            return(checkoutOrderArt(oa, ident, false));
        }
예제 #3
0
        /// <summary>
        /// Returns a list of ordered arts for a given order
        /// </summary>
        /// <param name="orderArtId"></param>
        /// <param name="vartOrdernr"></param>
        /// <param name="ident"></param>
        /// <returns></returns>
        public List <OrderArtCL> getOrderArt(int orderArtId, string vartOrdernr, string ident, bool getStock)
        {
            CReparator        cr        = new CReparator();
            List <OrderArtCL> orderArts = new List <OrderArtCL>();
            int identOK = cr.checkIdent(ident);

            if (identOK == -1)
            {
                OrderArtCL oa = new OrderArtCL();
                oa.ErrCode    = -10;
                oa.ErrMessage = "Ogiltigt login";
                orderArts.Add(oa);
                return(orderArts);
            }
            return(getOrderArt(orderArtId, vartOrdernr, getStock));
        }
예제 #4
0
        /// <summary>
        /// Gets one article defined by artnr
        /// Also returns stock for this article
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="artnr"></param>
        /// <returns></returns>
        public OrderArtCL getCheckoutableArticle(string ident, string artnr)
        {
            CReparator        cr        = new CReparator();
            List <OrderArtCL> orderArts = new List <OrderArtCL>();
            int identOK = cr.checkIdent(ident);

            if (identOK == -1)
            {
                OrderArtCL oa = new OrderArtCL();
                oa.ErrCode    = -10;
                oa.ErrMessage = "Ogiltigt login";
                return(oa);
            }
            orderArts = getCheckoutableArticles(artnr, 1);
            return(orderArts[0]);
        }
예제 #5
0
 private void setOaParameters(NxParameterCollection pc, OrderArtCL oa, Boolean forInsert, String AnvId)
 {
     pc.Add("coAntal", oa.CoAntal);
     if (forInsert)
     {
         pc.Add("vart_ordernr", oa.VartOrdernr);
         pc.Add("artnr", oa.Artnr);
         pc.Add("reg", AnvId);
         pc.Add("regdat", System.DateTime.Now);
     }
     else
     {
         pc.Add("orderArtId", oa.OrderArtId);
         pc.Add("uppdaterat", AnvId);
         pc.Add("uppdat_dat", System.DateTime.Now);
     }
 }
예제 #6
0
        private int validateOa(OrderArtCL oa, ref string errTxt)
        {
            List <OrderArtCL> oaList = getCheckoutableArticles(oa.Artnr, 0);

            if (oaList.Count == 0)
            {
                return(-1);
            }
            int liRc = servHuvExistsAndOpen(oa.VartOrdernr, ref errTxt);

            if (liRc == -1)
            {
                return(-2);
            }
            if (liRc == -2)
            {
                return(-3);
            }
            return(1);
        }
예제 #7
0
        private int reuseOrderArtId(OrderArtCL oa, ref decimal coAntal)
        {
            String sSql = " SELECT orderArtId, coAntal "
                          + " FROM orderArt "
                          + " where vart_ordernr = :vart_ordernr "
                          + " and artnr = :artnr ";
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("vart_ordernr", oa.VartOrdernr);
            pc.Add("artnr", oa.Artnr);
            string    error = "";
            DataTable dt    = cdb.getData(sSql, ref error, pc);

            if (dt.Rows.Count == 0)
            {
                return(0);
            }
            DataRow dr = dt.Rows[0];

            coAntal = Convert.ToDecimal(dr["coAntal"]);
            return(Convert.ToInt32(dr["orderArtId"]));
        }
예제 #8
0
        /// <summary>
        /// Returns a list of ordered arts for a given order
        /// </summary>
        /// <param name="orderArtId"></param>
        /// <param name="vartOrdernr"></param>
        /// <param name="ident"></param>
        /// <returns></returns>
        private List <OrderArtCL> getOrderArt(int orderArtId, string vartOrdernr, bool getStock)
        {
            List <OrderArtCL> orderArts = new List <OrderArtCL>();

            if (orderArtId == 0 && vartOrdernr == "")
            {
                OrderArtCL oa = new OrderArtCL();
                oa.ErrCode    = -101;
                oa.ErrMessage = "Felaktigt argument";
                orderArts.Add(oa);
                return(orderArts);
            }



            string sSql = "SELECT oa.orderArtId, oa.vart_ordernr, oa.artnr, oa.coAntal, oa.ciAntal, sum(coalesce(r.antal,0)) ordAntal, a.artnamn, a.artikelkod, coalesce(oa.tempCiAntal,0) tempCiAntal "
                          + " FROM orderArt oa "
                          + " join artikel a on oa.artnr = a.artnr "
                          + " left outer join reservdel r on (oa.vart_ordernr = r.vart_ordernr and oa.artnr = r.artnr) ";

            if (orderArtId > 0)
            {
                sSql += " where oa.orderArtId = :orderArtId ";
            }
            else
            {
                sSql += " where oa.vart_ordernr = :vart_ordernr ";
            }
            sSql += " group by oa.orderArtId, oa.vart_ordernr, oa.artnr, oa.coAntal, oa.ciAntal, a.artnamn, a.artikelkod, oa.tempCiAntal ";
            NxParameterCollection np = new NxParameterCollection();

            if (orderArtId > 0)
            {
                np.Add("orderArtId", orderArtId);
            }
            else
            {
                np.Add("vart_ordernr", vartOrdernr);
            }
            string    errText = "";
            DataTable dt      = cdb.getData(sSql, ref errText, np);

            if (errText != "")
            {
                OrderArtCL oa = new OrderArtCL();
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                oa.ErrCode    = -100;
                oa.ErrMessage = errText;
                orderArts.Add(oa);
                return(orderArts);
            }
            // 2018-05-22 KJBO
            PyramidServ.ServiceSoapClient client = new PyramidServ.ServiceSoapClient();
            foreach (DataRow dr in dt.Rows)
            {
                OrderArtCL oa = new OrderArtCL();
                oa.OrderArtId  = Convert.ToInt32(dr["orderArtId"]);
                oa.VartOrdernr = dr["vart_ordernr"].ToString();
                oa.Artnr       = dr["artnr"].ToString();
                oa.ArtNamn     = dr["artnamn"].ToString();
                oa.Artikelkod  = dr["artikelkod"].ToString();
                oa.CoAntal     = Convert.ToDecimal(dr["coAntal"]);
                oa.CiAntal     = Convert.ToDecimal(dr["ciAntal"]);
                oa.OrdAntal    = Convert.ToDecimal(dr["ordAntal"]);
                // 2018-05-02 KJBO
                oa.TempCiAntal = Convert.ToDecimal(dr["tempCiAntal"]);
                oa.Stock       = 0;
                if (getStock)
                {
                    oa.Stock = getPyramidArtStock(oa.Artikelkod, client);
                }
                orderArts.Add(oa);
            }
            client.Close();
            return(orderArts);
        }
예제 #9
0
        public OrderArtCL checkoutOrderArt(OrderArtCL oa, string id, bool acceptGodkand)
        {
            ExportToPyramid.CExportToPyramid pyExport = new ExportToPyramid.CExportToPyramid();
            string exportErr = pyExport.checkPyramidAPIAvailable();

            if (exportErr != "")
            {
                OrderArtCL oacl = new OrderArtCL();
                oacl.ErrCode    = -18250;
                oacl.ErrMessage = exportErr;
                return(oacl);
            }

            ReparatorCL rep = null;

            if (id == "")
            {
                rep       = new ReparatorCL();
                rep.AnvID = "Pyramid";
            }
            else
            {
                CReparator cr = new CReparator();
                rep = cr.getReparator(id);
            }
            // 2018-04-23 KJBO
            // Special handling due to gui limitations
            //if (oa.OrderArtId != 0 && oa.Artnr == null)
            //{
            //    oa.Artnr = getArtnrForOrderArt(oa.OrderArtId);
            //}


            if (oa.VartOrdernr == "")
            {
                OrderArtCL oaRet = new OrderArtCL();
                oaRet.ErrCode    = -103;
                oaRet.ErrMessage = "Ordernummer måste anges";
                return(oaRet);
            }

            if (oa.Artnr == "")
            {
                OrderArtCL oaRet = new OrderArtCL();
                oaRet.ErrCode    = -104;
                oaRet.ErrMessage = "Artikelnummer måste anges";
                return(oaRet);
            }


            string errTxt = "";
            int    rc     = validateOa(oa, ref errTxt);

            if (rc == -1)
            {
                OrderArtCL oaRet = new OrderArtCL();
                oaRet.ErrCode    = -106;
                oaRet.ErrMessage = "Felaktigt ordernr";
                return(oaRet);
            }

            if (rc == -2)
            {
                OrderArtCL oaRet = new OrderArtCL();
                oaRet.ErrCode = -107;
                if (errTxt == "")
                {
                    oaRet.ErrMessage = "Felaktigt ordernr";
                }
                else
                {
                    oaRet.ErrMessage = errTxt;
                }
                return(oaRet);
            }

            if (!acceptGodkand)
            {
                if (rc == -3)
                {
                    OrderArtCL oaRet = new OrderArtCL();
                    oaRet.ErrCode = -108;
                    if (errTxt == "")
                    {
                        oaRet.ErrMessage = "Ordern är godkänd. Ändringar ej tillåtna";
                    }
                    else
                    {
                        oaRet.ErrMessage = errTxt;
                    }
                    return(oaRet);
                }
            }

            string sSql = "";

            // 2018-04-30 KJBO
            if (oa.OrderArtId == 0)
            {
                decimal toBeAdded = 0;
                oa.OrderArtId = reuseOrderArtId(oa, ref toBeAdded);
                if (oa.OrderArtId != 0)
                {
                    oa.CoAntal += toBeAdded;
                }
            }
            if (oa.OrderArtId == 0)
            {
                sSql = getOaInsertSql();
            }
            else
            {
                sSql = getOaUpdateSql();
            }
            NxParameterCollection pc = new NxParameterCollection();

            setOaParameters(pc, oa, oa.OrderArtId == 0, rep.AnvID);

            int li_rc = cdb.updateData(sSql, ref errTxt, pc);

            if (errTxt != "")
            {
                OrderArtCL oaRet = new OrderArtCL();
                if (errTxt.Length > 2000)
                {
                    errTxt = errTxt.Substring(1, 2000);
                }
                oaRet.ErrCode    = -100;
                oaRet.ErrMessage = errTxt;
                return(oaRet);
            }

            if (oa.OrderArtId == 0)
            {
                sSql = "SELECT MAX(orderArtId) orderArtId FROM orderArt ";
                DataTable dt = cdb.getData(sSql, ref errTxt);


                if (errTxt != "")
                {
                    OrderArtCL oaRet = new OrderArtCL();
                    if (errTxt.Length > 2000)
                    {
                        errTxt = errTxt.Substring(1, 2000);
                    }
                    oaRet.ErrCode    = -100;
                    oaRet.ErrMessage = errTxt;
                    return(oaRet);
                }
                oa.OrderArtId = Convert.ToInt32(dt.Rows[0][0]);
            }



            List <OrderArtCL> oaList = getOrderArt(oa.OrderArtId, "");

            if (oaList.Count != 1)
            {
                OrderArtCL oaRet = new OrderArtCL();
                if (errTxt.Length > 2000)
                {
                    errTxt = errTxt.Substring(1, 2000);
                }
                oaRet.ErrCode    = -110;
                oaRet.ErrMessage = "Error when retrieving orderArt";
                return(oaRet);
            }

            ErrorCL errCl = pyExport.reserveArticle(oaList[0].OrderArtId);

            //pyExport.retryAllOrders();
            return(oaList[0]);
        }