/// <summary>
        /// Set All information of ReturnDetails in Return Detail Table.
        /// </summary>
        /// <param name="ReturnTblID">
        /// pass ReturnID as parameter.
        /// </param>
        /// <param name="SKUNumber">
        /// SKUNumber Pass String as Parameter.
        /// </param>
        /// <param name="ProductName">
        /// String Productname as Parameter.
        /// </param>
        /// <param name="DeliveredQty">
        /// int DeliveredQTY as parameter.
        /// </param>
        /// <param name="ExpectedQty">
        /// int Expected Qty as Parameter.
        /// </param>
        /// <param name="ReturnQty">
        /// int ReturnQty as Parameter.
        /// </param>
        /// <param name="TK"></param>
        /// <param name="CreatedBy">
        /// User Guid pass as paeameter.means Createdby.
        /// </param>
        /// <returns>
        /// Return Guid ReturnDetails.
        /// </returns>
        public Guid SetReturnDetailTbl(Guid ReturnTblID, String SKUNumber, String ProductName, int DeliveredQty, int ExpectedQty, int ReturnQty, string TK, Guid CreatedBy)
        {
            Guid _ReturnID = Guid.Empty;

            try
            {
                ReturnDetail TblReturnDetails = new ReturnDetail();

                TblReturnDetails.ReturnDetailID = Guid.NewGuid();
                TblReturnDetails.ReturnID       = ReturnTblID;
                TblReturnDetails.SKUNumber      = SKUNumber;
                TblReturnDetails.ProductName    = ProductName;
                TblReturnDetails.DeliveredQty   = DeliveredQty;
                TblReturnDetails.ExpectedQty    = ExpectedQty;
                TblReturnDetails.TCLCOD_0       = TK;
                TblReturnDetails.ReturnQty      = ReturnQty;
                TblReturnDetails.ProductStatus  = 0;
                TblReturnDetails.CreatedBy      = CreatedBy;
                TblReturnDetails.CreatedDate    = DateTime.UtcNow;
                TblReturnDetails.UpadatedDate   = DateTime.UtcNow;
                TblReturnDetails.UpdatedBy      = CreatedBy;

                //On Success of transaction.
                if (cRetutnDetailsTbl.UpdateReturnDetail(TblReturnDetails))
                {
                    _ReturnID = TblReturnDetails.ReturnDetailID;
                }
            }
            catch (Exception)
            {
            }
            return(_ReturnID);
        }
 public ActionResult AddItems(Guid id, string ids)
 {
     try
     {
         PackageReturn model = db.PackageReturns.Find(id);
         foreach (var item in ids.Split(','))
         {
             var          trackingDetail = db.TrackingDetails.Find(Guid.Parse(item));
             ReturnDetail detail         = new ReturnDetail()
             {
                 CreatedAt        = DateTime.Now,
                 CreatedBy        = user.Staff.UserName,
                 Id               = Guid.NewGuid(),
                 PackageReturnId  = model.Id,
                 StoregeJPId      = trackingDetail.StoregeJPId,
                 TrackingSubCode  = trackingDetail.TrackingSubCode,
                 Weigh            = trackingDetail.Weigh,
                 TrackingDetailId = trackingDetail.Id,
                 Size             = trackingDetail.Size,
                 UpdatedAt        = DateTime.Now,
                 UpdatedBy        = user.Staff.UserName
             };
             db.ReturnDetails.Add(detail);
         }
         db.SaveChanges();
         return(Json(new { message = "Xử lý dữ liệu thành công !", status = true }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex) { return(Json(new { message = "Đã xảy ra lỗi trong quá trình xử lý dữ liệu", status = false }, JsonRequestBehavior.AllowGet)); }
 }
Example #3
0
        public int InsertReturnDetails(ReturnItem model)
        {
            Mapper.CreateMap <ReturnItem, ReturnDetail>();
            ReturnDetail objReturnItem = Mapper.Map <ReturnDetail>(model);

            DbContext.ReturnDetails.Add(objReturnItem);
            return(DbContext.SaveChanges());
        }
        /// <summary>
        /// List Of ReturnDetails.
        /// </summary>
        /// <param name="lsReturn">
        /// list of Return information.
        /// </param>
        /// <returns>
        /// Retrurn List Of ReturnDetails.
        /// </returns>

        public List <ReturnDetail> ReturnAllRowsfromReturnTbl(List <Return> lsReturn)
        {
            List <ReturnDetail> lsReD = new List <ReturnDetail>();

            try
            {
                var ReturnDetais = from rm in lsReturn
                                   join Rd in Obj.Rcall.ReturnDetailAll()
                                   on rm.ReturnID equals Rd.ReturnID
                                   select new
                {
                    Rd.ReturnDetailID,
                    Rd.ReturnID,
                    Rd.SKUNumber,
                    Rd.ProductName,
                    Rd.TCLCOD_0,
                    Rd.DeliveredQty,
                    Rd.ExpectedQty,
                    Rd.ReturnQty,
                    Rd.ProductStatus,
                    Rd.CreatedBy,
                    Rd.UpdatedBy,
                    Rd.CreatedDate,
                    Rd.UpadatedDate,
                    Rd.RGADROWID
                };


                foreach (var ReturnDetails in ReturnDetais)
                {
                    ReturnDetail Rd1 = new ReturnDetail();
                    Rd1.ReturnDetailID = ReturnDetails.ReturnDetailID;
                    Rd1.ReturnID       = ReturnDetails.ReturnID;
                    Rd1.SKUNumber      = ReturnDetails.SKUNumber;
                    Rd1.ProductName    = ReturnDetails.ProductName;
                    Rd1.TCLCOD_0       = ReturnDetails.TCLCOD_0;
                    Rd1.DeliveredQty   = (int)ReturnDetails.DeliveredQty;
                    Rd1.ExpectedQty    = (int)ReturnDetails.ExpectedQty;
                    Rd1.ReturnQty      = (int)ReturnDetails.ReturnQty;
                    Rd1.ProductStatus  = (int)ReturnDetails.ProductStatus;
                    Rd1.CreatedBy      = (Guid)ReturnDetails.CreatedBy;
                    Rd1.UpdatedBy      = (Guid)ReturnDetails.UpdatedBy;
                    Rd1.CreatedDate    = (DateTime)ReturnDetails.CreatedDate;
                    Rd1.UpadatedDate   = (DateTime)ReturnDetails.UpadatedDate;
                    Rd1.RGADROWID      = ReturnDetails.RGADROWID;
                    lsReD.Add(Rd1);
                }
            }
            catch (Exception)
            { }

            return(lsReD);
        }
Example #5
0
        public int Update(ReturnItem model)
        {
            ReturnDetail objIssue = DbContext.ReturnDetails.SingleOrDefault(m => m.ReId == model.ReId);

            objIssue.ItemId        = model.ItemId;
            objIssue.ReturnableAmt = model.ReturnableAmt;
            objIssue.Qty           = model.Qty;
            objIssue.ReDate        = model.ReDate;
            objIssue.ItemId        = model.ItemId;
            objIssue.EmpId         = model.EmpId;
            objIssue.UpdatedDate   = System.DateTime.Now;
            return(DbContext.SaveChanges());
        }
        /// <summary>
        /// Update returndetail Table information.
        /// </summary>
        /// <param name="_lsreturn">
        /// pass return object as parameter.
        /// </param>
        /// <returns>
        /// return Bolean
        /// </returns>
        public Boolean UpdateReturnDetail(ReturnDetail _lsreturndetail)
        {
            Boolean _flag = false;

            try
            {
                _flag = Service.SetRMA.ReturnDetails(_lsreturndetail.ConvertToSaveDTO(_lsreturndetail));
            }
            catch (Exception)
            {
            }
            return(_flag);
        }
Example #7
0
        public Guid SetReturnDetailTbl(Guid ReturnDetailsID, Guid ReturnTblID, String SKUNumber, String ProductName, int DeliveredQty, int ExpectedQty, int ReturnQty, string TK, Guid CreatedBy, string SKU_Status, int SKU_Reason_Total_Points, int IsScanned, int IsManually, int NewItemQty, int SKU_Qty_Seq, string ProductID, decimal SalesPrice, int LineType, int ShipmentLines, int ReturnLines)
        {
            Guid _ReturnID = Guid.Empty;

            try
            {
                ReturnDetail TblReturnDetails = new ReturnDetail();

                TblReturnDetails.ReturnDetailID = ReturnDetailsID;
                TblReturnDetails.ReturnID       = ReturnTblID;
                TblReturnDetails.SKUNumber      = SKUNumber;
                TblReturnDetails.ProductName    = ProductName;
                TblReturnDetails.DeliveredQty   = DeliveredQty;
                TblReturnDetails.ExpectedQty    = ExpectedQty;
                TblReturnDetails.TCLCOD_0       = TK;
                TblReturnDetails.ReturnQty      = ReturnQty;
                TblReturnDetails.ProductStatus  = 0;
                TblReturnDetails.CreatedBy      = CreatedBy;
                TblReturnDetails.CreatedDate    = DateTime.UtcNow;
                TblReturnDetails.UpadatedDate   = DateTime.UtcNow;
                TblReturnDetails.UpdatedBy      = CreatedBy;

                TblReturnDetails.SKU_Status = SKU_Status;
                TblReturnDetails.SKU_Reason_Total_Points = SKU_Reason_Total_Points;

                TblReturnDetails.IsSkuScanned    = IsScanned;
                TblReturnDetails.IsManuallyAdded = IsManually;

                TblReturnDetails.SKU_Sequence = NewItemQty;
                TblReturnDetails.SKU_Qty_Seq  = SKU_Qty_Seq;

                TblReturnDetails.SalesPrice = SalesPrice;
                TblReturnDetails.ProductID  = ProductID;

                TblReturnDetails.LineType = LineType;

                TblReturnDetails.ReturnLines   = ReturnLines;
                TblReturnDetails.ShipmentLines = ShipmentLines;

                //On Success of transaction.
                if (cRetutnDetailsTbl.UpsetReturnDetail(TblReturnDetails))
                {
                    _ReturnID = TblReturnDetails.ReturnDetailID;
                }
            }
            catch (Exception ex)
            {
                ex.LogThis("mReturnDetails/SetReturnDetailTbl");
            }
            return(_ReturnID);
        }
Example #8
0
        /// <summary>
        /// Upsert record in to ReturnDetail table of RMASYSTEM database.
        /// </summary>
        /// <param name="ReturnDetailsObj">
        /// Return table object to be add or update in to the database.
        /// </param>
        /// <returns>
        /// Boolean value true if transaction is success.
        /// otherwise false if transaction is fail.
        /// </returns>
        public Boolean UpsetReturnDetail(ReturnDetail ReturnDetailsObj)
        {
            Boolean _returnFlag = false;

            try
            {
                _returnFlag = Service.entSave.ReturnDetails(ReturnDetailsObj.ConvertToSaveDTO(ReturnDetailsObj));
            }
            catch (Exception ex)
            {
                ex.LogThis("cmdReturnDetail/UpsetReturnDetail");
            }
            return(_returnFlag);
        }
        ///

        //end

        public Guid SetReturnDetailNewInsertTbl(Guid _lsreturndetail, Guid ReturnTblID, String SKUNumber, String ProductName, int ReturnQty, Guid CreatedBy, string SKU_Status, int SKU_Reason_Total_Points, int IsScanned, int Manually, int NewItemQty, int SKU_Qty_Seq, string ProductID, decimal SalesPrice, int LineType, int ShipmentLines, int ReturnLines)
        {
            Return _lsreturn    = new Return();
            Guid   returndetail = Guid.Empty;

            try
            {
                ReturnDetail TblReturnDetails = new ReturnDetail();

                TblReturnDetails.ReturnDetailID = Guid.NewGuid();
                TblReturnDetails.ReturnID       = ReturnTblID;
                TblReturnDetails.SKUNumber      = SKUNumber;
                TblReturnDetails.ProductName    = ProductName;
                TblReturnDetails.DeliveredQty   = 0;
                TblReturnDetails.ExpectedQty    = 0;
                TblReturnDetails.TCLCOD_0       = "";
                TblReturnDetails.SKU_Qty_Seq    = ReturnQty;
                TblReturnDetails.ProductStatus  = 0;
                TblReturnDetails.CreatedBy      = CreatedBy;
                TblReturnDetails.CreatedDate    = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Eastern Standard Time");
                TblReturnDetails.UpadatedDate   = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Eastern Standard Time");
                TblReturnDetails.UpdatedBy      = CreatedBy;

                TblReturnDetails.SKU_Status = SKU_Status;
                TblReturnDetails.SKU_Reason_Total_Points = SKU_Reason_Total_Points;
                TblReturnDetails.IsSkuScanned            = IsScanned;
                TblReturnDetails.IsManuallyAdded         = Manually;

                TblReturnDetails.SKU_Sequence = NewItemQty;
                TblReturnDetails.SKU_Qty_Seq  = ReturnQty;

                TblReturnDetails.SalesPrice = SalesPrice;
                TblReturnDetails.ProductID  = ProductID;

                TblReturnDetails.LineType = LineType;

                TblReturnDetails.ShipmentLines = ShipmentLines;
                TblReturnDetails.ReturnLines   = ReturnLines;

                if (Obj.Rcall.UpsetReturnDetails(TblReturnDetails))
                {
                    returndetail = TblReturnDetails.ReturnDetailID;
                }
            }
            catch (Exception)
            {
            }
            return(returndetail);
        }
Example #10
0
        /// <summary>
        /// 获取可退换商品列表
        /// </summary>
        /// <param name="stockOutSysNo">出库单编号</param>
        /// <returns>可退换商品列表</returns>
        /// <remarks>2013-09-12 周唐炬 添加注释</remarks>
        public Result <ReturnDetail> GetReturnInfo(string stockOutSysNo)
        {
            ReturnDetail returnDetail = null;
            var          status       = true;

            try
            {
                returnDetail = BLL.Warehouse.WhWarehouseBo.Instance.GetReturnInfo(int.Parse(stockOutSysNo));
            }
            catch (Exception)
            {
                status = false;
            }

            return(new Result <ReturnDetail>
            {
                Data = returnDetail,
                Status = status
            });
        }
        public static ReturnDetail GetReturnData(string id, string hdReturnType)
        {
            var data = new ReturnDetail();

            using (SqlConnection conn = new SqlConnection(SPlanetUtil.GetConnectionString()))
            {
                //Create array of Parameters
                List <SqlParameter> arrParm = new List <SqlParameter>
                {
                    new SqlParameter("@id", SqlDbType.Int)
                    {
                        Value = Convert.ToInt32(id)
                    },
                    new SqlParameter("@search_name", SqlDbType.VarChar, 200)
                    {
                        Value = ""
                    },
                    new SqlParameter("@return_type", SqlDbType.VarChar, 200)
                    {
                        Value = hdReturnType == "" ? "" :hdReturnType
                    }
                };
                conn.Open();
                var dsReturnData = SqlHelper.ExecuteDataset(conn, "sp_return_header_list", arrParm.ToArray());
                conn.Close();

                if (dsReturnData.Tables.Count > 0)
                {
                    if (dsReturnData.Tables[0].Rows.Count > 0)
                    {
                        var row = (from t in dsReturnData.Tables[0].AsEnumerable() select t).FirstOrDefault();
                        if (row != null)
                        {
                            data.return_no = Convert.IsDBNull(row["return_no"]) ? string.Empty : Convert.ToString(row["return_no"]);
                        }
                    }
                }
            }

            return(data);
        }
Example #12
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgProducts.SelectedRows.Count > 0)
                {
                    ReturnDetail oReturnDetail = dgProducts.SelectedRows[0].Tag as ReturnDetail;
                    //numGrundTotal.Value = numGrundTotal.Value + (decimal)oReturnDetail.UTAmount;
                    if (oReturnDetail.ReturnDetailsID > 0)
                    {
                        if (_RemoveReturnDetail == null)
                        {
                            _RemoveReturnDetail = new List <ReturnDetail>();
                        }
                        _RemoveReturnDetail.Add(oReturnDetail);
                        _ReturnDetails.Remove(oReturnDetail);
                    }
                    else
                    {
                        _ReturnDetails.Remove(oReturnDetail);
                    }
                    _Return.GrandTotal  = (decimal)(numGrundTotal.Value - oReturnDetail.UTAmount);
                    numGrundTotal.Value = (decimal)_Return.GrandTotal;
                    numTotal.Value      = (decimal)_Return.GrandTotal;
                    // RefreshValue();
                    RefreshGrid();
                }
                else
                {
                    MessageBox.Show("select an item to remove", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
Example #13
0
        private async Task EditionModeToggle()
        {
            if (_editionMode)
            {
                EditBtn.Text = "Editar";
                CleanForm();
            }
            else
            {
                _entityToEdit = await _returnDetail.Get(GetIdCurrentRow());

                EditBtn.Text = "Cancelar";

                commentTxt.Text       = _entityToEdit.Comment;
                dpDate.Value          = _entityToEdit.Date;
                cbStatus.SelectedItem = _entityToEdit.Status;
            }

            DeleteBtn.Enabled      = !DeleteBtn.Enabled;
            rentDataGrid.Enabled   = !rentDataGrid.Enabled;
            returnDataGrid.Enabled = !returnDataGrid.Enabled;

            _editionMode = !_editionMode;
        }
Example #14
0
 public Boolean UpsetReturnDetails(ReturnDetail ReturnDtls)
 {
     return(_cReturnDetail.UpdateReturnDetail(ReturnDtls));
 }
 public bool UpdateReturnDetail(ReturnDetail returnDetail)
 {
     _unitOfWork.ReturnDetailRepository.Update(returnDetail);
     _unitOfWork.SaveChanges();
     return(true);
 }
 public void InsertReturnDetail(ReturnDetail returnDetail)
 {
     _unitOfWork.ReturnDetailRepository.Add(returnDetail);
     _unitOfWork.SaveChanges();
 }
Example #17
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsAddToOrderValid())
                {
                    return;
                }

                var oProduct = db.Products.FirstOrDefault(i => i.ProductID == _StockControl.ProductID);

                if (oProduct.ProductType == (int)EnumProductType.BarCode || oProduct.ProductType == (int)EnumProductType.SerialNo)
                {
                    _Return.GrandTotal   = (decimal)(numGrundTotal.Value + numUTotal.Value);
                    numGrundTotal.Value  = (decimal)_Return.GrandTotal;
                    numTotal.Value       = (decimal)_Return.GrandTotal;
                    numTotalDueAmt.Value = numTotal.Value - numPaid.Value;
                    #region Return Details
                    _ReturnDetail           = new ReturnDetail();
                    _ReturnDetail.ProductID = _StockControl.ProductID;//Item
                    _ReturnDetail.UnitPrice = (decimal)numUnitPrice.Value;
                    _ReturnDetail.Quantity  = (decimal)numQTY.Value;
                    _ReturnDetail.UTAmount  = (decimal)numUTotal.Value;
                    _ReturnDetail.SDetailID = _StockDetailControl.SDetailID;
                    _ReturnDetails.Add(_ReturnDetail);
                    #endregion
                }
                else
                {
                    var SuppProductsales = (from so in db.POrders
                                            join sod in db.POrderDetails on so.POrderID equals sod.POrderID
                                            join std in db.StockDetails on sod.POrderDetailID equals std.POrderDetailID
                                            where so.SupplierID == ctlSupplier.SelectedID && so.Status == (int)EnumSalesType.Sales &&
                                            std.StockID == _StockControl.StockID
                                            select new
                    {
                        std.SDetailID,
                        so.POrderID,
                        so.OrderDate,
                        SalesPrice = sod.UnitPrice - sod.PPDISAmt,
                        std.Quantity,
                        sod.ProductID,
                        sod.POrderDetailID
                    }).OrderBy(o => o.SDetailID).ToList();

                    decimal returnQty = numQTY.Value, UTotalAmt = 0;

                    foreach (var item in SuppProductsales)
                    {
                        _ReturnDetail           = new ReturnDetail();
                        _ReturnDetail.ProductID = _StockControl.ProductID;//Item

                        if (item.Quantity == returnQty)
                        {
                            _ReturnDetail.Quantity  = returnQty;
                            _ReturnDetail.UTAmount  = numUnitPrice.Value * returnQty; //item.SalesPrice * returnQty;
                            _ReturnDetail.UnitPrice = numUnitPrice.Value;             //item.SalesPrice;
                            _ReturnDetail.SDetailID = item.SDetailID;                 // _StockControl.StockDetails.FirstOrDefault(i => i.POrderDetailID == item.POrderDetailID).SDetailID;//item.StockDetailID;
                            _ReturnDetails.Add(_ReturnDetail);
                            UTotalAmt += (decimal)_ReturnDetail.UTAmount;
                            break;
                        }
                        else if (item.Quantity > returnQty)
                        {
                            _ReturnDetail.Quantity = returnQty;

                            _ReturnDetail.Quantity  = returnQty;
                            _ReturnDetail.UTAmount  = numUnitPrice.Value * returnQty; //item.SalesPrice * returnQty;
                            _ReturnDetail.UnitPrice = numUnitPrice.Value;             //item.SalesPrice;
                            _ReturnDetail.SDetailID = item.SDetailID;                 //  _StockControl.StockDetails.FirstOrDefault(i => i.POrderDetailID == item.POrderDetailID).SDetailID;//item.StockDetailID;

                            _ReturnDetails.Add(_ReturnDetail);
                            UTotalAmt += (decimal)_ReturnDetail.UTAmount;

                            break;
                        }
                        else if (item.Quantity < returnQty)
                        {
                            _ReturnDetail.Quantity  = item.Quantity;
                            _ReturnDetail.UTAmount  = numUnitPrice.Value * item.Quantity; //item.SalesPrice * item.Quantity;
                            _ReturnDetail.UnitPrice = numUnitPrice.Value;                 //item.SalesPrice;
                            _ReturnDetail.SDetailID = item.SDetailID;                     // _StockControl.StockDetails.FirstOrDefault(i => i.POrderDetailID == item.POrderDetailID).SDetailID;//item.StockDetailID;
                            returnQty = returnQty - item.Quantity;
                            _ReturnDetails.Add(_ReturnDetail);

                            UTotalAmt += (decimal)_ReturnDetail.UTAmount;
                        }
                    }

                    _Return.GrandTotal  = (decimal)(numGrundTotal.Value + UTotalAmt);
                    numGrundTotal.Value = (decimal)_Return.GrandTotal;
                    numTotal.Value      = (decimal)_Return.GrandTotal;
                    //numPaid.Value = (decimal)_Return.GrandTotal;
                    numTotalDueAmt.Value = numTotal.Value - numPaid.Value;
                }

                RefreshGrid();
                RefreshControl();
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
Example #18
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                #region validation check

                if (numQTY.Value > numSalesQty.Value)
                {
                    MessageBox.Show("Return quantity can not be greater than sales quantity !", "Product Name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    numQTY.Focus();
                    return;
                }

                ReturnDetail op = null;
                op = _ReturnDetails.FirstOrDefault(o => o.ProductID == _StockControl.ProductID && o.SDetailID == _StockControl.ColorID);

                if (op != null)
                {
                    MessageBox.Show("You have already selected this item", "Product Name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ctlProduct.Focus();
                    return;
                }

                if (ctlCustomer.SelectedID == 0)
                {
                    MessageBox.Show("Select Customer Name.", "Customer Name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ctlCustomer.Focus();
                    return;
                }

                if (ctlProduct.SelectedID == 0)
                {
                    MessageBox.Show("Select Product Name.", "Product Name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ctlProduct.Focus();
                    return;
                }

                if (numQTY.Value <= 0)
                {
                    MessageBox.Show("Please enter product quantity.", "Quantity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    numQTY.Focus();
                    return;
                }

                if (numUnitPrice.Value <= 0)
                {
                    MessageBox.Show("Please enter Unit Price.", "Unit Price", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    numUnitPrice.Focus();
                    return;
                }

                #endregion

                var oProduct = db.Products.FirstOrDefault(i => i.ProductID == _StockControl.ProductID);
                if (oProduct.ProductType == (int)EnumProductType.BarCode || oProduct.ProductType == (int)EnumProductType.SerialNo)
                {
                    _Return.GrandTotal  = (decimal)(numGrundTotal.Value + numUTotal.Value);
                    numGrundTotal.Value = (decimal)_Return.GrandTotal;
                    numTotal.Value      = (decimal)_Return.GrandTotal;
                    //numPaid.Value = (decimal)_Return.GrandTotal;
                    numTotalDueAmt.Value = numTotal.Value - numPaid.Value;
                    #region Return Details
                    _ReturnDetail           = new ReturnDetail();
                    _ReturnDetail.ProductID = _StockControl.ProductID;//Item
                    _ReturnDetail.UnitPrice = (decimal)numUnitPrice.Value;
                    _ReturnDetail.Quantity  = (decimal)numQTY.Value;
                    _ReturnDetail.UTAmount  = (decimal)numUTotal.Value;
                    _ReturnDetail.SDetailID = _StockDetailControl.SDetailID;
                    _ReturnDetails.Add(_ReturnDetail);
                    #endregion
                }
                else
                {
                    var CustProductsales = (from so in db.SOrders
                                            join sod in db.SOrderDetails on so.SOrderID equals sod.SOrderID
                                            where so.CustomerID == ctlCustomer.SelectedID && so.Status == (int)EnumSalesType.Sales && sod.ProductID == _StockControl.ProductID && sod.StockDetailID == _StockDetailControl.SDetailID
                                            select new
                    {
                        so.SOrderID,
                        so.InvoiceDate,
                        SalesPrice = sod.UnitPrice - sod.PPDAmount,
                        sod.Quantity,
                        sod.ProductID,
                        sod.StockDetailID,
                    }).OrderByDescending(i => i.InvoiceDate).ToList();

                    decimal returnQty = numQTY.Value, UTotalAmt = 0;

                    foreach (var item in CustProductsales)
                    {
                        _ReturnDetail           = new ReturnDetail();
                        _ReturnDetail.ProductID = _StockControl.ProductID;//Item

                        if (item.Quantity == returnQty)
                        {
                            _ReturnDetail.Quantity  = returnQty;
                            _ReturnDetail.UTAmount  = numUnitPrice.Value * returnQty; //item.SalesPrice * returnQty;
                            _ReturnDetail.UnitPrice = numUnitPrice.Value;             //item.SalesPrice;
                            _ReturnDetail.SDetailID = item.StockDetailID;
                            _ReturnDetails.Add(_ReturnDetail);
                            UTotalAmt += (decimal)_ReturnDetail.UTAmount;
                            break;
                        }
                        else if (item.Quantity > returnQty)
                        {
                            _ReturnDetail.Quantity = returnQty;

                            _ReturnDetail.Quantity  = returnQty;
                            _ReturnDetail.UTAmount  = numUnitPrice.Value * returnQty; //item.SalesPrice * returnQty;
                            _ReturnDetail.UnitPrice = numUnitPrice.Value;             //item.SalesPrice;
                            _ReturnDetail.SDetailID = item.StockDetailID;

                            _ReturnDetails.Add(_ReturnDetail);
                            UTotalAmt += (decimal)_ReturnDetail.UTAmount;

                            break;
                        }
                        else if (item.Quantity < returnQty)
                        {
                            _ReturnDetail.Quantity  = item.Quantity;
                            _ReturnDetail.UTAmount  = numUnitPrice.Value * item.Quantity; //item.SalesPrice * item.Quantity;
                            _ReturnDetail.UnitPrice = numUnitPrice.Value;                 //item.SalesPrice;
                            _ReturnDetail.SDetailID = item.StockDetailID;
                            returnQty = returnQty - item.Quantity;
                            _ReturnDetails.Add(_ReturnDetail);

                            UTotalAmt += (decimal)_ReturnDetail.UTAmount;
                        }
                    }

                    _Return.GrandTotal  = (decimal)(numGrundTotal.Value + UTotalAmt);
                    numGrundTotal.Value = (decimal)_Return.GrandTotal;
                    numTotal.Value      = (decimal)_Return.GrandTotal;
                    //numPaid.Value = (decimal)_Return.GrandTotal;
                    numTotalDueAmt.Value = numTotal.Value - numPaid.Value;
                }

                RefreshGrid();
                RefreshControl();
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }