Example #1
0
        /// <summary>
        /// This method is used for fetching purchase order details for printing receipt. - JJ
        /// </summary>
        /// <param name="RecordId">parent record id</param>
        /// <param name="Comment"></param>
        /// <param name="userName">currently logged in user's username</param>
        /// <param name="RoleName">logged in user's rolename</param>
        /// <param name="RoleId">logged in user's role id</param>
        /// <returns>object of SPOReceipt</returns>
        public SPOReceipt PrintSPOReceipt(string Comment, int RecordId, int RoleId, string RoleName, string userName)
        {
            var purchaseOrder = _supplierPOContext.Fetch(x => x.RecordId == RecordId).FirstOrDefault();

            if (purchaseOrder.IsApproved && !purchaseOrder.IsReceived && !purchaseOrder.IsVerified && !purchaseOrder.IsPaid)
            {
                var itemList   = new List <SupplierItemAC>();
                var poItemList = _purchaseOrderItemContext.Fetch(x => x.PurchaseOrderId == purchaseOrder.Id).ToList();
                foreach (var item in poItemList)
                {
                    var spoItem = new SupplierItemAC
                    {
                        FlavourEn       = item.ItemProfile.FlavourEn,
                        ItemNameEn      = item.ItemProfile.ItemNameEn,
                        Type            = item.ItemProfile.SystemParameter.ValueEn + "-" + item.ItemProfile.BaseUnit,
                        OrderCostPrice  = item.OrderCostPrice,
                        OrderQuantity   = item.OrderQuantity,
                        TotalOrderPrice = item.OrderQuantity * item.OrderCostPrice
                    };
                    itemList.Add(spoItem);
                }

                var spoReceipt = new SPOReceipt();
                spoReceipt.BranchAddress       = purchaseOrder.InitiatorBranch.Address;
                spoReceipt.BranchName          = purchaseOrder.InitiatorBranch.NameSl;
                spoReceipt.Comment             = Comment;
                spoReceipt.DueDate             = purchaseOrder.DueDate;
                spoReceipt.IssueDate           = purchaseOrder.CreatedDateTime;
                spoReceipt.MobileNo            = purchaseOrder.SupplierProfile.Phone;
                spoReceipt.POType              = purchaseOrder.SupplierProfile.SupplierType.ValueSl;
                spoReceipt.SPONumber           = purchaseOrder.PurchaseOrderNumber;
                spoReceipt.SupplierItem        = itemList;
                spoReceipt.SupplierName        = purchaseOrder.SupplierProfile.NameEn;
                spoReceipt.SupplierEmail       = purchaseOrder.SupplierProfile.Email;
                spoReceipt.Invoice             = InvoiceToHtml.get39(purchaseOrder.PurchaseOrderNumber, 1, 20);
                purchaseOrder.IsSend           = true;
                purchaseOrder.ModifiedDateTime = DateTime.UtcNow;
                _supplierPOContext.Update(purchaseOrder);
                _supplierPOContext.SaveChanges();

                SaveSupplierPurchaseOrderLog(StringConstants.Send, Comment, purchaseOrder.Id, RecordId, RoleName, "" + RoleName + " " + StringConstants.SendSPO, userName);
                return(spoReceipt);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
 /// <summary>
 /// This method is used for fetching supplier item list from database. - JJ
 /// </summary>
 /// <param name="SupplierId">id of supplier</param>
 /// <param name="userName">name of user</param>
 /// <returns>list of objects of SupplierItemAC</returns>
 public List <SupplierItemAC> GetSupplierItemList(int SupplierId, string userName)
 {
     try
     {
         var itemList   = new List <SupplierItemAC>();
         var categories = _itemSupplierContext.Fetch(x => x.SupplierId == SupplierId && !x.IsDelete && x.SupplierProfile.IsActive).ToList();
         foreach (var category in categories)
         {
             var items = _itemProfileContext.Fetch(x => x.CategoryId == category.CategoryId && !x.IsDeleted).ToList();
             foreach (var item in items)
             {
                 if (item.IsActive && !item.IsDeleted)
                 {
                     SupplierItemAC itemProfile = new SupplierItemAC
                     {
                         SupplierDaysLimit = category.SupplierProfile.TotalDaysLimit,
                         SupplierTypeId    = category.SupplierProfile.SupplierTypeId,
                         Barcode           = item.Barcode,
                         BaseUnit          = item.BaseUnit,
                         Category          = item.Category,
                         Code            = item.Code,
                         CostPrice       = item.CostPrice,
                         FlavourEn       = item.FlavourEn,
                         ItemId          = item.Id,
                         ItemNameEn      = item.ItemNameEn,
                         ActualQuantity  = 0,
                         MaxQuantity     = 0,
                         Type            = item.SystemParameter.ValueEn,
                         UnitParamTypeId = item.UnitParamTypeId
                     };
                     itemList.Add(itemProfile);
                 }
             }
         }
         return(itemList);
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
 public IHttpActionResult ReceiveSPOItem(SupplierItemAC SupplierItemAC)
 {
     try
     {
         if (HttpContext.Current.User.Identity.IsAuthenticated)
         {
             var status = _spoReceivingContext.ReceiveSPOItem(SupplierItemAC, MerchantContext.UserDetails, MerchantContext.CompanyDetails);
             return(Ok(new { status = status }));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
Example #4
0
        /// <summary>
        /// This method is used for fetching supplier purchase order item list from database. - JJ
        /// </summary>
        /// <param name="id">id of spo</param>
        ///<param name="PONum">Purchase Order Number of SPO</param>
        /// <returns>list of objects of SupplierItemAC</returns>
        public List <SupplierItemAC> GetSupplierPOItemList(int?id, string PONum)
        {
            var itemList = new List <SupplierItemAC>();
            List <PurchaseOrderItem> poItems;

            if (id != null && id > 0)
            {
                poItems = _purchaseOrderItemContext.Fetch(x => x.PurchaseOrderId == id).ToList();
            }
            else
            {
                poItems = _purchaseOrderItemContext.Fetch(x => x.SupplierPurchaseOrder.PurchaseOrderNumber == PONum).ToList();
            }

            foreach (var poItem in poItems)
            {
                var items = _itemProfileContext.Fetch(x => x.Id == poItem.ItemId).ToList();
                foreach (var item in items)
                {
                    var isIcrActive = false;
                    var icrdetails  = _icrDetailContext.Fetch(x => x.ItemId == item.Id).ToList();
                    foreach (var icr in icrdetails)
                    {
                        var workFlowLog = _workFlowLogContext.Fetch(x => x.RecordId == icr.RecordId).ToList().LastOrDefault();
                        if (workFlowLog != null && !workFlowLog.WorkFlowDetail.NextActivity.IsClosed && !icr.IsRejected && !icr.IsDeleted)
                        {
                            isIcrActive = true;
                            break;
                        }
                    }

                    //for different branches the quantities are diff. so fetch quantity based on branch
                    var Quantity       = _itemQuantityContext.FirstOrDefault(x => x.ItemId == item.Id && x.BranchId == poItem.SupplierPurchaseOrder.InitiationBranchId);
                    var actualQuantity = Quantity != null ? Quantity.ActualQuantity : 0;
                    var recordId       = (poItem.SupplierPurchaseOrder.RecordId != null && poItem.SupplierPurchaseOrder.RecordId > 0) ? (int)poItem.SupplierPurchaseOrder.RecordId : 0;

                    SupplierItemAC itemProfile = new SupplierItemAC
                    {
                        Barcode            = item.Barcode,
                        BaseUnit           = item.BaseUnit,
                        Category           = item.Category,
                        Code               = item.Code,
                        OrderCostPrice     = poItem.OrderCostPrice,
                        CostPrice          = item.CostPrice,
                        FlavourEn          = item.FlavourEn,
                        ItemId             = item.Id,
                        ItemNameEn         = item.ItemNameEn,
                        ActualQuantity     = actualQuantity,
                        UnitParamTypeId    = item.UnitParamTypeId,
                        Type               = item.SystemParameter.ValueEn,
                        FreeQuantity       = poItem.FreeQuantity,
                        IsIcrGenerated     = isIcrActive,
                        OrderQuantity      = poItem.OrderQuantity,
                        ReceiveQuantity    = poItem.ReceivingQuantity,
                        ReceiveCostPrice   = poItem.ReceivingCostPrice,
                        BillCostPrice      = poItem.BillCostPrice,
                        ParentRecordId     = recordId,
                        PercentageDiscount = poItem.PercentageDiscount,
                        SPOReceivingStatus = poItem.SPOReceivingStatus
                    };
                    itemList.Add(itemProfile);
                }
            }
            return(itemList);
        }
Example #5
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);
            }
        }
Example #6
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;
            }
        }