public GeneralResponse DeleteCreditSaleDetail(DeleteRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            CreditSaleDetail creditSaleDetail = new CreditSaleDetail();

            creditSaleDetail = _creditSaleDetailRepository.FindBy(request.ID);

            if (creditSaleDetail != null)
            {
                try
                {
                    _creditSaleDetailRepository.Remove(creditSaleDetail);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }

            return(response);
        }
        public GeneralResponse EditCreditSaleDetail(EditCreditSaleDetailRequest request)
        {
            GeneralResponse  response         = new GeneralResponse();
            CreditSaleDetail creditSaleDetail = new CreditSaleDetail();

            creditSaleDetail = _creditSaleDetailRepository.FindBy(request.ID);

            if (creditSaleDetail != null)
            {
                try
                {
                    creditSaleDetail.ModifiedDate     = PersianDateTime.Now;
                    creditSaleDetail.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (creditSaleDetail.CreditService.ID != request.CreditServiceID)
                    {
                        creditSaleDetail.CreditService = this._creditServiceRepository.FindBy(request.CreditServiceID);
                    }
                    creditSaleDetail.Discount   = request.Discount;
                    creditSaleDetail.Imposition = request.Imposition;
                    creditSaleDetail.UnitPrice  = request.UnitPrice;

                    if (creditSaleDetail.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        creditSaleDetail.RowVersion += 1;
                    }

                    if (creditSaleDetail.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in creditSaleDetail.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    _creditSaleDetailRepository.Save(creditSaleDetail);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }
        private CreditSaleDetail PrepareCreditSaleDetail(AddCreditSaleDetailRequest request)
        {
            CreditSaleDetail response = new CreditSaleDetail();

            CreditSaleDetail creditSaleDetail = new CreditSaleDetail();

            creditSaleDetail.ID             = Guid.NewGuid();
            creditSaleDetail.CreateDate     = PersianDateTime.Now;
            creditSaleDetail.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
            creditSaleDetail.CreditService  = this._creditServiceRepository.FindBy(request.CreditServiceID);
            creditSaleDetail.Discount       = request.Discount;
            creditSaleDetail.Imposition     = request.Imposition;
            creditSaleDetail.UnitPrice      = request.UnitPrice;
            creditSaleDetail.Units          = request.Units;
            creditSaleDetail.RowVersion     = 1;

            return(response);
        }
        public GetCreditSaleDetailResponse GetCreditSaleDetail(GetRequest request)
        {
            GetCreditSaleDetailResponse response = new GetCreditSaleDetailResponse();

            try
            {
                CreditSaleDetail creditSaleDetail = new CreditSaleDetail();
                //CreditSaleDetailView creditSaleDetailView = creditSaleDetail.ConvertToCreditSaleDetailView();

                creditSaleDetail = _creditSaleDetailRepository.FindBy(request.ID);
                if (creditSaleDetail != null)
                {
                    CreditSaleDetailView creditSaleDetailView = creditSaleDetail.ConvertToCreditSaleDetailView();

                    response.CreditSaleDetailView = creditSaleDetailView;
                }
            }
            catch (Exception ex)
            {
            }

            return(response);
        }
        //public GetGeneralResponse<IEnumerable<GetSaleDetailReportView>> GetSaleReport(SaleReportRequest request)
        //{
        //    GetGeneralResponse<IEnumerable<GetSaleDetailReportView>> response = new GetGeneralResponse<IEnumerable<GetSaleDetailReportView>>();

        //    IQueryable<CreditSaleDetail> query = _creditSaleDetailRepository.Queryable();


        //    if (request.SaleEmployeeID != null )
        //        query = query.Where(x => request.SaleEmployeeID.Contains(x.Sale.CreateEmployee.ID));

        //    if (request.DeliverEmployeeID != null )
        //        query = query.Where(x => request.DeliverEmployeeID.Contains(x.DeliverEmployee.ID));

        //    if (request.RollBackEmployeeID != null )
        //        query = query.Where(x => request.RollBackEmployeeID.Contains(x.CreateEmployee.ID)).Where(x=>x.IsRollbackDetail);

        //    if (request.Networks != null)
        //    {
        //        query = query.Where(x => request.Networks.Contains(x.CreditService.Network.ID));
        //    }

        //    if (request.CreditService != null)
        //    {
        //        query = query.Where(x => request.Products.Contains(x.CreditService.ID));
        //    }

        //    //if (request.SaleStartDate != null)
        //    //{

        //    //    query = query.Where(w => string.Compare(w.Sale.CloseDate.Substring(0, 10), request.SaleStartDate) >= 0);
        //    //}
        //    //if (request.SaleEndDate != null)
        //    //{
        //    //    query = query.Where(w => (string.Compare(w.Sale.CloseDate.Substring(0, 10), request.SaleEndDate) < 0));
        //    //}
        //    if (request.RollBackStartDate != null)
        //    {

        //    }
        //    if (request.RollBackEndDate != null)
        //    {

        //    }
        //    if (request.Deliverd != null)
        //    {
        //        query = query.Where(x => x.Delivered == false);
        //    }
        //    if (request.Confirmed != null)
        //    {
        //        query = query.Where(x => x.Sale.Closed == request.Confirmed);
        //    }

        //    if (request.RollBacked != null)
        //    {
        //        query = query.Where(x => x.Rollbacked == request.RollBacked);
        //    }

        //    IEnumerable<CreditSaleDetail> creditSaleDetail = query.ToList();

        //    IList<GetSaleDetailReportView> Report = new List<GetSaleDetailReportView>();
        //    foreach (CreditSaleDetail _creditSaleDetail in creditSaleDetail)
        //    {
        //        GetSaleDetailReportView item = new GetSaleDetailReportView();

        //        item.ADSLPhone = _creditSaleDetail.Sale.Customer.ADSLPhone;
        //        item.CenterName = _creditSaleDetail.Sale.Customer.Center == null ? "" : _creditSaleDetail.Sale.Customer.Center.CenterName;
        //        item.DeliverDate = _creditSaleDetail.DeliverDate;
        //        item.DeliverEmployeeName = _creditSaleDetail.DeliverEmployee == null ? "" : (string)_creditSaleDetail.DeliverEmployee.Name;
        //        item.Discount = _creditSaleDetail.LineDiscount;
        //        item.Imposition = _creditSaleDetail.LineImposition;
        //        item.Name = _creditSaleDetail.Sale.Customer.Name;
        //        item.Price = _creditSaleDetail.UnitPrice;
        //        item.Count = _creditSaleDetail.Units;
        //        item.CreditServiceName = _creditSaleDetail.CreditService.ServiceName;

        //        #region Get Network
        //        CreditService creditService = _creditServiceRepository.FindBy(_creditSaleDetail.CreditService.ID);
        //        item.NetworkName = creditService.Network.NetworkName;
        //        #endregion

        //        item.RollBackEmployeeName = _creditSaleDetail.ModifiedEmployee == null ? "" : (string)_creditSaleDetail.ModifiedEmployee.Name;
        //        item.RollBackPrice = _creditSaleDetail.RollbackPrice;
        //        item.RoolBackDate = _creditSaleDetail.ModifiedDate;
        //        item.SaleDate = _creditSaleDetail.Sale.CloseDate;
        //        item.Total = _creditSaleDetail.LineTotal;
        //        item.TotalRollBack = _creditSaleDetail.Units;
        //        item.SaleDate = _creditSaleDetail.Sale.CreateDate;
        //        item.SaleEmployeeName = _creditSaleDetail.CreateEmployee.Name;



        //        Report.Add(item);
        //    }

        //    response.data = Report;
        //    response.totalCount = Report.Count();

        //    return response;

        //}

        #endregion

        #region sale Report New

        public GetGeneralResponse <IEnumerable <GetSaleDetailReportView> > GetSaleReport(IList <FilterData> filters)
        {
            GetGeneralResponse <IEnumerable <GetSaleDetailReportView> > response = new GetGeneralResponse <IEnumerable <GetSaleDetailReportView> >();

            string query = FilterUtilityService.GenerateFilterHQLQuery(filters, "CreditSaleDetail", null);

            Response <CreditSaleDetail> creditSaleDetail = _creditSaleDetailRepository.FindAll(query);

            IList <GetSaleDetailReportView> Report = new List <GetSaleDetailReportView>();

            foreach (CreditSaleDetail _creditSaleDetail in creditSaleDetail.data)
            {
                GetSaleDetailReportView item = new GetSaleDetailReportView();
                item.ADSLPhone   = _creditSaleDetail.Sale.Customer.ADSLPhone;
                item.NetworkName = _creditSaleDetail.CreditService.Network.NetworkName;
                item.CenterName  = _creditSaleDetail.Sale.Customer.Center == null
                    ? ""
                    : _creditSaleDetail.Sale.Customer.Center.CenterName;
                item.Name = _creditSaleDetail.Sale.Customer.Name;
                item.CreditServiceName = _creditSaleDetail.CreditService.ServiceName;
                item.BonusDate         = _creditSaleDetail.BonusDate;
                item.ComissionDate     = _creditSaleDetail.ComissionDate;
                if (_creditSaleDetail.IsRollbackDetail)
                {
                    item.Bonus     = _creditSaleDetail.Bonus;
                    item.Comission = _creditSaleDetail.Comission;

                    item.DeliverDate         = _creditSaleDetail.MainSaleDetail.DeliverDate;
                    item.DeliverEmployeeName = _creditSaleDetail.MainSaleDetail.DeliverEmployee == null
                        ? ""
                        : (string)_creditSaleDetail.MainSaleDetail.DeliverEmployee.Name;
                    item.Discount             = _creditSaleDetail.MainSaleDetail.LineDiscount;
                    item.Imposition           = _creditSaleDetail.MainSaleDetail.LineImposition;
                    item.Price                = _creditSaleDetail.MainSaleDetail.UnitPrice;
                    item.Count                = _creditSaleDetail.MainSaleDetail.Units;
                    item.RollBackEmployeeName = _creditSaleDetail.CreateEmployee.Name;
                    item.RollBackPrice        = _creditSaleDetail.RollbackPrice;
                    item.RoolBackDate         = _creditSaleDetail.CreateDate;
                    item.SaleDate             = _creditSaleDetail.MainSaleDetail.CreateDate;
                    item.Total                = _creditSaleDetail.LineTotal;
                    item.TotalRollBack        = _creditSaleDetail.Units;
                    item.SaleEmployeeName     = _creditSaleDetail.MainSaleDetail.CreateEmployee.Name;
                }
                else
                {
                    item.Bonus     = _creditSaleDetail.Bonus;
                    item.Comission = _creditSaleDetail.Comission;

                    item.DeliverDate         = _creditSaleDetail.DeliverDate;
                    item.DeliverEmployeeName = _creditSaleDetail.DeliverEmployee == null
                        ? ""
                        : (string)_creditSaleDetail.DeliverEmployee.Name;
                    item.Discount         = _creditSaleDetail.LineDiscount;
                    item.Imposition       = _creditSaleDetail.LineImposition;
                    item.Price            = _creditSaleDetail.UnitPrice;
                    item.Count            = _creditSaleDetail.Units;
                    item.SaleDate         = _creditSaleDetail.CreateDate;
                    item.Total            = _creditSaleDetail.LineTotal;
                    item.SaleEmployeeName = _creditSaleDetail.CreateEmployee.Name;
                    item.CustomerID       = _creditSaleDetail.Sale.Customer.ID;


                    if (_creditSaleDetail.Rollbacked)
                    {
                        Infrastructure.Querying.Query q = new Query();
                        Criterion crt = new Criterion("MainSaleDetail.ID", _creditSaleDetail.ID, CriteriaOperator.Equal);
                        q.Add(crt);
                        CreditSaleDetail RollbakedCreditSaleDetail = _creditSaleDetailRepository.FindBy(q).FirstOrDefault();
                        if (RollbakedCreditSaleDetail != null)
                        {
                            item.RollBackEmployeeName = RollbakedCreditSaleDetail.CreateEmployee.Name;
                            item.RollBackPrice        = RollbakedCreditSaleDetail.LineTotal;
                            item.RoolBackDate         = RollbakedCreditSaleDetail.CreateDate;
                            item.TotalRollBack        = RollbakedCreditSaleDetail.Units;
                        }
                    }
                }


                Report.Add(item);
            }

            var temp = Report.Sum(x => x.Total);

            response.data       = Report;
            response.totalCount = Report.Count();

            return(response);
        }
示例#6
0
 public static CreditSaleDetailView ConvertToCreditSaleDetailView(this CreditSaleDetail creditSaleDetail)
 {
     return(Mapper.Map <CreditSaleDetail, CreditSaleDetailView>(creditSaleDetail));
 }
示例#7
0
        private CheckConditionResponse CheckLevelCondition(Level newLevel, Customer customer)
        {
            IEnumerable <Condition> conditions = newLevel.Conditions;
            CheckConditionResponse  response   = new CheckConditionResponse();

            Infrastructure.Querying.Query query = new Infrastructure.Querying.Query();
            Criterion criteria = new Criterion("Customer.ID", customer.ID, CriteriaOperator.Equal);

            query.Add(criteria);
            IEnumerable <Sale> sales = _saleRepository.FindBy(query);

            response.CanEnter = true;

            foreach (Condition condition in conditions)
            {
                // اگر کوئری از نوع هایبرنیت باشد
                if (condition.nHibernate)
                {
                    bool canEnter = _customerRepository.CheckCondition(condition, newLevel, customer);
                    response.CanEnter = response.CanEnter & canEnter;

                    if (!canEnter)
                    {
                        response.ErrorMessages.Add(condition.ErrorText);
                    }
                }
                // اگر کوئری از نوع هایبرنیت نباشد
                else
                {
                    // StatusIsAdameEmkan
                    // وضعیت مرکز تحت پوشش باشد
                    if (condition.QueryText == "CenterStatusIsSupport")
                    {
                        response.CanEnter = customer.Center.StatusKey == "Support" ? true : false;
                        response.ErrorMessages.Add(condition.ErrorText);
                    }
                    // وضعیت مرکز تحت پوشش نباشد
                    if (condition.QueryText == "StatusIsNotSupport")
                    {
                        response.CanEnter = customer.Center.StatusKey == "NotSupport" ? true : false;
                        response.ErrorMessages.Add(condition.ErrorText);
                    }
                    // وضعیت مرکز عدم امکان موقت باشد
                    if (condition.QueryText == "StatusIsAdameEmkan")
                    {
                        response.CanEnter = customer.Center.StatusKey == "AdameEmkan" ? true : false;
                        response.ErrorMessages.Add(condition.ErrorText);
                    }
                    // کالا تحویل نشده نداشته باشد و یا برگشت شده باشد
                    if (condition.QueryText == "HasNoUndeliveredProductsOrAllRollbacked")
                    {
                        foreach (var sale in sales)
                        {
                            foreach (var saleDetail in sale.ProductSaleDetails)
                            {
                                // تحویل نشده ی برگشت نشده فالس است
                                if (!saleDetail.Delivered && !saleDetail.Rollbacked && !saleDetail.IsRollbackDetail)
                                {
                                    response.CanEnter = false;
                                }
                            }
                            //foreach (var saleDetail in sale.CreditSaleDetails)
                            //{
                            //    // تحویل نشده ی برگشت نشده فالس است
                            //    if (!saleDetail.Delivered && !saleDetail.Rollbacked && !saleDetail.IsRollbackDetail)
                            //    {
                            //        response.CanEnter = false;

                            //    }
                            //}
                            //foreach (var saleDetail in sale.UncreditSaleDetails)
                            //{
                            //    // تحویل نشده ی برگشت نشده فالس است
                            //    if (!saleDetail.Delivered && !saleDetail.Rollbacked && !saleDetail.IsRollbackDetail)
                            //    {
                            //        response.CanEnter = false;

                            //    }
                            //}

                            response.ErrorMessages.Add(condition.ErrorText);
                        }
                    }
                    // خدمات اعتباری تحویل نشده نداشته باشد و یا برگشت شده باشد
                    else if (condition.QueryText == "HasNoUndeliveredCreditOrAllRollbacked")
                    {
                        foreach (var sale in sales)
                        {
                            foreach (var saleDetail in sale.CreditSaleDetails)
                            {
                                // تحویل نشده ی برگشت نشده فالس است
                                if (!saleDetail.Delivered && !saleDetail.Rollbacked && !saleDetail.IsRollbackDetail)
                                {
                                    response.CanEnter = false;
                                    response.ErrorMessages.Add(condition.ErrorText);
                                }
                            }
                        }
                    }
                    // خدمات غیر اعتباری تحویل نشده نداشته باشد و یا برگشت شده باشد
                    else if (condition.QueryText == "HasNoUndeliveredUncreditOrAllRollbacked")
                    {
                        foreach (var sale in sales)
                        {
                            foreach (var saleDetail in sale.UncreditSaleDetails)
                            {
                                // تحویل نشده ی برگشت نشده فالس است
                                if (!saleDetail.Delivered && !saleDetail.Rollbacked && !saleDetail.IsRollbackDetail)
                                {
                                    response.CanEnter = false;
                                    response.ErrorMessages.Add(condition.ErrorText);
                                }
                            }
                        }
                    }
                    // آخرین خدمات اعتباری که فروخته شده منقضی شده باشد
                    else if (condition.QueryText == "LastCreditExpired")
                    {
                        CreditSaleDetail saleDetail = sales.OrderByDescending(o => o.CreateDate).FirstOrDefault().CreditSaleDetails.OrderByDescending(o => o.CreateDate).FirstOrDefault();
                        // شرط عدم انقضاء
                        if (saleDetail.CreditService.ExpDays >= PersianDateTime.DateDiff(PersianDateTime.Now, saleDetail.CreateDate))
                        {
                            response.CanEnter = false;
                            response.ErrorMessages.Add(condition.ErrorText);
                        }
                    }
                    //آخرین خدمات اعتباری که فروخته شده منقضی نشده باشد
                    else if (condition.QueryText == "LastCreditNotExpired")
                    {
                        CreditSaleDetail saleDetail = sales.OrderByDescending(o => o.CreateDate).FirstOrDefault().CreditSaleDetails.OrderByDescending(o => o.CreateDate).FirstOrDefault();
                        // شرط انقضاء
                        if (saleDetail.CreditService.ExpDays < PersianDateTime.DateDiff(PersianDateTime.Now, saleDetail.CreateDate))
                        {
                            response.CanEnter = false;
                            response.ErrorMessages.Add(condition.ErrorText);
                        }
                    }
                    // شبکه انتخاب شده برای مشتری تحت پوشش باشد
                    else if (condition.QueryText == "NetworkOfCustomerIsSupport")
                    {
                        if (customer.Network != null)
                        {
                            if (!customer.Network.NetworkCenters.Where(w => w.Status == NetworkCenterStatus.Support && w.Center == customer.Center).Any())
                            {
                                response.CanEnter = false;
                                response.ErrorMessages.Add(condition.ErrorText);
                            }
                        }
                        else
                        {
                            response.CanEnter = false;
                            response.ErrorMessages.Add("برای انتقال مشتری به این مرحله ، حتما باید شبکه مشتری مشخص باشد. لطفا در ثبت نام کامل ، شبکه مشتری را انتخاب کنید.");
                        }
                    }
                    // شبکه انتخاب شده برای مشتری عدم پوشش باشد
                    else if (condition.QueryText == "NetworkOfCustomerIsNotSupport")
                    {
                        if (!customer.Network.NetworkCenters.Where(w => w.Status == NetworkCenterStatus.NotSupport && w.Center == customer.Center).Any())
                        {
                            response.CanEnter = false;
                            response.ErrorMessages.Add(condition.ErrorText);
                        }
                    }
                    // شبکه انتخاب شده برای مشتری عدم امکان موقت باشد
                    else if (condition.QueryText == "NetworkOfCustomerIsAdameEmkan")
                    {
                        if (!customer.Network.NetworkCenters.Where(w => w.Status == NetworkCenterStatus.NotSupport && w.Center == customer.Center).Any())
                        {
                            response.CanEnter = false;
                            response.ErrorMessages.Add(condition.ErrorText);
                        }
                    }
                    // امکان تحویل حداقل یک کالا یا خدمات فروخته شده وجود داشته باشد
                    else if (condition.QueryText == "CanDeliverAtLeastOnItem")
                    {
                        foreach (Sale sale in sales)
                        {
                            if (sale.Closed)
                            {
                                foreach (var saleDetail in sale.CreditSaleDetails)
                                {
                                    // جمع سطر کمتر از مانده قابل تحویل باشد
                                    if (saleDetail.LineTotal <= customer.CanDeliverCost)
                                    {
                                        response.CanEnter = true;
                                    }
                                }
                                foreach (var saleDetail in sale.UncreditSaleDetails)
                                {
                                    // جمع سطر کمتر از مانده قابل تحویل باشد
                                    if (saleDetail.LineTotal <= customer.CanDeliverCost)
                                    {
                                        response.CanEnter = true;
                                    }
                                }
                                foreach (var saleDetail in sale.ProductSaleDetails)
                                {
                                    // جمع سطر کمتر از مانده قابل تحویل باشد
                                    if (saleDetail.LineTotal <= customer.CanDeliverCost)
                                    {
                                        response.CanEnter = true;
                                    }
                                }

                                response.ErrorMessages.Add(condition.ErrorText);
                            }
                        }
                    }
                    else if (condition.QueryText == "HasNoOpenCSupport")
                    {
                        if (customer.Supports.Any())
                        {
                            IEnumerable <Support> support =
                                customer.Supports.Where(x => x.SupportStatus.IsLastSupportState != true);

                            if (support.Count() > 0)
                            {
                                response.CanEnter = false;
                                response.ErrorMessages.Add(condition.ErrorText);
                            }
                        }
                    }
                }
            }

            return(response);
        }
示例#8
0
        public GeneralResponse DoCourierAction(Guid CourierID, int CourierStatuse, string ExpertComment, Guid CourierEmployeeID, Guid ModifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Courier courier = new Courier();
                courier = _courierRepository.FindBy(CourierID);
                if (courier.CourierStatuse == Courier.CourierStatuses.Confirmed)
                {
                    response.ErrorMessages.Add("این اعزام پیک تایید شده است.  لذا دیگر قادر به تغییر وضعیت آن نیستید");
                    return(response);
                }

                courier.ExpertComment    = ExpertComment;
                courier.CourierStatuse   = (Courier.CourierStatuses)CourierStatuse;
                courier.ModifiedDate     = PersianDateTime.Now;
                courier.ModifiedEmployee = _employeeRepository.FindBy((ModifiedEmployeeID));
                courier.CourierEmployee  = _courierEmployeeRepository.FindBy(CourierEmployeeID);

                #region Add Courier To Bonus An Comissions

                if ((Courier.CourierStatuses)CourierStatuse == Courier.CourierStatuses.Confirmed)
                {
                    //برای خدمات غیر اعتباری
                    foreach (var item in courier.Sale.UncreditSaleDetails.Where(x => x.Rollbacked == false))
                    {
                        Query     query = new Query();
                        Criterion UncreditSaleDetailID = new Criterion("ID", item.ID,
                                                                       CriteriaOperator.Equal);
                        query.Add(UncreditSaleDetailID);
                        UncreditSaleDetail unCreditSaleDetail = _uncreditSaleDetailRepository.FindBy(query).FirstOrDefault();
                        if (unCreditSaleDetail != null)
                        {
                            unCreditSaleDetail.BonusDate = PersianDateTime.Now;

                            _uncreditSaleDetailRepository.Save(unCreditSaleDetail);
                        }
                    }

                    //برای خدمات  اعتباری
                    foreach (var item in courier.Sale.CreditSaleDetails.Where(x => x.Rollbacked == false))
                    {
                        Query     query = new Query();
                        Criterion UncreditSaleDetailID = new Criterion("ID", item.ID,
                                                                       CriteriaOperator.Equal);
                        query.Add(UncreditSaleDetailID);
                        CreditSaleDetail creditSaleDetail = _creditSaleDetailRepository.FindBy(query).FirstOrDefault();
                        if (creditSaleDetail != null)
                        {
                            creditSaleDetail.BonusDate = PersianDateTime.Now;
                            _creditSaleDetailRepository.Save(creditSaleDetail);
                        }
                    }

                    //برای کالاها
                    foreach (var item in courier.Sale.ProductSaleDetails.Where(x => x.Rollbacked == false))
                    {
                        Query     query = new Query();
                        Criterion UncreditSaleDetailID = new Criterion("ID", item.ID,
                                                                       CriteriaOperator.Equal);
                        query.Add(UncreditSaleDetailID);
                        ProductSaleDetail productsaleDetail = _productSaleDetailRepository.FindBy(query).FirstOrDefault();
                        if (productsaleDetail != null)
                        {
                            productsaleDetail.BonusDate = PersianDateTime.Now;
                            _productSaleDetailRepository.Save(productsaleDetail);
                        }
                    }
                }

                #endregion

                _courierRepository.Save(courier);

                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }