Ejemplo n.º 1
0
        public mlRESQtaByTdr C_SEToReServe(mlREQQtaByTdrReserve poREQQtaByTdrReserve)
        {
            var oRESQtaByTdrcs = new cResQtaByTdrcs();
            var oSql           = new StringBuilder();

            try
            {
                if (poREQQtaByTdrReserve.tML_BBYQuota == "0" || poREQQtaByTdrReserve.tML_BBYQuota == "")// กันเหนียวไว้ก่อน
                {
                    tC_ResCod  = "03";
                    tC_Message = "จำนวน Quota เกิน Limit ที่กำหนด";
                    return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
                }
                switch (poREQQtaByTdrReserve.tML_BBYQuotaType)
                {
                case "1":     //Per Bonus Buy

                    oSql = C_GEToCountTransNo(poREQQtaByTdrReserve);
                    oSql.AppendLine("GROUP BY FTScdBBYNo");
                    return(C_CHKoQuota(oSql.ToString(), poREQQtaByTdrReserve));

                case "2":     //Per Store

                    oSql = C_GEToCountTransNo(poREQQtaByTdrReserve);
                    oSql.AppendLine("AND (FTStmCode = '" + poREQQtaByTdrReserve.tML_StmCode + "')");
                    oSql.AppendLine("GROUP BY FTStmCode, FTScdBBYNo");
                    return(C_CHKoQuota(oSql.ToString(), poREQQtaByTdrReserve));

                case "3":     //per Plant

                    oSql = C_GEToCountTransNo(poREQQtaByTdrReserve);
                    oSql.AppendLine("AND (FTShdPlantCode = '" + poREQQtaByTdrReserve.tML_PlantCode + "')");
                    oSql.AppendLine("GROUP BY FTShdPlantCode, FTScdBBYNo");
                    return(C_CHKoQuota(oSql.ToString(), poREQQtaByTdrReserve));

                case "4":     //per Day

                    oSql = C_GEToCountTransNo(poREQQtaByTdrReserve);
                    oSql.AppendLine("AND (FTShdPlantCode = '" + poREQQtaByTdrReserve.tML_PlantCode + "')");
                    oSql.AppendLine("AND (DATENAME(dw, FDShdTransDate) = '" + poREQQtaByTdrReserve.tML_BBYDayName + "')");
                    oSql.AppendLine("GROUP BY FTScdBBYNo, DATENAME(dw, FDShdTransDate)");
                    return(C_CHKoQuota(oSql.ToString(), poREQQtaByTdrReserve));

                default:
                    tC_ResCod  = "44";
                    tC_Message = "ข้อมูล BBYQuotaType ไม่ถูกต้อง";
                    return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
                }
            }
            catch (Exception oEx)
            {
                tC_ResCod  = "44";
                tC_Message = "[ReServe : C_SEToReServe] Error=" + oEx.Message;
                return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
            }
        }
Ejemplo n.º 2
0
        private mlRESQtaByTdr C_CHKoQuota(string ptSql, mlREQQtaByTdrReserve poREQQtaByTdrReserve)
        {
            var oRESQtaByTdrcs = new cResQtaByTdrcs();
            var oINSQtaByTdr   = new cInsQtaByTdr();

            try
            {
                // Check Quota By Exprie
                var oTransDate = DateTime.Parse(poREQQtaByTdrReserve.tML_TransDate);
                var oStartDate = DateTime.Parse(poREQQtaByTdrReserve.tML_BBYStartDate);
                var oEndDate   = DateTime.Parse(poREQQtaByTdrReserve.tML_BBYEndDate);
                if (oTransDate < oStartDate || oTransDate > oEndDate)
                {
                    tC_ResCod  = "45";
                    tC_Message = "ไม่อยู่ในช่วงโปรโมชั่น";
                    return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
                }

                //Check Quota By Count
                var oDtQuota = cCNSP.SP_GEToDbTbl(ptSql);
                if (oDtQuota.Rows.Count != 0)
                {
                    // Count By CrdQuota
                    if (int.Parse(oDtQuota.Rows[0]["FNIDCnt"].ToString()) >= int.Parse(poREQQtaByTdrReserve.tML_CrdQuota))
                    {
                        tC_ResCod  = "03";
                        tC_Message = "CrdQuota Limit  บัตรใช้งาน ครบจำนวนแล้ว";
                        return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
                    }
                    // Count By TransNo
                    else if (int.Parse(oDtQuota.Rows[0]["FNCnt"].ToString()) >= int.Parse(poREQQtaByTdrReserve.tML_BBYQuota))
                    {
                        tC_ResCod  = "03";
                        tC_Message = "จำนวน Quota เกิน Limit";
                        return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
                    }
                    else
                    {
                        //เจอรหัสโปรโมรชั่น และยังไม่หมดโครต้า ให้ทำการจอง
                        return(oINSQtaByTdr.C_INSoTPSTSalBBYTdr(poREQQtaByTdrReserve));
                    }
                }
                else
                {
                    //ไม่เจอรหัสโปรโมรชั่น ให้ทำการจอง
                    return(oINSQtaByTdr.C_INSoTPSTSalBBYTdr(poREQQtaByTdrReserve));
                }
            }
            catch (Exception oEx)
            {
                tC_ResCod  = "44";
                tC_Message = "[ReServe : C_CHKoQuota] Error=" + oEx.Message;
                return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message));
            }
        }
Ejemplo n.º 3
0
        public string GETtReserve(string ptUrl, string ptStmCode, string ptPOSNo, string ptTransNo, string ptTransType, string ptTransDate
                                  , string ptPlantCode, string ptMcardNo, string ptMcardType, string ptBBYProfID
                                  , string ptBBYNo, string ptBBYStartDate, string ptBBYEndDate, string ptBBYQuotaType, string ptBBYDayName
                                  , string ptBBYQuota, string ptCrdQuota, string ptTdmCode, string ptTdmCardType, string ptAmtB4Disc
                                  , string ptUserName, string ptDateIns, string ptTimeIns, string ptSrcSeqNo
                                  )
        {
            try
            {
                //-----------------------------------------------Reserve------------------------------------------//
                mlREQQtaByTdrReserve oREQQtaByTdrReserve = new mlREQQtaByTdrReserve()
                {
                    tML_StmCode   = ptStmCode,
                    tML_POSNo     = ptPOSNo,
                    tML_TransNo   = ptTransNo,
                    tML_TransType = ptTransType,
                    tML_TransDate = ptTransDate,

                    tML_PlantCode = ptPlantCode,
                    tML_McardNo   = ptMcardNo,
                    tML_McardType = ptMcardType,
                    tML_BBYProfID = ptBBYProfID,

                    tML_BBYNo        = ptBBYNo,
                    tML_BBYStartDate = ptBBYStartDate,
                    tML_BBYEndDate   = ptBBYEndDate,
                    tML_BBYQuotaType = ptBBYQuotaType,
                    tML_BBYDayName   = ptBBYDayName,

                    tML_BBYQuota = ptBBYQuota,
                    tML_CrdQuota = ptCrdQuota,

                    tML_TdmCode     = ptTdmCode,
                    tML_TdmCardType = ptTdmCardType,
                    tML_AmtB4Disc   = ptAmtB4Disc,

                    tML_UserName = ptUserName,

                    tML_DateIns = ptDateIns,
                    tML_TimeIns = ptTimeIns,

                    tML_SrcSeqNo = ptSrcSeqNo
                };
                var tJson        = JsonConvert.SerializeObject(oREQQtaByTdrReserve, Formatting.Indented);
                var tResultMsg   = oC_POSTJsonToAPI.C_POSTtHTTPCliant(ptUrl + "/Reserve", tJson);
                var oRESQtaByTdr = JsonConvert.DeserializeObject <mlRESQtaByTdr>(tResultMsg);
                var tResult      = oRESQtaByTdr.tML_ResCode + "|" + oRESQtaByTdr.tML_Message + "|" + oRESQtaByTdr.tML_DateIns + "|" + oRESQtaByTdr.tML_TimeIns;
                return(tResult);
            }
            catch (Exception oEx)
            {
                throw oEx;
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult SEToPromoByTdrReserve([FromBody] mlREQQtaByTdrReserve pmlREQQtaByTdrReserve)
        {
            try
            {
                oC_Log.Debug("-------------------------------START------------------------------------");
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

                // C_CHKxMemcach();
                var oReServe = new cReServe();
                oC_RESQtaByTdrcs = new mlRESQtaByTdr();
                oC_RESQtaByTdrcs = oReServe.C_SEToReServe(pmlREQQtaByTdrReserve);
                oC_Log.Debug("-------------------------------End------------------------------------");
                return(Json(oC_RESQtaByTdrcs));
            }
            catch (Exception oEx)
            {
                return(BadRequest(oEx.Message));
            }
        }
Ejemplo n.º 5
0
        private StringBuilder C_GEToCountTransNo(mlREQQtaByTdrReserve poREQQtaByTdrReserve)
        {
            var oSql = new StringBuilder();

            try
            {
                oSql.AppendLine("SELECT COUNT(FTShdTransNo)  AS FNCnt ");
                oSql.AppendLine(",SUM (CASE WHEN ''='" + poREQQtaByTdrReserve.tML_McardNo + "' THEN 0");
                oSql.AppendLine("WHEN FTScdCardID = '" + poREQQtaByTdrReserve.tML_McardNo + "' THEN 1 ELSE 0 END) AS FNIDCnt ");
                oSql.AppendLine("FROM TPSTSalBBYTdr WITH(NOLOCK)");
                oSql.AppendLine("WHERE (FTScdBBYNo = '" + poREQQtaByTdrReserve.tML_BBYNo + "')");
                oSql.AppendLine("AND (FDShdTransDate BETWEEN '" + poREQQtaByTdrReserve.tML_BBYStartDate + "' AND '" + poREQQtaByTdrReserve.tML_BBYEndDate + "' )");
                oSql.AppendLine("AND (FTSbyStatus <> 'C')");
                return(oSql);
            }
            catch (SqlException oEx)
            {
                throw oEx;
            }
        }
Ejemplo n.º 6
0
        public mlRESQtaByTdr C_INSoTPSTSalBBYTdr(mlREQQtaByTdrReserve poREQQtaByTdrReserve)
        {
            StringBuilder     oSql           = new StringBuilder();
            cResMsgQtaByTdrcs oRESQtaByTdrcs = new cResMsgQtaByTdrcs();
            string            tC_ResCod;
            string            tC_Message;
            string            tTransStatus = "R";

            try
            {
                string tTransDate = "'" + cCNSP.DTEtByFormat(poREQQtaByTdrReserve.tML_TransDate, "YYYY-MM-DD") + "'";
                oSql.Clear();
                oSql.AppendLine("INSERT INTO TPSTSalBBYTdr WITH(ROWLOCK) (");
                oSql.AppendLine("FTStmCode");
                oSql.AppendLine(",FTTmnNum");
                oSql.AppendLine(",FTShdTransNo");
                oSql.AppendLine(",FTShdTransType");
                oSql.AppendLine(",FDShdTransDate");
                oSql.AppendLine(",FTShdPlantCode");
                oSql.AppendLine(",FTSbyStatus");
                oSql.AppendLine(",FTScdCardID");
                oSql.AppendLine(",FTMcdCardType");
                oSql.AppendLine(",FTScdBBYProfID");
                oSql.AppendLine(",FTScdBBYNo");
                oSql.AppendLine(",FTSbyQuotaType");
                oSql.AppendLine(",FTSbyDayName");
                oSql.AppendLine(",FTSbyQuota");
                oSql.AppendLine(",FNPpmCrdQuota");
                oSql.AppendLine(",FTTdmCode");
                oSql.AppendLine(",FTCdcCreditType");
                oSql.AppendLine(",FCScdAmtB4Avi");
                oSql.AppendLine(",FTWhoIns");
                oSql.AppendLine(",FDDateIns");
                oSql.AppendLine(",FTTimeIns");
                oSql.AppendLine(",FNSrcSeqNo");
                oSql.AppendLine(")VALUES(");
                oSql.AppendLine("'" + poREQQtaByTdrReserve.tML_StmCode + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_POSNo + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_TransNo + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_TransType + "'");
                oSql.AppendLine(",CONVERT(VARCHAR(10), " + tTransDate + ", 121)");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_PlantCode + "'");
                oSql.AppendLine(",'" + tTransStatus + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_McardNo + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_McardType + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_BBYProfID + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_BBYNo + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_BBYQuotaType + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_BBYDayName + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_BBYQuota + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_CrdQuota + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_TdmCode + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_TdmCardType + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_AmtB4Disc + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_UserName + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_DateIns + "'");
                oSql.AppendLine(",'" + poREQQtaByTdrReserve.tML_TimeIns + "'");
                oSql.AppendLine(",'" + int.Parse(poREQQtaByTdrReserve.tML_SrcSeqNo) + "'");
                oSql.AppendLine(")");
                int nResult = cConDbByTender.C_SETnDbTbl(oSql.ToString());
                if (nResult > 0)
                {
                    tC_ResCod  = "00";
                    tC_Message = "จองสิทธิ์ส่วนลด สำเร็จ";
                    return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message, poREQQtaByTdrReserve.tML_DateIns, poREQQtaByTdrReserve.tML_TimeIns));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (SqlException)
            {
                tC_ResCod  = "44";
                tC_Message = "จองสิทธิ์ส่วนลด ไม่สำเร็จ อาจจะมีอยู่แล้ว หรือใช้ไปแล้ว";
                return(oRESQtaByTdrcs.C_SEToRESQtaByTdr(tC_ResCod, tC_Message, poREQQtaByTdrReserve.tML_DateIns, poREQQtaByTdrReserve.tML_TimeIns));
            }
        }