public IHttpActionResult UpdateSupplierReturnRequest(SupplierReturnRequest SupplierReturnRequest)
        {
            try
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    if (MerchantContext.Permission.IsAllowToEditSupplierReturnRequest)
                    {
                        var supplierReturnRequest = _ISupReturnWorkListRepositoryContext.GetSupReturnRequest(SupplierReturnRequest.SupplierReturnId);
                        if (supplierReturnRequest != null && (supplierReturnRequest.IsRejected || supplierReturnRequest.IsDeleted || _iWorkFlowDetailsRepository.CheckLastActionPerform(supplierReturnRequest.RecordId, StringConstants.ReturnAction, MerchantContext.UserDetails.RoleId)))
                        {
                            return(Ok(new { status = StringConstants.AlreadyActivityProcessed }));
                        }

                        var status = _ISupplierReturnRepositoryContext.UpdateSupplierReturnRequest(SupplierReturnRequest, MerchantContext.UserDetails, MerchantContext.CompanyDetails);
                        return(Ok(new { status = status }));
                    }
                    else
                    {
                        var status = StringConstants.PermissionDenied;
                        return(Ok(new { status = status }));
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
 public IHttpActionResult SaveSupplierReturnRequest(SupplierReturnRequest SupplierReturnRequest)
 {
     try
     {
         if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
             if (MerchantContext.Permission.IsAllowToInitiateSupplierReturnRequest)
             {
                 var supplierReturnRequest = _ISupplierReturnRepositoryContext.SaveSupplierReturnRequest(SupplierReturnRequest, MerchantContext.UserDetails, MerchantContext.CompanyDetails);
                 return(Ok(supplierReturnRequest));
             }
             else
             {
                 SupplierReturnRequest.Status = StringConstants.PermissionDenied;
                 return(Ok(SupplierReturnRequest));
             }
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
Beispiel #3
0
        /// <summary>
        /// This method is used for fetching supplier return request from database. - JJ
        /// </summary>
        /// <param name="id">id of supplier return detail</param>
        /// <returns>object of SupplierReturnRequest</returns>
        public SupplierReturnRequest GetSupReturnRequest(int id)
        {
            try
            {
                var supplierReturn = _supplierReturnDetailContext.Find(id);
                var log            = _IWorkFlowDetailsRepository.GetAllWorkFlowActionList(supplierReturn.RecordId);

                if (supplierReturn.IsRejected || supplierReturn.IsDeleted)
                {
                    var workFlowActionAc = new WorkFlowActionAc();
                    if (supplierReturn.IsRejected)
                    {
                        var rejector = _userDetailContext.Find(supplierReturn.RejectorId);
                        workFlowActionAc.Stage    = "Rejected by " + rejector.RoleName;
                        workFlowActionAc.Action   = StringConstants.RejectAction;
                        workFlowActionAc.UserName = rejector.UserName;
                        workFlowActionAc.RoleName = rejector.RoleName;
                    }
                    else
                    {
                        workFlowActionAc.Stage    = "Deleted by " + supplierReturn.Initiator.RoleName;
                        workFlowActionAc.Action   = "Deleted";
                        workFlowActionAc.UserName = supplierReturn.Initiator.UserName;
                        workFlowActionAc.RoleName = supplierReturn.Initiator.RoleName;
                    }
                    workFlowActionAc.Comment    = supplierReturn.Comment;
                    workFlowActionAc.ActionDate = String.Format("{0:dd-MM-yyyy}", supplierReturn.RejectedDate);
                    log.Add(workFlowActionAc);
                }
                var supplierReturnItem    = ConvertToApplicationClass(_supplierReturnItemContext.Fetch(x => x.SupplierReturnId == id).ToList());
                var supplierReturnRequest = new SupplierReturnRequest
                {
                    BranchId             = supplierReturn.BranchId,
                    BranchName           = supplierReturn.BranchDetail.Name,
                    InitiationDate       = supplierReturn.CreatedDateTime,
                    IsRejected           = supplierReturn.IsRejected,
                    RequestNo            = supplierReturn.RequestNo,
                    Initiator            = supplierReturn.Initiator.FullName,
                    InitiatorId          = supplierReturn.InitiatorId,
                    IsDeleted            = supplierReturn.IsDeleted,
                    SupplierId           = supplierReturn.SupplierId,
                    SupplierName         = supplierReturn.SupplierProfile.NameEn,
                    SupplierCode         = supplierReturn.SupplierProfile.Code,
                    SupplierReturnId     = supplierReturn.Id,
                    SupplierReturnItemAC = supplierReturnItem,
                    RecordId             = supplierReturn.RecordId,
                    WorkFlowLog          = log
                };
                return(supplierReturnRequest);
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
        /// <summary>
        /// This method is used for save new  supplier return request in database. - JJ
        /// </summary>
        /// <param name="SupplierReturnRequest">object of SupplierReturnRequest</param>
        /// <param name="company">object of CompanyDetail</param>
        /// <param name="user">object of UserDetail</param>
        /// <returns>object of SupplierReturnRequest</returns>

        public SupplierReturnRequest SaveSupplierReturnRequest(SupplierReturnRequest SupplierReturnRequest, UserDetail user, CompanyDetail company)
        {
            try
            {
                var status = CheckSupplierConditions(SupplierReturnRequest.SupplierId, SupplierReturnRequest.SupplierReturnItemAC);
                if (status == "ok")
                {
                    var ParentRecordId = 0;
                    var workFlowLog    = _IWorkFlowDetailsRepository.GetInitiationActionWorkFlow(StringConstants.SupplierReturnRequest, StringConstants.InitiateSupplierReturnRequest, user, company, null, SupplierReturnRequest.InitiationComment, null);
                    if (workFlowLog != null)
                    {
                        WorkFlowLog    log            = (WorkFlowLog)workFlowLog.Item1;
                        WorkFlowDetail workFlowDetail = (WorkFlowDetail)workFlowLog.Item2;
                        ParentRecordId = log.RecordId;
                        var requestNo            = RequestNumberGenerator(company.Id);
                        var supplierReturnDetail = new SupplierReturnDetail
                        {
                            CreatedDateTime   = DateTime.UtcNow,
                            IsRejected        = false,
                            IsDeleted         = false,
                            RecordId          = ParentRecordId,
                            LastActivityDate  = DateTime.UtcNow,
                            SupplierId        = SupplierReturnRequest.SupplierId,
                            RequestNo         = requestNo,
                            BranchId          = SupplierReturnRequest.BranchId,
                            InitiatorId       = user.Id,
                            InitiationComment = SupplierReturnRequest.InitiationComment
                        };
                        _supplierReturnDetailContext.Add(supplierReturnDetail);
                        _supplierReturnDetailContext.SaveChanges();

                        foreach (var item in SupplierReturnRequest.SupplierReturnItemAC)
                        {
                            var supplierReturnItem = new SupplierReturnItem
                            {
                                CostPrice        = item.CostPrice,
                                CreatedDateTime  = DateTime.UtcNow,
                                ItemId           = item.ItemId,
                                ReturnQuantity   = item.ReturnQuantity,
                                SupplierReturnId = supplierReturnDetail.Id,
                                ReturnCauseId    = item.ReturnCauseId
                            };
                            _supplierReturnItemContext.Add(supplierReturnItem);
                            _supplierReturnItemContext.SaveChanges();

                            var itemProfile = _itemProfileContext.Find(item.ItemId);
                            itemProfile.IsSupplierReturnRequestGenerated = true;
                            _itemProfileContext.Update(itemProfile);
                            _itemProfileContext.SaveChanges();
                        }
                        SupplierReturnRequest.SupplierReturnId = supplierReturnDetail.Id;
                        var companyid = _branchDetailContext.Find(supplierReturnDetail.BranchId).CompanyId;
                        if (workFlowDetail.NextActivity.IsClosed)
                        {
                            var outcome = _ISupReturnWorkListRepository.IssueCreditNote(supplierReturnDetail.Id, supplierReturnDetail.BranchId, companyid, supplierReturnDetail.InitiationComment);
                            if (outcome)
                            {
                                SupplierReturnRequest.Status = "print";
                            }
                            else
                            {
                                SupplierReturnRequest.Status = "Error in Issueing Credit Note";
                            }
                            return(SupplierReturnRequest);
                        }
                        else
                        {
                            SupplierReturnRequest.Status = "ok";
                            return(SupplierReturnRequest);
                        }
                    }
                    else
                    {
                        SupplierReturnRequest.Status = StringConstants.WorkFlowNotCreated;
                        return(SupplierReturnRequest);
                    }
                }
                else
                {
                    SupplierReturnRequest.Status = status;
                    return(SupplierReturnRequest);
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
        /// <summary>
        /// This method is used for update supplier return request in database. - JJ
        /// </summary>
        /// <param name="SupplierReturnRequest">object of SupplierReturnRequest</param>
        /// <param name="company">object of CompanyDetail</param>
        /// <param name="user">object of UserDetail</param>
        /// <returns>status</returns>
        public string UpdateSupplierReturnRequest(SupplierReturnRequest SupplierReturnRequest, UserDetail user, CompanyDetail company)
        {
            try
            {
                var workFlowLog    = new WorkFlowLog();
                var supplierReturn = _supplierReturnDetailContext.Fetch(x => x.RecordId == SupplierReturnRequest.RecordId).FirstOrDefault();
                if (supplierReturn.IsRejected || supplierReturn.IsDeleted)
                {
                    if (supplierReturn.IsRejected)
                    {
                        return("Supplier Return Request is Rejected. You cannot Resubmit or Edit it");
                    }
                    else
                    {
                        return("Supplier Return Request is Deleted. You cannot Resubmit or Edit it");
                    }
                }
                else
                {
                    var status = CheckSupplierConditions(SupplierReturnRequest.SupplierId, SupplierReturnRequest.SupplierReturnItemAC);
                    if (status == "ok")
                    {
                        if (SupplierReturnRequest.IsResubmit)
                        {
                            workFlowLog = _IWorkFlowDetailsRepository.GetResubmitActionWorkFlow(SupplierReturnRequest.RecordId, SupplierReturnRequest, SupplierReturnRequest, StringConstants.ReSubmitedAction, SupplierReturnRequest.Comment, user);
                        }
                        else
                        {
                            workFlowLog = _IWorkFlowDetailsRepository.GetResubmitActionWorkFlow(SupplierReturnRequest.RecordId, SupplierReturnRequest, SupplierReturnRequest, StringConstants.EditedAction, SupplierReturnRequest.InitiationComment, user);
                        }
                        if (workFlowLog != null)
                        {
                            supplierReturn.SupplierId       = SupplierReturnRequest.SupplierId;
                            supplierReturn.LastActivityDate = DateTime.UtcNow;
                            supplierReturn.ModifiedDateTime = DateTime.UtcNow;
                            _supplierReturnDetailContext.Update(supplierReturn);
                            _supplierReturnDetailContext.SaveChanges();

                            DeleteSupplierReturnItem(supplierReturn.Id);

                            foreach (var item in SupplierReturnRequest.SupplierReturnItemAC)
                            {
                                var supplierReturnItem = new SupplierReturnItem
                                {
                                    CostPrice        = item.CostPrice,
                                    CreatedDateTime  = DateTime.UtcNow,
                                    ItemId           = item.ItemId,
                                    ReturnQuantity   = item.ReturnQuantity,
                                    SupplierReturnId = SupplierReturnRequest.SupplierReturnId,
                                    ReturnCauseId    = item.ReturnCauseId
                                };
                                _supplierReturnItemContext.Add(supplierReturnItem);
                                _supplierReturnItemContext.SaveChanges();

                                var itemProfile = _itemProfileContext.Find(item.ItemId);
                                itemProfile.IsSupplierReturnRequestGenerated = true;
                                itemProfile.ModifiedDateTime = DateTime.UtcNow;
                                _itemProfileContext.Update(itemProfile);
                                _itemProfileContext.SaveChanges();
                            }
                            return("ok");
                        }
                        else
                        {
                            return(StringConstants.WorkFlowNotCreated);
                        }
                    }
                    else
                    {
                        return(status);
                    }
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }
Beispiel #6
0
        /// <summary>
        /// This method is used for fetching supplier return request list from database. - JJ
        /// </summary>
        /// <param name="BranchId">branch id of the currently logged in user</param>
        /// <param name="CompanyId"></param>
        /// <param name="IsAllow">whether is allowed to fetch details of other branches</param>
        /// <returns>list of objects of SupplierReturnRequest</returns>
        public List <SupplierReturnRequest> GetSupReturnWorkList(int CompanyId, bool IsAllow, int?BranchId)
        {
            try
            {
                var date           = DateTime.UtcNow.Subtract(TimeSpan.FromDays(14));
                var isInList       = false;
                var supplierReturn = new List <SupplierReturnDetail>();
                if (IsAllow)
                {
                    supplierReturn = _supplierReturnDetailContext.Fetch(x => x.BranchDetail.CompanyId == CompanyId).OrderByDescending(x => x.CreatedDateTime).ToList();
                }
                else
                {
                    supplierReturn = _supplierReturnDetailContext.Fetch(x => x.BranchDetail.Id == BranchId).OrderByDescending(x => x.CreatedDateTime).ToList();
                }
                var supplierReturnList = new List <SupplierReturnRequest>();

                foreach (var detail in supplierReturn)
                {
                    isInList = false;
                    if (detail.RejectedDate != null)
                    {
                        if (detail.RejectedDate > date)
                        {
                            isInList = true;
                        }
                    }
                    else
                    {
                        isInList = false;
                        var log = _workFlowLogContext.Fetch(x => x.RecordId == detail.RecordId).ToList().LastOrDefault();
                        if (log != null)
                        {
                            var workFlow = _workFlowDetailContext.Find(log.WorkFlowId);
                            if (workFlow != null)
                            {
                                if (workFlow.NextActivityId == 3)
                                {
                                    if (detail.LastActivityDate != null && detail.LastActivityDate > date)
                                    {
                                        isInList = true;
                                    }
                                }
                                else
                                {
                                    isInList = true;
                                }
                            }
                        }
                    }
                    if (isInList)
                    {
                        var supplierReturnDetail = new SupplierReturnRequest
                        {
                            SupplierReturnId = detail.Id,
                            BranchId         = detail.BranchId,
                            BranchName       = detail.BranchDetail.Name,
                            Initiator        = detail.Initiator.FullName,
                            InitiationDate   = detail.CreatedDateTime,
                            RequestNo        = detail.RequestNo,
                            IsRejected       = detail.IsRejected,
                            IsDeleted        = detail.IsDeleted,
                            SupplierId       = detail.SupplierId,
                            SupplierName     = detail.SupplierProfile.NameEn,
                            Action           = GetActionName(detail.RecordId)
                        };
                        supplierReturnList.Add(supplierReturnDetail);
                    }
                }
                return(supplierReturnList);
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }