public int SaveAdjustItemRequest(InvLeatherStockAdjustModel model, int userID)
        {
            var leatherTypeID   = DalCommon.GetLeatherTypeCode("Raw Hide");
            var leatherStatusID = DalCommon.GetLeatherStatusCode("Raw Hide");

            using (TransactionScope transaction = new TransactionScope())
            {
                #region Insert

                Inv_LeatherStockAdjustRequest objAdjustmentRequest = new Inv_LeatherStockAdjustRequest();

                objAdjustmentRequest.PurchaseYear = model.PurchaseYear;
                objAdjustmentRequest.RequestDate  = DalCommon.SetDate(model.RequestDate);
                objAdjustmentRequest.LeatherType  = model.LeatherType;
                objAdjustmentRequest.StoreID      = model.StoreID;
                objAdjustmentRequest.RecordStatus = "NCF";
                objAdjustmentRequest.SetBy        = userID;
                objAdjustmentRequest.SetOn        = DateTime.Now;

                _context.Inv_LeatherStockAdjustRequest.Add(objAdjustmentRequest);
                _context.SaveChanges();

                var currentRequestID = objAdjustmentRequest.RequestID;

                foreach (var item in model.StockAdjustItemList)
                {
                    Inv_LeatherStockAdjustItem objAdjustmentItems = new Inv_LeatherStockAdjustItem();

                    objAdjustmentItems.RequestID       = currentRequestID;
                    objAdjustmentItems.SupplierID      = item.SupplierID;
                    objAdjustmentItems.PurchaseID      = item.ChallanID;
                    objAdjustmentItems.ItemTypeID      = item.ItemTypeID;
                    objAdjustmentItems.LeatherType     = model.LeatherType;
                    objAdjustmentItems.LeatherStatus   = leatherStatusID;
                    objAdjustmentItems.ItemQty         = item.ItemQty;
                    objAdjustmentItems.Unit            = item.Unit;
                    objAdjustmentItems.Remarks         = item.Remarks;
                    objAdjustmentItems.AdjustmentCause = item.AdjustmentCause;



                    _context.Inv_LeatherStockAdjustItem.Add(objAdjustmentItems);
                    _context.SaveChanges();
                }

                transaction.Complete();
                return(currentRequestID);

                #endregion
            }
        }
        public long Save(PRDYearMonthCrustReqItem model, int userId)
        {
            long CurrentRequisitionItemID = 0;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        var RequisitionDateInfo = (from r in _context.PRD_YearMonthFinishReqDate.AsEnumerable()
                                                   where r.RequisitionDateID == model.RequisitionDateID
                                                   select r).FirstOrDefault();

                        RequisitionDateInfo.Remark = model.ConfirmNote;
                        _context.SaveChanges();


                        #region Update_Item_Information
                        if (model.ItemList != null)
                        {
                            foreach (var Item in model.ItemList)
                            {
                                #region New_Item_Insertion
                                if (Item.RequisitionItemID == 0)
                                {
                                    PRD_YearMonthFinishReqItem objItem = new PRD_YearMonthFinishReqItem();

                                    objItem.RequisitionDateID    = Item.RequisitionDateID;
                                    objItem.ScheduleItemID       = Item.ScheduleItemID;
                                    objItem.ScheduleProductionNo = Item.ScheduleProductionNo;
                                    //objItem.RequisitionNo = Convert.ToInt32(model.PurchaseID);
                                    objItem.BuyerID      = Item.BuyerID;
                                    objItem.BuyerOrderID = Item.BuyerOrderID;
                                    objItem.ArticleID    = Item.ArticleID;
                                    objItem.ArticleNo    = Item.ArticleNo;

                                    if (Item.ArticleChallanID != 0)
                                    {
                                        objItem.ArticleChallanID = Item.ArticleChallanID;
                                        objItem.ArticleChallanNo = Item.ArticleChallanNo;
                                    }
                                    objItem.AvgSize         = Item.AvgSize;
                                    objItem.AvgSizeUnit     = DalCommon.GetUnitCode(Item.AvgSizeUnitName);
                                    objItem.SelectionRange  = Item.SelectionRange;
                                    objItem.SideDescription = Item.SideDescription;
                                    objItem.Thickness       = Item.Thickness;
                                    objItem.ThicknessUnit   = DalCommon.GetUnitCode(Item.ThicknessUnitName);
                                    objItem.ThicknessAt     = (Item.ThicknessAt == "After Shaving" ? "AFSV" : "AFFN");
                                    objItem.ItemTypeID      = DalCommon.GetItemTypeCode(Item.ItemTypeName);
                                    objItem.LeatherStatusID = DalCommon.GetLeatherStatusCode(Item.LeatherStatusName);
                                    objItem.LeatherTypeID   = DalCommon.GetLeatherTypeCode("Crust");
                                    objItem.Remark          = Item.Remarks;
                                    objItem.SetOn           = DateTime.Now;
                                    objItem.SetBy           = 1;;

                                    _context.PRD_YearMonthFinishReqItem.Add(objItem);
                                    _context.SaveChanges();

                                    CurrentRequisitionItemID = objItem.RequisitionItemID;
                                }
                                #endregion

                                #region Existing_Challan_Update
                                else if (Item.RequisitionItemID != 0)
                                {
                                    var CurrentItem = (from c in _context.PRD_YearMonthFinishReqItem.AsEnumerable()
                                                       where c.RequisitionItemID == Item.RequisitionItemID
                                                       select c).FirstOrDefault();

                                    CurrentItem.RequisitionDateID    = Item.RequisitionDateID;
                                    CurrentItem.ScheduleProductionNo = Item.ScheduleProductionNo;
                                    //CurrentItem.RequisitionNo = Convert.ToInt32(model.PurchaseID);
                                    CurrentItem.BuyerID      = Item.BuyerID;
                                    CurrentItem.BuyerOrderID = Item.BuyerOrderID;
                                    CurrentItem.ArticleID    = Item.ArticleID;
                                    CurrentItem.ArticleNo    = Item.ArticleNo;

                                    if (Item.ArticleChallanID != 0)
                                    {
                                        CurrentItem.ArticleChallanID = Item.ArticleChallanID;
                                        CurrentItem.ArticleChallanNo = Item.ArticleChallanNo;
                                    }

                                    CurrentItem.AvgSize         = Item.AvgSize;
                                    CurrentItem.AvgSizeUnit     = DalCommon.GetUnitCode(Item.AvgSizeUnitName);
                                    CurrentItem.SelectionRange  = Item.SelectionRange;
                                    CurrentItem.SideDescription = Item.SideDescription;
                                    CurrentItem.Thickness       = Item.Thickness.ToString();
                                    CurrentItem.ThicknessUnit   = DalCommon.GetUnitCode(Item.ThicknessUnitName);
                                    CurrentItem.ThicknessAt     = Item.ThicknessAt;
                                    CurrentItem.ItemTypeID      = DalCommon.GetItemTypeCode(Item.ItemTypeName);
                                    CurrentItem.LeatherStatusID = DalCommon.GetLeatherStatusCode(Item.LeatherStatusName);
                                    CurrentItem.LeatherTypeID   = DalCommon.GetLeatherTypeCode("Crust");
                                    CurrentItem.Remark          = Item.Remarks;
                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }

                        #endregion

                        #region To_Find_ColorItemID_For_Items_If_Any

                        if (model.ColorList != null)
                        {
                            foreach (var Color in model.ColorList)
                            {
                                if (Color.RequisitionItemID != null && Color.RequisitionItemID != 0)
                                {
                                    CurrentRequisitionItemID = Convert.ToInt64(Color.RequisitionItemID);
                                    break;
                                }
                                else
                                {
                                    if (model.SelectedRequisitionItemID != 0)
                                    {
                                        CurrentRequisitionItemID = model.SelectedRequisitionItemID;
                                    }
                                    break;
                                }
                            }
                        }
                        #endregion

                        #region Update_Color_Item_Information
                        if (model.ColorList != null)
                        {
                            foreach (var Color in model.ColorList)
                            {
                                #region New_Color_Item_Insertion
                                if (Color.ReqItemColorID == 0)
                                {
                                    PRD_YearMonthFinishReqItemColor objColor = new PRD_YearMonthFinishReqItemColor();

                                    objColor.RequisitionItemID = CurrentRequisitionItemID;
                                    objColor.ColorID           = Color.ColorID;
                                    objColor.ArticleColorNo    = Color.ArticleColorNo;
                                    objColor.ColorPcs          = (Color.ColorPCS);
                                    objColor.ColorSide         = (Color.ColorSide);
                                    objColor.ColorArea         = Color.ColorArea;
                                    objColor.AreaUnit          = DalCommon.GetUnitCode(Color.AreaUnitName);
                                    objColor.Remarks           = Color.Remarks;
                                    objColor.SetBy             = 1;;
                                    objColor.SetOn             = DateTime.Now;

                                    _context.PRD_YearMonthFinishReqItemColor.Add(objColor);
                                    _context.SaveChanges();
                                }
                                #endregion

                                #region Update_Existing_Color_Item
                                else if (Color.ReqItemColorID != 0)
                                {
                                    var currentColorItem = (from c in _context.PRD_YearMonthFinishReqItemColor.AsEnumerable()
                                                            where c.ReqItemColorID == Color.ReqItemColorID
                                                            select c).FirstOrDefault();

                                    currentColorItem.RequisitionItemID = CurrentRequisitionItemID;
                                    currentColorItem.ColorID           = Color.ColorID;
                                    currentColorItem.ArticleColorNo    = Color.ArticleColorNo;
                                    currentColorItem.ColorPcs          = (Color.ColorPCS);
                                    currentColorItem.ColorSide         = (Color.ColorSide);
                                    currentColorItem.ColorArea         = Color.ColorArea;
                                    currentColorItem.AreaUnit          = DalCommon.GetUnitCode(Color.AreaUnitName);
                                    currentColorItem.Remarks           = Color.Remarks;
                                    currentColorItem.SetBy             = 1;;
                                    currentColorItem.SetOn             = DateTime.Now;
                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }
                        #endregion
                    }
                    transaction.Complete();
                }
                return(CurrentRequisitionItemID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Beispiel #3
0
        public bool ConfirmPurchase(string purchaseNumber, string confirmComment)
        {
            try
            {
                using (TransactionScope Transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        var purchaseInfo = (from p in _context.Prq_Purchase.AsEnumerable()
                                            where (p.PurchaseID).ToString() == purchaseNumber
                                            select p).FirstOrDefault();

                        var challanList = (from c in _context.Prq_PurchaseChallan.AsEnumerable()
                                           where (c.PurchaseID).ToString() == purchaseNumber
                                           select c).ToList();

                        foreach (var item in challanList)
                        {
                            var challanItem = (from i in _context.Prq_PurchaseChallanItem.AsEnumerable()
                                               where i.ChallanID == item.ChallanID
                                               select i).ToList();

                            foreach (var leatherItem in challanItem)
                            {
                                var leatherTypeID = DalCommon.GetLeatherTypeCode("Raw Hide");
                                leatherTypeID = leatherTypeID == 0 ? Convert.ToByte(1) : leatherTypeID;
                                var leatherStatusID = DalCommon.GetLeatherStatusCode("Raw Hide");
                                leatherStatusID = leatherStatusID == 0 ? Convert.ToByte(1) : leatherStatusID;

                                var currentDate = DateTime.Now.Date;

                                if (leatherItem.RecordStatus != "CNF" && leatherItem.RecordStatus != "Confirmed")
                                {
                                    #region Daily_Stock_Update

                                    var CheckDate = (from ds in _context.Inv_StockDaily.AsEnumerable()
                                                     where ds.ItemTypeID == leatherItem.ItemTypeID && ds.StoreID == item.ReceiveStore &&
                                                     ds.LeatherStatus == leatherStatusID && ds.LeatherType == leatherTypeID && ds.StockDate == currentDate
                                                     select ds).Any();

                                    if (CheckDate)
                                    {
                                        var CurrentItem = (from ds in _context.Inv_StockDaily.AsEnumerable()
                                                           where ds.ItemTypeID == leatherItem.ItemTypeID && ds.StoreID == item.ReceiveStore &&
                                                           ds.LeatherStatus == leatherStatusID && ds.LeatherType == leatherTypeID && ds.StockDate == currentDate
                                                           select ds).FirstOrDefault();

                                        CurrentItem.DailyReceiveQty = CurrentItem.DailyReceiveQty + leatherItem.ReceiveQty;
                                        CurrentItem.ClosingQty      = CurrentItem.ClosingQty + leatherItem.ReceiveQty;
                                        _context.SaveChanges();
                                    }
                                    else
                                    {
                                        var PreviousRecord = (from ds in _context.Inv_StockDaily.AsEnumerable()
                                                              where ds.ItemTypeID == leatherItem.ItemTypeID && ds.StoreID == item.ReceiveStore &&
                                                              ds.LeatherStatus == leatherStatusID && ds.LeatherType == leatherTypeID
                                                              orderby ds.TransectionID descending
                                                              select ds).FirstOrDefault();

                                        Inv_StockDaily objStockDaily = new Inv_StockDaily();

                                        objStockDaily.ItemTypeID    = leatherItem.ItemTypeID;
                                        objStockDaily.StoreID       = item.ReceiveStore;
                                        objStockDaily.UnitID        = leatherItem.UnitID;
                                        objStockDaily.LeatherStatus = leatherStatusID;
                                        objStockDaily.LeatherType   = leatherTypeID;

                                        objStockDaily.OpeningQty      = (PreviousRecord == null ? 0 : PreviousRecord.ClosingQty);
                                        objStockDaily.DailyReceiveQty = leatherItem.ReceiveQty;
                                        objStockDaily.DailyIssueQty   = 0;
                                        objStockDaily.ClosingQty      = objStockDaily.OpeningQty + leatherItem.ReceiveQty;

                                        objStockDaily.StockDate = currentDate;

                                        _context.Inv_StockDaily.Add(objStockDaily);
                                        _context.SaveChanges();
                                    }

                                    #endregion

                                    #region Supplier_Stock_Update

                                    var CheckSupplierStock = (from i in _context.Inv_StockSupplier.AsEnumerable()
                                                              where i.SupplierID == purchaseInfo.SupplierID && i.ItemTypeID == leatherItem.ItemTypeID &&
                                                              i.LeatherType == leatherTypeID && i.LeatherStatusID == leatherStatusID && i.StoreID == item.ReceiveStore &&
                                                              i.PurchaseID.ToString() == purchaseInfo.PurchaseID.ToString()
                                                              select i).Any();

                                    if (!CheckSupplierStock)
                                    {
                                        Inv_StockSupplier objStockSupplier = new Inv_StockSupplier();
                                        objStockSupplier.SupplierID      = purchaseInfo.SupplierID;
                                        objStockSupplier.StoreID         = item.ReceiveStore;
                                        objStockSupplier.PurchaseID      = purchaseInfo.PurchaseID;
                                        objStockSupplier.RefChallanID    = item.ChallanID;
                                        objStockSupplier.ItemTypeID      = leatherItem.ItemTypeID;
                                        objStockSupplier.LeatherType     = leatherTypeID;
                                        objStockSupplier.LeatherStatusID = leatherStatusID;
                                        objStockSupplier.UnitID          = leatherItem.UnitID;
                                        objStockSupplier.OpeningQty      = 0;
                                        objStockSupplier.ReceiveQty      = leatherItem.ReceiveQty;
                                        objStockSupplier.IssueQty        = 0;
                                        objStockSupplier.ClosingQty      = leatherItem.ReceiveQty;
                                        objStockSupplier.UpdateReason    = "Receive";


                                        _context.Inv_StockSupplier.Add(objStockSupplier);
                                        _context.SaveChanges();
                                    }
                                    else
                                    {
                                        var LastSupplierStock = (from i in _context.Inv_StockSupplier.AsEnumerable()
                                                                 where i.SupplierID == purchaseInfo.SupplierID && i.ItemTypeID == leatherItem.ItemTypeID && i.LeatherType == leatherTypeID && i.LeatherStatusID == leatherStatusID && i.StoreID == item.ReceiveStore && i.PurchaseID.ToString() == purchaseInfo.PurchaseID.ToString()
                                                                 orderby i.TransectionID descending
                                                                 select i).FirstOrDefault();

                                        Inv_StockSupplier objStockSupplier = new Inv_StockSupplier();
                                        objStockSupplier.SupplierID      = purchaseInfo.SupplierID;
                                        objStockSupplier.StoreID         = item.ReceiveStore;
                                        objStockSupplier.PurchaseID      = purchaseInfo.PurchaseID;
                                        objStockSupplier.RefChallanID    = item.ChallanID;
                                        objStockSupplier.ItemTypeID      = leatherItem.ItemTypeID;
                                        objStockSupplier.LeatherType     = leatherTypeID;
                                        objStockSupplier.LeatherStatusID = leatherStatusID;
                                        objStockSupplier.UnitID          = leatherItem.UnitID;

                                        objStockSupplier.OpeningQty   = LastSupplierStock.ClosingQty;
                                        objStockSupplier.ReceiveQty   = leatherItem.ReceiveQty;
                                        objStockSupplier.IssueQty     = 0;
                                        objStockSupplier.ClosingQty   = LastSupplierStock.ClosingQty + leatherItem.ReceiveQty;
                                        objStockSupplier.UpdateReason = "Receive";

                                        _context.Inv_StockSupplier.Add(objStockSupplier);
                                        _context.SaveChanges();
                                    }
                                    #endregion

                                    #region Item_Stock_Update

                                    var CheckItemStock = (from i in _context.Inv_StockItem.AsEnumerable()
                                                          where i.ItemTypeID == leatherItem.ItemTypeID && i.LeatherType == leatherTypeID && i.LeatherStatus == leatherStatusID && i.StoreID == item.ReceiveStore
                                                          select i).Any();


                                    if (!CheckItemStock)
                                    {
                                        Inv_StockItem objStockItem = new Inv_StockItem();

                                        objStockItem.ItemTypeID    = leatherItem.ItemTypeID;
                                        objStockItem.LeatherType   = leatherTypeID;
                                        objStockItem.LeatherStatus = leatherStatusID;
                                        objStockItem.StoreID       = item.ReceiveStore;
                                        objStockItem.UnitID        = leatherItem.UnitID;
                                        objStockItem.OpeningQty    = 0;
                                        objStockItem.ReceiveQty    = leatherItem.ReceiveQty;
                                        objStockItem.IssueQty      = 0;
                                        objStockItem.ClosingQty    = leatherItem.ReceiveQty;

                                        _context.Inv_StockItem.Add(objStockItem);
                                        _context.SaveChanges();
                                    }
                                    else
                                    {
                                        var LastItemInfo = (from i in _context.Inv_StockItem
                                                            where i.ItemTypeID == leatherItem.ItemTypeID && i.LeatherType == leatherTypeID && i.LeatherStatus == leatherStatusID && i.StoreID == item.ReceiveStore
                                                            orderby i.TransectionID descending
                                                            select i).FirstOrDefault();

                                        //var LastItemInfo = (from i in context.Inv_StockItem
                                        //                    where i.TransectionID == LastItemTransactionID
                                        //                    select i).FirstOrDefault();

                                        Inv_StockItem objStockItem = new Inv_StockItem();

                                        objStockItem.OpeningQty    = LastItemInfo.ClosingQty;
                                        objStockItem.IssueQty      = 0;
                                        objStockItem.ReceiveQty    = leatherItem.ReceiveQty;
                                        objStockItem.ClosingQty    = LastItemInfo.ClosingQty + leatherItem.ReceiveQty;
                                        objStockItem.ItemTypeID    = LastItemInfo.ItemTypeID;
                                        objStockItem.LeatherType   = LastItemInfo.LeatherType;
                                        objStockItem.LeatherStatus = LastItemInfo.LeatherStatus;
                                        objStockItem.StoreID       = LastItemInfo.StoreID;
                                        objStockItem.UnitID        = leatherItem.UnitID;

                                        _context.Inv_StockItem.Add(objStockItem);
                                        _context.SaveChanges();
                                    }

                                    #endregion

                                    leatherItem.RecordStatus = "CNF";
                                }
                            }

                            item.RecordStatus = "CNF";
                        }

                        purchaseInfo.RecordStatus = "CNF";

                        _context.SaveChanges();
                    }
                    Transaction.Complete();
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public int UpdateAdjustItemRequest(InvLeatherStockAdjustModel model, int userID)
        {
            var leatherTypeID   = DalCommon.GetLeatherTypeCode("Raw Hide");
            var leatherStatusID = DalCommon.GetLeatherStatusCode("Raw Hide");

            //var requestdate = (model.RequestDate).ToString("dd'/'MM'/'yyyy");

            using (TransactionScope transaction = new TransactionScope())
            {
                var currentRequestID = Convert.ToInt32(model.RequestID);
                var currentRequest   = (from r in _context.Inv_LeatherStockAdjustRequest.AsEnumerable()
                                        where r.RequestID == Convert.ToInt32(model.RequestID)
                                        select r).FirstOrDefault();



                currentRequest.RequestDate  = DalCommon.SetDate(model.RequestDate);
                currentRequest.PurchaseYear = model.PurchaseYear;
                currentRequest.LeatherType  = model.LeatherType;
                currentRequest.StoreID      = model.StoreID;
                currentRequest.SetBy        = userID;
                currentRequest.SetOn        = DateTime.Now;
                _context.SaveChanges();

                if (model.StockAdjustItemList != null)
                {
                    foreach (var item in model.StockAdjustItemList)
                    {
                        if (item.AdjustID == 0)
                        {
                            Inv_LeatherStockAdjustItem objAdjustmentItems = new Inv_LeatherStockAdjustItem();

                            objAdjustmentItems.RequestID       = Convert.ToInt32(model.RequestID);
                            objAdjustmentItems.SupplierID      = item.SupplierID;
                            objAdjustmentItems.PurchaseID      = item.ChallanID;
                            objAdjustmentItems.ItemTypeID      = item.ItemTypeID;
                            objAdjustmentItems.LeatherType     = model.LeatherType;
                            objAdjustmentItems.LeatherStatus   = leatherStatusID;
                            objAdjustmentItems.ItemQty         = item.ItemQty;
                            objAdjustmentItems.Unit            = item.Unit;
                            objAdjustmentItems.Remarks         = item.Remarks;
                            objAdjustmentItems.AdjustmentCause = item.AdjustmentCause;


                            _context.Inv_LeatherStockAdjustItem.Add(objAdjustmentItems);
                            _context.SaveChanges();
                        }
                        else
                        {
                            var CurrentItem = (from i in _context.Inv_LeatherStockAdjustItem.AsEnumerable()
                                               where i.AdjustID == item.AdjustID
                                               select i).FirstOrDefault();

                            CurrentItem.SupplierID      = item.SupplierID;
                            CurrentItem.PurchaseID      = item.ChallanID;
                            CurrentItem.ItemTypeID      = item.ItemTypeID;
                            CurrentItem.LeatherType     = model.LeatherType;
                            CurrentItem.LeatherStatus   = leatherStatusID;
                            CurrentItem.ItemQty         = item.ItemQty;
                            CurrentItem.Unit            = item.Unit;
                            CurrentItem.Remarks         = item.Remarks;
                            CurrentItem.AdjustmentCause = item.AdjustmentCause;
                            _context.SaveChanges();
                        }
                    }
                }

                transaction.Complete();
                return(currentRequestID);
            }
        }