Esempio n. 1
0
 /// <summary>
 /// this method is used for adding ICR.- JJ
 /// </summary>
 /// <param name="company"></param>
 /// <param name="itemChangedDetail"></param>
 /// <param name="ParentRecordId"></param>
 /// <param name="user"></param>
 /// <param name="WorkFlowId"></param>
 /// <returns>status</returns>
 public string AddICR(ItemChangedDetailsAC itemChangedDetail, int ParentRecordId, int?WorkFlowId, CompanyDetail company, UserDetail user)
 {
     try
     {
         var item = _itemProfileContext.Find(itemChangedDetail.ItemId);
         if (item.IsItemChangeRequestGenerated && itemChangedDetail.IsInDirect)
         {
             return(StringConstants.ICRPriceGenerateError);
         }
         else
         {
             var icrDetail = new IcrDetail
             {
                 CreatedDateTime      = DateTime.UtcNow,
                 IsAddItemIcr         = itemChangedDetail.IsAddItemIcr,
                 IsPOItemIcr          = itemChangedDetail.IsPOItemIcr,
                 IsPriceChangeRequest = itemChangedDetail.IsPriceChangeRequest,
                 ItemId   = itemChangedDetail.ItemId,
                 RecordId = ParentRecordId
             };
             if (itemChangedDetail.POItemId > 0)
             {
                 icrDetail.SPOItemId = itemChangedDetail.POItemId;
             }
             _icrDetailContext.Add(icrDetail);
             _icrDetailContext.SaveChanges();
             string status   = AddICRPriceQuantity(itemChangedDetail, itemChangedDetail.ItemId, icrDetail.Id, false, true);
             var    workflow = _workFlowContext.Find(WorkFlowId);
             if (workflow.NextActivity.IsClosed)
             {
                 _IICRWorkListRepository.UpdateItem(ParentRecordId, true, company, user);
             }
             return(status);
         }
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// this method is used for deleting ICR.- JJ
        /// </summary>
        /// <param name="Id">Id of ICR Detail</param>
        public void DeleteICR(int Id)
        {
            IcrDetail icrDetail = _icrDetailContext.Find(Id);

            icrDetail.IsDeleted        = true;
            icrDetail.ModifiedDateTime = DateTime.UtcNow;
            _icrDetailContext.Update(icrDetail);
            _icrDetailContext.SaveChanges();

            var icrPrice = _icrPriceContext.Fetch(x => x.IcrId == Id).FirstOrDefault();

            _icrPriceContext.Delete(icrPrice);
            _icrPriceContext.SaveChanges();

            var item = _itemProfileContext.Find(icrDetail.ItemId);

            item.IsItemChangeRequestGenerated = false;
            item.ModifiedDateTime             = DateTime.UtcNow;
            _itemProfileContext.Update(item);
            _itemProfileContext.SaveChanges();
        }
        /// <summary>
        /// this method is used for fetching Item Change Request Details.
        /// </summary>
        /// <param name="Id">Id of Icr</param>
        /// <returns>object of ItemChangedDetailsAC</returns>
        public ItemChangedDetailsAC GetICRDetail(int Id, string userId)
        {
            IcrDetail icrDetail           = _icrDetailContext.Find(Id);
            var       ModifyingCostPrice  = 0M;
            var       ModifyingSellPrice  = 0M;
            var       ModifyingSellPriceA = 0M;
            var       ModifyingSellPriceB = 0M;
            var       ModifyingSellPriceC = 0M;
            var       ModifyingSellPriceD = 0M;
            var       icrQuantity         = _icrQuantityContext.Fetch(x => x.IcrId == Id).ToList();

            if (icrDetail != null)
            {
                var logList      = _iWorkFlowDetailsRepository.GetAllWorkFlowActionList(icrDetail.RecordId);
                var quantityList = new List <IcrQuantityAC>();
                foreach (var quantity in icrQuantity)
                {
                    var icrQuantityAC = new IcrQuantityAC
                    {
                        BranchId          = quantity.BranchId,
                        BranchName        = quantity.BranchDetail.Name,
                        ActualQuantity    = quantity.SystemQuantity,
                        IcrId             = quantity.IcrId,
                        IsAddOperation    = quantity.IsAddOperation,
                        ModifyingQuantity = quantity.ModifyingQuantity
                    };
                    quantityList.Add(icrQuantityAC);
                }
                var icrPrice = _icrPriceContext.Fetch(x => x.IcrId == Id).FirstOrDefault();
                if (icrPrice != null)
                {
                    ModifyingCostPrice  = icrPrice.ModifyingCostPrice;
                    ModifyingSellPrice  = icrPrice.ModifyingSellPrice;
                    ModifyingSellPriceA = icrPrice.ModifyingSellPriceA;
                    ModifyingSellPriceB = icrPrice.ModifyingSellPriceB;
                    ModifyingSellPriceC = icrPrice.ModifyingSellPriceC;
                    ModifyingSellPriceD = icrPrice.ModifyingSellPriceD;
                }
                var hideQuantity =
                    userId != icrDetail.ParentRecord.InitiatorId;

                var icrDetailAC = new ItemChangedDetailsAC
                {
                    ItemProfile          = icrDetail.ItemProfile,
                    IcrQuantity          = quantityList,
                    WorkFlowLog          = logList,
                    Id                   = icrDetail.Id,
                    IsAddItemIcr         = icrDetail.IsAddItemIcr,
                    IsPOItemIcr          = icrDetail.IsPOItemIcr,
                    IsPriceChangeRequest = icrDetail.IsPriceChangeRequest,
                    ItemId               = icrDetail.ItemId,
                    ParentRecordId       = icrDetail.RecordId,
                    IsRejected           = icrDetail.IsRejected,
                    IsReturned           = icrDetail.IsReturned,
                    ModifyingCostPrice   = ModifyingCostPrice,
                    ModifyingSellPrice   = ModifyingSellPrice,
                    ModifyingSellPriceA  = ModifyingSellPriceA,
                    ModifyingSellPriceB  = ModifyingSellPriceB,
                    ModifyingSellPriceC  = ModifyingSellPriceC,
                    ModifyingSellPriceD  = ModifyingSellPriceD,
                    RequestedDate        = icrDetail.CreatedDateTime,
                    HideQuantity         = hideQuantity
                };
                if (icrDetail.SPOItemId != null)
                {
                    icrDetailAC.POItemId = (int)icrDetail.SPOItemId;
                }
                else
                {
                    icrDetailAC.POItemId = 0;
                }
                return(icrDetailAC);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This method is used for receive an item of SPO. This is a private method called by ReceiveSPOItem - JJ
        /// </summary>
        /// <param name="SupplierItemAC">object of SupplierItemAC</param>
        /// <param name="currentUser">object of UserDetail</param>
        /// <param name="company">object of CompanyDetail</param>
        private int Receive(SupplierItemAC SupplierItemAC, UserDetail currentUser, CompanyDetail company)
        {
            PurchaseOrderItem poItem = _purchaseOrderItemContext.FirstOrDefault(x => x.ItemId == SupplierItemAC.ItemId && x.PurchaseOrderId == SupplierItemAC.PurchaseOrderId && x.SupplierPurchaseOrder.IsApproved && x.SupplierPurchaseOrder.IsSend);
            var  status     = "";
            bool icrCreated = false;

            poItem.ReceivingCostPrice = SupplierItemAC.ReceiveCostPrice;
            poItem.ReceivingQuantity  = SupplierItemAC.ReceiveQuantity;
            poItem.BillCostPrice      = SupplierItemAC.BillCostPrice;
            if (SupplierItemAC.ReceiveQuantity > SupplierItemAC.OrderQuantity)
            {
                poItem.SPOReceivingStatus = SPOReceivingStatus.PartiallyReceived;
            }

            var workflowLog = _iWorkFlowDetailsRepository.GetInitiationActionWorkFlow(StringConstants.SPOReceiving, StringConstants.ReceiveSPO, currentUser, company, poItem, null, poItem);

            if (workflowLog != null)
            {
                IcrDetail prevICR = _icrDetailContext.FirstOrDefault(x => x.SPOItemId == poItem.Id && !x.IsDeleted);
                if (prevICR != null)
                {
                    _iICRRepository.DeleteICR(prevICR.Id);
                }

                WorkFlowLog log            = (WorkFlowLog)workflowLog.Item1;
                var         workFlowDetail = (WorkFlowDetail)workflowLog.Item2;

                if (workFlowDetail.NextActivity.Id == 3)
                {
                    if (poItem.OrderQuantity > SupplierItemAC.ReceiveQuantity)
                    {
                        poItem.SPOReceivingStatus = SPOReceivingStatus.PartiallyReceived;
                    }
                    else
                    {
                        poItem.SPOReceivingStatus = SPOReceivingStatus.Received;
                    }
                }
                else
                {
                    poItem.SPOReceivingStatus = SPOReceivingStatus.NotReceived;
                }
                if (workFlowDetail.ParentPermission.Name == StringConstants.ItemChangeRequest && poItem.SPOReceivingStatus == SPOReceivingStatus.NotReceived)
                {
                    icrCreated = true;

                    ItemChangedDetailsAC itemChange = new ItemChangedDetailsAC
                    {
                        IsPOItemIcr          = true,
                        IsPriceChangeRequest = true,
                        ItemId              = SupplierItemAC.ItemId,
                        ModifyingCostPrice  = poItem.ReceivingCostPrice,
                        ModifyingSellPrice  = poItem.ItemProfile.SellPrice,
                        ModifyingSellPriceA = poItem.ItemProfile.SellPriceA,
                        ModifyingSellPriceB = poItem.ItemProfile.SellPriceB,
                        ModifyingSellPriceC = poItem.ItemProfile.SellPriceC,
                        ModifyingSellPriceD = poItem.ItemProfile.SellPriceD,
                        POItemId            = poItem.Id,
                        RequestedDate       = DateTime.UtcNow,
                        ParentRecordId      = log.RecordId,
                        IsInDirect          = true
                    };
                    status = _iICRRepository.SaveICR(itemChange, currentUser, company, workFlowDetail.Id);
                }
                if (status == "ok")
                {
                    var newICR = _icrDetailContext.Fetch(x => x.SPOItemId == poItem.Id && !x.IsDeleted).ToList().LastOrDefault();
                    if (newICR != null)
                    {
                        poItem.ICRDetailId = newICR.Id;
                        if (newICR.IsApproved && poItem.SPOReceivingStatus != SPOReceivingStatus.PartiallyReceived)
                        {
                            poItem.SPOReceivingStatus = SPOReceivingStatus.Received;
                        }
                    }
                }
                poItem.ModifiedDateTime = DateTime.UtcNow;
                _purchaseOrderItemContext.Update(poItem);
                _purchaseOrderItemContext.SaveChanges();
                if (icrCreated)
                {
                    return(300);
                }
                else
                {
                    return((int)poItem.SPOReceivingStatus);
                }
            }
            else
            {
                return(400);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This method is used for receive an item of SPO - JJ
        /// </summary>
        /// <param name="SupplierItemAC">object of SupplierItemAC</param>
        /// <param name="currentUser">object of UserDetail</param>
        /// <param name="company">object of CompanyDetail</param>
        /// <returns>receiving status id</returns>
        public int ReceiveSPOItem(SupplierItemAC SupplierItemAC, UserDetail currentUser, CompanyDetail company)
        {
            try
            {
                SupplierPurchaseOrder purchaseOrder = _supplierPOContext.Find(SupplierItemAC.PurchaseOrderId);
                purchaseOrder.IsVerified       = false;
                purchaseOrder.IsReceived       = false;
                purchaseOrder.ModifiedDateTime = DateTime.UtcNow;
                _supplierPOContext.Update(purchaseOrder);
                _supplierPOContext.SaveChanges();
                PurchaseOrderItem poItem = _purchaseOrderItemContext.Fetch(x => x.ItemId == SupplierItemAC.ItemId && x.PurchaseOrderId == SupplierItemAC.PurchaseOrderId && x.SupplierPurchaseOrder.IsApproved && x.SupplierPurchaseOrder.IsSend).Include(x => x.ItemProfile).FirstOrDefault();
                if (poItem != null)
                {
                    IcrDetail icrDetail = poItem.ICRDetailId != null?_icrDetailContext.FirstOrDefault(x => !x.IsDeleted && x.Id == (int)poItem.ICRDetailId) : null;

                    List <int> spoBranchIds = _purchaseOrderBranchContext.Fetch(x => x.PurchaseOrderId == purchaseOrder.Id).Select(x => x.BranchId).ToList();
                    //bit indicates whether an ICR is generated for item if it is generated then is it for this POItem.
                    bool IsIcrForPOItem = true;
                    List <ItemQuantity> itemQuantities = _itemQuantityContext.Fetch(x => x.ItemId == poItem.ItemId && spoBranchIds.Contains(x.BranchId)).ToList();
                    if (itemQuantities?.Count > 0)
                    {
                        IsIcrForPOItem = !(itemQuantities.Any(x => x.IsICRGenerated));
                    }

                    if (IsIcrForPOItem && poItem.ItemProfile.IsItemChangeRequestGenerated)
                    {
                        IsIcrForPOItem = false;
                        if (poItem.Id == icrDetail?.SPOItemId)
                        {
                            IsIcrForPOItem = true;
                        }
                    }
                    if (IsIcrForPOItem)
                    {
                        if (poItem.ICRDetailId != null)
                        {
                            var icrPrice = _icrPriceContext.Fetch(x => x.IcrId == poItem.ICRDetailId).ToList().LastOrDefault();
                            if (icrPrice != null && icrPrice.ModifyingCostPrice == SupplierItemAC.ReceiveCostPrice)
                            {
                                var icr = _icrDetailContext.FirstOrDefault(x => x.Id == icrPrice.IcrId && !x.IsDeleted);
                                if (icr != null && icr.IsApproved)
                                {
                                    if (poItem.OrderQuantity > SupplierItemAC.ReceiveQuantity)
                                    {
                                        poItem.SPOReceivingStatus = SPOReceivingStatus.PartiallyReceived;
                                    }
                                    else
                                    {
                                        poItem.SPOReceivingStatus = SPOReceivingStatus.Received;
                                    }
                                }
                                else
                                {
                                    poItem.SPOReceivingStatus = SPOReceivingStatus.NotReceived;
                                }

                                poItem.ModifiedDateTime = DateTime.UtcNow;
                                _purchaseOrderItemContext.Update(poItem);
                                _purchaseOrderItemContext.SaveChanges();
                                return((int)poItem.SPOReceivingStatus);
                            }
                            return(Receive(SupplierItemAC, currentUser, company));
                        }
                        return(Receive(SupplierItemAC, currentUser, company));
                    }
                    return(401);
                }
                return(404);
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }