예제 #1
0
파일: PurBLL.cs 프로젝트: allen660412/YRERP
        /**********  其他常用function ********/
        #region OfGetPrice
        /// <summary>
        ///
        /// </summary>
        /// <param name="pPbc01">價格條件</param>
        /// <param name="pVendor">客戶編號</param>
        /// <param name="pItem">料號</param>
        /// <param name="pUnit">單位</param>
        /// <param name="pDate">日期</param>
        /// <param name="pCurrency">幣別</param>
        /// <param name="pType">2.採購 3.收貨</param>
        /// <param name="pQty">數量</param>
        /// <param name="pTaxYN">含稅否</param>
        /// <param name="pTaxRate">稅率</param>
        /// <param name="pExRate">匯率</param>
        /// <param name="pUtaxPrice">回傳未稅價格</param>
        /// <param name="pTaxPrice">回傳含稅價格</param>
        /// <returns></returns>
        public Result OfGetPrice(string pPbc01, string pVendor, string pItem, string pUnit, DateTime?pDate, string pCurrency,
                                 string pType, decimal pQty, string pTaxYN, decimal pTaxRate, decimal pExRate,
                                 out decimal pUtaxPrice, out decimal pTaxPrice
                                 )
        {
            Result rtnResult = null;
            string sqlSelect = "";
            List <SqlParameter> sqlParmList = null;
            List <pbc_tb>       pbcList     = null;
            ica_tb  icaModel = null;
            bek_tb  bekModel = null;
            InvBLL  boInv = null;
            BasBLL  boBas = null;
            decimal tempUtaxPrice = 0, tempTaxPrice = 0, unitRate = 0;
            bool    flag = false;

            pUtaxPrice = 0; pTaxPrice = 0;
            try
            {
                rtnResult      = new Result();
                rtnResult.Key1 = pItem;
                boInv          = new InvBLL(OfGetConntion());
                boInv.TRAN     = this.TRAN;
                boBas          = new BasBLL(OfGetConntion());
                boBas.TRAN     = this.TRAN;

                pbcList = OfgetPbcList(pPbc01);
                if (pbcList == null || pbcList.Count == 0)
                {
                    rtnResult.Message = "未設定取價原則!";
                    return(rtnResult);
                }

                icaModel = boInv.OfGetIcaModel(pItem);
                if (icaModel == null)
                {
                    rtnResult.Message = "查無此料號資料!";
                    return(rtnResult);
                }

                bekModel = boBas.OfGetBekModel(pCurrency);
                if (bekModel == null)
                {
                    rtnResult.Message = "查無此幣別資料!";
                    return(rtnResult);
                }

                foreach (pbc_tb pbcModel in pbcList.OrderBy(p => p.pbc04))
                {
                    switch (pbcModel.pbc03.ToUpper())
                    {
                    case "A1":      //依料號最近市價 考量含稅否及匯率
                        tempUtaxPrice = icaModel.ica19;
                        if (pTaxYN == "Y")
                        {
                            tempTaxPrice = tempUtaxPrice * (1 + pTaxRate / 100);
                        }
                        //取得單位換算率 傳入單位與採購單位的換算率--這個適用A1跟A2
                        flag = boInv.OfGetUnitCovert(pItem, icaModel.ica08, pUnit, out unitRate);
                        if (flag == false)
                        {
                            rtnResult.Message = "取得料號換算率失敗!";
                            return(rtnResult);
                        }
                        tempUtaxPrice = tempUtaxPrice * unitRate;
                        tempTaxPrice  = tempTaxPrice * unitRate;
                        break;

                    case "A2":     //依料號最近採購價 考量含稅否及匯率
                        tempUtaxPrice = icaModel.ica18;
                        if (pTaxYN == "Y")
                        {
                            tempTaxPrice = tempUtaxPrice * (1 + pTaxRate / 100);
                        }
                        //取得單位換算率 傳入單位與採購單位的換算率--這個適用A1跟A2
                        flag = boInv.OfGetUnitCovert(pItem, icaModel.ica08, pUnit, out unitRate);
                        if (flag == false)
                        {
                            rtnResult.Message = "取得料號換算率失敗!";
                            return(rtnResult);
                        }
                        tempUtaxPrice = tempUtaxPrice * unitRate;
                        tempTaxPrice  = tempTaxPrice * unitRate;
                        break;

                    case "A3":      //依料號供應商單價
                        var pddModel = OfGetPddModel(pItem, pVendor, pCurrency);
                        if (pddModel == null)
                        {
                            continue;
                        }
                        tempUtaxPrice = pddModel.pdd09;
                        tempTaxPrice  = pddModel.pdd10;

                        //取得匯率
                        //取得單位換算率 傳入單位與採購單位的換算率--這個適用A1跟A2
                        flag = boInv.OfGetUnitCovert(pItem, pddModel.pdd12, pUnit, out unitRate);
                        if (flag == false)
                        {
                            rtnResult.Message = "取得料號換算率失敗!";
                            return(rtnResult);
                        }

                        tempUtaxPrice = tempUtaxPrice * unitRate;
                        tempTaxPrice  = tempTaxPrice * unitRate;
                        break;
                    }
                    if (pTaxYN == "Y" && tempTaxPrice == 0)
                    {
                        continue;
                    }
                    if (pTaxYN != "Y" && tempUtaxPrice == 0)
                    {
                        continue;
                    }

                    if (pbcModel.pbc03.ToUpper() == "A1" || pbcModel.pbc03.ToUpper() == "A2")
                    {
                        pUtaxPrice = tempUtaxPrice / pExRate;
                        pTaxPrice  = tempTaxPrice / pExRate;
                        pUtaxPrice = GlobalFn.Round(pUtaxPrice, bekModel.bek03);
                        pTaxPrice  = GlobalFn.Round(pTaxPrice, bekModel.bek03);
                        break;
                    }

                    if (pbcModel.pbc03.ToUpper() == "A3")  //查詢已包含幣別,所以不用考量匯率
                    {
                        pUtaxPrice = GlobalFn.Round(tempUtaxPrice, bekModel.bek03);
                        pTaxPrice  = GlobalFn.Round(tempTaxPrice, bekModel.bek03);
                        break;
                    }
                }

                rtnResult.Success = true;
                return(rtnResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        //回傳值 true.通過驗證 false.未通過驗證,會把值還原
        protected override bool WfItemCheck(object sender, ItemCheckInfo e)
        {
            int        iChkCnts    = 0;
            vw_invi102 masterModel = null;

            try
            {
                masterModel = DrMaster.ToItem <vw_invi102>();
                #region 單頭-pick vw_invi102
                if (e.Row.Table.Prefix.ToLower() == "vw_invi102")
                {
                    switch (e.Column.ToLower())
                    {
                    case "icp01":    //料號
                        if (GlobalFn.varIsNull(e.Value))
                        {
                            e.Row["icp01_c"] = "";
                            return(true);
                        }
                        var icaModel = BoInv.OfGetIcaModel(e.Value.ToString());
                        if (icaModel == null)
                        {
                            WfShowErrorMsg("查無此料號!");
                            return(false);
                        }
                        if (icaModel.icaconf != "Y")
                        {
                            WfShowErrorMsg("料號未確認!");
                            return(false);
                        }
                        if (icaModel.icavali == "N")
                        {
                            WfShowErrorMsg("此為無效料號!");
                            return(false);
                        }
                        e.Row["icp01_c"] = icaModel.ica02;
                        if (masterModel.icp02 == 0)
                        {
                            WfSetIcp02(e.Value.ToString());
                        }
                        break;

                    case "icp02":    //項次
                        if (GlobalFn.varIsNull(masterModel.icp01))
                        {
                            WfShowErrorMsg("請先輸入料號!");
                            return(false);
                        }
                        if (!GlobalFn.isNumeric(e.Value.ToString()))
                        {
                            WfShowErrorMsg("請輸入數字!");
                            return(false);
                        }
                        if (FormEditMode == YREditType.新增)
                        {
                            if (BoInv.OfChkIcpPKExists(masterModel.icp01, Convert.ToInt32(e.Value)))
                            {
                                WfShowErrorMsg("此項次已存在!");
                                return(false);
                            }
                        }
                        break;

                    case "icp06":       //預設圖片
                        if (GlobalFn.isNullRet(e.Value, "") == "Y")
                        {
                            e.Row["icp05"] = 0;
                            WfSetControlReadonly(ute_icp05, true);
                        }
                        else
                        {
                            e.Row["icp05"] = 999;
                            WfSetControlReadonly(ute_icp05, false);
                        }
                        break;
                    }
                }
                #endregion
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }